原文链接及内容

运行界面

此示例演示了解析WMTS GetCapabilities响应的结果对象的内容。

解析的结果如下:

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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
{
"ServiceIdentification": {
"Title": "Koordinates Labs",
"ServiceType": "OGC WMTS",
"ServiceTypeVersion": "1.0.0"
},
"ServiceProvider": {
"ProviderName": "Koordinates",
"ProviderSite": "http://labs.koordinates.com",
"ServiceContact": {}
},
"OperationsMetadata": {
"GetCapabilities": {
"DCP": {
"HTTP": {
"Get": [
{
"href": "https://labs.koordinates.com/services;key=d740ea02e0c44cafb70dce31a774ca10/wmts/1.0.0/layer/7328/WMTSCapabilities.xml?",
"Constraint": [
{
"name": "GetEncoding",
"AllowedValues": {
"Value": [
"KVP"
]
}
}
]
}
]
}
}
},
"GetFeatureInfo": {
"DCP": {
"HTTP": {
"Get": [
{
"href": "https://labs.koordinates.com/services;key=d740ea02e0c44cafb70dce31a774ca10/wmts/?",
"Constraint": [
{
"name": "GetEncoding",
"AllowedValues": {
"Value": [
"KVP"
]
}
}
]
}
]
}
}
}
},
"version": "1.0.0",
"Contents": {
"Layer": [
{
"Title": "New Zealand Earthquakes",
"Abstract": "Historical earthquake data, accessed via the [GeoNet WFS feed](http://info.geonet.org.nz/display/appdata/Advanced+Queries). The data has been filtered to only include quakes in proximity to New Zealand with an `eventtype` of \"Earthquake\" or \"none\" per the [GeoNet catalogue](http://info.geonet.org.nz/display/appdata/Catalogue+Output). Most fields have been removed. Please also note the excluded data per this [GeoNet page](http://info.geonet.org.nz/display/appdata/The+Gap). We acknowledge the New Zealand GeoNet project and its sponsors EQC, GNS Science and LINZ, for providing data used in this layer.",
"Identifier": "layer-7328",
"WGS84BoundingBox": [
-180,
-49.454297,
180,
-31.16
],
"Style": [
{
"Title": "Weighted point styles",
"Identifier": "style=39",
"isDefault": true
}
],
"Format": [
"image/png"
],
"TileMatrixSetLink": [
{
"TileMatrixSet": "EPSG:3857"
}
],
"ResourceURL": [
{
"format": "image/png",
"template": "https://koordinates-tiles-a.global.ssl.fastly.net/services;key=d740ea02e0c44cafb70dce31a774ca10/tiles/v4/layer=7328,{style}/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png",
"resourceType": "tile"
},
{
"format": "application/json",
"template": "https://labs.koordinates.com/services;key=d740ea02e0c44cafb70dce31a774ca10/wmts/1.0.0/layer/7328/featureinfo/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}/{I}/{J}.json",
"resourceType": "FeatureInfo"
},
{
"format": "text/html",
"template": "https://labs.koordinates.com/services;key=d740ea02e0c44cafb70dce31a774ca10/wmts/1.0.0/layer/7328/featureinfo/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}/{I}/{J}.html",
"resourceType": "FeatureInfo"
}
]
}
],
"TileMatrixSet": [
{
"Identifier": "EPSG:3857",
"BoundingBox": [
-20037508.342789,
-20037508.342789,
20037508.342789,
20037508.342789
],
"SupportedCRS": "urn:ogc:def:crs:EPSG::3857",
"WellKnownScaleSet": "urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible",
"TileMatrix": [
{
"Identifier": "0",
"ScaleDenominator": 559082264.029,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 1,
"MatrixHeight": 1
},
{
"Identifier": "1",
"ScaleDenominator": 279541132.014,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 2,
"MatrixHeight": 2
},
{
"Identifier": "2",
"ScaleDenominator": 139770566.007,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 4,
"MatrixHeight": 4
},
{
"Identifier": "3",
"ScaleDenominator": 69885283.0036,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 8,
"MatrixHeight": 8
},
{
"Identifier": "4",
"ScaleDenominator": 34942641.5018,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 16,
"MatrixHeight": 16
},
{
"Identifier": "5",
"ScaleDenominator": 17471320.7509,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 32,
"MatrixHeight": 32
},
{
"Identifier": "6",
"ScaleDenominator": 8735660.37545,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 64,
"MatrixHeight": 64
},
{
"Identifier": "7",
"ScaleDenominator": 4367830.18772,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 128,
"MatrixHeight": 128
},
{
"Identifier": "8",
"ScaleDenominator": 2183915.09386,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 256,
"MatrixHeight": 256
},
{
"Identifier": "9",
"ScaleDenominator": 1091957.54693,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 512,
"MatrixHeight": 512
},
{
"Identifier": "10",
"ScaleDenominator": 545978.773466,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 1024,
"MatrixHeight": 1024
},
{
"Identifier": "11",
"ScaleDenominator": 272989.386733,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 2048,
"MatrixHeight": 2048
},
{
"Identifier": "12",
"ScaleDenominator": 136494.693366,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 4096,
"MatrixHeight": 4096
},
{
"Identifier": "13",
"ScaleDenominator": 68247.3466832,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 8192,
"MatrixHeight": 8192
},
{
"Identifier": "14",
"ScaleDenominator": 34123.6733416,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 16384,
"MatrixHeight": 16384
},
{
"Identifier": "15",
"ScaleDenominator": 17061.8366708,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 32768,
"MatrixHeight": 32768
},
{
"Identifier": "16",
"ScaleDenominator": 8530.9183354,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 65536,
"MatrixHeight": 65536
},
{
"Identifier": "17",
"ScaleDenominator": 4265.4591677,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 131072,
"MatrixHeight": 131072
},
{
"Identifier": "18",
"ScaleDenominator": 2132.72958385,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 262144,
"MatrixHeight": 262144
},
{
"Identifier": "19",
"ScaleDenominator": 1066.36479192,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 524288,
"MatrixHeight": 524288
},
{
"Identifier": "20",
"ScaleDenominator": 533.182395962,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 1048576,
"MatrixHeight": 1048576
},
{
"Identifier": "21",
"ScaleDenominator": 266.591197981,
"TopLeftCorner": [
-20037508.3428,
20037508.3428
],
"TileWidth": 256,
"TileHeight": 256,
"MatrixWidth": 2097152,
"MatrixHeight": 2097152
}
]
}
]
}
}

main.js代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
import WMTSCapabilities from 'ol/format/WMTSCapabilities.js';

const parser = new WMTSCapabilities();

fetch('data/WMTSCapabilities.xml')
.then(function (response) {
return response.text();
})
.then(function (text) {
const result = parser.read(text);
document.getElementById('log').innerText = JSON.stringify(result, null, 2);
});

界面布局文件index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WMTS Capabilities Parsing</title>
<link rel="stylesheet" href="node_modules/ol/ol.css">
<style>
.map {
width: 100%;
height: 400px;
}
.log-container {
height: 400px;
overflow: scroll;
}
</style>
</head>
<body>
<pre class="log-container"><code id="log"></code></pre>
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
<script src="https://cdn.jsdelivr.net/npm/elm-pep@1.0.6/dist/elm-pep.js"></script>
<script type="module" src="main.js"></script>
</body>
</html>