From 95b83a4ae35294a15e7e24726a87bb594f0903d3 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 8 Sep 2015 18:12:27 +0200 Subject: [PATCH] allow auto-refresh markers --- wdocs/last/functions.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wdocs/last/functions.js b/wdocs/last/functions.js index 4932236..ebd241e 100644 --- a/wdocs/last/functions.js +++ b/wdocs/last/functions.js @@ -1,5 +1,6 @@ var map; var markers = {}; +var livemarkers = true; function initialize() { var lat = 50.098280; @@ -28,6 +29,18 @@ function clog(upd, id, s) { console.log(upd + ": " + ident + " " + s); } +/* + * Close all the infowindows in the `markers' object, and then open the + * infowindow in the specified marker. + */ + +function refreshmarkers(m) { + for (var k in markers) { + markers[k]['infowindow'].close(); + } + m['infowindow'].open(map, m); +} + /* * `loc' is a location object obtained via Websockets from the recorder */ @@ -54,6 +67,9 @@ function map_marker(loc) /* Grab the InfoWindow of this marker and change content */ m['infowindow'].setContent(loc.description); + if (livemarkers) { + refreshmarkers(m); + } } else { clog("NEW", id, JSON.stringify(loc)); var circle ={ @@ -82,6 +98,9 @@ function map_marker(loc) google.maps.event.addListener(m, "click", function(e) { this['infowindow'].open(map, this); }); + if (livemarkers) { + refreshmarkers(m); + } markers[id] = m; }