-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
test_timestamped_geo_json.py
170 lines (155 loc) · 6.7 KB
/
test_timestamped_geo_json.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# -*- coding: utf-8 -*-
"""
Test TimestampedGeoJson
-----------------------
"""
import folium
from folium import plugins
from folium.utilities import normalize
from jinja2 import Template
import numpy as np
def test_timestamped_geo_json():
coordinates = [[[[lon-8*np.sin(theta), -47+6*np.cos(theta)] for
theta in np.linspace(0, 2*np.pi, 25)],
[[lon-4*np.sin(theta), -47+3*np.cos(theta)] for theta
in np.linspace(0, 2*np.pi, 25)]] for
lon in np.linspace(-150, 150, 7)]
data = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [0, 0],
},
'properties': {
'times': [1435708800000+12*86400000]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'MultiPoint',
'coordinates': [[lon, -25] for
lon in np.linspace(-150, 150, 49)],
},
'properties': {
'times': [1435708800000+i*86400000 for
i in np.linspace(0, 25, 49)]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [[lon, 25] for
lon in np.linspace(-150, 150, 25)],
},
'properties': {
'times': [1435708800000+i*86400000 for
i in np.linspace(0, 25, 25)],
'style': {
'color': 'red'
},
},
},
{
'type': 'Feature',
'geometry': {
'type': 'MultiLineString',
'coordinates': [[[lon-4*np.sin(theta),
47+3*np.cos(theta)] for theta
in np.linspace(0, 2*np.pi, 25)]
for lon in
np.linspace(-150, 150, 13)],
},
'properties': {
'times': [1435708800000+i*86400000 for
i in np.linspace(0, 25, 13)]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': coordinates,
},
'properties': {
'times': [1435708800000+i*86400000 for
i in np.linspace(0, 25, 7)]
}
},
],
}
m = folium.Map([47, 3], zoom_start=1)
tgj = plugins.TimestampedGeoJson(data).add_to(m)
out = normalize(m._parent.render())
# Verify the imports.
assert '<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>' in out
assert '<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>' in out
assert '<script src="https://rawcdn.githack.com/nezasa/iso8601-js-period/master/iso8601.min.js"></script>' in out
assert '<script src="https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js"></script>' in out # noqa
assert '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css"/>' in out # noqa
assert '<link rel="stylesheet" href="https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.control.min.css"/>' in out # noqa
assert '<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>' in out
# Verify that the script is okay.
tmpl = Template("""
L.Control.TimeDimensionCustom = L.Control.TimeDimension.extend({
_getDisplayDateFormat: function(date){
var newdate = new moment(date);
console.log(newdate)
return newdate.format("{{this.date_options}}");
}
});
{{this._parent.get_name()}}.timeDimension = L.timeDimension(
{
period: {{ this.period|tojson }},
}
);
var timeDimensionControl = new L.Control.TimeDimensionCustom(
{{ this.options|tojson }}
);
{{this._parent.get_name()}}.addControl(this.timeDimensionControl);
var geoJsonLayer = L.geoJson({{this.data}}, {
pointToLayer: function (feature, latLng) {
if (feature.properties.icon == 'marker') {
if(feature.properties.iconstyle){
return new L.Marker(latLng, {
icon: L.icon(feature.properties.iconstyle)});
}
//else
return new L.Marker(latLng);
}
if (feature.properties.icon == 'circle') {
if (feature.properties.iconstyle) {
return new L.circleMarker(latLng, feature.properties.iconstyle)
};
//else
return new L.circleMarker(latLng);
}
//else
return new L.Marker(latLng);
},
style: function (feature) {
return feature.properties.style;
},
onEachFeature: function(feature, layer) {
if (feature.properties.popup) {
layer.bindPopup(feature.properties.popup);
}
}
})
var {{this.get_name()}} = L.timeDimension.layer.geoJson(
geoJsonLayer,
{
updateTimeDimension: true,
addlastPoint: {{ this.add_last_point|tojson }},
duration: {{ this.duration }},
}
).addTo({{this._parent.get_name()}});
""") # noqa
expected = normalize(tmpl.render(this=tgj))
assert expected in out
bounds = m.get_bounds()
assert bounds == [[-53.0, -158.0], [50.0, 158.0]], bounds