[android] #3758 - Projection / Visible Region implementation.

[android] #3758 - add VisibleRegion + unit tests, removed boundingbox, cleanup jni, cleanup test app, renamed CoordinateSpan to LatLng.
This commit is contained in:
Tobrun
2016-02-03 17:26:09 +01:00
parent bc1f4b1fc0
commit aa05cba0df
24 changed files with 460 additions and 686 deletions

View File

@@ -99,7 +99,7 @@ public class InfoWindow {
// Calculate default Android x,y coordinate
mCoordinates = mapboxMap.toScreenLocation(position);
mCoordinates = mapboxMap.getProjection().toScreenLocation(position);
float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - view.getMeasuredHeight() + offsetY;
@@ -231,7 +231,7 @@ public class InfoWindow {
Marker marker = mBoundMarker.get();
View view = mView.get();
if (mapboxMap != null && marker != null && view != null) {
mCoordinates = mapboxMap.toScreenLocation(marker.getPosition());
mCoordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
view.setX(mCoordinates.x + mViewWidthOffset);
view.setY(mCoordinates.y + mMarkerHeightOffset);
}

View File

@@ -1,297 +0,0 @@
package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
import java.io.Serializable;
import java.util.List;
/**
* A rectangular geographical area defined in latitude and longitude units.
*/
public final class BoundingBox implements Parcelable {
private final double mLatNorth;
private final double mLatSouth;
private final double mLonEast;
private final double mLonWest;
private final boolean mIsValid;
/**
* Construct a new bounding box based on its corners, given in NESW
* order.
*
* @param northLatitude Northern Latitude
* @param eastLongitude Eastern Longitude
* @param southLatitude Southern Latitude
* @param westLongitude Western Longitude
*/
public BoundingBox(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
this.mLatNorth = northLatitude;
this.mLonEast = eastLongitude;
this.mLatSouth = southLatitude;
this.mLonWest = westLongitude;
this.mIsValid = ((this.mLonWest < this.mLonEast) && (this.mLatNorth > this.mLatSouth));
}
/**
* Construct a new bounding box based on its corners, given in NESW order.
*
* @param northEast Coordinate
* @param southWest Coordinate
*/
public BoundingBox(final LatLng northEast, final LatLng southWest) {
this(northEast.getLatitude(), northEast.getLongitude(), southWest.getLatitude(), southWest.getLongitude());
}
/**
* Create a bounding box from another bounding box
*
* @param other the other bounding box
*/
public BoundingBox(final BoundingBox other) {
this.mLatNorth = other.getLatNorth();
this.mLonEast = other.getLonEast();
this.mLatSouth = other.getLatSouth();
this.mLonWest = other.getLonWest();
this.mIsValid = other.isValid();
}
/**
* Calculates the centerpoint of this bounding box by simple interpolation and returns
* it as a point. This is a non-geodesic calculation which is not the geographic center.
*
* @return LatLng center of this BoundingBox
*/
public LatLng getCenter() {
return new LatLng((this.mLatNorth + this.mLatSouth) / 2,
(this.mLonEast + this.mLonWest) / 2);
}
public double getLatNorth() {
return this.mLatNorth;
}
public double getLatSouth() {
return this.mLatSouth;
}
public double getLonEast() {
return this.mLonEast;
}
public double getLonWest() {
return this.mLonWest;
}
public boolean isValid() {
return this.mIsValid;
}
/**
* Get the area spanned by this bounding box
*
* @return CoordinateSpan area
*/
public CoordinateSpan getSpan() {
return new CoordinateSpan(getLatitudeSpan(), getLongitudeSpan());
}
/**
* Get the absolute distance, in degrees, between the north and
* south boundaries of this bounding box
*
* @return Span distance
*/
public double getLatitudeSpan() {
return Math.abs(this.mLatNorth - this.mLatSouth);
}
/**
* Get the absolute distance, in degrees, between the west and
* east boundaries of this bounding box
*
* @return Span distance
*/
public double getLongitudeSpan() {
return Math.abs(this.mLonEast - this.mLonWest);
}
/**
* Validate if bounding box is empty, determined if absolute distance is
*
* @return boolean indicating if span is empty
*/
public boolean isEmpty() {
return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
}
@Override
public String toString() {
return "N:" + this.mLatNorth + "; E:" + this.mLonEast + "; S:" + this.mLatSouth + "; W:" + this.mLonWest;
}
/**
* Constructs a bounding box that contains all of a list of LatLng
* objects. Empty lists will yield invalid bounding boxes.
*
* @param latLngs List of LatLng objects
* @return BoundingBox
*/
public static BoundingBox fromLatLngs(final List<? extends ILatLng> latLngs) {
double minLat = 90,
minLon = 180,
maxLat = -90,
maxLon = -180;
for (final ILatLng gp : latLngs) {
final double latitude = gp.getLatitude();
final double longitude = gp.getLongitude();
minLat = Math.min(minLat, latitude);
minLon = Math.min(minLon, longitude);
maxLat = Math.max(maxLat, latitude);
maxLon = Math.max(maxLon, longitude);
}
return new BoundingBox(maxLat, maxLon, minLat, minLon);
}
/**
* Determines whether this bounding box matches another one via coordinates.
*
* @param o another object
* @return a boolean indicating whether the bounding boxes are equal
*/
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o instanceof BoundingBox) {
BoundingBox other = (BoundingBox) o;
return mLatNorth == other.getLatNorth()
&& mLatSouth == other.getLatSouth()
&& mLonEast == other.getLonEast()
&& mLonWest == other.getLonWest();
}
return false;
}
/**
* Determines whether this bounding box contains a point and the point
* does not touch its boundary.
*
* @param pGeoPoint the point which may be contained
* @return true, if the point is contained within the box.
*/
public boolean contains(final ILatLng pGeoPoint) {
final double latitude = pGeoPoint.getLatitude();
final double longitude = pGeoPoint.getLongitude();
return ((latitude < this.mLatNorth)
&& (latitude > this.mLatSouth))
&& ((longitude < this.mLonEast)
&& (longitude > this.mLonWest));
}
/**
* Returns a new BoundingBox that stretches to contain both this and another BoundingBox.
*
* @param box BoundingBox to add
* @return BoundingBox
*/
public BoundingBox union(BoundingBox box) {
return union(box.getLatNorth(), box.getLonEast(), box.getLatSouth(), box.getLonWest());
}
/**
* Returns a new BoundingBox that stretches to include another bounding box,
* given by corner points.
*
* @param lonNorth Northern Longitude
* @param latEast Eastern Latitude
* @param lonSouth Southern Longitude
* @param latWest Western Longitude
* @return BoundingBox
*/
public BoundingBox union(final double lonNorth, final double latEast, final double lonSouth, final double latWest) {
return new BoundingBox((this.mLatNorth < lonNorth) ? lonNorth : this.mLatNorth,
(this.mLonEast < latEast) ? latEast : this.mLonEast,
(this.mLatSouth > lonSouth) ? lonSouth : this.mLatSouth,
(this.mLonWest > latWest) ? latWest : this.mLonWest);
}
/**
* Returns a new BoundingBox that is the intersection of this with another box
*
* @param box BoundingBox to intersect with
* @return BoundingBox
*/
public BoundingBox intersect(BoundingBox box) {
double minLatWest = Math.max(getLonWest(), box.getLonWest());
double maxLatEast = Math.min(getLonEast(), box.getLonEast());
if (maxLatEast > minLatWest) {
double minLonSouth = Math.max(getLatSouth(), box.getLatSouth());
double maxLonNorth = Math.min(getLatNorth(), box.getLatNorth());
if (maxLonNorth > minLonSouth) {
return new BoundingBox(maxLonNorth, maxLatEast, minLonSouth, minLatWest);
}
}
return null;
}
/**
* Returns a new BoundingBox that is the intersection of this with another box
*
* @param northLongitude Northern Longitude
* @param eastLatitude Eastern Latitude
* @param southLongitude Southern Longitude
* @param westLatitude Western Latitude
* @return BoundingBox
*/
public BoundingBox intersect(double northLongitude, double eastLatitude, double southLongitude, double westLatitude) {
return intersect(new BoundingBox(northLongitude, eastLatitude, southLongitude, westLatitude));
}
public static final Parcelable.Creator<BoundingBox> CREATOR =
new Parcelable.Creator<BoundingBox>() {
@Override
public BoundingBox createFromParcel(final Parcel in) {
return readFromParcel(in);
}
@Override
public BoundingBox[] newArray(final int size) {
return new BoundingBox[size];
}
};
@Override
public int hashCode() {
return (int) ((mLatNorth + 90)
+ ((mLatSouth + 90) * 1000)
+ ((mLonEast + 180) * 1000000)
+ ((mLonEast + 180) * 1000000000));
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(final Parcel out, final int arg1) {
out.writeDouble(this.mLatNorth);
out.writeDouble(this.mLonEast);
out.writeDouble(this.mLatSouth);
out.writeDouble(this.mLonWest);
}
private static BoundingBox readFromParcel(final Parcel in) {
final double lonNorth = in.readDouble();
final double latEast = in.readDouble();
final double lonSouth = in.readDouble();
final double latWest = in.readDouble();
return new BoundingBox(lonNorth, latEast, lonSouth, latWest);
}
}

View File

@@ -3,10 +3,7 @@ package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import java.util.ArrayList;
@@ -68,10 +65,10 @@ public class LatLngBounds implements Parcelable {
/**
* Get the area spanned by this LatLngBounds
*
* @return CoordinateSpan area
* @return LatLngSpan area
*/
public CoordinateSpan getSpan() {
return new CoordinateSpan(getLatitudeSpan(), getLongitudeSpan());
public LatLngSpan getSpan() {
return new LatLngSpan(getLatitudeSpan(), getLongitudeSpan());
}
/**

View File

@@ -7,17 +7,17 @@ import android.support.annotation.NonNull;
/**
* A geographical span defined by its latitude and longitude span.
*/
public class CoordinateSpan implements Parcelable {
public class LatLngSpan implements Parcelable {
private double mLatitudeSpan;
private double mLongitudeSpan;
public CoordinateSpan(@NonNull Parcel in){
public LatLngSpan(@NonNull Parcel in){
mLatitudeSpan = in.readDouble();
mLongitudeSpan = in.readDouble();
}
public CoordinateSpan(double latitudeSpan, double longitudeSpan) {
public LatLngSpan(double latitudeSpan, double longitudeSpan) {
mLatitudeSpan = latitudeSpan;
mLongitudeSpan = longitudeSpan;
}
@@ -41,24 +41,24 @@ public class CoordinateSpan implements Parcelable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof CoordinateSpan) {
CoordinateSpan other = (CoordinateSpan) o;
if (o instanceof LatLngSpan) {
LatLngSpan other = (LatLngSpan) o;
return mLongitudeSpan == other.getLongitudeSpan()
&& mLatitudeSpan == other.getLatitudeSpan();
}
return false;
}
public static final Parcelable.Creator<CoordinateSpan> CREATOR =
new Parcelable.Creator<CoordinateSpan>() {
public static final Parcelable.Creator<LatLngSpan> CREATOR =
new Parcelable.Creator<LatLngSpan>() {
@Override
public CoordinateSpan createFromParcel(Parcel in) {
return new CoordinateSpan(in);
public LatLngSpan createFromParcel(Parcel in) {
return new LatLngSpan(in);
}
@Override
public CoordinateSpan[] newArray(int size) {
return new CoordinateSpan[size];
public LatLngSpan[] newArray(int size) {
return new LatLngSpan[size];
}
};

View File

@@ -0,0 +1,120 @@
package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Contains the four points defining the four-sided polygon that is visible in a map's camera.
* This polygon can be a trapezoid instead of a rectangle, because a camera can have tilt.
* If the camera is directly over the center of the camera, the shape is rectangular,
* but if the camera is tilted, the shape will appear to be a trapezoid whose
* smallest side is closest to the point of view.
*/
public class VisibleRegion implements Parcelable {
/**
* LatLng object that defines the far left corner of the camera.
*/
public final LatLng farLeft;
/**
* LatLng object that defines the far right corner of the camera.
*/
public final LatLng farRight;
/**
* LatLng object that defines the bottom left corner of the camera.
*/
public final LatLng nearLeft;
/**
* LatLng object that defines the bottom right corner of the camera.
*/
public final LatLng nearRight;
/**
* The smallest bounding box that includes the visible region defined in this class.
*/
public final LatLngBounds latLngBounds;
private VisibleRegion(Parcel in) {
this.farLeft = in.readParcelable(LatLng.class.getClassLoader());
this.farRight = in.readParcelable(LatLng.class.getClassLoader());
this.nearLeft = in.readParcelable(LatLng.class.getClassLoader());
this.nearRight = in.readParcelable(LatLng.class.getClassLoader());
this.latLngBounds = in.readParcelable(LatLngBounds.class.getClassLoader());
}
/**
* Creates a new VisibleRegion given the four corners of the camera.
*
* @param farLeft A LatLng object containing the latitude and longitude of the near left corner of the region.
* @param farRight A LatLng object containing the latitude and longitude of the near left corner of the region.
* @param nearLeft A LatLng object containing the latitude and longitude of the near left corner of the region.
* @param nearRight A LatLng object containing the latitude and longitude of the near left corner of the region.
* @param latLngBounds The smallest bounding box that includes the visible region defined in this class.
*/
public VisibleRegion(LatLng farLeft, LatLng farRight, LatLng nearLeft, LatLng nearRight, LatLngBounds latLngBounds) {
this.farLeft = farLeft;
this.farRight = farRight;
this.nearLeft = nearLeft;
this.nearRight = nearRight;
this.latLngBounds = latLngBounds;
}
/**
* Compares this VisibleRegion to another object.
* If the other object is actually a pointer to this object,
* or if all four corners and the bounds of the two objects are the same,
* this method returns true. Otherwise, this method returns false.
* @param o The Object to compare with.
* @return true if both objects are the same object.
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof VisibleRegion)) {
return false;
}
if (o == this) {
return true;
}
VisibleRegion visibleRegion = (VisibleRegion) o;
return farLeft.equals(visibleRegion.farLeft)
&& farRight.equals(visibleRegion.farRight)
&& nearLeft.equals(visibleRegion.nearLeft)
&& nearRight.equals(visibleRegion.nearRight)
&& latLngBounds.equals(visibleRegion.latLngBounds);
}
@Override
public String toString() {
return "[farLeft [" + farLeft + "], farRight [" + farRight + "], nearLeft [" + nearLeft + "], nearRight [" + nearRight + "], latLngBounds ["+latLngBounds+"]]";
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(farLeft, flags);
out.writeParcelable(farRight, flags);
out.writeParcelable(nearLeft, flags);
out.writeParcelable(nearRight, flags);
out.writeParcelable(latLngBounds, flags);
}
public static final Parcelable.Creator<VisibleRegion> CREATOR
= new Parcelable.Creator<VisibleRegion>() {
public VisibleRegion createFromParcel(Parcel in) {
return new VisibleRegion(in);
}
public VisibleRegion[] newArray(int size) {
return new VisibleRegion[size];
}
};
}

View File

@@ -240,7 +240,7 @@ public class CameraUpdateFactory {
centerPixel.y = viewportHeight - centerPixel.y;
LatLng center = mapboxMap.fromScreenLocation(centerPixel);
LatLng center = mapboxMap.getProjection().fromScreenLocation(centerPixel);
return new CameraPosition.Builder()
.target(center)
@@ -370,7 +370,7 @@ public class CameraUpdateFactory {
} else {
return new CameraPosition.Builder(cameraPosition)
.zoom(transformZoom(cameraPosition.zoom))
.target(mapboxMap.fromScreenLocation(new PointF(getX(), getY())))
.target(mapboxMap.getProjection().fromScreenLocation(new PointF(getX(), getY())))
.build();
}
}

View File

@@ -73,8 +73,8 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.utils.ApiAccess;
@@ -1254,7 +1254,7 @@ public class MapView extends FrameLayout {
return new ArrayList<>(mAnnotations);
}
private List<Marker> getMarkersInBounds(@NonNull BoundingBox bbox) {
private List<Marker> getMarkersInBounds(@NonNull LatLngBounds bbox) {
if (bbox == null) {
Log.w(TAG, "bbox was null, so just returning null");
return null;
@@ -1699,15 +1699,13 @@ public class MapView extends FrameLayout {
RectF tapRect = new RectF(tapPoint.x - toleranceSides, tapPoint.y + toleranceTop,
tapPoint.x + toleranceSides, tapPoint.y - toleranceBottom);
List<LatLng> corners = Arrays.asList(
fromScreenLocation(new PointF(tapRect.left, tapRect.bottom)),
fromScreenLocation(new PointF(tapRect.left, tapRect.top)),
fromScreenLocation(new PointF(tapRect.right, tapRect.top)),
fromScreenLocation(new PointF(tapRect.right, tapRect.bottom))
);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(fromScreenLocation(new PointF(tapRect.left, tapRect.bottom)));
builder.include(fromScreenLocation(new PointF(tapRect.left, tapRect.top)));
builder.include(fromScreenLocation(new PointF(tapRect.right, tapRect.top)));
builder.include(fromScreenLocation(new PointF(tapRect.right, tapRect.bottom)));
BoundingBox tapBounds = BoundingBox.fromLatLngs(corners);
List<Marker> nearbyMarkers = getMarkersInBounds(tapBounds);
List<Marker> nearbyMarkers = getMarkersInBounds(builder.build());
long newSelectedMarkerId = -1;
if (nearbyMarkers != null && nearbyMarkers.size() > 0) {

View File

@@ -2,7 +2,7 @@ package com.mapbox.mapboxsdk.maps;
import android.Manifest;
import android.content.Context;
import android.graphics.PointF;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.FloatRange;
@@ -39,6 +39,7 @@ public class MapboxMap {
private MapView mMapView;
private UiSettings mUiSettings;
private Projection mProjection;
private CameraPosition mCameraPosition;
private boolean mInvalidCameraPosition;
private String mStyleUrl;
@@ -63,6 +64,7 @@ public class MapboxMap {
mMapView = mapView;
mMapView.addOnMapChangedListener(new MapChangeCameraPositionListener());
mUiSettings = new UiSettings(mapView);
mProjection = new Projection(mapView);
mSelectedMarkers = new ArrayList<>();
mInfoWindows = new ArrayList<>();
}
@@ -80,6 +82,17 @@ public class MapboxMap {
return mUiSettings;
}
//
// Projection
//
/**
* Get the Projection object that you can use to convert between screen coordinates and latitude/longitude coordinates.
*/
public Projection getProjection() {
return mProjection;
}
//
// Camera API
//
@@ -438,49 +451,6 @@ public class MapboxMap {
return mMapView.getAccessToken();
}
//
// Projection
//
/**
* Converts a point in this view's coordinate system to a map coordinate.
*
* @param point A point in this view's coordinate system.
* @return The converted map coordinate.
*/
@UiThread
@NonNull
public LatLng fromScreenLocation(@NonNull PointF point) {
return mMapView.fromScreenLocation(point);
}
/**
* Converts a map coordinate to a point in this view's coordinate system.
*
* @param location A map coordinate.
* @return The converted point in this view's coordinate system.
*/
@UiThread
@NonNull
public PointF toScreenLocation(@NonNull LatLng location) {
return mMapView.toScreenLocation(location);
}
/**
* <p>
* Returns the distance spanned by one pixel at the specified latitude and current zoom level.
* </p>
* The distance between pixels decreases as the latitude approaches the poles.
* This relationship parallels the relationship between longitudinal coordinates at different latitudes.
*
* @param latitude The latitude for which to return the value.
* @return The distance measured in meters.
*/
@UiThread
public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) {
return mMapView.getMetersPerPixelAtLatitude(latitude);
}
//
// Annotations
//

View File

@@ -10,8 +10,8 @@ import android.view.Surface;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.layers.CustomLayer;
@@ -403,7 +403,7 @@ final class NativeMapView {
nativeRemoveAnnotations(mNativeMapViewPtr, ids);
}
public long[] getAnnotationsInBounds(BoundingBox bbox) {
public long[] getAnnotationsInBounds(LatLngBounds bbox) {
return nativeGetAnnotationsInBounds(mNativeMapViewPtr, bbox);
}
@@ -633,7 +633,7 @@ final class NativeMapView {
private native void nativeRemoveAnnotations(long nativeMapViewPtr, long[] id);
private native long[] nativeGetAnnotationsInBounds(long mNativeMapViewPtr, BoundingBox bbox);
private native long[] nativeGetAnnotationsInBounds(long mNativeMapViewPtr, LatLngBounds bbox);
private native void nativeAddAnnotationIcon(long nativeMapViewPtr, String symbol,
int width, int height, float scale, byte[] pixels);

View File

@@ -0,0 +1,72 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
/**
* A projection is used to translate between on screen location and geographic coordinates on
* the surface of the Earth (LatLng). Screen location is in screen pixels (not display pixels)
* with respect to the top left corner of the map (and not necessarily of the whole screen).
*/
public class Projection {
private MapView mMapView;
Projection(@NonNull MapView mapView) {
this.mMapView = mapView;
}
/**
* Returns the geographic location that corresponds to a screen location.
* The screen location is specified in screen pixels (not display pixels) relative to the
* top left of the map (not the top left of the whole screen).
*
* @param point A Point on the screen in screen pixels.
* @return The LatLng corresponding to the point on the screen, or null if the ray through
* the given screen point does not intersect the ground plane.
*/
public LatLng fromScreenLocation(PointF point) {
return mMapView.fromScreenLocation(point);
}
/**
* Gets a projection of the viewing frustum for converting between screen coordinates and
* geo-latitude/longitude coordinates.
*
* @return The projection of the viewing frustum in its current state.
*/
public VisibleRegion getVisibleRegion() {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
int viewportWidth = mMapView.getWidth();
int viewportHeight = mMapView.getHeight();
LatLng topLeft = fromScreenLocation(new PointF(0, 0));
LatLng topRight = fromScreenLocation(new PointF(viewportWidth, 0));
LatLng bottomRight = fromScreenLocation(new PointF(viewportWidth, viewportHeight));
LatLng bottomLeft = fromScreenLocation(new PointF(0, viewportHeight));
builder.include(topLeft)
.include(topRight)
.include(bottomRight)
.include(bottomLeft);
return new VisibleRegion(topLeft,topRight,bottomLeft,bottomRight,builder.build());
}
/**
* Returns a screen location that corresponds to a geographical coordinate (LatLng).
* The screen location is in screen pixels (not display pixels) relative to the top left
* of the map (not of the whole screen).
*
* @param location A LatLng on the map to convert to a screen location.
* @return A Point representing the screen location in screen pixels.
*/
public PointF toScreenLocation(LatLng location) {
return mMapView.toScreenLocation(location);
}
}

View File

@@ -10,17 +10,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests on VisibleCoordinateBoundsActivity
* Tests on LatLngBoundsActivity
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class VisibleCoordinateBoundsActivityTest extends BaseTest {
@Rule
public ActivityTestRule<VisibleCoordinateBoundsActivity> mActivityRule = new ActivityTestRule<>(
VisibleCoordinateBoundsActivity.class);
public ActivityTestRule<LatLngBoundsActivity> mActivityRule = new ActivityTestRule<>(
LatLngBoundsActivity.class);
private VisibleCoordinateBoundsActivity mActivity = null;
private LatLngBoundsActivity mActivity = null;
@Before
public void setActivity() {

View File

@@ -27,7 +27,7 @@
android:name=".MapboxMapActivity"
android:label="@string/action_mapboxmap" />
<activity
android:name=".VisibleCoordinateBoundsActivity"
android:name=".LatLngBoundsActivity"
android:label="@string/activity_visible_coordinate_bounds" />
<activity
android:name=".InfoWindowAdapterActivity"

View File

@@ -5,9 +5,11 @@ import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -18,12 +20,13 @@ import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
public class LatLngBoundsActivity extends AppCompatActivity {
private MapView mMapView;
private static final LatLng LOS_ANGELES = new LatLng(34.053940, -118.242622);
private static final LatLng NEW_YORK = new LatLng(40.712730, -74.005953);
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -68,8 +71,11 @@ public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
// And padding
int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
// Animate camera
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
// Move camera to the bounds with padding
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
// Call mapboxMap.getProjection().getVisibleRegion().latLngBounds to retrieve the bounds
Log.v(MapboxConstants.TAG, mapboxMap.getProjection().getVisibleRegion().latLngBounds.toString());
}
});

View File

@@ -38,7 +38,6 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
@@ -403,7 +402,7 @@ public class MainActivity extends AppCompatActivity {
return true;
case R.id.action_visible_bounds:
startActivity(new Intent(getApplicationContext(), VisibleCoordinateBoundsActivity.class));
startActivity(new Intent(getApplicationContext(), LatLngBoundsActivity.class));
return true;
case R.id.action_user_tracking_mode:

View File

@@ -83,7 +83,7 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapboxM
@Override
public void onMapLongClick(@NonNull LatLng point) {
PointF pixel = mMapboxMap.toScreenLocation(point);
PointF pixel = mMapboxMap.getProjection().toScreenLocation(point);
String title = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " + LAT_LON_FORMATTER.format(point.getLongitude());
String snippet = "X = " + (int) pixel.x + ", Y = " + (int) pixel.y;

View File

@@ -1,7 +1,5 @@
package com.mapbox.mapboxsdk.geometry;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import org.junit.Before;
@@ -58,8 +56,8 @@ public class LatLngBoundsTest {
@Test
public void testCoordinateSpan() {
CoordinateSpan coordinateSpan = mLatLngBounds.getSpan();
assertEquals("CoordinateSpan should be the same", new CoordinateSpan(2, 2), coordinateSpan);
LatLngSpan latLngSpan = mLatLngBounds.getSpan();
assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan);
}
@Test

View File

@@ -0,0 +1,50 @@
package com.mapbox.mapboxsdk.geometry;
import com.mapbox.mapboxsdk.geometry.LatLngSpan;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class LatLngSpanTest {
private static final double DELTA = 1e-15;
@Test
public void testSanity() {
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
assertNotNull("latLngSpan should not be null", latLngSpan);
}
@Test
public void testLatitudeConstructor() {
double latitude = 1.23;
LatLngSpan latLngSpan = new LatLngSpan(latitude, 0.0);
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
}
@Test
public void testLongitudeConstructor() {
double longitude = 1.23;
LatLngSpan latLngSpan = new LatLngSpan(0.0, longitude);
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
}
@Test
public void testLatitudeMethod() {
double latitude = 1.23;
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
latLngSpan.setLatitudeSpan(latitude);
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
}
@Test
public void testLongitudeMethod() {
double longitude = 1.23;
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
latLngSpan.setLongitudeSpan(longitude);
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
}
}

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.maps;
package com.mapbox.mapboxsdk.geometry;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;

View File

@@ -0,0 +1,71 @@
package com.mapbox.mapboxsdk.geometry;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class VisibleRegionTest {
private static final LatLng FAR_LEFT = new LatLng(52, -12);
private static final LatLng NEAR_LEFT = new LatLng(34, -12);
private static final LatLng FAR_RIGHT = new LatLng(52, 26);
private static final LatLng NEAR_RIGHT = new LatLng(34, 26);
private static final LatLngBounds BOUNDS = new LatLngBounds.Builder().include(FAR_LEFT).include(FAR_RIGHT).include(NEAR_LEFT).include(NEAR_RIGHT).build();
@Test
public void testSanity() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertNotNull("region should not be null", region);
}
@Test
public void testFarLeftConstructor() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("LatLng should match", region.farLeft, FAR_LEFT);
}
@Test
public void testNearLeftConstructor() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("LatLng should match", region.nearLeft, NEAR_LEFT);
}
@Test
public void testFarRightConstructor() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("LatLng should match", region.farRight, FAR_RIGHT);
}
@Test
public void testNearRightConstructor() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("LatLng should match", region.nearRight, NEAR_RIGHT);
}
@Test
public void testLatLngBoundsConstructor() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("LatLngBounds should match", region.latLngBounds, BOUNDS);
}
@Test
public void testEquals() {
VisibleRegion regionLeft = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
VisibleRegion regionRight = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("VisibleRegions should match", regionLeft, regionRight);
}
@Test
public void testToString() {
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
assertEquals("string should match",
"[farLeft [LatLng [longitude=-12.0, latitude=52.0, altitude=0.0]], " +
"farRight [LatLng [longitude=26.0, latitude=52.0, altitude=0.0]], " +
"nearLeft [LatLng [longitude=-12.0, latitude=34.0, altitude=0.0]], " +
"nearRight [LatLng [longitude=26.0, latitude=34.0, altitude=0.0]], " +
"latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]"
, region.toString());
}
}

View File

@@ -1,170 +0,0 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class BoundingBoxTest {
private BoundingBox mBoundingBox;
@Before
public void setup() {
mBoundingBox = new BoundingBox(20.0, 10.0, 0.0, 0.0);
}
@Test
public void testSanity() {
BoundingBox boundingBox = new BoundingBox(0.0, 0.0, 0.0, 0.0);
assertNotNull("boundingBox should not be null", boundingBox);
}
@Test
public void testEqualityConstructors() {
BoundingBox cornerBoundingBox = new BoundingBox(new LatLng(20.0, 10.0), new LatLng(0.0, 0.0));
BoundingBox cloneBoundingBox = new BoundingBox(mBoundingBox);
assertEquals("boundingBoxes should match", mBoundingBox, cornerBoundingBox);
assertEquals("boundingBoxes should match", mBoundingBox, cloneBoundingBox);
}
@Test
public void testValidBox() {
assertTrue(mBoundingBox.isValid());
}
@Test
public void testInvalidLatitudeSpanBox() {
mBoundingBox = new BoundingBox(0.0, 10.0, 10.0, 0.0);
assertFalse(mBoundingBox.isValid());
}
@Test
public void testInvalidLongitudeSpanBox() {
mBoundingBox = new BoundingBox(10.0, 0.0, 0.0, 20.0);
assertFalse(mBoundingBox.isValid());
}
@Test
public void testCenterCoordinate() {
LatLng center = new LatLng(10.0, 5.0);
assertEquals("boundingBox center should match", center, mBoundingBox.getCenter());
}
@Test
public void testUnionSameBox() {
assertEquals(mBoundingBox, mBoundingBox.union(mBoundingBox));
}
@Test
public void testUnionInnerBox() {
BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0);
assertEquals(mBoundingBox.union(innerBox), mBoundingBox);
}
@Test
public void testUnionOverlapBox() {
BoundingBox resultBox = new BoundingBox(22.0, 12.0, 0.0, 0.0);
BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0);
assertEquals(resultBox, mBoundingBox.union(overlapBox));
}
@Test
public void testUnionOuterBox() {
BoundingBox resultBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
assertEquals(resultBox, mBoundingBox.union(outerBox));
}
@Test
public void testIntersectSameBox() {
assertEquals(mBoundingBox, mBoundingBox.intersect(mBoundingBox));
}
@Test
public void testIntersectInnerBox() {
BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0);
assertEquals(innerBox, mBoundingBox.intersect(innerBox));
}
@Test
public void testIntersectOuterBox() {
BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
assertEquals(mBoundingBox, mBoundingBox.intersect(outerBox));
}
@Test
public void testIntersectOverlapBox() {
BoundingBox resultBox = new BoundingBox(20.0, 10.0, 1.0, 1.0);
BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0);
assertEquals(resultBox, mBoundingBox.intersect(overlapBox));
}
@Test
public void testIntersectNoneBox() {
BoundingBox outsideBox = new BoundingBox(100.0, 100.0, 50.0, 50.0);
assertNull(mBoundingBox.intersect(outsideBox));
}
@Test
public void testContainsCoordinate() {
LatLng coordinate = new LatLng(1.0, 1.0);
assertTrue(mBoundingBox.contains(coordinate));
}
@Test
public void testContainsCoordinateOnBoundary() {
LatLng coordinate = new LatLng(20.0, 9.0);
assertFalse(mBoundingBox.contains(coordinate));
}
@Test
public void testContainsNoCoordinate() {
LatLng coordinate = new LatLng(100.0, 100.0);
assertFalse(mBoundingBox.contains(coordinate));
}
@Test
public void testSpan() {
CoordinateSpan span = new CoordinateSpan(20.0, 10.0);
assertTrue(mBoundingBox.getSpan().equals(span));
}
@Test
public void testLatitudeSpan() {
double height = 20.0;
assertTrue(mBoundingBox.getLatitudeSpan() == height);
}
@Test
public void testLongitudeSpan() {
double width = 10.0;
assertTrue(mBoundingBox.getLongitudeSpan() == width);
}
@Test
public void testEmptySpanEmptyNotEmptyBox() {
assertFalse(mBoundingBox.isEmpty());
}
@Test
public void testEmptySpanEmptyLatitude() {
mBoundingBox = new BoundingBox(1.0, 2.0, 0.0, 2.0);
assertTrue(mBoundingBox.isEmpty());
}
@Test
public void testEmptySpanEmptyLongitude() {
mBoundingBox = new BoundingBox(0.0, 3.0, 0.0, 1.0);
assertTrue(mBoundingBox.isEmpty());
}
}

View File

@@ -1,50 +0,0 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class CoordinateSpanTest {
private static final double DELTA = 1e-15;
@Test
public void testSanity() {
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
assertNotNull("coordinateSpan should not be null", coordinateSpan);
}
@Test
public void testLatitudeConstructor() {
double latitude = 1.23;
CoordinateSpan coordinateSpan = new CoordinateSpan(latitude, 0.0);
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
}
@Test
public void testLongitudeConstructor() {
double longitude = 1.23;
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, longitude);
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
}
@Test
public void testLatitudeMethod() {
double latitude = 1.23;
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
coordinateSpan.setLatitudeSpan(latitude);
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
}
@Test
public void testLongitudeMethod() {
double longitude = 1.23;
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
coordinateSpan.setLongitudeSpan(longitude);
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
}
}

View File

@@ -47,7 +47,7 @@ public class MapboxMapTest {
}
//
// Test UiSettings
// UiSettings
//
@Test
@@ -55,6 +55,16 @@ public class MapboxMapTest {
assertNotNull("UiSettings should not be null", mMapboxMap.getUiSettings());
}
//
// Projection
//
@Test
public void testProjection(){
assertNotNull("Projection should not be null",mMapboxMap.getProjection());
}
//
// InfoWindow

View File

@@ -0,0 +1,26 @@
package com.mapbox.mapboxsdk.maps;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
public class ProjectionTest {
@InjectMocks
MapView mMapView = mock(MapView.class);
@Before
public void beforeTest() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testSanity() {
Projection projection = new Projection(mMapView);
assertNotNull("projection should not be null", projection);
}
}

View File

@@ -47,18 +47,12 @@ jmethodID latLngConstructorId = nullptr;
jfieldID latLngLatitudeId = nullptr;
jfieldID latLngLongitudeId = nullptr;
jclass latLngZoomClass = nullptr;
jmethodID latLngZoomConstructorId = nullptr;
jfieldID latLngZoomLatitudeId = nullptr;
jfieldID latLngZoomLongitudeId = nullptr;
jfieldID latLngZoomZoomId = nullptr;
jclass bboxClass = nullptr;
jmethodID bboxConstructorId = nullptr;
jfieldID bboxLatNorthId = nullptr;
jfieldID bboxLatSouthId = nullptr;
jfieldID bboxLonEastId = nullptr;
jfieldID bboxLonWestId = nullptr;
jclass latLngBoundsClass = nullptr;
jmethodID latLngBoundsConstructorId = nullptr;
jfieldID latLngBoundsLatNorthId = nullptr;
jfieldID latLngBoundsLatSouthId = nullptr;
jfieldID latLngBoundsLonEastId = nullptr;
jfieldID latLngBoundsLonWestId = nullptr;
jclass iconClass = nullptr;
jfieldID iconIdId = nullptr;
@@ -1148,35 +1142,35 @@ void JNICALL nativeRemoveAnnotations(JNIEnv *env, jobject obj, jlong nativeMapVi
nativeMapView->getMap().removeAnnotations(ids);
}
jlongArray JNICALL nativeGetAnnotationsInBounds(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject bbox) {
jlongArray JNICALL nativeGetAnnotationsInBounds(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject latLngBounds) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetAnnotationsInBounds");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
if (env->ExceptionCheck() || (bbox == nullptr)) {
if (env->ExceptionCheck() || (latLngBounds == nullptr)) {
env->ExceptionDescribe();
return nullptr;
}
jdouble swLat = env->GetDoubleField(bbox, bboxLatSouthId);
jdouble swLat = env->GetDoubleField(latLngBounds, latLngBoundsLatSouthId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble swLon = env->GetDoubleField(bbox, bboxLonWestId);
jdouble swLon = env->GetDoubleField(latLngBounds, latLngBoundsLonWestId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble neLat = env->GetDoubleField(bbox, bboxLatNorthId);
jdouble neLat = env->GetDoubleField(latLngBounds, latLngBoundsLatNorthId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble neLon = env->GetDoubleField(bbox, bboxLonEastId);
jdouble neLon = env->GetDoubleField(latLngBounds, latLngBoundsLonEastId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
@@ -1625,38 +1619,38 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
bboxClass = env->FindClass("com/mapbox/mapboxsdk/geometry/BoundingBox");
if (bboxClass == nullptr) {
latLngBoundsClass = env->FindClass("com/mapbox/mapboxsdk/geometry/LatLngBounds");
if (latLngBoundsClass == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxConstructorId = env->GetMethodID(bboxClass, "<init>", "(DDDD)V");
if (bboxConstructorId == nullptr) {
latLngBoundsConstructorId = env->GetMethodID(latLngBoundsClass, "<init>", "(DDDD)V");
if (latLngBoundsConstructorId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLatNorthId = env->GetFieldID(bboxClass, "mLatNorth", "D");
if (bboxLatNorthId == nullptr) {
latLngBoundsLatNorthId = env->GetFieldID(latLngBoundsClass, "mLatNorth", "D");
if (latLngBoundsLatNorthId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLatSouthId = env->GetFieldID(bboxClass, "mLatSouth", "D");
if (bboxLatSouthId == nullptr) {
latLngBoundsLatSouthId = env->GetFieldID(latLngBoundsClass, "mLatSouth", "D");
if (latLngBoundsLatSouthId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLonEastId = env->GetFieldID(bboxClass, "mLonEast", "D");
if (bboxLonEastId == nullptr) {
latLngBoundsLonEastId = env->GetFieldID(latLngBoundsClass, "mLonEast", "D");
if (latLngBoundsLonEastId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLonWestId = env->GetFieldID(bboxClass, "mLonWest", "D");
if (bboxLonWestId == nullptr) {
latLngBoundsLonWestId = env->GetFieldID(latLngBoundsClass, "mLonWest", "D");
if (latLngBoundsLonWestId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
@@ -2052,7 +2046,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
reinterpret_cast<void *>(&nativeAddPolygons)},
{"nativeRemoveAnnotation", "(JJ)V", reinterpret_cast<void *>(&nativeRemoveAnnotation)},
{"nativeRemoveAnnotations", "(J[J)V", reinterpret_cast<void *>(&nativeRemoveAnnotations)},
{"nativeGetAnnotationsInBounds", "(JLcom/mapbox/mapboxsdk/geometry/BoundingBox;)[J",
{"nativeGetAnnotationsInBounds", "(JLcom/mapbox/mapboxsdk/geometry/LatLngBounds;)[J",
reinterpret_cast<void *>(&nativeGetAnnotationsInBounds)},
{"nativeAddAnnotationIcon", "(JLjava/lang/String;IIF[B)V", reinterpret_cast<void *>(&nativeAddAnnotationIcon)},
{"nativeSetVisibleCoordinateBounds", "(J[Lcom/mapbox/mapboxsdk/geometry/LatLng;Landroid/graphics/RectF;DJ)V",
@@ -2101,12 +2095,11 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
bboxClass = reinterpret_cast<jclass>(env->NewGlobalRef(bboxClass));
if (bboxClass == nullptr) {
latLngBoundsClass = reinterpret_cast<jclass>(env->NewGlobalRef(latLngBoundsClass));
if (latLngBoundsClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
return JNI_ERR;
}
@@ -2114,8 +2107,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (iconClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
return JNI_ERR;
}
@@ -2123,8 +2115,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (markerClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
return JNI_ERR;
}
@@ -2133,8 +2124,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (polylineClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
return JNI_ERR;
@@ -2144,8 +2134,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (polygonClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2156,8 +2145,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (runtimeExceptionClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2170,8 +2158,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (nullPointerExceptionClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2184,8 +2171,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (arrayListClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2199,8 +2185,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (projectedMetersClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2215,8 +2200,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (pointFClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(polylineClass);
@@ -2233,8 +2217,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(polylineClass);
env->DeleteGlobalRef(polygonClass);
env->DeleteGlobalRef(runtimeExceptionClass);
@@ -2249,8 +2232,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (httpContextClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2267,8 +2249,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (httpRequestClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2307,20 +2288,13 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
latLngLongitudeId = nullptr;
latLngLatitudeId = nullptr;
env->DeleteGlobalRef(latLngZoomClass);
latLngZoomClass = nullptr;
latLngZoomConstructorId = nullptr;
latLngZoomLongitudeId = nullptr;
latLngZoomLatitudeId = nullptr;
latLngZoomZoomId = nullptr;
env->DeleteGlobalRef(bboxClass);
bboxClass = nullptr;
bboxConstructorId = nullptr;
bboxLatNorthId = nullptr;
bboxLatSouthId = nullptr;
bboxLonEastId = nullptr;
bboxLonWestId = nullptr;
env->DeleteGlobalRef(latLngBoundsClass);
latLngBoundsClass = nullptr;
latLngBoundsConstructorId = nullptr;
latLngBoundsLatNorthId = nullptr;
latLngBoundsLatSouthId = nullptr;
latLngBoundsLonEastId = nullptr;
latLngBoundsLonWestId = nullptr;
env->DeleteGlobalRef(iconClass);
iconClass = nullptr;