0

I have a feature layer where one of the properties always takes 4 possible values.

Now I want to make 1 request to get all the features, group them by this property and feed each group to a different markercluster (or esri leaflet cluster) so I can have a separate cluster for every group. However it doesn't seem possible to do it without creating a cluster layer for each group explicitly, which would result in 4 separate requests and multiplying complexity. As far as I can see pointToLayer and iconCreateFunction doesn't really do the job (and they do weird things when points are removed or recreated), and panes only group the rendered markers, not the actual cluster itself.

1 Answer 1

0

marker.cluster clusters need names, you would have to declare each one separately.
You can however query your full layer once hold the GeoJSON object under the name data and use leaflet's filter method

var data;
fetch('url://of.the.esri.featureserver.query', {
  method: 'GET'
}).then(function(response) {
  data = response.json();
})

var cluster1 = L.markerClusterGroup();  
var cluster2 = L.markerClusterGroup();  

var layer1 = L.geoJSON(data, {
  filter: function(feature){
    if(feature.properties.column == 1 ){
        return true
      }
}
});

var layer2 = L.geoJSON(data, {
  filter: function(feature){
    if(feature.properties.column == 2 ){
        return true
      }
}
});

layer1.addTo(cluster1);
layer2.addTo(cluster2);

This way you get the data once, and use it multiple times.

7
  • This would always return all the features in the feature layer, no? My feature layer contains lots of points and I really need to confine the return result within the boundaries of the map, so getting all of them at once is out of the question. Manually re-inventing the code for this and updating the data dynamically would be a really big hassle...
    – user171163
    Commented Oct 12, 2020 at 8:12
  • You would have to share some code if you want to explain what is your problem. I would also recommend asking what is your input if possible and what is your desired output.
    – Dror Bogin
    Commented Oct 12, 2020 at 8:19
  • I don't see how any of that would help explaining the problem. I already have a feature layer that I'm using L.esri.featureLayer/L.esri.Cluster.featureLayer to integrate with and display. Now I want to group the points into several categories to feed into each layer of its own. I DO NOT want to re-invent the wheel and re-implement all the features featureLayer gives to me, including bounding box, query, max/min view and other things by fetching the features manually.
    – user171163
    Commented Oct 12, 2020 at 8:28
  • Then why not use the query option as documented here?
    – Dror Bogin
    Commented Oct 12, 2020 at 8:38
  • I want to avoid making 4 requests separately. Each group of points would then be rendered at different times and it's difficult to coordinate them together.
    – user171163
    Commented Oct 12, 2020 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.