@@ -100,7 +100,12 @@ class MapViewModel @Inject constructor(
100
100
entry.value.forEach { error ->
101
101
featureForm.getFormElement(entry.key)?.let { formElement ->
102
102
if (formElement.isEditable.value) {
103
- errors.add(ErrorInfo (formElement.label, error as FeatureFormValidationException ))
103
+ errors.add(
104
+ ErrorInfo (
105
+ formElement.label,
106
+ error as FeatureFormValidationException
107
+ )
108
+ )
104
109
}
105
110
}
106
111
}
@@ -121,7 +126,8 @@ class MapViewModel @Inject constructor(
121
126
serviceFeatureTable.serviceGeodatabase?.applyEdits()
122
127
? : throw IllegalStateException (" cannot apply feature edit without a ServiceGeodatabase" )
123
128
feature.refresh()
124
- Unit
129
+ // unselect the feature after the edits have been saved
130
+ (feature.featureTable?.layer as FeatureLayer ).clearSelection()
125
131
}
126
132
// set the state to not editing since the feature was updated successfully
127
133
_uiState .value = UIState .NotEditing
@@ -153,6 +159,8 @@ class MapViewModel @Inject constructor(
153
159
fun rollbackEdits (): Result <Unit > {
154
160
(_uiState .value as ? UIState .Editing )?.let {
155
161
it.featureForm.discardEdits()
162
+ // unselect the feature
163
+ (it.featureForm.feature.featureTable?.layer as FeatureLayer ).clearSelection()
156
164
_uiState .value = UIState .NotEditing
157
165
return Result .success(Unit )
158
166
} ? : return Result .failure(IllegalStateException (" Not in editing state" ))
@@ -167,41 +175,30 @@ class MapViewModel @Inject constructor(
167
175
tolerance = 22.0 ,
168
176
returnPopupsOnly = false
169
177
).onSuccess { results ->
170
- results.firstNotNullOfOrNull { result ->
171
- try {
172
- result.geoElements.filterIsInstance<ArcGISFeature >()
173
- .firstOrNull { feature ->
174
- (feature.featureTable?.layer as ? FeatureLayer )?.featureFormDefinition != null
175
- }
176
- } catch (e: Exception ) {
177
- e.printStackTrace()
178
- Toast .makeText(
179
- context,
180
- " failed to load the FeatureFormDefinition for the feature" ,
181
- Toast .LENGTH_LONG
182
- ).show()
183
- null
184
- }
185
- }?.let { feature ->
186
- feature.load().onSuccess {
187
- try {
188
- val featureForm = FeatureForm (
189
- feature,
190
- (feature.featureTable?.layer as FeatureLayer ).featureFormDefinition!!
191
- )
192
- // set the UI to an editing state and set the FeatureForm
178
+ try {
179
+ results.forEach { result ->
180
+ result.geoElements.firstOrNull {
181
+ it is ArcGISFeature && (it.featureTable?.layer as ? FeatureLayer )?.featureFormDefinition != null
182
+ }?.let {
183
+ val feature = it as ArcGISFeature
184
+ val layer = feature.featureTable!! .layer as FeatureLayer
185
+ val featureForm =
186
+ FeatureForm (feature, layer.featureFormDefinition!! )
187
+ // select the feature
188
+ layer.selectFeature(feature)
189
+ // set the UI to an editing state with the FeatureForm
193
190
_uiState .value = UIState .Editing (featureForm)
194
- } catch (e: Exception ) {
195
- e.printStackTrace() // for debugging core issues
196
- Toast .makeText(
197
- context,
198
- " failed to create a FeatureForm for the feature and layer" ,
199
- Toast .LENGTH_LONG
200
- ).show()
201
191
}
202
- }.onFailure { println (" failed to load tapped Feature" ) }
203
- } ? : println (" identified features do not have feature forms defined" )
204
- }.onFailure { println (" tap was not on a feature" ) }
192
+ }
193
+ } catch (e: Exception ) {
194
+ e.printStackTrace()
195
+ Toast .makeText(
196
+ context,
197
+ " failed to create a FeatureForm for the feature" ,
198
+ Toast .LENGTH_LONG
199
+ ).show()
200
+ }
201
+ }
205
202
}
206
203
}
207
204
}
0 commit comments