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(); await new MessageDialog($"Edited feature {_selectedFeature.Attributes["objectid"]}", "Success!").ShowAsync(); } catch (Exception ex) { await new MessageDialog(ex.ToString(), "Failed to edit feature.").ShowAsync(); } 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 void SetYTY() { await ArcGISFeature.LoadAsync(); IReadOnlyList <Attachment> attachments = await ArcGISFeature.GetAttachmentsAsync(); foreach (Attachment attachment in attachments) { if (attachment.Name.Equals(ArcGisService.YTY_FILE_NAME)) { Stream jsonStream = await attachment.GetDataAsync(); StreamReader streamReader = new StreamReader(jsonStream); string jsonString = streamReader.ReadToEnd(); Binstance.YTYDatas.Clear(); Binstance.YTYDatas.AddRange((List <YTYData>)JsonConvert.DeserializeObject <IEnumerable <YTYData> >(jsonString)); break; } } }
private async void UpdateDamageType(string selectedAttributeValue) { try { // Load the feature. await _selectedFeature.LoadAsync(); if (_selectedFeature.Attributes[AttributeFieldName].ToString() == selectedAttributeValue) { throw new Exception("Old and new attribute values are the same."); } // 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.Message); } finally { // Clear the selection. _damageLayer.ClearSelection(); _selectedFeature = null; // Dismiss any callout. _myMapView.DismissCallout(); } }
private async void MoveSelectedFeature(Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs tapEventDetails) { try { // Get the MapPoint from the EventArgs for the tap. MapPoint destinationPoint = tapEventDetails.Location; // Normalize the point - needed when the tapped location is over the international date line. destinationPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(destinationPoint); // Load the feature. await _selectedFeature.LoadAsync(); // Update the geometry of the selected feature. _selectedFeature.Geometry = destinationPoint; // Apply the edit to the feature table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Push the update to the service. ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable; await serviceTable.ApplyEditsAsync(); await Application.Current.MainPage.DisplayAlert("Success!", $"Moved feature {_selectedFeature.Attributes["objectid"]}", "OK"); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error when moving feature", ex.ToString(), "OK"); } finally { // Reset the selection. _damageLayer.ClearSelection(); _selectedFeature = null; } }
private async void MoveSelectedFeature(GeoViewInputEventArgs tapEventDetails) { try { // Get the MapPoint from the EventArgs for the tap. MapPoint destinationPoint = tapEventDetails.Location; // Normalize the point - needed when the tapped location is over the international date line. destinationPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(destinationPoint); // Load the feature. await _selectedFeature.LoadAsync(); // Update the geometry of the selected feature. _selectedFeature.Geometry = destinationPoint; // Apply the edit to the feature table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Push the update to the service. ServiceFeatureTable serviceTable = (ServiceFeatureTable)_selectedFeature.FeatureTable; await serviceTable.ApplyEditsAsync(); MessageBox.Show("Moved feature " + _selectedFeature.Attributes["objectid"], "Success!"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error when moving feature."); } finally { // Reset the selection. _damageLayer.ClearSelection(); _selectedFeature = null; } }
// Handle a new selected comment record in the table view. private async void CommentsListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { // Clear selected features from the graphics overlay. _selectedFeaturesOverlay.Graphics.Clear(); // Get the selected comment feature. If there is no selection, return. ArcGISFeature selectedComment = e.AddedItems[0] as ArcGISFeature; if (selectedComment == null) { return; } // Get the map image layer that contains the service request sublayer and the service request comments table. ArcGISMapImageLayer serviceRequestsMapImageLayer = (ArcGISMapImageLayer)MyMapView.Map.OperationalLayers[0]; // Get the (non-spatial) table that contains the service request comments. ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0]; // Get the relationship that defines related service request features for features in the comments table (this is the first and only relationship). RelationshipInfo commentsRelationshipInfo = commentsTable.LayerInfo.RelationshipInfos.FirstOrDefault(); // Create query parameters to get the related service request for features in the comments table. RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo) { ReturnGeometry = true }; try { // Query the comments table to get the related service request feature for the selected comment. IReadOnlyList <RelatedFeatureQueryResult> relatedRequestsResult = await commentsTable.QueryRelatedFeaturesAsync(selectedComment, relatedQueryParams); // Get the first result. RelatedFeatureQueryResult result = relatedRequestsResult.FirstOrDefault(); // Get the first feature from the result. If it's null, warn the user and return. ArcGISFeature serviceRequestFeature = result.FirstOrDefault() as ArcGISFeature; if (serviceRequestFeature == null) { MessageBox.Show("Related feature not found.", "No Feature"); return; } // Load the related service request feature (so its geometry is available). await serviceRequestFeature.LoadAsync(); // Get the service request geometry (point). MapPoint serviceRequestPoint = serviceRequestFeature.Geometry as MapPoint; // Create a cyan marker symbol to display the related feature. Symbol selectedRequestSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Cyan, 14); // Create a graphic using the service request point and marker symbol. Graphic requestGraphic = new Graphic(serviceRequestPoint, selectedRequestSymbol); // Add the graphic to the graphics overlay and zoom the map view to its extent. _selectedFeaturesOverlay.Graphics.Add(requestGraphic); await MyMapView.SetViewpointCenterAsync(serviceRequestPoint, 150000); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } }
// When a comment is clicked, get the related feature (service request) and select it on the map. private async void CommentsListBox_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { // Clear selected features from the graphics overlay. _selectedFeaturesOverlay.Graphics.Clear(); // Get the clicked record (ArcGISFeature) using the list position. If one is not found, return. ArcGISFeature selectedComment = _commentFeatures[e.Position] as ArcGISFeature; if (selectedComment == null) { return; } // Get the map image layer that contains the service request sublayer and the service request comments table. ArcGISMapImageLayer serviceRequestsMapImageLayer = _myMapView.Map.OperationalLayers[0] as ArcGISMapImageLayer; // Get the (non-spatial) table that contains the service request comments. ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0]; // Get the relationship that defines related service request features to features in the comments table (this is the first and only relationship). RelationshipInfo commentsRelationshipInfo = commentsTable.LayerInfo.RelationshipInfos.FirstOrDefault(); // Create query parameters to get the related service request for features in the comments table. RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo) { ReturnGeometry = true }; // Query the comments table to get the related service request feature for the selected comment. IReadOnlyList <RelatedFeatureQueryResult> relatedRequestsResult = await commentsTable.QueryRelatedFeaturesAsync(selectedComment, relatedQueryParams); // Get the first result. RelatedFeatureQueryResult result = relatedRequestsResult.FirstOrDefault(); // Get the first feature from the result. If it's null, warn the user and return. ArcGISFeature serviceRequestFeature = result.FirstOrDefault() as ArcGISFeature; if (serviceRequestFeature == null) { // Report to the user that a related feature was not found, then return. AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); AlertDialog alert = alertBuilder.Create(); alert.SetMessage("Related feature not found."); alert.Show(); return; } // Load the related service request feature (so its geometry is available). await serviceRequestFeature.LoadAsync(); // Get the service request geometry (point). MapPoint serviceRequestPoint = serviceRequestFeature.Geometry as MapPoint; // Create a cyan marker symbol to display the related feature. Symbol selectedRequestSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Cyan, 14); // Create a graphic using the service request point and marker symbol. Graphic requestGraphic = new Graphic(serviceRequestPoint, selectedRequestSymbol); // Add the graphic to the graphics overlay and zoom the map view to its extent. _selectedFeaturesOverlay.Graphics.Add(requestGraphic); await _myMapView.SetViewpointCenterAsync(serviceRequestPoint, 150000); }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // Check if a feature is selected and the service geodatabase is not on the default version. if (_selectedFeature is ArcGISFeature && _serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName) { try { // Load the feature. await _selectedFeature.LoadAsync(); // Update the feature geometry. _selectedFeature.Geometry = e.Location; // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. await((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync(); ShowAlert("Moved feature " + _selectedFeature.Attributes["objectid"]); } catch (Exception ex) { ShowAlert(ex.Message, "Failed to edit feature"); } } else { try { // Perform an identify to determine if a user tapped on a feature. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_featureLayer, e.Position, 2, false); // Do nothing if there are no results. if (!identifyResult.GeoElements.Any()) { return; } // Get the tapped feature. _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First(); // Select the feature. _featureLayer.SelectFeature(_selectedFeature); // Get the current value. string currentAttributeValue = _selectedFeature.Attributes[_attributeFieldName].ToString(); // Update the combobox selection without triggering the event. DamageBox.SelectedItem = currentAttributeValue; MoveText.IsVisible = DamageBox.IsEnabled = _serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName; } catch (Exception ex) { ShowAlert(ex.Message, ex.GetType().Name); } finally { // Update the UI for the selection. SwitchView(AttributeView); } } }
private async void MapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Check if a feature is selected and the service geodatabase is not on the default version. if (_selectedFeature is ArcGISFeature && _serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName) { try { // Load the feature. await _selectedFeature.LoadAsync(); // Update the feature geometry. _selectedFeature.Geometry = e.Location; // Update the table. await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature); // Update the service. await((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync(); ShowAlert("Moved feature " + _selectedFeature.Attributes["objectid"]); } catch (Exception ex) { ShowAlert(ex.Message, "Failed to edit feature"); } } else { try { // Clear the selection. _featureLayer.ClearSelection(); _selectedFeature = null; // Perform an identify to determine if a user tapped on a feature. IdentifyLayerResult identifyResult = await _myMapView.IdentifyLayerAsync(_featureLayer, e.Position, 2, false); // Do nothing if there are no results. if (!identifyResult.GeoElements.Any()) { SwitchView(_defaultView); return; } // Get the tapped feature. _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First(); // Select the feature. _featureLayer.SelectFeature(_selectedFeature); // Get the current value. string currentAttributeValue = _selectedFeature.Attributes[_attributeFieldName].ToString(); // Update the damage button. _damageButton.SetTitle($"Damage: {currentAttributeValue}", UIControlState.Normal); _moveText.Hidden = _serviceGeodatabase.VersionName == _serviceGeodatabase.DefaultVersionName; _damageButton.Enabled = !_moveText.Hidden; // Update the UI for the selection. SwitchView(_damageView); } catch (Exception ex) { ShowAlert(ex.Message, ex.GetType().Name); } } }
public static async Task <ArcCrudEnum> EditBin(BinViewModel binViewModel) { IBinstance bin = binViewModel.Binstance; ArcGISFeature featureToEdit = binViewModel.ArcGISFeature; try { await featureToEdit.LoadAsync(); featureToEdit.Attributes["identifier"] = bin.Identifier; featureToEdit.Attributes["modified_by"] = binViewModel.EmpoyeeNumber; switch (bin.BinType) { case BinTypeEnum.RoundStorage: featureToEdit.Attributes["bin_type"] = "round_storage"; break; case BinTypeEnum.GravityWagon: featureToEdit.Attributes["bin_type"] = "gravity_wagon"; break; case BinTypeEnum.PolygonStructure: featureToEdit.Attributes["bin_type"] = "polygon_structure"; break; case BinTypeEnum.FlatStructure: featureToEdit.Attributes["bin_type"] = "flat_structure"; break; } featureToEdit.Attributes["year_collected"] = bin.YearCollected; if (bin.IsLeased.HasValue) { featureToEdit.Attributes["owned_or_leased"] = bin.IsLeased.Value ? "leased" : "owned"; } if (bin.HasDryingDevice.HasValue) { featureToEdit.Attributes["drying_device"] = bin.HasDryingDevice.Value ? "true" : "false"; } if (bin.HasGrainHeightIndicator.HasValue) { featureToEdit.Attributes["bin_level_indicator_device"] = bin.HasGrainHeightIndicator.Value ? "true" : "false"; } switch (bin.LadderType) { case Ladder.None: featureToEdit.Attributes["ladder_type"] = "none"; break; case Ladder.Ladder: featureToEdit.Attributes["ladder_type"] = "ladder"; break; case Ladder.Stairs: featureToEdit.Attributes["ladder_type"] = "stairs"; break; } featureToEdit.Attributes["notes"] = bin.Notes; double dr; //double.TryParse(bin.BinVolume, out dr); //featureToEdit.Attributes["bin_volume"] = dr; //bin type specific logic below Type t = bin.GetType(); if (bin.BinType == BinTypeEnum.FlatStructure) { if (t.Equals(typeof(FlatBin))) { FlatBin flat = (FlatBin)bin; featureToEdit.Attributes["crib_height"] = flat.CribLength; featureToEdit.Attributes["crib_width"] = flat.CribWidth; } } else if (bin.BinType == BinTypeEnum.GravityWagon) { if (t.Equals(typeof(GravityBin))) { GravityBin gravityBin = (GravityBin)bin; featureToEdit.Attributes["chute_length"] = gravityBin.ChuteLength; featureToEdit.Attributes["hopper_height"] = gravityBin.HopperHeight; featureToEdit.Attributes["rectangle_height"] = gravityBin.RectangleHeight; featureToEdit.Attributes["rectangle_length"] = gravityBin.RectangleLength; featureToEdit.Attributes["rectangle_width"] = gravityBin.RectangleWidth; } } else if (bin.BinType == BinTypeEnum.PolygonStructure) { if (t.Equals(typeof(PolygonBin))) { PolygonBin polygonBin = (PolygonBin)bin; featureToEdit.Attributes["side_height"] = polygonBin.SideHeight; featureToEdit.Attributes["side_width"] = polygonBin.SideWidth; featureToEdit.Attributes["number_of_sides"] = polygonBin.NumberOfSides; } } else if (bin.BinType == BinTypeEnum.RoundStorage) { if (t.Equals(typeof(PolygonBin))) { RoundBin round = (RoundBin)bin; if (round.HasHopper.HasValue) { featureToEdit.Attributes["has_hopper"] = round.HasHopper.Value ? "true" : "false"; } featureToEdit.Attributes["radius"] = round.Radius; featureToEdit.Attributes["wall_height"] = round.WallHeight; featureToEdit.Attributes["roof_height"] = round.RoofHeight; featureToEdit.Attributes["hopper_height"] = round.HopperHeight; } } // can't be null if (binViewModel.Binstance.YTYDatas == null) { binViewModel.Binstance.YTYDatas = new List <YTYData>(); } //use data in _binViewModel System.Diagnostics.Debug.Print("Feature can edit attachments" + (featureToEdit.CanEditAttachments ? "Yes" : "No")); //-------- Formatting -------- //create json string jsonString = JsonConvert.SerializeObject(binViewModel.Binstance.YTYDatas); //System.Diagnostics.Debug.Print(jsonString); //System.Diagnostics.Debug.Print(((Binstance)(binViewModel.Binstance)).YTYDatasString()); // convert json to byte array byte[] byteArray = Encoding.UTF8.GetBytes(jsonString); //-------- ARC Connection -------- //remove old YTYData List <Attachment> attachmentsToRemove = new List <Attachment>(); IReadOnlyList <Attachment> attachments = await featureToEdit.GetAttachmentsAsync(); foreach (Attachment attachment in attachments) { System.Diagnostics.Debug.Print(attachment.Name); if (attachment.Name.Equals(YTY_FILE_NAME)) { System.Diagnostics.Debug.Print("Found YTY attachment"); attachmentsToRemove.Add(attachment); } } System.Diagnostics.Debug.Print("Attachments to remove:"); foreach (Attachment attachment in attachments) { System.Diagnostics.Debug.Print(attachment.Name); } if (attachmentsToRemove.Any()) { //update the json file await featureToEdit.UpdateAttachmentAsync(attachmentsToRemove.First(), YTY_FILE_NAME, "application/json", byteArray); } _featureTable = (ServiceFeatureTable)featureToEdit.FeatureTable; // update feature after attachment added await _featureTable.UpdateFeatureAsync(featureToEdit); //agsFeature System.Diagnostics.Debug.Print("Feature table updated"); // push to ArcGIS Online feature service IReadOnlyList <EditResult> editResults = await _featureTable.ApplyEditsAsync(); System.Diagnostics.Debug.Print("Arc updated"); foreach (var er in editResults) { if (er.CompletedWithErrors) { // handle error (er.Error.Message) return(ArcCrudEnum.Failure); } } return(ArcCrudEnum.Success); } catch (ArcGISWebException) { return(ArcCrudEnum.Exception); } }