Giter Club home page Giter Club logo

Comments (8)

nmccready avatar nmccready commented on July 20, 2024

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>

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

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

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

From @stefan2k on October 27, 2014 13:33

Nice workaround!

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

From @briankostar on May 14, 2015 21:16

this saved me some time! thanks

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

👍

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

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

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

From @briankostar on May 14, 2015 21:36

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

from ui-leaflet.

nmccready avatar nmccready commented on July 20, 2024

From @mahmoudmy on June 17, 2015 15:1

Very useful, thanks!

from ui-leaflet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.