-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
test_pattern.py
49 lines (35 loc) · 1.32 KB
/
test_pattern.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
# -*- coding: utf-8 -*-
"""
Test pattern
---------------
"""
import os
import folium
from folium import plugins
from folium.utilities import normalize
def test_pattern():
m = folium.Map([40., -105.], zoom_start=6)
stripes = plugins.pattern.StripePattern(angle=-45)
stripes.add_to(m)
circles = plugins.pattern.CirclePattern(width=20, height=20, radius=5,
fill_opacity=0.5, opacity=1)
def style_function(feature):
default_style = {
'opacity': 1.0,
'fillColor': '#ffff00',
'color': 'black',
'weight': 2
}
if feature['properties']['name'] == 'Colorado':
default_style['fillPattern'] = stripes
default_style['fillOpacity'] = 1.0
if feature['properties']['name'] == 'Utah':
default_style['fillPattern'] = circles
default_style['fillOpacity'] = 1.0
return default_style
data = os.path.join(os.path.dirname(__file__), os.pardir, 'us-states.json')
folium.GeoJson(data, style_function=style_function).add_to(m)
out = normalize(m._parent.render())
# We verify that the script import is present.
script = '<script src="https://teastman.github.io/Leaflet.pattern/leaflet.pattern.js"></script>' # noqa
assert script in out