[android] - optimise interface definition
This commit is contained in:
@@ -246,7 +246,7 @@ public final class MapboxMap {
|
||||
* @param enable true to enable
|
||||
*/
|
||||
public void setPrefetchesTiles(boolean enable) {
|
||||
nativeMapView.setPrefetchesTiles(enable);
|
||||
nativeMapView.setPrefetchTiles(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +256,7 @@ public final class MapboxMap {
|
||||
* @see MapboxMap#setPrefetchesTiles(boolean)
|
||||
*/
|
||||
public boolean getPrefetchesTiles() {
|
||||
return nativeMapView.getPrefetchesTiles();
|
||||
return nativeMapView.getPrefetchTiles();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -597,7 +597,7 @@ public final class MapboxMap {
|
||||
* @param y Amount of pixels to scroll to in y direction
|
||||
*/
|
||||
public void scrollBy(float x, float y) {
|
||||
nativeMapView.moveBy(x, y);
|
||||
nativeMapView.moveBy(x, y, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,19 +17,93 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
interface NativeMap {
|
||||
void destroy();
|
||||
|
||||
//
|
||||
// Lifecycle API
|
||||
//
|
||||
|
||||
void update();
|
||||
|
||||
void resizeView(int width, int height);
|
||||
|
||||
void onLowMemory();
|
||||
|
||||
void destroy();
|
||||
|
||||
boolean isDestroyed();
|
||||
|
||||
//
|
||||
// Camera API
|
||||
//
|
||||
|
||||
void jumpTo(@NonNull LatLng center, double zoom, double pitch, double bearing);
|
||||
|
||||
void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration,
|
||||
boolean easingInterpolator);
|
||||
|
||||
void flyTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration);
|
||||
|
||||
void moveBy(double deltaX, double deltaY, long duration);
|
||||
|
||||
@NonNull
|
||||
CameraPosition getCameraPosition();
|
||||
|
||||
CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds bounds, int[] padding, double bearing, double pitch);
|
||||
|
||||
CameraPosition getCameraForGeometry(@NonNull Geometry geometry, int[] padding, double bearing, double pitch);
|
||||
|
||||
void resetPosition();
|
||||
|
||||
void setLatLng(@NonNull LatLng latLng, long duration);
|
||||
|
||||
LatLng getLatLng();
|
||||
|
||||
void setLatLngBounds(@NonNull LatLngBounds latLngBounds);
|
||||
|
||||
void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding,
|
||||
double direction, long duration);
|
||||
|
||||
void setPitch(double pitch, long duration);
|
||||
|
||||
double getPitch();
|
||||
|
||||
void setZoom(double zoom, @NonNull PointF focalPoint, long duration);
|
||||
|
||||
double getZoom();
|
||||
|
||||
void setMinZoom(double zoom);
|
||||
|
||||
double getMinZoom();
|
||||
|
||||
void setMaxZoom(double zoom);
|
||||
|
||||
double getMaxZoom();
|
||||
|
||||
void resetZoom();
|
||||
|
||||
void rotateBy(double sx, double sy, double ex, double ey, long duration);
|
||||
|
||||
void setBearing(double degrees, long duration);
|
||||
|
||||
void setBearing(double degrees, double fx, double fy, long duration);
|
||||
|
||||
double getBearing();
|
||||
|
||||
void resetNorth();
|
||||
|
||||
void cancelTransitions();
|
||||
|
||||
//
|
||||
// Style API
|
||||
//
|
||||
|
||||
void setStyleUrl(String url);
|
||||
|
||||
@NonNull
|
||||
@@ -40,68 +114,115 @@ interface NativeMap {
|
||||
@NonNull
|
||||
String getStyleJson();
|
||||
|
||||
void setLatLngBounds(LatLngBounds latLngBounds);
|
||||
boolean isFullyLoaded();
|
||||
|
||||
void cancelTransitions();
|
||||
void addLayer(@NonNull Layer layer);
|
||||
|
||||
void setGestureInProgress(boolean inProgress);
|
||||
void addLayerBelow(@NonNull Layer layer, @NonNull String below);
|
||||
|
||||
void moveBy(double dx, double dy);
|
||||
void addLayerAbove(@NonNull Layer layer, @NonNull String above);
|
||||
|
||||
void moveBy(double dx, double dy, long duration);
|
||||
void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index);
|
||||
|
||||
void setLatLng(@NonNull LatLng latLng);
|
||||
@NonNull
|
||||
List<Layer> getLayers();
|
||||
|
||||
void setLatLng(@NonNull LatLng latLng, long duration);
|
||||
Layer getLayer(String layerId);
|
||||
|
||||
LatLng getLatLng();
|
||||
boolean removeLayer(@NonNull String layerId);
|
||||
|
||||
CameraPosition getCameraForLatLngBounds(LatLngBounds bounds, int[] padding, double bearing, double tilt);
|
||||
boolean removeLayer(@NonNull Layer layer);
|
||||
|
||||
CameraPosition getCameraForGeometry(Geometry geometry, int[] padding, double bearing, double tilt);
|
||||
boolean removeLayerAt(@IntRange(from = 0) int index);
|
||||
|
||||
void resetPosition();
|
||||
void addSource(@NonNull Source source);
|
||||
|
||||
double getPitch();
|
||||
@NonNull
|
||||
List<Source> getSources();
|
||||
|
||||
void setPitch(double pitch);
|
||||
Source getSource(@NonNull String sourceId);
|
||||
|
||||
void setPitch(double pitch, long duration);
|
||||
boolean removeSource(@NonNull String sourceId);
|
||||
|
||||
void setZoom(double zoom, @NonNull PointF focalPoint, long duration);
|
||||
boolean removeSource(@NonNull Source source);
|
||||
|
||||
double getZoom();
|
||||
void setTransitionOptions(@NonNull TransitionOptions transitionOptions);
|
||||
|
||||
void resetZoom();
|
||||
@NonNull
|
||||
TransitionOptions getTransitionOptions();
|
||||
|
||||
void setMinZoom(double zoom);
|
||||
void addImages(Image[] images);
|
||||
|
||||
double getMinZoom();
|
||||
Bitmap getImage(String name);
|
||||
|
||||
void setMaxZoom(double zoom);
|
||||
void removeImage(String name);
|
||||
|
||||
double getMaxZoom();
|
||||
Light getLight();
|
||||
|
||||
void rotateBy(double sx, double sy, double ex, double ey);
|
||||
|
||||
void rotateBy(double sx, double sy, double ex, double ey,
|
||||
long duration);
|
||||
//
|
||||
// Content padding API
|
||||
//
|
||||
|
||||
void setContentPadding(float[] padding);
|
||||
|
||||
float[] getContentPadding();
|
||||
|
||||
void setBearing(double degrees);
|
||||
//
|
||||
// Query API
|
||||
//
|
||||
|
||||
void setBearing(double degrees, long duration);
|
||||
@NonNull
|
||||
List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Expression filter);
|
||||
|
||||
void setBearing(double degrees, double cx, double cy);
|
||||
@NonNull
|
||||
List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Expression filter);
|
||||
|
||||
void setBearing(double degrees, double fx, double fy, long duration);
|
||||
//
|
||||
// Projection API
|
||||
//
|
||||
|
||||
double getBearing();
|
||||
double getMetersPerPixelAtLatitude(double lat);
|
||||
|
||||
void resetNorth();
|
||||
ProjectedMeters projectedMetersForLatLng(@NonNull LatLng latLng);
|
||||
|
||||
LatLng latLngForProjectedMeters(@NonNull ProjectedMeters projectedMeters);
|
||||
|
||||
@NonNull
|
||||
PointF pixelForLatLng(@NonNull LatLng latLng);
|
||||
|
||||
LatLng latLngForPixel(@NonNull PointF pixel);
|
||||
|
||||
//
|
||||
// Utils API
|
||||
//
|
||||
|
||||
void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener);
|
||||
|
||||
void setDebug(boolean debug);
|
||||
|
||||
boolean getDebug();
|
||||
|
||||
void cycleDebugOptions();
|
||||
|
||||
void setReachability(boolean status);
|
||||
|
||||
void setApiBaseUrl(String baseUrl);
|
||||
|
||||
void setPrefetchTiles(boolean enable);
|
||||
|
||||
boolean getPrefetchTiles();
|
||||
|
||||
void setGestureInProgress(boolean inProgress);
|
||||
|
||||
float getPixelRatio();
|
||||
|
||||
//
|
||||
// Deprecated Annotations API
|
||||
//
|
||||
|
||||
long addMarker(Marker marker);
|
||||
|
||||
@@ -128,120 +249,16 @@ interface NativeMap {
|
||||
|
||||
void removeAnnotations(long[] ids);
|
||||
|
||||
@NonNull
|
||||
long[] queryPointAnnotations(RectF rect);
|
||||
|
||||
@NonNull
|
||||
long[] queryShapeAnnotations(RectF rectF);
|
||||
double getTopOffsetPixelsForAnnotationSymbol(String symbolName);
|
||||
|
||||
void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels);
|
||||
|
||||
void removeAnnotationIcon(String symbol);
|
||||
|
||||
void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration);
|
||||
|
||||
void onLowMemory();
|
||||
|
||||
void setDebug(boolean debug);
|
||||
|
||||
void cycleDebugOptions();
|
||||
|
||||
boolean getDebug();
|
||||
|
||||
boolean isFullyLoaded();
|
||||
|
||||
void setReachability(boolean status);
|
||||
|
||||
double getMetersPerPixelAtLatitude(double lat);
|
||||
|
||||
ProjectedMeters projectedMetersForLatLng(@NonNull LatLng latLng);
|
||||
|
||||
LatLng latLngForProjectedMeters(@NonNull ProjectedMeters projectedMeters);
|
||||
@NonNull
|
||||
long[] queryPointAnnotations(RectF rectF);
|
||||
|
||||
@NonNull
|
||||
PointF pixelForLatLng(@NonNull LatLng latLng);
|
||||
long[] queryShapeAnnotations(RectF rectF);
|
||||
|
||||
LatLng latLngForPixel(@NonNull PointF pixel);
|
||||
|
||||
double getTopOffsetPixelsForAnnotationSymbol(String symbolName);
|
||||
|
||||
void jumpTo(double angle, @NonNull LatLng center, double pitch, double zoom);
|
||||
|
||||
void easeTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom,
|
||||
boolean easingInterpolator);
|
||||
|
||||
void flyTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom);
|
||||
|
||||
@NonNull
|
||||
CameraPosition getCameraPosition();
|
||||
|
||||
void setPrefetchesTiles(boolean enable);
|
||||
|
||||
boolean getPrefetchesTiles();
|
||||
|
||||
long getTransitionDuration();
|
||||
|
||||
void setTransitionDuration(long duration);
|
||||
|
||||
long getTransitionDelay();
|
||||
|
||||
void setTransitionDelay(long delay);
|
||||
|
||||
@NonNull
|
||||
List<Layer> getLayers();
|
||||
|
||||
Layer getLayer(String layerId);
|
||||
|
||||
void addLayer(@NonNull Layer layer);
|
||||
|
||||
void addLayerBelow(@NonNull Layer layer, @NonNull String below);
|
||||
|
||||
void addLayerAbove(@NonNull Layer layer, @NonNull String above);
|
||||
|
||||
void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index);
|
||||
|
||||
boolean removeLayer(@NonNull String layerId);
|
||||
|
||||
boolean removeLayer(@NonNull Layer layer);
|
||||
|
||||
boolean removeLayerAt(@IntRange(from = 0) int index);
|
||||
|
||||
@NonNull
|
||||
List<Source> getSources();
|
||||
|
||||
Source getSource(@NonNull String sourceId);
|
||||
|
||||
void addSource(@NonNull Source source);
|
||||
|
||||
boolean removeSource(@NonNull String sourceId);
|
||||
|
||||
boolean removeSource(@NonNull Source source);
|
||||
|
||||
void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf);
|
||||
|
||||
void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap);
|
||||
|
||||
void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap, boolean sdf);
|
||||
|
||||
void removeImage(String name);
|
||||
|
||||
Bitmap getImage(String name);
|
||||
|
||||
@NonNull
|
||||
List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Expression filter);
|
||||
|
||||
@NonNull
|
||||
List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Expression filter);
|
||||
|
||||
void setApiBaseUrl(String baseUrl);
|
||||
|
||||
Light getLight();
|
||||
|
||||
float getPixelRatio();
|
||||
|
||||
void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener);
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,12 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.Geometry;
|
||||
import com.mapbox.mapboxsdk.LibraryLoader;
|
||||
@@ -32,17 +29,15 @@ import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
// Class that wraps the native methods for convenience
|
||||
final class NativeMapView implements NativeMap {
|
||||
@@ -242,14 +237,6 @@ final class NativeMapView implements NativeMap {
|
||||
nativeSetGestureInProgress(inProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveBy(double dx, double dy) {
|
||||
if (checkState("moveBy")) {
|
||||
return;
|
||||
}
|
||||
moveBy(dx, dy, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveBy(double dx, double dy, long duration) {
|
||||
if (checkState("moveBy")) {
|
||||
@@ -258,14 +245,6 @@ final class NativeMapView implements NativeMap {
|
||||
nativeMoveBy(dx / pixelRatio, dy / pixelRatio, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLatLng(@NonNull LatLng latLng) {
|
||||
if (checkState("setLatLng")) {
|
||||
return;
|
||||
}
|
||||
setLatLng(latLng, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLatLng(@NonNull LatLng latLng, long duration) {
|
||||
if (checkState("setLatLng")) {
|
||||
@@ -330,11 +309,6 @@ final class NativeMapView implements NativeMap {
|
||||
return nativeGetPitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPitch(double pitch) {
|
||||
setPitch(pitch, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPitch(double pitch, long duration) {
|
||||
if (checkState("setPitch")) {
|
||||
@@ -399,14 +373,6 @@ final class NativeMapView implements NativeMap {
|
||||
return nativeGetMaxZoom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateBy(double sx, double sy, double ex, double ey) {
|
||||
if (checkState("rotateBy")) {
|
||||
return;
|
||||
}
|
||||
rotateBy(sx, sy, ex, ey, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateBy(double sx, double sy, double ex, double ey,
|
||||
long duration) {
|
||||
@@ -435,7 +401,7 @@ final class NativeMapView implements NativeMap {
|
||||
return new float[] {0, 0, 0, 0};
|
||||
}
|
||||
float[] topLeftBottomRight = nativeGetContentPadding();
|
||||
return new float[]{
|
||||
return new float[] {
|
||||
topLeftBottomRight[1] * pixelRatio,
|
||||
topLeftBottomRight[0] * pixelRatio,
|
||||
topLeftBottomRight[3] * pixelRatio,
|
||||
@@ -443,14 +409,6 @@ final class NativeMapView implements NativeMap {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearing(double degrees) {
|
||||
if (checkState("setBearing")) {
|
||||
return;
|
||||
}
|
||||
setBearing(degrees, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearing(double degrees, long duration) {
|
||||
if (checkState("setBearing")) {
|
||||
@@ -459,14 +417,6 @@ final class NativeMapView implements NativeMap {
|
||||
nativeSetBearing(degrees, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearing(double degrees, double cx, double cy) {
|
||||
if (checkState("setBearing")) {
|
||||
return;
|
||||
}
|
||||
setBearing(degrees, cx, cy, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBearing(double degrees, double fx, double fy, long duration) {
|
||||
if (checkState("setBearing")) {
|
||||
@@ -731,7 +681,7 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpTo(double angle, @NonNull LatLng center, double pitch, double zoom) {
|
||||
public void jumpTo(@NonNull LatLng center, double zoom, double pitch, double angle) {
|
||||
if (checkState("jumpTo")) {
|
||||
return;
|
||||
}
|
||||
@@ -739,7 +689,7 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void easeTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom,
|
||||
public void easeTo(@NonNull LatLng center, double zoom, double angle, double pitch, long duration,
|
||||
boolean easingInterpolator) {
|
||||
if (checkState("easeTo")) {
|
||||
return;
|
||||
@@ -749,7 +699,7 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flyTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom) {
|
||||
public void flyTo(@NonNull LatLng center, double zoom, double angle, double pitch, long duration) {
|
||||
if (checkState("flyTo")) {
|
||||
return;
|
||||
}
|
||||
@@ -766,41 +716,32 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrefetchesTiles(boolean enable) {
|
||||
if (checkState("setPrefetchesTiles")) {
|
||||
public void setPrefetchTiles(boolean enable) {
|
||||
if (checkState("setPrefetchTiles")) {
|
||||
return;
|
||||
}
|
||||
nativeSetPrefetchesTiles(enable);
|
||||
nativeSetPrefetchTiles(enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPrefetchesTiles() {
|
||||
if (checkState("getPrefetchesTiles")) {
|
||||
public boolean getPrefetchTiles() {
|
||||
if (checkState("getPrefetchTiles")) {
|
||||
return false;
|
||||
}
|
||||
return nativeGetPrefetchesTiles();
|
||||
return nativeGetPrefetchTiles();
|
||||
}
|
||||
|
||||
// Runtime style Api
|
||||
|
||||
@Override
|
||||
public long getTransitionDuration() {
|
||||
return nativeGetTransitionDuration();
|
||||
public void setTransitionOptions(@NonNull TransitionOptions transitionOptions) {
|
||||
nativeSetTransitionOptions(transitionOptions);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public void setTransitionDuration(long duration) {
|
||||
nativeSetTransitionDuration(duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTransitionDelay() {
|
||||
return nativeGetTransitionDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransitionDelay(long delay) {
|
||||
nativeSetTransitionDelay(delay);
|
||||
public TransitionOptions getTransitionOptions() {
|
||||
return nativeGetTransitionOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -928,31 +869,11 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
|
||||
if (checkState("addImage")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine pixel ratio, cast to float to avoid rounding, see mapbox-gl-native/issues/11809
|
||||
float pixelRatio = (float) image.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
|
||||
nativeAddImage(name, image, pixelRatio, sdf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) {
|
||||
public void addImages(@NonNull Image[] images) {
|
||||
if (checkState("addImages")) {
|
||||
return;
|
||||
}
|
||||
this.addImages(bitmapHashMap, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
|
||||
if (checkState("addImages")) {
|
||||
return;
|
||||
}
|
||||
//noinspection unchecked
|
||||
new BitmapImageConversionTask(this, sdf).execute(bitmapHashMap);
|
||||
nativeAddImages(images);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1342,6 +1263,13 @@ final class NativeMapView implements NativeMap {
|
||||
@Keep
|
||||
private native CameraPosition nativeGetCameraPosition();
|
||||
|
||||
@Keep
|
||||
private native void nativeSetTransitionOptions(TransitionOptions transitionOptions);
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
private native TransitionOptions nativeGetTransitionOptions();
|
||||
|
||||
@Keep
|
||||
private native long nativeGetTransitionDuration();
|
||||
|
||||
@@ -1431,20 +1359,20 @@ final class NativeMapView implements NativeMap {
|
||||
private native Light nativeGetLight();
|
||||
|
||||
@Keep
|
||||
private native void nativeSetPrefetchesTiles(boolean enable);
|
||||
private native void nativeSetPrefetchTiles(boolean enable);
|
||||
|
||||
@Keep
|
||||
private native boolean nativeGetPrefetchesTiles();
|
||||
private native boolean nativeGetPrefetchTiles();
|
||||
|
||||
int getWidth() {
|
||||
if (checkState("")) {
|
||||
if (checkState("") || viewCallback == null) {
|
||||
return 0;
|
||||
}
|
||||
return viewCallback.getWidth();
|
||||
}
|
||||
|
||||
int getHeight() {
|
||||
if (checkState("")) {
|
||||
if (checkState("") || viewCallback == null) {
|
||||
return 0;
|
||||
}
|
||||
return viewCallback.getHeight();
|
||||
@@ -1487,62 +1415,11 @@ final class NativeMapView implements NativeMap {
|
||||
});
|
||||
}
|
||||
|
||||
boolean isDestroyed() {
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
//
|
||||
// Image conversion
|
||||
//
|
||||
|
||||
private static class BitmapImageConversionTask extends AsyncTask<HashMap<String, Bitmap>, Void, List<Image>> {
|
||||
|
||||
private NativeMapView nativeMapView;
|
||||
private boolean sdf;
|
||||
|
||||
BitmapImageConversionTask(NativeMapView nativeMapView, boolean sdf) {
|
||||
this.nativeMapView = nativeMapView;
|
||||
this.sdf = sdf;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected List<Image> doInBackground(HashMap<String, Bitmap>... params) {
|
||||
HashMap<String, Bitmap> bitmapHashMap = params[0];
|
||||
|
||||
List<Image> images = new ArrayList<>();
|
||||
ByteBuffer buffer;
|
||||
String name;
|
||||
Bitmap bitmap;
|
||||
|
||||
for (Map.Entry<String, Bitmap> stringBitmapEntry : bitmapHashMap.entrySet()) {
|
||||
name = stringBitmapEntry.getKey();
|
||||
bitmap = stringBitmapEntry.getValue();
|
||||
|
||||
if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
|
||||
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
|
||||
}
|
||||
|
||||
buffer = ByteBuffer.allocate(bitmap.getByteCount());
|
||||
bitmap.copyPixelsToBuffer(buffer);
|
||||
|
||||
float pixelRatio = (float) bitmap.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
|
||||
|
||||
images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight(), sdf));
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(@NonNull List<Image> images) {
|
||||
super.onPostExecute(images);
|
||||
if (nativeMapView != null && !nativeMapView.checkState("nativeAddImages")) {
|
||||
nativeMapView.nativeAddImages(images.toArray(new Image[images.size()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ViewCallback {
|
||||
int getWidth();
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringDef;
|
||||
import android.util.DisplayMetrics;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
@@ -13,6 +15,8 @@ import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -26,6 +30,7 @@ import java.util.Map;
|
||||
* has been loaded by underlying map.
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Style {
|
||||
|
||||
private final NativeMap nativeMap;
|
||||
@@ -38,7 +43,7 @@ public class Style {
|
||||
/**
|
||||
* Private constructor to build a style object.
|
||||
*
|
||||
* @param builder the builder used for creating this style
|
||||
* @param builder the builder used for creating this style
|
||||
* @param nativeMap the map object used to load this style
|
||||
*/
|
||||
private Style(@NonNull Builder builder, @NonNull NativeMap nativeMap) {
|
||||
@@ -296,21 +301,28 @@ public class Style {
|
||||
/**
|
||||
* Adds an image to be used in the map's style
|
||||
*
|
||||
* @param name the name of the image
|
||||
* @param image the pre-multiplied Bitmap
|
||||
* @param sdf the flag indicating image is an SDF or template image
|
||||
* @param name the name of the image
|
||||
* @param bitmap the pre-multiplied Bitmap
|
||||
* @param sdf the flag indicating image is an SDF or template image
|
||||
*/
|
||||
public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
|
||||
public void addImage(@NonNull final String name, @NonNull final Bitmap bitmap, boolean sdf) {
|
||||
validateState("addImage");
|
||||
nativeMap.addImage(name, image, sdf);
|
||||
new BitmapImageConversionTask(nativeMap, sdf).execute(new Builder.ImageWrapper(name, bitmap, sdf));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an images to be used in the map's style.
|
||||
*/
|
||||
public void addImages(@NonNull HashMap<String, Bitmap> images) {
|
||||
addImages(images, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an images to be used in the map's style.
|
||||
*/
|
||||
public void addImages(@NonNull HashMap<String, Bitmap> images, boolean sdf) {
|
||||
validateState("addImages");
|
||||
nativeMap.addImages(images);
|
||||
new BitmapImageConversionTask(nativeMap, sdf).execute(Builder.ImageWrapper.convertToImageArray(images, sdf));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,8 +361,7 @@ public class Style {
|
||||
*/
|
||||
public void setTransition(@NonNull TransitionOptions transitionOptions) {
|
||||
validateState("setTransition");
|
||||
nativeMap.setTransitionDuration(transitionOptions.getDuration());
|
||||
nativeMap.setTransitionDelay(transitionOptions.getDelay());
|
||||
nativeMap.setTransitionOptions(transitionOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,7 +375,7 @@ public class Style {
|
||||
@NonNull
|
||||
public TransitionOptions getTransition() {
|
||||
validateState("getTransition");
|
||||
return new TransitionOptions(nativeMap.getTransitionDuration(), nativeMap.getTransitionDelay());
|
||||
return nativeMap.getTransitionOptions();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -675,7 +686,7 @@ public class Style {
|
||||
return new Style(this, nativeMap);
|
||||
}
|
||||
|
||||
class ImageWrapper {
|
||||
static class ImageWrapper {
|
||||
Bitmap bitmap;
|
||||
String id;
|
||||
boolean sdf;
|
||||
@@ -685,6 +696,16 @@ public class Style {
|
||||
this.bitmap = bitmap;
|
||||
this.sdf = sdf;
|
||||
}
|
||||
|
||||
static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
|
||||
ImageWrapper[] images = new ImageWrapper[bitmapHashMap.size()];
|
||||
List<String> keyList = new ArrayList<>(bitmapHashMap.keySet());
|
||||
for (int i = 0; i < bitmapHashMap.size(); i++) {
|
||||
String id = keyList.get(i);
|
||||
images[i] = new ImageWrapper(id, bitmapHashMap.get(id), sdf);
|
||||
}
|
||||
return images;
|
||||
}
|
||||
}
|
||||
|
||||
class LayerWrapper {
|
||||
@@ -723,6 +744,53 @@ public class Style {
|
||||
}
|
||||
}
|
||||
|
||||
private static class BitmapImageConversionTask extends AsyncTask<Builder.ImageWrapper, Void, List<Image>> {
|
||||
|
||||
private WeakReference<NativeMap> nativeMap;
|
||||
private boolean sdf;
|
||||
|
||||
BitmapImageConversionTask(NativeMap nativeMap, boolean sdf) {
|
||||
this.nativeMap = new WeakReference<>(nativeMap);
|
||||
this.sdf = sdf;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected List<Image> doInBackground(Builder.ImageWrapper... params) {
|
||||
List<Image> images = new ArrayList<>();
|
||||
ByteBuffer buffer;
|
||||
String name;
|
||||
Bitmap bitmap;
|
||||
|
||||
for (Builder.ImageWrapper param : params) {
|
||||
name = param.id;
|
||||
bitmap = param.bitmap;
|
||||
|
||||
if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
|
||||
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
|
||||
}
|
||||
|
||||
buffer = ByteBuffer.allocate(bitmap.getByteCount());
|
||||
bitmap.copyPixelsToBuffer(buffer);
|
||||
|
||||
float pixelRatio = (float) bitmap.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
|
||||
|
||||
images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight(), sdf));
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(@NonNull List<Image> images) {
|
||||
super.onPostExecute(images);
|
||||
NativeMap nativeMap = this.nativeMap.get();
|
||||
if (nativeMap != null && !nativeMap.isDestroyed()) {
|
||||
nativeMap.addImages(images.toArray(new Image[images.size()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to be invoked when a style has finished loading.
|
||||
*/
|
||||
|
||||
@@ -99,7 +99,7 @@ final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
if (isValidCameraPosition(cameraPosition)) {
|
||||
cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
|
||||
nativeMap.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
|
||||
nativeMap.jumpTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.tilt, cameraPosition.bearing);
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
invalidateCameraPosition();
|
||||
handler.post(new Runnable() {
|
||||
@@ -125,8 +125,8 @@ final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
cameraCancelableCallback = callback;
|
||||
}
|
||||
mapView.addOnCameraDidChangeListener(this);
|
||||
nativeMap.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
|
||||
cameraPosition.zoom, easingInterpolator);
|
||||
nativeMap.easeTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing, cameraPosition.tilt,
|
||||
durationMs, easingInterpolator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,8 @@ final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
cameraCancelableCallback = callback;
|
||||
}
|
||||
mapView.addOnCameraDidChangeListener(this);
|
||||
nativeMap.flyTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
|
||||
cameraPosition.zoom);
|
||||
nativeMap.flyTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing,
|
||||
cameraPosition.tilt, durationMs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,11 +231,11 @@ final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
}
|
||||
|
||||
void setBearing(double bearing) {
|
||||
nativeMap.setBearing(bearing);
|
||||
nativeMap.setBearing(bearing, 0);
|
||||
}
|
||||
|
||||
void setBearing(double bearing, float focalX, float focalY) {
|
||||
nativeMap.setBearing(bearing, focalX, focalY);
|
||||
nativeMap.setBearing(bearing, focalX, focalY, 0);
|
||||
}
|
||||
|
||||
void setBearing(double bearing, float focalX, float focalY, long duration) {
|
||||
@@ -272,7 +272,7 @@ final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
}
|
||||
|
||||
void setCenterCoordinate(LatLng centerCoordinate) {
|
||||
nativeMap.setLatLng(centerCoordinate);
|
||||
nativeMap.setLatLng(centerCoordinate, 0);
|
||||
}
|
||||
|
||||
void setGestureInProgress(boolean gestureInProgress) {
|
||||
|
||||
@@ -11,7 +11,9 @@ import android.support.annotation.Nullable;
|
||||
*/
|
||||
public class TransitionOptions {
|
||||
|
||||
@Keep
|
||||
private long duration;
|
||||
@Keep
|
||||
private long delay;
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,8 +29,7 @@ class MapboxMapTest {
|
||||
nativeMapView = mockk()
|
||||
mapboxMap = MapboxMap(nativeMapView, Transform(mapView, nativeMapView, cameraChangeDispatcher), null, null, null, cameraChangeDispatcher)
|
||||
every { nativeMapView.styleUrl = any() } answers {}
|
||||
every { nativeMapView.transitionDuration = any() } answers {}
|
||||
every { nativeMapView.transitionDelay = any() } answers {}
|
||||
every { nativeMapView.transitionOptions = any() } answers {}
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT
|
||||
every { nativeMapView.cancelTransitions() } answers {}
|
||||
@@ -38,7 +37,7 @@ class MapboxMapTest {
|
||||
every { nativeMapView.minZoom = any() } answers {}
|
||||
every { nativeMapView.maxZoom = any() } answers {}
|
||||
every { nativeMapView.setOnFpsChangedListener(any()) } answers {}
|
||||
every { nativeMapView.prefetchesTiles = any() } answers {}
|
||||
every { nativeMapView.prefetchTiles = any() } answers {}
|
||||
every { nativeMapView.setLatLngBounds(any()) } answers {}
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
@@ -49,8 +48,7 @@ class MapboxMapTest {
|
||||
fun testTransitionOptions() {
|
||||
val expected = TransitionOptions(100, 200)
|
||||
mapboxMap.style?.transition = expected
|
||||
verify { nativeMapView.transitionDelay = 200 }
|
||||
verify { nativeMapView.transitionDuration = 100 }
|
||||
verify { nativeMapView.transitionOptions = expected }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +58,7 @@ class MapboxMapTest {
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(expected), callback)
|
||||
verify { nativeMapView.jumpTo(-1.0, target, -1.0, -1.0) }
|
||||
verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@@ -86,7 +84,7 @@ class MapboxMapTest {
|
||||
@Test
|
||||
fun testTilePrefetch() {
|
||||
mapboxMap.prefetchesTiles = true
|
||||
verify { nativeMapView.prefetchesTiles = true }
|
||||
verify { nativeMapView.prefetchTiles = true }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,9 +33,8 @@ class StyleTest {
|
||||
every { nativeMapView.addLayerAbove(any(), any()) } answers {}
|
||||
every { nativeMapView.addLayerAt(any(), any()) } answers {}
|
||||
every { nativeMapView.addSource(any()) } answers {}
|
||||
every { nativeMapView.addImage(any(), any(), any()) } answers {}
|
||||
every { nativeMapView.transitionDuration = any() } answers {}
|
||||
every { nativeMapView.transitionDelay = any() } answers {}
|
||||
every { nativeMapView.addImages(any()) } answers {}
|
||||
every { nativeMapView.transitionOptions = any() } answers {}
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
}
|
||||
@@ -104,24 +103,7 @@ class StyleTest {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder().withTransition(transitionOptions)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.transitionDuration = 100 }
|
||||
verify(exactly = 1) { nativeMapView.transitionDelay = 200 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImage() {
|
||||
val image = mockk<Bitmap>()
|
||||
val builder = Style.Builder().withImage("id", image)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.addImage("id", image, false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithImageSdf() {
|
||||
val image = mockk<Bitmap>()
|
||||
val builder = Style.Builder().withImage("id", image, true)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.addImage("id", image, true) }
|
||||
verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,28 +168,7 @@ class StyleTest {
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.transitionDuration = 100 }
|
||||
verify(exactly = 1) { nativeMapView.transitionDelay = 200 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromImage() {
|
||||
val bitmap = mockk<Bitmap>()
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withImage("id", bitmap)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addImage("id", bitmap, false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromImageSdf() {
|
||||
val bitmap = mockk<Bitmap>()
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withImage("id", bitmap, true)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addImage("id", bitmap, true) }
|
||||
verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -44,7 +44,7 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testBearing() {
|
||||
val expected = BEARING_TEST
|
||||
nativeMapView.bearing = expected
|
||||
nativeMapView.setBearing(expected, 0)
|
||||
val actual = nativeMapView.bearing
|
||||
assertEquals("Bearing should match", expected, actual, DELTA)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testLatLng() {
|
||||
val expected = LATLNG_TEST
|
||||
nativeMapView.latLng = expected
|
||||
nativeMapView.setLatLng(expected, 0)
|
||||
val actual = nativeMapView.latLng
|
||||
assertEquals("Latitude should match", expected.latitude, actual.latitude, DELTA)
|
||||
assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA)
|
||||
@@ -81,7 +81,7 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testPitch() {
|
||||
val expected = PITCH_TEST
|
||||
nativeMapView.pitch = expected
|
||||
nativeMapView.setPitch(expected, 0)
|
||||
val actual = nativeMapView.pitch
|
||||
assertEquals("Pitch should match", expected, actual, DELTA)
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class NativeMapViewTest {
|
||||
.tilt(PITCH_TEST)
|
||||
.zoom(ZOOM_TEST)
|
||||
.build()
|
||||
nativeMapView.jumpTo(BEARING_TEST, LATLNG_TEST, PITCH_TEST, ZOOM_TEST)
|
||||
nativeMapView.jumpTo(LATLNG_TEST, ZOOM_TEST, PITCH_TEST, BEARING_TEST)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, DELTA)
|
||||
assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, DELTA)
|
||||
@@ -133,7 +133,7 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testLatLngForPixel() {
|
||||
val expected = LATLNG_TEST
|
||||
nativeMapView.latLng = LATLNG_TEST
|
||||
nativeMapView.setLatLng(LATLNG_TEST,0)
|
||||
val actual = nativeMapView.latLngForPixel(
|
||||
PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat())
|
||||
)
|
||||
@@ -145,7 +145,7 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testPixelForLatLng() {
|
||||
val expected = PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat())
|
||||
nativeMapView.latLng = LATLNG_TEST
|
||||
nativeMapView.setLatLng(LATLNG_TEST, 0)
|
||||
val actual = nativeMapView.pixelForLatLng(LATLNG_TEST)
|
||||
assertEquals("X should match", expected.x.toDouble(), actual.x.toDouble(), DELTA_BIG)
|
||||
assertEquals("Y should match", expected.y.toDouble(), actual.y.toDouble(), DELTA_BIG)
|
||||
@@ -155,8 +155,8 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testPrefetchTilesTrue() {
|
||||
val expected = true
|
||||
nativeMapView.prefetchesTiles = true
|
||||
val actual = nativeMapView.prefetchesTiles
|
||||
nativeMapView.prefetchTiles = true
|
||||
val actual = nativeMapView.prefetchTiles
|
||||
assertEquals("Flag should match", expected, actual)
|
||||
}
|
||||
|
||||
@@ -164,8 +164,8 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testPrefetchTilesFalse() {
|
||||
val expected = false
|
||||
nativeMapView.prefetchesTiles = false
|
||||
val actual = nativeMapView.prefetchesTiles
|
||||
nativeMapView.prefetchTiles = false
|
||||
val actual = nativeMapView.prefetchTiles
|
||||
assertEquals("Flag should match", expected, actual)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ class NativeMapViewTest {
|
||||
@UiThreadTest
|
||||
fun testPrefetchTilesDefault() {
|
||||
val expected = true
|
||||
val actual = nativeMapView.prefetchesTiles
|
||||
val actual = nativeMapView.prefetchTiles
|
||||
assertEquals("Flag should match", expected, actual)
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ class NativeMapViewTest {
|
||||
.target(LatLng(12.0, 14.0))
|
||||
.bearing(20.0)
|
||||
.build()
|
||||
nativeMapView.flyTo(expected.bearing, expected.target, 0, expected.tilt, expected.zoom)
|
||||
nativeMapView.flyTo(expected.target, expected.zoom, expected.bearing, expected.tilt, 0)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA)
|
||||
@@ -251,7 +251,7 @@ class NativeMapViewTest {
|
||||
.target(LatLng(12.0, 14.0))
|
||||
.bearing(20.0)
|
||||
.build()
|
||||
nativeMapView.easeTo(expected.bearing, expected.target, 0, expected.tilt, expected.zoom, false)
|
||||
nativeMapView.easeTo(expected.target, expected.zoom, expected.bearing, expected.tilt, 0, false)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA)
|
||||
@@ -269,7 +269,7 @@ class NativeMapViewTest {
|
||||
.target(LatLng(0.0, 0.0))
|
||||
.bearing(0.0)
|
||||
.build()
|
||||
nativeMapView.jumpTo(1.0, LatLng(1.0, 2.0), 23.0, 12.0)
|
||||
nativeMapView.jumpTo(LatLng(1.0, 2.0), 12.0, 23.0, 1.0)
|
||||
nativeMapView.resetPosition()
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
@@ -310,7 +310,7 @@ class NativeMapViewTest {
|
||||
.target(LatLng(4.21494310024160, -4.218749958739409))
|
||||
.bearing(0.0)
|
||||
.build()
|
||||
nativeMapView.moveBy(12.0, 12.0)
|
||||
nativeMapView.moveBy(12.0, 12.0, 0)
|
||||
val actual = nativeMapView.cameraPosition
|
||||
assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA)
|
||||
assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA)
|
||||
|
||||
@@ -33,6 +33,9 @@ public class ImageTest extends EspressoTest {
|
||||
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
|
||||
mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet);
|
||||
|
||||
// adding an image requires converting the image with an asynctask
|
||||
uiController.loopMainThreadForAtLeast(200);
|
||||
|
||||
Bitmap bitmapGet = mapboxMap.getStyle().getImage(IMAGE_ID);
|
||||
assertTrue(bitmapGet.sameAs(bitmapSet));
|
||||
|
||||
|
||||
@@ -629,13 +629,11 @@ jni::Local<jni::Array<jlong>> NativeMapView::addPolygons(JNIEnv& env, const jni:
|
||||
return result;
|
||||
}
|
||||
|
||||
//TODO: Move to Polyline class and make native peer
|
||||
void NativeMapView::updatePolyline(JNIEnv& env, jlong polylineId, const jni::Object<Polyline>& polyline) {
|
||||
mbgl::LineAnnotation annotation = Polyline::toAnnotation(env, polyline);
|
||||
map->updateAnnotation(polylineId, annotation);
|
||||
}
|
||||
|
||||
//TODO: Move to Polygon class and make native peer
|
||||
void NativeMapView::updatePolygon(JNIEnv& env, jlong polygonId, const jni::Object<Polygon>& polygon) {
|
||||
mbgl::FillAnnotation annotation = Polygon::toAnnotation(env, polygon);
|
||||
map->updateAnnotation(polygonId, annotation);
|
||||
@@ -680,25 +678,18 @@ jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, const
|
||||
return map->getTopOffsetPixelsForAnnotationImage(jni::Make<std::string>(env, symbolName));
|
||||
}
|
||||
|
||||
jlong NativeMapView::getTransitionDuration(JNIEnv&) {
|
||||
jni::Local<jni::Object<TransitionOptions>> NativeMapView::getTransitionOptions(JNIEnv& env) {
|
||||
const auto transitionOptions = map->getStyle().getTransitionOptions();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.duration.value_or(mbgl::Duration::zero())).count();
|
||||
const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.duration.value_or(mbgl::Duration::zero())).count();
|
||||
const auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.delay.value_or(mbgl::Duration::zero())).count();
|
||||
return TransitionOptions::fromTransitionOptions(env, duration, delay);
|
||||
}
|
||||
|
||||
void NativeMapView::setTransitionDuration(JNIEnv&, jlong duration) {
|
||||
auto transitionOptions = map->getStyle().getTransitionOptions();
|
||||
transitionOptions.duration.emplace(mbgl::Milliseconds(duration));
|
||||
map->getStyle().setTransitionOptions(transitionOptions);
|
||||
}
|
||||
|
||||
jlong NativeMapView::getTransitionDelay(JNIEnv&) {
|
||||
const auto transitionOptions = map->getStyle().getTransitionOptions();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(transitionOptions.delay.value_or(mbgl::Duration::zero())).count();
|
||||
}
|
||||
|
||||
void NativeMapView::setTransitionDelay(JNIEnv&, jlong delay) {
|
||||
auto transitionOptions = map->getStyle().getTransitionOptions();
|
||||
transitionOptions.delay.emplace(mbgl::Milliseconds(delay));
|
||||
void NativeMapView::setTransitionOptions(JNIEnv& env, const jni::Object<TransitionOptions>& options) {
|
||||
const mbgl::style::TransitionOptions transitionOptions(
|
||||
Duration(mbgl::Milliseconds(TransitionOptions::getDuration(env, options))),
|
||||
Duration(mbgl::Milliseconds(TransitionOptions::getOffset(env, options)))
|
||||
);
|
||||
map->getStyle().setTransitionOptions(transitionOptions);
|
||||
}
|
||||
|
||||
@@ -1012,11 +1003,11 @@ jni::Local<jni::Object<Bitmap>> NativeMapView::getImage(JNIEnv& env, const jni::
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::setPrefetchesTiles(JNIEnv&, jni::jboolean enable) {
|
||||
void NativeMapView::setPrefetchTiles(JNIEnv&, jni::jboolean enable) {
|
||||
map->setPrefetchZoomDelta(enable ? util::DEFAULT_PREFETCH_ZOOM_DELTA : uint8_t(0));
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::getPrefetchesTiles(JNIEnv&) {
|
||||
jni::jboolean NativeMapView::getPrefetchTiles(JNIEnv&) {
|
||||
return jni::jboolean(map->getPrefetchZoomDelta() > 0);
|
||||
}
|
||||
|
||||
@@ -1093,10 +1084,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::addAnnotationIcon, "nativeAddAnnotationIcon"),
|
||||
METHOD(&NativeMapView::removeAnnotationIcon, "nativeRemoveAnnotationIcon"),
|
||||
METHOD(&NativeMapView::getTopOffsetPixelsForAnnotationSymbol, "nativeGetTopOffsetPixelsForAnnotationSymbol"),
|
||||
METHOD(&NativeMapView::getTransitionDuration, "nativeGetTransitionDuration"),
|
||||
METHOD(&NativeMapView::setTransitionDuration, "nativeSetTransitionDuration"),
|
||||
METHOD(&NativeMapView::getTransitionDelay, "nativeGetTransitionDelay"),
|
||||
METHOD(&NativeMapView::setTransitionDelay, "nativeSetTransitionDelay"),
|
||||
METHOD(&NativeMapView::getTransitionOptions, "nativeGetTransitionOptions"),
|
||||
METHOD(&NativeMapView::setTransitionOptions, "nativeSetTransitionOptions"),
|
||||
METHOD(&NativeMapView::queryPointAnnotations, "nativeQueryPointAnnotations"),
|
||||
METHOD(&NativeMapView::queryShapeAnnotations, "nativeQueryShapeAnnotations"),
|
||||
METHOD(&NativeMapView::queryRenderedFeaturesForPoint, "nativeQueryRenderedFeaturesForPoint"),
|
||||
@@ -1118,8 +1107,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::removeImage, "nativeRemoveImage"),
|
||||
METHOD(&NativeMapView::getImage, "nativeGetImage"),
|
||||
METHOD(&NativeMapView::setLatLngBounds, "nativeSetLatLngBounds"),
|
||||
METHOD(&NativeMapView::setPrefetchesTiles, "nativeSetPrefetchesTiles"),
|
||||
METHOD(&NativeMapView::getPrefetchesTiles, "nativeGetPrefetchesTiles")
|
||||
METHOD(&NativeMapView::setPrefetchTiles, "nativeSetPrefetchTiles"),
|
||||
METHOD(&NativeMapView::getPrefetchTiles, "nativeGetPrefetchTiles")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,13 +187,9 @@ public:
|
||||
|
||||
jni::jdouble getTopOffsetPixelsForAnnotationSymbol(JNIEnv&, const jni::String&);
|
||||
|
||||
jni::jlong getTransitionDuration(JNIEnv&);
|
||||
jni::Local<jni::Object<TransitionOptions>> getTransitionOptions(JNIEnv&);
|
||||
|
||||
void setTransitionDuration(JNIEnv&, jni::jlong);
|
||||
|
||||
jni::jlong getTransitionDelay(JNIEnv&);
|
||||
|
||||
void setTransitionDelay(JNIEnv&, jni::jlong);
|
||||
void setTransitionOptions(JNIEnv&, const jni::Object<TransitionOptions>&);
|
||||
|
||||
jni::Local<jni::Array<jlong>> queryPointAnnotations(JNIEnv&, const jni::Object<RectF>&);
|
||||
|
||||
@@ -239,9 +235,9 @@ public:
|
||||
|
||||
jni::Local<jni::Object<Bitmap>> getImage(JNIEnv&, const jni::String&);
|
||||
|
||||
void setPrefetchesTiles(JNIEnv&, jni::jboolean);
|
||||
void setPrefetchTiles(JNIEnv&, jni::jboolean);
|
||||
|
||||
jni::jboolean getPrefetchesTiles(JNIEnv&);
|
||||
jni::jboolean getPrefetchTiles(JNIEnv&);
|
||||
|
||||
mbgl::Map& getMap();
|
||||
|
||||
|
||||
@@ -9,6 +9,18 @@ jni::Local<jni::Object<TransitionOptions>> TransitionOptions::fromTransitionOpti
|
||||
return javaClass.Call(env, method, duration, delay);
|
||||
}
|
||||
|
||||
long TransitionOptions::getDuration(jni::JNIEnv& env, const jni::Object<TransitionOptions>& transitionOptions) {
|
||||
static auto& javaClass = jni::Class<TransitionOptions>::Singleton(env);
|
||||
static auto field = javaClass.GetField<jlong>(env, "duration");
|
||||
return transitionOptions.Get(env, field);
|
||||
}
|
||||
|
||||
long TransitionOptions::getOffset(jni::JNIEnv& env, const jni::Object<TransitionOptions>& transitionOptions) {
|
||||
static auto& javaClass = jni::Class<TransitionOptions>::Singleton(env);
|
||||
static auto field = javaClass.GetField<jlong>(env, "offset");
|
||||
return transitionOptions.Get(env, field);
|
||||
}
|
||||
|
||||
void TransitionOptions::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<TransitionOptions>::Singleton(env);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ public:
|
||||
|
||||
static jni::Local<jni::Object<TransitionOptions>> fromTransitionOptions(jni::JNIEnv&, jlong duration, jlong offset);
|
||||
|
||||
static long getDuration(jni::JNIEnv&, const jni::Object<TransitionOptions>&);
|
||||
|
||||
static long getOffset(jni::JNIEnv&, const jni::Object<TransitionOptions>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user