diff --git a/html/layers.js b/html/layers.js index b494276e..a9d2537c 100644 --- a/html/layers.js +++ b/html/layers.js @@ -100,28 +100,36 @@ function createBaseLayers() { })); if (1) { - let openfreemap = new ol.layer.VectorTile({ + world.push(new ol.layer.VectorTile({ type: 'base', name: 'OpenFreeMapLiberty', title: 'OpenFreeMap Liberty', declutter: true, - }); - // ol-mapbox-style plugin packed in with ol ... (kinda ugly) - ol.mapboxStyle.applyStyle(openfreemap, "https://tiles.openfreemap.org/styles/liberty"); - ol.mapboxStyle.applyBackground(openfreemap, "https://tiles.openfreemap.org/styles/liberty"); - world.push(openfreemap); + onVisible: (layer) => { + if (!layer.get('styleApplied')) { + // ol-mapbox-style plugin packed in with ol ... (kinda ugly) + ol.mapboxStyle.applyStyle(layer, "https://tiles.openfreemap.org/styles/liberty"); + ol.mapboxStyle.applyBackground(layer, "https://tiles.openfreemap.org/styles/liberty"); + layer.set('styleApplied', true); + } + }, + })); } if (1) { - let openfreemap = new ol.layer.VectorTile({ + world.push(new ol.layer.VectorTile({ type: 'base', name: 'OpenFreeMapPositron', title: 'OpenFreeMap Positron', declutter: true, - }); - // ol-mapbox-style plugin packed in with ol ... (kinda ugly) - ol.mapboxStyle.applyStyle(openfreemap, "https://tiles.openfreemap.org/styles/positron"); - ol.mapboxStyle.applyBackground(openfreemap, "https://tiles.openfreemap.org/styles/positron"); - world.push(openfreemap); + onVisible: (layer) => { + if (!layer.get('styleApplied')) { + // ol-mapbox-style plugin packed in with ol ... (kinda ugly) + ol.mapboxStyle.applyStyle(layer, "https://tiles.openfreemap.org/styles/positron"); + ol.mapboxStyle.applyBackground(layer, "https://tiles.openfreemap.org/styles/positron"); + layer.set('styleApplied', true); + } + }, + })); } diff --git a/html/script.js b/html/script.js index cc40b7db..5e82d5da 100644 --- a/html/script.js +++ b/html/script.js @@ -2501,6 +2501,10 @@ function ol_map_init() { if (MapType_tar1090 == lyr.get('name')) { foundType = true; lyr.setVisible(true); + + mapTypeSettings(); + const onVisible = lyr.get('onVisible'); + onVisible && onVisible(lyr); } else { lyr.setVisible(false); } @@ -2509,6 +2513,8 @@ function ol_map_init() { if (evt.target.getVisible()) { MapType_tar1090 = loStore['MapType_tar1090'] = evt.target.get('name'); mapTypeSettings(); + const onVisible = lyr.get('onVisible'); + onVisible && onVisible(lyr); } }); } else if (lyr.get('type') === 'overlay') {