Exemple #1
0
        private async Task <Graphic> GetGraphicAsync()
        {
            Window w = Window.GetWindow(this);

            myMapView = (MapView)w.FindName("myMapView");
            // Wait for the user to click a location on the map
            Esri.ArcGISRuntime.Geometry.Geometry mapPoint = await myMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false);

            // Convert the map point to a screen point
            Point screenCoordinate = myMapView.LocationToScreen((MapPoint)mapPoint);

            // Identify graphics in the graphics overlay using the point
            IReadOnlyList <IdentifyGraphicsOverlayResult> results = await myMapView.IdentifyGraphicsOverlaysAsync(screenCoordinate, 2, false);

            // If results were found, get the first graphic
            Graphic graphic = null;
            IdentifyGraphicsOverlayResult idResult = results.FirstOrDefault();

            if (idResult != null && idResult.Graphics.Count > 0)
            {
                graphic = idResult.Graphics.FirstOrDefault();
            }

            // Return the graphic (or null if none were found)
            return(graphic);
        }
        private async void SketchGeometry(string sketchModeName)
        {
            try
            {
                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)_sketchModeDictionary[sketchModeName];
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await _myMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                var alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Error drawing graphic shape");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
Exemple #3
0
        private async void DrawButtonClick(object sender, RoutedEventArgs e)
        {
            ////////////////////////////////////////////////////////////////////////////////////////////////////

            //MainWindow t = new MainWindow();
            //GraphicsOverlay _sketchOverlay = MainWindow.graphicsOverlay;
            try
            {
                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)SketchModeComboBox.SelectedItem;
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await myMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);

                // Enable/disable the clear and edit buttons according to whether or not graphics exist in the overlay
                ClearButton.IsEnabled = _sketchOverlay.Graphics.Count > 0;
                EditButton.IsEnabled  = _sketchOverlay.Graphics.Count > 0;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                MessageBox.Show("绘制控件发生错误 : " + ex.Message);
            }
        }
        private async void EditGraphic()
        {
            try
            {
                // Allow the user to select a graphic
                Graphic editGraphic = await GetGraphicAsync();

                if (editGraphic == null)
                {
                    return;
                }

                // Let the user make changes to the graphic's geometry, await the result (updated geometry)
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await _myMapView.SketchEditor.StartAsync(editGraphic.Geometry);

                // Display the updated geometry in the graphic
                editGraphic.Geometry = newGeometry;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel editing
            }
            catch (Exception ex)
            {
                // Report exceptions
                var alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Error editing shape");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
        private async void OnSketchModeItemClicked(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            try
            {
                // Get the title of the selected menu item (sketch mode)
                var sketchModeName = e.Item.TitleCondensedFormatted.ToString();

                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)_sketchModeDictionary[sketchModeName];
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await _myMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                var alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Error drawing graphic shape");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
Exemple #6
0
        // 创建图形
        private Graphic CreateGraphic(Esri.ArcGISRuntime.Geometry.Geometry geometry)
        {
            // Create a graphic to display the specified geometry
            Symbol symbol = null;

            switch (geometry.GeometryType)
            {
            // Symbolize with a fill symbol
            case GeometryType.Envelope:
            case GeometryType.Polygon:
            {
                symbol = drawSimpleFillSymbol;
                break;
            }

            // Symbolize with a line symbol
            case GeometryType.Polyline:
            {
                symbol = drawLineSymbol;
                break;
            }

            // Symbolize with a marker symbol
            case GeometryType.Point:
            case GeometryType.Multipoint:
            {
                symbol = drawPointSymbol;
                break;
            }
            }

            // pass back a new graphic with the appropriate symbol
            return(new Graphic(geometry, symbol));
        }
Exemple #7
0
        private async void myTestBtn3_Click(object sender, RoutedEventArgs e)
        {
            FeatureLayer       a = (FeatureLayer)myMapView.Map.OperationalLayers[0];
            FeatureQueryResult r = await a.GetSelectedFeaturesAsync();

            IEnumerator <Feature> resultFeatures = r.GetEnumerator();
            List <Feature>        features       = new List <Feature>();

            while (resultFeatures.MoveNext())
            {
                features.Add(resultFeatures.Current);
            }
            myTest.Text = features.Count + " 个";
            Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Union(features[0].Geometry, features[1].Geometry);
            myTest.Text = resultGeometry.IsEmpty + "";
            // 渲染
            SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol()
            {
                Style = SimpleLineSymbolStyle.Solid,
                Width = 4,
                Color = System.Drawing.Color.Green
            };
            Graphic graphic = new Graphic(resultGeometry, simpleLineSymbol);

            graphicsOverlay.Graphics.Add(graphic);
        }
        private async void EditButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Set the focus to the map view(close the flyout panel)
                DrawToolsFlyout.Hide();

                // Allow the user to select a graphic
                Graphic editGraphic = await GetGraphicAsync();

                if (editGraphic == null)
                {
                    return;
                }

                // Let the user make changes to the graphic's geometry, await the result (updated geometry)
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await MyMapView.SketchEditor.StartAsync(editGraphic.Geometry);

                // Display the updated geometry in the graphic
                editGraphic.Geometry = newGeometry;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel editing
            }
            catch (Exception ex)
            {
                // Report exceptions
                var dialog = new MessageDialog("Error editing shape: " + ex.Message);
                dialog.ShowAsync();
            }
        }
        public async override void Execute(object parameter)
        {
            if (MapVM.ZoomWithDrawIsActive)
            {
                if (((MapView)parameter).SketchEditor.CancelCommand.CanExecute(parameter))
                {
                    ((MapView)parameter).SketchEditor.CancelCommand.Execute(parameter);
                }
                MapVM.ZoomWithDrawIsActive = false;
                return;
            }


            try
            {
                MapVM.ZoomWithDrawIsActive = true;
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await((MapView)parameter).SketchEditor.StartAsync(Esri.ArcGISRuntime.UI.SketchCreationMode.Rectangle, false);
                ((MapView)parameter).SetViewpointGeometryAsync(newGeometry);
                MapVM.ZoomWithDrawIsActive = false;
                Execute(parameter);
            }
            catch (Exception e)
            {
                MapVM.ZoomWithDrawIsActive = false;
            }
        }
        private async void DrawButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Set the focus to the map view(close the flyout panel)
                DrawToolsFlyout.Hide();

                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)SketchModeComboBox.SelectedItem;
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);

                // Enable/disable the clear and edit buttons according to whether or not graphics exist in the overlay
                ClearButton.IsEnabled = _sketchOverlay.Graphics.Count > 0;
                EditButton.IsEnabled  = _sketchOverlay.Graphics.Count > 0;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                var dialog = new MessageDialog("Error drawing graphic shape: " + ex.Message);
                dialog.ShowAsync();
            }
        }
        private async void myMeasureLine_Click(object sender, RoutedEventArgs e)
        {
            // 找到鼠标点击位置的坐标
            myMapView.GeoViewTapped += MyMapViewOnGeoViewTapped_Line;
            myMapView.GeoViewTapped -= MyMapViewOnGeoViewTapped_Area;
            myMeasureLine.IsEnabled  = false;
            try
            {
                // 0表示point
                SketchCreationMode creationMode = SketchCreationMode.Polyline;
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await myMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                measureOverlay.Graphics.Add(graphic);
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                MessageBox.Show("Error drawing graphic shape: " + ex.Message);
            }
        }
        private async void DrawButtonClick(object sender, EventArgs e)
        {
            try
            {
                // Hide the draw/edit tools
                DrawToolsGrid.IsVisible = false;

                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)SketchModePicker.SelectedIndex;
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);

                // Enable/disable the clear and edit buttons according to whether or not graphics exist in the overlay
                ClearButton.IsEnabled = _sketchOverlay.Graphics.Count > 0;
                EditButton.IsEnabled  = _sketchOverlay.Graphics.Count > 0;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                await DisplayAlert("Error", "Error drawing graphic shape: " + ex.Message, "OK");
            }
        }
Exemple #13
0
        private async void DrawButtonClick(object sender, RoutedEventArgs e)
        {
            MyMapView.GeoViewTapped -= MapViewTapped_Mouse_Point;
            _sketchOverlay.Graphics.Clear();
            routeline      = null;
            polygondrawgrp = null;
            try
            {
                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)SketchModeComboBox.SelectedItem;
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);
                if (geometry.GeometryType.ToString() == "Polyline")
                {
                    routeline = coordinatesystem_polyline(geometry);
                }
                else if (geometry.GeometryType.ToString() == "Polygon")
                {
                    polygondrawgrp = coordinatesystem_polygon(graphic);
                }
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                MessageBox.Show("Error drawing graphic shape: " + ex.Message);
            }
            MyMapView.GeoViewTapped += MapViewTapped_Mouse_Point;
        }
Exemple #14
0
        private Graphic coordinatesystem_polygon(Graphic graphic)
        {
            Graphic polylgonGraphic = null;
            var     poly            = graphic.Geometry as Esri.ArcGISRuntime.Geometry.Polygon;

            this.polygonbuild = new PolygonBuilder(poly);
            foreach (var re in polygonbuild.Parts)
            {
                IReadOnlyList <MapPoint> mapPoints = re.Points;
                var polypoints = Mapcoordinates_Aftertransform(mapPoints);

                var polygon = new Esri.ArcGISRuntime.Geometry.Polygon(polypoints);

                //Create symbol for polyline
                var polylineSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Transparent,
                                                          new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(0, 0, 255), 2));
                //Create a polyline graphic with geometry and symbol
                polylgonGraphic = new Graphic(polygon, polylineSymbol);

                //Add polygone to graphics overlay

                _sketchOverlay.Graphics.Add(polylgonGraphic);
                Esri.ArcGISRuntime.Geometry.Geometry gr = polygon;
            }
            return(polylgonGraphic);
        }
Exemple #15
0
        private async void ExecuteDrawing(Func <SceneView, Task <Esri.ArcGISRuntime.Geometry.Geometry> > createGeometryAsync, Esri.ArcGISRuntime.Symbology.Symbol symbol)
        {
            Esri.ArcGISRuntime.Geometry.Geometry DrawedGeometry = null;
            bool toContinueDrawing = true;

            while (toContinueDrawing)
            {
                try
                {
                    DrawedGeometry = await createGeometryAsync(View);
                }
                catch (DrawCanceledExeption e)
                {
                    DrawedGeometry    = e.DrawedGepmetry;
                    toContinueDrawing = false;
                }
                finally
                {
                    if (DrawedGeometry != null && !DrawedGeometry.IsEmpty)
                    {
                        var graphic = new Graphic(DrawedGeometry);
                        graphic.Symbol = symbol;
                        _drawingOverlay.Graphics.Add(graphic);
                    }
                }
            }
        }
Exemple #16
0
        private async void EditButtonClick(object sender, EventArgs e)
        {
            try
            {
                // Hide the draw/edit tools
                DrawToolsGrid.IsVisible = false;

                // Allow the user to select a graphic
                Graphic editGraphic = await GetGraphicAsync();

                if (editGraphic == null)
                {
                    return;
                }

                // Let the user make changes to the graphic's geometry, await the result (updated geometry)
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await MyMapView.SketchEditor.StartAsync(editGraphic.Geometry);

                // Display the updated geometry in the graphic
                editGraphic.Geometry = newGeometry;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel editing
            }
            catch (Exception ex)
            {
                // Report exceptions
                DisplayAlert("Error", "Error editing shape: " + ex.Message, "OK");
            }
        }
Exemple #17
0
        private void Mapview1_ExtentChanged(object sender, EventArgs e)
        {
            Esri.ArcGISRuntime.Geometry.Geometry ext = GeometryEngine.NormalizeCentralMeridian(Mapview1.Extent);
            var vp = new Esri.ArcGISRuntime.Controls.Viewpoint(ext);

            SceneView1.SetViewAsync(vp);
        }
Exemple #18
0
 private GraphicsLayer CreateBuffer(int layerIndex, Color color, double radius)
 {
     if (MyMapView.Map.Layers[layerIndex] is FeatureLayer fLayer)
     {
         var fTable = fLayer.FeatureTable;
         var filter = new QueryFilter {
             WhereClause = "1=1"
         };
         var features      = fTable.QueryAsync(filter).Result;
         var bufferGrLayer = new GraphicsLayer()
         {
             ID          = fLayer.ID + "Buffer",
             DisplayName = fLayer.DisplayName + "Buffer"
         };
         MyMapView.Map.Layers.Add(bufferGrLayer);
         AddItemToListBox(bufferGrLayer.DisplayName);
         var    geometries      = features.Select(feature => feature.Geometry);
         double metersToDegrees = 1d / 111.325 / 1000;
         foreach (var geometry in geometries)
         {
             Esri.ArcGISRuntime.Geometry.Geometry geometryBuffer =
                 GeometryEngine.Buffer(geometry, radius * metersToDegrees);
             Symbol bufferSymbol = GetGraphicStyle(color);
             bufferGrLayer.Graphics.Add(new Graphic(geometryBuffer, bufferSymbol));
         }
         return(bufferGrLayer);
     }
     else
     {
         throw new Exception("Fail");
     }
 }
        private async void EditGraphic()
        {
            try
            {
                // Allow the user to select a graphic
                Graphic editGraphic = await GetGraphicAsync();

                if (editGraphic == null)
                {
                    return;
                }

                // Let the user make changes to the graphic's geometry, await the result (updated geometry)
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await _myMapView.SketchEditor.StartAsync(editGraphic.Geometry);

                // Display the updated geometry in the graphic
                editGraphic.Geometry = newGeometry;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel editing
            }
            catch (Exception ex)
            {
                // Report exceptions
                UIAlertView alert = new UIAlertView("Error", "Error editing shape: " + ex.Message, null, "OK", null);
            }
        }
Exemple #20
0
 public static Esri.ArcGISRuntime.Geometry.Geometry ChangeSpatailReference(
     Esri.ArcGISRuntime.Geometry.Geometry geom, SpatialReference sr)
 {
     if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Point)
     {
         MapPoint p = geom as MapPoint;
         return(ChangeSpatailReference(p, sr));
     }
     else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Multipoint)
     {
         Multipoint             mp    = geom as Multipoint;
         IEnumerable <MapPoint> newMP = ChangeSpatialReference(mp.Points, sr);
         return(new Multipoint(newMP, sr));
     }
     else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Polyline)
     {
         Esri.ArcGISRuntime.Geometry.Polyline pl = geom as Esri.ArcGISRuntime.Geometry.Polyline;
         PartCollection newPart = ChangeSpatialReference(pl.Parts, sr);
         return(new Esri.ArcGISRuntime.Geometry.Polyline(newPart, sr));
     }
     else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Polygon)
     {
         Esri.ArcGISRuntime.Geometry.Polygon pg = geom as Esri.ArcGISRuntime.Geometry.Polygon;
         PartCollection newPart = ChangeSpatialReference(pg.Parts, sr);
         return(new Esri.ArcGISRuntime.Geometry.Polygon(newPart, sr));
     }
     else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Envelope)
     {
         Envelope ev = geom as Envelope;
         return(new Envelope(ev.XMin, ev.YMin, ev.XMax, ev.YMax, sr));
     }
     return(null);
 }
        // Accepts two user shapes and adds them to the graphics layer
        private async void StartDrawingButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnDraw.IsEnabled      = false;
                btnTest.IsEnabled      = false;
                resultPanel.Visibility = Visibility.Collapsed;

                _graphicsOverlay.Graphics.Clear();

                // Shape One
                Esri.ArcGISRuntime.Geometry.Geometry shapeOne = await MyMapView.Editor.RequestShapeAsync(
                    (DrawShape)comboShapeOne.SelectedValue, _symbols[comboShapeOne.SelectedIndex]);

                _graphicsOverlay.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex]));

                // Shape Two
                Esri.ArcGISRuntime.Geometry.Geometry shapeTwo = await MyMapView.Editor.RequestShapeAsync(
                    (DrawShape)comboShapeTwo.SelectedValue, _symbols[comboShapeTwo.SelectedIndex]);

                _graphicsOverlay.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex]));
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                btnTest.IsEnabled = (_graphicsOverlay.Graphics.Count >= 2);
            }
        }
Exemple #22
0
        private async void EditButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Allow the user to select a graphic
                Graphic editGraphic = await GetGraphicAsync();

                if (editGraphic == null)
                {
                    return;
                }

                // Let the user make changes to the graphic's geometry, await the result (updated geometry)
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await MyMapView.SketchEditor.StartAsync(editGraphic.Geometry); //맵에 기존geometry 얻어오기

                // Display the updated geometry in the graphic
                editGraphic.Geometry = newGeometry;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel editing
            }
            catch (Exception ex)
            {
                // Report exceptions
                MessageBox.Show("Error editing shape: " + ex.Message);
            }
        }
        // Summary:
        //     Select objects by geometry
        // Remarks:
        //     The function selects graphics at first,
        //     then it returns the corresponding DGObjects as a list.
        //     If a graphic has no corresponding DGObject, it will
        //     still be in a selected state.
        public List <DGObject> selectObjectsByRect(IGeometry geom)
        {
            Esri.ArcGISRuntime.Geometry.Geometry rect = geom
                                                        as Esri.ArcGISRuntime.Geometry.Geometry;

            foreach (Graphic g in graphics)
            {
                if (!GeometryEngine.Contains(rect, g.Geometry))
                {
                    continue;
                }

                IGraphic ig = g as IGraphic;
                // make sure all graphics with the name is selected.
                if (_graphic2Objs != null &&
                    _graphic2Objs.ContainsKey(ig))
                {
                    DGObject           obj = _graphic2Objs[ig];
                    IGraphicCollection gc  = _obj2Graphics[obj];
                    foreach (IGraphic item in gc)
                    {
                        item.IsSelected = true;
                    }
                }
                else
                {
                    g.IsSelected = true;
                }
            }
            List <DGObject> objs = getHighlightedObjects();

            return(objs);
        }
Exemple #24
0
        // 鹰眼
        private void myMapView_ViewpointChanged(object sender, EventArgs e)
        {
            // 声明鹰眼地图的覆盖层边框
            Esri.ArcGISRuntime.Geometry.Geometry eagleViewEnv = null;
            // 每次主地图的焦点改变, 都会清空鹰眼地图的覆盖层
            myMapView_Eagle.GraphicsOverlays.Clear();
            // 获取主地图的四至
            Esri.ArcGISRuntime.Geometry.Polygon vExtent = myMapView.VisibleArea;
            // 鹰眼地图的覆盖层边框等于主地图四至
            eagleViewEnv = vExtent.Extent;
            // 鹰眼地图的覆盖层边框为"红色"
            System.Drawing.Color lineColor = System.Drawing.Color.FromName("Red");
            // 鹰眼地图的覆盖层边框样式
            Esri.ArcGISRuntime.Symbology.SimpleLineSymbol lineSymbol = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(Esri.ArcGISRuntime.Symbology.SimpleLineSymbolStyle.Dash, lineColor, 2.0);
            System.Drawing.Color fillColor = System.Drawing.Color.FromArgb(0, 255, 255, 255);
            Esri.ArcGISRuntime.Symbology.SimpleFillSymbol polySymbol = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(Esri.ArcGISRuntime.Symbology.SimpleFillSymbolStyle.Solid, fillColor, lineSymbol);
            var graphicOverlay = new Esri.ArcGISRuntime.UI.GraphicsOverlay();
            // 几何图层
            var envGraphic = new Esri.ArcGISRuntime.UI.Graphic(eagleViewEnv, polySymbol);

            // 覆盖层
            graphicOverlay.Graphics.Add(envGraphic);
            // 覆盖层添加到鹰眼地图
            myMapView_Eagle.GraphicsOverlays.Add(graphicOverlay);
        }
Exemple #25
0
        protected List <Graphic> CreateGraphic(Esri.ArcGISRuntime.Geometry.Geometry poly, System.Windows.Media.Color color, int zOrder, bool bDrawEdge = true)
        {
            List <Graphic> graphicList = new List <Graphic>();

            graphicList.Add(new Graphic()
            {
                Geometry = poly, Symbol = new SimpleFillSymbol()
                {
                    Color = color
                }, ZIndex = zOrder
            });

            if (bDrawEdge)
            {
                graphicList.Add(new Graphic()
                {
                    Geometry = poly, Symbol = new SimpleLineSymbol()
                    {
                        Color = System.Windows.Media.Colors.Black, Width = 1
                    }, ZIndex = zOrder
                });
            }

            return(graphicList);
        }
Exemple #26
0
        public void ZoomToEnvelope(Geometry geometry, MapView MyMapView)
        {
            //MyMapView1.SetViewpointGeometryAsync(new Polygon((geometry as Polygon).Parts.Last().Points, geometry.SpatialReference));

            Envelope envelope = new Envelope(xMin, yMin, xMax, yMax, SpatialReferences.Wgs84);

            MyMapView.SetViewpointGeometryAsync(envelope);
        }
Exemple #27
0
        private async void OnEditButtonClick()
        {
            if (_selection == null)
            {
                return;                     // Selection missing
            }
            // Cancel previous edit
            if (SceneEditHelper.IsActive)
            {
                SceneEditHelper.Cancel();
            }

            Esri.ArcGISRuntime.Geometry.Geometry editedGeometry = null;

            try
            {
                // Edit selected geometry and set it back to the selected graphic
                switch (_selection.GeometryType)
                {
                case GeometryType.Point:
                    editedGeometry = await SceneEditHelper.CreatePointAsync(
                        View);

                    break;

                case GeometryType.Polyline:
                    _selection.SetHidden();     // Hide selected graphic from the UI
                    editedGeometry = await SceneEditHelper.EditPolylineAsync(
                        View,
                        _selection.SelectedGraphic.Geometry as Polyline);

                    break;

                case GeometryType.Polygon:
                    _selection.SetHidden();     // Hide selected graphic from the UI
                    editedGeometry = await SceneEditHelper.EditPolygonAsync(
                        View,
                        _selection.SelectedGraphic.Geometry as Polygon);

                    break;

                default:
                    break;
                }

                _selection.SelectedGraphic.Geometry = editedGeometry; // Set edited geometry to selected graphic
            }
            catch (TaskCanceledException tce)
            {
                // This occurs if draw operation is canceled or new operation is started before previous was finished.
                Debug.WriteLine("Previous edit operation was canceled.");
            }
            finally
            {
                _selection.Unselect();
                _selection.SetVisible(); // Show selected graphic from the UI
            }
        }
 //Exercise 2
 private void zoomScene(double factor)
 {
     Esri.ArcGISRuntime.Geometry.Geometry target = sceneView.GetCurrentViewpoint(ViewpointType.CenterAndScale).TargetGeometry;
     if (target.GeometryType == GeometryType.Point)
     {
         Camera camera = sceneView.Camera.ZoomToward((Esri.ArcGISRuntime.Geometry.MapPoint)target, factor);
         sceneView.SetViewpointCameraAsync(camera, new TimeSpan(1000));
     }
 }
        }   // end CreateGraphic


        /// <summary>
        ///  Draw Button Callback
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void DrawButtonClick(object sender, RoutedEventArgs e)
        {

            if (selectedLayers == null)
            {
                MessageBox.Show("Please select at least one layer", "LAYER SELECTION ERROR");
                haveLayer = false;
            }
            else if (selectedLayers.Count < 1)
            {
                haveLayer = false;
                MessageBox.Show("Please select at least one layer", "LAYER SELECTION ERROR");
            }
            else try
                {
                    // Clear out previous graphics if they exist
                    sketchOverlay.Graphics.Clear();

                    // Set Buttons
                    AOIDraw.IsEnabled = true;
                    AOIClear.IsEnabled = true;
                    AOICancel.IsEnabled = true;
                    AOISelect.IsEnabled = true;

                    // Create graphics area for a redrawable rectangle w/labels
                    SketchCreationMode creationMode = (SketchCreationMode)6;
                    SketchEditConfiguration sketchEdit = new SketchEditConfiguration
                    {
                        AllowMove = true,
                        AllowRotate = false,
                        ResizeMode = (SketchResizeMode)1
                    };

                    // Let the user draw on the map view using the chosen sketch mode
                    Esri.ArcGISRuntime.Geometry.Geometry geometry =
                       await BasemapView.SketchEditor.StartAsync(creationMode, true);

                    // Create and add a graphic from the geometry the user drew
                    Graphic graphic = CreateGraphic(geometry);
                    sketchOverlay.Graphics.Add(graphic);
                    haveSketch = true;
                }
                catch (TaskCanceledException)
                {
                    sketchOverlay.Graphics.Clear();
                    haveSketch = false;
                    AOIDraw.IsEnabled = true;
                    AOIClear.IsEnabled = true;
                    AOICancel.IsEnabled = true;
                    AOISelect.IsEnabled = true;
                }
                catch (Exception ex)
                {
                    // Report exceptions
                    MessageBox.Show("Error drawing graphic shape: " + ex.Message);
                }
        }   // end DrawButtonClick
Exemple #30
0
        private async void AddButton_Click(object sender, EventArgs e)
        {
            try
            {
                Esri.ArcGISRuntime.Geometry.Geometry geom = await mapView1.Editor.RequestShapeAsync(DrawShape.Freehand);

                mapView1.Map.Layers.OfType <GraphicsLayer>().First().Graphics.Add(new Graphic(geom));
            }
            catch (OperationCanceledException) { }
        }
 public Task FlyToAsync(Geometry flyTo, double margin = 20)
 {
     if (Controller == null || flyTo == null)
         return Task.FromResult(false);
     var extent = flyTo.Extent;
     // set the padding around the extent - if the side pane is open add its width to the left margin
     var padding = new Thickness((IsSidePaneOpen ? _collapsibleTabWidth : 0) + margin, margin, margin, margin);
     return Controller.FlyToAsync(extent, padding);
 }
        private void RestoreGeometry()
        {
            if (_currentMessage != null && _beforeEditGeometry != null )
            {
                var tam = _mission.MilitaryMessages.FirstOrDefault(msg => msg.Id == _currentMessage.Id);

                if (tam != null)
                {
                    UpdateCurrentMessage(tam, _beforeEditGeometry);
                    _beforeEditGeometry = null;
                }
            }
        }
        private void ProcessSymbol(SymbolViewModel symbol, Geometry geometry)
        {
            if (symbol == null || geometry == null)
            {
                return;
            }

            //create a new message
            var msg = new TimeAwareMilitaryMessage
            {
                VisibleTimeExtent = new TimeExtent(_mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.Start,
                    _mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.End),
                Id = Guid.NewGuid().ToString("D"),
                SymbolGeometry = geometry
            };

            // set default time extent

            //set the ID and other parts of the message
            msg.Add(MilitaryMessage.TypePropertyName, Constants.MSG_TYPE_POSITION_REPORT);
            msg.Add(MilitaryMessage.ActionPropertyName, Constants.MSG_ACTION_UPDATE);
            msg.Add(MilitaryMessage.WkidPropertyName, "3857");
            msg.Add(MilitaryMessage.SicCodePropertyName, symbol.SymbolID);
            msg.Add(MilitaryMessage.UniqueDesignationPropertyName, "1");

            // Construct the Control Points based on the geometry type of the drawn geometry.
            switch (geometry.GeometryType)
            {
                case GeometryType.Point:
                    MapPoint point = geometry as MapPoint;
                    if (point != null)
                        msg.Add(MilitaryMessage.ControlPointsPropertyName, string.Format("{0},{1}", point.X.ToString(), point.Y.ToString()));
                    break;
                case GeometryType.Polygon:
                    Polygon polygon = geometry as Polygon;
                    string cpts = polygon.Parts.SelectMany(pt => pt.GetPoints()).Aggregate(string.Empty, (current, segpt) => current + (";" + segpt.X.ToString() + "," + segpt.Y.ToString()));
                    //foreach (var pt in polygon.Rings[0])
                    msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts);
                    break;
                case GeometryType.Polyline:
                    Polyline polyline = geometry as Polyline;
                    cpts = string.Empty;

                    // TODO find a way to determine if polyline map points need adjustment based on symbol being drawn
                    var mpList = AdjustMapPoints(polyline, symbol);

                    cpts = mpList.Aggregate(cpts, (current, mp) => current + (";" + mp.X.ToString() + "," + mp.Y.ToString()));

                    msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts);
                    break;
            }

            //Process the message
            if (ProcessMessage(_militaryMessageLayer, msg))
            {
                RecordMessageBeingAdded(msg);

                DoCloneMission(null);
            }
            else
            {
                MessageBox.Show("Failed to process message.");
            }
        }
        /// <summary>
        /// On this command the currently selected geometry gets edited if it is a polyline or polygon
        /// Updates the military message with the new geometry during and after editing
        /// </summary>
        /// <param name="obj"></param>
        private async void DoEditGeometry(object obj)
        {
            if (_mapView.Editor.IsActive)
            {
                if (_mapView.Editor.Complete.CanExecute(null))
                {
                    _mapView.Editor.Complete.Execute(null);
                    _editState = EditState.None;
                    return;
                }
            }

            if (_currentMessage != null)
            {
                var tam = _mission.MilitaryMessages.FirstOrDefault(msg => msg.Id == _currentMessage.Id);

                if (tam != null)
                {
                    _editState = EditState.Edit;

                    try
                    {
                        var progress = new Progress<GeometryEditStatus>();

                        progress.ProgressChanged += (a, ges) =>
                        {
                            UpdateCurrentMessage(tam, ges.NewGeometry);
                        };

                        _beforeEditGeometry = tam.SymbolGeometry;

                        var resultGeometry = await _mapView.Editor.EditGeometryAsync(tam.SymbolGeometry, null, progress);

                        if (resultGeometry != null)
                        {
                            tam.SymbolGeometry = resultGeometry;
                            UpdateCurrentMessage(tam, resultGeometry);
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
        }
        private void UpdateCurrentMessage(TimeAwareMilitaryMessage tam, Geometry geometry)
        {
            var cpts = string.Empty;

            // TODO find a way to determine if polyline map points need adjustment based on symbol being drawn

            List<MapPoint> mpList = null;

            var polyline = geometry as Polyline;

            if (polyline != null)
            {
                if (tam[MilitaryMessage.SicCodePropertyName].Contains("POLA") ||
                    tam[MilitaryMessage.SicCodePropertyName].Contains("PPA"))
                {
                    mpList = AdjustMapPoints(polyline, DrawShape.Arrow);
                }
                else
                {
                    mpList = AdjustMapPoints(polyline, DrawShape.Polyline);
                }
            }
            else
            {
                var polygon = geometry as Polygon;

                if (polygon != null)
                {
                    mpList = new List<MapPoint>();
                    foreach (var part in polygon.Parts)
                    {
                        mpList.AddRange(part.GetPoints());
                    }
                }
            }

            if (mpList != null)
            {
                var msg = new MilitaryMessage(tam.Id, MilitaryMessageType.PositionReport, MilitaryMessageAction.Update,
                    mpList);

                tam[MilitaryMessage.ControlPointsPropertyName] = msg[MilitaryMessage.ControlPointsPropertyName];

                if (_militaryMessageLayer.ProcessMessage(msg))
                {
                    UpdateMilitaryMessageControlPoints(msg);

                    DoCloneMission(null);
                }
            }
        }