Skip to content

Commit

Permalink
update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiqima committed Dec 20, 2023
1 parent cd958b4 commit 13ff83b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 120 deletions.
3 changes: 2 additions & 1 deletion identify-layer-features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ Tap to identify features. A bottom text banner will show all layers with feature

## Additional information

This sample uses the GeoCompose Toolkit module to be able to implement a Composable MapView.
The GeoView supports two methods of identify: `identifyLayer`, which identifies features within a specific layer and `identifyLayers`, which identifies features for all layers in the current view.

## Tags

identify, recursion, recursive, sublayers
identify, geocompose, recursion, recursive, sublayers, toolkit
3 changes: 2 additions & 1 deletion identify-layer-features/README.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
],
"keywords": [
"identify",
"geocompose",
"recursion",
"recursive",
"sublayers",
"toolkit",
"IdentifyLayerResult",
"IdentifyLayerResult.sublayerResults",
"LayerContent"
Expand All @@ -24,7 +26,6 @@
],
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/identifylayerfeatures/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/identifylayerfeatures/components/ComposeMapView.kt",
"src/main/java/com/esri/arcgismaps/sample/identifylayerfeatures/components/MapViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/identifylayerfeatures/screens/MainScreen.kt"
],
Expand Down
3 changes: 3 additions & 0 deletions identify-layer-features/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation project(path: ':samples-lib')
// Toolkit dependencies
implementation(platform("com.esri:arcgis-maps-kotlin-toolkit-bom:$arcgisToolkitVersion"))
implementation('com.esri:arcgis-maps-kotlin-toolkit-geo-compose')
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class MainActivity : ComponentActivity() {
color = MaterialTheme.colorScheme.background
) {
MainScreen(
sampleName = getString(R.string.app_name),
application = application
sampleName = getString(R.string.app_name)
)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ import com.arcgismaps.mapping.view.IdentifyLayerResult
import com.esri.arcgismaps.sample.identifylayerfeatures.R
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

class MapViewModel(
application: Application,
private val sampleCoroutineScope: CoroutineScope
) : AndroidViewModel(application) {
// set the MapView mutable stateflow
val mapViewState = MutableStateFlow(MapViewState())

// create an ArcGISMap and Viewpoint
var arcGISMap: ArcGISMap = ArcGISMap(BasemapStyle.ArcGISNavigationNight)
var viewpoint: Viewpoint = Viewpoint(
center = Point(
x = -10977012.785807,
y = 4514257.550369,
spatialReference = SpatialReference(wkid = 3857)
),
scale = 68015210.0
)

// create a ViewModel to handle dialog interactions
val messageDialogVM: MessageDialogViewModel = MessageDialogViewModel()
Expand Down Expand Up @@ -74,7 +82,7 @@ class MapViewModel(
operationalLayers.add(featureLayer)
}
// assign the map to the map view
mapViewState.value.arcGISMap = map
arcGISMap = map
}

/**
Expand Down Expand Up @@ -129,19 +137,4 @@ class MapViewModel(
}
return subLayerGeoElementCount + result.geoElements.size
}
}

/**
* Data class that represents the MapView state
*/
data class MapViewState(
var arcGISMap: ArcGISMap = ArcGISMap(BasemapStyle.ArcGISNavigationNight),
var viewpoint: Viewpoint = Viewpoint(
center = Point(
x = -10977012.785807,
y = 4514257.550369,
spatialReference = SpatialReference(wkid = 3857)
),
scale = 68015210.0
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,30 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.esri.arcgismaps.sample.identifylayerfeatures.components.ComposeMapView
import com.arcgismaps.toolkit.geocompose.MapView
import com.arcgismaps.toolkit.geocompose.MapViewProxy
import com.arcgismaps.toolkit.geocompose.MapViewpointOperation
import com.esri.arcgismaps.sample.identifylayerfeatures.components.MapViewModel
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialog
import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
import kotlinx.coroutines.launch

/**
* Main screen layout for the sample app
*/
@Composable
fun MainScreen(sampleName: String, application: Application) {
fun MainScreen(sampleName: String) {
// coroutineScope that will be cancelled when this call leaves the composition
val sampleCoroutineScope = rememberCoroutineScope()
// get the application property that will be used to construct MapViewModel
val sampleApplication = LocalContext.current.applicationContext as Application
// create a ViewModel to handle MapView interactions
val mapViewModel = remember { MapViewModel(application, sampleCoroutineScope) }
val mapViewModel = remember { MapViewModel(sampleApplication, sampleCoroutineScope) }
// create a mapViewProxy that will be used to identify features in the MapView
// should also be passed to the MapView composable this mapViewProxy is associated with
val mapViewProxy = MapViewProxy()

Scaffold(
topBar = { SampleTopAppBar(title = sampleName) },
Expand All @@ -53,13 +62,24 @@ fun MainScreen(sampleName: String, application: Application) {
.fillMaxSize()
.padding(it)
) {
// composable function that wraps the MapView
ComposeMapView(
MapView(
modifier = Modifier
.fillMaxSize()
.weight(1f)
.animateContentSize(),
mapViewModel = mapViewModel
arcGISMap = mapViewModel.arcGISMap,
viewpointOperation = MapViewpointOperation.Set(viewpoint = mapViewModel.viewpoint),
mapViewProxy = mapViewProxy,
onSingleTapConfirmed = { singleTapConfirmedEvent ->
sampleCoroutineScope.launch {
val identifyResult = mapViewProxy.identifyLayers(
screenCoordinate = singleTapConfirmedEvent.screenCoordinate,
tolerance = 12.dp,
maximumResults = 10
)
mapViewModel.handleIdentifyResult(identifyResult)
}
}
)
// Bottom text to display the identify results
Row(
Expand Down
2 changes: 1 addition & 1 deletion version.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {
// ArcGIS Maps SDK for Kotlin version
arcgisVersion = '200.4.0-4085'
// ArcGIS Maps SDK for Kotlin Toolkit version
arcgisToolkitVersion = '200.3.0-1'
arcgisToolkitVersion = '200.4.0-1'
// SDK versions
compileSdkVersion = 34
minSdkVersion = 26
Expand Down

0 comments on commit 13ff83b

Please sign in to comment.