Skip to content

Commit 5140825

Browse files
committed
imagery: support legacy location query params
1 parent 368d52e commit 5140825

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cookbooks/imagery/templates/default/imagery.js.erb

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
<% require 'uri' %>
2+
function getUrlParams() {
3+
const params = {};
4+
const queryString = window.location.search.substring(1);
5+
const regex = /([^&=]+)=([^&]*)/g;
6+
let match;
7+
8+
while (match = regex.exec(queryString)) {
9+
params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
10+
}
11+
12+
return params;
13+
}
14+
215
function createMap(divName) {
16+
// Get URL parameters
17+
const params = getUrlParams();
18+
const lon = params.lon ? parseFloat(params.lon) : null;
19+
const lat = params.lat ? parseFloat(params.lat) : null;
20+
const zoom = params.zoom ? parseInt(params.zoom) : null;
21+
322
// Create a map
423
var map = L.map(divName, {
524
worldCopyJump: true
6-
}).fitBounds(<%= @bbox.to_json %>);
25+
});
26+
27+
// Set initial view if URL parameters are available, otherwise fitBounds
28+
if (lat !== null && lon !== null && zoom !== null) {
29+
map.setView([lat, lon], zoom);
30+
} else {
31+
map.fitBounds(<%= @bbox.to_json %>);
32+
}
733

834
// Create a layer switcher
935
var layers = L.control.layers(null, null, {collapsed:false}).addTo(map);

0 commit comments

Comments
 (0)