Compute _layers for MarkerCluster, so to easily know if layer has data

This commit is contained in:
Yohan Boniface 2023-08-10 08:16:03 +02:00
parent c6ded31daa
commit 5dda33f5e4

View file

@ -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 () {
@ -266,7 +281,7 @@ L.U.DataLayer = L.Evented.extend({
},
hasDataVisible: function () {
return !!Object.keys(this.layer._layers).length
return this.layer.hasDataVisible()
},
resetLayer: function (force) {
@ -981,9 +996,7 @@ L.U.DataLayer = L.Evented.extend({
buildVersionsFieldset: function (container) {
const appendVersion = function (data) {
const date = new Date(parseInt(data.at, 10))
const content = `${date.toLocaleString(L.lang)} (${
parseInt(data.size) / 1000
}Kb)`
const content = `${date.toLocaleString(L.lang)} (${parseInt(data.size) / 1000}Kb)`
const el = L.DomUtil.create('div', 'umap-datalayer-version', versionsContainer)
const a = L.DomUtil.create('a', '', el)
L.DomUtil.add('span', '', el, content)