Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 55 additions & 36 deletions folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,99 @@
import sys
import warnings

import branca
from branca.colormap import (ColorMap, LinearColormap, StepColormap)
from branca.element import (CssLink, Div, Element, Figure, Html, IFrame,
JavascriptLink, Link, MacroElement)
from branca.element import (
CssLink,
Div,
Element,
Figure,
Html,
IFrame,
JavascriptLink,
Link,
MacroElement,
)

from folium._version import get_versions

from folium.features import (
ClickForMarker, ColorLine, CustomIcon, DivIcon, GeoJson,
LatLngPopup, RegularPolygonMarker, TopoJson, Vega, VegaLite,
GeoJsonTooltip, Choropleth
Choropleth,
ClickForMarker,
ColorLine,
CustomIcon,
DivIcon,
GeoJson,
LatLngPopup,
RegularPolygonMarker,
TopoJson,
Vega,
VegaLite,
)

from folium.raster_layers import TileLayer, WmsTileLayer

from folium.folium import Map

from folium.map import (
FeatureGroup, FitBounds, Icon, LayerControl, Marker, Popup, Tooltip
FeatureGroup,
FitBounds,
Icon,
LayerControl,
Marker,
Popup,
Tooltip,
)
from folium.raster_layers import TileLayer, WmsTileLayer
from folium.vector_layers import Circle, CircleMarker, PolyLine, Polygon, Rectangle

from folium.vector_layers import Circle, CircleMarker, PolyLine, Polygon, Rectangle # noqa

import branca
if tuple(int(x) for x in branca.__version__.split('.')[:2]) < (0, 3):
raise ImportError('branca version 0.3.0 or higher is required. '
'Update branca with e.g. `pip install branca --upgrade`.')

if sys.version_info < (3, 0):
warnings.warn(
("folium will stop working with Python 2.7 starting Jan. 1, 2019."
" Please transition to Python 3 before this time."
" Check out https://python3statement.org/ for more info."),
('folium will stop working with Python 2.7 starting Jan. 1, 2019.'
' Please transition to Python 3 before this time.'
' Check out https://python3statement.org/ for more info.'),
PendingDeprecationWarning
)

__version__ = get_versions()['version']
del get_versions

__all__ = [
'Choropleth',
'ClickForMarker',
'ColorLine',
'ColorMap',
'CssLink',
'CustomIcon',
'Div',
'DivIcon',
'Element',
'FeatureGroup',
'Figure',
'FitBounds',
'GeoJson',
'GeoJsonStyle',
'GeoJsonTooltip',
'Html',
'IFrame',
'Icon',
'JavascriptLink',
'LatLngPopup',
'LayerControl',
'LinearColormap',
'Link',
'MacroElement',
'ColorMap',
'ColorLine',
'LinearColormap',
'StepColormap',
'Map',
'FeatureGroup',
'FitBounds',
'Icon',
'LayerControl',
'Marker',
'MarkerCluster',
'Popup',
'Tooltip',
'RegularPolygonMarker',
'StepColormap',
'TileLayer',
'ClickForMarker',
'CustomIcon',
'DivIcon',
'GeoJson',
'GeoJsonStyle',
'LatLngPopup',
'MarkerCluster',
'Tooltip',
'TopoJson',
'Vega',
'VegaLite',
'RegularPolygonMarker',
'TopoJson',
'WmsTileLayer',
'Choropleth',
# vector_layers
'Circle',
'CircleMarker',
Expand Down
46 changes: 26 additions & 20 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@
import json
import warnings

import requests
import numpy as np

from branca.colormap import LinearColormap, StepColormap
from branca.element import (Element, Figure, JavascriptLink, MacroElement)
from branca.utilities import (_locations_tolist, _parse_size, image_to_url,
none_max, none_min, color_brewer)
from branca.utilities import color_brewer

from folium.folium import Map
from folium.map import (FeatureGroup, Icon, Layer, Marker, Tooltip)

from folium.utilities import get_bounds
from folium.utilities import (
_iter_tolist,
_parse_size,
get_bounds,
image_to_url,
none_max,
none_min,
)
from folium.vector_layers import PolyLine

from jinja2 import Template

import numpy as np

import requests

from six import binary_type, text_type


Expand Down Expand Up @@ -84,7 +90,7 @@ def __init__(self, location, color='black', opacity=1, weight=2,
fill_color='blue', fill_opacity=1, number_of_sides=4,
rotation=0, radius=15, popup=None, tooltip=None):
super(RegularPolygonMarker, self).__init__(
_locations_tolist(location),
_iter_tolist(location),
popup=popup, tooltip=tooltip
)
self._name = 'RegularPolygonMarker'
Expand Down Expand Up @@ -684,26 +690,26 @@ def __init__(self, fields, aliases=None, labels=True,
super(GeoJsonTooltip, self).__init__(
text='', style=style, sticky=sticky, **kwargs
)
self._name = "GeoJsonTooltip"
self._name = 'GeoJsonTooltip'

assert isinstance(fields, (list, tuple)), "Please pass a list or " \
"tuple to fields."
assert isinstance(fields, (list, tuple)), 'Please pass a list or ' \
'tuple to fields.'
if aliases is not None:
assert isinstance(aliases, (list, tuple))
assert len(fields) == len(aliases), "fields and aliases must have" \
" the same length."
assert isinstance(labels, bool), "labels requires a boolean value."
assert isinstance(localize, bool), "localize must be bool."
assert 'permanent' not in kwargs, "The `permanent` option does not " \
"work with GeoJsonTooltip."
assert len(fields) == len(aliases), 'fields and aliases must have' \
' the same length.'
assert isinstance(labels, bool), 'labels requires a boolean value.'
assert isinstance(localize, bool), 'localize must be bool.'
assert 'permanent' not in kwargs, 'The `permanent` option does not ' \
'work with GeoJsonTooltip.'

self.fields = fields
self.aliases = aliases
self.labels = labels
self.localize = localize
if style:
assert isinstance(style, str), \
"Pass a valid inline HTML style property string to style."
'Pass a valid inline HTML style property string to style.'
# noqa outside of type checking.
self.style = style

Expand All @@ -720,8 +726,8 @@ def render(self, **kwargs):
'than a GeoJson or TopoJson object.')
keys = tuple(x for x in keys if x not in ('style', 'highlight'))
for value in self.fields:
assert value in keys, ("The field {} is not available in the data. "
"Choose from: {}.".format(value, keys))
assert value in keys, ('The field {} is not available in the data. '
'Choose from: {}.'.format(value, keys))
super(GeoJsonTooltip, self).render(**kwargs)


Expand Down
3 changes: 1 addition & 2 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
import warnings

from branca.element import CssLink, Element, Figure, JavascriptLink, MacroElement
from branca.utilities import _parse_size

from folium.map import FitBounds
from folium.raster_layers import TileLayer
from folium.utilities import _validate_location
from folium.utilities import _parse_size, _validate_location

from jinja2 import Environment, PackageLoader, Template

Expand Down
29 changes: 14 additions & 15 deletions folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from __future__ import (absolute_import, division, print_function)

import json

from collections import OrderedDict

from branca.element import CssLink, Element, Figure, Html, JavascriptLink, MacroElement # noqa

from folium.utilities import _validate_coordinates, get_bounds, camelize
from folium.utilities import _validate_coordinates, camelize, get_bounds

from jinja2 import Template

Expand Down Expand Up @@ -371,20 +370,20 @@ class Tooltip(MacroElement):
{% endmacro %}
""")
valid_options = {
"pane": (str, ),
"offset": (tuple, ),
"direction": (str, ),
"permanent": (bool, ),
"sticky": (bool, ),
"interactive": (bool, ),
"opacity": (float, int),
"attribution": (str, ),
"className": (str, ),
'pane': (str, ),
'offset': (tuple, ),
'direction': (str, ),
'permanent': (bool, ),
'sticky': (bool, ),
'interactive': (bool, ),
'opacity': (float, int),
'attribution': (str, ),
'className': (str, ),
}

def __init__(self, text, style=None, sticky=True, **kwargs):
super(Tooltip, self).__init__()
self._name = "Tooltip"
self._name = 'Tooltip'

self.text = str(text)

Expand All @@ -393,7 +392,7 @@ def __init__(self, text, style=None, sticky=True, **kwargs):

if style:
assert isinstance(style, str), \
"Pass a valid inline HTML style property string to style."
'Pass a valid inline HTML style property string to style.'
# noqa outside of type checking.
self.style = style

Expand All @@ -402,11 +401,11 @@ def parse_options(self, kwargs):
kwargs = {camelize(key): value for key, value in kwargs.items()}
for key in kwargs.keys():
assert key in self.valid_options, (
"The option {} is not in the available options: {}."
'The option {} is not in the available options: {}.'
.format(key, ', '.join(self.valid_options))
)
assert isinstance(kwargs[key], self.valid_options[key]), (
"The option {} must be one of the following types: {}."
'The option {} must be one of the following types: {}.'
.format(key, self.valid_options[key])
)
return json.dumps(kwargs)
Expand Down
8 changes: 4 additions & 4 deletions folium/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
from folium.plugins.heat_map_withtime import HeatMapWithTime
from folium.plugins.marker_cluster import MarkerCluster
from folium.plugins.measure_control import MeasureControl
from folium.plugins.minimap import MiniMap
from folium.plugins.mouse_position import MousePosition
from folium.plugins.polyline_text_path import PolyLineTextPath
from folium.plugins.scroll_zoom_toggler import ScrollZoomToggler
from folium.plugins.search import Search
from folium.plugins.terminator import Terminator
from folium.plugins.time_slider_choropleth import TimeSliderChoropleth
from folium.plugins.timestamped_geo_json import TimestampedGeoJson
from folium.plugins.timestamped_wmstilelayer import TimestampedWmsTileLayers
from folium.plugins.search import Search
from folium.plugins.minimap import MiniMap

__all__ = [
'BeautifyIcon',
Expand All @@ -43,13 +43,13 @@
'HeatMapWithTime',
'MarkerCluster',
'MeasureControl',
'MiniMap',
'MousePosition',
'PolyLineTextPath',
'ScrollZoomToggler',
'Search',
'Terminator',
'TimeSliderChoropleth',
'TimestampedGeoJson',
'TimestampedWmsTileLayers',
'Search',
'MiniMap',
]
6 changes: 3 additions & 3 deletions folium/plugins/beautify_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import json

from branca.element import Figure, JavascriptLink, CssLink, MacroElement

from six import iteritems
from branca.element import CssLink, Figure, JavascriptLink, MacroElement

from jinja2 import Template

from six import iteritems


class BeautifyIcon(MacroElement):
"""
Expand Down
4 changes: 2 additions & 2 deletions folium/plugins/heat_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import json

from branca.element import Figure, JavascriptLink
from branca.utilities import none_max, none_min

from folium.map import Layer
from folium.utilities import _isnan
from folium.utilities import _isnan, _iter_tolist, none_max, none_min

from jinja2 import Template

Expand Down Expand Up @@ -65,6 +64,7 @@ def __init__(self, data, name=None, min_opacity=0.5, max_zoom=18,
overlay=True, control=True, show=True):
super(HeatMap, self).__init__(name=name, overlay=overlay,
control=control, show=show)
data = _iter_tolist(data)
if _isnan(data):
raise ValueError('data cannot contain NaNs, '
'got:\n{!r}'.format(data))
Expand Down
2 changes: 1 addition & 1 deletion folium/plugins/heat_map_withtime.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

from branca.element import CssLink, Element, Figure, JavascriptLink
from branca.utilities import none_max, none_min

from folium.map import Layer
from folium.utilities import none_max, none_min

from jinja2 import Template

Expand Down
3 changes: 2 additions & 1 deletion folium/plugins/marker_cluster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function

import json

from branca.element import CssLink, Figure, JavascriptLink
Expand Down
Loading