Beispiel #1
0
        private async Task DrawPolyline(List <BasicGeoposition> geopositions)
        {
            SegmentMap.MapElements.Clear();

            if (geopositions.Any())
            {
                if (ExpandMapButton == null)
                {
                    FindName("ExpandMapButton");
                }
                else
                {
                    ExpandMapButton.Visibility = Visibility.Visible;
                }

                var polyLine = new MapPolyline {
                    Path = new Geopath(geopositions), StrokeThickness = 4, StrokeColor = (Color)App.Current.Resources["StravaRedColor"]
                };
                SegmentMap.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"));
                SegmentMap.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"));
                SegmentMap.MapElements.Add(endMapIcon);

                var zoomed = false;
                while (!zoomed)
                {
                    zoomed = await SegmentMap.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geopositions), null, MapAnimationKind.None);
                }
            }
            else
            if (ExpandMapButton != null)
            {
                ExpandMapButton.Visibility = Visibility.Collapsed;
            }
        }