示例#1
0
        // -------------------- DRAWING STUFF ON THE MAP -----------------------

        private async void DrawPoints(object sender, RoutedEventArgs e)
        {
            // How to draw a new MapIcon with a label, anchorpoint and custom icon.
            // Icon comes from project assets
            var anchorPoint = new Point(0.5, 0.5);
            var image       = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/wplogo.png"));

            // Helper extension method
            try
            {
                var area = MyMap.GetViewArea();

                // PointList is just a helper class that gives 'some data'
                var points = PointList.GetRandomPoints(
                    new Geopoint(area.NorthwestCorner), new Geopoint(area.SoutheastCorner),
                    50);
                foreach (var dataObject in points)
                {
                    var shape = new MapIcon
                    {
                        Title    = dataObject.Name,
                        Location = new Geopoint(dataObject.Points.First()),
                        NormalizedAnchorPoint = anchorPoint,
                        Image = image,
                        CollisionBehaviorDesired =
                            onCollisionShow? MapElementCollisionBehavior.RemainVisible :
                            MapElementCollisionBehavior.Hide,

                        ZIndex = 3,
                    };
                    shape.AddData(dataObject);

                    MyMap.MapElements.Add(shape);
                }
            }
            catch (Exception)
            {
                var dialog = new MessageDialog("GetViewArea error");
                await dialog.ShowAsync();
            }
        }
示例#2
0
        private void DrawLines(object sender, RoutedEventArgs e)
        {
            if (!DeleteShapesFromLevel(2))
            {
                var strokeColor = Colors.Green;
                strokeColor.A = 200;

                //Drawing lines, notice the use of Geopath. Consists out of BasicGeopositions
                foreach (var dataObject in PointList.GetLines())
                {
                    var shape = new MapPolyline
                    {
                        StrokeThickness = 9,
                        StrokeColor     = strokeColor,
                        StrokeDashed    = false,
                        ZIndex          = 2,
                        Path            = new Geopath(dataObject.Points)
                    };
                    shape.AddData(dataObject);

                    MyMap.MapElements.Add(shape);
                }
            }
        }
        /// <summary>
        /// Get 50 random point in the view
        /// </summary>
        public static IEnumerable<PointList> GetRandomPoints(Geopoint point1, Geopoint point2, int nrOfPoints)
        {
            var result = new List<PointList>();
              var p1 = new BasicGeoposition
              {
            Latitude = Math.Min(point1.Position.Latitude, point2.Position.Latitude),
            Longitude = Math.Min(point1.Position.Longitude, point2.Position.Longitude)
              };
              var p2 = new BasicGeoposition
              {
            Latitude = Math.Max(point1.Position.Latitude, point2.Position.Latitude),
            Longitude = Math.Max(point1.Position.Longitude, point2.Position.Longitude)
              };

              var dLat = p2.Latitude - p1.Latitude;
              var dLon = p2.Longitude - p1.Longitude;

              var r = new Random(DateTime.Now.Millisecond);
              for (var i = 0; i < nrOfPoints; i++)
              {
            var item = new PointList { Name = "Point " + i };
            item.Points.Add(
              new BasicGeoposition
              {
            Latitude = p1.Latitude + (r.NextDouble() * dLat),
            Longitude = p1.Longitude + (r.NextDouble() * dLon),
            Altitude = 1000 * r.NextDouble()
              });
            result.Add(item);
              }
              return result;
        }