Only show layerSwitcher controls if there is more than 1 base layer present

This commit is contained in:
James Wilson 2017-02-03 10:50:37 -06:00
parent 5d781785aa
commit 484765a119

View file

@ -495,12 +495,14 @@ function initialize_map() {
}));
var foundType = false;
var baseCount = 0;
ol.control.LayerSwitcher.forEachRecursive(layers, function(lyr) {
if (!lyr.get('name'))
return;
if (lyr.get('type') === 'base') {
baseCount++;
if (MapType === lyr.get('name')) {
foundType = true;
lyr.setVisible(true);
@ -547,13 +549,16 @@ function initialize_map() {
controls: [new ol.control.Zoom(),
new ol.control.Rotate(),
new ol.control.Attribution({collapsed: true}),
new ol.control.ScaleLine({units: DisplayUnits}),
new ol.control.LayerSwitcher()
new ol.control.ScaleLine({units: DisplayUnits})
],
loadTilesWhileAnimating: true,
loadTilesWhileInteracting: true
});
if (baseCount > 1) {
OLMap.addControl(new ol.control.LayerSwitcher());
}
// Listeners for newly created Map
OLMap.getView().on('change:center', function(event) {
var center = ol.proj.toLonLat(OLMap.getView().getCenter(), OLMap.getView().getProjection());