Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marker keyword does not work for TimeLine class #2087

Closed
LeResch opened this issue Jan 24, 2025 · 2 comments
Closed

marker keyword does not work for TimeLine class #2087

LeResch opened this issue Jan 24, 2025 · 2 comments

Comments

@LeResch
Copy link

LeResch commented Jan 24, 2025

Describe the bug
I tried to change the marker of the features of a TimeLine object. The GeoJSON input data only contains Point geometries.
Since TimeLine should base on GeoJSON class, I tried using the marker keyword in the timeline. The python code runs without an error, but when I try to open the map in the browser I get the following error:

Uncaught ReferenceError: circle_edc1a78feb8824a28fc2c53a5e766edf is not defined
at folium_ywd748p8.html:102:13
So apparently the circle referenced by the timeline_options is not created.

To Reproduce

import geopandas as gpd
from datetime import datetime
import folium
from folium.plugins import Timeline, TimelineSlider

data = gpd.read_file("https://raw.githubusercontent.com/python-visualization/folium-example-data/main/subway_stations.geojson")
data["start"] = (datetime.strptime("01.01.2025", "%d.%m.%Y")).timestamp()*10e2
data["end"] = (datetime.strptime("01.01.2026", "%d.%m.%Y")).timestamp()*10e2
m = folium.Map()
timeline = Timeline(
    data=data,
    marker = folium.Circle(radius=3, color="black")
).add_to(m)
TimelineSlider(
    auto_play=False,
    show_ticks=True,
    enable_keyboard_controls=True,
    start = (datetime.strptime("01.01.2024", "%d.%m.%Y")).timestamp()*10e2
).add_timelines(timeline).add_to(m)

m.show_in_browser() 

Expected behavior
I would except that when the timeline class is based on the GeoJSON class, that I can change the marker for Point geometries with the marker keyword. The marker also needs to be created, when the map object is rendered to html.

Environment (please complete the following information):

  • Browser: MS Edge Version 131.0.2903.86
  • Python version: 3.9.7
  • folium version: 0.19.4
  • branca version: 0.8.1
@hansthen
Copy link
Collaborator

I see your point. Unfortunately, the current implementation of Timeline and GeoJson make it really hard to do this the exact way you want.

There is a workaround. You can customize the marker for the layer by customizing the Javascript point_to_layer function:

timeline = Timeline(
    data=data,
    point_to_layer=JsCode("(f, latlng) => { return L.circleMarker(latlng, {radius: 8, fillOpacity: 0.2})}")
).add_to(m)

Can you check if that works out for you?

@LeResch LeResch closed this as completed Jan 27, 2025
@LeResch
Copy link
Author

LeResch commented Jan 27, 2025

Okay, understood.
The workaround is working fine for me, thank you for providing that. I think in combination with the style_function there are hardly any or no restrictions, so I'll close this bug.

@LeResch LeResch closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants