Esempio n. 1
0
        private async void Edit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Hide the base UI and enable the complete button.
                ShapesPanel.Visibility    = Visibility.Collapsed;
                CompleteButton.Visibility = Visibility.Visible;
                SaveResetGrid.Visibility  = Visibility.Collapsed;

                // Create variables for the sketch creation mode and color.
                SketchCreationMode creationMode;

                // Set the creation mode and UI based on which button called this method.
                switch (((Button)sender).Name)
                {
                case nameof(PointButton):
                    creationMode          = SketchCreationMode.Point;
                    InstructionsText.Text = "Tap to add a point.";
                    StyleText.Text        = "Select an icon for the placemark.";
                    break;

                case nameof(PolylineButton):
                    creationMode          = SketchCreationMode.Polyline;
                    InstructionsText.Text = "Tap to add a vertex.";
                    StyleText.Text        = "Select a color for the placemark.";
                    break;

                case nameof(PolygonButton):
                    creationMode          = SketchCreationMode.Polygon;
                    InstructionsText.Text = "Tap to add a vertex.";
                    StyleText.Text        = "Select a color for the placemark.";
                    break;

                default:
                    return;
                }

                // Get the user-drawn geometry.
                Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

                // Project the geometry to WGS84 (WGS84 is required by the KML standard).
                Geometry projectedGeometry = GeometryEngine.Project(geometry, SpatialReferences.Wgs84);

                // Create a KmlGeometry using the new geometry.
                KmlGeometry kmlGeometry = new KmlGeometry(projectedGeometry, KmlAltitudeMode.ClampToGround);

                // Create a new placemark.
                _currentPlacemark = new KmlPlacemark(kmlGeometry);

                // Add the placemark to the KmlDocument.
                _kmlDocument.ChildNodes.Add(_currentPlacemark);

                // Enable the style editing UI.
                StyleBorder.Visibility = Visibility.Visible;
                MainUI.Visibility      = Visibility.Collapsed;

                // Display the Icon picker or the color picker based on the creation mode.
                IconPicker.Visibility    = creationMode == SketchCreationMode.Point ? Visibility.Visible : Visibility.Collapsed;
                ColorSelector.Visibility = creationMode != SketchCreationMode.Point ? Visibility.Visible : Visibility.Collapsed;
            }
            catch (ArgumentException)
            {
                await new MessageDialog("Unsupported Geometry", "Error").ShowAsync();
            }
            finally
            {
                // Reset the UI.
                ShapesPanel.Visibility    = Visibility.Visible;
                CompleteButton.Visibility = Visibility.Collapsed;
                InstructionsText.Text     = "Select the type of feature you would like to add.";

                // Enable the save and reset buttons.
                SaveResetGrid.Visibility = Visibility;
            }
        }
        private async void AddGeometry(UIAlertAction obj)
        {
            try
            {
                // Create variables for the sketch creation mode and color.
                SketchCreationMode creationMode;

                // Set the creation mode and UI based on which button called this method.
                switch (obj.Title)
                {
                case "Point":
                    creationMode    = SketchCreationMode.Point;
                    _helpLabel.Text = "Tap to add a point.";
                    break;

                case "Polyline":
                    creationMode    = SketchCreationMode.Polyline;
                    _helpLabel.Text = "Tap to add a vertex.";
                    break;

                case "Polygon":
                    creationMode    = SketchCreationMode.Polygon;
                    _helpLabel.Text = "Tap to add a vertex.";
                    break;

                default:
                    return;
                }

                // Get the user-drawn geometry.
                Geometry geometry = await _myMapView.SketchEditor.StartAsync(creationMode, true);

                // Project the geometry to WGS84 (WGS84 is required by the KML standard).
                Geometry projectedGeometry = GeometryEngine.Project(geometry, SpatialReferences.Wgs84);

                // Create a KmlGeometry using the new geometry.
                KmlGeometry kmlGeometry = new KmlGeometry(projectedGeometry, KmlAltitudeMode.ClampToGround);

                // Create a new placemark.
                _currentPlacemark = new KmlPlacemark(kmlGeometry);

                // Add the placemark to the KmlDocument.
                _kmlDocument.ChildNodes.Add(_currentPlacemark);

                // Enable the style editing UI.
                ChooseStyle();
            }
            catch (ArgumentException)
            {
                ShowMessage("Error", "Unsupported Geometry");
            }
            finally
            {
                // Re-add toolbar.
                _toolbar.Items = new[]
                {
                    _addButton,
                    new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                    _saveButton,
                    _resetButton
                };
                _helpLabel.Text = "";
            }
        }
Esempio n. 3
0
        private async void Draw(object sender, DialogClickEventArgs e)
        {
            try
            {
                // Hide the base UI and enable the complete button.
                _buttonLayout.Visibility   = ViewStates.Invisible;
                _completeButton.Visibility = ViewStates.Visible;

                // Create variables for the sketch creation mode and color.
                SketchCreationMode creationMode;

                // Set the creation mode and UI based on which button called this method.
                switch (e.Which)
                {
                case 0:
                    creationMode = SketchCreationMode.Point;
                    _status.Text = "Tap to add a point.";
                    //StyleText.Text = "Select an icon for the placemark.";
                    break;

                case 1:
                    creationMode = SketchCreationMode.Polyline;
                    _status.Text = "Tap to add a vertex.";
                    //StyleText.Text = "Select a color for the placemark.";
                    break;

                case 2:
                    creationMode = SketchCreationMode.Polygon;
                    _status.Text = "Tap to add a vertex.";
                    //StyleText.Text = "Select a color for the placemark.";
                    break;

                default:
                    return;
                }

                // Get the user-drawn geometry.
                Geometry geometry = await _myMapView.SketchEditor.StartAsync(creationMode, true);

                // Project the geometry to WGS84 (WGS84 is required by the KML standard).
                Geometry projectedGeometry = GeometryEngine.Project(geometry, SpatialReferences.Wgs84);

                // Create a KmlGeometry using the new geometry.
                KmlGeometry kmlGeometry = new KmlGeometry(projectedGeometry, KmlAltitudeMode.ClampToGround);

                // Create a new placemark.
                _currentPlacemark = new KmlPlacemark(kmlGeometry);

                // Add the placemark to the KmlDocument.
                _kmlDocument.ChildNodes.Add(_currentPlacemark);

                // Choose whether to open the icon picker or color picker.
                if (creationMode == SketchCreationMode.Point)
                {
                    OpenIconDialog();
                }
                else
                {
                    OpenColorDialog();
                }
            }
            catch (ArgumentException)
            {
                new AlertDialog.Builder(this).SetMessage("Unsupported Geometry").SetTitle("Error").Show();
            }
            finally
            {
                // Reset the UI.
                _buttonLayout.Visibility   = ViewStates.Visible;
                _completeButton.Visibility = ViewStates.Invisible;
                _status.Text = "";
            }
        }
        private async void Edit_Click(object sender, EventArgs e)
        {
            try
            {
                // Hide the base UI and enable the complete button.
                ShapeGrid.IsVisible      = false;
                CompleteButton.IsVisible = true;
                SaveResetGrid.IsEnabled  = false;

                // Create variables for the sketch creation mode and color.
                SketchCreationMode creationMode;

                // Set the creation mode and UI based on which button called this method.
                switch (((Button)sender).Text)
                {
                case "Point":
                    creationMode = SketchCreationMode.Point;
                    Status.Text  = "Tap to add a point.";
                    break;

                case "Polyline":
                    creationMode = SketchCreationMode.Polyline;
                    Status.Text  = "Tap to add a vertex.";
                    break;

                case "Polygon":
                    creationMode = SketchCreationMode.Polygon;
                    Status.Text  = "Tap to add a vertex.";
                    break;

                default:
                    return;
                }

                // Get the user-drawn geometry.
                Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

                // Project the geometry to WGS84 (WGS84 is required by the KML standard).
                Geometry projectedGeometry = GeometryEngine.Project(geometry, SpatialReferences.Wgs84);

                // Create a KmlGeometry using the new geometry.
                KmlGeometry kmlGeometry = new KmlGeometry(projectedGeometry, KmlAltitudeMode.ClampToGround);

                // Create a new placemark.
                _currentPlacemark = new KmlPlacemark(kmlGeometry);

                // Add the placemark to the KmlDocument.
                _kmlDocument.ChildNodes.Add(_currentPlacemark);

                // Choose whether to enable the icon picker or color picker.
                IconPicker.IsVisible  = creationMode == SketchCreationMode.Point;
                ColorPicker.IsVisible = creationMode != SketchCreationMode.Point;

                // Enable the style editing UI.
                StyleUI.IsVisible = true;
                MainUI.IsVisible  = false;
            }
            catch (ArgumentException)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Unsupported Geometry", "OK");
            }
            finally
            {
                // Reset the UI.
                ShapeGrid.IsVisible      = true;
                CompleteButton.IsVisible = false;
                Status.Text = "Select the type of feature you would like to add.";

                // Enable the save and reset buttons.
                SaveResetGrid.IsEnabled = true;
            }
        }
 /// <summary>
 /// Initializes a new KML <c>&lt;Document&gt;</c> element.
 /// </summary>
 /// <param name="xml">The XML element the document should be based on.</param>
 /// <param name="namespaces">The XML namespace.</param>
 protected KmlPlacemark(XElement xml, XmlNamespaceManager namespaces) : base(xml, namespaces)
 {
     ExtendedData = xml.GetElement("kml:ExtendedData", namespaces, KmlExtendedData.Parse);
     Geometry     = KmlUtils.ParseGeometryChildren(xml, namespaces).FirstOrDefault();
 }
 /// <summary>
 /// Initializes a new KML <c>&lt;Placemark&gt;</c> element containing the specified <paramref name="geometry"/>..
 /// </summary>
 /// <param name="geometry">The geometry to be added.</param>
 public KmlPlacemark(KmlGeometry geometry)
 {
     Geometry = geometry;
 }