/
test_raster_layers.py
126 lines (97 loc) · 3.21 KB
/
test_raster_layers.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
"""
Test raster_layers
-----------------
"""
from __future__ import (absolute_import, division, print_function)
import folium
from jinja2 import Template
def test_tile_layer():
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
layer = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
folium.raster_layers.TileLayer(
tiles=layer,
name='OpenStreetMap',
attr='attribution'
).add_to(m)
folium.raster_layers.TileLayer(
tiles=layer,
name='OpenStreetMap2',
attr='attribution2',
overlay=True).add_to(m)
folium.LayerControl().add_to(m)
m._repr_html_()
bounds = m.get_bounds()
assert bounds == [[None, None], [None, None]], bounds
def _is_working_zoom_level(zoom, tiles, session):
"""Check if the zoom level works for the given tileset."""
url = tiles.format(s='a', x=0, y=0, z=zoom)
response = session.get(url, timeout=5)
if response.status_code < 400:
return True
return False
def test_custom_tile_subdomains():
"""Test custom tile subdomains."""
url = 'http://{s}.custom_tiles.org/{z}/{x}/{y}.png'
m = folium.Map(location=[45.52, -122.67], tiles=url,
attr='attribution',
subdomains='1234')
url_with_name = 'http://{s}.custom_tiles-subdomains.org/{z}/{x}/{y}.png'
tile_layer = folium.raster_layers.TileLayer(
tiles=url,
name='subdomains2',
attr='attribution',
subdomains='5678'
)
tile_layer.add_to(m)
m.add_tile_layer(
tiles=url_with_name, attr='attribution',
subdomains='9012'
)
out = m._parent.render()
assert '1234' in out
assert '5678' in out
assert '9012' in out
def test_wms():
m = folium.Map([40, -100], zoom_start=4)
url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
w = folium.raster_layers.WmsTileLayer(
url=url,
name='test',
fmt='image/png',
layers='nexrad-n0r-900913',
attr=u'Weather data © 2012 IEM Nexrad',
transparent=True
)
w.add_to(m)
m._repr_html_()
bounds = m.get_bounds()
assert bounds == [[None, None], [None, None]], bounds
def test_image_overlay():
"""Test image overlay."""
data = [[[1, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
[[1, 1, 0, 0.5], [0, 0, 1, 1], [0, 0, 1, 1]]]
m = folium.Map()
io = folium.raster_layers.ImageOverlay(
data, [[0, -180], [90, 180]],
mercator_project=True
)
io.add_to(m)
m._repr_html_()
out = m._parent.render()
# Verify the URL generation.
url = ('data:image/png;base64,'
'iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAA'
'AF0lEQVR42mP4z8AARFDw/z/DeiA5H4QBV60H6ABl9ZIAAAAASUVORK5CYII=')
assert io.url == url
# Verify the script part is okay.
tmpl = Template("""
var {{this.get_name()}} = L.imageOverlay(
'{{ this.url }}',
{{ this.bounds }},
{{ this.options }}
).addTo({{this._parent.get_name()}});
""")
assert tmpl.render(this=io) in out
bounds = m.get_bounds()
assert bounds == [[0, -180], [90, 180]], bounds