feat: add Android host weather runtime facade
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -29,6 +31,7 @@
|
||||
#include <mbgl/util/projection.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/layers/raster_particle_layer.hpp>
|
||||
#include <mbgl/style/layers/weather_color_layer.hpp>
|
||||
#include <mbgl/style/sources/raster_array_source.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/style/filter.hpp>
|
||||
@@ -1169,6 +1172,48 @@ jni::jboolean NativeMapView::setStyleLayerFloatProperty(JNIEnv& env,
|
||||
return true;
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::setStyleLayerVisibility(JNIEnv& env, const jni::String& layerId, const jni::jboolean visible) {
|
||||
auto* layer = map->getStyle().getLayer(jni::Make<std::string>(env, layerId));
|
||||
if (!layer) return false;
|
||||
layer->setVisibility(visible ? mbgl::style::VisibilityType::Visible : mbgl::style::VisibilityType::None);
|
||||
return true;
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::setRasterParticleColors(JNIEnv& env,
|
||||
const jni::String& layerId,
|
||||
const jni::Array<jni::jfloat>& particle,
|
||||
const jni::Array<jni::jfloat>& trail) {
|
||||
auto* layer = dynamic_cast<mbgl::style::RasterParticleLayer*>(map->getStyle().getLayer(jni::Make<std::string>(env, layerId)));
|
||||
if (!layer || particle.Length(env) != 4 || trail.Length(env) != 4) return false;
|
||||
std::array<float, 4> particleColor, trailColor;
|
||||
jni::GetArrayRegion(env, particle, 0, 4, particleColor.data());
|
||||
jni::GetArrayRegion(env, trail, 0, 4, trailColor.data());
|
||||
if (!mbgl::style::validWeatherRGBA(particleColor) || !mbgl::style::validWeatherRGBA(trailColor)) return false;
|
||||
layer->setParticleColor(particleColor);
|
||||
layer->setTrailColor(trailColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::setWeatherColorStops(JNIEnv& env,
|
||||
const jni::String& layerId,
|
||||
const jni::Array<jni::jfloat>& speeds,
|
||||
const jni::Array<jni::jfloat>& rgba) {
|
||||
auto* layer = dynamic_cast<mbgl::style::WeatherColorLayer*>(map->getStyle().getLayer(jni::Make<std::string>(env, layerId)));
|
||||
const auto count = speeds.Length(env);
|
||||
if (!layer || count < 2 || count > static_cast<jni::jsize>(mbgl::style::MaxWeatherColorStops) || rgba.Length(env) != count * 4) return false;
|
||||
std::vector<float> speedValues(count), rgbaValues(static_cast<size_t>(count) * 4);
|
||||
jni::GetArrayRegion(env, speeds, 0, count, speedValues.data());
|
||||
jni::GetArrayRegion(env, rgba, 0, count * 4, rgbaValues.data());
|
||||
std::vector<mbgl::style::WeatherColorStop> stops;
|
||||
stops.reserve(count);
|
||||
for (jni::jsize i = 0; i < count; ++i) {
|
||||
std::array<float, 4> color;
|
||||
std::copy_n(rgbaValues.data() + i * 4, 4, color.data());
|
||||
stops.push_back({speedValues[i], color});
|
||||
}
|
||||
return layer->setColorStops(std::move(stops));
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -1227,6 +1272,25 @@ jni::jint NativeMapView::submitRasterArraySourceHostField(JNIEnv& env,
|
||||
return static_cast<jni::jint>(result);
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::clearRasterArraySourceHostFields(JNIEnv& env, const jni::String& sourceId) {
|
||||
const auto id = jni::Make<std::string>(env, sourceId);
|
||||
auto* source = dynamic_cast<mbgl::style::RasterArraySource*>(map->getStyle().getSource(id));
|
||||
if (!source) return false;
|
||||
const bool cleared = source->clearHostFields();
|
||||
mbgl::Log::Info(mbgl::Event::JNI,
|
||||
"WeatherRuntime: event=CLEAR_FIELDS sourceId=" + id + " result=" +
|
||||
(cleared ? "SUCCESS" : "REJECTED"));
|
||||
return cleared;
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::seekRasterArraySourceTimelineToTimestamp(JNIEnv& env,
|
||||
const jni::String& sourceId,
|
||||
const jni::jlong timestamp) {
|
||||
const auto id = jni::Make<std::string>(env, sourceId);
|
||||
auto* source = dynamic_cast<mbgl::style::RasterArraySource*>(map->getStyle().getSource(id));
|
||||
return source && timestamp >= 0 && source->seekRuntimeTimelineToTimestamp(static_cast<uint64_t>(timestamp));
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::controlRasterArraySourceTimeline(JNIEnv& env,
|
||||
const jni::String& sourceId,
|
||||
const jni::jint command,
|
||||
@@ -1625,9 +1689,14 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::getLayers, "nativeGetLayers"),
|
||||
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
|
||||
METHOD(&NativeMapView::setStyleLayerFloatProperty, "nativeSetStyleLayerFloatProperty"),
|
||||
METHOD(&NativeMapView::setStyleLayerVisibility, "nativeSetStyleLayerVisibility"),
|
||||
METHOD(&NativeMapView::setRasterParticleColors, "nativeSetRasterParticleColors"),
|
||||
METHOD(&NativeMapView::setWeatherColorStops, "nativeSetWeatherColorStops"),
|
||||
METHOD(&NativeMapView::advanceRasterArraySourceFieldWindow, "nativeAdvanceRasterArraySourceFieldWindow"),
|
||||
METHOD(&NativeMapView::repeatRasterArraySourceFieldWindow, "nativeRepeatRasterArraySourceFieldWindow"),
|
||||
METHOD(&NativeMapView::submitRasterArraySourceHostField, "nativeSubmitRasterArraySourceHostField"),
|
||||
METHOD(&NativeMapView::clearRasterArraySourceHostFields, "nativeClearRasterArraySourceHostFields"),
|
||||
METHOD(&NativeMapView::seekRasterArraySourceTimelineToTimestamp, "nativeSeekRasterArraySourceTimelineToTimestamp"),
|
||||
METHOD(&NativeMapView::controlRasterArraySourceTimeline, "nativeControlRasterArraySourceTimeline"),
|
||||
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
|
||||
METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
|
||||
|
||||
Reference in New Issue
Block a user