// Invoked when the application is launched normally by the end user. protected override void OnLaunched(LaunchActivatedEventArgs e) { // Register CARTO license bool registered = MapView.RegisterLicense(License); if (registered) { Carto.Utils.Log.ShowDebug = true; } MapView = new MapView(); // Add base map // TODO: Crashes here for some reason CartoOnlineVectorTileLayer baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDark); MapView.Layers.Add(baseLayer); // Set default location and zoom Projection projection = MapView.Options.BaseProjection; MapPos tallinn = projection.FromWgs84(new MapPos(24.646469, 59.426939)); MapView.AddMarkerToPosition(tallinn); MapView.SetFocusPos(tallinn, 0); MapView.SetZoom(3, 0); Window.Current.Content = MapView; Window.Current.Activate(); }
public override void ViewDidLoad() { base.ViewDidLoad(); MapView = View as MapView; // Add base map CartoOnlineVectorTileLayer 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); Marker marker = MapView.AddMarkerToPosition(berlin); // Add simple event listener that changes size and/or color on map click MapView.MapEventListener = new HelloMapEventListener(marker); }
// Invoked when the application is launched normally by the end user. protected override void OnLaunched(LaunchActivatedEventArgs e) { // Register CARTO license bool registered = MapView.RegisterLicense(License); if (registered) { Carto.Utils.Log.ShowDebug = true; } MapView = new MapView(); // Add base map // TODO: Crashes here for some reason CartoOnlineVectorTileLayer baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDark); MapView.Layers.Add(baseLayer); // Set default location and zoom Projection projection = MapView.Options.BaseProjection; MapPos tallinn = projection.FromWgs84(new MapPos(24.646469, 59.426939)); MapView.AddMarkerToPosition(tallinn); MapView.SetFocusPos(tallinn, 0); MapView.SetZoom(3, 0); Window.Current.Content = MapView; Window.Current.Activate(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Register license MapView.RegisterLicense(LICENSE, ApplicationContext); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); MapView = (MapView)FindViewById(Resource.Id.mapView); // Add base map CartoOnlineVectorTileLayer baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager); 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); Marker marker = MapView.AddMarkerToPosition(berlin); // Add simple event listener that changes size and/or color on map click MapView.MapEventListener = new HelloMapEventListener(marker); }
// Invoked when the application is launched normally by the end user. protected override void OnLaunched(LaunchActivatedEventArgs e) { // Register CARTO license bool registered = MapView.RegisterLicense(License); // Create MapView MapView = new MapView(); // Set MapView options MapView.Options.ZoomGestures = true; MapView.Options.BaseProjection = new EPSG4326(); MapView.Options.DPI = 240; MapView.Options.RenderProjectionMode = RenderProjectionMode.RenderProjectionModeSpherical; // Add base map layer CartoOnlineVectorTileLayer baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager); MapView.Layers.Add(baseLayer); // Set default location and zoom MapPos tallinn = new MapPos(24.646469, 59.426939); MapView.AddMarkerToPosition(tallinn); MapView.SetFocusPos(tallinn, 0); MapView.SetZoom(3, 0); MapView.SetZoom(4, 2); Window.Current.Content = MapView; Window.Current.Activate(); }
public static void UpdateVis(this MapView map, string url, Action <string> error = null) { ThreadPool.QueueUserWorkItem(delegate { map.Layers.Clear(); // Create VIS loader CartoVisLoader loader = new CartoVisLoader(); loader.DefaultVectorLayerMode = true; BasicCartoVisBuilder builder = new BasicCartoVisBuilder(map); try { loader.LoadVis(builder, url); } catch (Exception e) { if (error != null) { error(e.Message); } } MapPos tallinn = new MapPos(24.646469, 59.426939); map.AddMarkerToPosition(tallinn); }); }
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; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Register license MapView.RegisterLicense(LICENSE, ApplicationContext); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); MapView = (MapView)FindViewById(Resource.Id.mapView); // Add base map CartoOnlineVectorTileLayer 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); Marker marker = MapView.AddMarkerToPosition(berlin); // Add simple event listener that changes size and/or color on map click MapView.MapEventListener = new HelloMapEventListener(marker); }
public override void ViewDidLoad() { base.ViewDidLoad(); MapView = View as MapView; // Add base map CartoOnlineVectorTileLayer 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); Marker marker = MapView.AddMarkerToPosition(berlin); // Add simple event listener that changes size and/or color on map click MapView.MapEventListener = new HelloMapEventListener(marker); }
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; }