aboutsummaryrefslogtreecommitdiff
path: root/web/public
diff options
context:
space:
mode:
authorKumar Damani <kumar.damani@mail.utoronto.ca>2019-03-08 01:36:06 +0000
committerKumar Damani <kumar.damani@mail.utoronto.ca>2019-03-08 01:36:06 +0000
commitd54324f974ddc85ba76e1922faeb58b247baf651 (patch)
tree22ed7ba4be0b6e276e234cd33bbb0deff4b6a7a8 /web/public
parent7ea91f912c1511f60466c3a47ad6ee075cecc0f2 (diff)
parent5f1fa4936a3b45139c2bc111ecd602f3d13c2e90 (diff)
resolving conflicts
Diffstat (limited to 'web/public')
-rw-r--r--web/public/javascripts/map.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js
index 4b8b8f3..5b196d9 100644
--- a/web/public/javascripts/map.js
+++ b/web/public/javascripts/map.js
@@ -7,12 +7,16 @@ function plotPointsOnMap(points) {
L.geoJson(points, {
pointToLayer: function (feature, latlng) {
//return L.circleMarker(latlng);
+ latlngbounds.extend(latlng);
return L.marker(latlng);
}
}).bindPopup(function (layer) {
// layer.feature.geometry gives you access to all the fields
return "<p>" + JSON.stringify(layer.feature.geometry) + "</p>";
}).addTo(map)
+
+ // rezoom the map so that all the markers fit in the view
+ map.fitBounds(latlngbounds);
}
// different basemap
@@ -23,10 +27,15 @@ L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r}
maxZoom: 18,
ext: 'png'
}).addTo(map);
+
+// keep track of the boundary of the markers so that we can update the
+// map to fit them all
+var latlngbounds = new L.latLngBounds();
+
plotPointsOnMap(points);
if (window.EventSource) {
var source = new EventSource('/stream');
-
+
source.addEventListener('message', function(e) {
var data = JSON.parse(e.data);
if (data.coordinates) {
@@ -34,11 +43,11 @@ if (window.EventSource) {
plotPointsOnMap(points);
}
}, false)
-
+
source.addEventListener('open', function(e) {
console.log("Connection was opened")
}, false)
-
+
source.addEventListener('error', function(e) {
if (e.readyState == EventSource.CLOSED) {
console.log("Connection was closed")