我会将实例ol.View的副本传递给地图构造函数。当我停止变焦时,我想知道为什么吗? 我必须写一些文字才能创建帖子eh ..
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.2.0/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.2.0/build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
const copy = (obj) => {
return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
};
const v = new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 4
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: copy(v)
});
</script>
</body>
</html>
Openlayers v5.2.0