I am following some code examples to plot time aware coordinates on a folium map using the folium.plugins.TimestampedGeoJson method. As in the example, I'm using a for-loop to tie coordinates and timestamps in a list of GeoJson features. In other work I have formatted styling of GeoJson feature collections using lambda functions like so
collection = folium.GeoJson(
geoPandasDataframeObj,
marker=folium.Circle(radius=8, fill_color=None, fill_opacity=1, color=None, weight=1),
popup=folium.GeoJsonPopup(fields=["Field 1", "Field 2"]),
style_function=lambda x: {
"fillColor": colormap(x['properties']['Field 1']),
"color": colormap(x['properties']['Field 2']),
},
)
Is it possible to use a similar approach with TimestampedGeoJson to apply icon/marker styling using lambdas? The example code I'm using is here (Example Code):
import folium
from folium.plugins import TimestampedGeoJson
m = folium.Map(
location=[56.096555, -3.64746],
tiles="cartodbpositron",
zoom_start=5,
)
table = """\
<table style=\'width:100%\'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
"""
points = [
{
"time": "2017-06-02",
"popup": "<h1>address1</h1>",
"coordinates": [-2.548828, 51.467697],
},
{
"time": "2017-07-02",
"popup": "<h2 style='color:blue;'>address2<h2>",
"coordinates": [-0.087891, 51.536086],
},
{
"time": "2017-08-02",
"popup": "<h2 style='color:orange;'>address3<h2>",
"coordinates": [-6.240234, 53.383328],
},
{
"time": "2017-09-02",
"popup": "<h2 style='color:green;'>address4<h2>",
"coordinates": [-1.40625, 60.261617],
},
{
"time": "2017-10-02",
"popup": table,
"coordinates": [-1.516113, 53.800651]
},
]
times = ["2017-06-02", "2017-07-02", "2017-08-02", "2017-09-02", "2017-10-02"]
coords = [(-2.548828, 51.467697), (-0.087891, 51.536086), (-6.240234, 53.383328), (-1.40625, 60.261617), (-1.516113, 53.800651)]
colors = ['#e41a1c','#377eb8','#4daf4a','#984ea3','#ff7f00']
features = []
for point in range(0,len(times)):
features.append({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": coords[point],
},
"properties": {
"time": times[point],
"icon": "circle",
"iconstyle": {"color": colors[point], "fill": "true", "fillOpacity": 1.0, "radius": 5},
},
})
folium.plugins.TimestampedGeoJson(
{
"type": "FeatureCollection",
"features": features,
},
period="P7D",
add_last_point=True,
).add_to(m)
m.save('TimestampedGeoJsonPoint.html')