Change Projection in OpenLayers Map

落花浮王杯 提交于 2019-12-06 07:14:02

问题


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?


回答1:


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




回答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);



回答3:


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.




回答4:


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)



来源:https://stackoverflow.com/questions/2673945/change-projection-in-openlayers-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!