我尝试在自定义应用程序上更新 Open Layer 7.4.0 版本,但 openlayers 停止工作。
我从网站下载了最新的openlayer版本:https://openlayers.org/download/ 然后用我的旧 ol.css 和 ol.jss 更新它,但它不起作用。
阅读一长串升级说明https://github.com/openlayers/openlayers/blob/main/changelog/upgrade-notes.md以了解可能破坏旧代码的任何更改。另请注意,您必须设置地图 div 的大小(通常在 css 中完成)。
这足以让非常简单的地图与 v7.4.0 一起使用
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple Map</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/ol.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script>
<style>
html, body, .map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
</script>
</body>
</html>