Skip to content

Commit

Permalink
Add ?overlays request parameter to control overlays
Browse files Browse the repository at this point in the history
Behaviour on refresh and for hidden overlays is similar as for `?map`...
... except there is a preexisting issue right now where enabled overlays are not shown on refresh, but they are in the shared URL.

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 129ec9c
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions js/wtracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,11 @@ $(function(){
var params = "";
if (isChecked("#wtshare-map")) {
params += "&map=" + encodeURIComponent(baseLayer);
overlays = []
objectForEach(overlaysOn, function(oname, oon) {
if (oon) overlays.push(oname);
});
params += "&overlays=" + encodeURIComponent(overlays.join(','));
}
if (isChecked("#wtshare-enc")) {
var pwd = Math.random().toString(36).substring(2);
Expand Down Expand Up @@ -2061,8 +2066,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 +2182,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 129ec9c

Please sign in to comment.