avoid zoom-level relative calculation
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.oscim.core;
|
||||
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
@@ -74,6 +75,11 @@ public class GeoPoint implements Parcelable, Comparable<GeoPoint> {
|
||||
this(latitudeE6 / CONVERSION_FACTOR, longitudeE6 / CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
public void project(Point2D out) {
|
||||
out.x = MercatorProjection.longitudeToX(this.longitudeE6 / CONVERSION_FACTOR);
|
||||
out.y = MercatorProjection.latitudeToY(this.latitudeE6 / CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GeoPoint geoPoint) {
|
||||
if (this.longitudeE6 > geoPoint.longitudeE6) {
|
||||
|
||||
@@ -27,6 +27,7 @@ public class MapPosition {
|
||||
public float angle;
|
||||
public float tilt;
|
||||
|
||||
// map center in tile coordinates of current zoom-level
|
||||
public double x;
|
||||
public double y;
|
||||
|
||||
@@ -40,21 +41,6 @@ public class MapPosition {
|
||||
this.y = MercatorProjection.latitudeToPixelY(this.lat, zoomLevel);
|
||||
}
|
||||
|
||||
// public Point geopointToMap(GeoPoint in, Point reuse) {
|
||||
// Point out = reuse == null ? new Point() : reuse;
|
||||
// out.x = (int) (MercatorProjection.longitudeToPixelX(in.getLongitude(), zoomLevel) - x);
|
||||
// out.y = (int) (MercatorProjection.latitudeToPixelY(in.getLatitude(), zoomLevel) - y);
|
||||
//
|
||||
// return out;
|
||||
// }
|
||||
|
||||
// public void geopointToMap(GeoPoint in, float[] out, int pos) {
|
||||
// out[pos * 2 + 0] =
|
||||
// (float) (MercatorProjection.longitudeToPixelX(in.getLongitude(), zoomLevel) - x);
|
||||
// out[pos * 2 + 1] =
|
||||
// (float) (MercatorProjection.latitudeToPixelY(in.getLatitude(), zoomLevel) - y);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param geoPoint
|
||||
* the map position.
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.oscim.core;
|
||||
|
||||
import android.graphics.Point;
|
||||
|
||||
/**
|
||||
* An implementation of the spherical Mercator projection.
|
||||
@@ -197,6 +196,13 @@ public final class MercatorProjection {
|
||||
return 360 * ((pixelX / ((long) Tile.TILE_SIZE << zoomLevel)) - 0.5);
|
||||
}
|
||||
|
||||
public static double toLongitude(double pixelX) {
|
||||
return 360 * (pixelX - 0.5);
|
||||
}
|
||||
|
||||
public static double toLongitude(double pixelX, double scale) {
|
||||
return 360 * ((pixelX / scale) - 0.5);
|
||||
}
|
||||
/**
|
||||
* Converts a pixel X coordinate to the tile X number.
|
||||
*
|
||||
@@ -226,6 +232,15 @@ public final class MercatorProjection {
|
||||
return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
|
||||
}
|
||||
|
||||
public static double toLatitude(double pixelY) {
|
||||
double y = 0.5 - pixelY;
|
||||
return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
|
||||
}
|
||||
|
||||
public static double toLatitude(double pixelY, double scale) {
|
||||
double y = 0.5 - pixelY / scale;
|
||||
return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI;
|
||||
}
|
||||
/**
|
||||
* Converts a pixel Y coordinate to the tile Y number.
|
||||
*
|
||||
@@ -272,12 +287,14 @@ public final class MercatorProjection {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public static Point projectPoint(GeoPoint geopoint, byte z, Point reuse) {
|
||||
Point out = reuse == null ? new Point() : reuse;
|
||||
// public static Point projectPoint(GeoPoint geopoint, byte z, Point reuse) {
|
||||
// Point out = reuse == null ? new Point() : reuse;
|
||||
//
|
||||
// out.x = (int) MercatorProjection.longitudeToPixelX(geopoint.getLongitude(), z);
|
||||
// out.y = (int) MercatorProjection.latitudeToPixelY(geopoint.getLatitude(), z);
|
||||
//
|
||||
// return out;
|
||||
// }
|
||||
|
||||
out.x = (int) MercatorProjection.longitudeToPixelX(geopoint.getLongitude(), z);
|
||||
out.y = (int) MercatorProjection.latitudeToPixelY(geopoint.getLatitude(), z);
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user