Skip to content

Commit 90314c3

Browse files
authored
Merge pull request #1053 from Conengmo/draggable-markers
Draggable markers
2 parents 0e6ca7d + 8a12765 commit 90314c3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

folium/map.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ class Marker(MacroElement):
221221
Display a text when hovering over the object.
222222
icon: Icon plugin
223223
the Icon plugin to use to render the marker.
224+
draggable: bool, default False
225+
Set to True to be able to drag the marker around the map.
224226
225227
Returns
226228
-------
@@ -239,17 +241,22 @@ class Marker(MacroElement):
239241
var {{this.get_name()}} = L.marker(
240242
[{{this.location[0]}}, {{this.location[1]}}],
241243
{
242-
icon: new L.Icon.Default()
244+
icon: new L.Icon.Default(),
245+
{%- if this.draggable %}
246+
draggable: true,
247+
autoPan: true,
248+
{%- endif %}
243249
}
244250
).addTo({{this._parent.get_name()}});
245251
{% endmacro %}
246252
""")
247253

248-
def __init__(self, location, popup=None, tooltip=None, icon=None):
254+
def __init__(self, location, popup=None, tooltip=None, icon=None,
255+
draggable=False):
249256
super(Marker, self).__init__()
250257
self._name = 'Marker'
251-
self.tooltip = tooltip
252258
self.location = _validate_coordinates(location)
259+
self.draggable = draggable
253260
if icon is not None:
254261
self.add_child(icon)
255262
if isinstance(popup, text_type) or isinstance(popup, binary_type):

tests/plugins/test_marker_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_marker_cluster():
4949
var {{marker.get_name()}} = L.marker(
5050
[{{marker.location[0]}},{{marker.location[1]}}],
5151
{
52-
icon: new L.Icon.Default()
52+
icon: new L.Icon.Default(),
5353
}
5454
)
5555
.addTo({{this.get_name()}});

0 commit comments

Comments
 (0)