feat: add runtime particle field updates
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <mbgl/util/projection.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/layers/raster_particle_layer.hpp>
|
||||
#include <mbgl/style/sources/raster_array_source.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/style/filter.hpp>
|
||||
#include <mbgl/renderer/query.hpp>
|
||||
@@ -1145,6 +1146,24 @@ jni::jboolean NativeMapView::setStyleLayerFloatProperty(JNIEnv& env,
|
||||
return true;
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::advanceRasterArraySourceFieldWindow(JNIEnv& env, const jni::String& sourceId) {
|
||||
const auto id = jni::Make<std::string>(env, sourceId);
|
||||
auto* source = map->getStyle().getSource(id);
|
||||
auto* rasterArraySource = dynamic_cast<mbgl::style::RasterArraySource*>(source);
|
||||
if (!rasterArraySource) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI,
|
||||
"ParticleField: event=FIELD_WINDOW_UPDATE_REJECTED reason=SOURCE_NOT_FOUND sourceId=" + id);
|
||||
return false;
|
||||
}
|
||||
const auto result = rasterArraySource->advanceRuntimeFieldWindow();
|
||||
const bool success = result == mbgl::style::RasterArrayRuntimeFieldUpdateResult::Applied ||
|
||||
result == mbgl::style::RasterArrayRuntimeFieldUpdateResult::Noop;
|
||||
mbgl::Log::Info(mbgl::Event::JNI,
|
||||
"ParticleField: event=FIELD_WINDOW_UPDATE_BRIDGE sourceId=" + id +
|
||||
" result=" + (success ? "SUCCESS" : "REJECTED"));
|
||||
return success;
|
||||
}
|
||||
|
||||
void NativeMapView::addLayer(JNIEnv& env, jlong nativeLayerPtr, const jni::String& before) {
|
||||
assert(nativeLayerPtr != 0);
|
||||
|
||||
@@ -1529,6 +1548,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::getLayers, "nativeGetLayers"),
|
||||
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
|
||||
METHOD(&NativeMapView::setStyleLayerFloatProperty, "nativeSetStyleLayerFloatProperty"),
|
||||
METHOD(&NativeMapView::advanceRasterArraySourceFieldWindow, "nativeAdvanceRasterArraySourceFieldWindow"),
|
||||
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
|
||||
METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
|
||||
METHOD(&NativeMapView::addLayerAt, "nativeAddLayerAt"),
|
||||
|
||||
@@ -282,6 +282,7 @@ public:
|
||||
|
||||
jni::Local<jni::Object<Layer>> getLayer(JNIEnv&, const jni::String&);
|
||||
jni::jboolean setStyleLayerFloatProperty(JNIEnv&, const jni::String&, const jni::String&, jni::jfloat);
|
||||
jni::jboolean advanceRasterArraySourceFieldWindow(JNIEnv&, const jni::String&);
|
||||
|
||||
void addLayer(JNIEnv&, jlong, const jni::String&);
|
||||
|
||||
|
||||
@@ -291,6 +291,11 @@ public final class MapLibreMap {
|
||||
return nativeMapView.setStyleLayerFloatProperty(layerId, propertyName, value);
|
||||
}
|
||||
|
||||
/** Advances a Source-owned raster-array runtime Field window without reloading the Style. */
|
||||
public boolean advanceRasterArraySourceFieldWindow(String sourceId) {
|
||||
return nativeMapView.advanceRasterArraySourceFieldWindow(sourceId);
|
||||
}
|
||||
|
||||
// Style
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,6 +141,8 @@ interface NativeMap {
|
||||
|
||||
boolean setStyleLayerFloatProperty(String layerId, String propertyName, float value);
|
||||
|
||||
boolean advanceRasterArraySourceFieldWindow(String sourceId);
|
||||
|
||||
boolean removeLayer(@NonNull String layerId);
|
||||
|
||||
boolean removeLayer(@NonNull Layer layer);
|
||||
|
||||
@@ -956,6 +956,12 @@ final class NativeMapView implements NativeMap {
|
||||
&& nativeSetStyleLayerFloatProperty(layerId, propertyName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean advanceRasterArraySourceFieldWindow(String sourceId) {
|
||||
return !checkState("advanceRasterArraySourceFieldWindow")
|
||||
&& nativeAdvanceRasterArraySourceFieldWindow(sourceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayer(@NonNull Layer layer) {
|
||||
if (checkState("addLayer")) {
|
||||
@@ -1690,6 +1696,9 @@ final class NativeMapView implements NativeMap {
|
||||
@Keep
|
||||
private native boolean nativeSetStyleLayerFloatProperty(String layerId, String propertyName, float value);
|
||||
|
||||
@Keep
|
||||
private native boolean nativeAdvanceRasterArraySourceFieldWindow(String sourceId);
|
||||
|
||||
@Keep
|
||||
private native void nativeAddLayer(long layerPtr, String before) throws CannotAddLayerException;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user