maps: keep a single cluster layer (#22854)

This commit is contained in:
Frédéric Péters 2018-03-28 13:01:52 +02:00
parent 3b79d3c228
commit aaa7cba251
1 changed files with 10 additions and 4 deletions

View File

@ -34,7 +34,8 @@ $(function() {
if (map.geo_json) map.geo_json.remove();
map.geo_json = geo_json;
if ($map_widget.data('group-markers')) {
var markers = L.markerClusterGroup({showCoverageOnHover: false,
if (! map.clustered_markers) {
map.clustered_markers = L.markerClusterGroup({showCoverageOnHover: false,
zoomToBoundsOnClick: true,
removeOutsideVisibleBounds: true,
iconCreateFunction: function (cluster) {
@ -51,9 +52,14 @@ $(function() {
}
return new L.DivIcon({html: icon_html, className: 'marker-cluster' + c, iconSize: new L.Point(icon_size, icon_size)});
}});
markers.addLayer(geo_json);
map.addLayer(markers);
map.clustered_markers = markers;
map.addLayer(map.clustered_markers);
}
map.clustered_markers.eachLayer(
function(layer) {
map.clustered_markers.removeLayer(layer);
}
);
map.clustered_markers.addLayer(geo_json);
} else {
geo_json.addTo(map);
}