From d89b03a69750f255b9a9e00962078cd548457dba Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 13 Jun 2018 18:10:55 +0000 Subject: [PATCH] Optional 'zoom' parameter added to the map page to override Google Maps auto-zoom (needed if the page is embedded in an iframe) --- platypush/backend/http/__init__.py | 12 +++++++++++- platypush/backend/http/static/js/map.js | 6 +++++- platypush/backend/http/templates/map.html | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/platypush/backend/http/__init__.py b/platypush/backend/http/__init__.py index ed1189332f..f5e53320c7 100644 --- a/platypush/backend/http/__init__.py +++ b/platypush/backend/http/__init__.py @@ -147,6 +147,13 @@ class HttpBackend(Backend): @app.route('/map', methods=['GET']) def map(): """ + Query parameters: + start -- Map timeline start timestamp + end -- Map timeline end timestamp + zoom -- Between 1-20. Set it if you want to override the + Google's API auto-zoom. You may have to set it if you are + trying to embed the map into an iframe + Supported values for `start` and `end`: - now - yesterday @@ -158,6 +165,7 @@ class HttpBackend(Backend): Default: start=yesterday, end=now """ + def parse_time(time_string): if not time_string: return None @@ -200,9 +208,11 @@ class HttpBackend(Backend): start = parse_time(http_request.args.get('start', default='yesterday')) end = parse_time(http_request.args.get('end', default='now')) + zoom = http_request.args.get('zoom', default=None) + return render_template('map.html', config=self.maps, utils=HttpUtils, start=start, end=end, - token=self.token, api_key=api_key, + zoom=zoom, token=self.token, api_key=api_key, websocket_port=self.websocket_port) return app diff --git a/platypush/backend/http/static/js/map.js b/platypush/backend/http/static/js/map.js index 0c40998a2e..f8cf7dbc55 100644 --- a/platypush/backend/http/static/js/map.js +++ b/platypush/backend/http/static/js/map.js @@ -48,7 +48,11 @@ function initMapFromGeopoints(points) { // Now fit the map to the newly inclusive bounds map.fitBounds(bounds); setTimeout(function() { - map.setZoom(getBoundsZoomLevel(bounds, $map.children().width(), $map.children().height())); + if (window.zoom) { + map.setZoom(window.zoom); + } else { + map.setZoom(getBoundsZoomLevel(bounds, $map.children().width(), $map.children().height())); + } }, 1000); google.maps.event.removeListener(listener); diff --git a/platypush/backend/http/templates/map.html b/platypush/backend/http/templates/map.html index 6f6cab5ff9..5edce16f18 100644 --- a/platypush/backend/http/templates/map.html +++ b/platypush/backend/http/templates/map.html @@ -21,6 +21,12 @@ window.map_start = "{{ start }}"; window.map_end = "{{ end }}"; + {% if zoom %} + window.zoom = {{ zoom }}; + {% else %} + window.zoom = undefined; + {% endif %} + {% if token %} window.token = '{{ token }}' {% else %}