vue leaflet地图leaflet-canvas-marker海量点不卡顿,拖拽,缩放地图, 海量点清空,不卡顿

vue leaflet地图marker海量点

支持:拖拽地图,放大缩小地图,海量点清空,海量点重新标点不卡顿

vue 使用leaflet地图过程省略

leaflet 海量点

1、安装依赖
npm i leaflet-canvas-marker-xrr2021
2、在vue页面中引入依赖包
import('leaflet-canvas-marker-xrr2021')

引入依赖

3、初始化地图后,创建canvasIconLayer容器

that.ciLayer : 为海量标点创建的变量名

that.ciLayer = L.canvasIconLayer({}).addTo(map);
that.ciLayer.addOnClickListener(function (event, data) {});

在这里插入图片描述

4、进行marker标点
filterPoint(bounds) {
	let that = this;
	if (that.filterArr.length == 0) {   //在标点前,先清空已有标点。
       that.ciLayer.removeLayers(that.layers)
       return
  	 } else {
       that.ciLayer.removeLayers(that.layers)
	 }
	that.layers = [];  // 存放海量点的数组
	that.filterArr.map(point => {
        let str = `<span class="mapLetter">${point.gajgDwmc}</span>`;
        var myIcon1 = L.icon({
          iconUrl: require('../../../../assets/images/full-screen/dz.png'),
          iconSize: [14, 22],
          iconAnchor: [12, 22]
        });
         let wgs = toWGS.bd09togcj02(Number(point.sjdzDqjd), Number(point.sjdzDqwd))  // 转换坐标,依据自己需求
        let market = L.marker([wgs[1], wgs[0]], {icon: myIcon1, title: point.gajgDwmc, alt: point.gajgdwbm})
        that.layers.push(market)
        market.on({click: clickEvt})
      })
	that.ciLayer.addLayers(that.layers);   //海量点标点
}

在这里插入图片描述

5、清除海量点

1、全部清除:根据自己的逻辑,在需要清除海量点的地方,加入清除代码。不会造成卡。

that.ciLayer.removeLayers(that.layers)

2、按条清除:标点量大于300个的情况下一个一个点清除,在拖拽地图时,会导致地图卡。

 that.layers.map(item=>{
      that.ciLayer.removeLayer(item);
})

3、结合1、2点,所以博主的海量点标点逻辑是:在进行海量点标点前,先把海量点用1方法一次性情空,再把新的海量点放入数组that.layers中,然后重新进行标点(参考4、进行marker标点)

6、地图拖拽,海量点重新标点,获取新的地图区域,进行区域内标点
this.map.on('dragstart', function (e) {
          let bounds = that.map.getBounds() 
          that.filterPoint(bounds)    //调用4marker标点方法
      })
7、地图放大缩小,海量点标点
this.map.on('zoom', function (e) {
          let bounds = that.map.getBounds()
          that.filterPoint(bounds)  //调用4marker标点方法
      })
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值