esri.cluster.Featurelayeresri.cluster.Featurelayer的使用与直接引入CDN有一些使用的细节差异操作步骤省略
npm install esri-leaflet-cluster leaflet.markercluster
注意:因为esri.cluster.Featurelayer是基于leaflet.markercluster进行扩展开发的。故而安装时,两个包都需要安装。后者本身不是leaflet的官方组件,其实也是第三方扩展的,具体使用细节参考,https://github.com/Leaflet/Leaflet.markercluster

esri.cluster.Featurelayer和leaflet.markerclusterimport React, { useEffect } from 'react';
import L from "leaflet"
import * as esri from "esri-leaflet"
import * as markercluster from "leaflet.markercluster"
import * as cluster from "esri-leaflet-cluster"
import "leaflet.markercluster/dist/MarkerCluster.Default.css"
注意:若未引入leaflet.markercluster则编译运行后,浏览器很有可能报如下错误,主要就是基础类找不到的原因
TypeError: Object(…) is not a function
21 | this._layers = {};
22 | this._leafletIds = {};
23 |
> 24 | this.cluster = markerClusterGroup(options);
| ^ 25 | this._key = 'c' + (Math.random() * 1e9).toString(36).replace('.', '_');
import React, { useEffect } from 'react';
import L from "leaflet"
import * as esri from "esri-leaflet"
import * as markercluster from "leaflet.markercluster"
import * as cluster from "esri-leaflet-cluster"
import "leaflet.markercluster/dist/MarkerCluster.Default.css"
function ClusterFeatureLayer(props) {
useEffect(()=>{
//对于clusterFeatureLayer必须设置maxZoom属性,否则编译会出错
let map = L.map("clusterfeaturelayer_map", { maxZoom: 14}).setView([29.776,106.308],10)
let layer = cluster.featureLayer({
url: "http://localhost:6080/arcgis/rest/services/02_Tky_GDCGK/FeatureServer/4",
pointToLayer: function (geojson, latlng) {
return L.circleMarker(latlng, 2, {
color: "#2D84C8"
});
}
})
layer.addTo(map)
},[])
return (
<div id="clusterfeaturelayer_map" style={{ width: "100%", height: "800px" }}></div>
);
}
export default ClusterFeatureLayer;
maxZoom属性,否则会引起Uncaught Map has no maxZoom specified而导致地图不能加载 TypeError: Cannot read property '_addChild' of undefinedesri.cluster.Featurelayer和leaflet.markercluster的职责范围: esri.cluster.Featurelayer继承扩展自leaflet.markercluster因此,前者可以使用后者所提供的各种函数接口或config参数
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删