private async void MapView_Tapped(object sender, GeoViewInputEventArgs e) { try { // Create the feature. ArcGISFeature feature = (ArcGISFeature)_damageFeatureTable.CreateFeature(); // Get the normalized geometry for the tapped location and use it as the feature's geometry. MapPoint tappedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location); feature.Geometry = tappedPoint; // Set feature attributes. feature.SetAttributeValue("typdamage", "Minor"); feature.SetAttributeValue("primcause", "Earthquake"); // Add the feature to the table. await _damageFeatureTable.AddFeatureAsync(feature); // Apply the edits to the service. await _damageFeatureTable.ApplyEditsAsync(); // Update the feature to get the updated objectid - a temporary ID is used before the feature is added. feature.Refresh(); // Confirm feature addition. MessageBox.Show("Created feature " + feature.Attributes["objectid"], "Success!"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error adding feature"); } }
private async void UpdateDamageType(string selectedAttributeValue) { try { // Load the feature. await _selectedFeature.LoadAsync(); // Update the attribute value. _selectedFeature.SetAttributeValue(AttributeFieldName, selectedAttributeValue); // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. ServiceFeatureTable table = (ServiceFeatureTable)_selectedFeature.FeatureTable; await table.ApplyEditsAsync(); ShowMessage("Success!", $"Edited feature {_selectedFeature.Attributes["objectid"]}"); } catch (Exception ex) { ShowMessage("Failed to edit feature", ex.ToString()); } finally { // Clear the selection. _damageLayer.ClearSelection(); _selectedFeature = null; // Dismiss any callout. _myMapView.DismissCallout(); } }
private async void DamageBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { try { // Get the new value. string selectedAttributeValue = DamageBox.SelectedValue.ToString(); // Load the feature. await _selectedFeature.LoadAsync(); // Update the attribute value. _selectedFeature.SetAttributeValue(_attributeFieldName, selectedAttributeValue); // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. await((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync(); AttributePicker.Visibility = Visibility.Collapsed; ShowAlert("Edited feature " + _selectedFeature.Attributes["objectid"]); // Clear the selection. _featureLayer.ClearSelection(); _selectedFeature = null; } catch (Exception ex) { ShowAlert(ex.Message, "Failed to edit feature"); } }
private async void DamageType_Changed(object sender, SelectionChangedEventArgs e) { // Skip if nothing is selected. if (DamageTypeDropDown.SelectedIndex == -1) { return; } try { // Get the new value. string selectedAttributeValue = DamageTypeDropDown.SelectedValue.ToString(); // Load the feature. await _selectedFeature.LoadAsync(); // Update the attribute value. _selectedFeature.SetAttributeValue(AttributeFieldName, selectedAttributeValue); // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. ServiceFeatureTable table = (ServiceFeatureTable)_selectedFeature.FeatureTable; await table.ApplyEditsAsync(); MessageBox.Show("Edited feature " + _selectedFeature.Attributes["objectid"], "Success!"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Failed to edit feature"); } finally { // Clear the selection. _damageLayer.ClearSelection(); _selectedFeature = null; // Update the UI. DamageTypeDropDown.IsEnabled = false; DamageTypeDropDown.SelectedIndex = -1; } }
private async void DamageType_Changed(object sender, EventArgs e) { // Skip if nothing is selected. if (DamageTypePicker.SelectedIndex == -1) { return; } try { // Get the new value. string selectedAttributeValue = DamageTypePicker.SelectedItem.ToString(); // Load the feature. await _selectedFeature.LoadAsync(); // Update the attribute value. _selectedFeature.SetAttributeValue(AttributeFieldName, selectedAttributeValue); // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. ServiceFeatureTable table = (ServiceFeatureTable)_selectedFeature.FeatureTable; await table.ApplyEditsAsync(); await Application.Current.MainPage.DisplayAlert("Success!", $"Edited feature {_selectedFeature.Attributes["objectid"]}", "OK"); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Failed to edit feature", ex.ToString(), "OK"); } finally { // Clear the selection. _damageLayer.ClearSelection(); _selectedFeature = null; // Update the UI. DamageTypePicker.IsEnabled = false; DamageTypePicker.SelectedIndex = -1; } }
private async Task ApplyDamageChange() { try { // Get the value from the UI. string selectedAttributeValue = DamageBox.SelectedItem.ToString(); // Check if the new value is the same as the existing value. if (_selectedFeature.Attributes[_attributeFieldName].ToString() == selectedAttributeValue) { return; } // Load the feature. await _selectedFeature.LoadAsync(); // Update the attribute value. _selectedFeature.SetAttributeValue(_attributeFieldName, selectedAttributeValue); // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. await((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync(); SwitchView(DefaultView); ShowAlert("Edited feature " + _selectedFeature.Attributes["objectid"]); // Clear the selection. _featureLayer.ClearSelection(); _selectedFeature = null; } catch (Exception ex) { ShowAlert(ex.Message, "Failed to edit feature"); } }