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

Clustering GeoJson Points #415

Closed
vipervf1 opened this issue Jul 7, 2014 · 10 comments
Closed

Clustering GeoJson Points #415

vipervf1 opened this issue Jul 7, 2014 · 10 comments

Comments

@vipervf1
Copy link

vipervf1 commented Jul 7, 2014

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

@mathiasmuller4sh
Copy link

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>

@mathiasmuller4sh
Copy link

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;
        };

@stefan2k
Copy link

Nice workaround!

@briankostar
Copy link

this saved me some time! thanks

@nmccready
Copy link
Contributor

👍

@nmccready
Copy link
Contributor

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

@briankostar
Copy link

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

@mahmoudmy
Copy link

Very useful, thanks!

@nmccready
Copy link
Contributor

This issue was moved to angular-ui/ui-leaflet#30

@nmccready nmccready reopened this Oct 29, 2015
@tombatossals
Copy link
Owner

I'm going to rework&redesign angular-leaflet-directive to be compatible with Leaflet v1.0. It will mantain almost all its functionality, and will be compatible with the current features of the directive, but I must start from a fresh point, so I'm going to close this issue. If you think it must be worked with the new version, please reopen it.

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

No branches or pull requests

8 participants