简体   繁体   English

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

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

With OpenLayers 6.15.1, I can use the following code in my map options:使用 OpenLayers 6.15.1,我可以在 map 选项中使用以下代码:

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

With OpenLayers 7.1, this does not work anymore.在 OpenLayers 7.1 中,这不再起作用。 I get an error:我收到一个错误:

Uncaught TypeError: ol.control.defaults is not a function未捕获的类型错误:ol.control.defaults 不是 function

Does anyone could explain to me what I have to change in my code?有谁可以向我解释我必须在我的代码中更改什么? I have found nothing explicit in the OpenLayers official documentation online about ol/control/defaults that could explain this error.我在 OpenLayers 在线官方文档中没有发现任何关于 ol/control/defaults 可以解释此错误的明确内容。

Thanks, Thierry谢谢,蒂埃里

See ol.interaction.defaults is not a function #14020 (and Legacy build 'control.defaults' and 'interaction.defaults' broken #14078 )请参阅ol.interaction.defaults 不是 function #14020 (和旧版构建 'control.defaults' 和 'interaction.defaults' 损坏 #14078

from that issue :那个问题

  • ahocevar: It should be ol.interaction.defaults.defaults now. ahocevar:现在应该是 ol.interaction.defaults.defaults。
  • hweri69: Similarly it is now ol.control.defaults.defaults hweri69: 同样它现在是 ol.control.defaults.defaults

code snippet:代码片段:

 // // 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