vue使用高德地图轨迹活动效果demo(整理)

bash 复制代码
在html页面引入您自己的key
<script language="javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=6b26c2c58770d13a4ecf2b96615dbaee">
		</script>

<template>
	<div class="index">
		<div id="amapContainer"></div>
	</div>
</template>

<script>
	const pathList = [{
			path: [120.99152, 27.937717],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.99152, 27.937717],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.99152, 27.937717],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.99152, 27.937717],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [119.654841, 26.345312],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [119.604823, 26.146219],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [119.608848, 25.888029],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [119.604823, 25.719924],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [119.700834, 25.637084],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [119.750277, 25.506716],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.07108, 25.189062],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.374635, 24.832797],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.627598, 24.087605],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.406831, 22.596914],
			msg: '2023-12-14 14:21:43'
		},
		{
			path: [120.866763, 22.267658],
			msg: '2023-12-14 14:21:43'
		}
	];
	export default {
		name: 'amapFence',
		data() {
			return {
				path: [], // 当前绘制的多边形经纬度数组
				polygonItem: [], // 地图上绘制的所有多边形对象
				polyEditors: [] // 所有编辑对象数组
			};
		},
		props: {
			paths: {} // 编辑
		},
		mounted() {
			this.intAmap(() => {});
		},
		methods: {
			// 绘制路线,
			drawPath(path) {
				const polyline1 = new AMap.Polyline({
					path, // 设置线覆盖物路径
					showDir: true,
					strokeColor: '#58aaff', // 线颜色
					strokeWeight: 5 // 线宽
				});
				this.map.add([polyline1]);
			},
			// 绘制圆点
			createMaker(path = []) {
				console.log(path, 'path--');
				path.forEach(v => {
					// 点标记显示内容,HTML要素字符串
					const markerContent = `<div class="amap-maker-icon"><div class="title">${v.msg}</div></div>`;
					const position = new this.AMap.LngLat(v.path[0], v.path[1]);
					const marker = new this.AMap.Marker({
						position: position,
						// 将 html 传给 content
						content: markerContent,
						// 以 icon 的 [center bottom] 为原点
						offset: new this.AMap.Pixel(-5, -5)
					});

					// 将 markers 添加到地图
					this.map.add(marker);
				});
			},
			// 地图初始化
			intAmap(callBack) {
				this.AMap = window.AMap;
				this.AMap.plugin(['AMap.MouseTool', 'AMap.PolyEditor', 'AMap.ControlBar'], function() {
					//TODO  创建控件并添加
				});
				const len = Math.ceil(pathList.length / 2); // 数组中间那个数据
				const center = [pathList[len].path[0], pathList[len].path[1]];

				this.map = new this.AMap.Map("amapContainer", {
					center,
					zoom: 6,
					pitch: 80,
					layers: [new AMap.TileLayer.Satellite()],
					viewMode: '2D', //开启3D视图,默认为关闭
					buildingAnimation: true, //楼块出现是否带动画
				});

				this.map.addControl(new this.AMap.ControlBar());
				if (callBack && typeof callBack == 'function') {
					callBack();
					this.drawPath(pathList.map(v => v.path));
					this.createMaker(pathList);
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	::v-deep#amapContainer {
		height: 800px;
		width: 100%;

		.amap-maker-icon {
			position: relative;
			height: 10px;
			width: 10px;
			border-radius: 10px;
			background: red;

			&:hover {
				.title {
					display: block;
				}
			}

			.title {
				// display: none;
				position: absolute;
				top: -20px;
				left: -70px;
				width: 150px;
				color: #333;
				font-size: 10px;
				border-radius: 5px;
				background: rgba(256, 256, 256)
			}
		}
	}
</style>
相关推荐
GIS思维24 天前
零代码实现下载高德地图AOI矢量shp边界,如武夷山风景区矢量边界
arcgis·gis·qgis·高德地图·aoi
鸭子嘎鹅子呱2 个月前
uniapp使用高德地图设置marker标记点,后续根据接口数据改变某个marker标记点,动态更新
uni-app·map·高德地图
Jiaberrr2 个月前
Vue3中集成高德地图并实现平移缩放功能
前端·javascript·vue.js·map·高德地图
程序喵D2 个月前
高德地图SDK Android版开发 11 覆盖物示例 4 线
android·高德地图
bug0到13 个月前
SpringBoot接入高德地图猎鹰轨迹服务API
java·spring boot·redis·高德地图
Beer Home3 个月前
gpxt 小程序:轨迹合并与管理的高效工具
小程序·轨迹·骑行·运动轨迹
WeiComp4 个月前
基于高德地图实现Android定位功能实现(二)
android·gis·高德地图
学前端的小朱5 个月前
使用Vue3+ElementPlus+高德地图实现在浏览器中搜索地点并被标记在地图中
前端·javascript·vue.js·elementui·高德地图
java_强哥7 个月前
html接入高德地图
前端·html·高德地图
renkai7219 个月前
彻底解决vue接入高德地图不显示公司名字问题
vue.js·map·高德地图·amp