本文整理汇总了C#中MapView.ToView方法的典型用法代码示例。如果您正苦于以下问题:C# MapView.ToView方法的具体用法?C# MapView.ToView怎么用?C# MapView.ToView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapView
的用法示例。
在下文中一共展示了MapView.ToView方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainPage
public MainPage()
{
// Be sure to register your license in native code or in an #if case.
// Even if your package names are identical, licenses are platform-specific.
// This sample register's license in App.xaml.cs
AbsoluteLayout view = new AbsoluteLayout();
// Since MapView is a native element, initialize and set its size natively
// minimal platform-specific code is needed to create MapView
#if __ANDROID__
MapView = new MapView(Xamarin.Forms.Forms.Context);
#elif WINDOWS_PHONE
MapView = new MapView();
Windows.Foundation.Rect bounds = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds;
MapView.Width = bounds.Width;
MapView.Height = bounds.Height;
#elif __IOS__
MapView = new MapView();
// Set ScreenBounds in AppDelegate so they would be conveniently available here
MapView.Frame = iOS.AppDelegate.ScreenBounds;
#endif
// all the remaining usage of MapView is cross-platform
view.Children.Add(MapView.ToView());
Content = view;
// Add default base layer
var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);
MapView.Layers.Add(baseLayer);
// Set projection
Projection projection = MapView.Options.BaseProjection;
// Set default position and zoom
// Change projection of map so coordinates would fit on a mercator map
MapPos berlin = MapView.Options.BaseProjection.FromWgs84(new MapPos(13.38933, 52.51704));
MapView.SetFocusPos(berlin, 0);
MapView.SetZoom(10, 0);
// Custom extension method. cf Extensions.cs
MapView.AddMarkerToPosition(berlin);
// Good place to set the sizes and positions of Children,
// similar to LayoutSubviews of iOS and OnLayout of Android
view.SizeChanged += OnSizeChanged;
Button button = new Button();
button.BackgroundColor = Color.FromRgb(117, 58, 97);
button.TextColor = Color.White;
button.Text = "Hide Marker";
button.VerticalOptions = LayoutOptions.EndAndExpand;
button.HorizontalOptions = LayoutOptions.EndAndExpand;
view.Children.Add(button);
button.Clicked += OnButtonClick;
}