原文链接及内容

此地图的视图在一个范围内受到限制。这可以使用extent
视图选项来完成。请注意,当指定constrainOnlyCenter: True
时,仅将范围限制应用于视图中心。
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
| 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 ZoomSlider from 'ol/control/ZoomSlider.js'; import {defaults as defaultControls} from 'ol/control.js';
const view = new View({ center: [328627.563458, 5921296.662223], zoom: 8, extent: [-572513.341856, 5211017.966314, 916327.095083, 6636950.728974], });
new Map({ layers: [ new TileLayer({ source: new OSM(), }), ], keyboardEventTarget: document, target: 'map', view: view, controls: defaultControls().extend([new ZoomSlider()]), });
|
界面布局文件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>Constrained Extent</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>
|