Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample - add dynamic entity sample #161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion add-dynamic-entity-layer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ This sample uses a [stream service](https://realtimegis2016.esri.com:6443/arcgis

## Additional information

This sample uses the GeoCompose Toolkit module to be able to implement a Composable MapView.
More information about dynamic entities can be found in the [guide documentation](https://developers.arcgis.com/kotlin/real-time/work-with-dynamic-entities/).

## Tags

data, dynamic, entity, live, purge, real-time, service, stream, track
data, dynamic, entity, geocompose, live, purge, real-time, service, stream, toolkit, track
3 changes: 2 additions & 1 deletion add-dynamic-entity-layer/README.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"data",
"dynamic",
"entity",
"geocompose",
"live",
"purge",
"real-time",
"service",
"stream",
"toolkit",
"track",
"ArcGISStreamService",
"DynamicEntity",
Expand All @@ -36,7 +38,6 @@
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/adddynamicentitylayer/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/adddynamicentitylayer/components/BottomSheetContent.kt",
"src/main/java/com/esri/arcgismaps/sample/adddynamicentitylayer/components/ComposeMapView.kt",
"src/main/java/com/esri/arcgismaps/sample/adddynamicentitylayer/components/MapViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/adddynamicentitylayer/screens/MainScreen.kt"
],
Expand Down
3 changes: 3 additions & 0 deletions add-dynamic-entity-layer/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 @@ -47,8 +47,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 @@ -17,17 +17,16 @@
package com.esri.arcgismaps.sample.adddynamicentitylayer.components

import android.app.Application
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.AndroidViewModel
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.Viewpoint
import com.arcgismaps.mapping.layers.DynamicEntityLayer
import com.arcgismaps.realtime.ArcGISStreamService
import com.arcgismaps.realtime.ArcGISStreamServiceFilter
import com.esri.arcgismaps.sample.adddynamicentitylayer.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

class MapViewModel(
Expand All @@ -38,14 +37,11 @@ class MapViewModel(
// set the state of the switches and slider
val trackLineCheckedState = mutableStateOf(false)
val prevObservationCheckedState = mutableStateOf(false)
val trackSliderValue = mutableStateOf(5f)
val trackSliderValue = mutableFloatStateOf(5f)

// flag to show or dismiss the bottom sheet
val isBottomSheetVisible = mutableStateOf(false)

// set the MapView mutable stateflow
val mapViewState = MutableStateFlow(MapViewState())

// create ArcGIS Stream Service
private val streamService =
ArcGISStreamService(application.getString(R.string.stream_service_url))
Expand All @@ -56,6 +52,9 @@ class MapViewModel(
// layer displaying the dynamic entities on the map
private val dynamicEntityLayer: DynamicEntityLayer

// define ArcGIS map using Streets basemap
val map = ArcGISMap(BasemapStyle.ArcGISStreets)

/**
* set the data source for the dynamic entity layer.
*/
Expand All @@ -70,7 +69,7 @@ class MapViewModel(
dynamicEntityLayer = DynamicEntityLayer(streamService)

// add the dynamic entity layer to the map's operational layers
mapViewState.value.arcGISMap.operationalLayers.add(dynamicEntityLayer)
map.operationalLayers.add(dynamicEntityLayer)
}

// disconnects the stream service
Expand Down Expand Up @@ -125,10 +124,3 @@ class MapViewModel(
}
}

/**
* Data class that represents the MapView state
*/
data class MapViewState(
var arcGISMap: ArcGISMap = ArcGISMap(BasemapStyle.ArcGISStreets),
var viewpoint: Viewpoint = Viewpoint(40.559691, -111.869001, 150000.0)
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.esri.arcgismaps.sample.adddynamicentitylayer.components.ComposeMapView
import com.arcgismaps.mapping.Viewpoint
import com.arcgismaps.toolkit.geocompose.MapView
import com.arcgismaps.toolkit.geocompose.MapViewpointOperation
import com.esri.arcgismaps.sample.adddynamicentitylayer.components.DynamicEntityLayerProperties
import com.esri.arcgismaps.sample.adddynamicentitylayer.components.MapViewModel
import com.esri.arcgismaps.sample.sampleslib.components.BottomSheet
Expand All @@ -45,9 +48,11 @@ import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
* 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 context
val application = LocalContext.current.applicationContext as Application

// create a ViewModel to handle MapView interactions
val mapViewModel = remember { MapViewModel(application, sampleCoroutineScope) }
Expand All @@ -64,11 +69,14 @@ fun MainScreen(sampleName: String, application: Application) {
.padding(it)
) {
// composable function that wraps the MapView
ComposeMapView(
MapView(
modifier = Modifier
.fillMaxSize()
.weight(1f),
mapViewModel = mapViewModel
arcGISMap = mapViewModel.map,
viewpointOperation = MapViewpointOperation.Set(viewpoint = Viewpoint(40.559691, -111.869001, 150000.0)),
onSingleTapConfirmed = { mapViewModel.dismissBottomSheet() },
onPan = { mapViewModel.dismissBottomSheet() }
)
Row(
modifier = Modifier
Expand Down
Loading