diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java')
-rwxr-xr-x | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 68 |
1 files changed, 35 insertions, 33 deletions
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 e8eb7e8718..0e77910c3d 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 @@ -11,6 +11,8 @@ 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; import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.Marker; @@ -22,15 +24,13 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.geometry.ProjectedMeters; import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; 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.Filter; import com.mapbox.mapboxsdk.style.layers.Layer; 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 com.mapbox.services.commons.geojson.Feature; -import com.mapbox.services.commons.geojson.Geometry; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -229,18 +229,28 @@ final class NativeMapView { return nativeGetLatLng().wrap(); } - public CameraPosition getCameraForLatLngBounds(LatLngBounds latLngBounds) { + public CameraPosition getCameraForLatLngBounds(LatLngBounds latLngBounds, int[] padding) { if (isDestroyedOn("getCameraForLatLngBounds")) { return null; } - return nativeGetCameraForLatLngBounds(latLngBounds); + return nativeGetCameraForLatLngBounds( + latLngBounds, + padding[1] / pixelRatio, + padding[0] / pixelRatio, + padding[3] / pixelRatio, + padding[2] / pixelRatio); } - public CameraPosition getCameraForGeometry(Geometry geometry, double bearing) { + public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) { if (isDestroyedOn("getCameraForGeometry")) { return null; } - return nativeGetCameraForGeometry(geometry, bearing); + return nativeGetCameraForGeometry( + geometry, bearing, + padding[1] / pixelRatio, + padding[0] / pixelRatio, + padding[3] / pixelRatio, + padding[2] / pixelRatio); } public void resetPosition() { @@ -733,7 +743,7 @@ final class NativeMapView { if (isDestroyedOn("addSource")) { return; } - nativeAddSource(source.getNativePtr()); + nativeAddSource(source, source.getNativePtr()); } @Nullable @@ -741,14 +751,19 @@ final class NativeMapView { if (isDestroyedOn("removeSource")) { return null; } - return nativeRemoveSourceById(sourceId); + Source source = getSource(sourceId); + if (source != null) { + return removeSource(source); + } + return null; } + @Nullable public Source removeSource(@NonNull Source source) { if (isDestroyedOn("removeSource")) { return null; } - nativeRemoveSource(source.getNativePtr()); + nativeRemoveSource(source, source.getNativePtr()); return source; } @@ -757,20 +772,8 @@ final class NativeMapView { return; } - // Check/correct config - if (image.getConfig() != Bitmap.Config.ARGB_8888) { - image = image.copy(Bitmap.Config.ARGB_8888, false); - } - - // Get pixels - ByteBuffer buffer = ByteBuffer.allocate(image.getByteCount()); - image.copyPixelsToBuffer(buffer); - // Determine pixel ratio - float density = image.getDensity() == Bitmap.DENSITY_NONE ? Bitmap.DENSITY_NONE : image.getDensity(); - float pixelRatio = density / DisplayMetrics.DENSITY_DEFAULT; - - nativeAddImage(name, image.getWidth(), image.getHeight(), pixelRatio, buffer.array()); + nativeAddImage(name, image, image.getDensity() / DisplayMetrics.DENSITY_DEFAULT); } public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) { @@ -800,7 +803,7 @@ final class NativeMapView { @NonNull public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates, @Nullable String[] layerIds, - @Nullable Filter.Statement filter) { + @Nullable Expression filter) { if (isDestroyedOn("queryRenderedFeatures")) { return new ArrayList<>(); } @@ -812,7 +815,7 @@ final class NativeMapView { @NonNull public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates, @Nullable String[] layerIds, - @Nullable Filter.Statement filter) { + @Nullable Expression filter) { if (isDestroyedOn("queryRenderedFeatures")) { return new ArrayList<>(); } @@ -907,9 +910,11 @@ final class NativeMapView { private native LatLng nativeGetLatLng(); - private native CameraPosition nativeGetCameraForLatLngBounds(LatLngBounds latLngBounds); + private native CameraPosition nativeGetCameraForLatLngBounds( + LatLngBounds latLngBounds, double top, double left, double bottom, double right); - private native CameraPosition nativeGetCameraForGeometry(Geometry geometry, double bearing); + private native CameraPosition nativeGetCameraForGeometry( + Geometry geometry, double bearing, double top, double left, double bottom, double right); private native void nativeResetPosition(); @@ -1027,14 +1032,11 @@ final class NativeMapView { private native Source nativeGetSource(String sourceId); - private native void nativeAddSource(long nativeSourcePtr) throws CannotAddSourceException; - - private native Source nativeRemoveSourceById(String sourceId); + private native void nativeAddSource(Source source, long sourcePtr) throws CannotAddSourceException; - private native void nativeRemoveSource(long sourcePtr); + private native void nativeRemoveSource(Source source, long sourcePtr); - private native void nativeAddImage(String name, int width, int height, float pixelRatio, - byte[] array); + private native void nativeAddImage(String name, Bitmap bitmap, float pixelRatio); private native void nativeAddImages(Image[] images); |