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

interact with Leaflet.markercluster #12

Open
stefanocudini opened this issue Apr 23, 2013 · 3 comments
Open

interact with Leaflet.markercluster #12

stefanocudini opened this issue Apr 23, 2013 · 3 comments

Comments

@stefanocudini
Copy link

Exists an easy way for interact this plugin with Leaflet.markercluster??

1)the data is loaded in ajax
2)and the markers then are grouped by Leaflet.markercluster

@calvinmetcalf
Copy link
Owner

So the actual layer is just a geojson layer and the geojson layer does not work natively with the marker cluster plugin, it's expecting an array of markers not a feature collection, your best bet is probably to use the ajax method that this comes with to do it yourself, something like:

var clusters = (new L.MarkerClusterGroup()).addTo(map);
L.Util.ajax("url/same/origin.geojson", function(data){
    //check if it's an array of points or a feature collection
    var features = Array.isArray(data)?data:data.features;
    //map the features to points
    clusters.addLayers(features.map(function(feature){
        if(feature.geometry.type==="point"){
            return L.marker([feature.geometry.coordinates[1],feature.coordinates[0]]);//geojson is lng,lat
        }
    }).filter(function(v){return v}))//filter out any that weren't points
});

@khullrich
Copy link

Thanks for your solution but it doesn't work for me. No markers are displayed. :\

@calvinmetcalf
Copy link
Owner

@khullrich if you post what you did to jsfiddle I can take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants