Skip to content

Commit

Permalink
Factor out clearMapSwitcherLayers in fix-mapbox.js
Browse files Browse the repository at this point in the history
  • Loading branch information
liskin committed May 11, 2021
1 parent 2a5733b commit 9f48b85
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fix-mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ document.arrive(".mapboxgl-map", {onceOnly: false, existing: true, fireOnAttribu
const s = `${type}_overlay`;
if (!map.getSource(s))
map.addSource(s, sourceFromLeaflet(l.overlay));
if (map.getLayer("map-switcher-overlay"))
map.removeLayer("map-switcher-overlay");
map.addLayer({id: "map-switcher-overlay", type: "raster", source: s}, before);
}

if (!map.getSource(type))
map.addSource(type, sourceFromLeaflet(l));
map.addLayer({id: "map-switcher", type: "raster", source: type}, l.overlay ? "map-switcher-overlay" : before);
}

function clearMapSwitcherLayers(map) {
if (map.getLayer("map-switcher-overlay"))
map.removeLayer("map-switcher-overlay");
if (map.getLayer("map-switcher"))
map.removeLayer("map-switcher");
map.addLayer({id: "map-switcher", type: "raster", source: type}, l.overlay ? "map-switcher-overlay" : before);
}

function clearCompositeLayers(map) {
Expand All @@ -68,6 +71,7 @@ document.arrive(".mapboxgl-map", {onceOnly: false, existing: true, fireOnAttribu

try {
if (!map.getLayer("map-switcher") && mapType) {
clearMapSwitcherLayers(map);
layerFromLeaflet(map, mapType, "heat");
}
} catch (e) {
Expand Down Expand Up @@ -137,6 +141,7 @@ document.arrive(".mapboxgl-map", {onceOnly: false, existing: true, fireOnAttribu
if (t && !AdditionalMapLayers[t])
return;

clearMapSwitcherLayers(map);
localStorage.stravaMapSwitcherPreferred = t;

if (t) {
Expand Down

0 comments on commit 9f48b85

Please sign in to comment.