Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum of values of a point in a cluster #363

Closed
mironk opened this issue Jun 9, 2014 · 4 comments
Closed

Sum of values of a point in a cluster #363

mironk opened this issue Jun 9, 2014 · 4 comments

Comments

@mironk
Copy link

mironk commented Jun 9, 2014

Hi
is there a way to count and show in the icon the Sum of the values per point instead of count of child's
ex:
for the data -
[-37.8211946833, 175.2213655333, "1"],
[-37.8209458667, 175.2214051333, "5"],
[-37.8208292333, 175.2214374833, "7"],
[-37.8325816, 175.2238798667, "537"]

=> the values on cluster icon for those points will show 550 (instead of 4)

@Abbe98
Copy link

Abbe98 commented Jun 9, 2014

That does not sound as a feature of markelcluster, you would probably be forced to write a custom solution, or use another plugin.

@danzel
Copy link
Member

danzel commented Jun 9, 2014

This is pretty easy.
Record that value against each of your markers myMarker.someNumber = 5;
Then provide a custom iconCreateFunction that does something like this:
https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

var markers = new L.MarkerClusterGroup({
    iconCreateFunction: function(cluster) {
        var children = cluster.getAllChildMarkers();
        var sum = 0;
        for (var i = 0; i < children.length; i++) {
            sum += children[i].someNumber;
        }
        return new L.DivIcon({ html: '<b>' + sum + '</b>' });
    }
});

@danzel danzel closed this as completed Jun 9, 2014
@karthikpitani
Copy link

Hello danzel,

I don't have any experience with JS. Can you please help me how do I implement the above function in R using leaflet?

Specifically I'm struggling to understand how to record a value against the marker in the cluster.

@IvanSanchez
Copy link
Member

@pitKay Hi, great to hear that you find Leaflet useful!

However, this issue tracker is used for reporting bugs and discussing new features. For questions on using Leaflet, please use gis.stackexchange.com or stackoverflow.

If you are really sure that this is a bug in leaflet, or a feature request, please change the wording to make it look like a bug report.

@Leaflet Leaflet locked and limited conversation to collaborators Mar 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants