uniapp realiza el posicionamiento del mapa Tencent, la generación de puntos, la conexión multipunto, la línea de puntos clara, el mapa satelital y otras funciones

Función:

        1. Puntuación en el mapa, el punto tiene contenido y puede ver la información y los detalles del punto después de hacer clic en el punto

        2. Haga clic en el mapa para generar puntos y haga clic en varios puntos para realizar la función de conexión de puntos

        3. Después de hacer clic en el botón, los puntos generados se pueden borrar

        4. Mapa satelital y función de cambio de mapa predeterminado

1. Código completo + explicación del campo

1.latitud: latitud

2.enable-satellite: cambio de mapa satelital

3.longitud: longitud

4.escala: valor de escala

5.marcadores: puntuación, puede establecer el contenido del punto, llamada: establecer el contenido del cuadro de texto del punto

6.polygons: utilizado para la conexión

7. @callouttap: haga clic en el cuadro de texto sobre el punto para mostrar la capa de máscara y el contenido

<template>
	<view class="content">
		<map :enable-satellite="isMap" style="width: 100%; height: 100vh;" :latitude="latitude" :longitude="longitude"
			:scale="scale" :markers="markers" :polygons="polygons" @tap="mapTap" @callouttap="onCallouttap">
			<view class="btnmap" @click="isMap=!isMap">{
   
   {isMap?'腾讯地图':'卫星地图'}}</view>
			<!-- 覆盖在原生组件的文本视图 -->
			<!-- 遮罩层 -->
			<view v-if="popupShow" @click="popupShow=false" class="popup">
			</view>
			<view v-if="popupShow" class="deltail">
				弹层内容
			</view>
			<view class="btnmap way" @click="wayall">路径生成</view>
			<view class="btnmap close" @click="closeWayall">关闭路径</view>
		</map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude: '30.482814',
				longitude: '114.41917',
				isMap: false,
				scale: "16",
				markers: [{
					id: 0,
					latitude: 30.482814,
					longitude: 114.41917,
					width: 25,
					height: 35,
					callout: { // 气泡
						content: "标题",
						// bgColor: "rgba(255,255,255,0.51)",
						color: "#F56C6C",
						fontSize: 12,
						padding: 5,
						display: "ALWAYS",
						borderColor: "#F56C6C",
					},
				}],
				popupShow: false,
				polygons: [{ // 路线
					strokeWidth: 1,
					strokeColor: '#67c23a',
					fillColor: '#1791fc66',
					dottedLine: false,
					arrowLine: false,
					level: "abovelabels",
					// 必须要有三个默认属性,并且值不能完全一致,不然报错
					points: [{
						latitude: 30.627291,
						longitude: 114.343762
					}, {
						latitude: 30.627292,
						longitude: 114.343763,
					}, {
						latitude: 30.627291,
						longitude: 114.343762
					}]
				}],
				option: [],
				id: 0
			}
		},
		onLoad() {},
		methods: {
			mapTap({
				detail: {
					latitude,
					longitude
				}
			}) {
				// this.popupShow = true
				this.option = {
					id: ++this.id,
					latitude: latitude,
					longitude: longitude,
					width: 25,
					height: 35,
					callout: {
						content: `点${this.id}`,
						color: "#F56C6C",
						fontSize: 12,
						padding: 5,
						display: "ALWAYS",
						borderColor: "#F56C6C",
					}
				}
				let arr=[]
				this.markers.push(this.option)
				this.markers.forEach(item => {
					arr.push({
						latitude: item.latitude,
						longitude: item.longitude
					})
				})
				this.option=arr;
				// console.log(this.polygons, '地图画线');
			},
			wayall() {
				// 点线面,如果不是面就不让他生成
				if (this.option.length > 2) {
				this.polygons[0].points=[];
				this.polygons[0].points.push(...this.option)
				console.log(this.polygons,'得到的数值');
				}else{
					uni.showToast({
						title:"起码选择三个点",
						duration: 2000
					})
				}
			},
			change(){
				this.$refs.popup.close()
			},
			closeWayall(){
				this.polygons[0].points= [{
						latitude: 30.627291,
						longitude: 114.343762
					}, {
						latitude: 30.627292,
						longitude: 114.343763,
					}, {
						latitude: 30.627291,
						longitude: 114.343762
					}]
			},
			onCallouttap(event){
				console.log(event.detail.markerId,'获取到点的id之后可以用点id去请求接口');
				this.popupShow=true
			}
		},
	
	}
</script>

<style lang="scss" scoped>
	.popup {
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background: #000;
		opacity: 0.2;
		overflow: hidden;
		z-index: 1000;
		color: #fff;
	}

	.deltail {
		z-index: 10001;
		height: 300px;
		position: fixed;
		bottom: 0px;
		width: 100%;
		background-color: #fff;
	}

	.btnmap {
		position: fixed;
		top: 20px;
		right: 20px;
		width: 110px;
		height: 30px;
		color: #92bbea;
		text-align: center;
		line-height: 30px;
		border: 1px solid #92bbea;
		background-color: #fff;
	}

	.way {
		right: 140px;
	}
	.close{
		right: 260px;
	}
</style>

2. Efecto

 

 Este es el final del artículo, espero que les sea útil~

Supongo que te gusta

Origin blog.csdn.net/qq_44278289/article/details/131558589
Recomendado
Clasificación