OpenLayers 投影

发布于 2024-08-28 10:25:52 字数 1091 浏览 2 评论 0原文

我可以成功地做到:

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

到谷歌格式(以米为单位)的点,但是当我想做相反的事情:

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

到4326(常规纬度/经度格式)的点时,我遇到了一些问题。

当我进行转换时,任何负值似乎都会变成 NaN (不是数字)。关于反向转换有什么我不明白的地方吗?

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

编辑:这是我的代码:http://pastie.org/911524

具体来说:这就是我初始化地图的方式:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

提笔落墨 2024-09-04 10:25:52

啊,我想通了:

在我的代码中,有一次我混淆了纬度和经度,这把一切都搞乱了。

Ah, I figured it out:

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

哆兒滾 2024-09-04 10:25:52

如果您确实想使用所有坐标转换功能,则应该使用 proj4js 增强 openlayers http://proj4js.org/ 完整的坐标转换框架。

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.

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