Skip to content

Fix lints #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2016
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
68 changes: 37 additions & 31 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

Extra features Elements.
"""
from jinja2 import Template
import json

from branca.utilities import (_parse_size,
_locations_mirror, _locations_tolist, image_to_url,
text_type, binary_type,
none_min, none_max, iter_points,
)
from branca.element import Element, Figure, JavascriptLink, CssLink, MacroElement
from jinja2 import Template
from six import text_type

from branca.utilities import (
_parse_size, _locations_mirror, _locations_tolist, image_to_url,
binary_type, none_min, none_max, iter_points,
)
from branca.element import (Element, Figure, JavascriptLink, CssLink,
MacroElement)
from branca.colormap import LinearColormap

from .map import Layer, Icon, Marker, Popup, FeatureGroup
Expand Down Expand Up @@ -762,13 +764,14 @@ def __init__(self, bounds, color='black', weight=1, fill_color='black',
self.fill_opacity = fill_opacity
self._template = Template(u"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = L.rectangle([[{{this.location[0]}}, {{this.location[1]}}],
[{{this.location[2]}}, {{this.location[3]}}]],
var {{this.get_name()}} = L.rectangle(
[[{{this.location[0]}},{{this.location[1]}}],
[{{this.location[2]}},{{this.location[3]}}]],
{
color:'{{ this.color }}',
fillColor:'{{ this.fill_color }}',
fillOpacity:{{ this.fill_opacity }},
weight:{{ this.weight }}
color: '{{ this.color }}',
fillColor: '{{ this.fill_color }}',
fillOpacity: {{ this.fill_opacity }},
weight: {{ this.weight }}
}).addTo({{this._parent.get_name()}});

{% endmacro %}
Expand Down Expand Up @@ -799,18 +802,21 @@ def __init__(self, locations, color='black', weight=1, fill_color='black',
-------
folium.features.Polygon object

Example
-------
>>> loc= [[35.6762, 139.7795],
[35.6718, 139.7831],
[35.6767, 139.7868],
[35.6795, 139.7824],
[35.6787, 139.7791]]
Polygon(loc, color="blue", weight=10, fill_color="red",
fill_opacity=0.5, popup="Tokyo, Japan"))
Examples
--------
>>> loc = [[35.6762, 139.7795],
... [35.6718, 139.7831],
... [35.6767, 139.7868],
... [35.6795, 139.7824],
... [35.6787, 139.7791]]
>>> Polygon(loc, color="blue", weight=10, fill_color="red",
... fill_opacity=0.5, popup="Tokyo, Japan"))

"""
super(Polygon, self).__init__((_locations_mirror(locations) if not latlon else
_locations_tolist(locations)), popup=popup)
super(Polygon, self).__init__((
_locations_mirror(locations) if not latlon else
_locations_tolist(locations)), popup=popup
)
self._name = 'Polygon'
self.color = color
self.weight = weight
Expand Down Expand Up @@ -1096,12 +1102,11 @@ class ColorLine(FeatureGroup):
The list of segments colors.
It must have length equal to `len(positions)-1`.
colormap: branca.colormap.Colormap or list or tuple
The colormap to use.
If a list or tuple of colors is provided, a LinearColormap will be created
from it.
The colormap to use. If a list or tuple of colors is provided,
a LinearColormap will be created from it.
nb_steps: int, default 12
To have lighter output, the colormap will be discretized to that number
of colors.
To have lighter output the colormap will be discretized
to that number of colors.
opacity: float, default 1
Line opacity, scale 0-1
weight: int, default 2
Expand Down Expand Up @@ -1133,7 +1138,8 @@ def __init__(self, positions, colors, colormap=None, nb_steps=12,
else:
cm = colormap
out = {}
for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors):
for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors): # noqa
out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
for key, val in out.items():
self.add_child(MultiPolyLine(val, color=key, weight=weight, opacity=opacity))
self.add_child(MultiPolyLine(val, color=key,
weight=weight, opacity=opacity))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Jinja2
branca
six
7 changes: 4 additions & 3 deletions tests/test_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import branca.element

from folium.map import Popup, Marker, FitBounds, FeatureGroup
from folium.features import GeoJson, TopoJson, PolyLine, MultiPolyLine, RectangleMarker, Polygon
from folium.features import (GeoJson, TopoJson, PolyLine, MultiPolyLine,
RectangleMarker, Polygon)
from folium.plugins import ImageOverlay

rootpath = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -455,12 +456,12 @@ def test_geo_json_str(self):

out = ''.join(self.map._parent.render().split())

# Verify the geo_json object
# Verify the geo_json object.
obj_temp = jinja2.Template("""
var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
.addTo({{ this._parent.get_name() }});
{{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
""")
""") # noqa
obj = obj_temp.render(this=geo_json, json=json)
assert ''.join(obj.split())[:-1] in out

Expand Down