-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgallery.html
315 lines (290 loc) · 8.97 KB
/
gallery.html
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaflet tile maps</title>
<link rel="stylesheet" href="styles.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/js/all.min.js"></script>
<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>
</head>
<body>
<script>
var getJSON = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "json";
xhr.onload = function () {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
function getBaseMapName(data) {
var name = data["name"];
if (name.includes(".")) {
var basemap = name.split(".")[0];
} else {
var basemap = name;
}
return basemap;
}
var accessData = {
// contains the keys for basemaps that need some identification data (apikey, access token or ID code)
Thunderforest: {
keyString: "apikey",
idString: "",
name: "Thunderforest",
},
OpenWeatherMap: {
keyString: "apiKey",
idString: "",
name: "OpenWeatherMap",
},
MapTiler: {
keyString: "key",
idString: "",
name: "MapTiler",
},
MapBox: {
keyString: "accessToken",
idString: "",
name: "MapBox",
},
Jawg: {
keyString: "accessToken",
idString: "",
name: "Jawg",
},
TomTom: {
keyString: "apikey",
idString: "",
name: "TomTom",
},
HERE: {
keyString: "app_code",
idString: "app_id",
name: "HERE",
},
HEREv3: {
keyString: "apiKey",
idString: "",
name: "HEREv3",
},
AzureMaps: {
keyString: "subscriptionKey",
idString: "",
name: "AzureMaps",
},
};
function initMap(data, accessData) {
basemap = getBaseMapName(data);
const mainContainer = document.createElement("div");
mainContainer.className = "main-container";
document.body.append(mainContainer);
var titleDiv = document.createElement("div");
titleDiv.className = "title-container";
titleDiv.textContent = data["name"];
mainContainer.append(titleDiv);
var mapContainer = document.createElement("div");
mapContainer.className = "map-container";
mainContainer.append(mapContainer);
key = Object.keys(data);
val = Object.values(data);
nbOfRows = Object.keys(data).length;
var latitude = 0;
var longitude = 0;
var zoom = 1;
try {
//---------------------Basemaps with specific locations -------------------------------
//----and zooms to optimize the map views restricted to given geographic areas---------
if (
data["name"] === "Esri.ArcticOceanReference" ||
data["name"] === "Esri.ArcticOceanBase"
) {
latitude = 65.421505; // Artic ocean
longitude = -70.965421;
zoom = 1;
} else if (data["name"] === "Esri.AntarcticBasemap") {
latitude = 82.8628; // Arctic ocean
longitude = 135.0;
zoom = 6;
} else if (basemap === "OpenFireMap" || basemap === "OpenSeaMap") {
latitude = 50.1109; // Frankfurt
longitude = 8.6821;
zoom = 14;
} else if (basemap === "OpenAIP") {
latitude = 50.1109; // Frankfurt
longitude = 8.6821;
zoom = 9;
} else if (basemap === "Stamen") {
latitude = 32.7766642; // Dallas
longitude = -96.7969879;
zoom = 6;
} else if (basemap === "FreeMapSK") {
latitude = 48.736277; // Banská Bystrica Slovaky
longitude = 19.146192;
zoom = 14;
} else if (basemap === "JusticeMap") {
latitude = 32.7766642; // Dallas
longitude = -96.7969879;
zoom = 10;
} else if (
basemap === "OpenWeatherMap" ||
basemap === "Esri" ||
basemap === "USGS" ||
basemap === "WaymarkedTrails"
) {
latitude = 32.7766642; // Dallas
longitude = -96.7969879;
zoom = 4;
} else if (basemap === "BasemapAT") {
latitude = 47.5652; // Liezen
longitude = 14.2424;
zoom = 14;
} else if (basemap === "nlmaps") {
latitude = 52.370216; // Amsterdam
longitude = 4.895168;
zoom = 14;
} else if (basemap === "NLS") {
latitude = 53.381129; // Sheffield
longitude = -1.470085;
zoom = 12;
} else if (basemap === "OneMapSG") {
latitude = 1.352083; // Singapore
longitude = 103.819836;
zoom = 14;
} else if (basemap === "SwissFederalGeoportal") {
latitude = 46.5196535; // Lausanne
longitude = 6.6322734;
zoom = 10;
} else if (basemap === "OpenSnowMap") {
latitude = 45.923697; // Chamonix
longitude = 6.869433;
zoom = 14;
} else if (basemap === "Gaode") {
latitude = 39.904211; // Pekin
longitude = 116.407395;
zoom = 14;
} else if (basemap === "NASAGIBS" || basemap === "Strava") {
latitude = 48.856614; // Paris
longitude = 2.3522219;
zoom = 4;
} else {
latitude = 48.856614; // Paris
longitude = 2.3522219;
zoom = 14;
}
var sampleMap = L.map(mapContainer, { attributionControl: true }).setView(
[latitude, longitude],
zoom
);
// Case with no apikey
if (accessData[basemap] === undefined) {
L.tileLayer(data["url"], data).addTo(sampleMap);
tbl1 = document.createElement("table");
tbl1.className = "table-container";
for (let i = 0; i < nbOfRows; i++) {
const tr1 = tbl1.insertRow();
tr1.className = "line-container";
for (let j = 0; j < 2; j++) {
if (i === nbOfRows - 2 && j === 2) {
break;
} else {
const td1 = tr1.insertCell();
if (j == 0) {
// First column of the table : the one with the keys
td1.className = "key-cell";
td1.textContent = key[i];
} else {
// Second column of the table : the one with the values of the metadata
td1.className = "val-cell";
td1.textContent = val[i];
}
}
}
}
mainContainer.appendChild(tbl1);
} else {
// Case with apikey
var dict = accessData[basemap];
var keyString = dict["keyString"];
tbl2 = document.createElement("table");
tbl2.className = "table-container";
for (let i = 0; i < nbOfRows; i++) {
const tr2 = tbl2.insertRow();
tr2.className = "line-container";
for (let j = 0; j < 2; j++) {
if (i === nbOfRows - 2 && j === 2) {
break;
} else {
const td2 = tr2.insertCell();
if (j == 0) {
// First column of the table containing the keys of the metadata
td2.className = "key-cell";
td2.textContent = key[i];
} else {
// Second column of the table containing the values of the metadata
td2.className = "val-cell";
// create a single input and a button with onclick function for apikey
if (key[i] === keyString) {
var keyInput = document.createElement("input");
keyInput.type = "password";
keyInput.placeholder = "Enter your APIkey please";
keyInput.className = "key-container";
td2.append(keyInput);
var validationButton = document.createElement("button");
validationButton.className = "button-container";
td2.append(validationButton);
validationButton.innerHTML = "validate";
validationButton.onclick = get_keyCode;
function get_keyCode() {
val[i] = keyInput.value;
data[keyString] = keyInput.value;
L.tileLayer(data["url"], data).addTo(sampleMap);
}
} else {
td2.textContent = val[i];
}
}
}
}
}
mainContainer.appendChild(tbl2);
}
} catch {}
}
getJSON(
"https://raw.githubusercontent.com/geopandas/xyzservices/main/xyzservices/data/providers.json",
(err, data) => {
var dataList = [];
for ([key, val] of Object.entries(data)) {
if (val["url"] === undefined) {
// check if url is a key of the json object, if not go one level deeper and define the val as the new object
newData = val;
for ([newKey, newVal] of Object.entries(newData)) {
if (newVal["bounds"] !== undefined) {
newVal["bounds"] = undefined;
}
dataList.push(newVal);
}
} else {
dataList.push(val);
}
}
dataList.forEach((baseMapData) => {
initMap(baseMapData, accessData);
});
}
);
</script>
</body>
</html>