uniapp map画多边形 打点连线

我是参考https://blog.csdn.net/zyj12138/article/details/112463219这个地址完成的

先看结果
在这里插入图片描述
代码

<map
			style="width: 750rpx; height: 100vh;"
			id="myMap"
			ref="myMap"
			:latitude="latitude"
			:longitude="longitude"
			:scale="16"
			:show-location="true"
			:enable-satellite="true"
			:polyline="markerPolyline"
			:markers="markerPoints"
			:polygon="markerPolygon"
			@tap="tapMap"
		/>


data() {
		return {
			latitude: 41.67718,
			longitude: 123.4631,
			landPoints: []
		};
	},
	onLoad() {
		uni.getLocation({
			geocode: true,
			success: res => {
				this.latitude = res.latitude;
				this.longitude = res.longitude;
			}
		});
	},
	computed: {
		markerPoints() {
			if (this.landPoints.len
您可以使用uniapp内置的地图组件,通过监听地图点击事件来实现打点和弹窗功能。 首先,在`<template>`中添加地图组件: ```html <template> <view> <uni-mpvue-map :longitude="longitude" :latitude="latitude" @tap="onMapTap"> <uni-mpvue-map-marker v-for="(marker, index) in markers" :id="index" :longitude="marker.longitude" :latitude="marker.latitude" :title="marker.title" :iconPath="marker.iconPath" :label="marker.label" @tap="onMarkerTap"></uni-mpvue-map-marker> </uni-mpvue-map> </view> </template> ``` 其中,`longitude`和`latitude`为当前地图的中心点坐标。`markers`为已经打好的点的数组,`iconPath`为点的图标路径,`label`为点的标签。 然后,在`<script>`中添加以下代码: ```javascript export default { data() { return { longitude: 116.397389, latitude: 39.908860, markers: [ { longitude: 116.397389, latitude: 39.908860, title: '点1', iconPath: '/static/marker.png', label: { content: '标签1', color: '#ffffff', fontSize: 12, bgColor: '#000000', borderRadius: 3, padding: 5, textAlign: 'center' } }, { longitude: 116.407389, latitude: 39.908860, title: '点2', iconPath: '/static/marker.png', label: { content: '标签2', color: '#ffffff', fontSize: 12, bgColor: '#000000', borderRadius: 3, padding: 5, textAlign: 'center' } } ] } }, methods: { onMapTap(e) { const { longitude, latitude } = e.mp.detail this.markers.push({ longitude, latitude, title: '新点', iconPath: '/static/marker.png', label: { content: '新标签', color: '#ffffff', fontSize: 12, bgColor: '#000000', borderRadius: 3, padding: 5, textAlign: 'center' } }) }, onMarkerTap(e) { const { markerId } = e.mp.detail const marker = this.markers[markerId] uni.showModal({ title: marker.title, content: `经度:${marker.longitude},纬度:${marker.latitude}`, showCancel: false }) } } } ``` 在`onMapTap`函数中,通过`e.mp.detail`获取到点击的位置的经纬度,然后将该点信息添加到`markers`数组中,实现打点功能。 在`onMarkerTap`函数中,通过`e.mp.detail`获取到点击的点的`markerId`,然后根据`markerId`获取该点的信息,弹出该点的标题和经纬度的弹窗。 以上就是uniapp中使用地图组件打点并弹窗的实现方法。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值