// different basemap // L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { // 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', subdomains: 'abcd', minZoom: 0, maxZoom: 18, ext: 'png' }).addTo(map); plotPointsOnMap(points); if (window.EventSource) { var source = new EventSource('/stream'); source.addEventListener('message', function(e) { var data = JSON.parse(e.data); if (data.coordinates) { points.push(data); 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") } }, false) } else { console.log("sse not supported."); }