我正在尝试将OpenLayers地图集中在智利上,但很难让它工作。
这是我的代码: 这并不以智利的OpenLayers地图为中心。
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);
您应该插入所需地图中心的坐标(例如,智利圣地亚哥(:
var view = new ol.View({
center: [-33.27, -70.38],
zoom: 6
});
每个 GIS 地图都有一个坐标系。GIS Web 应用程序与桌面 GIS 地图非常相似,因此它们也具有坐标系。在称为投影的开放层中。
在 OpenLayers 中,每个 web 应用程序都由一个Map()
类组成,该类需要一个view()
来显示地图。默认情况下,每个view()
都使用Web Mercator projection
或EPSG:3857
作为其投影。将EPSG:5186
转换为EPSG:3857
的想法是正确的,但根据 espg.io 的说法,EPSG:5186
Korea 2000 / Central Belt 2010
!
所以我认为你使用了错误的转换。 如果您想要 WGS 84(经度系统(,只需使用以下代码之一:
view: new ol.View({
center: [-70.66, -33.44],
projection: 'EPSG:4326',
zoom: 0
})
或:
view: new ol.View({
center: ol.proj.fromLonLat([-70.66, -33.44]),
zoom: 0
})
或:
var birmingham = ol.proj.transform([-70.66, -33.44], 'EPSG:4326', 'EPSG:3857');