private void CreateOverlay()
        {
            // Create polygon builder and add polygon corners into it
            PolygonBuilder builder = new PolygonBuilder(SpatialReferences.WebMercator);
            builder.AddPoint(new MapPoint(-20e5, 20e5));
            builder.AddPoint(new MapPoint(20e5, 20e5));
            builder.AddPoint(new MapPoint(20e5, -20e5));
            builder.AddPoint(new MapPoint(-20e5, -20e5));

            // Get geometry from the builder
            Polygon polygonGeometry = builder.ToGeometry();

            // Create symbol for the polygon
            SimpleFillSymbol polygonSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid,
                System.Drawing.Color.Yellow,
                null);

            // Create new graphic
            Graphic polygonGraphic = new Graphic(polygonGeometry, polygonSymbol);

            // Create overlay to where graphics are shown
            _polygonOverlay = new GraphicsOverlay();
            _polygonOverlay.Graphics.Add(polygonGraphic);

            // Add created overlay to the MapView
            _myMapView.GraphicsOverlays.Add(_polygonOverlay);
        }
        private void CreateOverlay()
        {
            // Create polygon builder and add polygon corners into it.
            PolygonBuilder builder = new PolygonBuilder(SpatialReferences.WebMercator);

            builder.AddPoint(new MapPoint(-20e5, 20e5));
            builder.AddPoint(new MapPoint(20e5, 20e5));
            builder.AddPoint(new MapPoint(20e5, -20e5));
            builder.AddPoint(new MapPoint(-20e5, -20e5));

            // Get geometry from the builder.
            Polygon polygonGeometry = builder.ToGeometry();

            // Create symbol for the polygon.
            SimpleFillSymbol polygonSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid,
                System.Drawing.Color.Yellow,
                null);

            // Create new graphic.
            Graphic polygonGraphic = new Graphic(polygonGeometry, polygonSymbol);

            // Create overlay to where graphics are shown.
            _polygonOverlay = new GraphicsOverlay();
            _polygonOverlay.Graphics.Add(polygonGraphic);

            // Add created overlay to the MapView.
            _myMapView.GraphicsOverlays.Add(_polygonOverlay);
        }
        private Geometry polygonForStartingPoint(MapPoint mapPoint)
        {
            var polygon = new PolygonBuilder(SpatialReferences.Wgs84);

            polygon.AddPoint(mapPoint.X, mapPoint.Y);
            polygon.AddPoint(mapPoint.X, mapPoint.Y + squareSize);
            polygon.AddPoint(mapPoint.X + squareSize, mapPoint.Y + squareSize);
            polygon.AddPoint(mapPoint.X + squareSize, mapPoint.Y);

            return(polygon.ToGeometry());
        }
Example #4
0
        public void createPolygon(GraphicsOverlay myGraphicsOverlay)
        {
            var rec   = new PolygonBuilder(SpatialReferences.Wgs84);
            var lnSym = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Red, 2);

            rec.AddPoint(new MapPoint(xMin, yMin));
            rec.AddPoint(new MapPoint(xMin, yMax));
            rec.AddPoint(new MapPoint(xMax, yMax));
            rec.AddPoint(new MapPoint(xMax, yMin));
            myGraphicsOverlay.Graphics.Add(new Graphic(rec.ToGeometry(), lnSym));
            _geom = rec.ToGeometry();
        }
Example #5
0
 private void MySceneView_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (type == "line" && mapPoint_list.Count != 0)
     {
         BorderContentText.Visibility = Visibility.Visible;
         var boatPositions = new PolylineBuilder(SpatialReferences.Wgs84);
         for (var i = 0; i < mapPoint_list.Count; i++)
         {
             boatPositions.AddPoint(new MapPoint(mapPoint_list[i].X, mapPoint_list[i].Y));
         }
         var boatRoute = boatPositions.ToGeometry();
         _mapViewModel.Line(boatRoute, "line");
         LineText.Text = "Line Length: " + GeometryEngine.LengthGeodetic(boatRoute).ToString("N2") + " meters";
     }
     else if (type == "area" && mapPoint_list.Count != 0)
     {
         BorderContentText.Visibility = Visibility.Visible;
         var boatPositions = new PolygonBuilder(SpatialReferences.Wgs84);
         for (var i = 0; i < mapPoint_list.Count; i++)
         {
             boatPositions.AddPoint(new MapPoint(mapPoint_list[i].X, mapPoint_list[i].Y));
         }
         var boatRoute = boatPositions.ToGeometry();
         _mapViewModel.Area(boatRoute);
         AreaText.Text = "Area Size: " + GeometryEngine.AreaGeodetic(boatRoute).ToString("N2") + "  square meters";
     }
     mapPoint_list.Clear();
 }
Example #6
0
        public void ZoomToEnvelope(double xMin, double yMin, double xMax, double yMax, MapView MyMapView)
        {
            var p1     = new PolygonBuilder(SpatialReferences.Wgs84);
            var lnSym1 = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Colors.Yellow, 2);

            p1.AddPoint(xMin, yMin);
            p1.AddPoint(xMin, yMax);
            p1.AddPoint(180, yMax);
            p1.AddPoint(180, yMin);
            var rec = new Graphic(p1.ToGeometry(), lnSym1);

            graphicsOverlay2.Graphics.Add(rec);

            Envelope envelope = new Envelope(xMin + 1.6, yMin, 180.0, yMax, SpatialReferences.Wgs84);

            MyMapView.SetViewpointGeometryAsync(envelope);
        }
Example #7
0
        private Polygon ToPolygon(Polyline line)
        {
            var builder = new PolygonBuilder(SpatialReferences.WebMercator);

            if (line.Parts != null && line.Parts.Count > 0)
            {
                foreach (var point in line.Parts[0].GetPoints())
                {
                    builder.AddPoint(point);
                }
            }
            return(builder.ToGeometry());
        }
        public static async Task <Polygon> DrawPolygonAsync(MapView sceneView, System.Threading.CancellationToken cancellationToken)
        {
            var            tcs            = new TaskCompletionSource <Polygon>();
            PolygonBuilder polygonBuilder = new PolygonBuilder(sceneView.SpatialReference);
            var            sketchlayer    = CreateSketchLayer(sceneView);
            Graphic        polygonGraphic = new Graphic()
            {
                Symbol = DefaultFillSymbol
            };
            Graphic lineMoveGraphic = new Graphic()
            {
                Symbol = DefaultLineMoveSymbol
            };

            sketchlayer.Graphics.AddRange(new Graphic[] { polygonGraphic, lineMoveGraphic });
            Action cleanupEvents = SetUpHandlers(sceneView,
                                                 (p) => //On mouse move move completion line around
            {
                if (p != null && polygonBuilder.Parts.Count > 0)
                {
                    lineMoveGraphic.Geometry = new Polyline(new MapPoint[]
                    {
                        polygonBuilder.Parts[0].Last().EndPoint,
                        p,
                        polygonBuilder.Parts[0].First().StartPoint
                    });
                }
            },
                                                 (p) => //On tap add a vertex
            {
                if (p != null)
                {
                    polygonBuilder.AddPoint(p);
                    if (polygonBuilder.Parts.Count > 0 && polygonBuilder.Parts[0].Count > 0)
                    {
                        polygonGraphic.Geometry  = polygonBuilder.ToGeometry();
                        lineMoveGraphic.Geometry = null;
                    }
                }
            },
                                                 (p) => //View tapped - completes task and returns point
            {
                tcs.SetResult(polygonBuilder.ToGeometry());
            });
            Action cleanup = () =>
            {
                cleanupEvents();
                sceneView.GraphicsOverlays.Remove(sketchlayer);
            };

            cancellationToken.Register(() => tcs.SetCanceled());

            Polygon result = null;

            try
            {
                result = await tcs.Task;
            }
            finally
            {
                cleanup();
            }

            return(result);
        }
		public static async Task<Polygon> DrawPolygonAsync(SceneView sceneView, System.Threading.CancellationToken cancellationToken)
		{
			var tcs = new TaskCompletionSource<Polygon>();
			PolygonBuilder polygonBuilder = new PolygonBuilder(sceneView.SpatialReference);
			var sketchlayer = CreateSketchLayer(sceneView);
			Graphic polygonGraphic = new Graphic() { Symbol = DefaultFillSymbol };
			Graphic lineMoveGraphic = new Graphic() { Symbol = DefaultLineMoveSymbol };
			sketchlayer.Graphics.AddRange(new Graphic[] { polygonGraphic, lineMoveGraphic });
			Action cleanupEvents = SetUpHandlers(sceneView,
				(p) => //On mouse move move completion line around
				{
					if (p != null && polygonBuilder.Parts.Count > 0)
					{
						lineMoveGraphic.Geometry = new Polyline(new MapPoint[] 
							{
								 polygonBuilder.Parts[0].Last().EndPoint, 
								 p, 
								 polygonBuilder.Parts[0].First().StartPoint 
							});
					}
				},
				(p) => //On tap add a vertex
				{
					if (p != null)
					{
						polygonBuilder.AddPoint(p);
						if (polygonBuilder.Parts.Count > 0 && polygonBuilder.Parts[0].Count > 0)
						{
							polygonGraphic.Geometry = polygonBuilder.ToGeometry();
							lineMoveGraphic.Geometry = null;
						}
					}
				},
				(p) => //View tapped - completes task and returns point
				{
					tcs.SetResult(polygonBuilder.ToGeometry());
				});
			Action cleanup = () =>
			{
				cleanupEvents();
				sceneView.GraphicsOverlays.Remove(sketchlayer);
			};
			cancellationToken.Register(() => tcs.SetCanceled());

			Polygon result = null;
			try
			{
				result = await tcs.Task;
			}
			finally
			{
				cleanup();
			}

			return result;
		}