OpenLayers投影 [英] OpenLayers Projections

查看:175
本文介绍了OpenLayers投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以成功地执行:

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

对于谷歌格式(以米为单位),但是当我想要反向:

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

到一个4326(普通的lat / lon格式)的点,我有一些问题。



当我进行转换时,任何负值似乎都变成NaN(不是数字)。有没有关于转换的东西,我不明白?



编辑:更糟糕的是,当我没有负值时,坐标似乎关闭。我通过在屏幕上绘制一个正方形来获取坐标,然后将这些坐标保存到数据库并稍后加载。我可以在非洲尖端附近画一个正方形(正坐标),然后当它加载它在非洲大陆的顶部附近时,在大西洋。我肯定做错了...



编辑:这是我的代码:

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

// restrictedExtent:bounds.clone(),


});
//实际绘制地图
layerMapnik = new OpenLayers.Layer.OSM.Mapnik(Mapnik,{
displayOutsideMaxExtent:false,
wrapDateLine:true
/ / numZoomLevels:10
});


啊,我想出了:



在我的代码中有一点,我困惑了经纬度,它把所有的东西都弄乱了。


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

解决方案

Ah, I figured it out:

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

这篇关于OpenLayers投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆