简体   繁体   English

如何在OpenLayers中检查特定投影中的LonLat有效性

[英]How to check for LonLat validity in a specific projection, in OpenLayers

I want to use the method isValidLonLat to check for coordinate validity. 我想使用方法isValidLonLat来检查坐标的有效性。

Mostly, I insert the coordinates in EPSG:4326 projection, but the isValidLonLat method checks using the world bounds, that are in EPSG:900913. 通常,我将坐标插入EPSG:4326投影中,但isValidLonLat方法使用EPSG:900913中的世界范围进行检查。

For example: 例如:

map.isValidLonLat(new OpenLayers.LonLat(-8, 400)) // returns true

Maybe it should consider this as false, because the latitude is over 180º. 也许应该认为这是错误的,因为纬度超过180º。

I know why it returns true. 我知道为什么它返回true。 As I said before, I noticed that the check is made using the bounds in EPSG:900913. 如前所述,我注意到该检查是使用EPSG:900913中的边界进行的。

The question is: Is there a way to tell the method that the check should be made using a given projection (here EPSG:4326)? 问题是:有没有办法告诉该方法应该使用给定的投影进行检查(此处为EPSG:4326)?

Thanks 谢谢

You can convert you coordinates from EPSG:4326 to EPSG:900913 and then make the check. 您可以将坐标从EPSG:4326转换为EPSG:900913,然后进行检查。 For this you can use the proj4js Library 为此,您可以使用proj4js

See the example below: 请参阅以下示例:

var SourceProjection = new Proj4js.Proj('EPSG:4326');
var DestinationProjection = new Proj4js.Proj('EPSG:900913');

var Point = new Proj4js.Point(longitude, latitude);          
Proj4js.transform(SourceProjection, DestinationProjection, Point); 
map.isValidLonLat(new OpenLayers.LonLat(Point.x, Point.y));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM