@@ -21,33 +21,93 @@ import androidx.compose.foundation.layout.Box
21
21
import androidx.compose.foundation.layout.fillMaxSize
22
22
import androidx.compose.foundation.layout.padding
23
23
import androidx.compose.runtime.Composable
24
+ import androidx.compose.runtime.getValue
25
+ import androidx.compose.runtime.mutableStateOf
26
+ import androidx.compose.runtime.remember
27
+ import androidx.compose.runtime.rememberCoroutineScope
28
+ import androidx.compose.runtime.setValue
24
29
import androidx.compose.ui.Alignment
25
30
import androidx.compose.ui.Modifier
26
31
import androidx.compose.ui.unit.dp
27
- import androidx.lifecycle.viewmodel.compose.viewModel
32
+ import com.arcgismaps.geometry.Envelope
33
+ import com.arcgismaps.geometry.Geometry
28
34
import com.arcgismaps.mapping.ArcGISMap
29
35
import com.arcgismaps.mapping.PortalItem
36
+ import com.arcgismaps.mapping.Viewpoint
30
37
import com.arcgismaps.portal.Portal
31
- import com.arcgismaps.toolkit.composablemap.ComposableMap
38
+ import com.arcgismaps.toolkit.geocompose.MapView
39
+ import com.arcgismaps.toolkit.geocompose.MapViewpointOperation
32
40
import com.arcgismaps.toolkit.indoors.FloorFilter
41
+ import com.arcgismaps.toolkit.indoors.FloorFilterSelection
42
+ import com.arcgismaps.toolkit.indoors.FloorFilterState
33
43
34
44
@Composable
35
45
fun MainScreen () {
36
- val portal = Portal (" https://arcgis.com/" )
37
- val portalItem = PortalItem (portal, " b4b599a43a474d33946cf0df526426f5" )
38
- val floorAwareWebMap = ArcGISMap (portalItem)
46
+ val floorAwareWebMap by remember {
47
+ mutableStateOf(
48
+ ArcGISMap (
49
+ PortalItem (
50
+ Portal (" https://arcgis.com/" ),
51
+ " b4b599a43a474d33946cf0df526426f5"
52
+ )
53
+ )
54
+ )
55
+ }
56
+
57
+ var mapViewpointOperation: MapViewpointOperation ? by remember { mutableStateOf(null ) }
58
+
59
+ val coroutineScope = rememberCoroutineScope()
60
+
61
+ // use default UI properties
62
+ val floorFilterState: FloorFilterState by remember {
63
+ mutableStateOf(FloorFilterState (
64
+ geoModel = floorAwareWebMap,
65
+ coroutineScope = coroutineScope
66
+ ) { floorFilterSelection ->
67
+ when (floorFilterSelection.type) {
68
+ is FloorFilterSelection .Type .FloorSite -> {
69
+ val floorFilterSelectionType =
70
+ floorFilterSelection.type as FloorFilterSelection .Type .FloorSite
71
+ floorFilterSelectionType.site.geometry?.let {
72
+ mapViewpointOperation =
73
+ MapViewpointOperation .Set (Viewpoint (getEnvelopeWithBuffer(it)))
74
+ }
75
+ }
76
+
77
+ is FloorFilterSelection .Type .FloorFacility -> {
78
+ val floorFilterSelectionType =
79
+ floorFilterSelection.type as FloorFilterSelection .Type .FloorFacility
80
+ floorFilterSelectionType.facility.geometry?.let {
81
+ mapViewpointOperation =
82
+ MapViewpointOperation .Set (Viewpoint (getEnvelopeWithBuffer(it)))
83
+ }
84
+ }
39
85
40
- val mapViewModel = viewModel<MapViewModel >(factory = MapViewModelFactory (floorAwareWebMap))
86
+ else -> {}
87
+ }
88
+ })
89
+ }
41
90
42
- ComposableMap (
91
+ MapView (
43
92
modifier = Modifier .fillMaxSize(),
44
- mapInterface = mapViewModel
93
+ arcGISMap = floorAwareWebMap,
94
+ viewpointOperation = mapViewpointOperation
95
+ )
96
+ Box (
97
+ modifier = Modifier .fillMaxSize().padding(horizontal = 20 .dp, vertical = 40 .dp),
98
+ contentAlignment = Alignment .BottomStart
45
99
) {
46
- Box (
47
- modifier = Modifier .fillMaxSize().padding(horizontal = 20 .dp, vertical = 40 .dp),
48
- contentAlignment = Alignment .BottomStart
49
- ) {
50
- FloorFilter (floorFilterState = mapViewModel.floorFilterState)
51
- }
100
+ FloorFilter (floorFilterState = floorFilterState)
52
101
}
53
102
}
103
+
104
+ /* *
105
+ * Returns the envelope with an added buffer factor applied to the given Geometry's extent.
106
+ *
107
+ * @since 200.2.0
108
+ */
109
+ private fun getEnvelopeWithBuffer (geometry : Geometry ): Envelope {
110
+ val bufferFactor = 1.25
111
+ val envelope = geometry.extent
112
+ return Envelope (envelope.center, envelope.width * bufferFactor, envelope.height * bufferFactor)
113
+ }
0 commit comments