Skip to content

Commit c7c9719

Browse files
authored
Merge branch 'main' into add_event_handlers_to_drawn_layers_in_draw_plugin
2 parents 0c7f152 + 806f697 commit c7c9719

File tree

11 files changed

+53
-23
lines changed

11 files changed

+53
-23
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
ref: main
2626

2727
- name: Setup Micromamba env
28-
uses: mamba-org/setup-micromamba@v1
28+
uses: mamba-org/setup-micromamba@v2
2929
with:
3030
environment-name: TEST
3131
create-args: >-

.github/workflows/pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
4747
- name: Publish a Python distribution to PyPI
4848
if: success() && github.event_name == 'release'
49-
uses: pypa/[email protected].2
49+
uses: pypa/[email protected].3
5050
with:
5151
user: __token__
5252
password: ${{ secrets.PYPI_PASSWORD }}

.github/workflows/test_code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions/checkout@v4
2828

2929
- name: Setup Micromamba env
30-
uses: mamba-org/setup-micromamba@v1
30+
uses: mamba-org/setup-micromamba@v2
3131
with:
3232
environment-name: TEST
3333
create-args: >-

.github/workflows/test_latest_branca.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515

1616
- name: Setup Micromamba env
17-
uses: mamba-org/setup-micromamba@v1
17+
uses: mamba-org/setup-micromamba@v2
1818
with:
1919
environment-name: TEST
2020
create-args: >-

.github/workflows/test_mypy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515

1616
- name: Setup Micromamba env
17-
uses: mamba-org/setup-micromamba@v1
17+
uses: mamba-org/setup-micromamba@v2
1818
with:
1919
environment-name: TEST
2020
create-args: >-

.github/workflows/test_selenium.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v4
1919

2020
- name: Setup Micromamba env
21-
uses: mamba-org/setup-micromamba@v1
21+
uses: mamba-org/setup-micromamba@v2
2222
with:
2323
environment-name: TEST
2424
create-args: >-

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exclude: examples/data/|.*\.css|.*\.json|.*\.geojson|.*\.html
22

33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.6.0
5+
rev: v5.0.0
66
hooks:
77
- id: trailing-whitespace
88
- id: check-ast
@@ -15,7 +15,7 @@ repos:
1515
files: requirements-dev.txt
1616

1717
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.6.3
18+
rev: v0.6.9
1919
hooks:
2020
- id: ruff
2121

folium/plugins/draw.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class Draw(JSCSSMixin, MacroElement):
1212
----------
1313
export : bool, default False
1414
Add a small button that exports the drawn shapes as a geojson file.
15+
feature_group : FeatureGroup, optional
16+
The FeatureGroup object that will hold the editable figures. This can
17+
be used to initialize the Draw plugin with predefined Layer objects.
1518
filename : string, default 'data.geojson'
1619
Name of geojson file
1720
position : {'topleft', 'toprigth', 'bottomleft', 'bottomright'}
@@ -63,10 +66,17 @@ class Draw(JSCSSMixin, MacroElement):
6366
draw: {{ this.draw_options|tojson }},
6467
edit: {{ this.edit_options|tojson }},
6568
}
66-
// FeatureGroup is to store editable layers.
67-
var drawnItems_{{ this.get_name() }} = new L.featureGroup().addTo(
68-
{{ this._parent.get_name() }}
69-
);
69+
{%- if this.feature_group %}
70+
var drawnItems_{{ this.get_name() }} =
71+
{{ this.feature_group.get_name() }};
72+
{%- else %}
73+
// FeatureGroup is to store editable layers.
74+
var drawnItems_{{ this.get_name() }} =
75+
new L.featureGroup().addTo(
76+
{{ this._parent.get_name() }}
77+
);
78+
{%- endif %}
79+
7080
options.edit.featureGroup = drawnItems_{{ this.get_name() }};
7181
var {{ this.get_name() }} = new L.Control.Draw(
7282
options
@@ -89,7 +99,11 @@ class Draw(JSCSSMixin, MacroElement):
8999
);
90100
{%- endfor %}
91101
drawnItems_{{ this.get_name() }}.addLayer(layer);
92-
});
102+
});
103+
{{ this._parent.get_name() }}.on('draw:created', function(e) {
104+
drawnItems_{{ this.get_name() }}.addLayer(e.layer);
105+
});
106+
93107
{% if this.export %}
94108
document.getElementById('export').onclick = function(e) {
95109
var data = drawnItems_{{ this.get_name() }}.toGeoJSON();
@@ -123,6 +137,7 @@ class Draw(JSCSSMixin, MacroElement):
123137
def __init__(
124138
self,
125139
export=False,
140+
feature_group=None,
126141
filename="data.geojson",
127142
position="topleft",
128143
show_geometry_on_click=True,
@@ -133,6 +148,7 @@ def __init__(
133148
super().__init__()
134149
self._name = "DrawControl"
135150
self.export = export
151+
self.feature_group = feature_group
136152
self.filename = filename
137153
self.position = position
138154
self.show_geometry_on_click = show_geometry_on_click

folium/plugins/heat_map_withtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class HeatMapWithTime(JSCSSMixin, Layer):
8686
speedStep: {{this.speed_step}},
8787
styleNS: "{{this.style_NS}}",
8888
timeSlider: {{this.time_slider}},
89-
timeSliderDrapUpdate: {{this.time_slider_drap_update}},
89+
timeSliderDragUpdate: {{this.time_slider_drag_update}},
9090
timeSteps: {{this.index_steps}}
9191
})
9292
.addTo({{this._parent.get_name()}});
@@ -199,7 +199,7 @@ def __init__(
199199
self.time_slider = "true"
200200
self.play_button = "true"
201201
self.play_reverse_button = "true"
202-
self.time_slider_drap_update = "false"
202+
self.time_slider_drag_update = "false"
203203
self.style_NS = "leaflet-control-timecontrol"
204204

205205
def render(self, **kwargs):

folium/plugins/time_slider_choropleth.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
1919
styledict: dict
2020
A dictionary where the keys are the geojson feature ids and the values are
2121
dicts of `{time: style_options_dict}`
22+
date_options: str, default "ddd MMM DD YYYY"
23+
A format string to render the currently active time in the control.
2224
highlight: bool, default False
2325
Whether to show a visual effect on mouse hover and click.
2426
name : string, default None
@@ -44,6 +46,11 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
4446
let styledict = {{ this.styledict|tojson }};
4547
let current_timestamp = timestamps[{{ this.init_timestamp }}];
4648
49+
function formatDate(date) {
50+
var newdate = new moment(date);
51+
return newdate.format({{this.date_format|tojson}});
52+
}
53+
4754
let slider_body = d3.select("body").insert("div", "div.folium-map")
4855
.attr("id", "slider_{{ this.get_name() }}");
4956
$("#slider_{{ this.get_name() }}").hide();
@@ -64,7 +71,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
6471
.attr("step", "1")
6572
.style('align', 'center');
6673
67-
let datestring = new Date(parseInt(current_timestamp)*1000).toDateString();
74+
let datestring = formatDate(parseInt(current_timestamp)*1000);
6875
d3.select("#slider_{{ this.get_name() }} > output").text(datestring);
6976
7077
let fill_map = function(){
@@ -84,7 +91,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
8491
8592
d3.select("#slider_{{ this.get_name() }} > input").on("input", function() {
8693
current_timestamp = timestamps[this.value];
87-
var datestring = new Date(parseInt(current_timestamp)*1000).toDateString();
94+
let datestring = formatDate(parseInt(current_timestamp)*1000);
8895
d3.select("#slider_{{ this.get_name() }} > output").text(datestring);
8996
fill_map();
9097
});
@@ -155,12 +162,19 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
155162
"""
156163
)
157164

158-
default_js = [("d3v4", "https://d3js.org/d3.v4.min.js")]
165+
default_js = [
166+
("d3v4", "https://d3js.org/d3.v4.min.js"),
167+
(
168+
"moment",
169+
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js",
170+
),
171+
]
159172

160173
def __init__(
161174
self,
162175
data,
163176
styledict,
177+
date_options: str = "ddd MMM DD YYYY",
164178
highlight: bool = False,
165179
name=None,
166180
overlay=True,
@@ -173,21 +187,21 @@ def __init__(
173187
):
174188
super().__init__(name=name, overlay=overlay, control=control, show=show)
175189
self.data = GeoJson.process_data(GeoJson({}), data)
190+
self.date_format = date_options
176191
self.highlight = highlight
177192

178193
self.stroke_opacity = stroke_opacity
179194
self.stroke_width = stroke_width
180195
self.stroke_color = stroke_color
181196

182197
if not isinstance(styledict, dict):
183-
raise ValueError(
184-
f"styledict must be a dictionary, got {styledict!r}"
185-
) # noqa
198+
raise ValueError(f"styledict must be a dictionary, got {styledict!r}")
199+
186200
for val in styledict.values():
187201
if not isinstance(val, dict):
188202
raise ValueError(
189203
f"Each item in styledict must be a dictionary, got {val!r}"
190-
) # noqa
204+
)
191205

192206
# Make set of timestamps.
193207
timestamps_set = set()

0 commit comments

Comments
 (0)