Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Clustering GeoJson Points #30

Open
nmccready opened this issue Oct 29, 2015 · 8 comments
Open

Clustering GeoJson Points #30

nmccready opened this issue Oct 29, 2015 · 8 comments

Comments

@nmccready
Copy link
Contributor

From @vipervf1 on July 7, 2014 19:51

Is there an easy way to use the clustering plugin when using geojson points instead of markers?

Copied from original issue: tombatossals/angular-leaflet-directive#415

@nmccready
Copy link
Contributor Author

From @mathiasmuller4sh on July 10, 2014 15:10

Hi,
I'am working on the same problem.

I've made a little hack in the index.html and it seems to do the tricks.

EDIT: Now, need to add a listener to remove cluster on geojson layer remove

    <script src="lib/js/leaflet/dist/leaflet.js" type="text/javascript"></script>
    <script src="lib/js/leaflet.markercluster/dist/leaflet.markercluster.js" type="text/javascript"></script>
    <script>
        L.GeoJSON = L.GeoJSON.extend({
            addTo: function(map) {
                var markers = new L.MarkerClusterGroup({
                    spiderfyOnMaxZoom: false,
                    showCoverageOnHover: false,
                    zoomToBoundsOnClick: false,
                    disableClusteringAtZoom: 19
                });
                map.addLayer(markers);
                markers.addLayer(this);
                return this;
            }
        });
        L.geoJson = function (geojson, options) {
            return new L.GeoJSON(geojson, options);
        };
    </script>

@nmccready
Copy link
Contributor Author

From @mathiasmuller4sh on July 11, 2014 10:28

Complete hack with remove listener.
I use this code in my angular controller

        L.GeoJSON = L.GeoJSON.extend({
            addTo: function(map) {
                var self = this;
                map.addLayer(this.markers);
                var parentRemove = L.GeoJSON.prototype.onRemove;
                L.GeoJSON.prototype.onRemove = function (map) {
                    self.markers.removeLayer(self);
                    delete self.markers;
                    parentRemove(map);
                };
                return this;
            }
        });
        L.geoJson = function (geojson, options) {
            var geoJSON = new L.GeoJSON(geojson, options);
            var markers = new L.MarkerClusterGroup({
                spiderfyOnMaxZoom: false,
                showCoverageOnHover: true,
                zoomToBoundsOnClick: true,
                disableClusteringAtZoom: 18
            });
            markers.setGeoJSON = function(data) {
                geoJSON.setGeoJSON(data);
            };
            markers.addLayer(geoJSON);
            geoJSON.markers = markers;
            return  markers;
        };

@nmccready
Copy link
Contributor Author

From @stefan2k on October 27, 2014 13:33

Nice workaround!

@nmccready
Copy link
Contributor Author

From @briankostar on May 14, 2015 21:16

this saved me some time! thanks

@nmccready
Copy link
Contributor Author

👍

@nmccready
Copy link
Contributor Author

Someone want to work on flushing this out into the geojson directive?

@nmccready
Copy link
Contributor Author

From @briankostar on May 14, 2015 21:36

I'm still learning, but I'll take a crack at it this weekend.

@nmccready
Copy link
Contributor Author

From @mahmoudmy on June 17, 2015 15:1

Very useful, thanks!

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

No branches or pull requests

1 participant