diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index f44ac231e..46aaaabc2 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -80,6 +80,7 @@ public: mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } bool isUpdateSynchronous() const noexcept; + void setOverrideSynchronousUpdate(bool) noexcept; protected: Mutable createMutable() const noexcept final; diff --git a/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.cpp b/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.cpp index 926664fac..04a1231df 100644 --- a/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.cpp @@ -217,6 +217,10 @@ jboolean GeoJSONSource::isUpdateSynchronous(jni::JNIEnv&) { return source.as()->isUpdateSynchronous(); } +void GeoJSONSource::setOverrideSynchronousUpdate(jni::JNIEnv&, jni::jboolean newOverride) { + source.as()->setOverrideSynchronousUpdate(newOverride); +} + void GeoJSONSource::registerNative(jni::JNIEnv& env) { // Lookup the class static auto& javaClass = jni::Class::Singleton(env); @@ -241,7 +245,8 @@ void GeoJSONSource::registerNative(jni::JNIEnv& env) { METHOD(&GeoJSONSource::getClusterChildren, "nativeGetClusterChildren"), METHOD(&GeoJSONSource::getClusterLeaves, "nativeGetClusterLeaves"), METHOD(&GeoJSONSource::getClusterExpansionZoom, "nativeGetClusterExpansionZoom"), - METHOD(&GeoJSONSource::isUpdateSynchronous, "nativeIsUpdateSynchronous")); + METHOD(&GeoJSONSource::isUpdateSynchronous, "nativeIsUpdateSynchronous"), + METHOD(&GeoJSONSource::setOverrideSynchronousUpdate, "nativeSetOverrideSynchronousUpdate")); } void FeatureConverter::convertJson(std::shared_ptr json, ActorRef callback) { diff --git a/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.hpp b/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.hpp index 4e308b1dd..931e0a037 100644 --- a/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.hpp +++ b/platform/android/MapLibreAndroid/src/cpp/style/sources/geojson_source.hpp @@ -86,6 +86,7 @@ private: void setCollectionSync(jni::JNIEnv&, const jni::Object&); jboolean isUpdateSynchronous(jni::JNIEnv&); + void setOverrideSynchronousUpdate(jni::JNIEnv&, jni::jboolean); }; // class GeoJSONSource diff --git a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/style/sources/GeoJsonSource.kt b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/style/sources/GeoJsonSource.kt index 0fb2657d2..8710f42eb 100644 --- a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/style/sources/GeoJsonSource.kt +++ b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/style/sources/GeoJsonSource.kt @@ -560,9 +560,24 @@ class GeoJsonSource : Source { @Keep private external fun nativeGetClusterExpansionZoom(feature: Feature): Int + /** + * Overrides the synchronous update flag for this source at runtime. + * This is equivalent to constructing the source with [GeoJsonOptions.withSynchronousUpdate], + * but can be applied to existing sources loaded from a style JSON. + * + * @param override whether to force synchronous updates + */ + fun setOverrideSynchronousUpdate(override: Boolean) { + checkThread() + nativeSetOverrideSynchronousUpdate(override) + } + @Keep private external fun nativeIsUpdateSynchronous(): Boolean + @Keep + private external fun nativeSetOverrideSynchronousUpdate(override: Boolean) + @Keep @Throws(Throwable::class) protected external fun finalize() diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index 68fb83c9d..f082146a5 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -132,5 +132,9 @@ bool GeoJSONSource::isUpdateSynchronous() const noexcept { return baseImpl->isUpdateSynchronous(); } +void GeoJSONSource::setOverrideSynchronousUpdate(bool value) noexcept { + impl().setOverrideSynchronousUpdate(value); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 5f9cd72d2..cf7667b7c 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -144,7 +144,8 @@ GeoJSONSource::Impl::Impl(std::string id_, Immutable options_) GeoJSONSource::Impl::Impl(const GeoJSONSource::Impl& other, std::shared_ptr data_) : Source::Impl(other), options(other.options), - data(std::move(data_)) {} + data(std::move(data_)), + overrideSynchronousUpdate(other.overrideSynchronousUpdate) {} GeoJSONSource::Impl::~Impl() = default; @@ -161,7 +162,11 @@ std::optional GeoJSONSource::Impl::getAttribution() const { } bool GeoJSONSource::Impl::isUpdateSynchronous() const { - return options->synchronousUpdate; + return options->synchronousUpdate || overrideSynchronousUpdate; +} + +void GeoJSONSource::Impl::setOverrideSynchronousUpdate(bool newOverride) const { + overrideSynchronousUpdate = newOverride; } } // namespace style diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index c2a73a7eb..0b93136fd 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -24,10 +24,12 @@ public: std::optional getAttribution() const final; bool isUpdateSynchronous() const final; + void setOverrideSynchronousUpdate(bool newOverride) const; private: Immutable options; std::shared_ptr data; + mutable bool overrideSynchronousUpdate = false; }; } // namespace style