From 03ce11217b2d8f31ac731d343fb3f347f0a2234e Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Wed, 30 Sep 2015 11:07:00 +0200 Subject: [PATCH] experimental: live map fits bounds to all devices closes #46 --- docroot/last/functions.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docroot/last/functions.js b/docroot/last/functions.js index 94bd738..51a0144 100644 --- a/docroot/last/functions.js +++ b/docroot/last/functions.js @@ -41,6 +41,15 @@ function refreshmarkers(m) { m['infowindow'].open(map, m); } +function fitbounds() { + var bounds = new google.maps.LatLngBounds(); + for (var k in markers) { + bounds.extend(markers[k].getPosition()); + } + map.setCenter(bounds.getCenter()); /* Center to geometric center of all markers */ + map.fitBounds(bounds); +} + /* * `loc' is a location object obtained via Websockets from the recorder */ @@ -112,6 +121,8 @@ function map_marker(loc) markers[id] = m; } + + fitbounds(); } google.maps.event.addDomListener(window, 'load', initialize);