leaflet实现点位聚合代码
使用 markerClusterGroup 代替原生group
// 创建群组let markers = L.markerClusterGroup({maxClusterRadius: 120,animate: true,iconCreateFunction: function (cluster) {let curMarkers = cluster.getAllChildMarkers()let n = 0for (let i = 0; i < curMarkers.length; i++) {n += 1}let className = 'mycluster'if (n > 60) {className += ' error'}return L.divIcon({html: n, className: className, iconSize: L.point(40, 40)});}})// 将点位数据转化为地图点位for (let i = 0; i < points.length; i++) {let thisPoint = points[i]// 创建markerlet proLatlng = this.map.dataToProvider(thisPoint.lng, thisPoint.lat)let marker = L.marker({lng: proLatlng[0], lat: proLatlng[1]}, {title: thisPoint.crossName,riseOnHover: true,icon: this.markerIcon(thisPoint),$data: thisPoint // 挂载数据})// 配置popuplet popupTpl = `${thisPoint.crossName}
经纬度:${thisPoint.lng}, ${thisPoint.lat}
- 流量(pcu/h)${thisPoint.flow || 0}
- 饱和度${thisPoint.saturationIdx || 0}
- 溢流指数${thisPoint.overflowIdx || 0}
- 失衡指数${thisPoint.unbalanceIdx || 0}
实时诊断信号优化历史数据`let popup = L.popup().setContent(popupTpl)marker.bindPopup(popup)// 配置tooltipmarker.bindTooltip(L.tooltip({direction: 'top', offset: L.point(0, -10)})).setTooltipContent(`${thisPoint.crossName}`)// 添加到群组中markers.addLayer(marker)}// 群组添加到地图中this.map.$map.addLayer(markers)
有想换工作的同学可以找我内推哦不低于15k(前端,java,测试)

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
