/
OGC Web Map Service explorer.html
337 lines (273 loc) · 14.1 KB
/
OGC Web Map Service explorer.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<head>
<title>OGC Web Map Service explorer - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This is a simple tool for exploring Web Map Services (WMS) and Web Map Tile Services (WMTS) as layers on the map." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, web mapping service, web mapping tile service, wmts, wms, OGC, spatial io module" />
<meta name="author" content="Microsoft Azure Maps" /><meta name="version" content="1.0" />
<meta name="screenshot" content="screenshot.jpg" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" rel="stylesheet" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
<!-- Add reference to the Azure Maps Spatial IO module. -->
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
<script>
var map, popup, layer, currentCapabilities;
var proxyServiceUrl = 'https://samples.azuremaps.com/api/GetDataFromUrl?url=';
//Sample WMTS and WMS services to let users test with.
var services = [
//WMTS services
{ name: 'USGS Shaded Relief Only (WMTS)', url: 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSShadedReliefOnly/MapServer/WMTS/1.0.0/WMTSCapabilities.xml' },
{ name: 'basemap.at (WMTS)', url: 'https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml' },
{ name: 'USGS Geologic maps (WMTS)', url: 'https://mrdata.usgs.gov/mapcache/wmts/' },
{ name: 'Luxembourg admin areas (WMTS)', url: 'https://wmts1.geoportail.lu/opendata/service' },
{ name: 'GeoNorth AeronauticalCharts (WMTS)', url: 'https://gis.dnr.alaska.gov/terrapixel/cubeserv/AeronauticalCharts?SERVICE=WMTS&REQUEST=GetCapabilities' },
//WMS services
{ name: 'World geology survey (WMS)', url: 'https://mrdata.usgs.gov/services/gscworld' },
{ name: 'US Census areas (WMS)', url: 'https://tigerweb.geo.census.gov/arcgis/services/TIGERweb/tigerWMS_Current/MapServer/WMSServer' },
{ name: 'Radar base reflectivity (NOAA) (WMS)', url: 'https://idpgis.ncep.noaa.gov/arcgis/services/NWS_Observations/radar_base_reflectivity/MapServer/WmsServer' },
{ name: 'Wetlands_Raster (WMS)', url: 'https://www.fws.gov/wetlands/arcgis/services/Wetlands_Raster/ImageServer/WMSServer' },
{ name: 'Contours (WMS)', url: 'https://carto.nationalmap.gov/arcgis/services/contours/MapServer/WMSServer' },
{ name: 'Radar meteo imagery nexrad time (NOAA) (WMS)', url: 'https://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WMSServer' },
{ name: 'Natural Earth (WMS)', url: 'https://smallscale.nationalmap.gov/arcgis/services/NaturalEarth/MapServer/WMSServer' },
{ name: 'Water areas (WMS)', url: 'https://hydro.nationalmap.gov/arcgis/services/nhd/MapServer/WMSServer' },
{ name: 'USGS NAIP Plus (WMS)', url: 'https://services.nationalmap.gov/arcgis/services/USGSNAIPPlus/MapServer/WMSServer' },
{ name: 'Government land (WMS)', url: 'https://carto.nationalmap.gov/arcgis/services/govunits/MapServer/WMSServer' },
{ name: 'US Topo Availability (WMS)', url: 'https://index.nationalmap.gov/arcgis/services/USTopoAvailability/MapServer/WMSServer' },
{ name: 'FEMA National Flood Hazard Layer', url: 'https://hazards.fema.gov/nfhl/services/public/NFHLWMS/MapServer/WMSServer?request=GetCapabilities&service=WMS'}
];
function getMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
zoom: 1,
view: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
//Use Microsoft Entra ID authentication.
authType: 'anonymous',
clientId: 'e6b6ab59-eb5d-4d25-aa57-581135b927f0', //Your Azure Maps client id for accessing your Azure Maps account.
getToken: function (resolve, reject, map) {
//URL to your authentication service that retrieves an Microsoft Entra ID Token.
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
fetch(tokenServiceUrl).then(r => r.text()).then(token => resolve(token));
}
//Alternatively, use an Azure Maps key. Get an Azure Maps key at https://azure.com/maps. NOTE: The primary key should be used as the key.
//authType: 'subscriptionKey',
//subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
}
});
//Generate a selection list of some predefined OGC map services.
var html = ['<option value="-1"></option>'];
for (var i = 0; i < services.length; i++) {
html.push('<option value="', i, '">', services[i].name, '</option>');
}
document.getElementById('servicesDD').innerHTML = html.join('');
//Wait until the map resources are ready.
map.events.add('ready', function () {
popup = new atlas.Popup();
//Create a style control and add it to the map.
map.controls.add(new atlas.control.StyleControl({
mapStyles: 'all'
}), {
position: 'top-right'
});
//Add a click event to the map.
map.events.add('click', mapClick);
});
}
function loadLayer(url) {
clear();
//Show the loading icon.
document.getElementById('loadingIcon').style.display = '';
//Create an OGC layer.
layer = new atlas.layer.OgcMapLayer({
url: url,
proxyService: (document.getElementById('useProxyService').checked) ? proxyServiceUrl : null,
bringIntoView: document.getElementById('bringIntoView').checked,
debug: true
});
//Monitor for when the active layers change in the layer.
layer. => {
//Get the capabilities if the active layers change.
layer.getCapabilities().then(cap => {
if (cap) {
currentCapabilities = cap;
//Build a seleciton list of sub-layers.
buildLayerList();
}
});
//Hide the loading icon.
document.getElementById('loadingIcon').style.display = 'none';
};
map.layers.add(layer, 'transit');
}
//Handle user selection from the list of known OGC services.
function loadSelectInput() {
var elm = document.getElementById('servicesDD');
var serviceIdx = parseInt(elm.options[elm.selectedIndex].value);
if (serviceIdx >= 0) {
loadLayer(services[serviceIdx].url);
} else {
clear();
}
}
//Clear the map and reset the UI.
function clear() {
currentCapabilities = null;
document.getElementById('layerPicker').innerHTML = '';
if (layer) {
map.layers.remove(layer);
layer = null;
}
popup.close();
}
//Handle click events on the map.
function mapClick(e) {
if (layer) {
//Get the feature info for where the user clicked on the map.
layer.getFeatureInfo(e.position).then(result => {
if (result && result.features && result.features.length > 0) {
popup.setOptions({
content: atlas.PopupTemplate.applyTemplate(result.features[0].properties),
position: e.position
});
popup.open(map);
}
}, error => {
alert(error);
});
}
}
//Create a selection list of all the sub-layers in the layer.
function buildLayerList() {
var cap = currentCapabilities;
var html = [];
var o = layer.getOptions();
for (var i = 0; i < cap.sublayers.length; i++) {
html.push('<input type="checkbox" class="collapsible" value="', i, '"');
var isActive = false;
//Check to see if the layer is active.
if (o.activeLayers && o.activeLayers.length > 0) {
o.activeLayers.forEach(al => {
if ((typeof al === 'string' && al === cap.sublayers[i].id) || al.id === cap.sublayers[i].id) {
isActive = true;
}
});
}
var t = cap.sublayers[i].title;
if (!t || t === '') {
t = cap.sublayers[i].id;
}
//Add the title to the of the sub-layer.
if (isActive) {
html.push('checked="checked"/>', t, '<div class="content" style="display:block">');
} else {
html.push('/>', t, '<div class="content">');
}
html.push('<p>');
//Add the description of the sub-layer
if (cap.sublayers[i].description && cap.sublayers[i].description !== '') {
html.push(cap.sublayers[i].description, '<br/>');
}
//Add the zoom level range of the sub-layer.
html.push('Zoom range: ', cap.sublayers[i].minZoom, ' - ', cap.sublayers[i].maxZoom, '<br/><br/>');
//Add the legend for the sub-layer.
if (cap.sublayers[i].styles && cap.sublayers[i].styles.length > 0 && cap.sublayers[i].styles[0].legendUrl && cap.sublayers[i].styles[0].legendUrl !== '') {
html.push('<img src="', cap.sublayers[i].styles[0].legendUrl, '" />');
}
html.push('</p></div><br/>');
}
//Update the layer picker.
document.getElementById('layerPicker').innerHTML = html.join('');
//Loop through and make each collapsible item clickable.
var coll = document.getElementsByClassName("collapsible");
for (var i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
this.classList.toggle("active");
var content = this.nextElementSibling;
var idx = parseInt(this.value);
var o = layer.getOptions();
var al = o.activeLayers || [];
var clickedLayer = currentCapabilities.sublayers[idx].id;
//Show the loading icon when the selected layers changes.
document.getElementById('loadingIcon').style.display = '';
//WMS services allow multiple layers to be selected.
if (o.service === 'WMS') {
if (content.style.display === "block") {
//Remove the layer.
content.style.display = "none";
al = al.filter(e => e.id !== clickedLayer);
} else {
//Add the layer.
content.style.display = "block";
al.push(clickedLayer);
}
} else {
//WMTS layers only allow a single layer to be selected.
if (content.style.display === "block") {
//Remove the layer.
content.style.display = "none";
al = [];
} else {
//Add the layer.
content.style.display = "block";
al = [clickedLayer];
}
}
//Update the list of active layers.
layer.setOptions({ activeLayers: al });
});
}
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 400px);
min-width: 290px;
height: 600px;
float: left;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#loadingIcon {
position: absolute;
top: 250px;
left: 120px;
}
#layerPicker {
width: 330px;
height: 230px;
overflow-y: auto;
}
.collapsible {
}
.content {
padding: 0 18px;
display: none;
}
</style>
</head>
<body >
<fieldset class="sidePanel">
<legend>OGC Web Map Service explorer</legend>
This is a simple tool for exploring Web Map Services (WMS) and Web Map Tile Services (WMTS) as layers on the map.
<br /><br />
OGC Service:<br />
<select id="servicesDD" /><br />
<input id="useProxyService" type="checkbox" /> Use Proxy Service<br /><br />
<input id="bringIntoView" type="checkbox" checked="checked" /> Bring into view<br /><br />
<b>Sublayers</b><br /><br />
<div id="layerPicker"></div>
</fieldset>
<div id="myMap"></div>
<img id="loadingIcon" style="display:none;" src="/images/loadingIcon.gif" />
</body>
</html>