mapserver/public/js/components/LayerSelector.js
Andrey Stepanov e1c9bdb8bd
Show layer selector only if more that one layer (#411)
Co-authored-by: Pierre-Yves Rollo <dev@pyrollo.com>
2024-11-11 19:50:45 +01:00

25 lines
617 B
JavaScript

import LayerManager from '../LayerManager.js';
function onchange(e){
const params = m.route.param();
params.layerId = e.target.value;
m.route.set("/map/:layerId/:zoom/:lon/:lat", params);
}
export default {
view: function(){
// Display layer selector only if there is choice
if (LayerManager.layers.length <= 1)
return null;
const layers = LayerManager.layers.map(layer => m(
"option",
{ value: layer.id, selected: layer.id == LayerManager.getCurrentLayer().id },
layer.name
));
return m("select", { class: "form-control", onchange: onchange },layers);
}
};