Clustering GeoJson Points
Is there an easy way to use the clustering plugin when using geojson points instead of markers?
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>
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;
};
Nice workaround!
this saved me some time! thanks
:+1:
Someone want to work on flushing this out into the geojson directive?
I'm still learning, but I'll take a crack at it this weekend.
Very useful, thanks!
This issue was moved to angular-ui/ui-leaflet#30
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.