private async void GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { try { // Disregard if not ready for edits. if (_readyForEdits == EditState.NotReady) { return; } // If an edit is in process, finish it. if (_readyForEdits == EditState.Editing) { // Hold a list of any selected features. List <Feature> selectedFeatures = new List <Feature>(); // Get all selected features then clear selection. foreach (FeatureLayer layer in MyMapView.Map.OperationalLayers) { // Get the selected features. FeatureQueryResult layerFeatures = await layer.GetSelectedFeaturesAsync(); // FeatureQueryResult implements IEnumerable, so it can be treated as a collection of features. selectedFeatures.AddRange(layerFeatures); // Clear the selection. layer.ClearSelection(); } // Update all selected feature geometry. foreach (Feature feature in selectedFeatures) { // Get a reference to the correct feature table for the feature. GeodatabaseFeatureTable table = (GeodatabaseFeatureTable)feature.FeatureTable; // Ensure the geometry type of the table is point. if (table.GeometryType != GeometryType.Point) { continue; } // Set the new geometry. feature.Geometry = e.Location; try { // Update the feature in the table. await table.UpdateFeatureAsync(feature); } catch (Esri.ArcGISRuntime.ArcGISException) { ShowStatusMessage("Feature must be within extent of geodatabase."); } } // Update the edit state. _readyForEdits = EditState.Ready; // Enable the sync button. SyncButton.IsEnabled = true; // Update the help label. MyHelpLabel.Text = "4. Click 'Sync' or edit more features"; } // Otherwise, start an edit. else { // Define a tolerance for use with identifying the feature. double tolerance = 15 * MyMapView.UnitsPerPixel; // Define the selection envelope. Envelope selectionEnvelope = new Envelope(e.Location.X - tolerance, e.Location.Y - tolerance, e.Location.X + tolerance, e.Location.Y + tolerance); // Define query parameters for feature selection. QueryParameters query = new QueryParameters() { Geometry = selectionEnvelope }; // Track whether any selections were made. bool selectedFeature = false; // Select the feature in all applicable tables. foreach (FeatureLayer layer in MyMapView.Map.OperationalLayers) { FeatureQueryResult res = await layer.SelectFeaturesAsync(query, SelectionMode.New); selectedFeature = selectedFeature || res.Any(); } // Only update state if a feature was selected. if (selectedFeature) { // Set the edit state. _readyForEdits = EditState.Editing; // Update the help label. MyHelpLabel.Text = "3. Tap on the map to move the point"; } } } catch (Exception ex) { ShowStatusMessage(ex.ToString()); } }
private async void GeoViewTapped(object sender, GeoViewInputEventArgs e) { try { // Disregard if not ready for edits. if (_readyForEdits == EditState.NotReady) { return; } // If an edit is in process, finish it. if (_readyForEdits == EditState.Editing) { // Hold a list of any selected features. List <Feature> selectedFeatures = new List <Feature>(); // Get all selected features then clear selection. foreach (FeatureLayer layer in myMapView.Map.OperationalLayers) { // Get the selected features. FeatureQueryResult layerFeatures = await layer.GetSelectedFeaturesAsync(); // FeatureQueryResult implements IEnumerable, so it can be treated as a collection of features. selectedFeatures.AddRange(layerFeatures); // Clear the selection. layer.ClearSelection(); } // Update all selected features' geometry. foreach (Feature feature in selectedFeatures) { // Get a reference to the correct feature table for the feature. GeodatabaseFeatureTable table = (GeodatabaseFeatureTable)feature.FeatureTable; // Ensure the geometry type of the table is point. if (table.GeometryType != GeometryType.Point) { continue; } // Set the new geometry. feature.Geometry = e.Location; // Update the feature in the table. await table.UpdateFeatureAsync(feature); } // Update the edit state. _readyForEdits = EditState.Ready; // Enable the sync button. mySyncButton.IsEnabled = true; // Update the help label. MyHelpLabel.Text = "4. Click 'Synchronize' or keep editing"; } // Otherwise, start an edit. else { // Define a tolerance for use with identifying the feature. double tolerance = 15 * myMapView.UnitsPerPixel; // Define the selection envelope. Envelope selectionEnvelope = new Envelope(e.Location.X - tolerance, e.Location.Y - tolerance, e.Location.X + tolerance, e.Location.Y + tolerance); // Define query parameters for feature selection. QueryParameters query = new QueryParameters() { Geometry = selectionEnvelope }; // Select the feature in all applicable tables. foreach (FeatureLayer layer in myMapView.Map.OperationalLayers) { await layer.SelectFeaturesAsync(query, SelectionMode.New); } // Set the edit state. _readyForEdits = EditState.Editing; // Update the help label. MyHelpLabel.Text = "3. Tap on the map to move the point"; } } catch (Exception ex) { await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK"); } }
private async void GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Disregard if not ready for edits if (_readyForEdits == EditState.NotReady) { return; } // If an edit is in process, finish it if (_readyForEdits == EditState.Editing) { // Hold a list of any selected features List <Feature> selectedFeatures = new List <Feature>(); // Get all selected features then clear selection foreach (FeatureLayer layer in myMapView.Map.OperationalLayers) { // Get the selected features FeatureQueryResult layerFeatures = await layer.GetSelectedFeaturesAsync(); // FeatureQueryResult implements IEnumerable, so it can be treated as a collection of features selectedFeatures.AddRange(layerFeatures); // Clear the selection layer.ClearSelection(); } // Update all selected features' geometry foreach (Feature feature in selectedFeatures) { // Get a reference to the correct feature table for the feature GeodatabaseFeatureTable table = feature.FeatureTable as GeodatabaseFeatureTable; // Ensure the geometry type of the table is point if (table.GeometryType != GeometryType.Point) { continue; } // Set the new geometry feature.Geometry = e.Location; // Update the feature in the table await table.UpdateFeatureAsync(feature); } // Update the edit state _readyForEdits = EditState.Ready; // Enable the sync button mySyncButton.Enabled = true; } // Otherwise, start an edit else { // Define a tolerance for use with identifying the feature double tolerance = 15 * myMapView.UnitsPerPixel; // Define the selection envelope Envelope selectionEnvelope = new Envelope(e.Location.X - tolerance, e.Location.Y - tolerance, e.Location.X + tolerance, e.Location.Y + tolerance); // Define query parameters for feature selection QueryParameters query = new QueryParameters() { Geometry = selectionEnvelope }; // Select the feature in all applicable tables foreach (FeatureLayer layer in myMapView.Map.OperationalLayers) { await layer.SelectFeaturesAsync(query, SelectionMode.New); } // Set the edit state _readyForEdits = EditState.Editing; } }