0
# Plugins
1
2
Extensive plugin ecosystem providing specialized functionality including clustering, heatmaps, drawing tools, temporal visualizations, advanced controls, and interactive features. All plugins extend the base folium functionality with additional Leaflet.js plugins.
3
4
## Capabilities
5
6
### Marker Clustering and Management
7
8
Plugins for efficiently handling large numbers of markers and managing marker overlaps.
9
10
```python { .api }
11
class MarkerCluster:
12
"""
13
Group nearby markers into clusters for better performance and visualization.
14
15
Parameters:
16
- locations: list, marker coordinates (optional, can add markers individually)
17
- popups: list, popup content for each marker (optional)
18
- tooltips: list, tooltip content for each marker (optional)
19
- icons: list, custom icons for each marker (optional)
20
- name: str, layer name for layer control
21
- overlay: bool, treat as overlay layer (default True)
22
- control: bool, show in layer control (default True)
23
- show: bool, show layer initially (default True)
24
- icon_create_function: str, JavaScript function for custom cluster icons
25
- options: dict, additional clustering options
26
27
Returns:
28
MarkerCluster instance
29
"""
30
def __init__(
31
self,
32
locations=None,
33
popups=None,
34
tooltips=None,
35
icons=None,
36
name=None,
37
overlay=True,
38
control=True,
39
show=True,
40
icon_create_function=None,
41
options=None
42
): ...
43
44
class FastMarkerCluster:
45
"""
46
High-performance clustering for very large marker datasets.
47
48
Parameters:
49
- data: list, marker data with coordinates and properties
50
- name: str, layer name for layer control
51
- callback: str, JavaScript callback function for marker creation
52
- options: dict, clustering configuration options
53
54
Returns:
55
FastMarkerCluster instance
56
"""
57
def __init__(
58
self,
59
data,
60
name=None,
61
callback=None,
62
options=None
63
): ...
64
65
class OverlappingMarkerSpiderfier:
66
"""
67
Separate overlapping markers in a spider/fan pattern when clicked.
68
69
Parameters:
70
- name: str, layer name
71
- overlay: bool, treat as overlay (default True)
72
- control: bool, show in layer control (default True)
73
- show: bool, show initially (default True)
74
75
Returns:
76
OverlappingMarkerSpiderfier instance
77
"""
78
def __init__(
79
self,
80
name=None,
81
overlay=True,
82
control=True,
83
show=True
84
): ...
85
```
86
87
### Heatmaps and Density Visualization
88
89
Plugins for visualizing point density and temporal patterns.
90
91
```python { .api }
92
class HeatMap:
93
"""
94
Create density heatmaps from point data.
95
96
Parameters:
97
- data: list, point data [[lat, lon, intensity], ...] or [[lat, lon], ...]
98
- name: str, layer name for layer control
99
- min_opacity: float, minimum opacity (default 0.4)
100
- max_zoom: int, maximum zoom level (default 18)
101
- max_val: float, maximum data value for scaling (default 1.0)
102
- radius: int, heat radius in pixels (default 25)
103
- blur: int, blur amount (default 15)
104
- gradient: dict, color gradient mapping {value: 'color'}
105
- overlay: bool, treat as overlay layer (default True)
106
- control: bool, show in layer control (default True)
107
- show: bool, show layer initially (default True)
108
109
Returns:
110
HeatMap instance
111
"""
112
def __init__(
113
self,
114
data,
115
name=None,
116
min_opacity=0.4,
117
max_zoom=18,
118
max_val=1.0,
119
radius=25,
120
blur=15,
121
gradient=None,
122
overlay=True,
123
control=True,
124
show=True
125
): ...
126
127
class HeatMapWithTime:
128
"""
129
Create animated heatmaps showing temporal patterns.
130
131
Parameters:
132
- data: list, time-series data with timestamps
133
- name: str, layer name
134
- index: list, time index labels
135
- auto_play: bool, start animation automatically (default False)
136
- display_index: bool, show time index (default True)
137
- overlay: bool, treat as overlay (default True)
138
- control: bool, show in layer control (default True)
139
- show: bool, show initially (default True)
140
141
Returns:
142
HeatMapWithTime instance
143
"""
144
def __init__(
145
self,
146
data,
147
name=None,
148
index=None,
149
auto_play=False,
150
display_index=True,
151
overlay=True,
152
control=True,
153
show=True,
154
**kwargs
155
): ...
156
```
157
158
### Drawing and Editing Tools
159
160
Interactive tools for creating and editing geometries directly on the map.
161
162
```python { .api }
163
class Draw:
164
"""
165
Interactive drawing tools for creating and editing geometries.
166
167
Parameters:
168
- export: bool, enable GeoJSON export (default False)
169
- filename: str, export filename (default 'data.geojson')
170
- position: str, control position (default 'topleft')
171
- draw_options: dict, drawing tool options
172
- edit_options: dict, editing tool options
173
174
Returns:
175
Draw instance
176
"""
177
def __init__(
178
self,
179
export=False,
180
filename='data.geojson',
181
position='topleft',
182
draw_options=None,
183
edit_options=None
184
): ...
185
186
class GeoMan:
187
"""
188
Advanced geometry management and editing tools.
189
190
Parameters:
191
- position: str, control position (default 'topleft')
192
- draw_circle_marker: bool, enable circle marker drawing (default True)
193
- draw_polyline: bool, enable polyline drawing (default True)
194
- draw_rectangle: bool, enable rectangle drawing (default True)
195
- draw_polygon: bool, enable polygon drawing (default True)
196
- draw_circle: bool, enable circle drawing (default True)
197
- draw_marker: bool, enable marker drawing (default True)
198
- edit_mode: bool, enable editing mode (default True)
199
- drag_mode: bool, enable drag mode (default True)
200
- cut_polygon: bool, enable polygon cutting (default True)
201
- removal_mode: bool, enable removal mode (default True)
202
203
Returns:
204
GeoMan instance
205
"""
206
def __init__(
207
self,
208
position='topleft',
209
draw_circle_marker=True,
210
draw_polyline=True,
211
draw_rectangle=True,
212
draw_polygon=True,
213
draw_circle=True,
214
draw_marker=True,
215
edit_mode=True,
216
drag_mode=True,
217
cut_polygon=True,
218
removal_mode=True
219
): ...
220
221
class MeasureControl:
222
"""
223
Tool for measuring distances and areas on the map.
224
225
Parameters:
226
- position: str, control position (default 'topright')
227
- primary_length_unit: str, primary length unit ('feet', 'meters', 'miles', 'kilometers')
228
- secondary_length_unit: str, secondary length unit
229
- primary_area_unit: str, primary area unit ('sqfeet', 'sqmeters', 'sqmiles', 'hectares', 'acres', 'sqkilometers')
230
- secondary_area_unit: str, secondary area unit
231
- active_color: str, active measurement color (default '#ABE67E')
232
- completed_color: str, completed measurement color (default '#C8F2BE')
233
234
Returns:
235
MeasureControl instance
236
"""
237
def __init__(
238
self,
239
position='topright',
240
primary_length_unit='meters',
241
secondary_length_unit=None,
242
primary_area_unit='sqmeters',
243
secondary_area_unit=None,
244
active_color='#ABE67E',
245
completed_color='#C8F2BE'
246
): ...
247
```
248
249
### Advanced Layer Controls
250
251
Enhanced layer management with grouping and tree structures.
252
253
```python { .api }
254
class GroupedLayerControl:
255
"""
256
Layer control with hierarchical grouping of layers.
257
258
Parameters:
259
- groups: dict, layer groups with names and layers
260
- position: str, control position (default 'topright')
261
- collapsed: bool, collapse control initially (default True)
262
- exclusive_groups: list, groups where only one layer can be active
263
264
Returns:
265
GroupedLayerControl instance
266
"""
267
def __init__(
268
self,
269
groups=None,
270
position='topright',
271
collapsed=True,
272
exclusive_groups=None
273
): ...
274
275
class TreeLayerControl:
276
"""
277
Tree-structured layer management interface.
278
279
Parameters:
280
- base_tree: dict, base layer hierarchy
281
- overlay_tree: dict, overlay layer hierarchy
282
- position: str, control position (default 'topright')
283
- closed_symbol: str, symbol for closed nodes (default '+')
284
- open_symbol: str, symbol for open nodes (default '-')
285
- space_symbol: str, spacing symbol (default ' ')
286
- selector_back: bool, enable selector background (default False)
287
- selection_weight: int, selection highlight weight (default 1)
288
- collapsed: bool, collapse initially (default True)
289
290
Returns:
291
TreeLayerControl instance
292
"""
293
def __init__(
294
self,
295
base_tree=None,
296
overlay_tree=None,
297
position='topright',
298
closed_symbol='+',
299
open_symbol='-',
300
space_symbol=' ',
301
selector_back=False,
302
selection_weight=1,
303
collapsed=True
304
): ...
305
306
class FeatureGroupSubGroup:
307
"""
308
Create nested feature groups for advanced layer organization.
309
310
Parameters:
311
- group: FeatureGroup, parent feature group
312
- name: str, subgroup name
313
- overlay: bool, treat as overlay (default True)
314
- control: bool, show in layer control (default True)
315
- show: bool, show initially (default True)
316
317
Returns:
318
FeatureGroupSubGroup instance
319
"""
320
def __init__(
321
self,
322
group,
323
name=None,
324
overlay=True,
325
control=True,
326
show=True
327
): ...
328
```
329
330
### Navigation and UI Enhancement
331
332
Plugins that enhance map navigation and user interface.
333
334
```python { .api }
335
class Fullscreen:
336
"""
337
Add fullscreen toggle functionality to the map.
338
339
Parameters:
340
- position: str, control position (default 'topleft')
341
- title: str, button title text (default 'Full Screen')
342
- title_cancel: str, cancel button title (default 'Exit Full Screen')
343
- force_separate_button: bool, force separate button (default False)
344
345
Returns:
346
Fullscreen instance
347
"""
348
def __init__(
349
self,
350
position='topleft',
351
title='Full Screen',
352
title_cancel='Exit Full Screen',
353
force_separate_button=False
354
): ...
355
356
class MiniMap:
357
"""
358
Add an overview minimap widget to the main map.
359
360
Parameters:
361
- tile_layer: TileLayer, tile layer for minimap (defaults to main map tiles)
362
- position: str, minimap position (default 'bottomright')
363
- width: int, minimap width in pixels (default 150)
364
- height: int, minimap height in pixels (default 150)
365
- collapsed_width: int, collapsed width (default 19)
366
- collapsed_height: int, collapsed height (default 19)
367
- zoom_level_offset: int, zoom offset relative to main map (default -5)
368
- zoom_animation: bool, enable zoom animation (default False)
369
- toggle_display: bool, allow minimap toggle (default False)
370
- auto_toggle_display: bool, auto-toggle based on main map zoom (default False)
371
- minimized: bool, start minimized (default False)
372
373
Returns:
374
MiniMap instance
375
"""
376
def __init__(
377
self,
378
tile_layer=None,
379
position='bottomright',
380
width=150,
381
height=150,
382
collapsed_width=19,
383
collapsed_height=19,
384
zoom_level_offset=-5,
385
zoom_animation=False,
386
toggle_display=False,
387
auto_toggle_display=False,
388
minimized=False
389
): ...
390
391
class MousePosition:
392
"""
393
Display current mouse cursor coordinates on the map.
394
395
Parameters:
396
- position: str, control position (default 'bottomright')
397
- separator: str, coordinate separator (default ' | ')
398
- empty_string: str, text when outside map bounds (default 'Unavailable')
399
- lng_first: bool, show longitude first (default False)
400
- num_digits: int, decimal places for coordinates (default 5)
401
- prefix: str, prefix text
402
- lat_formatter: callable, custom latitude formatter
403
- lng_formatter: callable, custom longitude formatter
404
405
Returns:
406
MousePosition instance
407
"""
408
def __init__(
409
self,
410
position='bottomright',
411
separator=' | ',
412
empty_string='Unavailable',
413
lng_first=False,
414
num_digits=5,
415
prefix='',
416
lat_formatter=None,
417
lng_formatter=None
418
): ...
419
420
class LocateControl:
421
"""
422
Add user location finding control to the map.
423
424
Parameters:
425
- position: str, control position (default 'topleft')
426
- auto_start: bool, start location tracking automatically (default False)
427
- set_view: bool or str, set map view to user location (default 'untilPanOrZoom')
428
- keep_current_zoom_level: bool, maintain current zoom when locating (default True)
429
- strings: dict, localized text strings
430
- locateOptions: dict, location options (accuracy, timeout, etc.)
431
432
Returns:
433
LocateControl instance
434
"""
435
def __init__(
436
self,
437
position='topleft',
438
auto_start=False,
439
set_view='untilPanOrZoom',
440
keep_current_zoom_level=True,
441
strings=None,
442
locateOptions=None
443
): ...
444
445
class ScrollZoomToggler:
446
"""
447
Toggle scroll wheel zoom functionality.
448
449
Parameters:
450
- position: str, control position (default 'topright')
451
452
Returns:
453
ScrollZoomToggler instance
454
"""
455
def __init__(self, position='topright'): ...
456
```
457
458
### Temporal and Animation Plugins
459
460
Plugins for time-based data visualization and animation.
461
462
```python { .api }
463
class TimestampedGeoJson:
464
"""
465
Display animated GeoJSON features over time.
466
467
Parameters:
468
- data: dict, GeoJSON FeatureCollection with time properties
469
- period: str, time period format ('P1D' for daily, 'P1M' for monthly, etc.)
470
- add_last_point: bool, keep last point visible (default True)
471
- auto_play: bool, start animation automatically (default False)
472
- loop: bool, loop animation (default True)
473
- max_speed: int, maximum animation speed (default 10)
474
- loop_button: bool, show loop toggle button (default False)
475
- date_options: dict, date formatting options
476
- time_slider_drag_update: bool, update during drag (default False)
477
- duration: str, feature duration on map
478
479
Returns:
480
TimestampedGeoJson instance
481
"""
482
def __init__(
483
self,
484
data,
485
period='P1D',
486
add_last_point=True,
487
auto_play=False,
488
loop=True,
489
max_speed=10,
490
loop_button=False,
491
date_options=None,
492
time_slider_drag_update=False,
493
duration=None,
494
**kwargs
495
): ...
496
497
class TimeSliderChoropleth:
498
"""
499
Create animated choropleth maps with time slider control.
500
501
Parameters:
502
- data: DataFrame, time-series data for choropleth
503
- styledict: dict, styling configuration for time periods
504
- name: str, layer name
505
- overlay: bool, treat as overlay (default False)
506
- control: bool, show in layer control (default True)
507
- show: bool, show initially (default True)
508
509
Returns:
510
TimeSliderChoropleth instance
511
"""
512
def __init__(
513
self,
514
data,
515
styledict=None,
516
name=None,
517
overlay=False,
518
control=True,
519
show=True
520
): ...
521
522
class Timeline:
523
"""
524
Create timeline visualization for temporal events.
525
526
Parameters:
527
- data: dict, timeline data with events and timestamps
528
- name: str, layer name
529
- overlay: bool, treat as overlay (default True)
530
- control: bool, show in layer control (default True)
531
- show: bool, show initially (default True)
532
533
Returns:
534
Timeline instance
535
"""
536
def __init__(
537
self,
538
data,
539
name=None,
540
overlay=True,
541
control=True,
542
show=True
543
): ...
544
545
class TimelineSlider:
546
"""
547
Create slider control for timeline navigation.
548
549
Parameters:
550
- data: dict, timeline data
551
- start: int, start position (default 0)
552
- end: int, end position
553
- step: int, step size (default 1)
554
- position: str, control position (default 'bottomleft')
555
556
Returns:
557
TimelineSlider instance
558
"""
559
def __init__(
560
self,
561
data,
562
start=0,
563
end=None,
564
step=1,
565
position='bottomleft'
566
): ...
567
568
class TimestampedWmsTileLayers:
569
"""
570
Creates time-enabled WMS tile layers with temporal controls.
571
572
Adds time dimension support to WMS tile layers using the Leaflet.TimeDimension plugin,
573
enabling temporal data visualization and animation controls.
574
575
Parameters:
576
- data: WmsTileLayer or list of WmsTileLayer, WMS layers to add time support to
577
- transition_time: int, duration in ms of transition between timestamps (default 200)
578
- loop: bool, whether animation loops (default False)
579
- auto_play: bool, whether animation starts automatically (default False)
580
- period: str, ISO8601 duration for time intervals (default 'P1D')
581
- time_interval: bool, time interval settings (default False)
582
583
Returns:
584
TimestampedWmsTileLayers instance
585
"""
586
def __init__(
587
self,
588
data,
589
transition_time=200,
590
loop=False,
591
auto_play=False,
592
period='P1D',
593
time_interval=False
594
): ...
595
596
class Realtime:
597
"""
598
Real-time data updates and streaming visualization.
599
600
Parameters:
601
- source: str or callable, data source URL or function
602
- start: bool, start updates immediately (default True)
603
- interval: int, update interval in milliseconds (default 60000)
604
- get_feature_id: callable, function to get feature ID
605
- update_feature: callable, function to update features
606
- remove_missing: bool, remove missing features (default False)
607
- container: dict, GeoJSON container for features
608
609
Returns:
610
Realtime instance
611
"""
612
def __init__(
613
self,
614
source,
615
start=True,
616
interval=60000,
617
get_feature_id=None,
618
update_feature=None,
619
remove_missing=False,
620
container=None
621
): ...
622
```
623
624
### Search and Geocoding
625
626
Plugins for searching map features and location geocoding.
627
628
```python { .api }
629
class Search:
630
"""
631
Add search functionality for map features.
632
633
Parameters:
634
- layer: Layer, layer to search within
635
- search: list or str, searchable properties or search function
636
- position: str, control position (default 'topleft')
637
- placeholder: str, search input placeholder text
638
- collapsed: bool, start collapsed (default True)
639
- search_label: str, search field label
640
- search_zoom: int, zoom level for search results
641
- move_to_location: bool, move map to search result (default True)
642
643
Returns:
644
Search instance
645
"""
646
def __init__(
647
self,
648
layer=None,
649
search=None,
650
position='topleft',
651
placeholder='Search...',
652
collapsed=True,
653
search_label='Search',
654
search_zoom=None,
655
move_to_location=True,
656
**kwargs
657
): ...
658
659
class Geocoder:
660
"""
661
Add geocoding search control for address lookup.
662
663
Parameters:
664
- position: str, control position (default 'topleft')
665
- add_marker: bool, add marker for geocoded location (default True)
666
- collapsed: bool, start collapsed (default False)
667
- placeholder: str, search placeholder text
668
669
Returns:
670
Geocoder instance
671
"""
672
def __init__(
673
self,
674
position='topleft',
675
add_marker=True,
676
collapsed=False,
677
placeholder='Search for a location...'
678
): ...
679
```
680
681
### Specialized Markers and Patterns
682
683
Custom marker types and pattern fills for advanced visualization.
684
685
```python { .api }
686
class BeautifyIcon:
687
"""
688
Create enhanced marker icons with custom styling and effects.
689
690
Parameters:
691
- icon: str, icon name (FontAwesome)
692
- icon_shape: str, icon shape ('marker', 'circle-dot', 'rectangle', etc.)
693
- border_width: int, border width (default 3)
694
- border_color: str, border color (default '#1EB300')
695
- text_color: str, text/icon color (default 'white')
696
- background_color: str, background color (default '#1EB300')
697
- inner_icon_style: str, additional CSS for inner icon
698
699
Returns:
700
BeautifyIcon instance
701
"""
702
def __init__(
703
self,
704
icon=None,
705
icon_shape='marker',
706
border_width=3,
707
border_color='#1EB300',
708
text_color='white',
709
background_color='#1EB300',
710
inner_icon_style=''
711
): ...
712
713
class BoatMarker:
714
"""
715
Create directional boat-shaped markers for tracking moving objects.
716
717
Parameters:
718
- location: tuple, marker coordinates [lat, lon]
719
- heading: float, direction heading in degrees
720
- wind_heading: int, wind direction in degrees (default 0)
721
- wind_speed: int, wind speed (default 0)
722
- color: str, marker color (default '#d4442e')
723
724
Returns:
725
BoatMarker instance
726
"""
727
def __init__(
728
self,
729
location,
730
heading=0,
731
wind_heading=0,
732
wind_speed=0,
733
color='#d4442e'
734
): ...
735
736
class SemiCircle:
737
"""
738
Create semi-circular markers for directional data visualization.
739
740
Parameters:
741
- location: tuple, center coordinates [lat, lon]
742
- radius: float, radius in meters
743
- direction: float, direction in degrees (0 = North)
744
- arc: float, arc angle in degrees (default 180)
745
- popup: str or Popup, popup content
746
- tooltip: str or Tooltip, tooltip content
747
- color: str, border color
748
- weight: int, border width
749
- fill_color: str, fill color
750
- fill_opacity: float, fill opacity
751
752
Returns:
753
SemiCircle instance
754
"""
755
def __init__(
756
self,
757
location,
758
radius=10,
759
direction=0,
760
arc=180,
761
popup=None,
762
tooltip=None,
763
**kwargs
764
): ...
765
766
class CirclePattern:
767
"""
768
Create circular pattern fills for polygons.
769
770
Parameters:
771
- color: str, pattern color (default 'black')
772
- weight: int, pattern line weight (default 1)
773
- radius: int, circle radius (default 20)
774
- fill_opacity: float, pattern opacity (default 1.0)
775
- opacity: float, pattern line opacity (default 1.0)
776
777
Returns:
778
CirclePattern instance
779
"""
780
def __init__(
781
self,
782
color='black',
783
weight=1,
784
radius=20,
785
fill_opacity=1.0,
786
opacity=1.0
787
): ...
788
789
class StripePattern:
790
"""
791
Create stripe pattern fills for polygons.
792
793
Parameters:
794
- color: str, stripe color (default 'black')
795
- weight: int, stripe width (default 4)
796
- space: int, space between stripes (default 4)
797
- opacity: float, stripe opacity (default 1.0)
798
- angle: int, stripe angle in degrees (default 45)
799
800
Returns:
801
StripePattern instance
802
"""
803
def __init__(
804
self,
805
color='black',
806
weight=4,
807
space=4,
808
opacity=1.0,
809
angle=45
810
): ...
811
```
812
813
### Visualization Effects and Animation
814
815
Special effects and animated elements for enhanced visualization.
816
817
```python { .api }
818
class AntPath:
819
"""
820
Create animated dashed lines with marching ants effect.
821
822
Parameters:
823
- locations: list, path coordinates
824
- color: str, path color (default 'blue')
825
- weight: int, path width (default 3)
826
- opacity: float, path opacity (default 0.6)
827
- dash_array: list, dash pattern [dash_length, gap_length]
828
- delay: int, animation delay in milliseconds (default 400)
829
- pulse_color: str, pulse highlight color
830
- paused: bool, start animation paused (default False)
831
- reverse: bool, reverse animation direction (default False)
832
- hardware_acceleration: bool, use hardware acceleration (default False)
833
834
Returns:
835
AntPath instance
836
"""
837
def __init__(
838
self,
839
locations,
840
color='blue',
841
weight=3,
842
opacity=0.6,
843
dash_array=None,
844
delay=400,
845
pulse_color=None,
846
paused=False,
847
reverse=False,
848
hardware_acceleration=False,
849
**kwargs
850
): ...
851
852
class FloatImage:
853
"""
854
Create floating image overlays on the map.
855
856
Parameters:
857
- image: str, image URL or base64 data
858
- bounds: list, image bounds [[south, west], [north, east]]
859
- opacity: float, image opacity (default 1.0)
860
- alt: str, alt text for image
861
- origin: str, coordinate origin ('upper' or 'lower')
862
863
Returns:
864
FloatImage instance
865
"""
866
def __init__(
867
self,
868
image,
869
bounds,
870
opacity=1.0,
871
alt='',
872
origin='upper'
873
): ...
874
875
class Terminator:
876
"""
877
Display day/night terminator line on the map.
878
879
Parameters:
880
- time: datetime, time for terminator calculation (default: current time)
881
- resolution: float, line resolution in degrees (default 2.0)
882
- color: str, terminator line color (default '#CC0000')
883
- opacity: float, line opacity (default 0.5)
884
- weight: int, line width (default 2)
885
- fill_color: str, night side fill color (default '#000055')
886
- fill_opacity: float, night side opacity (default 0.2)
887
888
Returns:
889
Terminator instance
890
"""
891
def __init__(
892
self,
893
time=None,
894
resolution=2.0,
895
color='#CC0000',
896
opacity=0.5,
897
weight=2,
898
fill_color='#000055',
899
fill_opacity=0.2
900
): ...
901
```
902
903
### Advanced Data Handling
904
905
Plugins for specialized data formats and high-performance rendering.
906
907
```python { .api }
908
class PolygonFromEncoded:
909
"""
910
Create polygons from encoded polyline strings.
911
912
Parameters:
913
- encoded: str, encoded polyline string
914
- popup: str or Popup, popup content
915
- tooltip: str or Tooltip, tooltip content
916
- color: str, polygon border color
917
- weight: int, border width
918
- fill_color: str, fill color
919
- fill_opacity: float, fill opacity
920
921
Returns:
922
PolygonFromEncoded instance
923
"""
924
def __init__(
925
self,
926
encoded,
927
popup=None,
928
tooltip=None,
929
**kwargs
930
): ...
931
932
class PolyLineFromEncoded:
933
"""
934
Create polylines from encoded polyline strings (Google Polyline format).
935
936
Parameters:
937
- encoded: str, encoded polyline string
938
- popup: str or Popup, popup content
939
- tooltip: str or Tooltip, tooltip content
940
- color: str, line color
941
- weight: int, line width
942
- opacity: float, line opacity
943
944
Returns:
945
PolyLineFromEncoded instance
946
"""
947
def __init__(
948
self,
949
encoded,
950
popup=None,
951
tooltip=None,
952
**kwargs
953
): ...
954
955
class VectorGridProtobuf:
956
"""
957
High-performance vector tile rendering using Protobuf format.
958
959
Parameters:
960
- url: str, vector tile server URL template
961
- name: str, layer name
962
- options: dict, vector tile options
963
- vector_tile_layer_styles: dict, styling for vector tile layers
964
965
Returns:
966
VectorGridProtobuf instance
967
"""
968
def __init__(
969
self,
970
url,
971
name=None,
972
options=None,
973
vector_tile_layer_styles=None
974
): ...
975
```
976
977
### Specialized Tools
978
979
Additional utility plugins for specific use cases.
980
981
```python { .api }
982
class PolyLineTextPath:
983
"""
984
Add text labels that follow polyline paths.
985
986
Parameters:
987
- polyline: PolyLine, polyline to add text to
988
- text: str, text content
989
- repeat: bool, repeat text along path (default False)
990
- center: bool, center text on path (default False)
991
- below: bool, place text below path (default False)
992
- offset: int, text offset from path (default 0)
993
- orientation: str, text orientation ('flip' or 'perpendicular')
994
- attributes: dict, additional text attributes
995
996
Returns:
997
PolyLineTextPath instance
998
"""
999
def __init__(
1000
self,
1001
polyline,
1002
text,
1003
repeat=False,
1004
center=False,
1005
below=False,
1006
offset=0,
1007
orientation=None,
1008
attributes=None
1009
): ...
1010
1011
class PolyLineOffset:
1012
"""
1013
Create offset parallel polylines.
1014
1015
Parameters:
1016
- polyline: PolyLine, original polyline
1017
- offset: float, offset distance in meters
1018
- popup: str or Popup, popup content
1019
- tooltip: str or Tooltip, tooltip content
1020
1021
Returns:
1022
PolyLineOffset instance
1023
"""
1024
def __init__(
1025
self,
1026
polyline,
1027
offset,
1028
popup=None,
1029
tooltip=None,
1030
**kwargs
1031
): ...
1032
1033
class SideBySideLayers:
1034
"""
1035
Split-screen comparison of two layers with draggable divider.
1036
1037
Parameters:
1038
- layer_left: Layer, left side layer
1039
- layer_right: Layer, right side layer
1040
1041
Returns:
1042
SideBySideLayers instance
1043
"""
1044
def __init__(self, layer_left, layer_right): ...
1045
1046
class DualMap:
1047
"""
1048
Create two synchronized maps side by side for comparison.
1049
1050
Parameters:
1051
- location: tuple, initial center coordinates [lat, lon]
1052
- left_layer: Layer, left map base layer
1053
- right_layer: Layer, right map base layer
1054
- zoom_start: int, initial zoom level (default 10)
1055
- **kwargs: additional map parameters
1056
1057
Returns:
1058
DualMap instance containing two synchronized Map objects
1059
"""
1060
def __init__(
1061
self,
1062
location=None,
1063
left_layer=None,
1064
right_layer=None,
1065
zoom_start=10,
1066
**kwargs
1067
): ...
1068
1069
class TagFilterButton:
1070
"""
1071
Filter map features by tags with button interface.
1072
1073
Parameters:
1074
- tags: list, available filter tags
1075
- position: str, control position (default 'topleft')
1076
- clear_text: str, clear filter button text (default 'Clear filter')
1077
- tags_key: str, property key for tags in features (default 'tags')
1078
1079
Returns:
1080
TagFilterButton instance
1081
"""
1082
def __init__(
1083
self,
1084
tags,
1085
position='topleft',
1086
clear_text='Clear filter',
1087
tags_key='tags'
1088
): ...
1089
```
1090
1091
## Usage Examples
1092
1093
### Marker Clustering with Custom Icons
1094
1095
```python
1096
import folium
1097
from folium.plugins import MarkerCluster
1098
import pandas as pd
1099
1100
# Sample data
1101
data = pd.DataFrame({
1102
'lat': [45.52, 45.53, 45.51, 45.54, 45.50],
1103
'lon': [-122.67, -122.66, -122.68, -122.65, -122.69],
1104
'name': ['Point A', 'Point B', 'Point C', 'Point D', 'Point E'],
1105
'value': [10, 25, 15, 30, 5]
1106
})
1107
1108
m = folium.Map(location=[45.52, -122.67], zoom_start=12)
1109
1110
# Create marker cluster
1111
marker_cluster = MarkerCluster(
1112
name='Clustered Points',
1113
overlay=True,
1114
control=True,
1115
icon_create_function="""
1116
function(cluster) {
1117
var markers = cluster.getAllChildMarkers();
1118
var sum = 0;
1119
for (var i = 0; i < markers.length; i++) {
1120
sum += markers[i].options.myValue || 0;
1121
}
1122
return L.divIcon({
1123
html: '<div style="background-color:red;border-radius:50%;width:30px;height:30px;display:flex;align-items:center;justify-content:center;color:white;font-weight:bold;">' + sum + '</div>',
1124
className: 'custom-cluster-icon',
1125
iconSize: [30, 30]
1126
});
1127
}
1128
"""
1129
)
1130
1131
# Add markers to cluster
1132
for idx, row in data.iterrows():
1133
folium.Marker(
1134
location=[row['lat'], row['lon']],
1135
popup=f"{row['name']}: {row['value']}",
1136
tooltip=row['name'],
1137
icon=folium.Icon(color='blue', icon='info-sign'),
1138
# Add custom property for cluster calculation
1139
).add_to(marker_cluster)
1140
# Note: Custom properties need to be added via JavaScript
1141
1142
marker_cluster.add_to(m)
1143
folium.LayerControl().add_to(m)
1144
1145
m.save('clustered_markers.html')
1146
```
1147
1148
### Animated Heatmap with Time Control
1149
1150
```python
1151
import folium
1152
from folium.plugins import HeatMapWithTime
1153
import numpy as np
1154
import datetime
1155
1156
# Generate sample time-series data
1157
base_time = datetime.datetime(2023, 1, 1)
1158
times = [base_time + datetime.timedelta(hours=i) for i in range(24)]
1159
1160
# Simulate hourly location data (e.g., taxi pickups)
1161
data_by_hour = []
1162
for hour in range(24):
1163
# Generate random points around city center
1164
n_points = 50 + int(30 * np.sin(hour * np.pi / 12)) # More activity during rush hours
1165
lats = np.random.normal(45.52, 0.01, n_points)
1166
lons = np.random.normal(-122.67, 0.01, n_points)
1167
intensities = np.random.exponential(2, n_points)
1168
1169
hour_data = [[lat, lon, intensity] for lat, lon, intensity in zip(lats, lons, intensities)]
1170
data_by_hour.append(hour_data)
1171
1172
m = folium.Map(location=[45.52, -122.67], zoom_start=13)
1173
1174
# Create animated heatmap
1175
heatmap = HeatMapWithTime(
1176
data_by_hour,
1177
index=[t.strftime('%H:00') for t in times],
1178
name='Hourly Activity',
1179
auto_play=True,
1180
display_index=True,
1181
max_opacity=0.8,
1182
radius=15,
1183
blur=10
1184
)
1185
1186
heatmap.add_to(m)
1187
m.save('animated_heatmap.html')
1188
```
1189
1190
### Interactive Drawing with GeoJSON Export
1191
1192
```python
1193
import folium
1194
from folium.plugins import Draw
1195
1196
m = folium.Map(location=[45.52, -122.67], zoom_start=12)
1197
1198
# Add drawing tools
1199
draw = Draw(
1200
export=True,
1201
filename='my_drawings.geojson',
1202
position='topleft',
1203
draw_options={
1204
'polyline': {'allowIntersection': False},
1205
'polygon': {'allowIntersection': False, 'showArea': True},
1206
'circle': True,
1207
'rectangle': True,
1208
'marker': True,
1209
'circlemarker': False,
1210
},
1211
edit_options={'poly': {'allowIntersection': False}}
1212
)
1213
1214
draw.add_to(m)
1215
1216
# Add some reference data
1217
folium.GeoJson(
1218
{
1219
"type": "Feature",
1220
"geometry": {
1221
"type": "Point",
1222
"coordinates": [-122.67, 45.52]
1223
},
1224
"properties": {
1225
"name": "Reference Point"
1226
}
1227
},
1228
popup=folium.GeoJsonPopup(fields=['name'])
1229
).add_to(m)
1230
1231
m.save('drawing_map.html')
1232
```
1233
1234
### Multi-layer Map with Advanced Controls
1235
1236
```python
1237
import folium
1238
from folium.plugins import (
1239
GroupedLayerControl,
1240
MiniMap,
1241
MousePosition,
1242
MeasureControl,
1243
Fullscreen
1244
)
1245
1246
m = folium.Map(location=[45.52, -122.67], zoom_start=11)
1247
1248
# Create base layers
1249
osm = folium.TileLayer('OpenStreetMap', name='OpenStreetMap')
1250
cartodb = folium.TileLayer('CartoDB Positron', name='CartoDB Positron')
1251
1252
# Create overlay layers
1253
markers_group = folium.FeatureGroup(name='Markers')
1254
circles_group = folium.FeatureGroup(name='Circles')
1255
1256
# Add some sample data
1257
locations = [[45.51, -122.68], [45.53, -122.66], [45.50, -122.69]]
1258
for i, loc in enumerate(locations):
1259
folium.Marker(loc, popup=f'Marker {i+1}').add_to(markers_group)
1260
folium.Circle(loc, radius=500, color='red', fill=True).add_to(circles_group)
1261
1262
# Add layers to map
1263
osm.add_to(m)
1264
cartodb.add_to(m)
1265
markers_group.add_to(m)
1266
circles_group.add_to(m)
1267
1268
# Grouped layer control
1269
groups = {
1270
'Base Maps': [osm, cartodb],
1271
'Data Layers': [markers_group, circles_group]
1272
}
1273
GroupedLayerControl(groups=groups, exclusive_groups=['Base Maps']).add_to(m)
1274
1275
# Add minimap
1276
minimap = MiniMap(
1277
tile_layer='CartoDB Positron',
1278
position='bottomleft',
1279
width=150,
1280
height=150,
1281
zoom_level_offset=-4
1282
)
1283
minimap.add_to(m)
1284
1285
# Add mouse position display
1286
MousePosition(
1287
position='bottomright',
1288
separator=' | ',
1289
prefix='Coordinates: ',
1290
num_digits=4
1291
).add_to(m)
1292
1293
# Add measurement tool
1294
MeasureControl(
1295
position='topright',
1296
primary_length_unit='meters',
1297
secondary_length_unit='kilometers',
1298
primary_area_unit='sqmeters',
1299
secondary_area_unit='hectares'
1300
).add_to(m)
1301
1302
# Add fullscreen control
1303
Fullscreen(position='topleft').add_to(m)
1304
1305
m.save('advanced_controls.html')
1306
```