Comments (2)
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?
from folium.
@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.
from folium.
Related Issues (20)
- Add ability to add a dynamic text/title per frame when using TimestampedGeoJson HOT 2
- Folium maps not displayed with Safari in Iphones HOT 1
- GeoJson style is not being applied correctly HOT 2
- Keep original size of image in CustomIcon
- NumPy 2.0 support HOT 4
- AttributeError: module 'folium' has no attribute 'plugins' HOT 1
- Marker with same ID results into broken html HOT 1
- Make Folium follow the Leaflet class hierarchy more closely HOT 4
- Add example pattern for pulling JsCode snippets from external javascript files HOT 9
- Support function objects in Leaflet options. HOT 3
- HTML does not work when run on mobile. HOT 2
- Blue Lines when using TimestampedGeoJson in Folium HOT 2
- Docs not quite representative of the real "latest" version? HOT 8
- No popup when clicking on specific icons (BeautifyIcon plugin) HOT 3
- Geocoder plugin not working in Google Chrome HOT 2
- Making a tooltip stay when clicked on a marker/shape HOT 1
- Add Code of Conduct HOT 1
- Realtime Circles have non-changing radii. HOT 2
- Adding Multiple Clusters to map HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from folium.