[英]OpenLayers 4 center map on city coordinates
I have a problem with centering my map on creation. 我的地图以创作为中心时遇到问题。
My javascript code is from the quick start guide, same goes for the html code. 我的javascript代码来自快速入门指南,html代码也是如此。
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.transform([51.35847, 7.49918], 'EPSG:4326', 'EPSG:3857'),
zoom: 4
})
});
It just won't center and I don't understand why? 它只是不会居中,我也不明白为什么? I did exactly as described in other questions and topics on stackoverflow....
我所做的完全按照关于stackoverflow的其他问题和主题中的描述。
Fiddle: https://jsfiddle.net/gpo33ga6/ 小提琴: https : //jsfiddle.net/gpo33ga6/
Here is the solution : 这是解决方案:
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([7.49918, 51.35847]),
zoom: 4
})
});
Take care that the function takes (Lon, Lat)
and not (Lat, Lon)
. 请注意,该函数采用
(Lon, Lat)
而不是(Lat, Lon)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.