diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
8 files changed, 256 insertions, 333 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index dcd40326aa..3346bd6d64 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -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); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java index 96aec573cc..cf5961a313 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java @@ -17,63 +17,67 @@ 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 setStyleUrl(String url); + void onLowMemory(); - @NonNull - String getStyleUrl(); + void destroy(); - void setStyleJson(String newStyleJson); + boolean isDestroyed(); - @NonNull - String getStyleJson(); + // + // Camera API + // - void setLatLngBounds(LatLngBounds latLngBounds); + void jumpTo(@NonNull LatLng center, double zoom, double pitch, double bearing); - void cancelTransitions(); + void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration, + boolean easingInterpolator); - void setGestureInProgress(boolean inProgress); + void flyTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration); + + void moveBy(double deltaX, double deltaY, long duration); + + @NonNull + CameraPosition getCameraPosition(); - void moveBy(double dx, double dy); + CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds bounds, int[] padding, double bearing, double pitch); - void moveBy(double dx, double dy, long duration); + CameraPosition getCameraForGeometry(@NonNull Geometry geometry, int[] padding, double bearing, double pitch); - void setLatLng(@NonNull LatLng latLng); + void resetPosition(); void setLatLng(@NonNull LatLng latLng, long duration); LatLng getLatLng(); - CameraPosition getCameraForLatLngBounds(LatLngBounds bounds, int[] padding, double bearing, double tilt); + void setLatLngBounds(@NonNull LatLngBounds latLngBounds); - CameraPosition getCameraForGeometry(Geometry geometry, int[] padding, double bearing, double tilt); + void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, + double direction, long duration); - void resetPosition(); + void setPitch(double pitch, long duration); double getPitch(); - void setPitch(double pitch); - - void setPitch(double pitch, long duration); - void setZoom(double zoom, @NonNull PointF focalPoint, long duration); double getZoom(); - void resetZoom(); - void setMinZoom(double zoom); double getMinZoom(); @@ -82,75 +86,104 @@ interface NativeMap { double getMaxZoom(); - void rotateBy(double sx, double sy, double ex, double ey); - - void rotateBy(double sx, double sy, double ex, double ey, - long duration); - - void setContentPadding(float[] padding); - - float[] getContentPadding(); + void resetZoom(); - void setBearing(double degrees); + void rotateBy(double sx, double sy, double ex, double ey, long duration); void setBearing(double degrees, long duration); - void setBearing(double degrees, double cx, double cy); - void setBearing(double degrees, double fx, double fy, long duration); double getBearing(); void resetNorth(); - long addMarker(Marker marker); + void cancelTransitions(); + + // + // Style API + // + + void setStyleUrl(String url); @NonNull - long[] addMarkers(@NonNull List<Marker> markers); + String getStyleUrl(); - long addPolyline(Polyline polyline); + void setStyleJson(String newStyleJson); @NonNull - long[] addPolylines(@NonNull List<Polyline> polylines); + String getStyleJson(); - long addPolygon(Polygon polygon); + boolean isFullyLoaded(); + + 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); @NonNull - long[] addPolygons(@NonNull List<Polygon> polygons); + List<Layer> getLayers(); - void updateMarker(@NonNull Marker marker); + Layer getLayer(String layerId); - void updatePolygon(@NonNull Polygon polygon); + boolean removeLayer(@NonNull String layerId); - void updatePolyline(@NonNull Polyline polyline); + boolean removeLayer(@NonNull Layer layer); - void removeAnnotation(long id); + boolean removeLayerAt(@IntRange(from = 0) int index); - void removeAnnotations(long[] ids); + void addSource(@NonNull Source source); @NonNull - long[] queryPointAnnotations(RectF rect); + List<Source> getSources(); + + Source getSource(@NonNull String sourceId); + + boolean removeSource(@NonNull String sourceId); + + boolean removeSource(@NonNull Source source); + + void setTransitionOptions(@NonNull TransitionOptions transitionOptions); @NonNull - long[] queryShapeAnnotations(RectF rectF); + TransitionOptions getTransitionOptions(); - void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels); + void addImages(Image[] images); - void removeAnnotationIcon(String symbol); + Bitmap getImage(String name); - void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration); + void removeImage(String name); - void onLowMemory(); + Light getLight(); - void setDebug(boolean debug); + // + // Content padding API + // - void cycleDebugOptions(); + void setContentPadding(float[] padding); - boolean getDebug(); + float[] getContentPadding(); - boolean isFullyLoaded(); + // + // Query API + // - void setReachability(boolean status); + @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); + + // + // Projection API + // double getMetersPerPixelAtLatitude(double lat); @@ -163,85 +196,69 @@ interface NativeMap { 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); + // + // Utils API + // - @NonNull - CameraPosition getCameraPosition(); + void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener); - void setPrefetchesTiles(boolean enable); + void setDebug(boolean debug); - boolean getPrefetchesTiles(); + boolean getDebug(); - long getTransitionDuration(); + void cycleDebugOptions(); - void setTransitionDuration(long duration); + void setReachability(boolean status); - long getTransitionDelay(); + void setApiBaseUrl(String baseUrl); - void setTransitionDelay(long delay); + void setPrefetchTiles(boolean enable); - @NonNull - List<Layer> getLayers(); + boolean getPrefetchTiles(); - Layer getLayer(String layerId); + void setGestureInProgress(boolean inProgress); - void addLayer(@NonNull Layer layer); + float getPixelRatio(); - void addLayerBelow(@NonNull Layer layer, @NonNull String below); + // + // Deprecated Annotations API + // - void addLayerAbove(@NonNull Layer layer, @NonNull String above); + long addMarker(Marker marker); - void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index); + @NonNull + long[] addMarkers(@NonNull List<Marker> markers); - boolean removeLayer(@NonNull String layerId); + long addPolyline(Polyline polyline); - boolean removeLayer(@NonNull Layer layer); + @NonNull + long[] addPolylines(@NonNull List<Polyline> polylines); - boolean removeLayerAt(@IntRange(from = 0) int index); + long addPolygon(Polygon polygon); @NonNull - List<Source> getSources(); - - Source getSource(@NonNull String sourceId); + long[] addPolygons(@NonNull List<Polygon> polygons); - void addSource(@NonNull Source source); + void updateMarker(@NonNull Marker marker); - boolean removeSource(@NonNull String sourceId); + void updatePolygon(@NonNull Polygon polygon); - boolean removeSource(@NonNull Source source); + void updatePolyline(@NonNull Polyline polyline); - void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf); + void removeAnnotation(long id); - void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap); + void removeAnnotations(long[] ids); - void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap, boolean sdf); + double getTopOffsetPixelsForAnnotationSymbol(String symbolName); - void removeImage(String name); + void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels); - Bitmap getImage(String name); + void removeAnnotationIcon(String symbol); @NonNull - List<Feature> queryRenderedFeatures(@NonNull PointF coordinates, - @Nullable String[] layerIds, - @Nullable Expression filter); + long[] queryPointAnnotations(RectF rectF); @NonNull - List<Feature> queryRenderedFeatures(@NonNull RectF coordinates, - @Nullable String[] layerIds, - @Nullable Expression filter); - - void setApiBaseUrl(String baseUrl); - - Light getLight(); - - float getPixelRatio(); + long[] queryShapeAnnotations(RectF rectF); - void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener); -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 6b8d4b2bf5..3fe98efa34 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -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 { @@ -243,14 +238,6 @@ final class NativeMapView implements NativeMap { } @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")) { return; @@ -259,14 +246,6 @@ final class NativeMapView implements NativeMap { } @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")) { return; @@ -331,11 +310,6 @@ final class NativeMapView implements NativeMap { } @Override - public void setPitch(double pitch) { - setPitch(pitch, 0); - } - - @Override public void setPitch(double pitch, long duration) { if (checkState("setPitch")) { return; @@ -400,14 +374,6 @@ final class NativeMapView implements NativeMap { } @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) { if (checkState("rotateBy")) { @@ -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, @@ -444,14 +410,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")) { return; @@ -460,14 +418,6 @@ final class NativeMapView implements NativeMap { } @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")) { return; @@ -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(); - } - - @Override - public void setTransitionDuration(long duration) { - nativeSetTransitionDuration(duration); - } - - @Override - public long getTransitionDelay() { - return nativeGetTransitionDelay(); + public void setTransitionOptions(@NonNull TransitionOptions transitionOptions) { + nativeSetTransitionOptions(transitionOptions); } + @NonNull @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 @@ -1343,6 +1264,13 @@ final class NativeMapView implements NativeMap { private native CameraPosition nativeGetCameraPosition(); @Keep + private native void nativeSetTransitionOptions(TransitionOptions transitionOptions); + + @NonNull + @Keep + private native TransitionOptions nativeGetTransitionOptions(); + + @Keep private native long nativeGetTransitionDuration(); @Keep @@ -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(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java index 49c39e94b3..14fc69f456 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java @@ -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. */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index be98f7e51d..9356b112ba 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -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) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java index dbd6d77761..acbff20e96 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java @@ -11,7 +11,9 @@ import android.support.annotation.Nullable; */ public class TransitionOptions { + @Keep private long duration; + @Keep private long delay; /** diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt index 77fb272bd2..4c67049b39 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt @@ -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 diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt index 56223dadef..83769914ef 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt @@ -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 |