Add projection functions to Java
This commit is contained in:
@@ -30,6 +30,7 @@ import android.widget.ZoomButtonsController;
|
||||
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
|
||||
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
|
||||
import com.mapbox.mapboxgl.lib.geometry.LatLng;
|
||||
import com.mapbox.mapboxgl.lib.geometry.LatLngZoom;
|
||||
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
|
||||
@@ -135,7 +136,6 @@ public class MapView extends SurfaceView {
|
||||
|
||||
// Check if we are in Eclipse UI editor
|
||||
if (isInEditMode()) {
|
||||
// TODO editor does not load properly because we don't implement this
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ public class MapView extends SurfaceView {
|
||||
|
||||
public void removeAllClasses(long transitionDuration) {
|
||||
mNativeMapView.setDefaultTransitionDuration(transitionDuration);
|
||||
ArrayList<String> classes = new ArrayList<String>(0);
|
||||
ArrayList<String> classes = new ArrayList<>(0);
|
||||
setClasses(classes);
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ public class MapView extends SurfaceView {
|
||||
outState.putBoolean(STATE_DEBUG_ACTIVE, isDebugActive());
|
||||
outState.putString(STATE_STYLE_URL, mStyleUrl);
|
||||
outState.putString(STATE_ACCESS_TOKEN, getAccessToken());
|
||||
outState.putStringArrayList(STATE_CLASSES, new ArrayList<String>(getClasses()));
|
||||
outState.putStringArrayList(STATE_CLASSES, new ArrayList<>(getClasses()));
|
||||
outState.putLong(STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
|
||||
}
|
||||
|
||||
@@ -531,8 +531,6 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO examine how GLSurvaceView hadles attach/detach from window
|
||||
|
||||
// Called when view is no longer connected
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
@@ -560,10 +558,6 @@ public class MapView extends SurfaceView {
|
||||
// Draw events
|
||||
//
|
||||
|
||||
// TODO: onDraw for UI editor mockup?
|
||||
// By default it just shows a gray screen with "MapView"
|
||||
// Not too important but perhaps we could put a static demo map image there
|
||||
|
||||
//
|
||||
// Input events
|
||||
//
|
||||
@@ -782,7 +776,7 @@ public class MapView extends SurfaceView {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO complex decision between roate or scale or both (see Google
|
||||
// TODO complex decision between rotate or scale or both (see Google
|
||||
// Maps app)
|
||||
|
||||
// Cancel any animation
|
||||
@@ -1011,7 +1005,6 @@ public class MapView extends SurfaceView {
|
||||
|
||||
// Called for trackball events, all motions are relative in device specific
|
||||
// units
|
||||
// TODO: test trackball click and long click
|
||||
@Override
|
||||
public boolean onTrackballEvent(MotionEvent event) {
|
||||
// Choose the action
|
||||
@@ -1105,8 +1098,6 @@ public class MapView extends SurfaceView {
|
||||
@Override @TargetApi(12)
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
// Mouse events
|
||||
// TODO: SOURCE_TOUCH_NAVIGATION?
|
||||
// TODO: source device resolution?
|
||||
//if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { // this is not available before API 18
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == InputDevice.SOURCE_CLASS_POINTER) {
|
||||
// Choose the action
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.mapbox.mapboxgl.lib;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.view.Surface;
|
||||
|
||||
import com.mapbox.mapboxgl.lib.geometry.LatLng;
|
||||
import com.mapbox.mapboxgl.lib.geometry.LatLngZoom;
|
||||
import com.mapbox.mapboxgl.lib.geometry.ProjectedMeters;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -392,6 +395,30 @@ class NativeMapView {
|
||||
nativeSetReachability(mNativeMapViewPtr, status);
|
||||
}
|
||||
|
||||
//public void getWorldBoundsMeters();
|
||||
|
||||
//public void getWorldBoundsLatLng();
|
||||
|
||||
public double getMetersPerPixelAtLatitude(double lat, double zoom) {
|
||||
return nativeGetMetersPerPixelAtLatitude(mNativeMapViewPtr, lat, zoom);
|
||||
}
|
||||
|
||||
public ProjectedMeters projectedMetersForLatLng(LatLng latLng) {
|
||||
return nativeProjectedMetersForLatLng(mNativeMapViewPtr, latLng);
|
||||
}
|
||||
|
||||
public LatLng latLngForProjectedMeters(ProjectedMeters projectedMeters) {
|
||||
return nativeLatLngForProjectedMeters(mNativeMapViewPtr, projectedMeters);
|
||||
}
|
||||
|
||||
public PointF pixelForLatLng(LatLng latLng) {
|
||||
return nativePixelForLatLng(mNativeMapViewPtr, latLng);
|
||||
}
|
||||
|
||||
public LatLng latLngForPixel(PointF pixel) {
|
||||
return nativeLatLngForPixel(mNativeMapViewPtr, pixel);
|
||||
}
|
||||
|
||||
//
|
||||
// Callbacks
|
||||
//
|
||||
@@ -553,4 +580,18 @@ class NativeMapView {
|
||||
private native boolean nativeGetDebug(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeSetReachability(long nativeMapViewPtr, boolean status);
|
||||
|
||||
//private native void nativeGetWorldBoundsMeters(long nativeMapViewPtr);
|
||||
|
||||
//private native void nativeGetWorldBoundsLatLng(long nativeMapViewPtr);
|
||||
|
||||
private native double nativeGetMetersPerPixelAtLatitude(long nativeMapViewPtr, double lat, double zoom);
|
||||
|
||||
private native ProjectedMeters nativeProjectedMetersForLatLng(long nativeMapViewPtr, LatLng latLng);
|
||||
|
||||
private native LatLng nativeLatLngForProjectedMeters(long nativeMapViewPtr, ProjectedMeters projectedMeters);
|
||||
|
||||
private native PointF nativePixelForLatLng(long nativeMapViewPtr, LatLng latLng);
|
||||
|
||||
private native LatLng nativeLatLngForPixel(long nativeMapViewPtr, PointF pixel);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mapbox.mapboxgl.lib.constants;
|
||||
|
||||
public interface GeoConstants {
|
||||
public class GeoConstants {
|
||||
// http://en.wikipedia.org/wiki/Earth_radius#Equatorial_radius
|
||||
public static final int RADIUS_EARTH_METERS = 6378137;
|
||||
public static final double MIN_LATITUDE = -85.05112878;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mapbox.mapboxgl.lib.constants;
|
||||
|
||||
public interface MathConstants {
|
||||
public class MathConstants {
|
||||
public static final double DEG2RAD = (Math.PI / 180.0);
|
||||
public static final double RAD2DEG = (180.0 / Math.PI);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mapbox.mapboxgl.lib.geometry;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,8 +11,6 @@ import java.util.List;
|
||||
*/
|
||||
public final class BoundingBox implements Parcelable, Serializable {
|
||||
|
||||
static final long serialVersionUID = 2L;
|
||||
|
||||
private final double mLatNorth;
|
||||
private final double mLatSouth;
|
||||
private final double mLonEast;
|
||||
|
||||
@@ -7,7 +7,7 @@ public class CoordinateRegion {
|
||||
private LatLng center;
|
||||
private CoordinateSpan span;
|
||||
|
||||
public CoordinateRegion(LatLng center, CoordinateSpan span) {
|
||||
public CoordinateRegion(final LatLng center, final CoordinateSpan span) {
|
||||
this.center = center;
|
||||
this.span = span;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class CoordinateRegion {
|
||||
return center;
|
||||
}
|
||||
|
||||
public void setCenter(LatLng center) {
|
||||
public void setCenter(final LatLng center) {
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class CoordinateRegion {
|
||||
return span;
|
||||
}
|
||||
|
||||
public void setSpan(CoordinateSpan span) {
|
||||
public void setSpan(final CoordinateSpan span) {
|
||||
this.span = span;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package com.mapbox.mapboxgl.lib.geometry;
|
||||
/**
|
||||
* Implementation of iOS MKCoordinateSpan
|
||||
*/
|
||||
public final class CoordinateSpan {
|
||||
public class CoordinateSpan {
|
||||
|
||||
private double latitudeSpan;
|
||||
private double longitudeSpan;
|
||||
|
||||
public CoordinateSpan(double latitudeSpan, double longitudeSpan) {
|
||||
public CoordinateSpan(final double latitudeSpan, final double longitudeSpan) {
|
||||
this.latitudeSpan = latitudeSpan;
|
||||
this.longitudeSpan = longitudeSpan;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public final class CoordinateSpan {
|
||||
return latitudeSpan;
|
||||
}
|
||||
|
||||
public void setLatitudeSpan(double latitudeSpan) {
|
||||
public void setLatitudeSpan(final double latitudeSpan) {
|
||||
this.latitudeSpan = latitudeSpan;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public final class CoordinateSpan {
|
||||
return longitudeSpan;
|
||||
}
|
||||
|
||||
public void setLongitudeSpan(double longitudeSpan) {
|
||||
public void setLongitudeSpan(final double longitudeSpan) {
|
||||
this.longitudeSpan = longitudeSpan;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.mapbox.mapboxgl.lib.geometry;
|
||||
|
||||
public interface IProjectedMeters {
|
||||
double getNorthing();
|
||||
|
||||
double getEasting();
|
||||
}
|
||||
@@ -3,11 +3,13 @@ package com.mapbox.mapboxgl.lib.geometry;
|
||||
import android.location.Location;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxgl.lib.constants.GeoConstants;
|
||||
import com.mapbox.mapboxgl.lib.constants.MathConstants;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable, Serializable {
|
||||
public class LatLng implements ILatLng, Parcelable, Serializable {
|
||||
|
||||
public static final Parcelable.Creator<LatLng> CREATOR = new Parcelable.Creator<LatLng>() {
|
||||
public LatLng createFromParcel(Parcel in) {
|
||||
@@ -26,7 +28,7 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
/**
|
||||
* Construct a new latitude, longitude point given float arguments
|
||||
* @param latitude Latitude in degrees
|
||||
* @param longitude Longitude in degress
|
||||
* @param longitude Longitude in degrees
|
||||
*/
|
||||
public LatLng(double latitude, double longitude) {
|
||||
this.latitude = latitude;
|
||||
@@ -39,7 +41,7 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
* @param longitude Longitude in degress
|
||||
* @param altitude Altitude in meters
|
||||
*/
|
||||
public LatLng(final double latitude, final double longitude, final double altitude) {
|
||||
public LatLng(double latitude, double longitude, double altitude) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
@@ -49,7 +51,7 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
* Transform a Location into a LatLng point
|
||||
* @param location Android Location
|
||||
*/
|
||||
public LatLng(final Location location) {
|
||||
public LatLng(Location location) {
|
||||
this(location.getLatitude(), location.getLongitude(), location.getAltitude());
|
||||
}
|
||||
|
||||
@@ -57,15 +59,15 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
* Clone an existing latitude longitude point
|
||||
* @param aLatLng LatLng
|
||||
*/
|
||||
public LatLng(final LatLng aLatLng) {
|
||||
public LatLng(LatLng aLatLng) {
|
||||
this.latitude = aLatLng.latitude;
|
||||
this.longitude = aLatLng.longitude;
|
||||
this.altitude = aLatLng.altitude;
|
||||
}
|
||||
|
||||
protected LatLng(Parcel in) {
|
||||
longitude = in.readDouble();
|
||||
latitude = in.readDouble();
|
||||
longitude = in.readDouble();
|
||||
altitude = in.readDouble();
|
||||
}
|
||||
|
||||
@@ -86,14 +88,25 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LatLng latLng = (LatLng) o;
|
||||
|
||||
if (Double.compare(latLng.altitude, altitude) != 0) return false;
|
||||
if (Double.compare(latLng.latitude, latitude) != 0) return false;
|
||||
if (Double.compare(latLng.longitude, longitude) != 0) return false;
|
||||
if (Double.compare(latLng.altitude, altitude) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Double.compare(latLng.latitude, latitude) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Double.compare(latLng.longitude, longitude) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -123,8 +136,8 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeDouble(longitude);
|
||||
out.writeDouble(latitude);
|
||||
out.writeDouble(longitude);
|
||||
out.writeDouble(altitude);
|
||||
}
|
||||
|
||||
@@ -133,12 +146,12 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
* @param other Other LatLng to compare to
|
||||
* @return distance in meters
|
||||
*/
|
||||
public double distanceTo(final LatLng other) {
|
||||
public double distanceTo(LatLng other) {
|
||||
|
||||
final double a1 = DEG2RAD * this.latitude;
|
||||
final double a2 = DEG2RAD * this.longitude;
|
||||
final double b1 = DEG2RAD * other.getLatitude();
|
||||
final double b2 = DEG2RAD * other.getLongitude();
|
||||
final double a1 = MathConstants.DEG2RAD * this.latitude;
|
||||
final double a2 = MathConstants.DEG2RAD * this.longitude;
|
||||
final double b1 = MathConstants.DEG2RAD * other.getLatitude();
|
||||
final double b2 = MathConstants.DEG2RAD * other.getLongitude();
|
||||
|
||||
final double cosa1 = Math.cos(a1);
|
||||
final double cosb1 = Math.cos(b1);
|
||||
@@ -148,6 +161,6 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
|
||||
final double t3 = Math.sin(a1) * Math.sin(b1);
|
||||
final double tt = Math.acos(t1 + t2 + t3);
|
||||
|
||||
return RADIUS_EARTH_METERS * tt;
|
||||
return GeoConstants.RADIUS_EARTH_METERS * tt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.mapbox.mapboxgl.lib;
|
||||
package com.mapbox.mapboxgl.lib.geometry;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.mapbox.mapboxgl.lib.geometry.LatLng;
|
||||
|
||||
public class LatLngZoom extends LatLng implements Parcelable {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class LatLngZoom extends LatLng implements Parcelable, Serializable {
|
||||
|
||||
public static final Parcelable.Creator<LatLngZoom> CREATOR = new Parcelable.Creator<LatLngZoom>() {
|
||||
public LatLngZoom createFromParcel(Parcel in) {
|
||||
@@ -18,8 +19,8 @@ public class LatLngZoom extends LatLng implements Parcelable {
|
||||
|
||||
private double zoom;
|
||||
|
||||
public LatLngZoom(double lat, double lon, double zoom) {
|
||||
super(lat, lon);
|
||||
public LatLngZoom(double latitude, double longitude, double zoom) {
|
||||
super(latitude, longitude);
|
||||
this.zoom = zoom;
|
||||
}
|
||||
|
||||
@@ -43,13 +44,21 @@ public class LatLngZoom extends LatLng implements Parcelable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LatLngZoom that = (LatLngZoom) o;
|
||||
|
||||
if (Double.compare(that.zoom, zoom) != 0) return false;
|
||||
if (Double.compare(that.zoom, zoom) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mapbox.mapboxgl.lib.geometry;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ProjectedMeters implements IProjectedMeters, Parcelable, Serializable {
|
||||
|
||||
public static final Creator<ProjectedMeters> CREATOR = new Creator<ProjectedMeters>() {
|
||||
public ProjectedMeters createFromParcel(Parcel in) {
|
||||
return new ProjectedMeters(in);
|
||||
}
|
||||
|
||||
public ProjectedMeters[] newArray(int size) {
|
||||
return new ProjectedMeters[size];
|
||||
}
|
||||
};
|
||||
|
||||
private double northing;
|
||||
private double easting;
|
||||
|
||||
public ProjectedMeters(double northing, double easting) {
|
||||
this.northing = northing;
|
||||
this.easting = easting;
|
||||
}
|
||||
|
||||
public ProjectedMeters(ProjectedMeters aProjectedMeters) {
|
||||
this.northing = aProjectedMeters.northing;
|
||||
this.easting = aProjectedMeters.easting;
|
||||
}
|
||||
|
||||
protected ProjectedMeters(Parcel in) {
|
||||
northing = in.readDouble();
|
||||
easting = in.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNorthing() {
|
||||
return northing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEasting() {
|
||||
return easting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectedMeters projectedMeters = (ProjectedMeters) o;
|
||||
|
||||
if (Double.compare(projectedMeters.easting, easting) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Double.compare(projectedMeters.northing, northing) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(easting);
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(northing);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProjectedMeters [northing=" + northing + ", easting=" + easting + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeDouble(northing);
|
||||
out.writeDouble(easting);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxgl.lib.LatLngZoom;
|
||||
import com.mapbox.mapboxgl.lib.geometry.LatLngZoom;
|
||||
import com.mapbox.mapboxgl.lib.MapView;
|
||||
import com.mapzen.android.lost.LocationClient;
|
||||
import com.mapzen.android.lost.LocationListener;
|
||||
@@ -283,7 +283,7 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
ArrayList<String> classes = new ArrayList<String>(1);
|
||||
ArrayList<String> classes = new ArrayList<>(1);
|
||||
|
||||
switch(position) {
|
||||
// Day
|
||||
@@ -315,7 +315,7 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
ArrayList<String> classes = new ArrayList<String>(2);
|
||||
ArrayList<String> classes = new ArrayList<>(2);
|
||||
|
||||
switch(position) {
|
||||
// Labels + Contours
|
||||
|
||||
Reference in New Issue
Block a user