// Handle selection events in the spatial operations picker. private void OperationModel_ValueChanged(object sender, EventArgs e) { // Get the data model that contains the spatial operation choices. PickerDataModel operationsModel = (PickerDataModel)_operationPicker.Model; // If an operation hasn't been selected, return. if (operationsModel.SelectedItem == "") { return; } // Remove any currently displayed result. _polygonsOverlay.Graphics.Remove(_resultGraphic); // Polygon geometry from the input graphics. Geometry polygonOne = _graphicOne.Geometry; Geometry polygonTwo = _graphicTwo.Geometry; // Result polygon for spatial operations. Geometry resultPolygon = null; // Run the selected spatial operation on the polygon graphics and get the result geometry. switch (operationsModel.SelectedItem) { case "Union": resultPolygon = GeometryEngine.Union(polygonOne, polygonTwo); break; case "Difference": resultPolygon = GeometryEngine.Difference(polygonOne, polygonTwo); break; case "Symmetric difference": resultPolygon = GeometryEngine.SymmetricDifference(polygonOne, polygonTwo); break; case "Intersection": resultPolygon = GeometryEngine.Intersection(polygonOne, polygonTwo); break; } // Create a black outline symbol to use for the result polygon. SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 1); // Create a solid red fill symbol for the result polygon graphic. SimpleFillSymbol resultSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Red, outlineSymbol); // Create the result polygon graphic and add it to the graphics overlay. _resultGraphic = new Graphic(resultPolygon, resultSymbol); _polygonsOverlay.Graphics.Add(_resultGraphic); }
private void CreateLayout() { // Lay out the spatial operations UI vertically. _operationToolsView.Axis = UILayoutConstraintAxis.Vertical; // Create a label to prompt for a spatial operation. UILabel operationLabel = new UILabel(new CGRect(5, 0, View.Bounds.Width, 30)) { Text = "Choose a spatial operation:", TextAlignment = UITextAlignment.Left, TextColor = UIColor.Blue }; // Create a picker model with spatial operation choices. List <string> operationsList = new List <string> { "", "Difference", "Intersection", "Symmetric difference", "Union" }; PickerDataModel operationModel = new PickerDataModel(operationsList); // Handle the selection change for spatial operations. operationModel.ValueChanged += OperationModel_ValueChanged; // Create a picker to show the spatial operations. _operationPicker = new UIPickerView(new CGRect(20, 25, View.Bounds.Width - 20, 100)) { Model = operationModel }; // Create a button to reset the operation result. UIButton resetButton = new UIButton(UIButtonType.Plain); resetButton.Frame = new CGRect(20, 110, View.Bounds.Width - 20, 30); resetButton.SetTitle("Reset operation", UIControlState.Normal); resetButton.SetTitleColor(UIColor.Blue, UIControlState.Normal); resetButton.TouchUpInside += ResetButton_TouchUpInside; // Add the controls to the tools UI (stack view). _operationToolsView.AddSubviews(operationLabel, _operationPicker, resetButton); // Add the map view and tools sub-views to the view. View.AddSubviews(_myMapView, _operationToolsView); // Set the view background color. View.BackgroundColor = UIColor.White; }