Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
1. Clear up documentation
2. Add type annotions where missing
3. Cleanup template code to use parent namespace.
  • Loading branch information
hansthen committed Jan 27, 2024
1 parent 83238ba commit c533d11
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions folium/plugins/timestamped_geo_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
into a map with Map.add_child.
There are two main modes this plugin can run:
1. Event mode, in which features only have start times
2. Timeline mode, in which features have start and end times
1. Timestamp mode, in which features only have start times
2. Interval mode, in which features have start and end times
These modes require different layout of the GeoJson
Event mode
Timestamp mode
----------
For Event mode you need a GeoJson with the following conditions
For Timestamp mode you need a GeoJson with the following conditions
* it contains only features of types LineString, MultiPoint, MultiLineString,
Polygon and MultiPolygon.
Expand All @@ -33,15 +33,15 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
Eventually, you may have Point features with a 'times' property being an
array of length 1.
Timeline mode
Interval mode
-------------
For Timeline mode, you need a GeoJson with the following conditions.
For Interval mode, you need a GeoJson with the following conditions.
* Each feature contains a 'start' and 'end' property. The start and end
can be any comparable item.
Alternatively, you can trigger timeline mode by providing
Alternatively, you can trigger Interval mode by providing
a `get_interval` function.
* This function should be a JsCode object and take as parameter
Expand All @@ -65,7 +65,7 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
auto_play: bool, default True
Whether the animation shall start automatically at startup.
Event mode parameters
Timestamp mode parameters
------------------------
transition_time: int, default 200.
The duration in ms of a transition from between timestamps.
Expand All @@ -83,7 +83,7 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
Format: ISO8601 Duration
ex: 'P1M' 1/month, 'P1D' 1/day, 'PT1H' 1/hour, and 'PT1M' 1/minute
Timeline mode parameters
Interval mode parameters
-------------------
get_interval: JsCode
Called for each feature, and should return either a time range for the
Expand Down Expand Up @@ -114,7 +114,7 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
one displays in playback_duration/steps ms, so each frame really
takes frame processing time PLUS step time.
Example of Event mode
Example of Timestamp mode
--------
>>> TimestampedGeoJson(
... {
Expand All @@ -137,7 +137,7 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
See https://github.com/socib/Leaflet.TimeDimension for more information.
Example of Timeline mode
Example of Interval mode
--------
>>> data = requests.get(
Expand Down Expand Up @@ -199,26 +199,24 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
{% if this.type == "Timedimension" %}
L.Control.TimeDimensionCustom = L.Control.TimeDimension.extend({
_getDisplayDateFormat: {{ this._getDisplayDateFormat.js_code }}
_getDisplayDateFormat: {{ this._getDisplayDateFormat }}
});
{{this._parent.get_name()}}.timeDimension = L.timeDimension(
{
period: {{ this.period|tojson }},
}
);
var timeDimensionControl = new L.Control.TimeDimensionCustom(
{{ this.options|tojson }}
var {{this.get_name()}}_timeDimensionControl = new L.Control.TimeDimensionCustom(
{{ this.get_name() }}_options
);
{{this._parent.get_name()}}.addControl(this.timeDimensionControl);
{{this._parent.get_name()}}.addControl({{this.get_name()}}_timeDimensionControl);
var geoJsonLayer = L.geoJson({{this.data}}, {
pointToLayer: {{ this.get_name() }}_options.pointToLayer,
style: {{ this.get_name() }}_options.style,
onEachFeature: {{ this.get_name() }}_options.onEachFeature,
var {{this.get_name()}}_geoJsonLayer = L.geoJson({{this.data}},
{{ this.get_name() }}_options
})
var {{this.get_name()}} = L.timeDimension.layer.geoJson(
geoJsonLayer,
{{this.get_name()}}_geoJsonLayer,
{
updateTimeDimension: true,
addlastPoint: {{ this.add_last_point|tojson }},
Expand All @@ -232,15 +230,15 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
{{ this.data|tojson }},
{{ this.get_name() }}_options
);
var control = L.timelineSliderControl(
var {{ this.get_name() }}_control = L.timelineSliderControl(
{{ this.get_name() }}_options
);
control.addTo({{ this._parent.get_name() }});
{{ this.get_name() }}_control.addTo({{ this._parent.get_name() }});
{{ this._parent.get_name() }}.addControl(control);
{{ this.get_name() }}.addTo({{ this._parent.get_name() }});
control.addTimelines({{ this.get_name() }});
{{ this.get_name() }}_control.addTimelines({{ this.get_name() }});
{% endif %}
{% endmacro %}
Expand Down Expand Up @@ -313,35 +311,34 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
if(feature.properties.iconstyle) {
return new L.Marker(latLng, {
icon: L.icon(feature.properties.iconstyle)});
}
};
//else
return new L.Marker(latLng);
}
};
if (feature.properties.icon == 'circle') {
if (feature.properties.iconstyle) {
return new L.circleMarker(latLng,
feature.properties.iconstyle)
};
//else
return new L.circleMarker(latLng);
}
//else
return new L.Marker(latLng);
}
};
//else
return new L.Marker(latLng);
};
"""
)

def __init__(
self,
data: Union[dict, str, TextIO],
# arguments relevant to both
# arguments relevant to both interval and timestamp mode
auto_play: bool = True,
date_options: str = "YYYY-MM-DD HH:mm:ss",
point_to_layer: Optional[JsCode] = point_to_layer,
style: Optional[JsCode] = style,
on_each_feature: Optional[JsCode] = on_each_feature,
# arguments relevant to timeline
# arguments relevant to interval mode
get_interval: Optional[JsCode] = None,
start: Optional[Union[str, int, float]] = None,
end: Optional[Union[str, int, float]] = None,
Expand All @@ -350,17 +347,17 @@ def __init__(
show_ticks: bool = True,
steps: int = 1000,
playback_duration: int = 10000,
# arguments relevant to timedimension
# arguments relevant to timestamp mode
duration: Optional[str] = None,
add_last_point: bool = True,
transition_time=200,
loop=True,
period="P1D",
min_speed=0.1,
max_speed=10,
loop_button=False,
time_slider_drag_update=False,
speed_slider=True,
transition_time: int = 200,
loop: bool = True,
period: str = "P1D",
min_speed: float = 0.1,
max_speed: float = 10,
loop_button: bool = False,
time_slider_drag_update: bool = False,
speed_slider: bool = True,
**kwargs
):
super().__init__()
Expand Down

0 comments on commit c533d11

Please sign in to comment.