Skip to content

Commit ec897e2

Browse files
Duy PhạmDuy Phạm
authored andcommitted
Add click support to zoom-in markers for Google Map and Mapbox drawers
1 parent adf411b commit ec897e2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMapDrawer.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ fun W3WGoogleMapDrawMarkers(
397397
if (drawZoomIn.value) {
398398
DrawZoomInMarkers(
399399
defaultMarkerColor = defaultMarkerColor,
400-
markers = markers
400+
markers = markers,
401+
onMarkerClicked = onMarkerClicked
401402
)
402403
} else {
403404
DrawZoomOutMarkers(
@@ -422,7 +423,8 @@ fun W3WGoogleMapDrawMarkers(
422423
@Composable
423424
private fun DrawZoomInMarkers(
424425
defaultMarkerColor: W3WMarkerColor,
425-
markers: ImmutableList<W3WMarker>
426+
markers: ImmutableList<W3WMarker>,
427+
onMarkerClicked: (W3WMarker) -> Unit
426428
) {
427429
val context = LocalContext.current
428430
val density = LocalDensity.current.density
@@ -460,6 +462,10 @@ private fun DrawZoomInMarkers(
460462
)
461463
),
462464
image = icon,
465+
onClick = {
466+
onMarkerClicked(marker)
467+
},
468+
clickable = true
463469
)
464470
}
465471
}

lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBoxDrawer.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import kotlinx.collections.immutable.persistentListOf
5959
import kotlinx.collections.immutable.toImmutableList
6060
import kotlinx.collections.immutable.toPersistentList
6161

62+
import com.mapbox.maps.MapboxExperimental
63+
6264
/**
6365
* Main drawer component for rendering what3words elements on a Mapbox map.
6466
*
@@ -350,7 +352,8 @@ fun W3WMapBoxDrawMarkers(
350352
if (drawZoomIn.value) {
351353
DrawZoomInMarkers(
352354
defaultMarkerColor,
353-
markers
355+
markers,
356+
onMarkerClicked,
354357
)
355358
} else {
356359
DrawZoomOutMarkers(
@@ -435,14 +438,17 @@ private fun DrawZoomOutMarkers(
435438
* @param defaultMarkerColor The default color to use for squares with multiple markers
436439
* @param markers The list of markers to display on the map
437440
*/
441+
@OptIn(MapboxExperimental::class)
438442
@Composable
439443
@MapboxMapComposable
440444
private fun DrawZoomInMarkers(
441445
defaultMarkerColor: W3WMarkerColor,
442-
markers: ImmutableList<W3WMarker>
446+
markers: ImmutableList<W3WMarker>,
447+
onMarkerClicked: (W3WMarker) -> Unit
443448
) {
444449
val context = LocalContext.current
445450
val density = LocalDensity.current.density
451+
val currentOnMarkerClicked by rememberUpdatedState(onMarkerClicked)
446452

447453
// Map of cached bitmap with key is the ID of the W3WColor
448454
val bitmapCache = remember { mutableMapOf<Long, Bitmap>() }
@@ -483,6 +489,10 @@ private fun DrawZoomInMarkers(
483489
rasterLayerState = remember {
484490
RasterLayerState().apply {
485491
rasterEmissiveStrength = DoubleValue(1.0)
492+
interactionsState.onClicked { _, _ ->
493+
currentOnMarkerClicked(marker)
494+
true
495+
}
486496
}
487497
}
488498
)

0 commit comments

Comments
 (0)