原文链接及内容

此示例显示如何创建用于从GetCapables响应访问WMTS的配置。而加载WMTS服务示例显示如何手动创建用于访问WMTS数据源的配置。
main.js
代码如下:
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
| import Map from 'ol/Map.js'; import OSM from 'ol/source/OSM.js'; import TileLayer from 'ol/layer/Tile.js'; import View from 'ol/View.js'; import WMTS, {optionsFromCapabilities} from 'ol/source/WMTS.js'; import WMTSCapabilities from 'ol/format/WMTSCapabilities.js';
const parser = new WMTSCapabilities(); let map;
fetch('data/WMTSCapabilities.xml') .then(function (response) { return response.text(); }) .then(function (text) { const result = parser.read(text); const options = optionsFromCapabilities(result, { layer: 'layer-7328', matrixSet: 'EPSG:3857', });
map = new Map({ layers: [ new TileLayer({ source: new OSM(), opacity: 0.7, }), new TileLayer({ opacity: 1, source: new WMTS(options), }), ], target: 'map', view: new View({ center: [19412406.33, -5050500.21], zoom: 5, }), }); });
|
界面布局文件index.html
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>WMTS Layer from Capabilities</title> <link rel="stylesheet" href="node_modules/ol/ol.css"> <style> .map { width: 100%; height: 400px; } </style> </head> <body> <div id="map" class="map"></div> <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>
|