googlearchive / js-marker-clusterer

A marker clustering library for the Google Maps JavaScript API v3.
https://googlemaps.github.io/js-marker-clusterer/docs/reference.html
Apache License 2.0
1.28k stars 772 forks source link

Marker cluster using geojson #138

Open ronak90 opened 7 years ago

ronak90 commented 7 years ago

Is there any way to implement marker cluster using geojson data layer? This JS supports only those markers which are created by google.maps.Marker objects.

Linuus commented 6 years ago

I'm very much interested in this as well.

404mike commented 6 years ago
map.data.loadGeoJson('locate.json' + param, null, function(features) {

    // group items / cluster
    var markers = features.map(function(feature) {
        var g = feature.getGeometry();

        var marker = new google.maps.Marker({
            'position': g.get(0),
            'data' : feature
        });

        return marker;
    });

    // create a new marker cluster
    var markerCluster = new MarkerClusterer(map, markers, {
        imagePath: 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m',
        gridSize: 15, 
        zoomOnClick: false
    });

    // add event listener to the cluster
    google.maps.event.addListener(markerCluster, 'clusterclick', function (cluster) {
     // handle clickevent
    });

});

https://googlemaps.github.io/js-marker-clusterer/docs/reference.html

joenammour commented 6 years ago

Hi Everyone, for some reason this did not work for me but if I added this as as style then it worked. I wanted to mention it just in case it helps anyone else because it was driving me crazy.

map.data.setStyle({ visible: false });