From 1b38178d0fb79ae82a51f5754ddf51f3c1c09a5c Mon Sep 17 00:00:00 2001 From: Kristian Kraljic <(none)> Date: Sun, 19 Apr 2020 15:22:21 +0200 Subject: 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. --- web/simple/app.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'web/simple/app.js') diff --git a/web/simple/app.js b/web/simple/app.js index ed889f1..0c44bae 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) { -- cgit v1.2.3