I want to use the method isValidLonLat to check for coordinate validity.
Mostly, I insert the coordinates in EPSG:4326 projection, but the isValidLonLat method checks using the world bounds, that are in 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º.
I know why it returns true. As I said before, I noticed that the check is made using the bounds in 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)?
Thanks
You can convert you coordinates from EPSG:4326 to EPSG:900913 and then make the check. For this you can use the proj4js Library
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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.