Only show layerSwitcher controls if there is more than 1 base layer present
This commit is contained in:
parent
5d781785aa
commit
484765a119
|
@ -495,12 +495,14 @@ function initialize_map() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var foundType = false;
|
var foundType = false;
|
||||||
|
var baseCount = 0;
|
||||||
|
|
||||||
ol.control.LayerSwitcher.forEachRecursive(layers, function(lyr) {
|
ol.control.LayerSwitcher.forEachRecursive(layers, function(lyr) {
|
||||||
if (!lyr.get('name'))
|
if (!lyr.get('name'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (lyr.get('type') === 'base') {
|
if (lyr.get('type') === 'base') {
|
||||||
|
baseCount++;
|
||||||
if (MapType === lyr.get('name')) {
|
if (MapType === lyr.get('name')) {
|
||||||
foundType = true;
|
foundType = true;
|
||||||
lyr.setVisible(true);
|
lyr.setVisible(true);
|
||||||
|
@ -547,13 +549,16 @@ function initialize_map() {
|
||||||
controls: [new ol.control.Zoom(),
|
controls: [new ol.control.Zoom(),
|
||||||
new ol.control.Rotate(),
|
new ol.control.Rotate(),
|
||||||
new ol.control.Attribution({collapsed: true}),
|
new ol.control.Attribution({collapsed: true}),
|
||||||
new ol.control.ScaleLine({units: DisplayUnits}),
|
new ol.control.ScaleLine({units: DisplayUnits})
|
||||||
new ol.control.LayerSwitcher()
|
|
||||||
],
|
],
|
||||||
loadTilesWhileAnimating: true,
|
loadTilesWhileAnimating: true,
|
||||||
loadTilesWhileInteracting: true
|
loadTilesWhileInteracting: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (baseCount > 1) {
|
||||||
|
OLMap.addControl(new ol.control.LayerSwitcher());
|
||||||
|
}
|
||||||
|
|
||||||
// Listeners for newly created Map
|
// Listeners for newly created Map
|
||||||
OLMap.getView().on('change:center', function(event) {
|
OLMap.getView().on('change:center', function(event) {
|
||||||
var center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection());
|
var center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection());
|
||||||
|
|
Loading…
Reference in a new issue