fix: bridge Android particle mix property
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
This commit is contained in:
@@ -1106,6 +1106,23 @@ jni::Local<jni::Object<Layer>> NativeMapView::getLayer(JNIEnv& env, const jni::S
|
||||
return LayerManagerAndroid::get()->createJavaLayerPeer(env, *coreLayer);
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::setStyleLayerFloatProperty(JNIEnv& env,
|
||||
const jni::String& layerId,
|
||||
const jni::String& propertyName,
|
||||
const jni::jfloat value) {
|
||||
auto* layer = map->getStyle().getLayer(jni::Make<std::string>(env, layerId));
|
||||
if (!layer) return false;
|
||||
if (const auto error = layer->setProperty(jni::Make<std::string>(env, propertyName), static_cast<double>(value))) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "ParticleGPU: event=STYLE_PROPERTY_SET result=FAILURE " + error->message);
|
||||
return false;
|
||||
}
|
||||
mbgl::Log::Info(mbgl::Event::JNI,
|
||||
"ParticleGPU: event=STYLE_PROPERTY_SET layerId=" + jni::Make<std::string>(env, layerId) +
|
||||
" property=" + jni::Make<std::string>(env, propertyName) + " value=" + std::to_string(value) +
|
||||
" result=SUCCESS");
|
||||
return true;
|
||||
}
|
||||
|
||||
void NativeMapView::addLayer(JNIEnv& env, jlong nativeLayerPtr, const jni::String& before) {
|
||||
assert(nativeLayerPtr != 0);
|
||||
|
||||
@@ -1489,6 +1506,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::getLight, "nativeGetLight"),
|
||||
METHOD(&NativeMapView::getLayers, "nativeGetLayers"),
|
||||
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
|
||||
METHOD(&NativeMapView::setStyleLayerFloatProperty, "nativeSetStyleLayerFloatProperty"),
|
||||
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
|
||||
METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
|
||||
METHOD(&NativeMapView::addLayerAt, "nativeAddLayerAt"),
|
||||
|
||||
@@ -281,6 +281,7 @@ public:
|
||||
jni::Local<jni::Array<jni::Object<Layer>>> getLayers(JNIEnv&);
|
||||
|
||||
jni::Local<jni::Object<Layer>> getLayer(JNIEnv&, const jni::String&);
|
||||
jni::jboolean setStyleLayerFloatProperty(JNIEnv&, const jni::String&, const jni::String&, jni::jfloat);
|
||||
|
||||
void addLayer(JNIEnv&, jlong, const jni::String&);
|
||||
|
||||
|
||||
@@ -286,6 +286,11 @@ public final class MapLibreMap {
|
||||
return nativeMapView.getNativePtr();
|
||||
}
|
||||
|
||||
/** Updates a constant property on an existing Core style layer without requiring a Java Layer peer. */
|
||||
public boolean setStyleLayerFloatProperty(String layerId, String propertyName, float value) {
|
||||
return nativeMapView.setStyleLayerFloatProperty(layerId, propertyName, value);
|
||||
}
|
||||
|
||||
// Style
|
||||
|
||||
/**
|
||||
|
||||
@@ -139,6 +139,8 @@ interface NativeMap {
|
||||
|
||||
Layer getLayer(String layerId);
|
||||
|
||||
boolean setStyleLayerFloatProperty(String layerId, String propertyName, float value);
|
||||
|
||||
boolean removeLayer(@NonNull String layerId);
|
||||
|
||||
boolean removeLayer(@NonNull Layer layer);
|
||||
|
||||
@@ -950,6 +950,12 @@ final class NativeMapView implements NativeMap {
|
||||
return nativeGetLayer(layerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setStyleLayerFloatProperty(String layerId, String propertyName, float value) {
|
||||
return !checkState("setStyleLayerFloatProperty")
|
||||
&& nativeSetStyleLayerFloatProperty(layerId, propertyName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayer(@NonNull Layer layer) {
|
||||
if (checkState("addLayer")) {
|
||||
@@ -1681,6 +1687,9 @@ final class NativeMapView implements NativeMap {
|
||||
@Keep
|
||||
private native Layer nativeGetLayer(String layerId);
|
||||
|
||||
@Keep
|
||||
private native boolean nativeSetStyleLayerFloatProperty(String layerId, String propertyName, float value);
|
||||
|
||||
@Keep
|
||||
private native void nativeAddLayer(long layerPtr, String before) throws CannotAddLayerException;
|
||||
|
||||
|
||||
@@ -144,11 +144,6 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
|
||||
|
||||
private fun setTimeMix(value: Float) {
|
||||
val requestedTimeMix = value.coerceIn(0.0f, 1.0f)
|
||||
val layer = maplibreMap.style?.getLayer(PARTICLE_LAYER_ID)
|
||||
if (layer == null) {
|
||||
Log.i(TAG, "ParticleGPU: event=MIX_REJECTED reason=LAYER_NOT_READY styleEpoch=$styleLoadEpoch")
|
||||
return
|
||||
}
|
||||
val rejectReason = when {
|
||||
!styleReady -> "STYLE_LOADING"
|
||||
!enabled -> "DISABLED"
|
||||
@@ -159,8 +154,12 @@ class ParticleCoreLayerValidationActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "ParticleGPU: event=MIX_REJECTED reason=$rejectReason styleEpoch=$styleLoadEpoch")
|
||||
return
|
||||
}
|
||||
Log.i(TAG, "ParticleGPU: event=MIX_PROPERTY_REQUEST value=$requestedTimeMix styleEpoch=$styleLoadEpoch")
|
||||
if (!maplibreMap.setStyleLayerFloatProperty(PARTICLE_LAYER_ID, "raster-particle-time-mix", requestedTimeMix)) {
|
||||
Log.i(TAG, "ParticleGPU: event=MIX_REJECTED reason=CORE_LAYER_NOT_FOUND styleEpoch=$styleLoadEpoch")
|
||||
return
|
||||
}
|
||||
timeMix = requestedTimeMix
|
||||
layer.setProperties(PaintPropertyValue("raster-particle-time-mix", timeMix))
|
||||
status.text = statusText()
|
||||
Log.i(TAG, "ParticleGPU: event=MIX_PROPERTY_ONLY value=$timeMix styleEpoch=$styleLoadEpoch")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user