Fix layer control

This commit is contained in:
James Lyne 2021-08-22 18:01:03 +01:00
parent 82119dc32d
commit 94ecd3f495

View File

@ -70,44 +70,7 @@ var DynmapLayerControl = L.Control.Layers.extend({
this._lastZIndex++;
layer.setZIndex(this._lastZIndex);
}
},
// Function override to convert the position-based ordering into the id-based ordering
_onInputClick: function () {
var i, input, obj,
inputs = this._form.getElementsByTagName('input'),
inputsLen = inputs.length,
baseLayer;
this._handlingClick = true;
// Convert ID to pos
var id2pos = {};
for (i in this._layers) {
id2pos[this._layers[i].id] = i;
}
for (i = 0; i < inputsLen; i++) {
input = inputs[i];
obj = this._layers[id2pos[input.layerId]];
if (input.checked && !this._map.hasLayer(obj.layer)) {
this._map.addLayer(obj.layer);
if (!obj.overlay) {
baseLayer = obj.layer;
}
} else if (!input.checked && this._map.hasLayer(obj.layer)) {
this._map.removeLayer(obj.layer);
}
}
if (baseLayer) {
this._map.setZoom(this._map.getZoom());
this._map.fire('baselayerchange', {layer: baseLayer});
}
this._handlingClick = false;
},
}
});