Пример #1
0
        private async void DrawPolyline(List <BasicGeoposition> geopositions)
        {
            ActivityMap.MapElements.Clear();

            if (geopositions.Any())
            {
                var polyLine = new MapPolyline {
                    Path = new Geopath(geopositions), StrokeThickness = 4, StrokeColor = (Color)App.Current.Resources["StravaRedColor"]
                };
                ActivityMap.MapElements.Add(polyLine);

                MapIcon startMapIcon = new MapIcon();
                startMapIcon.Location = new Geopoint(geopositions.First());
                startMapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                startMapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Start.png"));
                ActivityMap.MapElements.Add(startMapIcon);

                MapIcon endMapIcon = new MapIcon();
                endMapIcon.Location = new Geopoint(geopositions.Last());
                endMapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
                endMapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/End.png"));
                ActivityMap.MapElements.Add(endMapIcon);

                var zoomed = false;
                while (!zoomed)
                {
                    zoomed = await ActivityMap.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geopositions), null, MapAnimationKind.None);
                }
            }
        }
Пример #2
0
        private async Task DrawPolylineAsync()
        {
            var geoPositions = new List <BasicGeoposition>
            {
                new BasicGeoposition {
                    Latitude = -37.88385, Longitude = 145.18219
                },
                new BasicGeoposition {
                    Latitude = -37.88334, Longitude = 145.17769
                },
                new BasicGeoposition {
                    Latitude = -37.88385, Longitude = 145.17745
                },
                new BasicGeoposition {
                    Latitude = -37.88336, Longitude = 145.17674
                },
                new BasicGeoposition {
                    Latitude = -37.88268, Longitude = 145.17029
                },
                new BasicGeoposition {
                    Latitude = -37.88148, Longitude = 145.17013
                },
                new BasicGeoposition {
                    Latitude = -37.88081, Longitude = 145.16776
                },
                new BasicGeoposition {
                    Latitude = -37.88066, Longitude = 145.16563
                },
                new BasicGeoposition {
                    Latitude = -37.87992, Longitude = 145.16356
                }
            };

            var polyLine = new MapPolyline
            {
                Path            = new Geopath(geoPositions),
                StrokeThickness = 4,
                StrokeDashed    = false,
                StrokeColor     = Color.FromArgb(200, 245, 51, 39)
            };

            ActivityMap.MapElements.Add(polyLine);

            var startPoint = new Button {
                Style = (Style)App.Current.Resources["ButtonMapPointStyle"]
            };

            ActivityMap.Children.Add(startPoint);
            MapControl.SetLocation(startPoint, new Geopoint(geoPositions.First()));
            MapControl.SetNormalizedAnchorPoint(startPoint, new Point(0.5, 0.5));

            var endPoint = new Button {
                Style = (Style)App.Current.Resources["ButtonMapPinStyle"]
            };

            ActivityMap.Children.Add(endPoint);
            MapControl.SetLocation(endPoint, new Geopoint(geoPositions.Last()));
            MapControl.SetNormalizedAnchorPoint(endPoint, new Point(0.5, 0.5));

            var margin = ActualWidth / 4;
            await ActivityMap.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geoPositions),
                                                    new Thickness(margin, margin, margin, margin), MapAnimationKind.Bow);
        }