OpenLayers Projections

冷暖自知 提交于 2019-12-23 15:46:13

问题


I can succesfully do:

point.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));

To a point that is in the google format (in meters), but when I want to do the reverse:

point.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));

to a point that is in 4326 (regular lat/lon format), I am having some issues.

Any negative value seems to become NaN (not a number) when I do the transformation. Is there something about the transformation in reverse that I don't understand?

Edit: Even worse, when I have no negative values, the coordinates seem off. I am getting the coordinates by drawing a square on the screen, then saving those coordinates to a database and loading them later. I can draw a square near the tip of africa (positive coordinates), and then when it loads it's near the top of africa, in the atlantic ocean. I'm definitely doing something wrong....

Edit: Here's my code: http://pastie.org/911524

Specifically: this is how I initialize my map:

 var navControl = new OpenLayers.Control.Navigation();
                 map = new OpenLayers.Map('map', {

                // restrictedExtent: bounds.clone(),


                 }); 
       //actually draws the map 
        layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
        displayOutsideMaxExtent: false,
        wrapDateLine: true
        //numZoomLevels: 10
        });

回答1:


Ah, I figured it out:

At one point in my code I confused latitude and longitude it was messing everything up.




回答2:


If you really want to use all the coordinate transformation power, you should enhance openlayers with proj4js http://proj4js.org/ a full coordinate transformation framework.



来源:https://stackoverflow.com/questions/2607734/openlayers-projections

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