-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__semicircle.py
105 lines (93 loc) · 3.8 KB
/
__semicircle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
import json
from branca.element import Figure, JavascriptLink
from folium.map import Marker
from folium.utilities import validate_location
from jinja2 import Template
class SemiCircle(Marker):
"""
Creates a Semicircle plugin to append into a map with
Map.add_plugin.
Use (direction and arc) or (startAngle and stopAngle)
Parameters
----------
location: tuple of length 2, default None
The latitude and longitude of the marker.
If None, then the middle of the map is used.
radius: int, default 0
Radius of semicircle
direction: int, default 0
Heading of direction angle value between 0 and 360 degrees
arc: int, default 0
Heading of arc angle value between 0 and 360 degrees.
startAngle: int, default 0
Heading of the start angle value between 0 and 360 degrees
stopAngle: int, default 0
Heading of the stop angle value between 0 and 360 degrees.
"""
_template = Template(u"""
{% macro script(this, kwargs) %}
if ({{this.direction}} || {{this.arc}}) {
var {{this.get_name()}} = L.semiCircle(
[{{this.location[0]}},{{this.location[1]}}],
{radius:{{this.radius}},
fill: {{this.fill}},
fillColor:'{{this.fill_color}}',
fillOpacity: {{this.fill_opacity}},
color: '{{this.color}}',
opacity: {{this.opacity}}
}).setDirection({{this.direction}},{{this.arc}})
.addTo({{this._parent.get_name()}});
} else if ({{this.startAngle}} || {{this.stopAngle}}) {
var {{this.get_name()}} = L.semiCircle(
[{{this.location[0]}},{{this.location[1]}}],
{radius:{{this.radius}},
fill: {{this.fill}},
fillColor:'{{this.fill_color}}',
fillOpacity: {{this.fill_opacity}},
color: '{{this.color}}',
opacity: {{this.opacity}},
startAngle:{{this.startAngle}},
stopAngle:{{this.stopAngle}}
})
.addTo({{this._parent.get_name()}});
}
{% endmacro %}
""")
def __init__(self,
location,
radius=0,
fill = True,
fill_color='#3388ff',
fill_opacity = 0.5,
color = '#3388ff',
opacity = 1,
direction=0,
arc=0,
startAngle=0,
stopAngle=0, **kwargs):
super(SemiCircle, self).__init__( validate_location(location), **kwargs)
self._name = 'SemiCircle'
self.radius = radius
if fill == True:
self.fill = 'true'
else: self.fill = 'false'
self.fill_color = fill_color
self.fill_opacity = fill_opacity
self.color = color
self.opacity = opacity
self.direction = direction
self.arc = arc
self.startAngle = startAngle
self.stopAngle = stopAngle
self.fill_color = fill_color
self.kwargs = json.dumps(kwargs)
def render(self, **kwargs):
super(SemiCircle, 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('http://jieter.github.io/Leaflet-semicircle/Semicircle.js'),
name='semicirclejs')