0

我在 carouselView 的地图中显示路线时遇到问题。

设置

我将 VireModel 中的 carouselview 绑定到 cotentview

        private ContentView carousel;
        public ContentView Carousel
        {
            get { return carousel; }
            set
            {
                if (carousel != value)
                {
                    carousel = value;
                    OnPropertyChanged("Carousel");
                }
            }
        }

我给它以下 contentViews 作为项目

        private void InitializeCarousel()
        {
            Carousel = new ContentView()
            {
                Content = CarouselView()
            };
        }

        private CarouselView CarouselView()
        {
            ContentView[] items = CarouselItems();


            CarouselView carouselView = new CarouselView()
            {

                ItemsSource = items,
                IndicatorView = indicatorView,
                ItemTemplate = viewDataTemplate
            };

            return carouselView;
        }

        private ContentView[] CarouselItems()
        {
            ContentView[] items = new ContentView[5] 
            {
                 MapView(), SpeedView(), PaceView(), HeightView(), StepLengthView() 
            };


            return items;

        }

MapView()是这样实现的:

        private ContentView MapView()
        {
            
            Polygon route = new Polygon
            {
                StrokeWidth = 8,
                StrokeColor = Color.FromHex("#1BA1E2"),
                Geopath =
                {
                    new Position(47.6368678, -122.137305),
                    new Position(47.6368894, -122.134655),
                    new Position(47.6359424, -122.134655),
                    new Position(47.6359496, -122.1325521),
                    new Position(47.6424124, -122.1325199),
                    new Position(47.642463,  -122.1338932),
                    new Position(47.6406414, -122.1344833),
                    new Position(47.6384943, -122.1361248),
                    new Position(47.6372943, -122.1376912)
                }
            };

            MapSpan span = new MapSpan(new Position(47.6368678, -122.137305), 0.02, 0.02);
            
            Map map = new Map(span)
            {
                HasScrollEnabled = false,
                HasZoomEnabled = false,
            };

            map.MapElements.Add(route);

            ContentView view = new ContentView()
            {
                Content = map
            };

            return view;
        }

问题

问题是,如果页面在应用程序中打开,则地图会完全缩小。如果我按时完整地刷过旋转木马,我会看到 Route 并且 MapSpan 是正确的。

  1. 第一的:

在此处输入图像描述

  1. 刷完旋转木马后

在此处输入图像描述

编辑

这是问题的 gif

在此处输入图像描述

4

1 回答 1

0

请添加map.MoveToRegion(mapSpan);MapView的方法。

 private ContentView MapView()
        {
            
            Polygon route = new Polygon
            {
                StrokeWidth = 8,
                StrokeColor = Color.FromHex("#1BA1E2"),
                Geopath =
                {
                    new Position(47.6368678, -122.137305),
                    new Position(47.6368894, -122.134655),
                    new Position(47.6359424, -122.134655),
                    new Position(47.6359496, -122.1325521),
                    new Position(47.6424124, -122.1325199),
                    new Position(47.642463,  -122.1338932),
                    new Position(47.6406414, -122.1344833),
                    new Position(47.6384943, -122.1361248),
                    new Position(47.6372943, -122.1376912)
                }
            };

            MapSpan span = new MapSpan(new Position(47.6368678, -122.137305), 0.02, 0.02);
            
            Map map = new Map(span)
            {
                HasScrollEnabled = false,
                HasZoomEnabled = false,
            };

            map.MapElements.Add(route);
           
            ContentView view = new ContentView()
            {
                Content = map
            };
            map.MoveToRegion(mapSpan);
            return view;
        }

于 2021-03-05T12:17:30.770 回答