Skip to content

Commit 6dc7218

Browse files
authored
add support for attribution text (#187)
* add support for attribution text * combine attribution bar properties/events in a state object * refactor mapview parameter list * update collect lambda * Update doc * update doc
1 parent fda1735 commit 6dc7218

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* COPYRIGHT 1995-2023 ESRI
3+
*
4+
* TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
5+
* Unpublished material - all rights reserved under the
6+
* Copyright Laws of the United States.
7+
*
8+
* For additional information, contact:
9+
* Environmental Systems Research Institute, Inc.
10+
* Attn: Contracts Dept
11+
* 380 New York Street
12+
* Redlands, California, USA 92373
13+
*
14+
15+
*/
16+
17+
package com.arcgismaps.toolkit.geocompose
18+
19+
import androidx.compose.runtime.Stable
20+
import com.arcgismaps.mapping.view.AttributionBarLayoutChangeEvent
21+
22+
/**
23+
* State holder for attribution bar related properties/events on the [com.arcgismaps.toolkit.geocompose.MapView].
24+
*
25+
* @since 200.3.0
26+
*/
27+
@Stable
28+
public data class AttributionState(
29+
val isAttributionBarVisible: Boolean = true,
30+
val onAttributionTextChanged: ((String) -> Unit)? = null,
31+
val onAttributionBarLayoutChanged: ((AttributionBarLayoutChangeEvent) -> Unit)? = null
32+
)
33+

toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/MapView.kt

+26-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import kotlinx.coroutines.launch
6969
* @param grid represents the display of a coordinate system [Grid] on the composable MapView
7070
* @param backgroundGrid the default color and context grid behind the map surface
7171
* @param wrapAroundMode the [WrapAroundMode] to specify whether continuous panning across the international date line is enabled
72+
* @param attributionState specifies the attribution bar's visibility, text changed and layout changed events
7273
* @param onViewpointChanged lambda invoked when the viewpoint of the composable MapView has changed
7374
* @param onInteractingChanged lambda invoked when the user starts and ends interacting with the composable MapView
7475
* @param onRotate lambda invoked when a user performs a rotation gesture on the composable MapView
@@ -90,11 +91,12 @@ public fun MapView(
9091
arcGISMap: ArcGISMap? = null,
9192
graphicsOverlays: GraphicsOverlayCollection = rememberGraphicsOverlayCollection(),
9293
locationDisplay: LocationDisplay = rememberLocationDisplay(),
93-
wrapAroundMode: WrapAroundMode = WrapAroundMode.EnabledWhenSupported,
9494
geometryEditor: GeometryEditor? = null,
9595
mapViewInteractionOptions: MapViewInteractionOptions = MapViewInteractionOptions(),
9696
viewLabelProperties: ViewLabelProperties = ViewLabelProperties(),
9797
selectionProperties: SelectionProperties = SelectionProperties(),
98+
wrapAroundMode: WrapAroundMode = WrapAroundMode.EnabledWhenSupported,
99+
attributionState: AttributionState = AttributionState(),
98100
grid: Grid? = null,
99101
backgroundGrid: BackgroundGrid = BackgroundGrid(),
100102
onViewpointChanged: (() -> Unit)? = null,
@@ -142,6 +144,8 @@ public fun MapView(
142144
}
143145
}
144146

147+
AttributionStateHandler(mapView, attributionState)
148+
145149
MapViewEventHandler(
146150
mapView,
147151
onViewpointChanged,
@@ -161,6 +165,27 @@ public fun MapView(
161165
GraphicsOverlaysUpdater(graphicsOverlays, mapView)
162166
}
163167

168+
/**
169+
* Sets up the attribution bar's property and events.
170+
*/
171+
@Composable
172+
private fun AttributionStateHandler(mapView: MapView, attributionState: AttributionState) {
173+
LaunchedEffect(attributionState) {
174+
// isAttributionBarVisible does not take effect if applied in the AndroidView update callback
175+
mapView.isAttributionBarVisible = attributionState.isAttributionBarVisible
176+
launch {
177+
mapView.attributionText.collect {
178+
attributionState.onAttributionTextChanged?.invoke(it)
179+
}
180+
}
181+
launch {
182+
mapView.onAttributionBarLayoutChanged.collect { attributionBarLayoutChangedEvent ->
183+
attributionState.onAttributionBarLayoutChanged?.invoke(attributionBarLayoutChangedEvent)
184+
}
185+
}
186+
}
187+
}
188+
164189
/**
165190
* Sets up the callbacks for all the view-based [mapView] events.
166191
*/

0 commit comments

Comments
 (0)