add osmdroid overlays + bonuspack

This commit is contained in:
Hannes Janetzek
2012-10-27 13:35:51 +02:00
parent 65a6f91f3c
commit ab5962d56c
114 changed files with 9562 additions and 1636 deletions

View File

@@ -16,40 +16,46 @@ package org.oscim.core;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
/**
* A BoundingBox represents an immutable set of two latitude and two longitude coordinates.
* A BoundingBox represents an immutable set of two latitude and two longitude
* coordinates.
*/
public class BoundingBox implements Serializable {
public class BoundingBox implements Parcelable {
/**
* Conversion factor from degrees to microdegrees.
*/
private static final double CONVERSION_FACTOR = 1000000d;
private static final long serialVersionUID = 1L;
private static boolean isBetween(int number, int min, int max) {
return min <= number && number <= max;
}
/**
* The maximum latitude value of this BoundingBox in microdegrees (degrees * 10^6).
* The maximum latitude value of this BoundingBox in microdegrees (degrees *
* 10^6).
*/
public final int maxLatitudeE6;
/**
* The maximum longitude value of this BoundingBox in microdegrees (degrees * 10^6).
* The maximum longitude value of this BoundingBox in microdegrees (degrees
* * 10^6).
*/
public final int maxLongitudeE6;
/**
* The minimum latitude value of this BoundingBox in microdegrees (degrees * 10^6).
* The minimum latitude value of this BoundingBox in microdegrees (degrees *
* 10^6).
*/
public final int minLatitudeE6;
/**
* The minimum longitude value of this BoundingBox in microdegrees (degrees * 10^6).
* The minimum longitude value of this BoundingBox in microdegrees (degrees
* * 10^6).
*/
public final int minLongitudeE6;
@@ -76,10 +82,20 @@ public class BoundingBox implements Serializable {
this.hashCodeValue = calculateHashCode();
}
public BoundingBox(double minLatitude, double minLongitude, double maxLatitude,
double maxLongitude) {
this.minLatitudeE6 = (int) (minLatitude * 1E6);
this.minLongitudeE6 = (int) (minLongitude * 1E6);
this.maxLatitudeE6 = (int) (maxLatitude * 1E6);
this.maxLongitudeE6 = (int) (maxLongitude * 1E6);
this.hashCodeValue = calculateHashCode();
}
/**
* @param geoPoint
* the point whose coordinates should be checked.
* @return true if this BoundingBox contains the given GeoPoint, false otherwise.
* @return true if this BoundingBox contains the given GeoPoint, false
* otherwise.
*/
public boolean contains(GeoPoint geoPoint) {
return isBetween(geoPoint.latitudeE6, this.minLatitudeE6, this.maxLatitudeE6)
@@ -107,12 +123,14 @@ public class BoundingBox implements Serializable {
}
/**
* @return the GeoPoint at the horizontal and vertical center of this BoundingBox.
* @return the GeoPoint at the horizontal and vertical center of this
* BoundingBox.
*/
public GeoPoint getCenterPoint() {
int latitudeOffset = (this.maxLatitudeE6 - this.minLatitudeE6) / 2;
int longitudeOffset = (this.maxLongitudeE6 - this.minLongitudeE6) / 2;
return new GeoPoint(this.minLatitudeE6 + latitudeOffset, this.minLongitudeE6 + longitudeOffset);
return new GeoPoint(this.minLatitudeE6 + latitudeOffset, this.minLongitudeE6
+ longitudeOffset);
}
/**
@@ -175,8 +193,78 @@ public class BoundingBox implements Serializable {
return result;
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
private void readObject(ObjectInputStream objectInputStream) throws IOException,
ClassNotFoundException {
objectInputStream.defaultReadObject();
this.hashCodeValue = calculateHashCode();
}
/* code below is from osdmroid, @author Nicolas Gramlich */
public static BoundingBox fromGeoPoints(final ArrayList<? extends GeoPoint> partialPolyLine) {
int minLat = Integer.MAX_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int maxLon = Integer.MIN_VALUE;
for (final GeoPoint gp : partialPolyLine) {
minLat = Math.min(minLat, gp.latitudeE6);
minLon = Math.min(minLon, gp.longitudeE6);
maxLat = Math.max(maxLat, gp.latitudeE6);
maxLon = Math.max(maxLon, gp.longitudeE6);
}
return new BoundingBox(minLat, minLon, maxLat, maxLon);
}
public static final Parcelable.Creator<BoundingBox> CREATOR = new Parcelable.Creator<BoundingBox>() {
@Override
public BoundingBox createFromParcel(final Parcel in) {
return new BoundingBox(in.readInt(), in.readInt(), in.readInt(), in.readInt());
}
@Override
public BoundingBox[] newArray(final int size) {
return new BoundingBox[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(minLatitudeE6);
dest.writeInt(minLongitudeE6);
dest.writeInt(maxLatitudeE6);
dest.writeInt(maxLongitudeE6);
}
// public BoundingBox(final double north, final double east, final double south,
// final double west) {
// this((int) (north * 1E6), (int) (east * 1E6), (int) (south * 1E6), (int) (west * 1E6));
// // this.mLatNorthE6 = (int) (north * 1E6);
// // this.mLonEastE6 = (int) (east * 1E6);
// // this.mLatSouthE6 = (int) (south * 1E6);
// // this.mLonWestE6 = (int) (west * 1E6);
// }
// public int getLatNorthE6() {
// return this.maxLatitudeE6;
// }
//
// public int getLatSouthE6() {
// return this.minLatitudeE6;
// }
//
// public int getLonEastE6() {
// return this.maxLongitudeE6;
// }
//
// public int getLonWestE6() {
// return this.minLongitudeE6;
// }
}

View File

@@ -1,6 +1,8 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* Copyright 2012 osmdroid authors: Nicolas Gramlich, Theodore Hong
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
@@ -14,10 +16,14 @@
*/
package org.oscim.core;
import android.os.Parcel;
import android.os.Parcelable;
/**
* A GeoPoint represents an immutable pair of latitude and longitude coordinates.
* A GeoPoint represents an immutable pair of latitude and longitude
* coordinates.
*/
public class GeoPoint implements Comparable<GeoPoint> {
public class GeoPoint implements Parcelable, Comparable<GeoPoint> {
/**
* Conversion factor from degrees to microdegrees.
*/
@@ -33,6 +39,8 @@ public class GeoPoint implements Comparable<GeoPoint> {
*/
public final int longitudeE6;
// public final int altitude;
/**
* The hash code of this object.
*/
@@ -40,9 +48,11 @@ public class GeoPoint implements Comparable<GeoPoint> {
/**
* @param latitude
* the latitude in degrees, will be limited to the possible latitude range.
* the latitude in degrees, will be limited to the possible
* latitude range.
* @param longitude
* the longitude in degrees, will be limited to the possible longitude range.
* the longitude in degrees, will be limited to the possible
* longitude range.
*/
public GeoPoint(double latitude, double longitude) {
double limitLatitude = MercatorProjection.limitLatitude(latitude);
@@ -50,14 +60,15 @@ public class GeoPoint implements Comparable<GeoPoint> {
double limitLongitude = MercatorProjection.limitLongitude(longitude);
this.longitudeE6 = (int) (limitLongitude * CONVERSION_FACTOR);
}
/**
* @param latitudeE6
* the latitude in microdegrees (degrees * 10^6), will be limited to the possible latitude range.
* the latitude in microdegrees (degrees * 10^6), will be limited
* to the possible latitude range.
* @param longitudeE6
* the longitude in microdegrees (degrees * 10^6), will be limited to the possible longitude range.
* the longitude in microdegrees (degrees * 10^6), will be
* limited to the possible longitude range.
*/
public GeoPoint(int latitudeE6, int longitudeE6) {
this(latitudeE6 / CONVERSION_FACTOR, longitudeE6 / CONVERSION_FACTOR);
@@ -135,4 +146,66 @@ public class GeoPoint implements Comparable<GeoPoint> {
result = 31 * result + this.longitudeE6;
return result;
}
// ===========================================================
// Methods from osmdroid
// ===========================================================
public static final float DEG2RAD = (float) (Math.PI / 180.0);
public static final float RAD2DEG = (float) (180.0 / Math.PI);
// http://en.wikipedia.org/wiki/Earth_radius#Equatorial_radius
public static final int RADIUS_EARTH_METERS = 6378137;
/**
* @see "http://www.geocities.com/DrChengalva/GPSDistance.html"
* @param other
* ...
* @return distance in meters
*/
public int distanceTo(final GeoPoint other) {
double a1 = DEG2RAD * latitudeE6 / 1E6;
double a2 = DEG2RAD * longitudeE6 / 1E6;
double b1 = DEG2RAD * other.latitudeE6 / 1E6;
double b2 = DEG2RAD * other.longitudeE6 / 1E6;
double cosa1 = Math.cos(a1);
double cosb1 = Math.cos(b1);
double t1 = cosa1 * Math.cos(a2) * cosb1 * Math.cos(b2);
double t2 = cosa1 * Math.sin(a2) * cosb1 * Math.sin(b2);
double t3 = Math.sin(a1) * Math.sin(b1);
double tt = Math.acos(t1 + t2 + t3);
return (int) (RADIUS_EARTH_METERS * tt);
}
// ===========================================================
// Parcelable
// ===========================================================
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(final Parcel out, final int flags) {
out.writeInt(latitudeE6);
out.writeInt(longitudeE6);
}
public static final Parcelable.Creator<GeoPoint> CREATOR = new Parcelable.Creator<GeoPoint>() {
@Override
public GeoPoint createFromParcel(final Parcel in) {
return new GeoPoint(in.readInt(), in.readInt());
}
@Override
public GeoPoint[] newArray(final int size) {
return new GeoPoint[size];
}
};
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -16,9 +17,7 @@ package org.oscim.core;
import android.opengl.Matrix;
/**
* A MapPosition Container.
*/
/** A MapPosition Container. */
public class MapPosition {
public double lon;
@@ -33,7 +32,9 @@ public class MapPosition {
public double y;
public float[] viewMatrix;
public float[] rotateMatrix;
// // DO NOT MODIFY! shared with MapViewPosition
// public float[] projMatrix;
public MapPosition() {
this.zoomLevel = (byte) 1;
@@ -49,19 +50,32 @@ public class MapPosition {
public void init() {
viewMatrix = new float[16];
Matrix.setIdentityM(viewMatrix, 0);
rotateMatrix = new float[16];
Matrix.setIdentityM(rotateMatrix, 0);
//
// rotateMatrix = new float[16];
// Matrix.setIdentityM(rotateMatrix, 0);
}
/**
* @param geoPoint
// 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.
* @param zoomLevel
* the zoom level.
* @param scale
* ...
*/
* ... */
public MapPosition(GeoPoint geoPoint, byte zoomLevel, float scale) {
this.zoomLevel = zoomLevel;
this.scale = scale;

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -14,6 +15,7 @@
*/
package org.oscim.core;
import android.graphics.Point;
/**
* An implementation of the spherical Mercator projection.
@@ -246,4 +248,13 @@ public final class MercatorProjection {
private MercatorProjection() {
throw new IllegalStateException();
}
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;
}
}