当前位置: 首页 > news >正文

vue使用高德地图实现轨迹显隐

<template><div><el-button type="primary" @click="pathShowOrHide">轨迹显/隐</el-button><div id="container" /></div>
</template><script>
import AMapLoader from '@amap/amap-jsapi-loader'export default {name: 'MapView',data() {return {map: null,PathSimplifier: null,$: null,pathState: true}},mounted() {this.initAMap()},unmounted() {this.map?.destroy()},methods: {initPage(PathSimplifier, $) {const pathSimplifierIns = new PathSimplifier({zIndex: 100,// autoSetFitView:false,map: this.map, // 所属的地图实例getPath: function(pathData, pathIndex) {return pathData.path},getHoverTitle: function(pathData, pathIndex, pointIndex) {return null}})window.pathSimplifierIns = pathSimplifierInspathSimplifierIns.setData([{name: '测试',path: [[116.405289, 39.904987],[113.964458, 40.54664],[111.47836, 41.135964],[108.949297, 41.670904]]}])const pathNavigatorStyles = [{width: 16,height: 24,content: 'defaultPathNavigator'}]function extend(dst) {if (!dst) {dst = {}}const slist = Array.prototype.slice.call(arguments, 1)for (let i = 0, len = slist.length; i < len; i++) {const source = slist[i]if (!source) {continue}for (const prop in source) {if (source.hasOwnProperty(prop)) {dst[prop] = source[prop]}}}return dst}let idx = 0const navg1 = pathSimplifierIns.createPathNavigator(0, {loop: true,speed: 1000000,pathNavigatorStyle: extend({}, pathNavigatorStyles[0])})navg1.start()function changeNavgContent() {// 获取到pathNavigatorStyle的引用const pathNavigatorStyle = navg1.getStyleOptions()// 覆盖修改extend(pathNavigatorStyle, pathNavigatorStyles[(++idx) % pathNavigatorStyles.length])// 重新绘制pathSimplifierIns.renderLater()}setInterval(changeNavgContent, 500)},initAMap() {const that = thisAMapLoader.load({key: 'ed030cd90d1a6014ea01f26d51250f40', // 申请好的Web端开发者Key,首次调用 load 时必填version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15plugins: ['AMap.Scale'], // 需要使用的的插件列表,如比例尺'AMap.Scale',支持添加多个如:['...','...']AMapUI: {version: '1.1',plugins: ['overlay/SimpleMarker']}// 需要使用的的插件列表,如比例尺'AMap.Scale'等}).then((AMap) => {this.map = new AMap.Map('container', {// 设置地图容器idviewMode: '3D', // 是否为3D地图模式zoom: 4, // 初始化地图级别center: [116.397428, 39.90923] // 初始化地图中心点位置})AMapUI.load(['ui/misc/PathSimplifier', 'lib/$'], (PathSimplifier, $) => {if (!PathSimplifier.supportCanvas) {alert('当前环境不支持 Canvas!')return}this.PathSimplifier = PathSimplifierthis.$ = $this.initPage(PathSimplifier, $)})}).catch((e) => {console.log(e)})},pathShowOrHide() {if (this.pathState) {window.pathSimplifierIns.setData([])this.pathState = false} else {this.initPage(this.PathSimplifier, this.$)this.pathState = true}}}
}
</script><style scoped>
#container {width: 100%;height: 300px;
}
</style>
http://www.lryc.cn/news/474658.html

相关文章:

  • Maven(20) 如何使用Maven进行版本管理?
  • AWS RDS MySQL内存使用
  • Vue指令:v-else、v-else-if
  • 基于SSM志愿者招募系统的设计
  • 数学建模与优化算法:从基础理论到实际应用
  • 微信小程序生成二维码
  • 自由软件与开源软件:异同与联系
  • Vue中ref、reactive、toRef、toRefs的区别
  • 凸极式发电机的相量图分析和计算,内功率因数角和外功率因数角和功角的定义。
  • systemctl restart NetworkManager 重启后,文件/etc/resolv.conf修改失败
  • Admin.NET源码学习(5:swagger使用浅析)
  • 在 openEuler 22.03 服务器上搭建 web 服务教程
  • 如何取消自动配置ipv4地址:步骤详解与实用指南
  • 医院信息化与智能化系统(15)
  • 小红书笔记详情API接口系列(概述到示例案例)
  • 跨境电商平台系统开发
  • 开源模型应用落地-qwen模型小试-Qwen2.5-7B-Instruct-玩转ollama-Modelfile文件(二)
  • 链表详解(一)
  • npm入门教程6:npm脚本
  • 用Python脚本执行安卓打包任务
  • 制作安装k8s需要的离线yum源
  • Node学习记录-events
  • Java Collection/Executor DelayedWorkQueue 总结
  • 《TCP/IP网络编程》学习笔记 | Chapter 1:理解网络编程和套接字
  • 服务端监控工具:Nmon使用方法
  • Java中的线程安全问题(如果想知道Java中有关线程安全问题的基本知识,那么只看这一篇就足够了!)
  • 基础设施即代码(IaC)在Python自动化运维中的应用探讨
  • 浅谈路由器
  • openGauss数据库-头歌实验1-1 初识openGauss
  • QT找不到ffmpeg链接库解决方法