Skip to content

Commit

Permalink
Add ?overlays request parameter to control overlays
Browse files Browse the repository at this point in the history
* Not yet implemented in track sharing URL generation
* Transient: will not be shown on next refresh (should be made consistent with behaviour for ?map one way or the other)
* Hidden overlays are shown (transient as well)
Examples:
- Multi: http://localhost:8000/?map=OpenStreetMap&overlays=Hills,Cycling
- Hidden: http://localhost:8000/?map=OpenStreetMap&overlays=FR%20IGN%20Parcelles
Part of #26
  • Loading branch information
eddy-geek committed Dec 23, 2021
1 parent f385bb2 commit 667ed15
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions js/wtracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2061,8 +2061,9 @@ $(function(){
var overlays = {};
var baseLayer = getVal("wt.baseLayer", config.display.map);
var requestedMap = getParameterByName("map")
var requestedOverlays = (getParameterByName("overlays") || "").split(',')
mapsForEach(function(name, props) {
if (props.on || name === requestedMap || name == baseLayer) {
if (props.on || name == baseLayer || name === requestedMap || requestedOverlays.includes(name)) {
var inList = props.in == MAP_MY ? mymaps : config.maps;
var tile = getProvider(inList[name]);
if (tile) {
Expand Down Expand Up @@ -2176,17 +2177,26 @@ $(function(){
.remove()
}

objectForEach(overlaysOn, function(oname, oon) {
var ovl = overlays[oname];
if (ovl) {
if (oon) {
if (requestedOverlays) {
requestedOverlays.forEach(function(oname) {
var ovl = overlays[oname];
if (ovl) {
map.addLayer(ovl);
}
} else {
// doesn't exist anymore, delete it
setOverlay(oname, undefined);
}
});
});
} else {
objectForEach(overlaysOn, function(oname, oon) {
var ovl = overlays[oname];
if (ovl) {
if (oon) {
map.addLayer(ovl);
}
} else {
// doesn't exist anymore, delete it
setOverlay(oname, undefined);
}
});
}

map.on("overlayadd", function(e) {
ga('send', 'event', 'map', 'overlay', e.name);
Expand Down

0 comments on commit 667ed15

Please sign in to comment.