Skip to content

Commit a45d31c

Browse files
lyydikoigithub-actions[bot]
authored andcommitted
[maps-sdk-android] Expose new queryRenderedRasterValue API in Android SDK (#9435)
## Summary Exposes the `queryRenderedRasterValues` API to allow querying raster values at a specific screen coordinate. This enables developers to retrieve raster layer data at any point on the rendered map. ## Changes ### Core API (`maps-sdk`) - **MapboxMap**: Added `queryRenderedRasterValues()` method with callback-based API - **NativeMapImpl**: Implemented bridge to native map functionality - **Coroutine Support**: Added suspend function extension in `MapFeatureQueryDelegateExt.kt` - **Delegate Interface**: Extended `MapFeatureQueryDelegate` with new query method - **Compose Integration (`extension-compose`)": **MapState** -- Added `queryRenderedRasterValues()` suspend function for Jetpack Compose integration ### API Surface - All API tracking files updated (metalava.txt and .api files for both `maps-sdk`, `sdk-base`, and `extension-compose`) - Marked as `@MapboxExperimental` to indicate experimental status ### Test - queryRenderedRasterValues() test added cc @mapbox/maps-android cc @mapbox/sdk-ci cc @mapbox/sdk-platform GitOrigin-RevId: f3c0b087743b438c124178dd9b52befa77dcbadf
1 parent 0964257 commit a45d31c

13 files changed

Lines changed: 101 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Mapbox welcomes participation and contributions from everyone.
99
## Features ✨ and improvements 🏁
1010
* Introduce experimental `queryRenderedRasterValues` API for querying the rendered raster array value at a point on the map.
1111
* Introduce new `AnnotationConfig#slotName` property to allow to specify a slot to position annotation layer.
12+
* Introduce experimental `queryRenderedRasterValues` API for querying the rendered raster values on the map at a specific screen coordinate.
1213

1314
## Bug fixes 🐞
1415
* Fix rare scenario where map render surface size was wrong.

extension-compose/api/Release/metalava.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ package com.mapbox.maps.extension.compose {
6363
method @com.mapbox.maps.MapboxExperimental public suspend <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> Object? queryRenderedFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.RenderedQueryGeometry? geometry = null, com.mapbox.maps.extension.style.expressions.generated.Expression? filter = null, kotlin.coroutines.Continuation<? super java.util.List<? extends FF>> = null);
6464
method @com.mapbox.maps.MapboxExperimental public suspend <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> Object? queryRenderedFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.RenderedQueryGeometry? geometry = null, kotlin.coroutines.Continuation<? super java.util.List<? extends FF>> = null);
6565
method @com.mapbox.maps.MapboxExperimental public suspend <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> Object? queryRenderedFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, kotlin.coroutines.Continuation<? super java.util.List<? extends FF>> = null);
66+
method @com.mapbox.maps.MapboxExperimental public suspend Object? queryRenderedRasterValues(com.mapbox.maps.ScreenCoordinate coordinate, com.mapbox.maps.RenderedRasterQueryOptions options, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.maps.QueriedRasterValues>>);
6667
method @com.mapbox.maps.MapboxExperimental public suspend <FS extends com.mapbox.maps.interactions.FeatureState, FSK extends com.mapbox.maps.interactions.FeatureStateKey<FS>> Object? removeFeatureState(com.mapbox.maps.interactions.FeaturesetFeature<FS> featuresetFeature, FSK? stateKey = null, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None>> = null);
6768
method @com.mapbox.maps.MapboxExperimental public suspend <FS extends com.mapbox.maps.interactions.FeatureState, FSK extends com.mapbox.maps.interactions.FeatureStateKey<FS>> Object? removeFeatureState(com.mapbox.maps.interactions.FeaturesetFeature<FS> featuresetFeature, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None>> = null);
6869
method @com.mapbox.maps.MapboxExperimental public suspend Object? resetFeatureStates(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,?> descriptor, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None>>);

extension-compose/api/extension-compose.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public final class com/mapbox/maps/extension/compose/MapState {
8686
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8787
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8888
public static synthetic fun queryRenderedFeatures$default (Lcom/mapbox/maps/extension/compose/MapState;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/extension/style/expressions/generated/Expression;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
89+
public final fun queryRenderedRasterValues (Lcom/mapbox/maps/ScreenCoordinate;Lcom/mapbox/maps/RenderedRasterQueryOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8990
public final fun removeFeatureState (Lcom/mapbox/maps/interactions/FeaturesetFeature;Lcom/mapbox/maps/interactions/FeatureStateKey;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
9091
public final fun removeFeatureState (Lcom/mapbox/maps/interactions/FeaturesetFeature;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
9192
public static synthetic fun removeFeatureState$default (Lcom/mapbox/maps/extension/compose/MapState;Lcom/mapbox/maps/interactions/FeaturesetFeature;Lcom/mapbox/maps/interactions/FeatureStateKey;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;

extension-compose/src/main/java/com/mapbox/maps/extension/compose/MapState.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import com.mapbox.maps.MapOptions
2222
import com.mapbox.maps.MapView
2323
import com.mapbox.maps.MapboxExperimental
2424
import com.mapbox.maps.MapboxMap
25+
import com.mapbox.maps.QueriedRasterValues
2526
import com.mapbox.maps.QueriedRenderedFeature
2627
import com.mapbox.maps.RenderFrameFinished
2728
import com.mapbox.maps.RenderFrameStarted
2829
import com.mapbox.maps.RenderedQueryGeometry
2930
import com.mapbox.maps.RenderedQueryOptions
31+
import com.mapbox.maps.RenderedRasterQueryOptions
3032
import com.mapbox.maps.ResourceRequest
3133
import com.mapbox.maps.ScreenBox
3234
import com.mapbox.maps.ScreenCoordinate
@@ -44,6 +46,7 @@ import com.mapbox.maps.coroutine.mapIdleEvents
4446
import com.mapbox.maps.coroutine.mapLoadedEvents
4547
import com.mapbox.maps.coroutine.mapLoadingErrorEvents
4648
import com.mapbox.maps.coroutine.queryRenderedFeatures
49+
import com.mapbox.maps.coroutine.queryRenderedRasterValues
4750
import com.mapbox.maps.coroutine.renderFrameFinishedEvents
4851
import com.mapbox.maps.coroutine.renderFrameStartedEvents
4952
import com.mapbox.maps.coroutine.resourceRequestEvents
@@ -280,6 +283,21 @@ public class MapState internal constructor(initialGesturesSettings: GesturesSett
280283
}
281284
}
282285

286+
/**
287+
* Queries the map for rendered raster values at a specific coordinate.
288+
*
289+
* @param coordinate The position on the screen to query.
290+
* @param options The options for configuring the rendered raster value query.
291+
*
292+
* @return [QueriedRasterValues] containing raster values or a string describing an error.
293+
*/
294+
@MapboxExperimental
295+
public suspend fun queryRenderedRasterValues(
296+
coordinate: ScreenCoordinate,
297+
options: RenderedRasterQueryOptions
298+
): Expected<String, QueriedRasterValues> =
299+
mapboxMapFlow.filterNotNull().first().queryRenderedRasterValues(coordinate, options)
300+
283301
/**
284302
* Gets the state map of a feature from a featureset asynchronously.
285303
*

maps-sdk/api/Release/metalava.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ package com.mapbox.maps {
260260
method @com.mapbox.maps.MapboxExperimental public <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.RenderedQueryGeometry? geometry = null, com.mapbox.bindgen.Value? filter = null, com.mapbox.maps.interactions.QueryRenderedFeaturesetFeaturesCallback<FF> callback);
261261
method @com.mapbox.maps.MapboxExperimental public <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.RenderedQueryGeometry? geometry = null, com.mapbox.maps.interactions.QueryRenderedFeaturesetFeaturesCallback<FF> callback);
262262
method @com.mapbox.maps.MapboxExperimental public <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.interactions.QueryRenderedFeaturesetFeaturesCallback<FF> callback);
263+
method @com.mapbox.maps.MapboxExperimental public com.mapbox.common.Cancelable queryRenderedRasterValues(com.mapbox.maps.ScreenCoordinate coordinate, com.mapbox.maps.RenderedRasterQueryOptions options, com.mapbox.maps.QueryRenderedRasterValuesCallback callback);
263264
method public com.mapbox.common.Cancelable querySourceFeatures(String sourceId, com.mapbox.maps.SourceQueryOptions options, com.mapbox.maps.QuerySourceFeaturesCallback callback);
264265
method public void reduceMemoryUse();
265266
method public com.mapbox.common.Cancelable removeFeatureState(String sourceId, String? sourceLayerId, String featureId, String? stateKey, com.mapbox.maps.FeatureStateOperationCallback callback);
@@ -570,6 +571,7 @@ package com.mapbox.maps.coroutine {
570571

571572
public final class MapFeatureQueryDelegateExtKt {
572573
method @kotlin.jvm.JvmSynthetic public static suspend com.mapbox.bindgen.Expected<java.lang.String,java.util.List<? extends com.mapbox.maps.QueriedRenderedFeature>>! queryRenderedFeatures(com.mapbox.maps.plugin.delegates.MapFeatureQueryDelegate, com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.RenderedQueryOptions options);
574+
method @com.mapbox.maps.MapboxExperimental @kotlin.jvm.JvmSynthetic public static suspend com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.maps.QueriedRasterValues>! queryRenderedRasterValues(com.mapbox.maps.plugin.delegates.MapFeatureQueryDelegate, com.mapbox.maps.ScreenCoordinate coordinate, com.mapbox.maps.RenderedRasterQueryOptions options);
573575
method @kotlin.jvm.JvmSynthetic public static suspend com.mapbox.bindgen.Expected<java.lang.String,java.util.List<? extends com.mapbox.maps.QueriedSourceFeature>>! querySourceFeatures(com.mapbox.maps.plugin.delegates.MapFeatureQueryDelegate, String sourceId, com.mapbox.maps.SourceQueryOptions options);
574576
}
575577

@@ -651,7 +653,7 @@ package com.mapbox.maps.renderer {
651653
method @com.mapbox.maps.renderer.RenderThread public void onFpsChanged(double fps);
652654
}
653655

654-
@kotlin.annotation.MustBeDocumented @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.SOURCE) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.FUNCTION, kotlin.annotation.AnnotationTarget.PROPERTY_GETTER, kotlin.annotation.AnnotationTarget.PROPERTY_SETTER, kotlin.annotation.AnnotationTarget.CONSTRUCTOR, kotlin.annotation.AnnotationTarget.CLASS}) public @interface RenderThread {
656+
@kotlin.annotation.MustBeDocumented @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.SOURCE) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.FUNCTION, kotlin.annotation.AnnotationTarget.PROPERTY_GETTER, kotlin.annotation.AnnotationTarget.PROPERTY_SETTER, kotlin.annotation.AnnotationTarget.PROPERTY, kotlin.annotation.AnnotationTarget.CONSTRUCTOR, kotlin.annotation.AnnotationTarget.CLASS}) public @interface RenderThread {
655657
}
656658

657659
@com.mapbox.maps.MapboxExperimental public final class RenderThreadStats {

maps-sdk/api/maps-sdk.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ public final class com/mapbox/maps/MapboxMap : com/mapbox/maps/MapboxStyleManage
270270
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
271271
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
272272
public static synthetic fun queryRenderedFeatures$default (Lcom/mapbox/maps/MapboxMap;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;ILjava/lang/Object;)Lcom/mapbox/common/Cancelable;
273+
public fun queryRenderedRasterValues (Lcom/mapbox/maps/ScreenCoordinate;Lcom/mapbox/maps/RenderedRasterQueryOptions;Lcom/mapbox/maps/QueryRenderedRasterValuesCallback;)Lcom/mapbox/common/Cancelable;
273274
public fun querySourceFeatures (Ljava/lang/String;Lcom/mapbox/maps/SourceQueryOptions;Lcom/mapbox/maps/QuerySourceFeaturesCallback;)Lcom/mapbox/common/Cancelable;
274275
public final fun reduceMemoryUse ()V
275276
public final fun removeFeatureState (Lcom/mapbox/maps/interactions/FeaturesetFeature;)Lcom/mapbox/common/Cancelable;
@@ -637,6 +638,7 @@ public final class com/mapbox/maps/coroutine/MapCameraManagerDelegateExtKt {
637638

638639
public final class com/mapbox/maps/coroutine/MapFeatureQueryDelegateExtKt {
639640
public static final synthetic fun queryRenderedFeatures (Lcom/mapbox/maps/plugin/delegates/MapFeatureQueryDelegate;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/RenderedQueryOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
641+
public static final synthetic fun queryRenderedRasterValues (Lcom/mapbox/maps/plugin/delegates/MapFeatureQueryDelegate;Lcom/mapbox/maps/ScreenCoordinate;Lcom/mapbox/maps/RenderedRasterQueryOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
640642
public static final synthetic fun querySourceFeatures (Lcom/mapbox/maps/plugin/delegates/MapFeatureQueryDelegate;Ljava/lang/String;Lcom/mapbox/maps/SourceQueryOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
641643
}
642644

maps-sdk/src/main/java/com/mapbox/maps/MapboxMap.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,24 @@ class MapboxMap :
13621362
return nativeMap.querySourceFeatures(sourceId, options, callback)
13631363
}
13641364

1365+
/**
1366+
* Queries the map for rendered raster values at a specific coordinate.
1367+
*
1368+
* @param coordinate The position on the screen to query.
1369+
* @param options The options for configuring the rendered raster value query.
1370+
* @param callback Callback invoked when the query completes
1371+
* @return A `cancelable` object that could be used to cancel the pending query.
1372+
*/
1373+
@MapboxExperimental
1374+
override fun queryRenderedRasterValues(
1375+
coordinate: ScreenCoordinate,
1376+
options: RenderedRasterQueryOptions,
1377+
callback: QueryRenderedRasterValuesCallback
1378+
): Cancelable {
1379+
checkNativeMap("queryRenderedRasterValues", false)
1380+
return nativeMap.queryRenderedRasterValues(coordinate, options, callback)
1381+
}
1382+
13651383
/**
13661384
* In some cases querying source / render features is expected to be a blocking operation
13671385
* e.g. performing this action on map click. In this case in order to avoid deadlock on main

maps-sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ internal class NativeMapImpl(val map: Map) {
496496
callback: QuerySourceFeaturesCallback
497497
): Cancelable = map.querySourceFeatures(sourceId, options, callback)
498498

499+
@MapboxExperimental
500+
fun queryRenderedRasterValues(
501+
coordinate: ScreenCoordinate,
502+
options: RenderedRasterQueryOptions,
503+
callback: QueryRenderedRasterValuesCallback
504+
): Cancelable = map.queryRenderedRasterValues(coordinate, options, callback)
505+
499506
fun queryFeatureExtensions(
500507
sourceIdentifier: String,
501508
feature: Feature,

maps-sdk/src/main/java/com/mapbox/maps/coroutine/MapFeatureQueryDelegateExt.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.mapbox.maps.coroutine
22

33
import com.mapbox.bindgen.Expected
4+
import com.mapbox.maps.MapboxExperimental
5+
import com.mapbox.maps.QueriedRasterValues
46
import com.mapbox.maps.QueriedRenderedFeature
57
import com.mapbox.maps.QueriedSourceFeature
68
import com.mapbox.maps.RenderedQueryGeometry
79
import com.mapbox.maps.RenderedQueryOptions
10+
import com.mapbox.maps.RenderedRasterQueryOptions
11+
import com.mapbox.maps.ScreenCoordinate
812
import com.mapbox.maps.SourceQueryOptions
913
import com.mapbox.maps.plugin.delegates.MapFeatureQueryDelegate
1014
import com.mapbox.maps.suspendMapboxCancellableCoroutine
@@ -45,4 +49,24 @@ suspend fun MapFeatureQueryDelegate.querySourceFeatures(
4549
): Expected<String, List<QueriedSourceFeature>> =
4650
suspendMapboxCancellableCoroutine { continuation ->
4751
querySourceFeatures(sourceId, options, continuation::resume)
52+
}
53+
54+
/**
55+
* Queries the map for rendered raster values at a specific coordinate.
56+
*
57+
* This is a suspend function variant of [MapFeatureQueryDelegate.queryRenderedRasterValues].
58+
*
59+
* @param coordinate The position on the screen to query.
60+
* @param options The options for configuring the rendered raster value query.
61+
*
62+
* @return [QueriedRasterValues] containing raster values or a string describing an error.
63+
*/
64+
@MapboxExperimental
65+
@JvmSynthetic
66+
suspend fun MapFeatureQueryDelegate.queryRenderedRasterValues(
67+
coordinate: ScreenCoordinate,
68+
options: RenderedRasterQueryOptions,
69+
): Expected<String, QueriedRasterValues> =
70+
suspendMapboxCancellableCoroutine { continuation ->
71+
queryRenderedRasterValues(coordinate, options, continuation::resume)
4872
}

maps-sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,15 @@ class MapboxMapTest {
15731573
verify { nativeMap.querySourceFeatures("id", querySourceOptions, querySourceCallback) }
15741574
}
15751575

1576+
@Test
1577+
fun queryRenderedRasterValues() {
1578+
val coordinate = mockk<ScreenCoordinate>()
1579+
val options = mockk<RenderedRasterQueryOptions>()
1580+
val callback = mockk<QueryRenderedRasterValuesCallback>()
1581+
mapboxMap.queryRenderedRasterValues(coordinate, options, callback)
1582+
verify { nativeMap.queryRenderedRasterValues(coordinate, options, callback) }
1583+
}
1584+
15761585
@Test
15771586
fun queryRenderedFeaturesGeometry() {
15781587
val queryCallback = mockk<QueryRenderedFeaturesCallback>()

0 commit comments

Comments
 (0)