Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
import json
from branca.element import Element, Figure
from folium.map import Layer
from folium.utilities import image_to_url, mercator_transform
from jinja2 import Template
class ImageOverlay(Layer):
"""
Used to load and display a single image over specific bounds of
the map, implements ILayer interface.
Parameters
----------
image: string, file or array-like object
The data you want to draw on the map.
* If string, it will be written directly in the output file.
* If file, it's content will be converted as embedded in the output file.
* If array-like, it will be converted to PNG base64 string and embedded in the output.
bounds: list
Image bounds on the map in the form [[lat_min, lon_min],
[lat_max, lon_max]]
opacity: float, default Leaflet's default (1.0)
alt: string, default Leaflet's default ('')
# -*- coding: utf-8 -*-
from branca.element import CssLink, Figure, JavascriptLink
from folium.map import Layer
from folium.raster_layers import WmsTileLayer
from folium.utilities import parse_options
from jinja2 import Template
class TimestampedWmsTileLayers(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.
self.options = parse_options(
min_zoom=min_zoom,
max_zoom=max_zoom,
max_native_zoom=max_native_zoom or max_zoom,
no_wrap=no_wrap,
attribution=attr,
subdomains=subdomains,
detect_retina=detect_retina,
tms=tms,
opacity=opacity,
**kwargs
)
class WmsTileLayer(Layer):
"""
Creates a Web Map Service (WMS) layer.
Parameters
----------
url : str
The url of the WMS server.
layers : str
Comma-separated list of WMS layers to show.
styles : str, optional
Comma-separated list of WMS styles.
fmt : str, default 'image/jpeg'
The format of the service output. Ex: 'image/png'
transparent: bool, default False
Whether the layer shall allow transparency.
version : str, default '1.1.1'
# -*- coding: utf-8 -*-
from branca.element import Figure, JavascriptLink
from folium.features import GeoJson
from folium.map import Layer
from jinja2 import Template
class TimeSliderChoropleth(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.
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
from branca.element import CssLink, Figure, JavascriptLink
from folium.map import Icon, Layer, Marker, Popup
from folium.utilities import parse_options
from jinja2 import Template
class MarkerCluster(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
var embedSpec = {
mode: "vega-lite",
spec: {{this.json}}
};
vg.embed(
{{this.get_name()}}, embedSpec, function(error, result) {}
);
""").render(this=self)), name=self.get_name())
figure.header.add_child(JavascriptLink('https://d3js.org/d3.v3.min.js'), name='d3')
figure.header.add_child(JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/vega/2.6.5/vega.js'), name='vega') # noqa
figure.header.add_child(JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/vega-lite/1.3.1/vega-lite.js'), name='vega-lite') # noqa
figure.header.add_child(JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/vega-embed/2.2.0/vega-embed.js'), name='vega-embed') # noqa
class GeoJson(Layer):
"""
Creates a GeoJson object for plotting into a Map.
Parameters
----------
data: file, dict or str.
The GeoJSON 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.
style_function: function, default None
Function mapping a GeoJson Feature to a style dict.
highlight_function: function, default None
Function mapping a GeoJson Feature to a style dict for mouse events.
# -*- coding: utf-8 -*-
from branca.element import CssLink, Element, Figure, JavascriptLink
from folium.map import Layer
from folium.utilities import none_max, none_min
from jinja2 import Template
class HeatMapWithTime(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
def __init__(self, name=None, overlay=False, control=True, show=True):
super(Layer, self).__init__()
self.layer_name = name if name is not None else self.get_name()
self.overlay = overlay
self.control = control
self.show = show
@staticmethod
def _to_key(d):
"""Convert dict to str and enable Jinja2 template syntax."""
as_str = json.dumps(d, sort_keys=True)
return as_str.replace('"{{', '{{').replace('}}"', '}}')
@staticmethod
def _set_default_key(mapping):
"""Replace the field with the most features with a 'default' field."""
key_longest = sorted([(len(v), k) for k, v in mapping.items()],
reverse=True)[0][1]
mapping['default'] = key_longest
del (mapping[key_longest])
class TopoJson(Layer):
"""
Creates a TopoJson object for plotting into a Map.
Parameters
----------
data: file, dict or str.
The TopoJSON 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.
object_path: str
The path of the desired object into the TopoJson structure.
Ex: 'objects.myobject'.
style_function: function, default None
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
import json
from folium.map import Layer
from jinja2 import Template
class VideoOverlay(Layer):
"""
Used to load and display a video over the map.
Parameters
----------
video_url: URL of the video
bounds: list
Video bounds on the map in the form [[lat_min, lon_min],
[lat_max, lon_max]]
opacity: float, default Leaflet's default (1.0)
attr: string, default Leaflet's default ('')
"""
def __init__(self, video_url, bounds, opacity=1., attr=None,
autoplay=True, loop=True):
super(VideoOverlay, self).__init__()