-
Notifications
You must be signed in to change notification settings - Fork 455
/
Copy pathWFS service explorer.html
243 lines (194 loc) · 9.09 KB
/
WFS 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>WFS 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 WFS services on Azure Maps." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, WFS, web feature service, ogc, spatial data, 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>
let map, client, layer, currentServiceUrl;
// Sample WFS services to let users test with.
var services = [
{ name: 'NZ GNS Science', url: 'https://data.gns.cri.nz/webmaps/geology/wfs' },
{ name: 'CIESIN, Columbia University', url: 'https://sedac.ciesin.columbia.edu/geoserver/grump-v1/ows?request=getcapabilities&service=wfs' },
{ name: 'BC Recreation Polygons', url: 'https://openmaps.gov.bc.ca/geo/pub/WHSE_FOREST_TENURE.FTEN_RECREATION_POLY_SVW/wfs' },
{ name: 'Aerogravity/magnetic 3d surveys', url: 'https://data.geus.dk/geusmap/ows/4258.jsp' },
{ name: 'US Active mines (USGS)', url: 'https://mrdata.usgs.gov/wfs/active-mines' },
{ name: 'Geology of Hawaii (USGS)', url: 'https://mrdata.usgs.gov/wfs/hi?request=getcapabilities&service=WFS&version=1.1.0&' }
];
function initializeMap() {
// Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
// Add authentication details for connecting to Azure Maps.
authOptions: {
authType: 'anonymous',
clientId: 'e6b6ab59-eb5d-4d25-aa57-581135b927f0', // Your Azure Maps Client Id for accessing your Azure Maps account.
getToken: resolveToken // Function that returns a promise with the Azure Maps access token to use.
}
// 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]'
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add a simple data layer for rendering the data.
layer = new atlas.layer.SimpleDataLayer(datasource);
map.layers.add(layer);
//Generate a selection list of some predefined WFS 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('');
});
}
// Function to retrieve an Azure Maps access token.
function resolveToken(resolve, reject, map) {
// URL to your authentication service that retrieves an Microsoft Entra ID Token.
fetch("https://samples.azuremaps.com/api/GetAzureMapsToken")
.then(response => response.text())
.then(token => resolve(token))
.catch(reject);
}
function loadClient(url) {
currentTypeName = null;
currentServiceUrl = url;
document.getElementById('loadingIcon').style.display = '';
document.getElementById('typeNames').innerHTML = '';
datasource.clear();
//Create the WFS client to access the service.
client = new atlas.io.ogc.WfsClient({
url: url
//proxyService: ''
});
//Check the capabilities of the service.
client.getCapabilities().then(cap => {
currentTypeName = cap.featureTypes[0].name;
//Create a list of feature type sets to choose from.
var html = [];
for (var i = 0; i < cap.featureTypes.length; i++) {
html.push('<option value="', cap.featureTypes[i].name, '"');
if (i === 0) {
html.push(' selected="selected"');
}
html.push('>', cap.featureTypes[i].name, '</option>');
}
document.getElementById('typeNames').innerHTML = html.join('');
processQuery();
});
}
function loadSelectInput() {
var serviceIdx = getSelectValue('servicesDD');
if (serviceIdx >= 0) {
currentServiceUrl = services[serviceIdx].url;
loadClient(currentServiceUrl);
} else {
currentServiceUrl = null;
datasource.clear();
}
}
function proxyOptionChanged() {
if (currentServiceUrl) {
loadClient(currentServiceUrl);
}
}
function processQuery() {
document.getElementById('status').innerText = '';
if (currentTypeName) {
//Create the request for the WFS service.
var request = {
typeNames: getSelectValue('typeNames')
};
var mf = getSelectValue('maxFeatures');
if (mf !== 'Max') {
request.count = parseInt(mf);
}
//Make a request to get features from the WFS service.
client.getFeatures(request).then(fc => {
if (fc) {
//IF there is bounding box information, use it to update the map view.
if (fc.bbox) {
map.setCamera({ bounds: fc.bbox, padding: 50 });
}
//Update the shapes in the data source with the results from the request.
datasource.setShapes(fc);
document.getElementById('status').innerText = `${fc.features.length} features loaded.`;
document.getElementById('loadingIcon').style.display = 'none';
}
}, error => {
document.getElementById('status').innerText = error;
document.getElementById('loadingIcon').style.display = 'none';
});
}
}
function getSelectValue(id) {
var elm = document.getElementById(id);
return elm.options[elm.selectedIndex].value;
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 375px);
min-width: 290px;
height: 600px;
float: left;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#loadingIcon {
position: absolute;
top: 250px;
left: 120px;
}
select {
max-width: 320px;
}
</style>
</head>
<body onload="initializeMap()">
<fieldset class="sidePanel">
<legend>WFS service explorer</legend>
This is a simple tool for exploring WFS services on Azure Maps.
<br /><br />
WFS Service:<br /><select id="servicesDD" onchange="loadSelectInput()"></select><br /><br />
<!--<input id="useProxyService" type="checkbox" onclick="proxyOptionChanged()" /> Use Proxy Service-->
<br /><br />
<b>Max features:</b>
<select id="maxFeatures" onchange="processQuery()">
<option value="100">100</option>
<option value="250">250</option>
<option value="500" selected="selected">500</option>
<option value="1000">1000</option>
<option value="5000">5000</option>
<option value="Max">Max</option>
</select>
<br /><br />
<b>Property types:</b><br /><br />
<select id="typeNames" onchange="processQuery()"></select>
<br /><br />
<b>Status: </b><span id="status"></span>
</fieldset>
<div id="myMap"></div>
<img id="loadingIcon" style="display:none;" src="/images/loadingIcon.gif" />
</body>
</html>