157 lines
7.0 KiB
Plaintext
157 lines
7.0 KiB
Plaintext
<%
|
|
const type = locals.type;
|
|
const properties = locals.properties;
|
|
-%>
|
|
// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.
|
|
|
|
#include "<%- type.replace('-', '_') %>_layer.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include "../conversion/property_value.hpp"
|
|
#include "../conversion/transition_options.hpp"
|
|
|
|
#include <mbgl/style/layer_impl.hpp>
|
|
|
|
namespace mbgl {
|
|
namespace android {
|
|
|
|
inline mbgl::style::<%- camelize(type) %>Layer& to<%- camelize(type) %>Layer(mbgl::style::Layer& layer) {
|
|
return static_cast<mbgl::style::<%- camelize(type) %>Layer&>(layer);
|
|
}
|
|
|
|
<% if (type === 'background' || type === 'location-indicator') { -%>
|
|
/**
|
|
* Creates an owning peer object (for layers not attached to the map) from the JVM side
|
|
*/
|
|
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String& layerId)
|
|
: Layer(std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(jni::Make<std::string>(env, layerId))) {
|
|
<% } else { -%>
|
|
/**
|
|
* Creates an owning peer object (for layers not attached to the map) from the JVM side
|
|
*/
|
|
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String& layerId, jni::String& sourceId)
|
|
: Layer(std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
|
|
<% } -%>
|
|
}
|
|
|
|
/**
|
|
* Creates a non-owning peer object (for layers currently attached to the map)
|
|
*/
|
|
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(mbgl::style::<%- camelize(type) %>Layer& coreLayer)
|
|
: Layer(coreLayer) {
|
|
}
|
|
|
|
/**
|
|
* Creates an owning peer object (for layers not attached to the map)
|
|
*/
|
|
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(std::unique_ptr<mbgl::style::<%- camelize(type) %>Layer> coreLayer)
|
|
: Layer(std::move(coreLayer)) {
|
|
}
|
|
|
|
<%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default;
|
|
|
|
// Property getters
|
|
|
|
<% for (const property of properties) { -%>
|
|
<% if (property.name != 'heatmap-color') { -%>
|
|
jni::Local<jni::Object<>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(jni::JNIEnv& env) {
|
|
using namespace mbgl::android::conversion;
|
|
auto layer = layerPtr.get();
|
|
if (!layer) {
|
|
return std::move(*convert<jni::Local<jni::Object<>>>(env, style::<%- camelize(type) %>Layer::getDefault<%- camelize(property.name) %>()));
|
|
}
|
|
return std::move(*convert<jni::Local<jni::Object<>>>(env, to<%- camelize(type) %>Layer(*layer).get<%- camelize(property.name) %>()));
|
|
}
|
|
|
|
<% } else { -%>
|
|
jni::Local<jni::Object<>> HeatmapLayer::getHeatmapColor(jni::JNIEnv& env) {
|
|
using namespace mbgl::android::conversion;
|
|
auto layer = layerPtr.get();
|
|
if (!layer) {
|
|
return std::move(*convert<jni::Local<jni::Object<>>>(env, style::<%- camelize(type) %>Layer::getDefaultHeatmapColor()));
|
|
}
|
|
|
|
auto propertyValue = to<%- camelize(type) %>Layer(*layer).getHeatmapColor();
|
|
if (propertyValue.isUndefined()) {
|
|
propertyValue = to<%- camelize(type) %>Layer(*layer).getDefaultHeatmapColor();
|
|
}
|
|
return std::move(*convert<jni::Local<jni::Object<>>>(env, propertyValue));
|
|
}
|
|
|
|
<% } -%>
|
|
<% if (property.transition) { -%>
|
|
jni::Local<jni::Object<TransitionOptions>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>Transition(jni::JNIEnv& env) {
|
|
using namespace mbgl::android::conversion;
|
|
auto layer = layerPtr.get();
|
|
if (!layer) {
|
|
return std::move(*convert<jni::Local<jni::Object<TransitionOptions>>>(env, mbgl::style::TransitionOptions()));
|
|
}
|
|
mbgl::style::TransitionOptions options = to<%- camelize(type) %>Layer(*layer).get<%- camelize(property.name) %>Transition();
|
|
return std::move(*convert<jni::Local<jni::Object<TransitionOptions>>>(env, options));
|
|
}
|
|
|
|
void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>Transition(jni::JNIEnv&, jlong duration, jlong delay) {
|
|
auto layer = layerPtr.get();
|
|
if (!layer) {
|
|
return;
|
|
}
|
|
mbgl::style::TransitionOptions options;
|
|
options.duration.emplace(mbgl::Milliseconds(duration));
|
|
options.delay.emplace(mbgl::Milliseconds(delay));
|
|
to<%- camelize(type) %>Layer(*layer).set<%- camelize(property.name) %>Transition(options);
|
|
}
|
|
|
|
<% } -%>
|
|
<% } -%>
|
|
|
|
// <%- camelize(type) %>JavaLayerPeerFactory
|
|
|
|
<%- camelize(type) %>JavaLayerPeerFactory::~<%- camelize(type) %>JavaLayerPeerFactory() = default;
|
|
|
|
namespace {
|
|
jni::Local<jni::Object<Layer>> createJavaPeer(jni::JNIEnv& env, Layer* layer) {
|
|
static auto& javaClass = jni::Class<<%- camelize(type) %>Layer>::Singleton(env);
|
|
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
|
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(layer));
|
|
}
|
|
} // namespace
|
|
|
|
jni::Local<jni::Object<Layer>> <%- camelize(type) %>JavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, mbgl::style::Layer& layer) {
|
|
assert(layer.baseImpl->getTypeInfo() == getTypeInfo());
|
|
return createJavaPeer(env, new <%- camelize(type) %>Layer(to<%- camelize(type) %>Layer(layer)));
|
|
}
|
|
|
|
jni::Local<jni::Object<Layer>> <%- camelize(type) %>JavaLayerPeerFactory::createJavaLayerPeer(jni::JNIEnv& env, std::unique_ptr<mbgl::style::Layer> layer) {
|
|
assert(layer->baseImpl->getTypeInfo() == getTypeInfo());
|
|
return createJavaPeer(env, new <%- camelize(type) %>Layer(std::unique_ptr<mbgl::style::<%- camelize(type) %>Layer>(static_cast<mbgl::style::<%- camelize(type) %>Layer*>(layer.release()))));
|
|
}
|
|
|
|
void <%- camelize(type) %>JavaLayerPeerFactory::registerNative(jni::JNIEnv& env) {
|
|
// Lookup the class
|
|
static auto& javaClass = jni::Class<<%- camelize(type) %>Layer>::Singleton(env);
|
|
|
|
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
|
|
|
// Register the peer
|
|
jni::RegisterNativePeer<<%- camelize(type) %>Layer>(
|
|
env,
|
|
javaClass,
|
|
"nativePtr",
|
|
<% if (type === 'background' || type === 'location-indicator') { -%>
|
|
jni::MakePeer<<%- camelize(type) %>Layer, jni::String&>,
|
|
<% } else { -%>
|
|
jni::MakePeer<<%- camelize(type) %>Layer, jni::String&, jni::String&>,
|
|
<% } -%>
|
|
"initialize",
|
|
"finalize",<% for(var i = 0; i < properties.length; i++) {%>
|
|
<% if (properties[i].transition) { -%>
|
|
METHOD(&<%- camelize(type) %>Layer::get<%- camelize(properties[i].name) %>Transition, "nativeGet<%- camelize(properties[i].name) %>Transition"),
|
|
METHOD(&<%- camelize(type) %>Layer::set<%- camelize(properties[i].name) %>Transition, "nativeSet<%- camelize(properties[i].name) %>Transition"),
|
|
<% } -%>
|
|
METHOD(&<%- camelize(type) %>Layer::get<%- camelize(properties[i].name) %>, "nativeGet<%- camelize(properties[i].name) %>")<% if(i != (properties.length -1)) {-%>,<% } -%><% } -%>);
|
|
}
|
|
|
|
} // namespace android
|
|
} // namespace mbgl
|