[android] - style image accessor
This commit is contained in:
committed by
Tobrun
parent
e204f6cd79
commit
385e4e6ade
@@ -473,6 +473,10 @@ public final class MapboxMap {
|
||||
nativeMapView.removeImage(name);
|
||||
}
|
||||
|
||||
public Bitmap getImage(@NonNull String name) {
|
||||
return nativeMapView.getImage(name);
|
||||
}
|
||||
|
||||
//
|
||||
// MinZoom
|
||||
//
|
||||
|
||||
@@ -808,6 +808,13 @@ final class NativeMapView {
|
||||
nativeRemoveImage(name);
|
||||
}
|
||||
|
||||
public Bitmap getImage(String name) {
|
||||
if (isDestroyedOn("getImage")) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetImage(name);
|
||||
}
|
||||
|
||||
// Feature querying
|
||||
|
||||
@NonNull
|
||||
@@ -1078,6 +1085,8 @@ final class NativeMapView {
|
||||
|
||||
private native void nativeRemoveImage(String name);
|
||||
|
||||
private native Bitmap nativeGetImage(String name);
|
||||
|
||||
private native void nativeUpdatePolygon(long polygonId, Polygon polygon);
|
||||
|
||||
private native void nativeUpdatePolyline(long polylineId, Polyline polyline);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* CRUD tests around Image
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ImageTest extends BaseActivityTest {
|
||||
|
||||
private static final String IMAGE_ID = "test.image";
|
||||
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return RuntimeStyleTestActivity.class;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGetImage() {
|
||||
validateTestSetup();
|
||||
MapboxMapAction.invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
Drawable drawable = rule.getActivity().getResources().getDrawable(R.drawable.ic_launcher_round);
|
||||
assertTrue(drawable instanceof BitmapDrawable);
|
||||
|
||||
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
|
||||
mapboxMap.addImage(IMAGE_ID, bitmapSet);
|
||||
|
||||
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
|
||||
assertTrue(bitmapGet.sameAs(bitmapSet));
|
||||
|
||||
mapboxMap.removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getImage(IMAGE_ID));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "map/camera_position.hpp"
|
||||
#include "style/light.hpp"
|
||||
#include "bitmap_factory.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -1043,6 +1044,14 @@ void NativeMapView::removeImage(JNIEnv& env, jni::String name) {
|
||||
map->getStyle().removeImage(jni::Make<std::string>(env, name));
|
||||
}
|
||||
|
||||
jni::Object<Bitmap> NativeMapView::getImage(JNIEnv& env, jni::String name) {
|
||||
const mbgl::style::Image *image = map->getStyle().getImage(jni::Make<std::string>(env, name));
|
||||
if (image) {
|
||||
return Bitmap::CreateBitmap(env, image->getImage());
|
||||
} else {
|
||||
return jni::Object<Bitmap>();
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::setPrefetchesTiles(JNIEnv&, jni::jboolean enable) {
|
||||
map->setPrefetchZoomDelta(enable ? util::DEFAULT_PREFETCH_ZOOM_DELTA : uint8_t(0));
|
||||
@@ -1553,6 +1562,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::removeSource, "nativeRemoveSource"),
|
||||
METHOD(&NativeMapView::addImage, "nativeAddImage"),
|
||||
METHOD(&NativeMapView::removeImage, "nativeRemoveImage"),
|
||||
METHOD(&NativeMapView::getImage, "nativeGetImage"),
|
||||
METHOD(&NativeMapView::setLatLngBounds, "nativeSetLatLngBounds"),
|
||||
METHOD(&NativeMapView::setPrefetchesTiles, "nativeSetPrefetchesTiles"),
|
||||
METHOD(&NativeMapView::getPrefetchesTiles, "nativeGetPrefetchesTiles")
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "map/camera_position.hpp"
|
||||
#include "style/light.hpp"
|
||||
#include "bitmap.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
@@ -253,6 +254,8 @@ public:
|
||||
|
||||
void removeImage(JNIEnv&, jni::String);
|
||||
|
||||
jni::Object<Bitmap> getImage(JNIEnv&, jni::String);
|
||||
|
||||
void setPrefetchesTiles(JNIEnv&, jni::jboolean);
|
||||
|
||||
jni::jboolean getPrefetchesTiles(JNIEnv&);
|
||||
|
||||
Reference in New Issue
Block a user