plugins

Folium plugins

Wrap some of the most populat leaflet external plugins.

class folium.plugins.BoatMarker(location, popup=None, icon=None, heading=0, wind_heading=None, wind_speed=0, **kwargs)

Bases: folium.map.Marker

Creates a BoatMarker plugin to append into a map with Map.add_plugin.

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.
render(**kwargs)
class folium.plugins.Draw(export=False)

Bases: branca.element.MacroElement

Vector drawing and editing plugin for Leaflet.

Examples

>>> m = folium.Map()
>>> Draw().draw.add_to(m)

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

render(**kwargs)
class folium.plugins.FastMarkerCluster(data, callback=None)

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) – List of list of shape [[], []]. Data points should be of the form [[lat, lng]].
  • callback (string, default None) – A string representation of a valid Javascript function that will be passed a lat, lon coordinate pair. See the FasterMarkerCluster for an example of a custom callback.
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)

Bases: 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 (boolean) – force seperate button to detach from zoom buttons, default: False
  • https (See) –
render(**kwargs)
class folium.plugins.HeatMap(data, name=None, min_opacity=0.5, max_zoom=18, max_val=1.0, radius=25, blur=15, gradient=None, overlay=True)

Bases: folium.raster_layers.TileLayer

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 (str) – The name of the layer that will be created.
  • 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
  • max_val (float, default 1.) – Maximum point intensity
  • 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’}
render(**kwargs)
class folium.plugins.HeatMapWithTime(data, index=None, name=None, radius=15, min_opacity=0, max_opacity=0.6, scale_radius=False, 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')

Bases: folium.raster_layers.TileLayer

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 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 (str) – The name of the layer that will be created.
  • 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.
  • 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 aimation 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’.
render(**kwargs)
class folium.plugins.MarkerCluster(locations=None, popups=None, icons=None, name=None, overlay=True, control=True, icon_create_function=None)

Bases: folium.map.Layer

Provides Beautiful Animated Marker Clustering functionality for maps.

Parameters:
  • 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
  • icon_create_function (string, default None) – Override the default behaviour, making possible to customize markers colors and sizes.
  • locations (list of list or array of shape (n, 2)) – Data points of the form [[lat, lng]].
  • popups (list of length n.) – Popup for each marker.
  • icons (list of length n.) – Icon for each marker.

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)});
}'''
render(**kwargs)
class folium.plugins.MeasureControl(position='topright', primary_length_unit='meters', secondary_length_unit='miles', primary_area_unit='sqmeters', secondary_area_unit='acres')

Bases: branca.element.MacroElement

Adds a measurem widget on the map.

Parameters:
  • position (location of the widget) – default is ‘topright’.
  • and secondary_length_unit (primary_length_unit) – defaults are ‘meters’ and ‘miles’ respectively.
  • and secondary_area_unit (primary_area_unit) – defaults are ‘sqmeters’ and ‘acres’ respectively.
  • https (See) –
render(**kwargs)
class folium.plugins.PolyLineTextPath(polyline, text, repeat=False, center=False, below=False, offset=0, orientation=0, attributes=None)

Bases: 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) –
render(**kwargs)
class folium.plugins.ScrollZoomToggler

Bases: branca.element.MacroElement

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

class folium.plugins.Terminator

Bases: branca.element.MacroElement

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

render(**kwargs)
class folium.plugins.TimeSliderChoropleth(data, styledict, name=None, overlay=True, control=True, **kwargs)

Bases: folium.features.GeoJson

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}
render(**kwargs)
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)

Bases: 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 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

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.

render(**kwargs)
class folium.plugins.TimestampedWmsTileLayers(data, transition_time=200, loop=False, auto_play=False, period='P1D', time_interval=False)

Bases: 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.

Examples

>>> w0 = features.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 = features.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 = plugins.TimestampedWmsTileLayers([w0, w1])
>>> time.add_to(m)

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

render(**kwargs)
class folium.plugins.Search(data, search_zoom=12, search_label='name', geom_type='Point', position='topleft')

Bases: branca.element.MacroElement

Adds a search tool to your map.

Parameters:
  • data (str/JSON) – GeoJSON strings
  • search_zoom (int) – zoom level when searching features, default 12
  • search_label (str) – label to index the search, default ‘name’
  • geom_type (str) – geometry type, default ‘Point’
  • position (str) – Change the position of the search bar, can be: ‘topleft’, ‘topright’, ‘bottomright’ or ‘bottomleft’, default ‘topleft’
  • https (See) –
render(**kwargs)