leaflet实现点聚合

使用leaflet地图实现点聚合

  • 引入插件
"leaflet.markercluster": "^1.5.3",
  • 在 .vue页面中使用
// 引入 leaflet.markercluster
import "leaflet.markercluster/dist/MarkerCluster.css"
import "leaflet.markercluster/dist/MarkerCluster.Default.css"
import "leaflet.markercluster";

//展示受影响的设备--暂时未用
 getpointFuc(str) {
   let urlString = config.newMapPath;
   let sqlBuffer = "tenant_id = '" + this.tenantId + "' and " + str;
   let param = {
       service: 'WFS',
       version: '2.0.0',
       request: 'GetFeature',
       typeName: `ne:${config.deviceTableName}`,
       propertyName: 'shape,device_name,is_conduit_up,device_code,device_model,device_material,supplier_name,device_addr',
       outputFormat: 'application/json',
       maxFeatures: 100000,
       srsName: 'EPSG:4326',
       startIndex: 0,
       cql_filter: sqlBuffer,
   };
   let u = urlString + L.Util.getParamString(param, urlString);
   this.$http({
       url: u
   }).then(res => {
       //设备数据返回后 处理渲染数据加到图层
       let features = res.data.features
       let markers = L.markerClusterGroup();   //点聚合
       this.customerLayer.addLayer(markers)
       let layers = [];
       for (let i = 0; i < features.length; i++) {
           let a = features[i];
           let deviceIcon = this.getIcon(type, 1);
           let marker = L.marker(new L.LatLng(a.geometry.coordinates[1], a.geometry.coordinates[0]), {
               title: a.properties.name,
               icon: deviceIcon,
           });
           let popupContent = `
               <div class="content-flex">名称:${a.properties.device}</div>
               <div class="content-flex">编码:${a.properties.device}</div>
               <div class="content-flex">型号:${a.properties.device}</div>
               <div class="content-flex">材质:${a.properties.device}</div>
               <div class="content-flex">厂商:${a.properties.device}</div>
               <div class="content-flex">地址:${a.properties.device}</div>`
           marker.bindPopup(popupContent);   //点击显示设备信息
           layers.push(marker)
       }
       markers.addLayers(layers);
   })
},

getIcon(isUp, type) {
	  if (type == 0) {
	      return L.icon({ iconUrl: a[0].q, iconSize: [40, 40] });
	  } else {
	      return L.icon({ iconUrl: a[0].s, iconSize: [40, 40] });
	  }
},
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值