private void MyMapViewOnGeoViewTapped_Line(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Get the tapped point, projected to WGS84.
            MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84);

            mapPoints.Add(destination);
            int len = mapPoints.Count();

            Esri.ArcGISRuntime.Geometry.PointCollection polylinePoints;
            Esri.ArcGISRuntime.Geometry.Geometry        pathGeometry;
            Esri.ArcGISRuntime.Geometry.Polyline        routeLine;
            if (len > 1)
            {
                polylinePoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84)
                {
                    mapPoints[len - 2],
                    destination
                };

                routeLine    = new Esri.ArcGISRuntime.Geometry.Polyline(polylinePoints);
                pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

                // 这是测地线的长度
                //double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
                double distance = GeometryEngine.Length(pathGeometry);
                //double distance = GeometryEngine.Length(routeLine);
                lengthList.Add(distance);
                myMeasureResult.Text += "\n" + distance + " (地图默认长度单位)";
            }
        }
        private void MyMapViewOnGeoViewTapped_Area(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Get the tapped point, projected to WGS84.
            MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84);

            // 点集(mapPoints) ——记得清空
            mapPoints.Add(destination);
            int len = mapPoints.Count();

            Esri.ArcGISRuntime.Geometry.PointCollection polygonPoints;
            Esri.ArcGISRuntime.Geometry.Geometry        areaGeometry;
            Esri.ArcGISRuntime.Geometry.Polygon         routeArea;
            if (len > 2)
            {
                polygonPoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84)
                {
                    mapPoints[len - 3],
                    mapPoints[len - 2],
                    destination
                };

                routeArea = new Esri.ArcGISRuntime.Geometry.Polygon(polygonPoints);
                //pathGeometry = GeometryEngine.DensifyGeodetic(routeArea, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

                // 这是测地线的长度
                //double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
                double area = GeometryEngine.Area(routeArea);
                if (areaList.Count() != 0)
                {
                    area += areaList[areaList.Count() - 1];
                }
                areaList.Add(area);
                myMeasureResult.Text += "\n" + area + " (地图默认面积单位)";
            }
        }
Beispiel #3
0
        private Graphic GraphicFromAttributes(List <XElement> graphicAttributes)
        {
            // Get the geometry and the spatial reference from the message elements.
            XElement geometryAttribute    = graphicAttributes.First(attr => attr.Name == "_control_points");
            XElement spatialReferenceAttr = graphicAttributes.First(attr => attr.Name == "_wkid");

            // Split the geometry field into a list of points.
            Array pointStrings = geometryAttribute.Value.Split(';');

            // Create a point collection in the correct spatial reference.
            int wkid = Convert.ToInt32(spatialReferenceAttr.Value);
            SpatialReference pointSR       = SpatialReference.Create(wkid);
            PointCollection  graphicPoints = new PointCollection(pointSR);

            // Add a point for each point in the list.
            foreach (string pointString in pointStrings)
            {
                var coords = pointString.Split(',');
                graphicPoints.Add(Convert.ToDouble(coords[0]), Convert.ToDouble(coords[1]));
            }

            // Create a multipoint from the point collection.
            Multipoint graphicMultipoint = new Multipoint(graphicPoints);

            // Create the graphic from the multipoint.
            Graphic messageGraphic = new Graphic(graphicMultipoint);

            // Add all of the message's attributes to the graphic (some of these are used for rendering).
            foreach (XElement attr in graphicAttributes)
            {
                messageGraphic.Attributes[attr.Name.ToString()] = attr.Value;
            }

            return(messageGraphic);
        }
        public static Graphic NewDonut(double x, double y, double innerRadius, double outerRadius)
        {
            double[] px = new double[NUM];
            double[] py = new double[NUM];
            GeometryAlgorithms.CircleToPoints(x, y, outerRadius, NUM, px, py, AngleDirection.CounterClockwise);

            Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            for (int i = 0; i < NUM; i++)
            {
                MapPoint p = new MapPoint(px[i], py[i]);
                pc.Add(p);
            }
            pc.Add(pc[0]);

            PolygonBuilder polygon = new PolygonBuilder(pc);

            GeometryAlgorithms.CircleToPoints(x, y, innerRadius, NUM, px, py, AngleDirection.Clockwise);
            pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            for (int i = 0; i < NUM; i++)
            {
                MapPoint p = new MapPoint(px[i], py[i]);
                pc.Add(p);
            }
            pc.Add(pc[0]);
            polygon.AddPart(pc);

            Graphic g = new Graphic();
            g.Geometry = polygon.ToGeometry();
            return g;
        }
        private void CreatePolygon()
        {
            // Create a green simple line symbol
            SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.FromRgb(0x00, 0x50, 0x00), 1);

            // Create a green mesh simple fill symbol
            SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.DiagonalCross, Color.FromRgb(0x00, 0x50, 0x00), outlineSymbol);

            // Create a new point collection for polygon
            Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84)
            {
                // Create and add points to the point collection
                new MapPoint(-2.6425, 56.0784),
                new MapPoint(-2.6430, 56.0763),
                new MapPoint(-2.6410, 56.0759),
                new MapPoint(-2.6380, 56.0765),
                new MapPoint(-2.6380, 56.0784),
                new MapPoint(-2.6410, 56.0786)
            };

            // Create the polyline from the point collection
            Polygon polygon = new Polygon(points);

            // Create the graphic with polyline and symbol
            Graphic graphic = new Graphic(polygon, fillSymbol);

            // Add graphic to the graphics overlay
            _overlay.Graphics.Add(graphic);
        }
        private void CreatePolyline()
        {
            // Create a purple simple line symbol
            SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.FromRgb(0x80, 0x00, 0x80), 4);

            // Create a new point collection for polyline
            Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84)
            {
                // Create and add points to the point collection
                new MapPoint(-2.715, 56.061),
                new MapPoint(-2.6438, 56.079),
                new MapPoint(-2.638, 56.079),
                new MapPoint(-2.636, 56.078),
                new MapPoint(-2.636, 56.077),
                new MapPoint(-2.637, 56.076),
                new MapPoint(-2.715, 56.061)
            };

            // Create the polyline from the point collection
            Polyline polyline = new Polyline(points);

            // Create the graphic with polyline and symbol
            Graphic graphic = new Graphic(polyline, lineSymbol);

            // Add graphic to the graphics overlay
            _overlay.Graphics.Add(graphic);
        }
        public void OnLineWinOK(object parameter)
        {
            readytodrawLine  = false;
            _graphicsOverlay = tagView.GraphicsOverlays["drawGraphicsOverlay"];
            var tempgraphic = drawLineGraphic;

            _graphicsOverlay.Graphics.Remove(drawLineGraphic);

            SphereMarkerSymbol tagsymbol = App.Current.Resources["drawtoolLine"] as SphereMarkerSymbol;

            LineColor = parameter as SolidColorBrush;
            var linesym = new SimpleLineSymbol();

            linesym.Color = LineColor.Color;
            linesym.Width = linewidth;

            var sPointcollect = new Esri.ArcGISRuntime.Geometry.PointCollection();

            foreach (MapPoint tPoint in Linepointcollec)
            {
                MapPoint sPoint = new MapPoint(tPoint.X, tPoint.Y, drawLineZ);
                sPointcollect.Add(sPoint);
            }

            drawLineGraphic = new Graphic(new Polyline(sPointcollect), linesym);
            drawLineGraphic.Attributes["Label"] = Linegraphictext;
            _graphicsOverlay.Graphics.Add(drawLineGraphic);

            drawLineZ = 0;
            Linepointcollec.Clear();
            linewinshowing = false;
            LineWin.Close();

            return;
        }
        public void OnPolygonWinOK(object parameter)
        {
            readytodrawPolygon = false;
            _graphicsOverlay   = tagView.GraphicsOverlays["drawGraphicsOverlay"];
            var tempgraphic = drawPolygonGraphic;

            _graphicsOverlay.Graphics.Remove(drawPolygonGraphic);

            SphereMarkerSymbol tagsymbol = App.Current.Resources["drawtoolPolygon"] as SphereMarkerSymbol;

            PolygonColor = parameter as SolidColorBrush;
            var Polygonsym = new SimpleFillSymbol();

            Polygonsym.Color = PolygonColor.Color;

            var sPointcollect = new Esri.ArcGISRuntime.Geometry.PointCollection();

            foreach (MapPoint tPoint in Polygonpointcollec)
            {
                MapPoint sPoint = new MapPoint(tPoint.X, tPoint.Y, drawPolygonZ);
                sPointcollect.Add(sPoint);
            }

            drawPolygonGraphic = new Graphic(new Polygon(sPointcollect), Polygonsym);
            drawPolygonGraphic.Attributes["Label"] = Polygongraphictext;
            _graphicsOverlay.Graphics.Add(drawPolygonGraphic);

            drawPolygonZ = 0;
            Polygonpointcollec.Clear();
            Polygonwinshowing = false;
            PolygonWin.Close();

            return;
        }
Beispiel #9
0
        public static Graphic NewDonut(double x, double y, double innerRadius, double outerRadius)
        {
            double[] px = new double[NUM];
            double[] py = new double[NUM];
            GeometryAlgorithms.CircleToPoints(x, y, outerRadius, NUM, px, py, AngleDirection.CounterClockwise);

            Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            for (int i = 0; i < NUM; i++)
            {
                MapPoint p = new MapPoint(px[i], py[i]);
                pc.Add(p);
            }
            pc.Add(pc[0]);

            PolygonBuilder polygon = new PolygonBuilder(pc);

            GeometryAlgorithms.CircleToPoints(x, y, innerRadius, NUM, px, py, AngleDirection.Clockwise);
            pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            for (int i = 0; i < NUM; i++)
            {
                MapPoint p = new MapPoint(px[i], py[i]);
                pc.Add(p);
            }
            pc.Add(pc[0]);
            polygon.AddPart(pc);

            Graphic g = new Graphic();

            g.Geometry = polygon.ToGeometry();
            return(g);
        }
        private async Task ChangeMission(string mission)
        {
            // Stop animating the current mission
            _animationTimer.Stop();

            // Get mission data
            _missionData = GetMissionData(mission);

            // Draw mission route on the inset
            // Create a collection of points to hold the mission
            PointCollection points = new PointCollection(SpatialReferences.Wgs84);

            // Add all of the points from the mission to the point collection
            points.AddPoints(_missionData.Select(m => m.ToMapPoint()));
            // Create a polyline to symbolize the route from the point collection
            Polyline route = new Polyline(points);

            // Update the route graphic's geometry with the newly created route polyline
            _routeGraphic.Geometry = route;
            // Update the inset map's scale
            await InsetMapView.SetViewpointScaleAsync(100000);

            // Update animation parameters
            _frameCount = _missionData.Length;
            _keyframe   = 0;

            // Set the MissionPlayPause button back to the currently 'playing' state
            MissionPlayPause.Content = "Pause";

            // Restart the animation
            _animationTimer.Start();
        }
Beispiel #11
0
 public static Graphic NewLine(MapPoint p1, MapPoint p2)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
     pc.Add(p1);
     pc.Add(p2);
     return(NewPolyline(pc));
 }
Beispiel #12
0
        public static Graphic NewPolyline(Esri.ArcGISRuntime.Geometry.PointCollection pc)
        {
            Esri.ArcGISRuntime.Geometry.Polyline polyline = new Esri.ArcGISRuntime.Geometry.Polyline(pc);
            Graphic g = new Graphic();

            g.Geometry = polyline;
            return(g);
        }
Beispiel #13
0
        protected Polygon CreatePolygon(Esri.ArcGISRuntime.Geometry.PointCollection mappoints)
        {
            var poly = new Polygon(mappoints); // new List<Esri.ArcGISRuntime.Geometry.PointCollection> { points }, sref);

            GeometryEngine.BufferGeodetic(poly, 0, LinearUnits.Kilometers);
            //GeometryEngine.DensifyGeodetic(poly, 10, LinearUnits.Kilometers);
            return(poly);
        }
Beispiel #14
0
        // Project a point to polyline.
        // point: (p), polyline: (part)
        // output distance relative to the start point of the polyline: (distance)
        // output projection point: (outPnt)
        // return value:
        //      true: the point is projected on the polyline without extending the polyline
        //      false: the point is projected on the polyline through extending the polyline
        //
        public static bool ProjectPointToPolyline(MapPoint p,
                                                  IEnumerable <MapPoint> part,
                                                  ref double distance, ref MapPoint outPnt)
        {
            Esri.ArcGISRuntime.Geometry.PointCollection pts =
                new Esri.ArcGISRuntime.Geometry.PointCollection(part);

            distance = 0.0;
            SpatialReference sf = pts[0].SpatialReference;

            double   outx = 0.0, outy = 0.0;
            MapPoint p0, p1;

            for (int i = 0; i < pts.Count - 1; ++i)
            {
                p0 = pts[i];
                p1 = pts[i + 1];

                bool canProject = GeometryAlgorithms.ProjectPointToLine(p.X, p.Y,
                                                                        p0.X, p0.Y, p1.X, p1.Y, ref outx, ref outy);

                if (canProject == true)
                {
                    distance += GeometryAlgorithms.PointDistanceToPoint(outx, outy, p0.X, p0.Y);
                    outPnt    = new MapPoint(outx, outy, sf);
                    return(true);
                }
                distance += GeometryAlgorithms.PointDistanceToPoint(p0.X, p0.Y, p1.X, p1.Y);
            }

            // Project the point by extending the polyline
            p0 = pts[0];
            p1 = pts[pts.Count - 1];
            double d0p = GeometryAlgorithms.PointDistanceToPoint(p.X, p.Y, p0.X, p0.Y);
            double d1p = GeometryAlgorithms.PointDistanceToPoint(p.X, p.Y, p1.X, p1.Y);

            if (d0p < d1p)
            {
                // the map point is closer to the beginning of the polyline,
                // then extend the beginning segment.
                p1 = pts[1];
                GeometryAlgorithms.ProjectPointToLine(p.X, p.Y,
                                                      p0.X, p0.Y, p1.X, p1.Y, ref outx, ref outy);
                distance  = GeometryAlgorithms.PointDistanceToPoint(outx, outy, p0.X, p0.Y);
                distance *= -1.0;
                outPnt    = new MapPoint(outx, outy, sf);
            }
            else
            {
                // the map point is closer to the endding of the polyline,
                // since the loop is ended on the last segment, just use the result is OK.
                distance += GeometryAlgorithms.PointDistanceToPoint(outx, outy, p1.X, p1.Y);
                outPnt    = new MapPoint(outx, outy, sf);
            }

            return(false);
        }
        private void CreatePoints()
        {
            _coordinates = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);

            _coordinates.Add(new MapPoint(-106.981, 39.028, 6000, SpatialReferences.Wgs84));
            _coordinates.Add(new MapPoint(-106.956, 39.081, 6000, SpatialReferences.Wgs84));
            _coordinates.Add(new MapPoint(-106.869, 39.081, 6000, SpatialReferences.Wgs84));
            _coordinates.Add(new MapPoint(-106.879, 39.014, 6000, SpatialReferences.Wgs84));
        }
Beispiel #16
0
 public static Graphic NewTriangle(MapPoint p1, MapPoint p2, MapPoint p3)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
     pc.Add(p1);
     pc.Add(p2);
     pc.Add(p3);
     //pc.Add(p1);
     return(NewPolygon(pc));
 }
Beispiel #17
0
 // 编辑绘制图层
 private void EditVertexMenuItem_Click(object sender, RoutedEventArgs e)
 {
     if (curSelGraphic != null)//检查当前是否有选择图形
     {
         operation = OperateType.EditVertex;
         if (curSelGraphic.Geometry.GeometryType == GeometryType.Point) //所选图形为点
         {
             selVertexLayer.Graphics.Clear();                           //清空顶点图层
             MapPoint pt = (MapPoint)curSelGraphic.Geometry;
             Graphic  pg = new Graphic(pt, vertexSymbol);               //创建新的点图形
             selVertexLayer.Graphics.Add(pg);
         }
         else if (curSelGraphic.Geometry.GeometryType == GeometryType.Polyline)//所选图形为线
         {
             if (pointCollection != null)
             {
                 pointCollection.Clear();//清空点集
             }
             else
             {
                 pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference);
             }
             Esri.ArcGISRuntime.Geometry.Polyline ln = (Esri.ArcGISRuntime.Geometry.Polyline)curSelGraphic.Geometry;
             pointCollection.AddPoints(ln.Parts[0].Points);  //将线的所有顶点加入点集
             selVertexLayer.Graphics.Clear();
             for (int i = 0; i < pointCollection.Count; i++) //将所有点以顶点图形样式显示
             {
                 MapPoint pt = pointCollection[i];
                 Graphic  pg = new Graphic(pt, vertexSymbol);
                 selVertexLayer.Graphics.Add(pg);
             }
         }
         else if (curSelGraphic.Geometry.GeometryType == GeometryType.Polygon)//所选图形为多边形
         {
             if (pointCollection != null)
             {
                 pointCollection.Clear();
             }
             else
             {
                 pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference);
             }
             Esri.ArcGISRuntime.Geometry.Polygon pg = (Esri.ArcGISRuntime.Geometry.Polygon)curSelGraphic.Geometry;
             pointCollection.AddPoints(pg.Parts[0].Points);
             selVertexLayer.Graphics.Clear();
             for (int i = 0; i < pointCollection.Count; i++)
             {
                 MapPoint pt = pointCollection[i];
                 Graphic  gg = new Graphic(pt, vertexSymbol);
                 selVertexLayer.Graphics.Add(gg);
             }
         }
         EditVertexMenuItem.IsEnabled   = false;
         UneditVertexMenuItem.IsEnabled = true;
     }
 }
		private void CreatePoints()
		{
			_coordinates = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);
			
			_coordinates.Add(new MapPoint(-106.981, 39.028, 6000, SpatialReferences.Wgs84));
			_coordinates.Add(new MapPoint(-106.956, 39.081, 6000, SpatialReferences.Wgs84));
			_coordinates.Add(new MapPoint(-106.869, 39.081, 6000, SpatialReferences.Wgs84));
			_coordinates.Add(new MapPoint(-106.879, 39.014, 6000, SpatialReferences.Wgs84));
			
		}
Beispiel #19
0
 public static Graphic NewQuadrilateral(MapPoint p1, MapPoint p2, MapPoint p3, MapPoint p4)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
     pc.Add(p1);
     pc.Add(p2);
     pc.Add(p3);
     pc.Add(p4);
     //pc.Add(p1);
     return(NewPolygon(pc));
 }
        private void Initialize()
        {
            // Create a map with 'Imagery with Labels' basemap.
            Map myMap = new Map(Basemap.CreateStreetsVector());

            // Assign the map to the MapView.
            MyMapView.Map = myMap;

            // Create a center point for the graphics.
            MapPoint centerPoint = new MapPoint(-117.195800, 34.056295, SpatialReferences.Wgs84);

            // Create an envelope from that center point.
            Envelope pointExtent = new Envelope(centerPoint, .5, .5);

            //get the four corners of the extent
            MapPoint location1 = new MapPoint(pointExtent.XMax, pointExtent.YMax);
            MapPoint location2 = new MapPoint(pointExtent.XMax, pointExtent.YMin);
            MapPoint location3 = new MapPoint(pointExtent.XMin, pointExtent.YMax);
            MapPoint location4 = new MapPoint(pointExtent.XMin, pointExtent.YMin);


            // Create a collection of points in the extent
            Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(Calculate(location1, location2, location3, location4), SpatialReferences.Wgs84);

            // Create overlay to where graphics are shown.
            _graphicsOverlay = new GraphicsOverlay();

            // Add points to the graphics overlay.
            foreach (MapPoint point in points)
            {
                // Create new graphic and add it to the overlay.
                _graphicsOverlay.Graphics.Add(new Graphic(point));
            }

            // Create symbol for points.
            SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol()
            {
                Color = System.Drawing.Color.Yellow,
                Size  = 30,
                Style = SimpleMarkerSymbolStyle.Square
            };

            // Create simple renderer with symbol.
            SimpleRenderer renderer = new SimpleRenderer(pointSymbol);

            // Set renderer to graphics overlay.
            _graphicsOverlay.Renderer = renderer;

            // Add created overlay to the MapView.
            MyMapView.GraphicsOverlays.Add(_graphicsOverlay);

            // Center the MapView on the points.
            MyMapView.SetViewpointGeometryAsync(pointExtent, 50);
        }
        private void OnViewpointChanged(object sender, EventArgs e)
        {
            // Unhook the event
            MyMapView.ViewpointChanged -= OnViewpointChanged;

            // Get area that is shown in a MapView
            Polygon visibleArea = MyMapView.VisibleArea;

            // Get extent of that area
            Envelope extent = visibleArea.Extent;

            // Get central point of the extent
            MapPoint centerPoint = extent.GetCenter();

            // Create values inside the visible extent for creating graphic
            var extentWidth = extent.Width / 5;
            var extentHeight = extent.Height / 10;

            // Create point collection
            Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.WebMercator)
                {
                    new MapPoint(centerPoint.X - extentWidth * 2, centerPoint.Y - extentHeight * 2),
                    new MapPoint(centerPoint.X - extentWidth * 2, centerPoint.Y + extentHeight * 2),
                    new MapPoint(centerPoint.X + extentWidth * 2, centerPoint.Y + extentHeight * 2),
                    new MapPoint(centerPoint.X + extentWidth * 2, centerPoint.Y - extentHeight * 2)
                };

            // Create overlay to where graphics are shown
            GraphicsOverlay overlay = new GraphicsOverlay();

            // Add points to the graphics overlay
            foreach (var point in points)
            {
                // Create new graphic and add it to the overlay
                overlay.Graphics.Add(new Graphic(point));
            }

            // Create symbol for points
            SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol()
            {
                Color = Colors.Yellow,
                Size = 30,
                Style = SimpleMarkerSymbolStyle.Square,
            };

            // Create simple renderer with symbol
            SimpleRenderer renderer = new SimpleRenderer(pointSymbol);

            // Set renderer to graphics overlay
            overlay.Renderer = renderer;

            // Add created overlay to the MapView
            MyMapView.GraphicsOverlays.Add(overlay);
        }
Beispiel #22
0
        private void Draw(bool points, bool area)
        {
            System.Drawing.Color redColor  = System.Drawing.Color.FromName("Red");
            System.Drawing.Color blueColor = System.Drawing.Color.FromName("Blue");

            if (points)
            {
                foreach (Incident incident in personOfInterest.Incidents)
                {
                    //Create a point geometry
                    var point = new MapPoint(incident.XCoord, incident.YCoord, SpatialReferences.Wgs84);



                    //Create point symbol with outline
                    var pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, redColor, 10);
                    pointSymbol.Outline = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, blueColor, 2);

                    //Create point graphic with geometry & symbol
                    var pointGraphic = new Graphic(point, pointSymbol);

                    //Add point graphic to graphic overlay
                    MapGraphics.Graphics.Add(pointGraphic);
                }
            }



            if (area)
            {
                //Create polygon geometry
                var polygonPoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);

                foreach (Incident incident in personOfInterest.Incidents)
                {
                    polygonPoints.Add(new MapPoint(incident.XCoord, incident.YCoord));
                }

                var polygon = new Polygon(polygonPoints);

                System.Drawing.Color blueColorTrans = System.Drawing.Color.FromArgb(128, 0, 0, 255);


                //Create symbol for polygon with outline
                var polygonSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, blueColorTrans,
                                                         new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, redColor, 2));

                //Create polygon graphic with geometry and symbol
                Graphic polygonGraphic = new Graphic(polygon, polygonSymbol);

                //Add polygon graphic to graphics overlay
                MapGraphics.Graphics.Add(polygonGraphic);
            }
        }
        private void OnViewpointChanged(object sender, EventArgs e)
        {
            // Unhook the event
            MyMapView.ViewpointChanged -= OnViewpointChanged;

            // Get area that is shown in a MapView
            Polygon visibleArea = MyMapView.VisibleArea;

            // Get extent of that area
            Envelope extent = visibleArea.Extent;

            // Get central point of the extent
            MapPoint centerPoint = extent.GetCenter();

            // Create values inside the visible extent for creating graphic
            var extentWidth  = extent.Width / 5;
            var extentHeight = extent.Height / 10;

            // Create point collection
            Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.WebMercator)
            {
                new MapPoint(centerPoint.X - extentWidth * 2, centerPoint.Y - extentHeight * 2),
                new MapPoint(centerPoint.X - extentWidth * 2, centerPoint.Y + extentHeight * 2),
                new MapPoint(centerPoint.X + extentWidth * 2, centerPoint.Y + extentHeight * 2),
                new MapPoint(centerPoint.X + extentWidth * 2, centerPoint.Y - extentHeight * 2)
            };

            // Create overlay to where graphics are shown
            GraphicsOverlay overlay = new GraphicsOverlay();

            // Add points to the graphics overlay
            foreach (var point in points)
            {
                // Create new graphic and add it to the overlay
                overlay.Graphics.Add(new Graphic(point));
            }

            // Create symbol for points
            SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol()
            {
                Color = Color.Yellow,
                Size  = 30,
                Style = SimpleMarkerSymbolStyle.Square,
            };

            // Create simple renderer with symbol
            SimpleRenderer renderer = new SimpleRenderer(pointSymbol);

            // Set renderer to graphics overlay
            overlay.Renderer = renderer;

            // Add created overlay to the MapView
            MyMapView.GraphicsOverlays.Add(overlay);
        }
Beispiel #24
0
 public static IEnumerable <MapPoint> ChangeSpatialReference(
     IEnumerable <MapPoint> part,
     SpatialReference sr)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection points =
         new Esri.ArcGISRuntime.Geometry.PointCollection(sr);
     foreach (MapPoint p in part)
     {
         points.Add(ChangeSpatialReference(p, sr));
     }
     return(points);
 }
Beispiel #25
0
 private void DrawPolylineMenuItem_Click(object sender, RoutedEventArgs e)
 {
     operation = OperateType.DrawPolyline;
     if (pointCollection != null)
     {
         pointCollection.Clear();
     }
     else
     {
         pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference);
     }
 }
Beispiel #26
0
        public static double Length(Esri.ArcGISRuntime.Geometry.PointCollection pts)
        {
            double   len = 0;
            MapPoint p1, p2;

            for (int i = 0; i < pts.Count - 1; ++i)
            {
                p1   = pts[i];
                p2   = pts[i + 1];
                len += Distance(p1, p2);
            }
            return(len);
        }
Beispiel #27
0
        public static Graphic NewCircle(double x, double y, double r)
        {
            double[] px = new double[NUM];
            double[] py = new double[NUM];
            GeometryAlgorithms.CircleToPoints(x, y, r, NUM, px, py, AngleDirection.CounterClockwise);

            Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            for (int i = 0; i < NUM; i++)
            {
                MapPoint p = new MapPoint(px[i], py[i]);
                pc.Add(p);
            }
            pc.Add(pc[0]);

            return(NewPolygon(pc));
        }
Beispiel #28
0
        public static Graphic NewCircle(double x, double y, double r)
        {
            double[] px = new double[NUM];
            double[] py = new double[NUM];
            GeometryAlgorithms.CircleToPoints(x, y, r, NUM, px, py, AngleDirection.CounterClockwise);

            Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            for (int i = 0; i < NUM; i++)
            {
                MapPoint p = new MapPoint(px[i], py[i]);
                pc.Add(p);
            }
            pc.Add(pc[0]);

            return NewPolygon(pc);
        }
Beispiel #29
0
        private void init()
        {
            operation          = OperateType.None;
            pointSymbol        = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.FromArgb(0, 0, 0), 8.0);
            lineSymbol         = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 2.0);
            fillSymbol         = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.FromArgb(125, 255, 0, 0), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.FromArgb(0, 0, 0), 2.0));
            vertexSymbol       = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Square, Color.FromArgb(0, 0, 255), 8.0);
            curSelGraphic      = null;
            orgPoint           = null;
            selGracphicIndex   = -1;
            selPointIndex      = -1;
            listOfClipGraphics = new List <Graphic>();

            // 画点
            drawPoint.Checked += (sender, e) =>
            {
                operation = OperateType.DrawPoint;
            };

            // 画线
            drawLine.Checked += (sender, e) =>
            {
                operation = OperateType.DrawPolyline;
                if (pointCollection != null)
                {
                    pointCollection.Clear();
                }
                else
                {
                    pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference);
                }
            };

            // 画面
            drawPoly.Checked += (sender, e) =>
            {
                operation = OperateType.DrawPolygon;
                if (pointCollection != null)
                {
                    pointCollection.Clear();
                }
                else
                {
                    pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference);
                }
            };
        }
Beispiel #30
0
        // Draw horizontal distributed load
        // Note: x1<x2, (x1,y1)-(x2,y1) is a horizontal line, (x1,y2)-(x2,y3) is a oblique line
        //
        public static GraphicCollection DistributedLoad_Horizontal(double x1, double x2, double y1, double y2, double y3,
                                                                   Symbol backgroundFillSymbol, Symbol arrowFillSymbol, Symbol lineSymbol)
        {
            GraphicCollection gc = new GraphicCollection();

            MapPoint p1 = new MapPoint(x1, y1);
            MapPoint p2 = new MapPoint(x1, y2);
            MapPoint p3 = new MapPoint(x2, y3);
            MapPoint p4 = new MapPoint(x2, y1);
            Graphic  g  = ArcGISMappingUtility.NewQuadrilateral(p1, p2, p3, p4);

            g.Symbol = backgroundFillSymbol;
            gc.Add(g);

            Esri.ArcGISRuntime.Geometry.PointCollection pc =
                new Esri.ArcGISRuntime.Geometry.PointCollection();
            pc.Add(p1);
            pc.Add(p2);
            pc.Add(p3);
            pc.Add(p4);
            pc.Add(p1);
            g        = ArcGISMappingUtility.NewPolyline(pc);
            g.Symbol = lineSymbol;
            gc.Add(g);

            double x00, y00, y01;

            for (int i = 0; i <= 10; ++i)
            {
                x00 = x1 + i * (x2 - x1) / 10.0;
                y00 = y1;
                y01 = y2 + i * (y3 - y2) / 10.0;
                MapPoint p00 = new MapPoint(x00, y00);
                MapPoint p01 = new MapPoint(x00, y01);
                g        = ArcGISMappingUtility.NewLine(p00, p01);
                g.Symbol = lineSymbol;
                gc.Add(g);

                pc       = ArcGISMappingUtility.VectorArrowPoints(x00, y2, p00);
                g        = ArcGISMappingUtility.NewPolygon(pc);
                g.Symbol = arrowFillSymbol;
                gc.Add(g);
            }

            return(gc);
        }
Beispiel #31
0
        public static void Reverse(Esri.ArcGISRuntime.Geometry.PointCollection pts)
        {
            IEnumerable <MapPoint> reversedPts = pts.Reverse();

            Esri.ArcGISRuntime.Geometry.PointCollection newPts =
                new Esri.ArcGISRuntime.Geometry.PointCollection();
            foreach (MapPoint pt in reversedPts)
            {
                newPts.Add(pt);
            }

            pts.Clear();
            foreach (MapPoint pt in newPts)
            {
                pts.Add(pt);
            }
        }
Beispiel #32
0
        public Polygon CreateCirclePolygon(double lat, double lon, double radiuskm)
        {
            var mappoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);



            double lat_rad1; //outer ring
            double lon_rad1;

            for (var i = 0; i < 35; i++)
            {
                var theta = (float)(2 * Math.PI * i) / 35;
                //outer ring
                RadialToLatitudeLongitude(radiuskm, theta, lat * Math.PI / 180, lon * Math.PI / 180, out lat_rad1, out lon_rad1);

                mappoints.Add(lon_rad1 * 180.0 / Math.PI, lat_rad1 * 180.0 / Math.PI, 10);
            }

            return(new Polygon(mappoints));
        }
        private void Load3DLineLayer(object parameter)
        {
            var pointcollec = new Esri.ArcGISRuntime.Geometry.PointCollection();

            pointcollec.Add(new MapPoint(116.587, 39.852, 3000));
            pointcollec.Add(new MapPoint(116.587, 39.952, 3000));
            pointcollec.Add(new MapPoint(116.687, 39.952, 3000));
            pointcollec.Add(new MapPoint(116.687, 40.052, 3000));

            var line = new Esri.ArcGISRuntime.Geometry.Polyline(pointcollec, SpatialReferences.Wgs84);

            var graphicLayer = new GraphicsLayer();

            graphicLayer.DisplayName = "3D线图层";
            graphicLayer.ShowLegend  = false;
            graphicLayer.Graphics.Add(new Graphic(line));
            graphicLayer.Renderer = App.Current.Resources["LineSimpleRenderer"] as SimpleRenderer;
            graphicLayer.SceneProperties.SurfacePlacement = SurfacePlacement.Relative;
            graphicLayer.ID = "3DLineLayer";
            scene.Layers.Add(graphicLayer);
        }
        // Creates a square polygon with a hole centered at the given point
        private Polygon CreatePolygonBox(MapPoint center, double length)
        {
            var halfLen = length / 2.0;

            Geometry.PointCollection coords = new Geometry.PointCollection();
            coords.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));
            coords.Add(new MapPoint(center.X + halfLen, center.Y + halfLen));
            coords.Add(new MapPoint(center.X + halfLen, center.Y - halfLen));
            coords.Add(new MapPoint(center.X - halfLen, center.Y - halfLen));
            coords.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));

            halfLen /= 3;
            Geometry.PointCollection coordsHole = new Geometry.PointCollection();
            coordsHole.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));
            coordsHole.Add(new MapPoint(center.X - halfLen, center.Y - halfLen));
            coordsHole.Add(new MapPoint(center.X + halfLen, center.Y - halfLen));
            coordsHole.Add(new MapPoint(center.X + halfLen, center.Y + halfLen));
            coordsHole.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));

            return(new Polygon(new List <Geometry.PointCollection> {
                coords, coordsHole
            }, MyMapView.SpatialReference));
        }
		// Creates a square polygon with a hole centered at the given point
		private Polygon CreatePolygonBox(MapPoint center, double length)
		{
			var halfLen = length / 2.0;

			Geometry.PointCollection coords = new Geometry.PointCollection();
			coords.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));
			coords.Add(new MapPoint(center.X + halfLen, center.Y + halfLen));
			coords.Add(new MapPoint(center.X + halfLen, center.Y - halfLen));
			coords.Add(new MapPoint(center.X - halfLen, center.Y - halfLen));
			coords.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));

			halfLen /= 3;
			Geometry.PointCollection coordsHole = new Geometry.PointCollection();
			coordsHole.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));
			coordsHole.Add(new MapPoint(center.X - halfLen, center.Y - halfLen));
			coordsHole.Add(new MapPoint(center.X + halfLen, center.Y - halfLen));
			coordsHole.Add(new MapPoint(center.X + halfLen, center.Y + halfLen));
			coordsHole.Add(new MapPoint(center.X - halfLen, center.Y + halfLen));

			return new Polygon(new List<Geometry.PointCollection> { coords, coordsHole }, MyMapView.SpatialReference);
		}
Beispiel #36
0
        private  async void MouseRightButtonUp(object parameter)
        {
            Point curPoint = Mouse.GetPosition(tagView as FrameworkElement);
            MapPoint tagPoint = tagView.ScreenToLocation(curPoint);
            _graphicsOverlay = tagView.GraphicsOverlays["drawGraphicsOverlay"];
            var ga = await _graphicsOverlay.HitTestAsync(tagView, curPoint);
            if (ga != null)
            {
                if(ga.Geometry.GeometryType==GeometryType.Point)
                {
                    drawPointGraphic = ga;
                    drawpointX = (drawPointGraphic.Geometry as MapPoint).X;
                    drawpointY = (drawPointGraphic.Geometry as MapPoint).Y;
                    drawpointZ = (drawPointGraphic.Geometry as MapPoint).Z;

                    if(pointwinshowing==false)
                    {
                        pointWin = new PointToolWin();
                        pointwinshowing = true;
                        pointWin.ShowDialog();
                    }
                   
                }
                if (ga.Geometry.GeometryType == GeometryType.Polyline)
                {
                    drawLineGraphic = ga;
                    linegraphictext = drawLineGraphic.Attributes["Label"] as string;
                    linewidth = (drawLineGraphic.Symbol as SimpleLineSymbol).Width;
                    Esri.ArcGISRuntime.Geometry.PointCollection tagcol = new Esri.ArcGISRuntime.Geometry.PointCollection();
                    foreach (var part in (drawLineGraphic.Geometry as Polyline).Parts)
                    {
                        for(int i=0;i<part.Count;i++)
                        {
                            var linepart = part.ElementAt(i);
                            tagcol.Add(linepart.StartPoint);
                            if(i==(part.Count-1)) tagcol.Add(linepart.EndPoint);
                            drawLineZ = linepart.StartPoint.Z;
                        }
                    }
                    Linepointcollec = tagcol;

                    if(linewinshowing==false)
                    {
                        LineWin = new LineToolWin();
                        linewinshowing = true;
                        LineWin.ShowDialog();

                    }
                    
                }
                if (ga.Geometry.GeometryType == GeometryType.Polygon)
                {
                    drawPolygonGraphic = ga;
                    polygongraphictext = drawPolygonGraphic.Attributes["Label"] as string;
                    Esri.ArcGISRuntime.Geometry.PointCollection tagcol = new Esri.ArcGISRuntime.Geometry.PointCollection();
                    foreach (var part in (drawPolygonGraphic.Geometry as Polygon).Parts)
                    {
                        for (int i = 0; i < part.Count; i++)
                        {
                            var Polygonpart = part.ElementAt(i);
                            tagcol.Add(Polygonpart.StartPoint);
                            if (i == (part.Count - 1)) tagcol.Add(Polygonpart.EndPoint);
                            drawPolygonZ = Polygonpart.StartPoint.Z;
                        }
                    }
                    Polygonpointcollec = tagcol;

                    if(Polygonwinshowing==false)
                    {
                        PolygonWin = new PolygonToolWin();
                        Polygonwinshowing = true;
                        PolygonWin.ShowDialog();
                    }                   
                }
            }
        }
Beispiel #37
0
        public void OnLineWinOK(object parameter)
        {
            readytodrawLine = false;
            _graphicsOverlay = tagView.GraphicsOverlays["drawGraphicsOverlay"];
            var tempgraphic = drawLineGraphic;
            _graphicsOverlay.Graphics.Remove(drawLineGraphic);

            SphereMarkerSymbol tagsymbol = App.Current.Resources["drawtoolLine"] as SphereMarkerSymbol;
            LineColor = parameter as SolidColorBrush;
            var linesym = new SimpleLineSymbol();
            
            linesym.Color = LineColor.Color;
            linesym.Width = linewidth;

            var sPointcollect = new Esri.ArcGISRuntime.Geometry.PointCollection();

            foreach(MapPoint tPoint in Linepointcollec)
            {
                MapPoint sPoint = new MapPoint(tPoint.X, tPoint.Y, drawLineZ);
                sPointcollect.Add(sPoint);
            }

            drawLineGraphic = new Graphic(new Polyline(sPointcollect), linesym);
            drawLineGraphic.Attributes["Label"] = Linegraphictext;
            _graphicsOverlay.Graphics.Add(drawLineGraphic);

            drawLineZ = 0;
            Linepointcollec.Clear();
            linewinshowing = false;
            LineWin.Close();

            return;

        }
Beispiel #38
0
        public void OnPolygonWinOK(object parameter)
        {
            readytodrawPolygon = false;
            _graphicsOverlay = tagView.GraphicsOverlays["drawGraphicsOverlay"];
            var tempgraphic = drawPolygonGraphic;
            _graphicsOverlay.Graphics.Remove(drawPolygonGraphic);

            SphereMarkerSymbol tagsymbol = App.Current.Resources["drawtoolPolygon"] as SphereMarkerSymbol;
            PolygonColor = parameter as SolidColorBrush;
            var Polygonsym = new SimpleFillSymbol();

            Polygonsym.Color = PolygonColor.Color;

            var sPointcollect = new Esri.ArcGISRuntime.Geometry.PointCollection();

            foreach (MapPoint tPoint in Polygonpointcollec)
            {
                MapPoint sPoint = new MapPoint(tPoint.X, tPoint.Y, drawPolygonZ);
                sPointcollect.Add(sPoint);
            }

            drawPolygonGraphic = new Graphic(new Polygon(sPointcollect), Polygonsym);
            drawPolygonGraphic.Attributes["Label"] = Polygongraphictext;
            _graphicsOverlay.Graphics.Add(drawPolygonGraphic);

            drawPolygonZ = 0;
            Polygonpointcollec.Clear();
            Polygonwinshowing = false;
            PolygonWin.Close();

            return;

        }
Beispiel #39
0
        private void Load3DLineLayer(object parameter)
        {
            var pointcollec = new Esri.ArcGISRuntime.Geometry.PointCollection();

            pointcollec.Add(new MapPoint(116.587, 39.852, 3000));
            pointcollec.Add(new MapPoint(116.587, 39.952, 3000));
            pointcollec.Add(new MapPoint(116.687, 39.952, 3000));
            pointcollec.Add(new MapPoint(116.687, 40.052, 3000));

            var line = new Esri.ArcGISRuntime.Geometry.Polyline(pointcollec, SpatialReferences.Wgs84);

            var graphicLayer = new GraphicsLayer();
            graphicLayer.DisplayName = "3D线图层";
            graphicLayer.ShowLegend = false;
            graphicLayer.Graphics.Add(new Graphic(line));
            graphicLayer.Renderer = App.Current.Resources["LineSimpleRenderer"] as SimpleRenderer;
            graphicLayer.SceneProperties.SurfacePlacement = SurfacePlacement.Relative;
            graphicLayer.ID = "3DLineLayer";
            scene.Layers.Add(graphicLayer);
        }
Beispiel #40
0
 public static Graphic NewPentagon(MapPoint p1, MapPoint p2, MapPoint p3, MapPoint p4, MapPoint p5)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
     pc.Add(p1);
     pc.Add(p2);
     pc.Add(p3);
     pc.Add(p4);
     pc.Add(p5);
     //pc.Add(p1);
     return NewPolygon(pc);
 }
Beispiel #41
0
 public static Graphic NewLine(MapPoint p1, MapPoint p2)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
     pc.Add(p1);
     pc.Add(p2);
     return NewPolyline(pc);
 }
Beispiel #42
0
 public static IEnumerable<MapPoint> ChangeSpatialReference(
     IEnumerable<MapPoint> part,
     SpatialReference sr)
 {
     Esri.ArcGISRuntime.Geometry.PointCollection points = 
         new Esri.ArcGISRuntime.Geometry.PointCollection(sr);
     foreach (MapPoint p in part)
         points.Add(ChangeSpatialReference(p, sr));
     return points;
 }
Beispiel #43
0
        // Draw horizontal distributed load
        // Note: x1<x2, (x1,y1)-(x2,y1) is a horizontal line, (x1,y2)-(x2,y3) is a oblique line
        //
        public static GraphicCollection DistributedLoad_Horizontal(double x1, double x2, double y1, double y2, double y3,
            Symbol backgroundFillSymbol, Symbol arrowFillSymbol, Symbol lineSymbol)
        {
            GraphicCollection gc = new GraphicCollection();

            MapPoint p1 = new MapPoint(x1, y1);
            MapPoint p2 = new MapPoint(x1, y2);
            MapPoint p3 = new MapPoint(x2, y3);
            MapPoint p4 = new MapPoint(x2, y1);
            Graphic g = ArcGISMappingUtility.NewQuadrilateral(p1, p2, p3, p4);
            g.Symbol = backgroundFillSymbol;
            gc.Add(g);

            Esri.ArcGISRuntime.Geometry.PointCollection pc =
                new Esri.ArcGISRuntime.Geometry.PointCollection();
            pc.Add(p1);
            pc.Add(p2);
            pc.Add(p3);
            pc.Add(p4);
            pc.Add(p1);
            g = ArcGISMappingUtility.NewPolyline(pc);
            g.Symbol = lineSymbol;
            gc.Add(g);

            double x00, y00, y01;
            for (int i = 0; i <= 10; ++i)
            {
                x00 = x1 + i * (x2 - x1) / 10.0;
                y00 = y1;
                y01 = y2 + i * (y3 - y2) / 10.0;
                MapPoint p00 = new MapPoint(x00, y00);
                MapPoint p01 = new MapPoint(x00, y01);
                g = ArcGISMappingUtility.NewLine(p00, p01);
                g.Symbol = lineSymbol;
                gc.Add(g);

                pc = ArcGISMappingUtility.VectorArrowPoints(x00, y2, p00);
                g = ArcGISMappingUtility.NewPolygon(pc);
                g.Symbol = arrowFillSymbol;
                gc.Add(g);
            }

            return gc;
        }
Beispiel #44
0
            VectorArrowPoints(double beginPntX, double beginPntY, MapPoint endPnt)
        {
            double x = beginPntX - endPnt.X;
            double y = beginPntY - endPnt.Y;
            double angle = Math.Atan2(y, x);

            double alpha = Math.PI / 6;                         // arrow is 30 degree by each side of original line
            double length = Math.Sqrt(x * x + y * y) * 0.25;      // arrow is a quarter of original length 

            MapPointBuilder p1 = new MapPointBuilder(endPnt);
            MapPointBuilder p2 = new MapPointBuilder(endPnt);
            p1.X += length * Math.Cos(angle + alpha);
            p1.Y += length * Math.Sin(angle + alpha);
            p2.X += length * Math.Cos(angle - alpha);
            p2.Y += length * Math.Sin(angle - alpha);

            Esri.ArcGISRuntime.Geometry.PointCollection pc = new Esri.ArcGISRuntime.Geometry.PointCollection();
            pc.Add(p1.ToGeometry());
            pc.Add(endPnt);
            pc.Add(p2.ToGeometry());

            return pc;
        }
Beispiel #45
0
        public static void Reverse(Esri.ArcGISRuntime.Geometry.PointCollection pts)
        {
            IEnumerable<MapPoint> reversedPts = pts.Reverse();

            Esri.ArcGISRuntime.Geometry.PointCollection newPts =
                new Esri.ArcGISRuntime.Geometry.PointCollection();
            foreach (MapPoint pt in reversedPts)
                newPts.Add(pt);

            pts.Clear();
            foreach (MapPoint pt in newPts)
                pts.Add(pt);
        }
Beispiel #46
0
        // Project a point to polyline.
        // point: (p), polyline: (part)
        // output distance relative to the start point of the polyline: (distance)
        // output projection point: (outPnt)
        // return value:
        //      true: the point is projected on the polyline without extending the polyline
        //      false: the point is projected on the polyline through extending the polyline
        //
        public static bool ProjectPointToPolyline(MapPoint p,
            IEnumerable<MapPoint> part,
            ref double distance, ref MapPoint outPnt)
        {
            Esri.ArcGISRuntime.Geometry.PointCollection pts =
                new Esri.ArcGISRuntime.Geometry.PointCollection(part);

            distance = 0.0;
            SpatialReference sf = pts[0].SpatialReference;

            double outx = 0.0, outy = 0.0;
            MapPoint p0, p1;
            for (int i = 0; i < pts.Count - 1; ++i)
            {
                p0 = pts[i];
                p1 = pts[i + 1];

                bool canProject = GeometryAlgorithms.ProjectPointToLine(p.X, p.Y,
                    p0.X, p0.Y, p1.X, p1.Y, ref outx, ref outy);

                if (canProject == true)
                {
                    distance += GeometryAlgorithms.PointDistanceToPoint(outx, outy, p0.X, p0.Y);
                    outPnt = new MapPoint(outx, outy, sf);
                    return true;
                }
                distance += GeometryAlgorithms.PointDistanceToPoint(p0.X, p0.Y, p1.X, p1.Y);
            }

            // Project the point by extending the polyline
            p0 = pts[0];
            p1 = pts[pts.Count - 1];
            double d0p = GeometryAlgorithms.PointDistanceToPoint(p.X, p.Y, p0.X, p0.Y);
            double d1p = GeometryAlgorithms.PointDistanceToPoint(p.X, p.Y, p1.X, p1.Y);
            if (d0p < d1p)
            {
                // the map point is closer to the beginning of the polyline,
                // then extend the beginning segment.
                p1 = pts[1];
                GeometryAlgorithms.ProjectPointToLine(p.X, p.Y,
                    p0.X, p0.Y, p1.X, p1.Y, ref outx, ref outy);
                distance = GeometryAlgorithms.PointDistanceToPoint(outx, outy, p0.X, p0.Y);
                distance *= -1.0;
                outPnt = new MapPoint(outx, outy, sf);
            }
            else
            {
                // the map point is closer to the endding of the polyline,
                // since the loop is ended on the last segment, just use the result is OK.
                distance += GeometryAlgorithms.PointDistanceToPoint(outx, outy, p1.X, p1.Y);
                outPnt = new MapPoint(outx, outy, sf);
            }

            return false;
        }