|
5 | 5 |
|
6 | 6 | Extra features Elements. |
7 | 7 | """ |
8 | | -from jinja2 import Template |
9 | 8 | import json |
10 | 9 |
|
11 | | -from branca.utilities import (_parse_size, |
12 | | - _locations_mirror, _locations_tolist, image_to_url, |
13 | | - text_type, binary_type, |
14 | | - none_min, none_max, iter_points, |
15 | | - ) |
16 | | -from branca.element import Element, Figure, JavascriptLink, CssLink, MacroElement |
| 10 | +from jinja2 import Template |
| 11 | +from six import text_type |
| 12 | + |
| 13 | +from branca.utilities import ( |
| 14 | + _parse_size, _locations_mirror, _locations_tolist, image_to_url, |
| 15 | + binary_type, none_min, none_max, iter_points, |
| 16 | +) |
| 17 | +from branca.element import (Element, Figure, JavascriptLink, CssLink, |
| 18 | + MacroElement) |
17 | 19 | from branca.colormap import LinearColormap |
18 | 20 |
|
19 | 21 | from .map import Layer, Icon, Marker, Popup, FeatureGroup |
@@ -762,13 +764,14 @@ def __init__(self, bounds, color='black', weight=1, fill_color='black', |
762 | 764 | self.fill_opacity = fill_opacity |
763 | 765 | self._template = Template(u""" |
764 | 766 | {% macro script(this, kwargs) %} |
765 | | - var {{this.get_name()}} = L.rectangle([[{{this.location[0]}}, {{this.location[1]}}], |
766 | | - [{{this.location[2]}}, {{this.location[3]}}]], |
| 767 | + var {{this.get_name()}} = L.rectangle( |
| 768 | + [[{{this.location[0]}},{{this.location[1]}}], |
| 769 | + [{{this.location[2]}},{{this.location[3]}}]], |
767 | 770 | { |
768 | | - color:'{{ this.color }}', |
769 | | - fillColor:'{{ this.fill_color }}', |
770 | | - fillOpacity:{{ this.fill_opacity }}, |
771 | | - weight:{{ this.weight }} |
| 771 | + color: '{{ this.color }}', |
| 772 | + fillColor: '{{ this.fill_color }}', |
| 773 | + fillOpacity: {{ this.fill_opacity }}, |
| 774 | + weight: {{ this.weight }} |
772 | 775 | }).addTo({{this._parent.get_name()}}); |
773 | 776 |
|
774 | 777 | {% endmacro %} |
@@ -799,18 +802,21 @@ def __init__(self, locations, color='black', weight=1, fill_color='black', |
799 | 802 | ------- |
800 | 803 | folium.features.Polygon object |
801 | 804 |
|
802 | | - Example |
803 | | - ------- |
804 | | - >>> loc= [[35.6762, 139.7795], |
805 | | - [35.6718, 139.7831], |
806 | | - [35.6767, 139.7868], |
807 | | - [35.6795, 139.7824], |
808 | | - [35.6787, 139.7791]] |
809 | | - Polygon(loc, color="blue", weight=10, fill_color="red", |
810 | | - fill_opacity=0.5, popup="Tokyo, Japan")) |
| 805 | + Examples |
| 806 | + -------- |
| 807 | + >>> loc = [[35.6762, 139.7795], |
| 808 | + ... [35.6718, 139.7831], |
| 809 | + ... [35.6767, 139.7868], |
| 810 | + ... [35.6795, 139.7824], |
| 811 | + ... [35.6787, 139.7791]] |
| 812 | + >>> Polygon(loc, color="blue", weight=10, fill_color="red", |
| 813 | + ... fill_opacity=0.5, popup="Tokyo, Japan")) |
| 814 | +
|
811 | 815 | """ |
812 | | - super(Polygon, self).__init__((_locations_mirror(locations) if not latlon else |
813 | | - _locations_tolist(locations)), popup=popup) |
| 816 | + super(Polygon, self).__init__(( |
| 817 | + _locations_mirror(locations) if not latlon else |
| 818 | + _locations_tolist(locations)), popup=popup |
| 819 | + ) |
814 | 820 | self._name = 'Polygon' |
815 | 821 | self.color = color |
816 | 822 | self.weight = weight |
@@ -1096,12 +1102,11 @@ class ColorLine(FeatureGroup): |
1096 | 1102 | The list of segments colors. |
1097 | 1103 | It must have length equal to `len(positions)-1`. |
1098 | 1104 | colormap: branca.colormap.Colormap or list or tuple |
1099 | | - The colormap to use. |
1100 | | - If a list or tuple of colors is provided, a LinearColormap will be created |
1101 | | - from it. |
| 1105 | + The colormap to use. If a list or tuple of colors is provided, |
| 1106 | + a LinearColormap will be created from it. |
1102 | 1107 | nb_steps: int, default 12 |
1103 | | - To have lighter output, the colormap will be discretized to that number |
1104 | | - of colors. |
| 1108 | + To have lighter output the colormap will be discretized |
| 1109 | + to that number of colors. |
1105 | 1110 | opacity: float, default 1 |
1106 | 1111 | Line opacity, scale 0-1 |
1107 | 1112 | weight: int, default 2 |
@@ -1133,7 +1138,8 @@ def __init__(self, positions, colors, colormap=None, nb_steps=12, |
1133 | 1138 | else: |
1134 | 1139 | cm = colormap |
1135 | 1140 | out = {} |
1136 | | - for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors): |
| 1141 | + for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors): # noqa |
1137 | 1142 | out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]]) |
1138 | 1143 | for key, val in out.items(): |
1139 | | - self.add_child(MultiPolyLine(val, color=key, weight=weight, opacity=opacity)) |
| 1144 | + self.add_child(MultiPolyLine(val, color=key, |
| 1145 | + weight=weight, opacity=opacity)) |
0 commit comments