使用leaflet地图实现点聚合
"leaflet.markercluster": "^1.5.3",
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] });
}
},