Skip to content

Commit 801d91c

Browse files
birdageocefpaf
authored andcommitted
added a cluster marker group, and simple markers can be added to the cluster group through the clustered_marker bool on generation
1 parent e76af1f commit 801d91c

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

folium/folium.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self, location=None, width=960, height=500,
176176
self.tile_types.update({'Custom': {'template': tiles, 'attr': attr}})
177177

178178
@iter_obj('simple')
179-
def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_color='blue',marker_icon='info-sign'):
179+
def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_color='blue',marker_icon='info-sign',clustered_marker=False):
180180
'''Create a simple stock Leaflet marker on the map, with optional
181181
popup text or Vincent visualization.
182182
@@ -193,6 +193,8 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_co
193193
color of marker you want
194194
marker_icon
195195
icon from (http://getbootstrap.com/components/) you want on the marker
196+
clustered_marker
197+
boolean of whether or not you want the marker clustered with other markers
196198
197199
Returns
198200
-------
@@ -228,9 +230,17 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_co
228230
count=count,
229231
popup_on=popup_on)
230232

231-
add_mark = 'map.addLayer(marker_{0})'.format(count)
233+
232234

233-
self.template_vars.setdefault('custom_markers', []).append((icon,
235+
if clustered_marker:
236+
add_mark = 'clusteredmarkers.addLayer(marker_{0})'.format(count)
237+
self.template_vars.setdefault('cluster_markers', []).append((icon,
238+
marker,
239+
popup_out,
240+
add_mark))
241+
else:
242+
add_mark = 'map.addLayer(marker_{0})'.format(count)
243+
self.template_vars.setdefault('custom_markers', []).append((icon,
234244
marker,
235245
popup_out,
236246
add_mark))

folium/templates/cluster_marker.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

folium/templates/fol_template.html

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@
6262
attribution: '{{ attr }}'
6363
}).addTo(map);
6464

65-
var markers = L.markerClusterGroup();
66-
67-
for (var i = 0; i < 5; i++) {
68-
var title = "test";
69-
var markerTest = L.marker(new L.LatLng(40+i, -68+i), { title: title });
70-
markerTest.bindPopup(title);
71-
markers.addLayer(markerTest);
72-
}
73-
74-
map.addLayer(markers);
65+
//cluster group
66+
var clusteredmarkers = L.markerClusterGroup();
67+
//section for adding clustered markers
68+
{% for icon, mark, popup, add_mark in cluster_markers %}
69+
{{ icon }}
70+
{{ mark }}
71+
{{ popup }}
72+
{{ add_mark }}
73+
{% endfor %}
74+
//add the clustered markers to the group anyway
75+
map.addLayer(clusteredmarkers);
7576

7677
{% for icon, mark, popup, add_mark in custom_markers %}
7778
{{ icon }}

0 commit comments

Comments
 (0)