@@ -3,144 +3,49 @@ package com.what3words.samples.googlemaps.compose
3
3
import android.os.Bundle
4
4
import androidx.activity.ComponentActivity
5
5
import androidx.activity.compose.setContent
6
- import androidx.compose.foundation.layout.Box
7
- import androidx.compose.foundation.layout.fillMaxSize
8
- import androidx.compose.runtime.Composable
9
- import androidx.compose.runtime.DisposableEffect
10
- import androidx.compose.runtime.LaunchedEffect
11
- import androidx.compose.runtime.remember
12
- import androidx.compose.ui.Modifier
13
- import androidx.compose.ui.graphics.Color
14
- import androidx.compose.ui.platform.LocalContext
6
+ import androidx.activity.viewModels
7
+ import androidx.navigation.compose.NavHost
8
+ import androidx.navigation.compose.composable
9
+ import androidx.navigation.compose.rememberNavController
15
10
import com.what3words.androidwrapper.datasource.text.W3WApiTextDataSource
16
- import com.what3words.components.compose.maps.MapProvider
17
- import com.what3words.components.compose.maps.W3WMapComponent
18
- import com.what3words.components.compose.maps.W3WMapDefaults
19
- import com.what3words.components.compose.maps.models.W3WMarkerColor
20
- import com.what3words.components.compose.maps.rememberW3WMapManager
21
- import com.what3words.core.datasource.text.W3WTextDataSource
22
- import com.what3words.core.types.geometry.W3WCoordinates
23
11
import com.what3words.design.library.ui.theme.W3WTheme
24
12
import com.what3words.samples.googlemaps.BuildConfig
25
-
26
- val london1Coordinate = W3WCoordinates (51.513678 , - 0.133823 )
27
- val london2Coordinate = W3WCoordinates (51.494947 , - 0.093923 )
28
- val london3Coordinate = W3WCoordinates (51.473062 , - 0.142303 )
29
- val london4Coordinate = W3WCoordinates (51.472335 , - 0.183234 )
30
- val london5Coordinate = W3WCoordinates (51.471445 , - 0.239064 )
31
- const val london1W3WAddress = " verbs.stacks.ranked"
32
- const val london2W3WAddress = " alarm.cargo.bills"
33
- const val london3W3WAddress = " gold.basin.freed"
34
- const val london4W3WAddress = " known.format.adults"
35
- const val london5W3WAddress = " piles.hedge.logo"
13
+ import com.what3words.samples.googlemaps.compose.ui.home.HomeScreen
14
+ import com.what3words.samples.googlemaps.compose.ui.overlaymap.ExistingMapWithDrawerScreen
15
+ import com.what3words.samples.googlemaps.compose.ui.standalone.W3WMapComponentScreen
36
16
37
17
class MapComposeActivity : ComponentActivity () {
38
18
39
19
override fun onCreate (savedInstanceState : Bundle ? ) {
40
20
super .onCreate(savedInstanceState)
41
21
22
+ val viewModel: MapViewModel by viewModels {
23
+ MapViewModelFactory (
24
+ textDataSource = W3WApiTextDataSource .create(this , BuildConfig .W3W_API_KEY )
25
+ )
26
+ }
27
+
42
28
setContent {
43
29
W3WTheme {
44
- W3WMapComponentApp (
45
- textDataSource = W3WApiTextDataSource .create(this , BuildConfig .W3W_API_KEY )
46
- )
30
+ val navController = rememberNavController()
31
+
32
+ NavHost (navController = navController, startDestination = " home" ) {
33
+ composable(" home" ) {
34
+ HomeScreen (navController)
35
+ }
36
+ composable(" first" ) {
37
+ W3WMapComponentScreen (
38
+ textDataSource = viewModel.w3WTextDataSource
39
+ )
40
+ }
41
+ composable(" second" ) {
42
+ ExistingMapWithDrawerScreen (
43
+ textDataSource = viewModel.w3WTextDataSource
44
+ )
45
+ }
46
+ }
47
47
}
48
48
}
49
49
}
50
50
}
51
51
52
- @Composable
53
- fun W3WMapComponentApp (
54
- modifier : Modifier = Modifier ,
55
- textDataSource : W3WTextDataSource
56
- ) {
57
-
58
- val context = LocalContext .current
59
-
60
- val mapManager = rememberW3WMapManager(
61
- mapProvider = MapProvider .GOOGLE_MAP
62
- )
63
-
64
- val locationSource = remember {
65
- LocationSourceImpl (context)
66
- }
67
-
68
- // Move the camera to a specific coordinate
69
- LaunchedEffect (Unit ) {
70
- mapManager.moveToPosition(london1Coordinate)
71
- }
72
-
73
- // Add a marker at a specific coordinate
74
- LaunchedEffect (Unit ) {
75
- mapManager.addMarkerAt(
76
- coordinates = london2Coordinate,
77
- markerColor = W3WMarkerColor (background = Color .Red , slash = Color .Yellow )
78
- )
79
- }
80
-
81
- // Add a list of marker at specific coordinates
82
- LaunchedEffect (Unit ) {
83
- mapManager.addMarkersAt(
84
- listCoordinates = listOf (
85
- london3Coordinate,
86
- london4Coordinate,
87
- london5Coordinate
88
- ),
89
- listName = " London" ,
90
- markerColor = W3WMarkerColor (background = Color .Yellow , slash = Color .Red )
91
- )
92
- }
93
-
94
- // Select a specific address on the map
95
- LaunchedEffect (Unit ) {
96
- mapManager.setSelectedAt(london1W3WAddress)
97
- }
98
-
99
- // Add a marker at a specific what3words address
100
- LaunchedEffect (Unit ) {
101
- mapManager.addMarkerAt(
102
- words = london2W3WAddress,
103
- markerColor = W3WMarkerColor (background = Color .Black , slash = Color .Yellow )
104
- )
105
- }
106
-
107
- // Add a list of marker at specific coordinates
108
- LaunchedEffect (Unit ) {
109
- mapManager.addMarkersAt(
110
- listWords = listOf (
111
- london3W3WAddress,
112
- london4W3WAddress,
113
- london5W3WAddress
114
- ),
115
- listName = " London 2" ,
116
- markerColor = W3WMarkerColor (background = Color .Blue , slash = Color .White )
117
- )
118
- }
119
-
120
- DisposableEffect (Unit ) {
121
- onDispose {
122
- locationSource.onDestroy()
123
- }
124
- }
125
-
126
- Box (
127
- modifier = modifier.fillMaxSize()
128
- ) {
129
- W3WMapComponent (
130
- textDataSource = textDataSource,
131
- modifier = Modifier .fillMaxSize(),
132
- locationSource = locationSource,
133
- mapConfig = W3WMapDefaults .defaultMapConfig(
134
- buttonConfig = W3WMapDefaults .ButtonConfig (
135
- isRecallFeatureEnabled = true ,
136
- isMapSwitchFeatureEnabled = true ,
137
- isMyLocationFeatureEnabled = true
138
- )
139
- ),
140
- mapManager = mapManager,
141
- onSelectedSquareChanged = {
142
- // Handle the selected square
143
- }
144
- )
145
- }
146
- }
0 commit comments