uni-app打包小程序使用地图标点优化


前言

使用小程序地图加载大批量的数据点会出现卡顿而且手机屏幕也是比较小 全部加载不仅体验不好而且数据点也没有办法全部观看 所以就想着优化一下 以当前的屏幕中心点为地图的中心加载附近的数据点

一、实现效果

在这里插入图片描述

二、代码实现

代码如下(示例):

<template>
	<view style="width: 100%;height: 100%;">
		<map id="map" style="width: 100%;height: 100%;" @regionchange="mapchangeTap" :markers="markers" :circles="circles"></map>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				circles: [],
				markers: [],
				title: '13233',
				id: 1,
			}
		},
		methods: {
			mapchangeTap(e) {
				if(e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {
					this.circles.splice(0)
					this.markers.splice(0)
					this.id++
					let map = uni.createMapContext("map",this)
					map.getCenterLocation({
						success: (res)=> {
							this.markers.push({
								id: this.id,
								latitude: res.latitude,
								longitude: res.longitude,
								label:123
							})
							this.circles.push({
							  latitude: res.latitude,
							  longitude: res.longitude,
							  color: '#FF0000DD',
							  fillColor: '#d1edff88',
							  radius: 100,//定位点半径
							  strokeWidth: 1
							})
						}
					})
				}
				
				
			}
		}
	}
</script>
<style>
page {
	height: 100%;
}
</style>

参考的帖子(https://blog.csdn.net/u010481239/article/details/83280946)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值