angular-leaflet-directive icon indicating copy to clipboard operation
angular-leaflet-directive copied to clipboard

Clustering GeoJson Points

Open vipervf1 opened this issue 12 years ago • 10 comments

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

vipervf1 avatar Jul 07 '14 19:07 vipervf1

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 avatar Jul 10 '14 15:07 mathiasmuller4sh

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

mathiasmuller4sh avatar Jul 11 '14 10:07 mathiasmuller4sh

Nice workaround!

stefan2k avatar Oct 27 '14 13:10 stefan2k

this saved me some time! thanks

briankostar avatar May 14 '15 21:05 briankostar

:+1:

nmccready avatar May 14 '15 21:05 nmccready

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

nmccready avatar May 14 '15 21:05 nmccready

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

briankostar avatar May 14 '15 21:05 briankostar

Very useful, thanks!

mahmoudmy avatar Jun 17 '15 15:06 mahmoudmy

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

nmccready avatar Oct 29 '15 16:10 nmccready

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.

tombatossals avatar Nov 04 '15 07:11 tombatossals