Closed shyney7 closed 7 months ago
You need to add an id
property to the geojson's features (or use a JsCode object to generate an id). Perhaps your input csv contains a column that provides a unique key for each row?
@hansthen thank you! I've changed the create_geojson() function to this:
def create_geojson():
with open(r'./gpslive/gpstobfilt.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
# init an empty list to store GeoJSON features
features = []
# loop through each row in the CSV
for index, row in enumerate(reader):
# create a GeoJSON feature
feature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [float(row['longitude']), float(row['latitude'])]
},
"properties": {
"id": index,
"total_counts": float(row['total_counts']),
"altitude": float(row['altitude'])
}
}
# add the feature to the list
features.append(feature)
# write the features to a new GeoJSON file
with open(r'./gpslive/data.geojson', 'w') as geojsonfile:
json.dump({'type': 'FeatureCollection', 'features': features}, geojsonfile)
#wait for 1 second
time.sleep(1)
That fixed only the last point to be shown. And I also changed the Realtime class initiation to this:
Realtime(
source,
get_feature_id=JsCode("(f) => { return f.properties.id}"),
point_to_layer=JsCode("""
(f, latlng) => {
var color = 'red';
if (f.properties.total_counts < 5) {
color = 'green';
} else if (f.properties.total_counts < 10) {
color = 'yellow';
}
var marker = L.circleMarker(latlng, {radius: 8, fillOpacity: 0.2, color: color});
marker.bindPopup(
'ID: ' + f.properties.id + '<br>' +
'Total Counts: ' + f.properties.total_counts + '<br>' +
'Altitude: ' + f.properties.altitude
);
return marker;
}
"""),
interval=1000,
).add_to(m)
To be able to see the porperties data when I click on a Point.
Is your feature request related to a problem? Please describe. If I use the Realtime Plugin to show new datapoints as they are added to my geojson file, only the last point is shown.
This is the geojson file: https://gist.github.com/shyney7/ac65a2fbecf72dcd730387bc1b851ac0 New points are added at the end.
Describe the solution you'd like I would like to be able to show all datapoints included inside the geojson current ones and future ones not only the last one.
Additional context