|
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
|
package org.maplibre.android.maps;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Looper;
|
|
|
|
|
@@ -12,6 +13,7 @@ import java.util.List;
|
|
|
|
|
* It owns no provider, network, route, ETA, Snapshot, T0/T1, or GPU state.
|
|
|
|
|
*/
|
|
|
|
|
public final class WeatherRuntime {
|
|
|
|
|
private static final long MAX_FIELD_PAYLOAD_BYTES = 64L * 1024L * 1024L;
|
|
|
|
|
public enum State { DISABLED, WAITING_FOR_FIELDS, READY, ERROR }
|
|
|
|
|
public enum PlaybackState { PLAY, PAUSE }
|
|
|
|
|
public enum PlaybackSpeed { HALF(0.5f), NORMAL(1.0f), DOUBLE(2.0f); final float value; PlaybackSpeed(float value) { this.value = value; } }
|
|
|
|
|
@@ -76,7 +78,27 @@ public final class WeatherRuntime {
|
|
|
|
|
if (state == State.READY && result.accepted()) scheduleCadenceWake();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
public CommandResult clearWindFields() { if (disposed || state == State.DISABLED) return CommandResult.REJECTED; boolean ok = map.clearRasterArraySourceHostFields(config.sourceId); state = stateAfterClear(state, ok); if (ok) cancelCadenceWake(); return result(ok); }
|
|
|
|
|
/** v2 provider-neutral ingress; missing scalar/vector is expressed only by its explicit presence flag. */
|
|
|
|
|
public FieldSubmitResult submitField(@NonNull String metadataJson, @Nullable byte[] scalarBytes, @Nullable byte[] vectorBytes, @NonNull byte[] validityBytes) {
|
|
|
|
|
requireAttached(); requireEnabled();
|
|
|
|
|
if (metadataJson.isEmpty() || validityBytes.length == 0 || (scalarBytes == null && vectorBytes == null)) return FieldSubmitResult.REJECTED_ADAPTER;
|
|
|
|
|
final int scalarLength = scalarBytes == null ? 0 : scalarBytes.length;
|
|
|
|
|
final int vectorLength = vectorBytes == null ? 0 : vectorBytes.length;
|
|
|
|
|
if ((scalarBytes != null && scalarLength == 0) || (vectorBytes != null && vectorLength == 0)) return FieldSubmitResult.REJECTED_ADAPTER;
|
|
|
|
|
final long total = (long) scalarLength + vectorLength + validityBytes.length;
|
|
|
|
|
// Do not rely on Kotlin's file-reference guard: Java callers can bypass it.
|
|
|
|
|
if (total > MAX_FIELD_PAYLOAD_BYTES || total > Integer.MAX_VALUE) return FieldSubmitResult.REJECTED_ADAPTER;
|
|
|
|
|
final byte[] packed = new byte[(int) total]; int offset = 0;
|
|
|
|
|
if (scalarBytes != null) { System.arraycopy(scalarBytes, 0, packed, offset, scalarLength); offset += scalarLength; }
|
|
|
|
|
if (vectorBytes != null) { System.arraycopy(vectorBytes, 0, packed, offset, vectorLength); offset += vectorLength; }
|
|
|
|
|
System.arraycopy(validityBytes, 0, packed, offset, validityBytes.length);
|
|
|
|
|
FieldSubmitResult result = FieldSubmitResult.fromCode(map.submitRasterArraySourceHostFieldV2(config.sourceId, metadataJson,
|
|
|
|
|
packed, scalarBytes != null, scalarLength, vectorBytes != null, vectorLength, validityBytes.length));
|
|
|
|
|
state = stateAfterSubmit(state, result); if (state == State.READY && result.accepted()) scheduleCadenceWake(); return result;
|
|
|
|
|
}
|
|
|
|
|
public CommandResult clearFields() { if (disposed || state == State.DISABLED) return CommandResult.REJECTED; boolean ok = map.clearRasterArraySourceHostFields(config.sourceId); state = stateAfterClear(state, ok); if (ok) cancelCadenceWake(); return result(ok); }
|
|
|
|
|
/** @deprecated v1 compatibility alias. */
|
|
|
|
|
public CommandResult clearWindFields() { return clearFields(); }
|
|
|
|
|
public CommandResult setWeatherEnabled(boolean enabled) {
|
|
|
|
|
if (disposed) return CommandResult.REJECTED;
|
|
|
|
|
if (!enabled) {
|
|
|
|
|
@@ -108,6 +130,11 @@ public final class WeatherRuntime {
|
|
|
|
|
public CommandResult setParticleOpacity(float opacity) { return setParticleFloat("raster-particle-particle-opacity", opacity); }
|
|
|
|
|
public CommandResult setTrailOpacity(float opacity) { return setParticleFloat("raster-particle-trail-opacity", opacity); }
|
|
|
|
|
public CommandResult setTrailFade(float fade) { return setParticleFloat("raster-particle-trail-fade", fade); }
|
|
|
|
|
public CommandResult setParticleAdvectionScale(float scale) { return disposed || !Float.isFinite(scale) || scale <= 0f ? CommandResult.REJECTED : setParticleFloat("raster-particle-advection-scale", scale); }
|
|
|
|
|
public CommandResult setFieldValueSource(@NonNull FieldValueSource source) {
|
|
|
|
|
if (disposed) return CommandResult.REJECTED;
|
|
|
|
|
return result(map.setStyleLayerFloatProperty(config.weatherColorLayerId, "weather-color-field-value-source", source.code));
|
|
|
|
|
}
|
|
|
|
|
public CommandResult setParticleSpeedColorEnabled(boolean enabled) { return setParticleFloat("raster-particle-speed-color-enabled", enabled ? 1f : 0f); }
|
|
|
|
|
/** Sets only the particle RGBA; trail color and WeatherColor ramp are unchanged. */
|
|
|
|
|
public CommandResult setParticleColor(float red, float green, float blue, float alpha) {
|
|
|
|
|
@@ -143,6 +170,7 @@ public final class WeatherRuntime {
|
|
|
|
|
return result(map.setWeatherColorStops(config.weatherColorLayerId, speeds, colors));
|
|
|
|
|
}
|
|
|
|
|
private static CommandResult result(boolean accepted) { return accepted ? CommandResult.ACCEPTED : CommandResult.REJECTED; }
|
|
|
|
|
public enum FieldValueSource { SCALAR(0f), VECTOR_MAGNITUDE(1f); final float code; FieldValueSource(float code) { this.code = code; } }
|
|
|
|
|
private boolean shouldWakeWeather() {
|
|
|
|
|
return !disposed && targetFps != TargetFps.AUTO && state == State.READY && (particleVisible || (weatherColorVisible && playbackState == PlaybackState.PLAY));
|
|
|
|
|
}
|
|
|
|
|
|