From 484765a1197cb6ef01148f7e8117882c1ec77505 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Fri, 3 Feb 2017 10:50:37 -0600 Subject: [PATCH] Only show layerSwitcher controls if there is more than 1 base layer present --- public_html/script.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public_html/script.js b/public_html/script.js index a11a8d6..fdb0da2 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -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());