-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-oat.htm
216 lines (170 loc) · 6.63 KB
/
demo-oat.htm
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<html>
<head><title>OGC API - Tiles Styling</title></head>
<body>
<div id="map" style="width:100vw;height:100vh;"></div>
<!-- load leaflet -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<!-- load VectorGrid extension -->
<script src="https://unpkg.com/[email protected]/dist/Leaflet.VectorGrid.bundled.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css" />
<a class="github-fork-ribbon" href="https://github.com/emotional-cities/vtiles-example.git" data-ribbon="Fork me on GitHub" title="Fork me on GitHub">Fork me on GitHub</a>
<script>
function getCollection(url) {
pUrl = url.substr(0, url.indexOf('tiles')-1);
console.log(pUrl);
return pUrl;
}
function getColor_cardio(val){
return val < 0.5 ? "#DAF7A6":
val < 1 ? "#FFC300":
val < 1.5 ? "#FF5733":
val < 2 ? "#C70039":
"#900C3F";
}
function getColor_pm10(val){
return val < 0.25 ? "#00ffbf":
val < 0.35 ? "#0ad553":
val < 0.45 ? "#34bb30":
"#6f7874";
}
var vectorTileStyling = {
meta: function(properties) {
return ({
fill: false,
fillColor: "#ffffff",
fillOpacity: 0.0,
weight: 0,
color: "green",
opacity: 0,
});
},
hits: function(properties) {
console.log(properties)
val = properties["properties.wprev_mean"]
return ({
fill: true,
fillColor: getColor_cardio(val),
fillOpacity: 0.7,
weight: 1,
color: "#B29071",
opacity: 1,
});
}
}
var vectorTileStyling2 = {
meta: function(properties) {
return ({
fill: false,
fillColor: "#ffffff",
fillOpacity: 0.0,
weight: 0,
color: "green",
opacity: 0,
});
},
hits: function(properties) {
//console.log(properties)
val = properties["properties.green_infrastructure_metric_table metric_table_cln_no2_mean_prop"]
return ({
fill: true,
fillColor: getColor_pm10(val),
fillOpacity: 0.7,
weight: 1,
color: "#B29071",
opacity: 1,
});
}
}
var mapVectorTileOptions = {
rendererFactory: L.canvas.tile,
interactive: true,
vectorTileLayerStyles: vectorTileStyling,
};
var mapVectorTileOptions2 = {
rendererFactory: L.canvas.tile,
interactive: true,
vectorTileLayerStyles: vectorTileStyling2,
};
var pbfURL_cardio = 'https://emotional.byteroad.net/collections/hex350_grid_cardio_1920/tiles/WebMercatorQuad/{z}/{x}/{y}?f=mvt';
var pbfURL_pm10 = 'https://emotional.byteroad.net/collections/hex350_grid_pm10_2019/tiles/WebMercatorQuad/{z}/{x}/{y}?f=mvt';
// create VectorGrid layers
var mapPbfLayer_cardio = new L.VectorGrid.Protobuf(
pbfURL_cardio, mapVectorTileOptions
);
var mapPbfLayer_pm10 = new L.VectorGrid.Protobuf(
pbfURL_pm10, mapVectorTileOptions2
);
var World_Light_Gray_Base =
new L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Esri, DeLorme, NAVTEQ',
minZoom: 1,
maxZoom: 16
});
var OpenStreetMap_Mapnik = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
let start = Date.now();
/* (async () => {
const border = await fetch('https://emotional.byteroad.net/collections/hex350_grid_cardio_1920/items?limit=5000', {
headers: {
'Accept': 'application/geo+json'
}
}).then(response => response.json());
var f_cardio = L.geoJSON(border);
(async () => {
const border = await fetch('https://emotional.byteroad.net/collections/hex350_grid_pm10_2019/items?limit=5000', {
headers: {
'Accept': 'application/geo+json'
}
}).then(response => response.json());
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var f_pm10 = L.geoJSON(border, {style: myStyle});
map = L.map('map', {layers: [World_Light_Gray_Base, f_cardio, f_pm10]}).setView({ lng: -0.0575, lat: 51.50722 }, 11);
var overlayMaps = {
"Prevalence rates of cardiovascular diseases": f_cardio,
"Annual mean PM10 based on output areas average concentrations": f_pm10,
};
var baseMaps = {
"OpenStreetMap": OpenStreetMap_Mapnik,
"Esri World Gray Canvas": World_Light_Gray_Base
};
var layerControl = L.control.layers(baseMaps, overlayMaps).addTo(map);
let timeTaken = Date.now() - start;
console.log("Total time taken : " + timeTaken + " milliseconds"); //6887 milliseconds // 6.9 sec
})();
})();
*/
map = L.map('map', {layers: [World_Light_Gray_Base, mapPbfLayer_cardio, mapPbfLayer_pm10]}).setView({ lng: 0, lat: 0 }, 11);
(async () => {
// Retrieve title from collection metadata
const metadata_cardio = await fetch(getCollection(pbfURL_cardio)).then(response => response.json());
const metadata_pm10 = await fetch(getCollection(pbfURL_pm10)).then(response => response.json());
var overlayMaps = {
[metadata_cardio.title]: mapPbfLayer_cardio,
[metadata_pm10.title]: mapPbfLayer_pm10
};
// Retrieve bounding box from collection metadata
const x = (metadata_cardio.extent.spatial.bbox[0][0] + metadata_cardio.extent.spatial.bbox[0][2])/ 2.0;
const y = (metadata_cardio.extent.spatial.bbox[0][1] + metadata_cardio.extent.spatial.bbox[0][3])/ 2.0;
map.flyTo({ lng: x, lat: y });
var baseMaps = {
"OpenStreetMap": OpenStreetMap_Mapnik,
"Esri World Gray Canvas": World_Light_Gray_Base
};
var layerControl = L.control.layers(baseMaps, overlayMaps).addTo(map);
let timeTaken = Date.now() - start;
console.log("Total time taken : " + timeTaken + " milliseconds"); //20 milliseconds - 0.29%
})();
</script>
</body>
</html>