Skip to content

Commit 69eb845

Browse files
authored
Change signature of QRF taking featureset to support nullable geometry (#2831)
1 parent e94bc12 commit 69eb845

File tree

9 files changed

+100
-24
lines changed

9 files changed

+100
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Mapbox welcomes participation and contributions from everyone.
44

55
# main
66
# 11.8.0
7+
## Breaking changes ⚠️
8+
* Change the signature of experimental `MapboxMap.queryRenderedFeatures(RenderedQueryGeometry, TypedFeaturesetDescriptor, Value?, QueryRenderedFeaturesetFeaturesCallback)` to `MapboxMap.queryRenderedFeatures(TypedFeaturesetDescriptor, RenderedQueryGeometry?, Value?, QueryRenderedFeaturesetFeaturesCallback)`. `RenderedQueryGeometry` being NULL is equivalent to passing a bounding box encompassing the entire map viewport.
9+
* [compose] Change the signature of experimental `MapState.queryRenderedFeatures(RenderedQueryGeometry, TypedFeaturesetDescriptor, Expression?): List` to `MapState.queryRenderedFeatures(TypedFeaturesetDescriptor, RenderedQueryGeometry?, Expression?): List`. `RenderedQueryGeometry` being NULL is equivalent to passing a bounding box encompassing the entire map viewport.
10+
711
## Bug fixes 🐞
812
* Disable false-positive lint error "Incorrect number of expressions".
913

compose-app/src/main/java/com/mapbox/maps/compose/testapp/examples/basic/QueryRenderedFeatureActivity.kt

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
66
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.material.FloatingActionButton
9+
import androidx.compose.material.Text
710
import androidx.compose.runtime.LaunchedEffect
811
import androidx.compose.runtime.getValue
912
import androidx.compose.runtime.mutableStateOf
@@ -12,6 +15,7 @@ import androidx.compose.runtime.rememberCoroutineScope
1215
import androidx.compose.runtime.setValue
1316
import androidx.compose.ui.Modifier
1417
import androidx.compose.ui.graphics.Color
18+
import androidx.compose.ui.unit.dp
1519
import com.mapbox.geojson.Point
1620
import com.mapbox.geojson.Polygon
1721
import com.mapbox.maps.MapboxExperimental
@@ -35,7 +39,11 @@ import kotlinx.coroutines.launch
3539
/**
3640
* Example to showcase usage of query rendered features.
3741
*/
42+
@OptIn(MapboxExperimental::class)
3843
public class QueryRenderedFeatureActivity : ComponentActivity() {
44+
45+
private val buildingFeatureset = TypedFeaturesetDescriptor.Layer("building")
46+
3947
override fun onCreate(savedInstanceState: Bundle?) {
4048
super.onCreate(savedInstanceState)
4149
setContent {
@@ -47,20 +55,39 @@ public class QueryRenderedFeatureActivity : ComponentActivity() {
4755
pinchToZoomEnabled = false
4856
}
4957
}
50-
var highlightedBuilding by remember {
58+
var clickedBuilding by remember {
5159
mutableStateOf(emptyList<List<Point>>())
5260
}
61+
var viewportHighlightedBuildings by remember {
62+
mutableStateOf(emptyList<List<List<Point>>>())
63+
}
5364
LaunchedEffect(Unit) {
5465
with(mapState) {
5566
// wait and suspend for the first ever map idle event, meaning map is rendered.
5667
mapIdleEvents.first()
57-
highlightedBuilding =
68+
clickedBuilding =
5869
queryBuildingCoordinatesAt(CityLocations.HELSINKI)!!
5970
}
6071
}
72+
val coroutineScope = rememberCoroutineScope()
6173
MapboxMapComposeTheme {
62-
ExampleScaffold {
63-
val coroutineScope = rememberCoroutineScope()
74+
ExampleScaffold(
75+
floatingActionButton = {
76+
FloatingActionButton(
77+
onClick = {
78+
coroutineScope.launch {
79+
viewportHighlightedBuildings = mapState.queryRenderedFeatures(
80+
buildingFeatureset
81+
).map {
82+
(it.geometry as? Polygon)?.coordinates()?.toList() ?: emptyList()
83+
}
84+
}
85+
}
86+
) {
87+
Text(modifier = Modifier.padding(10.dp), text = "Highlight all")
88+
}
89+
}
90+
) {
6491
MapboxMap(
6592
Modifier.fillMaxSize(),
6693
mapViewportState = rememberMapViewportState {
@@ -75,17 +102,23 @@ public class QueryRenderedFeatureActivity : ComponentActivity() {
75102
onMapClickListener = { clickedPoint ->
76103
coroutineScope.launch {
77104
mapState.queryBuildingCoordinatesAt(clickedPoint)?.let {
78-
highlightedBuilding = it
105+
clickedBuilding = it
79106
}
80107
}
81108
false
82109
},
83110
mapState = mapState
84111
) {
85-
PolygonAnnotation(highlightedBuilding) {
112+
PolygonAnnotation(clickedBuilding) {
86113
fillColor = Color.Red
87114
fillOpacity = 0.5
88115
}
116+
viewportHighlightedBuildings.forEach { building ->
117+
PolygonAnnotation(building) {
118+
fillColor = Color.Blue
119+
fillOpacity = 0.5
120+
}
121+
}
89122
}
90123
}
91124
}
@@ -96,7 +129,7 @@ public class QueryRenderedFeatureActivity : ComponentActivity() {
96129
private suspend fun MapState.queryBuildingCoordinatesAt(point: Point): List<List<Point>>? {
97130
val selectedBuildings = queryRenderedFeatures(
98131
geometry = RenderedQueryGeometry(pixelForCoordinate(point)),
99-
descriptor = TypedFeaturesetDescriptor.Layer("building")
132+
descriptor = buildingFeatureset
100133
)
101134
if (selectedBuildings.isEmpty()) {
102135
logD(TAG, "Clicked outside of building")

extension-compose/api/Release/metalava.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ package com.mapbox.maps.extension.compose {
5959
method public kotlinx.coroutines.flow.Flow<com.mapbox.maps.StyleLoaded> getStyleLoadedEvents();
6060
method public suspend Object? pixelForCoordinate(com.mapbox.geojson.Point coordinate, kotlin.coroutines.Continuation<? super com.mapbox.maps.ScreenCoordinate>);
6161
method public suspend Object? queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.RenderedQueryOptions options, kotlin.coroutines.Continuation<? super com.mapbox.bindgen.Expected<java.lang.String,java.util.List<? extends com.mapbox.maps.QueriedRenderedFeature>>>);
62-
method @com.mapbox.maps.MapboxExperimental public suspend <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> Object? queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.extension.style.expressions.generated.Expression? filter = null, kotlin.coroutines.Continuation<? super java.util.List<? extends FF>> = null);
63-
method @com.mapbox.maps.MapboxExperimental public suspend <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> Object? queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, kotlin.coroutines.Continuation<? super java.util.List<? extends FF>> = null);
62+
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);
63+
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);
64+
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);
6465
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);
6566
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);
6667
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ public final class com/mapbox/maps/extension/compose/MapState {
8181
public final fun getStyleLoadedEvents ()Lkotlinx/coroutines/flow/Flow;
8282
public final fun pixelForCoordinate (Lcom/mapbox/geojson/Point;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8383
public final fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/RenderedQueryOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
84-
public final fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/extension/style/expressions/generated/Expression;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
85-
public final fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
86-
public static synthetic fun queryRenderedFeatures$default (Lcom/mapbox/maps/extension/compose/MapState;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/extension/style/expressions/generated/Expression;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
84+
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/extension/style/expressions/generated/Expression;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
85+
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
86+
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
87+
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;
8788
public final fun removeFeatureState (Lcom/mapbox/maps/interactions/FeaturesetFeature;Lcom/mapbox/maps/interactions/FeatureStateKey;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8889
public final fun removeFeatureState (Lcom/mapbox/maps/interactions/FeaturesetFeature;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
8990
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.mapbox.maps.RenderFrameStarted
2727
import com.mapbox.maps.RenderedQueryGeometry
2828
import com.mapbox.maps.RenderedQueryOptions
2929
import com.mapbox.maps.ResourceRequest
30+
import com.mapbox.maps.ScreenBox
3031
import com.mapbox.maps.ScreenCoordinate
3132
import com.mapbox.maps.SourceAdded
3233
import com.mapbox.maps.SourceDataLoaded
@@ -238,9 +239,10 @@ public class MapState internal constructor(initialGesturesSettings: GesturesSett
238239
mapboxMapFlow.filterNotNull().first().queryRenderedFeatures(geometry, options)
239240

240241
/**
241-
* Queries the map for given [descriptor] and returns typed [FeaturesetFeature] list in the callback.
242+
* Queries the map for given [descriptor] and returns typed [FeaturesetFeature] list of rendered features.
242243
*
243-
* @param geometry The `screen pixel coordinates` (point, line string or box) to query for rendered features.
244+
* @param geometry The optional geometry ([ScreenCoordinate], [ScreenBox] or list of [ScreenCoordinate]s) to query for rendered features.
245+
* Passing NULL is equivalent to passing a bounding box encompassing the entire map viewport.
244246
* @param descriptor [TypedFeaturesetDescriptor] object representing either a featureset or a single layer.
245247
* @param filter optional global filter.
246248
*
@@ -249,8 +251,8 @@ public class MapState internal constructor(initialGesturesSettings: GesturesSett
249251
@MapboxExperimental
250252
@JvmOverloads
251253
public suspend fun <FF : FeaturesetFeature<*>> queryRenderedFeatures(
252-
geometry: RenderedQueryGeometry,
253254
descriptor: TypedFeaturesetDescriptor<*, FF>,
255+
geometry: RenderedQueryGeometry? = null,
254256
filter: Expression? = null,
255257
): List<FF> {
256258
mapboxMapFlow.filterNotNull().first().apply {

maps-sdk/api/Release/metalava.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ package com.mapbox.maps {
248248
method public com.mapbox.maps.MercatorCoordinate project(com.mapbox.geojson.Point point, double zoomScale);
249249
method public com.mapbox.maps.ProjectedMeters projectedMetersForCoordinate(com.mapbox.geojson.Point point);
250250
method public com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.RenderedQueryOptions options, com.mapbox.maps.QueryRenderedFeaturesCallback callback);
251-
method @com.mapbox.maps.MapboxExperimental public <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.bindgen.Value? filter = null, com.mapbox.maps.interactions.QueryRenderedFeaturesetFeaturesCallback<FF> callback);
252-
method @com.mapbox.maps.MapboxExperimental public <FF extends com.mapbox.maps.interactions.FeaturesetFeature<?>> com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,FF> descriptor, com.mapbox.maps.interactions.QueryRenderedFeaturesetFeaturesCallback<FF> callback);
251+
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);
252+
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);
253+
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);
253254
method @com.mapbox.maps.MapboxDelicateApi @com.mapbox.maps.MapboxExperimental public com.mapbox.common.Cancelable queryRenderedFeatures(com.mapbox.maps.RenderedQueryGeometry geometry, java.util.List<com.mapbox.maps.FeaturesetQueryTarget> targets, com.mapbox.maps.QueryRenderedFeaturesCallback callback);
254255
method public com.mapbox.common.Cancelable querySourceFeatures(String sourceId, com.mapbox.maps.SourceQueryOptions options, com.mapbox.maps.QuerySourceFeaturesCallback callback);
255256
method @com.mapbox.maps.MapboxExperimental public com.mapbox.common.Cancelable querySourceFeatures(com.mapbox.maps.interactions.TypedFeaturesetDescriptor<?,?> descriptor, com.mapbox.bindgen.Value? filter = null, Long? tag = null, com.mapbox.maps.QuerySourceFeaturesCallback callback);

maps-sdk/api/maps-sdk.api

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ public final class com/mapbox/maps/MapboxMap : com/mapbox/maps/MapboxStyleManage
257257
public fun project (Lcom/mapbox/geojson/Point;D)Lcom/mapbox/maps/MercatorCoordinate;
258258
public fun projectedMetersForCoordinate (Lcom/mapbox/geojson/Point;)Lcom/mapbox/maps/ProjectedMeters;
259259
public fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/RenderedQueryOptions;Lcom/mapbox/maps/QueryRenderedFeaturesCallback;)Lcom/mapbox/common/Cancelable;
260-
public final fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
261-
public final fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
262260
public final fun queryRenderedFeatures (Lcom/mapbox/maps/RenderedQueryGeometry;Ljava/util/List;Lcom/mapbox/maps/QueryRenderedFeaturesCallback;)Lcom/mapbox/common/Cancelable;
263-
public static synthetic fun queryRenderedFeatures$default (Lcom/mapbox/maps/MapboxMap;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;ILjava/lang/Object;)Lcom/mapbox/common/Cancelable;
261+
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
262+
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/RenderedQueryGeometry;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
263+
public final fun queryRenderedFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/interactions/QueryRenderedFeaturesetFeaturesCallback;)Lcom/mapbox/common/Cancelable;
264+
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;
264265
public final fun querySourceFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/QuerySourceFeaturesCallback;)Lcom/mapbox/common/Cancelable;
265266
public final fun querySourceFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/bindgen/Value;Ljava/lang/Long;Lcom/mapbox/maps/QuerySourceFeaturesCallback;)Lcom/mapbox/common/Cancelable;
266267
public final fun querySourceFeatures (Lcom/mapbox/maps/interactions/TypedFeaturesetDescriptor;Lcom/mapbox/maps/QuerySourceFeaturesCallback;)Lcom/mapbox/common/Cancelable;

0 commit comments

Comments
 (0)