如何在Openlayers中将矢量层坐标转换为地图纬度和经度 [英] How to convert Vector Layer coordinates into Map Latitude and Longitude in Openlayers

查看:416
本文介绍了如何在Openlayers中将矢量层坐标转换为地图纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑.我有一点:

x= -12669114.702301
y= 5561132.6760608

我是通过使用DrawFeature控制器在矢量层上绘制正方形得到的.

That I got from drawing a square on a vector layer with the DrawFeature controller.

数字似乎... erm ... awfull很大,但是它们似乎有用,因为如果以后我用所有相同的点画一个正方形,它的位置相同,因此我认为它们必须是正确的.

The numbers seem...erm...awfull large, but they seem to work, because if I later draw a square with all the same points, it's in the same position, so I figure they have to be right.

问题是当我尝试将此点转换为纬度和经度时.

The problem is when I try to convert this point to latitude and longitude.

我正在使用:

map.getLonLatFromPixel(pointToPixel(points[0]));

其中points [0]是几何Point,pointToPixel函数采用任意点并将其转换为像素(因为getLonLatFromPixel需要一个像素).只需将点的x设为像素x,依此类推.

Where points[0] is a geometry Point, and the pointToPixel function takes any point and turns it into a pixel (since the getLonLatFromPixel needs a pixel). It does this by simply taking the point's x, and making it the pixels x, and so on.

我得到的纬度和经度大约是:

The latitude and longitude I get is on the order of:

lat: -54402718463.864
lng: -18771380.353223

这很明显是错误的.我真的很困惑.我尝试使用以下方法投影该对象:

This is very clearly wrong. I'm left really confused. I try projecting this object, using:

.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());

但是我并没有真正理解它,并且可以肯定我做错了.

But I don't really get it and am pretty sure I did it incorrectly, anyways.

我的代码在这里: http://pastie.org/909644

我有点茫然.坐标看起来是一致的,因为我可以重复使用它们以获得相同的结果...但是它们看起来比我在openLayers网站上看到的任何示例都大得多...

I'm sort of at a loss. The coordinates seem consistent, because I can reuse them to get the same result...but they seem way larger than any of the examples I'm seeing on the openLayers website...

推荐答案

根据您的代码,您使用的投影是EPSG:900913,这是Google使用的投影.此投影的单位是米,并且您为该点获得的值完全正确:

According to your code, the projection you are using is EPSG:900913, which is the one that Google uses. The units for this projection are meters, and the values that you obtain for the point are perfectly correct:

x= -12669114.702301 (longitude)
y= 5561132.6760608 (latitude)

该值不是像素,而是EPSG:900913投影中的坐标,并且是正确的(只要它们应该位于

This values are not pixels but coordinates in the EPSG:900913 projection, and are correct (as long as they are supposed to be in Idaho, if not there is something wrong elsewhere)

要进行检查,可以转到 http://proj4js.org/并从EPSG转换坐标: 900913到WGS84(纬度/经度),这将为您提供:

To check it, you can go to http://proj4js.org/ and transform your coordinates from EPSG:900913 to WGS84 (lat/lon), which will give you:

x = -113.8085937334033 (longitude)
y = 44.615123313472 (latitude)

这是您可能期望的值.如果要从点坐标中获取它们,请使用类似以下内容的

This are the values you are probably expecting. If you want to obtain them from the point coordinates use something like:

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

这会将坐标从Google投影转换为WGS84(纬度/经度).

This will transform the coordinates from the Google projection to WGS84 (Latitude / Longitude).

这篇关于如何在Openlayers中将矢量层坐标转换为地图纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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