From 3b36b1ad459ee739a87a32a18bb5846770125bec Mon Sep 17 00:00:00 2001 From: ivanshen Date: Tue, 5 Mar 2019 16:39:35 -0500 Subject: modularize plot points --- web/public/javascripts/map.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'web/public/javascripts') diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index 5739dec..2547780 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -3,6 +3,18 @@ // attribution: '© OpenStreetMap contributors' // }).addTo(map); +function plotPointsOnMap(points) { + L.geoJson(points, { + pointToLayer: function (feature, latlng) { + //return L.circleMarker(latlng); + return L.marker(latlng); + } + }).bindPopup(function (layer) { + // layer.feature.geometry gives you access to all the fields + return "

" + JSON.stringify(layer.feature.geometry) + "

"; + }).addTo(map) +} + // different basemap L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r}.{ext}', { attribution: 'Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap contributors', @@ -11,15 +23,7 @@ L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r} maxZoom: 18, ext: 'png' }).addTo(map); -L.geoJson(points, { - pointToLayer: function (feature, latlng) { - //return L.circleMarker(latlng); - return L.marker(latlng); - } -}).bindPopup(function (layer) { - // layer.feature.geometry gives you access to all the fields - return "

" + JSON.stringify(layer.feature.geometry) + "

"; -}).addTo(map) +plotPointsOnMap(points); if (!!window.EventSource) { var source = new EventSource('/stream'); @@ -27,15 +31,7 @@ if (!!window.EventSource) { var data = JSON.parse(e.data); if (data.coordinates) { points.push(data); - L.geoJson(points, { - pointToLayer: function (feature, latlng) { - //return L.circleMarker(latlng); - return L.marker(latlng); - } - }).bindPopup(function (layer) { - // layer.feature.geometry gives you access to all the fields - return "

" + JSON.stringify(layer.feature.geometry) + "

"; - }).addTo(map) + plotPointsOnMap(points); } }, false) -- cgit v1.2.3