question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

realtime don't update properties of geojson

See original GitHub issue

Hi! i use this code snippet to update my gps tracker data on map, everything working well besides that the geojson properties not being updated in the map. I show this properties with the OnEachFeature Option which called a function. This function creates a popup which shows the properties.

Now the problem…if the geojson is updated (position and properties) and the update is executed, only the position of the marker is updated, but not the properties in the popup. I have to reload the page to see the new properties.

How can i improve this?


 function onEachFeature(feature, layer) {
                if (feature.properties.course) {
                        popupContent = "Kurs: "+ feature.properties.course+" Grad <br>";
                }
                if (feature.properties.speed) {
                        popupContent += "Geschwindigkeit: "+ feature.properties.speed+" m/s <br>";
                }
                if (feature.properties.time) {
                        popupContent += "Zeit der GPS Daten: "+ feature.properties.time+"<br>";
                }
                layer.bindPopup(popupContent);
        }


 //initialisiere map
 var mymap = L.map('mapid');
 L.tileLayer.provider('Hydda.Full').addTo(mymap);
 realtime = L.realtime(('http://myurl/position.geojson'), {
        interval: 8 * 1000,

        pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, punktdef).bindTooltip("Tooltiptext");},

        onEachFeature: onEachFeature,

                                                                }).addTo(mymap);
 realtime.on('update', function() {
    mymap.fitBounds(realtime.getBounds(), {maxZoom: 15});
                               });

this is the position.geojson example {"properties": {"course": "87.0", "speed": "2.4", "time": "18:01:25 21.08.2018"}, "geometry": {"type": "Point", "coordinates": [18.578666632, 57.452197767]}, "type": "Feature"}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tomber42commented, Aug 31, 2018

Cool…it works… and so i was able to compare both and found the problem with your code above

realtime.on('update', function(e) {
    Object.keys(e.enter).forEach(function(id) {
       var feature = e.enter[id];
       this.getLayer(id).bindPopup("Zeit der GPS Daten: "+ feature.properties.time+"<br>");
   }.bind(this));
}, this);

the last “this” is wrong…if i remove that everything is ok

0reactions
tomber42commented, Aug 31, 2018

Thx, will try this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating features with realtime and leaflet - Stack Overflow
I use leaflet-realtime.js to update the weather information. The weather data is stored in a Geojson file. Bootleaf has a sidebar and its ......
Read more >
Update a feature in realtime | Mapbox GL JS
This example shows how to change an existing feature on a map by updating its data. It shows the progression of a path...
Read more >
Updating GeoJSON properties? - GIS Stack Exchange
In order to change a property of the i-th feature in a GeoJSON FeatureCollection , just campus.features[i].properties.demand = newValue; ...
Read more >
An Update to Working with GeoJSON in the Browser | HERE
A few weeks ago, I wrote a blog post about working with GeoJSON entirely within the browser (Working with GeoJSON in the Browser)....
Read more >
Update real-time data with Python API - Learn ArcGIS
Using ArcGIS API for Python, you can update a feed routine to show the latest data on ... The polygon features in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found