diff options
author | Kristian Kraljic <(none)> | 2020-04-19 15:22:21 +0200 |
---|---|---|
committer | Kristian Kraljic <(none)> | 2020-04-19 19:39:38 +0200 |
commit | 1b38178d0fb79ae82a51f5754ddf51f3c1c09a5c (patch) | |
tree | c45b17b0af9a55ec65ec29d4e1b13bf65aff1f9b | |
parent | 3973030c9d7795779e6b3d309e6788f5b7077ecb (diff) | |
download | trackermap-web-1b38178d0fb79ae82a51f5754ddf51f3c1c09a5c.tar.gz trackermap-web-1b38178d0fb79ae82a51f5754ddf51f3c1c09a5c.tar.bz2 trackermap-web-1b38178d0fb79ae82a51f5754ddf51f3c1c09a5c.zip |
Add long./lat./zoom URI parameters to simple UI
Instead of reading the longitude, latitude and zoom options from the
user / server configuration, one could use the new longitude=,
latitude= and zoom= URI parameters, in order to define the launch map
view. This is especially useful, in case you would like to embed
multiple maps with different views into e.g. another website.
-rw-r--r-- | web/simple/app.js | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/web/simple/app.js b/web/simple/app.js index ed889f19..0c44bae5 100644 --- a/web/simple/app.js +++ b/web/simple/app.js @@ -29,8 +29,12 @@ if (!Array.prototype.find) { }); } +var getQueryParameter = function(name) { + return (window.location.search.match('[?&]' + name + '=([^&]*)') || [])[1]; +}; + var url = window.location.protocol + '//' + window.location.host; -var token = (window.location.search.match(/token=([^&#]+)/) || [])[1]; +var token = getQueryParameter('token'); var style = function (label) { return new ol.style.Style({ @@ -98,10 +102,10 @@ ajax('GET', url + '/api/server', function(server) { ajax('GET', url + '/api/session?token=' + token, function(user) { map.getView().setCenter(ol.proj.fromLonLat([ - user.longitude || server.longitude || 0.0, - user.latitude || server.latitude || 0.0 + parseFloat(getQueryParameter('longitude')) || user.longitude || server.longitude || 0.0, + parseFloat(getQueryParameter('latitude')) || user.latitude || server.latitude || 0.0 ])); - map.getView().setZoom(user.zoom || server.zoom || 2); + map.getView().setZoom(parseFloat(getQueryParameter('zoom')) || user.zoom || server.zoom || 2); ajax('GET', url + '/api/devices', function(devices) { |