[英]How do I center OpenLayers map over Chile
I'm trying to center an OpenLayers map over Chile and having a hard time to get it working.我正在尝试将 OpenLayers map 放在智利的中心,并且很难让它工作。
Here is my code: This doesn't center on OpenLayers map over Chile.这是我的代码:这不以智利的 OpenLayers map 为中心。
var osmLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
// Create latitude and longitude and convert them to default projection
var birmingham = ol.proj.transform([150.644, -34.397], 'EPSG:5186', 'EPSG:3857');
// Create a View, set it center and zoom level
var view = new ol.View({
center: birmingham,
zoom: 6
});
// Instanciate a Map, set the object target to the map DOM id
var map = new ol.Map({
target: 'map_new'
});
// Add the created layer to the Map
map.addLayer(osmLayer);
// Set the view for the map
map.setView(view);
You should insert the coordinates of the map center you want (for example, of Santiago de Chile):您应该插入您想要的 map 中心的坐标(例如,智利圣地亚哥):
var view = new ol.View({
center: [-33.27, -70.38],
zoom: 6
});
Every GIS map has a coordinate system.每个 GIS map 都有一个坐标系。 GIS web applications are very similar to desktop GIS maps, so they have a coordinate system too.
GIS web 应用程序与桌面 GIS 地图非常相似,因此它们也有坐标系。 in OpenLayers known as projection.
在 OpenLayers 中称为投影。
In OpenLayers, every web app made up of a Map()
class that needs a view()
to show the map.在 OpenLayers 中,每个 web 应用由
Map()
class 组成,需要一个view()
来显示 map。 By default, every view()
use Web Mercator projection
or EPSG:3857
as its projection.默认情况下,每个
view()
都使用Web Mercator projection
或EPSG:3857
作为其投影。 The idea of transforming EPSG:5186
to EPSG:3857
is right but according to espg.io , EPSG:5186
is Korea 2000 / Central Belt 2010
!将
EPSG:5186
转换为EPSG:3857
的想法是正确的,但根据espg.io , EPSG:5186
是Korea 2000 / Central Belt 2010
!
So I think you are using the wrong transformation.所以我认为你使用了错误的转换。 if you want WGS 84 (lat-long system) simply use one of the codes below:
如果您想要 WGS 84(经纬度系统),只需使用以下代码之一:
view: new ol.View({
center: [-70.66, -33.44],
projection: 'EPSG:4326',
zoom: 0
})
Or:或者:
view: new ol.View({
center: ol.proj.fromLonLat([-70.66, -33.44]),
zoom: 0
})
Or:或者:
var birmingham = ol.proj.transform([-70.66, -33.44], 'EPSG:4326', 'EPSG:3857');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.