From d188525c7416567cf279ca8ef028c575643acc6f Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 10 Aug 2023 08:16:03 +0200 Subject: [PATCH] Compute _layers for MarkerCluster, so to easily know if layer has data --- umap/static/umap/js/umap.layer.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index f6aecced..06035165 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -10,6 +10,10 @@ L.U.Layer = { }, postUpdate: function () {}, + + hasDataVisible: function () { + return !!Object.keys(this._layers).length + }, } L.U.Layer.Default = L.FeatureGroup.extend({ @@ -53,6 +57,17 @@ L.U.Layer.Cluster = L.MarkerClusterGroup.extend({ } L.MarkerClusterGroup.prototype.initialize.call(this, options) this._markerCluster = L.U.MarkerCluster + this._layers = [] + }, + + addLayer: function (layer) { + this._layers.push(layer) + return L.MarkerClusterGroup.prototype.addLayer.call(this, layer) + }, + + removeLayer: function (layer) { + this._layers.splice(this._layers.indexOf(layer), 1) + return L.MarkerClusterGroup.prototype.removeLayer.call(this, layer) }, getEditableOptions: function () { @@ -286,7 +301,7 @@ L.U.DataLayer = L.Evented.extend({ }, hasDataVisible: function () { - return !!Object.keys(this.layer._layers).length + return this.layer.hasDataVisible() }, resetLayer: function (force) {