[android] add unknown layer type
This commit is contained in:
committed by
Ivo van Dongen
parent
283aee0754
commit
3e48b377fd
@@ -0,0 +1,25 @@
|
||||
package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
/**
|
||||
* An unknown type of layer
|
||||
*/
|
||||
@UiThread
|
||||
public class UnknownLayer extends Layer {
|
||||
|
||||
/**
|
||||
* Creates a UnknownLayer.
|
||||
*
|
||||
* @param nativePtr pointer used by core
|
||||
*/
|
||||
UnknownLayer(long nativePtr) {
|
||||
super(nativePtr);
|
||||
}
|
||||
|
||||
protected native void initialize();
|
||||
|
||||
@Override
|
||||
protected native void finalize() throws Throwable;
|
||||
|
||||
}
|
||||
@@ -114,6 +114,8 @@ macro(mbgl_platform_core)
|
||||
platform/android/src/style/layers/raster_layer.hpp
|
||||
platform/android/src/style/layers/symbol_layer.cpp
|
||||
platform/android/src/style/layers/symbol_layer.hpp
|
||||
platform/android/src/style/layers/unknown_layer.cpp
|
||||
platform/android/src/style/layers/unknown_layer.hpp
|
||||
platform/android/src/style/sources/geojson_source.cpp
|
||||
platform/android/src/style/sources/geojson_source.hpp
|
||||
platform/android/src/style/sources/source.cpp
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "layers.hpp"
|
||||
|
||||
#include <mbgl/style/layer.hpp>
|
||||
#include <mbgl/style/layers/background_layer.hpp>
|
||||
#include <mbgl/style/layers/circle_layer.hpp>
|
||||
#include <mbgl/style/layers/fill_layer.hpp>
|
||||
@@ -10,11 +11,12 @@
|
||||
|
||||
#include "background_layer.hpp"
|
||||
#include "circle_layer.hpp"
|
||||
#include "custom_layer.hpp"
|
||||
#include "fill_layer.hpp"
|
||||
#include "line_layer.hpp"
|
||||
#include "raster_layer.hpp"
|
||||
#include "symbol_layer.hpp"
|
||||
#include "custom_layer.hpp"
|
||||
#include "unknown_layer.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -36,7 +38,7 @@ Layer* initializeLayerPeer(mbgl::Map& map, mbgl::style::Layer& coreLayer) {
|
||||
} else if (coreLayer.is<mbgl::style::CustomLayer>()) {
|
||||
layer = new CustomLayer(map, *coreLayer.as<mbgl::style::CustomLayer>());
|
||||
} else {
|
||||
throw new std::runtime_error("Layer type not implemented");
|
||||
layer = new UnknownLayer(map, coreLayer);
|
||||
}
|
||||
|
||||
return layer;
|
||||
@@ -53,11 +55,12 @@ void registerNativeLayers(jni::JNIEnv& env) {
|
||||
Layer::registerNative(env);
|
||||
BackgroundLayer::registerNative(env);
|
||||
CircleLayer::registerNative(env);
|
||||
CustomLayer::registerNative(env);
|
||||
FillLayer::registerNative(env);
|
||||
LineLayer::registerNative(env);
|
||||
RasterLayer::registerNative(env);
|
||||
SymbolLayer::registerNative(env);
|
||||
CustomLayer::registerNative(env);
|
||||
UnknownLayer::registerNative(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
49
platform/android/src/style/layers/unknown_layer.cpp
Normal file
49
platform/android/src/style/layers/unknown_layer.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "unknown_layer.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
// Dummy initializer (We don't support initializing this from the JVM)
|
||||
std::unique_ptr<mbgl::android::UnknownLayer> init(jni::JNIEnv&) {
|
||||
throw new std::runtime_error("UnknownLayer should not be initialized from the JVM");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
UnknownLayer::UnknownLayer(mbgl::Map& map, mbgl::style::Layer& coreLayer)
|
||||
: Layer(map, coreLayer) {
|
||||
}
|
||||
|
||||
UnknownLayer::UnknownLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::Layer> coreLayer)
|
||||
: Layer(map, std::move(coreLayer)) {
|
||||
}
|
||||
|
||||
jni::Class<UnknownLayer> UnknownLayer::javaClass;
|
||||
|
||||
jni::jobject* UnknownLayer::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto constructor = UnknownLayer::javaClass.template GetConstructor<jni::jlong>(env);
|
||||
return UnknownLayer::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void UnknownLayer::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
UnknownLayer::javaClass = *jni::Class<UnknownLayer>::Find(env).NewGlobalRef(env).release();
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
std::function<std::unique_ptr<UnknownLayer>(JNIEnv&)> initializer = nullptr;
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<UnknownLayer>(
|
||||
env, UnknownLayer::javaClass, "nativePtr",
|
||||
init,
|
||||
"initialize",
|
||||
"finalize");
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
30
platform/android/src/style/layers/unknown_layer.hpp
Normal file
30
platform/android/src/style/layers/unknown_layer.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "layer.hpp"
|
||||
#include <mbgl/style/layer.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class UnknownLayer : public Layer {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/layers/UnknownLayer"; };
|
||||
|
||||
static jni::Class<UnknownLayer> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
UnknownLayer(mbgl::Map&, mbgl::style::Layer&);
|
||||
|
||||
UnknownLayer(mbgl::Map&, std::unique_ptr<mbgl::style::Layer>);
|
||||
|
||||
~UnknownLayer() = default;
|
||||
|
||||
jni::jobject* createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class UnknownLayer
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user