Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
""") # noqa
def __init__(self, html=None, icon_size=None, icon_anchor=None,
popup_anchor=None, class_name='empty'):
super(DivIcon, self).__init__()
self._name = 'DivIcon'
self.options = parse_options(
html=html,
icon_size=icon_size,
icon_anchor=icon_anchor,
popup_anchor=popup_anchor,
class_name=class_name,
)
class LatLngPopup(MacroElement):
"""
When one clicks on a Map that contains a LatLngPopup,
a popup is shown that displays the latitude and longitude of the pointer.
"""
_template = Template(u"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = L.popup();
function latLngPop(e) {
{{this.get_name()}}
.setLatLng(e.latlng)
.setContent("Latitude: " + e.latlng.lat.toFixed(4) +
"<br>Longitude: " + e.latlng.lng.toFixed(4))
.openOn({{this._parent.get_name()}});
}
{{this._parent.get_name()}}.on('click', latLngPop);
Classes for drawing maps.
"""
from collections import OrderedDict
import warnings
from branca.element import Element, Figure, Html, MacroElement
from folium.utilities import validate_location, camelize, parse_options
from jinja2 import Template
class Layer(MacroElement):
"""An abstract class for everything that is a Layer on the map.
It will be used to define whether an object will be included in
LayerControls.
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.
show: bool, default True
Whether the layer will be shown on opening (only for overlays).
"""
def __init__(self, name=None, overlay=False, control=True, show=True):
# -*- coding: utf-8 -*-
from branca.element import Figure, JavascriptLink, MacroElement
from jinja2 import Template
class Terminator(MacroElement):
"""
Leaflet.Terminator is a simple plug-in to the Leaflet library to
overlay day and night regions on maps.
"""
_template = Template(u"""
{% macro script(this, kwargs) %}
L.terminator().addTo({{this._parent.get_name()}});
{% endmacro %}
""")
def __init__(self):
super(Terminator, self).__init__()
self._name = 'Terminator'
def render(self, **kwargs):
# -*- coding: utf-8 -*-
from branca.element import CssLink, Figure, JavascriptLink, MacroElement
from jinja2 import Template
from folium import Map
from folium.features import FeatureGroup, GeoJson, TopoJson
from folium.plugins import MarkerCluster
from folium.utilities import parse_options
class Search(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'
super(Icon, self).__init__()
self._name = 'Icon'
if color not in self.color_options:
warnings.warn('color argument of Icon should be one of: {}.'
.format(self.color_options), stacklevel=2)
self.options = parse_options(
marker_color=color,
icon_color=icon_color,
icon=icon,
prefix=prefix,
extra_classes='fa-rotate-{}'.format(angle),
**kwargs
)
class Marker(MacroElement):
"""
Create a simple stock Leaflet marker on the map, with optional
popup text or Vincent visualization.
Parameters
----------
location: tuple or list
Latitude and Longitude of Marker (Northing, Easting)
popup: string or folium.Popup, default None
Label for the Marker; either an escaped HTML string to initialize
folium.Popup or a folium.Popup instance.
tooltip: str or folium.Tooltip, default None
Display a text when hovering over the object.
icon: Icon plugin
the Icon plugin to use to render the marker.
draggable: bool, default False
{{this.get_name()}}
.setLatLng(e.latlng)
.setContent("Latitude: " + e.latlng.lat.toFixed(4) +
"<br>Longitude: " + e.latlng.lng.toFixed(4))
.openOn({{this._parent.get_name()}});
}
{{this._parent.get_name()}}.on('click', latLngPop);
{% endmacro %}
""") # noqa
def __init__(self):
super(LatLngPopup, self).__init__()
self._name = 'LatLngPopup'
class ClickForMarker(MacroElement):
"""
When one clicks on a Map that contains a ClickForMarker,
a Marker is created at the pointer's position.
Parameters
----------
popup: str, default None
Text to display in the markers' popups.
If None, the popups will display the marker's latitude and longitude.
"""
_template = Template(u"""
{% macro script(this, kwargs) %}
function newMarker(e){
var new_mark = L.marker().setLatLng(e.latlng).addTo({{this._parent.get_name()}});
new_mark.dragging.enable();
' d["{{this.kwargs.get("fillRule")[8:]}}"]'
' {% else %}"{{this.kwargs.get("fillRule")}}"{% endif %},'
' {% endif %}'
' })'
'{% if this.radius %}.setRadius('
'{% if this.radius.__str__().startswith("feature.") %}d["{{this.radius[8:]}}"]' # noqa
' {% else %}{{this.radius}}{% endif %}'
'){% endif %}'
'{% if this.popup %}.bindPopup(d["{{this.popup}}"]){% endif %}'
';}'
'{% endmacro %}'
)
class AwesomeMarkerFunction(MacroElement):
"""A circleMarker with radius specified in pixels (or in meters).
Parameters
----------
lat : str, default 'lat'
The name of the latitude column in the data set.
lng : str, default 'lng'
The name of the longitude column in the data set.
popup: str, default None
The name of (eventual) popup string in the data set.
radius: int, default 10
To specify the radius (in pixels) of cirlces.
radius_meter: bool, default False
If True, the radius is specified in meters so that the circles will
grow when you zoom in.
If False, the radius is in pixels.
self.add_child(self.geojson)
if self.color_scale:
self.add_child(self.color_scale)
def render(self, **kwargs):
"""Render the GeoJson/TopoJson and color scale objects."""
if self.color_scale:
# ColorMap needs Map as its parent
assert isinstance(self._parent, Map), ('Choropleth must be added'
' to a Map object.')
self.color_scale._parent = self._parent
super(Choropleth, self).render(**kwargs)
class DivIcon(MacroElement):
"""
Represents a lightweight icon for markers that uses a simple `div`
element instead of an image.
Parameters
----------
icon_size : tuple of 2 int
Size of the icon image in pixels.
icon_anchor : tuple of 2 int
The coordinates of the "tip" of the icon
(relative to its top left corner).
The icon will be aligned so that this point is at the
marker's geographical location.
popup_anchor : tuple of 2 int
The coordinates of the point from which popups will "open",
relative to the icon anchor.
# -*- coding: utf-8 -*-
from branca.element import CssLink, Figure, JavascriptLink, MacroElement
from folium.raster_layers import TileLayer
from folium.utilities import parse_options
from jinja2 import Template
class MiniMap(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
def render(self, **kwargs):
self.parent_map = get_obj_in_upper_tree(self, Map)
super(StripePattern, self).render(**kwargs)
figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')
figure.header.add_child(
JavascriptLink('https://teastman.github.io/Leaflet.pattern/leaflet.pattern.js'), # noqa
name='pattern'
)
class CirclePattern(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.