簡體   English   中英

ol/controls/default 不是 OpenLayers 7.1 中的 function

[英]ol/controls/default not a function in OpenLayers 7.1

使用 OpenLayers 6.15.1,我可以在 map 選項中使用以下代碼:

controls: ol.control.defaults({
    zoom: true,
    attribution: true,
    rotate: false
}),

在 OpenLayers 7.1 中,這不再起作用。 我收到一個錯誤:

未捕獲的類型錯誤:ol.control.defaults 不是 function

有誰可以向我解釋我必須在我的代碼中更改什么? 我在 OpenLayers 在線官方文檔中沒有發現任何關於 ol/control/defaults 可以解釋此錯誤的明確內容。

謝謝,蒂埃里

請參閱ol.interaction.defaults 不是 function #14020 (和舊版構建 'control.defaults' 和 'interaction.defaults' 損壞 #14078

那個問題

  • ahocevar:現在應該是 ol.interaction.defaults.defaults。
  • hweri69: 同樣它現在是 ol.control.defaults.defaults

代碼片段:

 // // Create map, giving it a rotate to north control. // const map = new ol.Map({ controls: ol.control.defaults.defaults({ zoom: true, attribution: true, rotate: false }), layers: [ new ol.layer.Tile({ // TileLayer({ source: new ol.source.OSM(), }), ], target: 'map', view: new ol.View({ center: [0, 0], zoom: 3, rotation: 1, }), });
 .map, html, body { width: 100%; height: 100%; margin: 0px; padding: 0px; }
 <:DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Default Controls</title> <script src="https.//cdn.jsdelivr.net/npm/ol@v7.1.0/dist/ol:js"></script> <link rel="stylesheet" href="https.//cdn.jsdelivr.net/npm/ol@v7.1.0/ol,css"> </head> <body> <div id="map" class="map"></div> <:-- Pointer events polyfill for old browsers. see https://caniuse.com/#feat=pointer --> <script src="https.//unpkg.com/elm-pep@1.0.6/dist/elm-pep.js"></script> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM