From 6023d2851d39f25848b8a3448d5be5954cbcb12b Mon Sep 17 00:00:00 2001 From: Cocker Koch Date: Tue, 13 Nov 2018 15:57:39 +0100 Subject: [PATCH] Issue-267: Swap Lat Lon - Coordinates in map_leaflet.js are calculated and displayed in unusual Order "Lon,Lat" instead of "Lat,Lon". So swap them - Improve Calculation of Popup-Text --- docroot/map/map_leaflet.js | 50 +++++++++++++++----------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/docroot/map/map_leaflet.js b/docroot/map/map_leaflet.js index aa42747..4c97c71 100644 --- a/docroot/map/map_leaflet.js +++ b/docroot/map/map_leaflet.js @@ -6,7 +6,7 @@ function initialize_leaflet() { attribution: '© OpenStreetMap contributors' }).addTo(map); - + var dataURL = location.protocol + "//" + location.host; var parts = location.pathname.split('/'); @@ -31,41 +31,31 @@ function initialize_leaflet() { features: [] }; - var geojsonLayer = new L.GeoJSON( empty_geojson , { + var geojsonLayer = new L.GeoJSON(empty_geojson, { pointToLayer: function (feature, latlng) { return L.circleMarker(latlng, geojsonMarkerOptions); }, onEachFeature: function(feature, layer) { - if (feature.geometry.type == "Point") { - var data ={} - data.lat = feature.geometry.coordinates[0].toFixed(4); - data.lon = feature.geometry.coordinates[1].toFixed(4); - data.addr = feature.properties.address; - var tst = feature.properties.tst; - // determine speed - data.speed = feature.properties.vel; - var speed = data.speed; - var dt = moment.utc(tst * 1000).local(); - data.tst = tst; - data.fulldate = dt.format("DD MMM YYYY HH:mm:ss") - var t = "{{ addr }}
({{ lat }},{{lon}}) {{ fulldate }}
Speed: {{ speed }}"; - // if speed is 0 then don't display speed - if (speed === 0) { - t = "{{ addr }}
({{ lat }},{{lon}}) {{ fulldate }}" - } - if (typeof(tst) === 'undefined') { - t = "Position: ({{lat}},{{lon}})
Speed: {{speed}}"; - } - // if speed is 0 then don't display speed - if (typeof(tst) === 'undefined' && speed === 0) { - t = "Position: ({{lat}},{{lon}})"; - } - - layer.bindPopup(Mustache.render(t, data)); + if (feature.geometry.type == 'Point') { + var data ={}; + data.address = feature.properties.address; + data.lat = feature.geometry.coordinates[1].toFixed(5); + data.lon = feature.geometry.coordinates[0].toFixed(5); + data.vel = feature.properties.vel; + data.tst = feature.properties.tst; + var localtime = moment.utc(data.tst * 1000).local(); + data.timestring = localtime.format('YYYY-MM-DD, ddd, HH:mm:ss Z'); + + var text = []; + if(data.timestring) {text.push('{{ timestring }}')} + if(data.lat && data.lon) {text.push('{{ lat }},{{ lon }}')} + if(data.address) {text.push('{{ address }}')} + if(data.vel !== undefined) {text.push('{{ vel }} km/h')} + layer.bindPopup(Mustache.render(text.join('
'), data)); } }, style : function(feature) { - if (feature.geometry.type == "Point") { + if (feature.geometry.type == 'Point') { return {} } else { return { @@ -75,7 +65,7 @@ function initialize_leaflet() { } } }); - + map.addLayer(geojsonLayer); $.getJSON( dataURL, function( data ) {