[英]Xamarin.Forms.Maps in CarouselView: Route not shown directly
I have a problem with displaying a route in a map on a carouselView.我在 carouselView 上的 map 中显示路线时遇到问题。
I have the carouselview in my VireModel binded to a cotentview我将 VireModel 中的 carouselview 绑定到 cotentview
private ContentView carousel;
public ContentView Carousel
{
get { return carousel; }
set
{
if (carousel != value)
{
carousel = value;
OnPropertyChanged("Carousel");
}
}
}
I give it the following contentViews as items我给它以下 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() is implemented like this: 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;
}
The problem is that if the page is open in the app the map is zoomed out completly.问题是如果页面在应用程序中打开,map 会完全缩小。 If I swipe trough the carousel on time completly I see the Route and the MapSpan is correct.
如果我按时完整地刷过旋转木马,我会看到 Route 并且 MapSpan 是正确的。
here is a gif of the problem这是问题的 gif
Please add map.MoveToRegion(mapSpan);
请添加
map.MoveToRegion(mapSpan);
in your MapView
's method.在您的
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.