-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add a custom container to the realtime plugin #1869
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
Merged
Conengmo
merged 7 commits into
python-visualization:main
from
hansthen:realtime_container
Mar 6, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
06ff73f
Add cluster override
hansthen e9bccae
Add tests
hansthen bf52bc9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9b80ae0
Add container argument to documentation
hansthen 9dcab34
Fix incorrect import
hansthen e89f1ce
Merge branch 'python-visualization:main' into realtime_container
hansthen 8466f4d
Update realtime.py
hansthen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
Test Realtime | ||
------------------ | ||
""" | ||
|
||
from jinja2 import Template | ||
|
||
import folium | ||
from folium.plugins import MarkerCluster, Realtime | ||
from folium.utilities import JsCode, normalize | ||
|
||
|
||
def test_realtime(): | ||
m = folium.Map(location=[40.73, -73.94], zoom_start=12) | ||
source = "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/subway_stations.geojson" | ||
|
||
container = MarkerCluster().add_to(m) | ||
|
||
rt = Realtime( | ||
source, | ||
get_feature_id=JsCode("(f) => { return f.properties.objectid }"), | ||
point_to_layer=JsCode( | ||
"(f, latlng) => { return L.circleMarker(latlng, {radius: 8, fillOpacity: 0.2})}" | ||
), | ||
container=container, | ||
interval=10000, | ||
) | ||
rt.add_to(m) | ||
|
||
tmpl_for_expected = Template( | ||
""" | ||
{% macro script(this, kwargs) %} | ||
var {{ this.get_name() }}_options = {{ this.options|tojson }}; | ||
{% for key, value in this.functions.items() %} | ||
{{ this.get_name() }}_options["{{key}}"] = {{ value }}; | ||
{% endfor %} | ||
|
||
{% if this.container -%} | ||
{{ this.get_name() }}_options["container"] | ||
= {{ this.container.get_name() }}; | ||
{% endif -%} | ||
|
||
var {{ this.get_name() }} = new L.realtime( | ||
{% if this.src is string or this.src is mapping -%} | ||
{{ this.src|tojson }}, | ||
{% else -%} | ||
{{ this.src.js_code }}, | ||
{% endif -%} | ||
{{ this.get_name() }}_options | ||
); | ||
{{ this._parent.get_name() }}.addLayer( | ||
{{ this.get_name() }}._container); | ||
{% endmacro %} | ||
""" | ||
) | ||
expected = normalize(tmpl_for_expected.render(this=rt)) | ||
|
||
out = normalize(m._parent.render()) | ||
|
||
# We verify that imports | ||
assert ( | ||
'<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-realtime/2.2.0/leaflet-realtime.js"></script>' # noqa | ||
in out | ||
) # noqa | ||
|
||
assert expected in out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.