更改 OpenLayers 地图中的投影

发布于 2024-08-29 16:35:57 字数 483 浏览 11 评论 0原文

我想将“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲欢浪云 2024-09-05 16:35:57

正如 milovanderlinden 所指出的,您必须先转换纬度/经度值(如 Google 或 Bing 地图中使用的),然后才能应用于 OpenStreetMap 图层,例如 OsmarenderMapnik

var datapoint = new OpenLayers.LonLat(-71.0, 42.0);
var proj_1 = new OpenLayers.Projection("EPSG:4326");
var proj_2 = new OpenLayers.Projection("EPSG:900913");
datapoint.transform(proj_1, proj_2);

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 likeOsmarenderorMapnik:

var datapoint = new OpenLayers.LonLat(-71.0, 42.0);
var proj_1 = new OpenLayers.Projection("EPSG:4326");
var proj_2 = new OpenLayers.Projection("EPSG:900913");
datapoint.transform(proj_1, proj_2);
瀞厅☆埖开 2024-09-05 16:35:57

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

栀梦 2024-09-05 16:35:57

什么是基础层。您想在 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.

半城柳色半声笛 2024-09-05 16:35:57

这不是一个错误,而是一个功能。球形墨卡托投影是一种方形像素投影,因此您的 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文