admin管理员组文章数量:1291120
With OpenLayers 6.15.1, I can use the following code in my map options:
controls: ol.control.defaults({
zoom: true,
attribution: true,
rotate: false
}),
With OpenLayers 7.1, this does not work anymore. I get an error:
Uncaught TypeError: ol.control.defaults is not a 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.
With OpenLayers 6.15.1, I can use the following code in my map options:
controls: ol.control.defaults({
zoom: true,
attribution: true,
rotate: false
}),
With OpenLayers 7.1, this does not work anymore. I get an error:
Uncaught TypeError: ol.control.defaults is not a 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.
Share Improve this question edited May 24, 2023 at 11:54 geocodezip 161k14 gold badges226 silver badges255 bronze badges asked Sep 13, 2022 at 6:56 ThierryThierry 511 silver badge3 bronze badges 1- 1 try ol.control.defaults.defaults – BR75 Commented Sep 13, 2022 at 9:09
1 Answer
Reset to default 12See ol.interaction.defaults is not a function #14020 (and Legacy build 'control.defaults' and 'interaction.defaults' broken #14078)
from that issue:
- ahocevar : It should be ol.interaction.defaults.defaults now.
- hweri69 : Similarly it is now ol.control.defaults.defaults
The code was moved to its own moddule to resolve a circular dependency, see: Remove circular dependency #13967
(per ment by @MoonE)
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/npm/[email protected]/dist/ol.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr/npm/[email protected]/ol.css">
</head>
<body>
<div id="map" class="map"></div>
<!-- Pointer events polyfill for old browsers, see https://caniuse./#feat=pointer -->
<script src="https://unpkg./[email protected]/dist/elm-pep.js"></script>
</body>
</html>
本文标签: javascriptolcontrolsdefault not a function in OpenLayers 71Stack Overflow
版权声明:本文标题:javascript - olcontrolsdefault not a function in OpenLayers 7.1 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741513559a2382748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论