MercatorProjection.latitudeToY not work at > ±85.05113°, fixes #222
This commit is contained in:
parent
7885529fff
commit
4b55043dcc
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||||
* Copyright 2012 Hannes Janetzek
|
* Copyright 2012 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -17,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.core;
|
package org.oscim.core;
|
||||||
|
|
||||||
|
import org.oscim.utils.FastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of the spherical Mercator projection.
|
* An implementation of the spherical Mercator projection.
|
||||||
*/
|
*/
|
||||||
@ -68,14 +71,14 @@ public final class MercatorProjection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Projects a longitude coordinate (in degrees) to the range [0.0,1.0]
|
* Projects a latitude coordinate (in degrees) to the range [0.0,1.0]
|
||||||
*
|
*
|
||||||
* @param latitude the latitude coordinate that should be converted.
|
* @param latitude the latitude coordinate that should be converted.
|
||||||
* @return the position .
|
* @return the position.
|
||||||
*/
|
*/
|
||||||
public static double latitudeToY(double latitude) {
|
public static double latitudeToY(double latitude) {
|
||||||
double sinLatitude = Math.sin(latitude * (Math.PI / 180));
|
double sinLatitude = Math.sin(latitude * (Math.PI / 180));
|
||||||
return 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
|
return FastMath.clamp(0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI), 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double toLatitude(double y) {
|
public static double toLatitude(double y) {
|
||||||
@ -86,7 +89,7 @@ public final class MercatorProjection {
|
|||||||
* Projects a longitude coordinate (in degrees) to the range [0.0,1.0]
|
* Projects a longitude coordinate (in degrees) to the range [0.0,1.0]
|
||||||
*
|
*
|
||||||
* @param longitude the longitude coordinate that should be converted.
|
* @param longitude the longitude coordinate that should be converted.
|
||||||
* @return the position .
|
* @return the position.
|
||||||
*/
|
*/
|
||||||
public static double longitudeToX(double longitude) {
|
public static double longitudeToX(double longitude) {
|
||||||
return (longitude + 180.0) / 360.0;
|
return (longitude + 180.0) / 360.0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user