Android: setOverrideSynchronousUpdate for existing sources (#4366)
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
committed by
GitHub
parent
f1905c5215
commit
40be634126
@@ -80,6 +80,7 @@ public:
|
||||
mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
bool isUpdateSynchronous() const noexcept;
|
||||
void setOverrideSynchronousUpdate(bool) noexcept;
|
||||
|
||||
protected:
|
||||
Mutable<Source::Impl> createMutable() const noexcept final;
|
||||
|
||||
@@ -217,6 +217,10 @@ jboolean GeoJSONSource::isUpdateSynchronous(jni::JNIEnv&) {
|
||||
return source.as<style::GeoJSONSource>()->isUpdateSynchronous();
|
||||
}
|
||||
|
||||
void GeoJSONSource::setOverrideSynchronousUpdate(jni::JNIEnv&, jni::jboolean newOverride) {
|
||||
source.as<style::GeoJSONSource>()->setOverrideSynchronousUpdate(newOverride);
|
||||
}
|
||||
|
||||
void GeoJSONSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto& javaClass = jni::Class<GeoJSONSource>::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<std::string> json, ActorRef<GeoJSONDataCallback> callback) {
|
||||
|
||||
@@ -86,6 +86,7 @@ private:
|
||||
void setCollectionSync(jni::JNIEnv&, const jni::Object<JNIType>&);
|
||||
|
||||
jboolean isUpdateSynchronous(jni::JNIEnv&);
|
||||
void setOverrideSynchronousUpdate(jni::JNIEnv&, jni::jboolean);
|
||||
|
||||
}; // class GeoJSONSource
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -144,7 +144,8 @@ GeoJSONSource::Impl::Impl(std::string id_, Immutable<GeoJSONOptions> options_)
|
||||
GeoJSONSource::Impl::Impl(const GeoJSONSource::Impl& other, std::shared_ptr<GeoJSONData> 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<std::string> 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
|
||||
|
||||
@@ -24,10 +24,12 @@ public:
|
||||
std::optional<std::string> getAttribution() const final;
|
||||
|
||||
bool isUpdateSynchronous() const final;
|
||||
void setOverrideSynchronousUpdate(bool newOverride) const;
|
||||
|
||||
private:
|
||||
Immutable<GeoJSONOptions> options;
|
||||
std::shared_ptr<GeoJSONData> data;
|
||||
mutable bool overrideSynchronousUpdate = false;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
Reference in New Issue
Block a user