Skip to content

Commit 10c872f

Browse files
committed
changes to display a map
1 parent bcfe16d commit 10c872f

File tree

5 files changed

+126
-8
lines changed

5 files changed

+126
-8
lines changed

microapps/MapComposeApp/app/src/main/java/com/arcgismaps/toolkit/mapcomposeapp/screens/MainScreen.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@
1818

1919
package com.arcgismaps.toolkit.mapcomposeapp.screens
2020

21+
import androidx.compose.foundation.layout.fillMaxSize
2122
import androidx.compose.runtime.Composable
23+
import androidx.compose.ui.Modifier
24+
import com.arcgismaps.mapping.ArcGISMap
25+
import com.arcgismaps.mapping.BasemapStyle
2226
import com.arcgismaps.toolkit.geocompose.Map
27+
import com.arcgismaps.toolkit.geocompose.MapState
2328

2429
@Composable
2530
fun MainScreen() {
26-
// Todo implementation
27-
Map()
31+
32+
val mapState = MapState(arcGISMap = ArcGISMap(BasemapStyle.ArcGISStreets))
33+
Map(
34+
modifier = Modifier.fillMaxSize(),
35+
mapState = mapState,
36+
)
2837
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Esri
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.arcgismaps.toolkit.geocompose
19+
20+
/**
21+
* Represents the state for the GeoCompose.
22+
*
23+
* @since 200.3.0
24+
*/
25+
public sealed interface GeoComposeState {
26+
// TODO add implementation
27+
}
28+
29+
public fun GeoComposeState(): GeoComposeState =
30+
GeoComposeStateImpl()
31+
32+
public open class GeoComposeStateImpl() : GeoComposeState {
33+
}
34+

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

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*
2-
*
32
* Copyright 2023 Esri
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,16 +17,41 @@
1817

1918
package com.arcgismaps.toolkit.geocompose
2019

21-
import androidx.compose.material3.Text
2220
import androidx.compose.runtime.Composable
21+
import androidx.compose.runtime.DisposableEffect
22+
import androidx.compose.runtime.collectAsState
23+
import androidx.compose.runtime.getValue
24+
import androidx.compose.runtime.remember
25+
import androidx.compose.ui.Modifier
26+
import androidx.compose.ui.platform.LocalContext
27+
import androidx.compose.ui.platform.LocalLifecycleOwner
2328
import androidx.compose.ui.tooling.preview.Preview
29+
import androidx.compose.ui.viewinterop.AndroidView
30+
import com.arcgismaps.mapping.view.MapView
2431

2532
@Composable
26-
public fun Map() {
27-
// Todo implementation...
28-
Text("Implement Map here! ")
33+
public fun Map(modifier: Modifier = Modifier, mapState: MapState = MapState()) {
34+
35+
val lifecycleOwner = LocalLifecycleOwner.current
36+
val context = LocalContext.current
37+
val mapView = remember { MapView(context) }
38+
val map by mapState.arcGISMap.collectAsState()
39+
40+
AndroidView(modifier = modifier, factory = { mapView })
41+
42+
DisposableEffect(Unit) {
43+
lifecycleOwner.lifecycle.addObserver(mapView)
44+
onDispose {
45+
lifecycleOwner.lifecycle.removeObserver(mapView)
46+
mapView.onDestroy(lifecycleOwner)
47+
}
48+
}
49+
50+
mapView.map = map
51+
2952
}
3053

54+
3155
@Preview
3256
@Composable
3357
internal fun MapPreview() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Esri
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.arcgismaps.toolkit.geocompose
19+
20+
import com.arcgismaps.mapping.ArcGISMap
21+
import kotlinx.coroutines.flow.MutableStateFlow
22+
import kotlinx.coroutines.flow.StateFlow
23+
import kotlinx.coroutines.flow.asStateFlow
24+
25+
/**
26+
* Represents the state for the Map.
27+
*
28+
* @since 200.3.0
29+
*/
30+
public sealed interface MapState : GeoComposeState {
31+
public val arcGISMap: StateFlow<ArcGISMap?>
32+
33+
public fun setArcGISMap(arcGISMap: ArcGISMap)
34+
}
35+
36+
public fun MapState(arcGISMap: ArcGISMap? = null): MapState = MapStateImpl(arcGISMap)
37+
38+
private class MapStateImpl(
39+
arcGISMap: ArcGISMap?
40+
) : MapState {
41+
42+
private val _arcGISMap: MutableStateFlow<ArcGISMap?> = MutableStateFlow(null)
43+
override val arcGISMap: StateFlow<ArcGISMap?> = _arcGISMap.asStateFlow()
44+
45+
override fun setArcGISMap(arcGISMap: ArcGISMap){
46+
_arcGISMap.value = arcGISMap
47+
}
48+
49+
init {
50+
_arcGISMap.value = arcGISMap
51+
}
52+
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*
2-
*
32
* Copyright 2023 Esri
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)