[android] addImage / removeImage jni bindings
This commit is contained in:
committed by
Ivo van Dongen
parent
b470a65582
commit
8fbc1bc750
@@ -187,6 +187,27 @@ public class MapboxMap {
|
||||
getMapView().getNativeMapView().removeSource(sourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an image to be used int hte map's style
|
||||
*
|
||||
* @param name the name of the image
|
||||
* @param image the pre-multiplied Bitmap
|
||||
*/
|
||||
@UiThread
|
||||
public void addImage(@NonNull String name, @NonNull Bitmap image) {
|
||||
getMapView().getNativeMapView().addImage(name, image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an image from the map's style
|
||||
*
|
||||
* @param name the name of the image to remove
|
||||
*/
|
||||
@UiThread
|
||||
public void removeImage(String name) {
|
||||
getMapView().getNativeMapView().removeImage(name);
|
||||
}
|
||||
|
||||
//
|
||||
// MinZoom
|
||||
//
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Surface;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
@@ -22,6 +24,7 @@ import com.mapbox.mapboxsdk.style.sources.NoSuchSourceException;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.services.commons.geojson.Feature;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -506,6 +509,27 @@ final class NativeMapView {
|
||||
nativeRemoveSource(nativeMapViewPtr, sourceId);
|
||||
}
|
||||
|
||||
public void addImage(@NonNull String name, @NonNull Bitmap image) {
|
||||
//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(nativeMapViewPtr, name, image.getWidth(), image.getHeight(), pixelRatio, buffer.array());
|
||||
}
|
||||
|
||||
public void removeImage(String name) {
|
||||
nativeRemoveImage(nativeMapViewPtr, name);
|
||||
}
|
||||
|
||||
// Feature querying
|
||||
|
||||
@NonNull
|
||||
@@ -722,6 +746,10 @@ final class NativeMapView {
|
||||
|
||||
private native void nativeRemoveSource(long nativeMapViewPtr, String sourceId) throws NoSuchSourceException;
|
||||
|
||||
private native void nativeAddImage(long nativeMapViewPtr, String name, int width, int height, float pixelRatio, byte[] array);
|
||||
|
||||
private native void nativeRemoveImage(long nativeMapViewPtr, String name);
|
||||
|
||||
private native void nativeUpdatePolygon(long nativeMapViewPtr, long polygonId, Polygon polygon);
|
||||
|
||||
private native void nativeUpdatePolyline(long nativeMapviewPtr, long polylineId, Polyline polyline);
|
||||
|
||||
Reference in New Issue
Block a user