原文链接及内容

当必应地图的切片服务没有给定分辨率和区域时,它会返回“占位符”切片,即在将地图缩放到19级以上(这里必应地图的最大缩放等级为19),可以看到“占位符”贴图(即超出一定层级时会没有该层级切片,则会显示空白)。如果你想让OpenLayers在缩放级别超出19时显示拉伸的切片(即拉伸最大的那个等级的切片),那么需要给ol/source/BingMaps
类对象的maxZoom
属性设置为19。
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 40 41 42 43 44 45 46 47 48
| import BingMaps from 'ol/source/BingMaps.js'; import Map from 'ol/Map.js'; import TileLayer from 'ol/layer/Tile.js'; import View from 'ol/View.js';
const styles = [ 'RoadOnDemand', 'Aerial', 'AerialWithLabelsOnDemand', 'CanvasDark', 'OrdnanceSurvey', ]; const layers = []; let i, ii; for (i = 0, ii = styles.length; i < ii; ++i) { layers.push( new TileLayer({ visible: false, preload: Infinity, source: new BingMaps({ key: 'Your Bing Maps Key from https://www.bingmapsportal.com/ here', imagerySet: styles[i], }), }) ); } const map = new Map({ layers: layers, target: 'map', view: new View({ center: [-6655.5402445057125, 6709968.258934638], zoom: 13, }), });
const select = document.getElementById('layer-select'); function onChange() { const style = select.value; for (let i = 0, ii = layers.length; i < ii; ++i) { layers[i].setVisible(styles[i] === style); } } select.addEventListener('change', onChange); onChange();
|
界面布局文件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 25 26 27 28
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Bing Maps</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> <select id="layer-select"> <option value="Aerial">Aerial</option> <option value="AerialWithLabelsOnDemand" selected>Aerial with labels</option> <option value="RoadOnDemand">Road</option> <option value="CanvasDark">Road dark</option> <option value="OrdnanceSurvey">Ordnance Survey</option> </select> <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>
|