diff options
author | Niklas Ulvinge <ulvinge@gmail.com> | 2015-07-20 23:15:53 +0200 |
---|---|---|
committer | Niklas Ulvinge <ulvinge@gmail.com> | 2015-07-20 23:15:53 +0200 |
commit | d7d816cb67525f30acfc0a71ec154beeee1e167a (patch) | |
tree | aa72edfad8ec34cdb19736d6adcdc7edf5475fb3 /android/cpp | |
parent | 42cd266aa63e7a6cfc874306c380bec5c262e0d3 (diff) | |
download | qtlocation-mapboxgl-d7d816cb67525f30acfc0a71ec154beeee1e167a.tar.gz |
SetSprite now works
Diffstat (limited to 'android/cpp')
-rw-r--r-- | android/cpp/jni.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 1878beda5b..7b585f2206 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -18,6 +18,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/annotation/point_annotation.hpp> #include <mbgl/annotation/shape_annotation.hpp> +#include <mbgl/annotation/sprite_image.hpp> #include <mbgl/platform/event.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/storage/network_status.hpp> @@ -532,6 +533,27 @@ void JNICALL nativeSetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, j nativeMapView->getMap().setLatLng(mbgl::LatLng(latitude, longitude), std::chrono::milliseconds(duration)); } +void JNICALL nativeSetSprite(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, + jstring symbol, jint width, jint height, jfloat scale, jbyteArray jpixels) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetSprite"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + + const std::string symbolName = std_string_from_jstring(env, symbol); + + jbyte* pixelData = env->GetByteArrayElements(jpixels, nullptr); + std::string pixels((char*)pixelData, width * height * 4); + env->ReleaseByteArrayElements(jpixels, pixelData, JNI_ABORT); + + auto spriteImage = std::make_shared<mbgl::SpriteImage>( + uint16_t(width), + uint16_t(height), + float(scale), + std::move(pixels)); + + nativeMapView->getMap().setSprite(symbolName, spriteImage); +} + jlong JNICALL nativeAddMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject marker) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarker"); assert(nativeMapViewPtr != 0); @@ -773,6 +795,8 @@ void JNICALL nativeRemoveAnnotations(JNIEnv *env, jobject obj, jlong nativeMapVi ids.push_back((uint32_t) jids[i]); } + env->ReleaseLongArrayElements(array, jids, JNI_ABORT); + nativeMapView->getMap().removeAnnotations(ids); } @@ -1439,6 +1463,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { {"nativeMoveBy", "(JDDJ)V", reinterpret_cast<void *>(&nativeMoveBy)}, {"nativeSetLatLng", "(JLcom/mapbox/mapboxgl/geometry/LatLng;J)V", reinterpret_cast<void *>(&nativeSetLatLng)}, + {"nativeSetSprite", "(JLjava/lang/String;IIF[B)V", reinterpret_cast<void *>(&nativeSetSprite)}, {"nativeAddMarker", "(JLcom/mapbox/mapboxgl/annotations/Marker;)J", reinterpret_cast<void *>(&nativeAddMarker)}, {"nativeAddPolyline", "(JLcom/mapbox/mapboxgl/annotations/Polyline;)J", |