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

Revisit query feature table sample #181

Merged
merged 2 commits into from
Mar 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
import com.arcgismaps.mapping.symbology.SimpleLineSymbol
import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
import com.arcgismaps.mapping.symbology.SimpleRenderer
import com.arcgismaps.toolkit.geocompose.MapViewpointOperation
import com.arcgismaps.toolkit.geocompose.MapViewProxy
import com.esri.arcgismaps.sample.queryfeaturetable.R
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import java.util.Locale

class MapViewModel(
private val application: Application,
application: Application,
private val sampleCoroutineScope: CoroutineScope
) : AndroidViewModel(application) {

Expand All @@ -69,8 +69,8 @@ class MapViewModel(
scale = 1e8
)

// define a mutable MapViewpointOperation and set the initial viewpoint
var mapViewpointOperation: MapViewpointOperation by mutableStateOf(MapViewpointOperation.Set(usaViewpoint))
// create a MapViewProxy to handle MapView operations
var mapViewProxy by mutableStateOf(MapViewProxy())

init {
// use symbols to show U.S. states with a black outline and yellow fill
Expand All @@ -93,7 +93,10 @@ class MapViewModel(
maxScale = 10000.0
}
// add the feature layer to the map's operational layers
map.operationalLayers.add(featureLayer)
map.apply {
initialViewpoint = usaViewpoint
operationalLayers.add(featureLayer)
}
}

/**
Expand Down Expand Up @@ -122,8 +125,8 @@ class MapViewModel(
// get the extent of the first feature in the result to zoom to
val envelope = feature.geometry?.extent
?: return@launch messageDialogVM.showMessageDialog("Error retrieving geometry extent")
// update the viewpoint to the bounding geometry of the returned feature
mapViewpointOperation = MapViewpointOperation.SetBoundingGeometry(envelope)
// update the map's viewpoint to the feature's geometry
mapViewProxy.setViewpointGeometry(envelope)
} else {
messageDialogVM.showMessageDialog("No states found with name: $searchQuery")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun MainScreen(sampleName: String) {
.fillMaxWidth()
.weight(1f),
arcGISMap = mapViewModel.map,
viewpointOperation = mapViewModel.mapViewpointOperation
mapViewProxy = mapViewModel.mapViewProxy
)
SearchBar(
modifier = Modifier.fillMaxWidth(),
Expand Down
Loading