diff --git a/web/static/map.js b/web/static/map.js index 23a554f..82ac01b 100644 --- a/web/static/map.js +++ b/web/static/map.js @@ -37,10 +37,8 @@ function initMap() { map.createPane('diffPane'); map.createPane('countyPane'); - // Set initial z-indices for panes - map.getPane('osmPane').style.zIndex = 400; - map.getPane('diffPane').style.zIndex = 401; - map.getPane('countyPane').style.zIndex = 402; + // Set initial z-indices for panes based on layerOrder + updateLayerZIndex(); // Setup drag selection setupDragSelection(); @@ -1100,14 +1098,30 @@ function updateLayerZIndex() { 'county': 'countyPane' }; + const layers = { + 'osm': osmLayer, + 'diff': diffLayer, + 'county': countyLayer + }; + // Reverse index so first item in list is on top + // Use higher base z-index (650) to ensure we're above overlay pane layerOrder.forEach((layerName, index) => { const paneName = panes[layerName]; const pane = map.getPane(paneName); if (pane) { - pane.style.zIndex = 400 + (layerOrder.length - 1 - index); + const zIndex = 650 + (layerOrder.length - 1 - index); + pane.style.zIndex = zIndex; } }); + + // Also bring layers to front in reverse order (last first, so first ends up on top) + for (let i = layerOrder.length - 1; i >= 0; i--) { + const layer = layers[layerOrder[i]]; + if (layer && map.hasLayer(layer)) { + layer.bringToFront(); + } + } } // Toggle layer visibility @@ -1117,13 +1131,15 @@ function toggleLayer(layerId, layer) { if (checkbox.checked && layer) { if (!map.hasLayer(layer)) { map.addLayer(layer); - updateLayerZIndex(); } } else if (layer) { if (map.hasLayer(layer)) { map.removeLayer(layer); } } + + // Always update z-index after toggling any layer + updateLayerZIndex(); } // Event listeners