【发布时间】:2019-09-25 23:18:32
【问题描述】:
我对使用 openlayers 非常陌生。下面的教程教如何显示地图并在本地构建,但问题是我无法更改地图的中心。即使我改变了位置,它也会显示地图的“零”点。
https://openlayers.org/en/latest/doc/tutorials/bundle.html
下面是 .js 示例和 .html,问题是中心:我无法更改地图中心
import 'ol/ol.css';
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM()
})
],
view: new View({
center: [0, 0],
zoom: 0
})
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Using Parcel with OpenLayers</title>
<style>
#map {
width: 400px;
height: 250px;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="./index.js"></script>
</body>
</html>
【问题讨论】:
-
嗨,Adm,欢迎来到 SO :) 能否请您展示一下代码示例,以便我们可以为您指明正确的方向,或者至少尝试一下 :)
-
刚刚编辑了 Svinjica,感谢您的帮助
-
尝试将此添加到中心属性
center:fromLonLat([37.6178, 55.7517]);在此之前您必须导入import {fromLonLat} from 'ol/proj.js';另外,值得一读openlayers.org/en/latest/doc/faq.html
标签: javascript openlayers