更改 OpenLayers 地图中的投影
我想将“EPSG:4326”设置为 OpenLayers 地图的投影,但当我尝试时,我总是得到“EPSG:900913”。
function init() {
var options = {
projection: new OpenLayers.Projection("EPSG:4326") // ignored
};
map = new OpenLayers.Map('map', options);
var layer = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
map.addLayer(layer);
...
alert(map.getProjection()); // returns "EPSG:900913"
...
}
底图是开放的街道地图。
如何将投影设置为 EPSG:4326?
I want to set "EPSG:4326" as the projection of an OpenLayers map, but when I try it, I always get "EPSG:900913".
function init() {
var options = {
projection: new OpenLayers.Projection("EPSG:4326") // ignored
};
map = new OpenLayers.Map('map', options);
var layer = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
map.addLayer(layer);
...
alert(map.getProjection()); // returns "EPSG:900913"
...
}
The base map is open street map.
How can I set the Projection to EPSG:4326?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 milovanderlinden 所指出的,您必须先转换纬度/经度值(如 Google 或 Bing 地图中使用的),然后才能应用于 OpenStreetMap 图层,例如
Osmarender
或Mapnik
:As milovanderlinden has pointed out, you have to transform latitude/longitude values (as used in Google or Bing maps) before the can be applied in OpenStreetMap layers like
Osmarender
orMapnik
:Osmarender 有一个硬编码的 900913 投影,与此无关。但你有没有考虑过反其道而行之呢?将坐标或图层转换为 EPSG:900913?请在此处查看文档:http://docs.openlayers.org/library/spherical_mercator.html
It is Osmarender that has a hardcoded 900913 projection, nothing to do about that. But have you considered taking things the other way around? Transforming your coordinates or layer to EPSG:900913? Check the documentation here: http://docs.openlayers.org/library/spherical_mercator.html
什么是基础层。您想在 GMap 或 Bing 地图上绘图吗?如果是这样,那么 OpenLayers 可能会尝试获取数据以匹配基础层的投影,以便其正确排列。
What is the base layer. Are you trying to draw on GMaps or Bing Maps? If so then OpenLayers may be trying to get the data to match the projection of the base layer so it lines up properly.
这不是一个错误,而是一个功能。球形墨卡托投影是一种方形像素投影,因此您的 openlayers 矢量特征可以准确地放置在地图上 - WSG-84 则不是这种情况 (EPSG:4326)
It's not a bug, it's a feature. Spherical Mercator is a square-pixel projection, so your openlayers vector features can be placed accurately on the map - this is not the case with WSG-84 (EPSG:4326)