Expose sync methods in GeoJsonSource (#3560)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
liyanjin
2025-06-24 20:38:22 +08:00
committed by GitHub
parent 55ff6a4428
commit 282735772b
4 changed files with 217 additions and 0 deletions

View File

@@ -275,6 +275,55 @@ class GeoJsonSource : Source {
}
}
/**
* Updates the GeoJson with a single feature. The update is performed synchronously,
* so the data will be immediately visible and available to query when this method returns.
*
* @param feature the GeoJSON [Feature] to set
*/
fun setGeoJsonSync(feature: Feature?) {
if (detached) {
return
}
checkThread()
nativeSetFeatureSync(feature)
}
/**
* Updates the GeoJson with a single geometry. The update is performed synchronously,
* so the data will be immediately visible and available to query when this method returns.
*
* @param geometry the GeoJSON [Geometry] to set
*/
fun setGeoJsonSync(geometry: Geometry?) {
if (detached) {
return
}
checkThread()
nativeSetGeometrySync(geometry)
}
/**
* Updates the GeoJson. The update is performed synchronously,
* so the data will be immediately visible and available to query when this method returns.
*
* @param featureCollection the GeoJSON FeatureCollection
*/
fun setGeoJsonSync(featureCollection: FeatureCollection?) {
if (detached) {
return
}
checkThread()
if (featureCollection != null && featureCollection.features() != null) {
val features = featureCollection.features()
val featuresCopy: List<Feature> = ArrayList(features)
nativeSetFeatureCollectionSync(FeatureCollection.fromFeatures(featuresCopy))
} else {
nativeSetFeatureCollectionSync(featureCollection)
}
}
/**
* Updates the GeoJson. The update is performed asynchronously,
* so the data won't be immediately visible or available to query when this method returns.
@@ -289,6 +338,20 @@ class GeoJsonSource : Source {
nativeSetGeoJsonString(json)
}
/**
* Updates the GeoJson. The update is performed synchronously,
* so the data will be immediately visible and available to query when this method returns.
*
* @param json the raw GeoJson FeatureCollection string
*/
fun setGeoJsonSync(json: String) {
if (detached) {
return
}
checkThread()
nativeSetGeoJsonStringSync(json)
}
/**
* Updates the url
*
@@ -480,6 +543,18 @@ class GeoJsonSource : Source {
@Keep
private external fun nativeSetGeometry(geometry: Geometry?)
@Keep
private external fun nativeSetGeoJsonStringSync(geoJson: String)
@Keep
private external fun nativeSetFeatureCollectionSync(geoJson: FeatureCollection?)
@Keep
private external fun nativeSetFeatureSync(feature: Feature?)
@Keep
private external fun nativeSetGeometrySync(geometry: Geometry?)
@Keep
private external fun querySourceFeatures(filter: Array<Any>?): Array<Feature>