Cluster multiple map services in leaflet

1863
2
Jump to solution
04-07-2017 02:55 PM
DarrylKlassen1
Occasional Contributor

I am trying to cluster multiple layers in leaflet, but it doesn't seem to be working.  I have 5 rest end points that I am trying to put together to cluster using the L.markerClusterGroup().  This is what I have in my html:

<script>
  var map = L.map('map').setView([50.6805, -120.3421], 12);

  L.esri.basemapLayer('Streets').addTo(map);
  var markers = L.markerClusterGroup();
  var ArtsCultureEducation = L.esri.featureLayer({
       url: 'http://geoprodsvr.kamloops.ca/arcgis3/rest/services/Website/CityFacilities_LL/MapServer/0',
  });
  var PublicSafteySite = L.esri.featureLayer({
      url: 'http://geoprodsvr.kamloops.ca/arcgis3/rest/services/Website/CityFacilities_LL/MapServer/1',
  });

  markers.addLayer(PublicSafteySite);
  markers.addLayer(ArtsCultureEducation);
  map.addLayer(markers);
</script>

The points from the 2 layers show up, but they don't cluster.  Any help would be appreciated.

Thanks

Darryl

0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor

when Leaflet.markerCluster.addLayer() is called, an attempt is made immediately to check whether a single lat/long can be extracted and clustered:

// if its not possible to dig out a single lat/lon from the layer,
// abort clustering
if (!layer.getLatLng) {
    this._nonPointGroup.addLayer(layer);
    this.fire('layeradd', { layer: layer });
    return this;
}‍‍‍‍‍‍‍‍‍‍‍

so you have several problems...

1. L.esri.featureLayer doesn't fetch any features at all until after it is added to the map and even then has to make asynchronous web requests to ask for features that intersect the area being drawn

2. even when these features are retrieved, they can't be pulled out of L.esri.featureLayer via the .getLatLng() method that plugin uses (above).

in the ArcGIS world, we tend to think of layers as entire collections of features with the same geometry type in a map. In Leaflet, a layer often refers to a single geometry (marker, polyline or polygon)

unfortunately, i don't have any helpful advice for conveniently managing and clustering data coming from several different services. it would take some work.

View solution in original post

0 Kudos
2 Replies
JohnGravois
Frequent Contributor

when Leaflet.markerCluster.addLayer() is called, an attempt is made immediately to check whether a single lat/long can be extracted and clustered:

// if its not possible to dig out a single lat/lon from the layer,
// abort clustering
if (!layer.getLatLng) {
    this._nonPointGroup.addLayer(layer);
    this.fire('layeradd', { layer: layer });
    return this;
}‍‍‍‍‍‍‍‍‍‍‍

so you have several problems...

1. L.esri.featureLayer doesn't fetch any features at all until after it is added to the map and even then has to make asynchronous web requests to ask for features that intersect the area being drawn

2. even when these features are retrieved, they can't be pulled out of L.esri.featureLayer via the .getLatLng() method that plugin uses (above).

in the ArcGIS world, we tend to think of layers as entire collections of features with the same geometry type in a map. In Leaflet, a layer often refers to a single geometry (marker, polyline or polygon)

unfortunately, i don't have any helpful advice for conveniently managing and clustering data coming from several different services. it would take some work.

View solution in original post

0 Kudos
DarrylKlassen1
Occasional Contributor

Thanks John

0 Kudos