Skip to content

Commit

Permalink
OpenFreeMap: only apply style if layer is used
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Feb 27, 2025
1 parent e289142 commit 41bc691
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
32 changes: 20 additions & 12 deletions html/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
}));
}


Expand Down
6 changes: 6 additions & 0 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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') {
Expand Down

0 comments on commit 41bc691

Please sign in to comment.