OpenLayers Projections

2019-07-04 15:47发布

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
        });

2条回答
Deceive 欺骗
2楼-- · 2019-07-04 16:33

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.

查看更多
做自己的国王
3楼-- · 2019-07-04 16:39

Ah, I figured it out:

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

查看更多
登录 后发表回答