plugins

Folium plugins

Wrap some of the most popular leaflet external plugins.

class folium.plugins.AntPath(locations, popup=None, tooltip=None, **kwargs)

Bases: folium.elements.JSCSSMixin, folium.vector_layers.BaseMultiLocation

Class for drawing AntPath polyline overlays on a map.

See folium.vector_layers.path_options() for the Path options.

Parameters
  • locations (list of points (latitude, longitude)) – Latitude and Longitude of line (Northing, Easting)

  • popup (str or folium.Popup, default None) – Input text or visualization for object displayed when clicking.

  • tooltip (str or folium.Tooltip, optional) – Display a text when hovering over the object.

  • **kwargs – Polyline and AntPath options. See their Github page for the available parameters.

  • https (//github.com/rubenspgcavalcante/leaflet-ant-path/) –

default_js = [('antpath', 'https://cdn.jsdelivr.net/npm/leaflet-ant-path@1.1.2/dist/leaflet-ant-path.min.js')]
class folium.plugins.BeautifyIcon(icon=None, icon_shape=None, border_width=3, border_color='#000', text_color='#000', background_color='#FFF', inner_icon_style='', spin=False, number=None, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Create a BeautifyIcon that can be added to a Marker

Parameters
  • icon (string, default None) – the Font-Awesome icon name to use to render the marker.

  • icon_shape (string, default None) – the icon shape

  • border_width (integer, default 3) – the border width of the icon

  • border_color (string with hexadecimal RGB, default '#000') – the border color of the icon

  • text_color (string with hexadecimal RGB, default '#000') – the text color of the icon

  • background_color (string with hexadecimal RGB, default '#FFF') – the background color of the icon

  • inner_icon_style (string with css styles for the icon, default '') – the css styles of the icon

  • spin (boolean, default False) – allow the icon to be spinning.

  • number (integer, default None) – the number of the icon.

Examples

Plugin Website: https://github.com/marslan390/BeautifyMarker >>> BeautifyIcon(text_color=’#000’, border_color=’transparent’, … background_color=’#FFF’).add_to(marker) >>> number_icon = BeautifyIcon(text_color=’#000’, border_color=’transparent’, … background_color=’#FFF’, number=10, … inner_icon_style=’font-size:12px;padding-top:-5px;’) >>> Marker(location=[45.5, -122.3], popup=folium.Popup(‘Portland, OR’), icon=number_icon) >>> BeautifyIcon(icon=’arrow-down’, icon_shape=’marker’).add_to(marker)

ICON_SHAPE_TYPES = ['circle', 'circle-dot', 'doughnut', 'rectangle-dot', 'marker', None]
default_css = [('beautify_icon_css', 'https://cdn.jsdelivr.net/gh/marslan390/BeautifyMarker/leaflet-beautify-marker-icon.min.css')]
default_js = [('beautify_icon_js', 'https://cdn.jsdelivr.net/gh/marslan390/BeautifyMarker/leaflet-beautify-marker-icon.min.js')]
class folium.plugins.BoatMarker(location, popup=None, icon=None, heading=0, wind_heading=None, wind_speed=0, **kwargs)

Bases: folium.elements.JSCSSMixin, folium.map.Marker

Add a Marker in the shape of a boat.

Parameters
  • location (tuple of length 2, default None) – The latitude and longitude of the marker. If None, then the middle of the map is used.

  • heading (int, default 0) – Heading of the boat to an angle value between 0 and 360 degrees

  • wind_heading (int, default None) – Heading of the wind to an angle value between 0 and 360 degrees If None, then no wind is represented.

  • wind_speed (int, default 0) – Speed of the wind in knots.

  • https (//github.com/thomasbrueggemann/leaflet.boatmarker) –

default_js = [('markerclusterjs', 'https://unpkg.com/leaflet.boatmarker/leaflet.boatmarker.min.js')]
class folium.plugins.CirclePattern(width=20, height=20, radius=12, weight=2.0, color='#3388ff', fill_color='#3388ff', opacity=0.75, fill_opacity=0.5)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Fill Pattern for polygon composed of repeating circles.

Add these to the ‘fillPattern’ field in GeoJson style functions.

Parameters
  • width (int, default 20) – Horizontal distance between circles (pixels).

  • height (int, default 20) – Vertical distance between circles (pixels).

  • radius (int, default 12) – Radius of each circle (pixels).

  • weight (float, default 2.0) – Width of outline around each circle (pixels).

  • color (string with hexadecimal, RGB, or named color, default "#3388ff") – Color of the circle outline.

  • fill_color (string with hexadecimal, RGB, or named color, default "#3388ff") – Color of the circle interior.

  • opacity (float, default 0.75) – Opacity of the circle outline. Should be between 0 and 1.

  • fill_opacity (float, default 0.5) – Opacity of the circle interior. Should be between 0 and 1.

  • https (See) –

default_js = [('pattern', 'https://teastman.github.io/Leaflet.pattern/leaflet.pattern.js')]
render(**kwargs)

Renders the HTML representation of the element.

class folium.plugins.Draw(export=False, filename='data.geojson', position='topleft', draw_options=None, edit_options=None)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Vector drawing and editing plugin for Leaflet.

Parameters

Examples

>>> m = folium.Map()
>>> Draw(
...     export=True,
...     filename='my_data.geojson',
...     position='topleft',
...     draw_options={'polyline': {'allowIntersection': False}},
...     edit_options={'poly': {'allowIntersection': False}}
... ).add_to(m)

For more info please check https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html

default_css = [('leaflet_draw_css', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.css')]
default_js = [('leaflet_draw_js', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.js')]
render(**kwargs)

Renders the HTML representation of the element.

class folium.plugins.DualMap(location=None, layout='horizontal', **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Create two maps in the same window.

Adding children to this objects adds them to both maps. You can access the individual maps with DualMap.m1 and DualMap.m2.

Uses the Leaflet plugin Sync: https://github.com/jieter/Leaflet.Sync

Parameters
  • location (tuple or list, optional) – Latitude and longitude of center point of the maps.

  • layout ({'horizontal', 'vertical'}) – Select how the two maps should be positioned. Either horizontal (left and right) or vertical (top and bottom).

  • **kwargs – Keyword arguments are passed to the two Map objects.

Examples

>>> # DualMap accepts the same arguments as Map:
>>> m = DualMap(location=(0, 0), tiles='cartodbpositron', zoom_start=5)
>>> # Add the same marker to both maps:
>>> Marker((0, 0)).add_to(m)
>>> # The individual maps are attributes called `m1` and `m2`:
>>> Marker((0, 1)).add_to(m.m1)
>>> LayerControl().add_to(m)
>>> m.save('map.html')
add_child(child, name=None, index=None)

Add object child to the first map and store it for the second.

default_js = [('Leaflet.Sync', 'https://cdn.jsdelivr.net/gh/jieter/Leaflet.Sync/L.Map.Sync.min.js')]
fit_bounds(*args, **kwargs)
keep_in_front(*args)
render(**kwargs)

Renders the HTML representation of the element.

class folium.plugins.FastMarkerCluster(data, callback=None, options=None, name=None, overlay=True, control=True, show=True, icon_create_function=None, **kwargs)

Bases: folium.plugins.marker_cluster.MarkerCluster

Add marker clusters to a map using in-browser rendering. Using FastMarkerCluster it is possible to render 000’s of points far quicker than the MarkerCluster class.

Be aware that the FastMarkerCluster class passes an empty list to the parent class’ __init__ method during initialisation. This means that the add_child method is never called, and no reference to any marker data are retained. Methods such as get_bounds() are therefore not available when using it.

Parameters
  • data (list of list with values) – List of list of shape [[lat, lon], [lat, lon], etc.] When you use a custom callback you could add more values after the lat and lon. E.g. [[lat, lon, ‘red’], [lat, lon, ‘blue’]]

  • callback (string, optional) – A string representation of a valid Javascript function that will be passed each row in data. See the FasterMarkerCluster for an example of a custom callback.

  • name (string, optional) – The name of the Layer, as it will appear in LayerControls.

  • overlay (bool, default True) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

  • icon_create_function (string, default None) – Override the default behaviour, making possible to customize markers colors and sizes.

  • **kwargs – Additional arguments are passed to Leaflet.markercluster options. See https://github.com/Leaflet/Leaflet.markercluster

class folium.plugins.FeatureGroupSubGroup(group, name=None, overlay=True, control=True, show=True)

Bases: folium.elements.JSCSSMixin, folium.map.Layer

Creates a Feature Group that adds its child layers into a parent group when added to a map (e.g. through LayerControl). Useful to create nested groups, or cluster markers from multiple overlays. From [0].

[0] https://github.com/ghybs/Leaflet.FeatureGroup.SubGroup

Parameters
  • group (Layer) – The MarkerCluster or FeatureGroup containing this subgroup.

  • name (string, default None) – The name of the Layer, as it will appear in LayerControls

  • overlay (bool, default True) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

Examples

>>> fg = folium.FeatureGroup()                          # Main group
>>> g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')  # First subgroup of fg
>>> g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')  # Second subgroup of fg
>>> m.add_child(fg)
>>> m.add_child(g1)
>>> m.add_child(g2)
>>> g1.add_child(folium.Marker([0,0]))
>>> g2.add_child(folium.Marker([0,1]))
>>> folium.LayerControl().add_to(m)
>>> mcg = folium.plugins.MarkerCluster(control=False)   # Marker Cluster, hidden in controls
>>> g1 = folium.plugins.FeatureGroupSubGroup(mcg, 'g1') # First group, in mcg
>>> g2 = folium.plugins.FeatureGroupSubGroup(mcg, 'g2') # Second group, in mcg
>>> m.add_child(mcg)
>>> m.add_child(g1)
>>> m.add_child(g2)
>>> g1.add_child(folium.Marker([0,0]))
>>> g2.add_child(folium.Marker([0,1]))
>>> folium.LayerControl().add_to(m)
default_js = [('featuregroupsubgroupjs', 'https://unpkg.com/leaflet.featuregroup.subgroup@1.0.2/dist/leaflet.featuregroup.subgroup.js')]
class folium.plugins.FloatImage(image, bottom=75, left=75)

Bases: branca.element.MacroElement

Adds a floating image in HTML canvas on top of the map.

class folium.plugins.Fullscreen(position='topleft', title='Full Screen', title_cancel='Exit Full Screen', force_separate_button=False, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Adds a fullscreen button to your map.

Parameters
  • position (str) – change the position of the button can be: ‘topleft’, ‘topright’, ‘bottomright’ or ‘bottomleft’ default: ‘topleft’

  • title (str) – change the title of the button, default: ‘Full Screen’

  • title_cancel (str) – change the title of the button when fullscreen is on, default: ‘Exit Full Screen’

  • force_separate_button (bool, default False) – force seperate button to detach from zoom buttons,

  • https (See) –

default_css = [('Control.FullScreen.css', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.css')]
default_js = [('Control.Fullscreen.js', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.js')]
class folium.plugins.Geocoder(collapsed=False, position='topright', add_marker=True, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

A simple geocoder for Leaflet that by default uses OSM/Nominatim.

Please respect the Nominatim usage policy: https://operations.osmfoundation.org/policies/nominatim/

Parameters
  • collapsed (bool, default False) – If True, collapses the search box unless hovered/clicked.

  • position (str, default 'topright') – Choose from ‘topleft’, ‘topright’, ‘bottomleft’ or ‘bottomright’.

  • add_marker (bool, default True) – If True, adds a marker on the found location.

  • all options see https (For) –

default_css = [('Control.Geocoder.css', 'https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css')]
default_js = [('Control.Geocoder.js', 'https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js')]
class folium.plugins.HeatMap(data, name=None, min_opacity=0.5, max_zoom=18, radius=25, blur=15, gradient=None, overlay=True, control=True, show=True, **kwargs)

Bases: folium.elements.JSCSSMixin, folium.map.Layer

Create a Heatmap layer

Parameters
  • data (list of points of the form [lat, lng] or [lat, lng, weight]) – The points you want to plot. You can also provide a numpy.array of shape (n,2) or (n,3).

  • name (string, default None) – The name of the Layer, as it will appear in LayerControls.

  • min_opacity (default 1.) – The minimum opacity the heat will start at.

  • max_zoom (default 18) – Zoom level where the points reach maximum intensity (as intensity scales with zoom), equals maxZoom of the map by default

  • radius (int, default 25) – Radius of each “point” of the heatmap

  • blur (int, default 15) – Amount of blur

  • gradient (dict, default None) – Color gradient config. e.g. {0.4: ‘blue’, 0.65: ‘lime’, 1: ‘red’}

  • overlay (bool, default True) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

default_js = [('leaflet-heat.js', 'https://cdn.jsdelivr.net/gh/python-visualization/folium@master/folium/templates/leaflet_heat.min.js')]
class folium.plugins.HeatMapWithTime(data, index=None, name=None, radius=15, min_opacity=0, max_opacity=0.6, scale_radius=False, gradient=None, use_local_extrema=False, auto_play=False, display_index=True, index_steps=1, min_speed=0.1, max_speed=10, speed_step=0.1, position='bottomleft', overlay=True, control=True, show=True)

Bases: folium.elements.JSCSSMixin, folium.map.Layer

Create a HeatMapWithTime layer

Parameters
  • data (list of list of points of the form [lat, lng] or [lat, lng, weight]) – The points you want to plot. The outer list corresponds to the various time steps in sequential order. (weight is in (0, 1] range and defaults to 1 if not specified for a point)

  • index (Index giving the label (or timestamp) of the elements of data. Should have) – the same length as data, or is replaced by a simple count if not specified.

  • name (string, default None) – The name of the Layer, as it will appear in LayerControls.

  • radius (default 15.) – The radius used around points for the heatmap.

  • min_opacity (default 0) – The minimum opacity for the heatmap.

  • max_opacity (default 0.6) – The maximum opacity for the heatmap.

  • scale_radius (default False) – Scale the radius of the points based on the zoom level.

  • gradient (dict, default None) – Match point density values to colors. Color can be a name (‘red’), RGB values (‘rgb(255,0,0)’) or a hex number (‘#FF0000’).

  • use_local_extrema (default False) – Defines whether the heatmap uses a global extrema set found from the input data OR a local extrema (the maximum and minimum of the currently displayed view).

  • auto_play (default False) – Automatically play the animation across time.

  • display_index (default True) – Display the index (usually time) in the time control.

  • index_steps (default 1) – Steps to take in the index dimension between animation steps.

  • min_speed (default 0.1) – Minimum fps speed for animation.

  • max_speed (default 10) – Maximum fps speed for animation.

  • speed_step (default 0.1) – Step between different fps speeds on the speed slider.

  • position (default 'bottomleft') – Position string for the time slider. Format: ‘bottom/top’+’left/right’.

  • overlay (bool, default True) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

default_css = [('leaflet.timedimension.control.min.css', 'https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.control.css')]
default_js = [('iso8601', 'https://cdn.jsdelivr.net/npm/iso8601-js-period@0.2.1/iso8601.min.js'), ('leaflet.timedimension.min.js', 'https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.min.js'), ('heatmap.min.js', 'https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/pa7_hm.min.js'), ('leaflet-heatmap.js', 'https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/pa7_leaflet_hm.min.js')]
render(**kwargs)

Renders the HTML representation of the element.

class folium.plugins.LocateControl(auto_start=False, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Control plugin to geolocate the user.

This plugins adds a button to the map, and when it’s clicked shows the current user device location.

To work properly in production, the connection needs to be encrypted, otherwise browser will not allow users to share their location.

Parameters
  • auto-start (bool, default False) – When set to True, plugin will be activated on map loading and search for user position. Once user location is founded, the map will automatically centered in using user coordinates.

  • **kwargs – For possible options, see https://github.com/domoritz/leaflet-locatecontrol

Examples

>>> m = folium.Map()
# With default settings
>>> LocateControl().add_to(m)

# With some custom options >>> LocateControl( … position=”bottomright”, … strings={“title”: “See you current location”, … “popup”: “Your position”}).add_to(m))

For more info check: https://github.com/domoritz/leaflet-locatecontrol

default_css = [('Control_locate_min_css', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.66.2/L.Control.Locate.min.css')]
default_js = [('Control_locate_min_js', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.66.2/L.Control.Locate.min.js')]
class folium.plugins.MarkerCluster(locations=None, popups=None, icons=None, name=None, overlay=True, control=True, show=True, icon_create_function=None, options=None, **kwargs)

Bases: folium.elements.JSCSSMixin, folium.map.Layer

Provides Beautiful Animated Marker Clustering functionality for maps.

Parameters
  • locations (list of list or array of shape (n, 2)) – Data points of the form [[lat, lng]].

  • popups (list of length n, default None) – Popup for each marker, either a Popup object or a string or None.

  • icons (list of length n, default None) – Icon for each marker, either an Icon object or a string or None.

  • name (string, default None) – The name of the Layer, as it will appear in LayerControls

  • overlay (bool, default True) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

  • icon_create_function (string, default None) – Override the default behaviour, making possible to customize markers colors and sizes.

  • options (dict, default None) – A dictionary with options for Leaflet.markercluster. See https://github.com/Leaflet/Leaflet.markercluster for options.

Example

>>> icon_create_function = '''
...     function(cluster) {
...     return L.divIcon({html: '<b>' + cluster.getChildCount() + '</b>',
...                       className: 'marker-cluster marker-cluster-small',
...                       iconSize: new L.Point(20, 20)});
...     }
... '''
default_css = [('markerclustercss', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.css'), ('markerclusterdefaultcss', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.Default.css')]
default_js = [('markerclusterjs', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js')]
class folium.plugins.MeasureControl(position='topright', primary_length_unit='meters', secondary_length_unit='miles', primary_area_unit='sqmeters', secondary_area_unit='acres', **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Add a measurement widget on the map.

Parameters
  • position (str, default 'topright') – Location of the widget.

  • primary_length_unit (str, default 'meters') –

  • secondary_length_unit (str, default 'miles') –

  • primary_area_unit (str, default 'sqmeters') –

  • secondary_area_unit (str, default 'acres') –

  • https (See) –

default_css = [('leaflet_measure_css', 'https://cdn.jsdelivr.net/gh/ljagis/leaflet-measure@2.1.7/dist/leaflet-measure.min.css')]
default_js = [('leaflet_measure_js', 'https://cdn.jsdelivr.net/gh/ljagis/leaflet-measure@2.1.7/dist/leaflet-measure.min.js')]
class folium.plugins.MiniMap(tile_layer=None, position='bottomright', width=150, height=150, collapsed_width=25, collapsed_height=25, zoom_level_offset=- 5, zoom_level_fixed=None, center_fixed=False, zoom_animation=False, toggle_display=False, auto_toggle_display=False, minimized=False, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Add a minimap (locator) to an existing map.

Uses the Leaflet plugin by Norkart under BSD 2-Clause “Simplified” License. https://github.com/Norkart/Leaflet-MiniMap

Parameters
  • tile_layer (folium TileLayer object or str, default None) – Provide a folium TileLayer object or the wanted tiles as string. If not provided it will use the default of ‘TileLayer’, currently OpenStreetMap.

  • position (str, default 'bottomright') – The standard Control position parameter for the widget.

  • width (int, default 150) – The width of the minimap in pixels.

  • height (int, default 150) – The height of the minimap in pixels.

  • collapsed_width (int, default 25) – The width of the toggle marker and the minimap when collapsed in pixels.

  • collapsed_height (int, default 25) – The height of the toggle marker and the minimap when collapsed

  • zoom_level_offset (int, default -5) – The offset applied to the zoom in the minimap compared to the zoom of the main map. Can be positive or negative.

  • zoom_level_fixed (int, default None) – Overrides the offset to apply a fixed zoom level to the minimap regardless of the main map zoom. Set it to any valid zoom level, if unset zoom_level_offset is used instead.

  • center_fixed (bool, default False) – Applies a fixed position to the minimap regardless of the main map’s view / position. Prevents panning the minimap, but does allow zooming (both in the minimap and the main map). If the minimap is zoomed, it will always zoom around the centerFixed point. You can pass in a LatLng-equivalent object.

  • zoom_animation (bool, default False) – Sets whether the minimap should have an animated zoom. (Will cause it to lag a bit after the movement of the main map.)

  • toggle_display (bool, default False) – Sets whether the minimap should have a button to minimise it.

  • auto_toggle_display (bool, default False) – Sets whether the minimap should hide automatically if the parent map bounds does not fit within the minimap bounds. Especially useful when ‘zoomLevelFixed’ is set.

  • minimized (bool, default False) – Sets whether the minimap should start in a minimized position.

Examples

>>> MiniMap(tile_layer='Stamen WaterColor', position='bottomleft')
default_css = [('Control_MiniMap_css', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-minimap/3.6.1/Control.MiniMap.css')]
default_js = [('Control_MiniMap_js', 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-minimap/3.6.1/Control.MiniMap.js')]
class folium.plugins.MousePosition(position='bottomright', separator=' : ', empty_string='Unavailable', lng_first=False, num_digits=5, prefix='', lat_formatter=None, lng_formatter=None, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Add a field that shows the coordinates of the mouse position.

Uses the Leaflet plugin by Ardhi Lukianto under MIT license. https://github.com/ardhi/Leaflet.MousePosition

Parameters
  • position (str, default 'bottomright') – The standard Control position parameter for the widget.

  • separator (str, default ' : ') – Character used to separate latitude and longitude values.

  • empty_string (str, default 'Unavailable') – Initial text to display.

  • lng_first (bool, default False) – Whether to put the longitude first or not. Set as True to display longitude before latitude.

  • num_digits (int, default '5') – Number of decimal places included in the displayed longitude and latitude decimal degree values.

  • prefix (str, default '') – A string to be prepended to the coordinates.

  • lat_formatter (str, default None) – Custom Javascript function to format the latitude value.

  • lng_formatter (str, default None) – Custom Javascript function to format the longitude value.

Examples

>>> fmtr = "function(num) {return L.Util.formatNum(num, 3) + ' º ';};"
>>> MousePosition(position='topright', separator=' | ', prefix="Mouse:",
...               lat_formatter=fmtr, lng_formatter=fmtr)
default_css = [('Control_MousePosition_css', 'https://cdn.jsdelivr.net/gh/ardhi/Leaflet.MousePosition/src/L.Control.MousePosition.min.css')]
default_js = [('Control_MousePosition_js', 'https://cdn.jsdelivr.net/gh/ardhi/Leaflet.MousePosition/src/L.Control.MousePosition.min.js')]
class folium.plugins.PolyLineOffset(locations, popup=None, tooltip=None, offset=0, **kwargs)

Bases: folium.elements.JSCSSMixin, folium.vector_layers.PolyLine

Add offset capabilities to the PolyLine class.

This plugin adds to folium Polylines the ability to be drawn with a relative pixel offset, without modifying their actual coordinates. The offset value can be either negative or positive, for left- or right-side offset, and remains constant across zoom levels.

See folium.vector_layers.path_options() for the Path options.

Parameters
  • locations (list of points (latitude, longitude)) – Latitude and Longitude of line (Northing, Easting)

  • popup (str or folium.Popup, default None) – Input text or visualization for object displayed when clicking.

  • tooltip (str or folium.Tooltip, optional) – Display a text when hovering over the object.

  • offset (int, default 0) – Relative pixel offset to draw a line parallel to an existant one, at a fixed distance.

  • **kwargs – Polyline options. See their Github page for the available parameters.

  • https (See) –

Examples

>>> plugins.PolyLineOffset([[58, -28], [53, -23]], color="#f00", opacity=1, offset=-5).add_to(m)
>>> plugins.PolyLineOffset([[58, -28], [53, -23]], color="#080", opacity=1, offset=10).add_to(m)
default_js = [('polylineoffset', 'https://cdn.jsdelivr.net/npm/leaflet-polylineoffset@1.1.1/leaflet.polylineoffset.min.js')]
class folium.plugins.PolyLineTextPath(polyline, text, repeat=False, center=False, below=False, offset=0, orientation=0, attributes=None, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Shows a text along a PolyLine.

Parameters
  • polyline (folium.features.PolyLine object) – The folium.features.PolyLine object to attach the text to.

  • text (string) – The string to be attached to the polyline.

  • repeat (bool, default False) – Specifies if the text should be repeated along the polyline.

  • center (bool, default False) – Centers the text according to the polyline’s bounding box

  • below (bool, default False) – Show text below the path

  • offset (int, default 0) – Set an offset to position text relative to the polyline.

  • orientation (int, default 0) – Rotate text to a specified angle.

  • attributes (dict) – Object containing the attributes applied to the text tag. Check valid attributes here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text#Attributes Example: {‘fill’: ‘#007DEF’, ‘font-weight’: ‘bold’, ‘font-size’: ‘24’}

  • https (See) –

default_js = [('polylinetextpath', 'https://cdn.jsdelivr.net/npm/leaflet-textpath@1.2.3/leaflet.textpath.min.js')]
class folium.plugins.ScrollZoomToggler

Bases: branca.element.MacroElement

Creates a button for enabling/disabling scroll on the Map.

class folium.plugins.Search(layer, search_label=None, search_zoom=None, geom_type='Point', position='topleft', placeholder='Search', collapsed=False, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Adds a search tool to your map.

Parameters
  • layer (GeoJson, TopoJson, FeatureGroup, MarkerCluster class object.) – The map layer to index in the Search view.

  • search_label (str, optional) – ‘properties’ key in layer to index Search, if layer is GeoJson/TopoJson.

  • search_zoom (int, optional) – Zoom level to set the map to on match. By default zooms to Polygon/Line bounds and points on their natural extent.

  • geom_type (str, default 'Point') – Feature geometry type. “Point”, “Line” or “Polygon”

  • position (str, default 'topleft') – Change the position of the search bar, can be: ‘topleft’, ‘topright’, ‘bottomright’ or ‘bottomleft’,

  • placeholder (str, default 'Search') – Placeholder text inside the Search box if nothing is entered.

  • collapsed (boolean, default False) – Whether the Search box should be collapsed or not.

  • **kwargs. – Assorted style options to change feature styling on match. Use the same way as vector layer arguments.

  • https (See) –

default_css = [('Leaflet.Search.css', 'https://cdn.jsdelivr.net/npm/leaflet-search@2.9.7/dist/leaflet-search.min.css')]
default_js = [('Leaflet.Search.js', 'https://cdn.jsdelivr.net/npm/leaflet-search@2.9.7/dist/leaflet-search.min.js')]
render(**kwargs)

Renders the HTML representation of the element.

test_params(keys)
class folium.plugins.SemiCircle(location, radius, direction=None, arc=None, start_angle=None, stop_angle=None, popup=None, tooltip=None, **kwargs)

Bases: folium.elements.JSCSSMixin, folium.map.Marker

Add a marker in the shape of a semicircle, similar to the Circle class.

Use (direction and arc) or (start_angle and stop_angle), not both.

Parameters
  • location (tuple[float, float]) – Latitude and Longitude pair (Northing, Easting)

  • radius (float) – Radius of the circle, in meters.

  • direction (int, default None) – Direction angle in degrees

  • arc (int, default None) – Arc angle in degrees.

  • start_angle (int, default None) – Start angle in degrees

  • stop_angle (int, default None) – Stop angle in degrees.

  • popup (str or folium.Popup, optional) – Input text or visualization for object displayed when clicking.

  • tooltip (str or folium.Tooltip, optional) – Display a text when hovering over the object.

  • **kwargs – For additional arguments see folium.vector_layers.path_options()

  • Leaflet plugin https (Uses) –

default_js = [('semicirclejs', 'https://cdn.jsdelivr.net/npm/leaflet-semicircle@2.0.4/Semicircle.min.js')]
class folium.plugins.StripePattern(angle=0.5, weight=4, space_weight=4, color='#000000', space_color='#ffffff', opacity=0.75, space_opacity=0.0, **kwargs)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Fill Pattern for polygon composed of alternating lines.

Add these to the ‘fillPattern’ field in GeoJson style functions.

Parameters
  • angle (float, default 0.5) – Angle of the line pattern (degrees). Should be between -360 and 360.

  • weight (float, default 4) – Width of the main lines (pixels).

  • space_weight (float) – Width of the alternate lines (pixels).

  • color (string with hexadecimal, RGB, or named color, default "#000000") – Color of the main lines.

  • space_color (string with hexadecimal, RGB, or named color, default "#ffffff") – Color of the alternate lines.

  • opacity (float, default 0.75) – Opacity of the main lines. Should be between 0 and 1.

  • space_opacity (float, default 0.0) – Opacity of the alternate lines. Should be between 0 and 1.

  • https (See) –

default_js = [('pattern', 'https://teastman.github.io/Leaflet.pattern/leaflet.pattern.js')]
render(**kwargs)

Renders the HTML representation of the element.

class folium.plugins.Terminator

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Leaflet.Terminator is a simple plug-in to the Leaflet library to overlay day and night regions on maps.

default_js = [('terminator', 'https://unpkg.com/@joergdietrich/leaflet.terminator')]
class folium.plugins.TimeSliderChoropleth(data, styledict, name=None, overlay=True, control=True, show=True)

Bases: folium.elements.JSCSSMixin, folium.map.Layer

Creates a TimeSliderChoropleth plugin to append into a map with Map.add_child.

Parameters
  • data (str) – geojson string

  • styledict (dict) – A dictionary where the keys are the geojson feature ids and the values are dicts of {time: style_options_dict}

  • name (string, default None) – The name of the Layer, as it will appear in LayerControls.

  • overlay (bool, default False) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

default_js = [('d3v4', 'https://d3js.org/d3.v4.min.js')]
class folium.plugins.TimestampedGeoJson(data, transition_time=200, loop=True, auto_play=True, add_last_point=True, period='P1D', min_speed=0.1, max_speed=10, loop_button=False, date_options='YYYY-MM-DD HH:mm:ss', time_slider_drag_update=False, duration=None)

Bases: folium.elements.JSCSSMixin, branca.element.MacroElement

Creates a TimestampedGeoJson plugin from timestamped GeoJSONs to append into a map with Map.add_child.

A geo-json is timestamped if:

  • it contains only features of types LineString, MultiPoint, MultiLineString, Polygon and MultiPolygon.

  • each feature has a ‘times’ property with the same length as the coordinates array.

  • each element of each ‘times’ property is a timestamp in ms since epoch, or in ISO string.

Eventually, you may have Point features with a ‘times’ property being an array of length 1.

Parameters
  • data (file, dict or str.) –

    The timestamped geo-json data you want to plot.

    • If file, then data will be read in the file and fully embedded in Leaflet’s javascript.

    • If dict, then data will be converted to json and embedded in the javascript.

    • If str, then data will be passed to the javascript as-is.

  • transition_time (int, default 200.) – The duration in ms of a transition from between timestamps.

  • loop (bool, default True) – Whether the animation shall loop.

  • auto_play (bool, default True) – Whether the animation shall start automatically at startup.

  • add_last_point (bool, default True) – Whether a point is added at the last valid coordinate of a LineString.

  • period (str, default "P1D") – Used to construct the array of available times starting from the first available time. Format: ISO8601 Duration ex: ‘P1M’ 1/month, ‘P1D’ 1/day, ‘PT1H’ 1/hour, and ‘PT1M’ 1/minute

  • duration (str, default None) – Period of time which the features will be shown on the map after their time has passed. If None, all previous times will be shown. Format: ISO8601 Duration ex: ‘P1M’ 1/month, ‘P1D’ 1/day, ‘PT1H’ 1/hour, and ‘PT1M’ 1/minute

Examples

>>> TimestampedGeoJson({
...     'type': 'FeatureCollection',
...     'features': [
...       {
...         'type': 'Feature',
...         'geometry': {
...           'type': 'LineString',
...           'coordinates': [[-70,-25],[-70,35],[70,35]],
...           },
...         'properties': {
...           'times': [1435708800000, 1435795200000, 1435881600000]
...           }
...         }
...       ]
...     })

See https://github.com/socib/Leaflet.TimeDimension for more information.

default_css = [('highlight.js_css', 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css'), ('leaflet.timedimension_css', 'https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.control.css')]
default_js = [('jquery2.0.0', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js'), ('jqueryui1.10.2', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js'), ('iso8601', 'https://cdn.jsdelivr.net/npm/iso8601-js-period@0.2.1/iso8601.min.js'), ('leaflet.timedimension', 'https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.min.js'), ('moment', 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js')]
render(**kwargs)

Renders the HTML representation of the element.

class folium.plugins.TimestampedWmsTileLayers(data, transition_time=200, loop=False, auto_play=False, period='P1D', time_interval=False, name=None)

Bases: folium.elements.JSCSSMixin, folium.map.Layer

Creates a TimestampedWmsTileLayer that takes a WmsTileLayer and adds time control with the Leaflet.TimeDimension plugin.

Parameters
  • data (WmsTileLayer.) – The WmsTileLayer that you want to add time support to. Must be created like a typical WmsTileLayer and added to the map before being passed to this class.

  • transition_time (int, default 200.) – The duration in ms of a transition from between timestamps.

  • loop (bool, default False) – Whether the animation shall loop, default is to reduce load on WMS services.

  • auto_play (bool, default False) – Whether the animation shall start automatically at startup, default is to reduce load on WMS services.

  • period (str, default 'P1D') – Used to construct the array of available times starting from the first available time. Format: ISO8601 Duration ex: ‘P1M’ -> 1/month, ‘P1D’ -> 1/day, ‘PT1H’ -> 1/hour, and ‘PT1M’ -> 1/minute Note: this seems to be overridden by the WMS Tile Layer GetCapabilities.

  • name (string, default None) – The name of the Layer, as it will appear in LayerControls.

  • overlay (bool, default True) – Adds the layer as an optional overlay (True) or the base layer (False).

  • control (bool, default True) – Whether the Layer will be included in LayerControls.

  • show (bool, default True) – Whether the layer will be shown on opening (only for overlays).

Examples

>>> w0 = WmsTileLayer(
...          'http://this.wms.server/ncWMS/wms',
...          name='Test WMS Data',
...          styles='',
...          fmt='image/png',
...          transparent=True,
...          layers='test_data',
...          COLORSCALERANGE='0,10',
...)
>>> w0.add_to(m)
>>> w1 = WmsTileLayer(
...          'http://this.wms.server/ncWMS/wms',
...          name='Test WMS Data',
...          styles='',
...          fmt='image/png',
...          transparent=True,
...          layers='test_data_2',
...          COLORSCALERANGE='0,5',
...)
>>> w1.add_to(m)
>>> # Add WmsTileLayers to time control.
>>> time = TimestampedWmsTileLayers([w0, w1])
>>> time.add_to(m)

See https://github.com/socib/Leaflet.TimeDimension for more information.

default_css = [('highlight.js_css', 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css'), ('leaflet.timedimension_css', 'https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.control.css')]
default_js = [('jquery2.0.0', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js'), ('jqueryui1.10.2', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js'), ('iso8601', 'https://cdn.jsdelivr.net/npm/iso8601-js-period@0.2.1/iso8601.min.js'), ('leaflet.timedimension', 'https://cdn.jsdelivr.net/npm/leaflet-timedimension@1.1.1/dist/leaflet.timedimension.min.js')]