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);
        }
Exemple #2
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Clear the default layer, add a dark one instead
            MapView.Layers.Clear();

            var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDarkmatter);

            // Remove texts so dots would be more prominent
            (baseLayer.TileDecoder as MBVectorTileDecoder).SetStyleParameter("lang", "nolang");

            MapView.Layers.Add(baseLayer);

            Projection projection = MapView.Options.BaseProjection;

            // Create a datasource and layer for the map
            LocalVectorDataSource source = new LocalVectorDataSource(projection);
            VectorLayer           layer  = new VectorLayer(source);

            MapView.Layers.Add(layer);

            // Initialize CartoSQL service, set a username
            CartoSQLService service = new CartoSQLService();

            service.Username = "******";

            PointStyleBuilder builder = new PointStyleBuilder
            {
                Color = new Carto.Graphics.Color(255, 0, 0, 255),
                Size  = 1
            };

            MapView.QueryFeatures(service, source, builder.BuildStyle(), query);
        }
Exemple #3
0
        public void SetOnlineMode(Action complete = null)
        {
            System.Threading.Tasks.Task.Run(delegate
            {
                if (onlineLayer == null)
                {
                    onlineLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);
                }

                if (offlineLayer != null)
                {
                    MapView.Layers.Remove(offlineLayer);
                }

                if (MapView.Layers.Count == 0)
                {
                    MapView.Layers.Add(onlineLayer);
                }
                else
                {
                    MapView.Layers.Insert(0, onlineLayer);
                }

                if (complete != null)
                {
                    complete();
                }
            });
        }
        // 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();
        }
        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.CartoBasemapStyleDark);

            MapView.Layers.Add(baseLayer);

            // Set default location and zoom
            Projection projection = MapView.Options.BaseProjection;

            MapPos berlin = projection.FromWgs84(new MapPos(13.38933, 52.51704));

            MapView.SetFocusPos(berlin, 0);
            MapView.SetZoom(10, 0);

            // Load vis
            string url = "http://documentation.carto.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json";

            MapView.UpdateVis(url);
        }
        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 location and zoom
            MapPos berlin = projection.FromWgs84(new MapPos(13.38933, 52.51704));

            MapView.SetFocusPos(berlin, 0);
            MapView.SetZoom(10, 0);

            //// Load vis from URL
            string url = "http://documentation.carto.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json";

            UpdateVis(url);
        }
        // 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();
        }
Exemple #8
0
        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);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "mainGPS" layout resource, reload MapView
            SetContentView(Resource.Layout.MainGPS);
            MapView = (MapView)FindViewById(Resource.Id.mapView);

            // Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            // Bind the textViewMessage
            _textViewMessage = FindViewById <TextView>(Resource.Id.textViewMessage);

            // create layer and add object to the layer, finally add layer to the map.
            // All overlay layers must be same projection as base layer, so we reuse it
            _markerDataSource = new LocalVectorDataSource(MapView.Options.BaseProjection);
            var _markerLayer = new VectorLayer(_markerDataSource);

            MapView.Layers.Add(_markerLayer);

            // Initialize the location manager to get the current position
            InitializeLocationManager();
        }
        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;
        }
        // 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 void AddOnlineBaseLayer(CartoBaseMapStyle withStyle)
        {
            // Initialize map
            var baseLayer = new CartoOnlineVectorTileLayer(withStyle);

            MapView.Layers.Add(baseLayer);
        }
Exemple #13
0
        public CartoOnlineVectorTileLayer AddBaseLayer(CartoBaseMapStyle style)
        {
            var layer = new CartoOnlineVectorTileLayer(style);

            MapView.Layers.Add(layer);
            return(layer);
        }
        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);
        }
        public BaseMapsView(Context context) : base(context, Resource.Drawable.icon_menu_round)
        {
            var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            MapView.Layers.Add(baseLayer);

            Menu = new BaseMapSectionMenu(context);
            AddView(Menu);
        }
Exemple #16
0
        public MainView(Context context) : base(context)
        {
            MapView = new MapView(context);
            AddView(MapView);

            // Just use close icon for both images,
            // as back icon is not used in this application
            int close = Resource.Drawable.icon_close;

            Popup = new SlideInPopup(context, close, close);
            AddView(Popup);

            Content = new PopupContent(context);
            Popup.SetPopupContent(Content);
            Popup.Header.Text = "SUBMIT A NEW LOCATION";

            Done = new ActionButton(context, Resource.Drawable.icon_done);
            Done.SetBackground(Colors.CartoGreen);
            AddView(Done);

            Cancel = new ActionButton(context, Resource.Drawable.icon_remove);
            Cancel.SetBackground(Colors.LocationRed);
            AddView(Cancel);

            Add = new ActionButton(context, Resource.Drawable.icon_add);
            Add.SetBackground(Colors.AppleBlue);
            AddView(Add);

            Crosshair = new ImageView(Context);
            Crosshair.SetImageResource(Resource.Drawable.icon_crosshair);
            Crosshair.SetScaleType(ImageView.ScaleType.CenterCrop);
            Crosshair.SetAdjustViewBounds(true);
            AddView(Crosshair);

            Attachment       = new AttachmentImage(context);
            Attachment.Alpha = 0;
            AddView(Attachment);

            /*
             * Frame setting.
             * Everything should be initialized before this point
             */
            SetMainViewFrame();

            var layer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);

            MapView.Layers.Add(layer);

            Popup.BringToFront();
            Banner.BringToFront();

            Crosshair.Visibility = ViewStates.Gone;

            Popup.SetPopupContent(Content);
        }
        public BaseGeocodingView()
        {
            var layer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);

            MapView.Layers.Add(layer);

            ObjectSource = new LocalVectorDataSource(Projection);
            var objectLayer = new VectorLayer(ObjectSource);

            MapView.Layers.Add(objectLayer);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            MapSetup.AddMapOverlays(MapView);
        }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            /// Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            MapSetup.AddMapOverlays(MapView);
        }
Exemple #20
0
        public void SetOnlineMode()
        {
            if (onlineLayer == null)
            {
                onlineLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);
            }

            if (offlineLayer != null)
            {
                MapView.Layers.Remove(offlineLayer);
            }

            MapView.Layers.Add(onlineLayer);
        }
Exemple #21
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            // read json from assets and add to map
            var json = System.IO.File.ReadAllText(AssetUtils.CalculateResourcePath("capitals_3857.geojson"));

            MapSetup.AddJsonLayer(MapView, json);
        }
        public void SetMap(MapView mapView, MapPos position)
        {
            AddSubview(mapView);
            mapView.Frame = Bounds;

            BringSubviewToFront(image);

            mapView.Zoom     = 18;
            mapView.FocusPos = position;

            var layer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);

            mapView.Layers.Add(layer);

            SetIconRoundWithBackground();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            MapView = new MapView();
            View    = MapView;

            BaseProjection = new EPSG3857();

            // Initialize map
            var styleAsset = AssetUtils.LoadAsset("nutibright-v3.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            Title = Name;
        }
        public BaseMapsView(Context context) : base(context)
        {
            MapView = new MapView(context);

            var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            MapView.Layers.Add(baseLayer);

            MapView.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

            AddView(MapView);

            Button = new MenuButton(Resource.Drawable.icon_menu_round, context);
            AddView(Button);

            Menu = new BaseMapSectionMenu(context);
            AddView(Menu);
        }
Exemple #25
0
        public MainView()
        {
            MapView = new MapView();
            AddSubview(MapView);

            Done = new ActionButton("icon_done.png");
            Done.BackgroundColor = Colors.CartoGreen;
            AddSubview(Done);

            Cancel = new ActionButton("icon_remove.png");
            Cancel.BackgroundColor = Colors.CartoRed;
            AddSubview(Cancel);

            AddLocation = new ActionButton("icon_add.png");
            AddLocation.BackgroundColor = Colors.AppleBlue;
            AddSubview(AddLocation);

            Popup             = new SlideInPopup();
            Popup.Header.Text = "SUBMIT A NEW LOCATION";
            AddSubview(Popup);

            Crosshair       = new UIImageView();
            Crosshair.Image = UIImage.FromFile("icon_crosshair.png");
            AddSubview(Crosshair);

            Attachment = new AttachmentImage();
            AddSubview(Attachment);

            Content = new PopupContent();
            Popup.SetContent(Content);

            var layer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);

            MapView.Layers.Add(layer);

            Crosshair.Hidden = true;

            BringSubviewToFront(Done);
            BringSubviewToFront(Cancel);
            BringSubviewToFront(AddLocation);

            SendSubviewToBack(Popup);
        }
        protected override void UpdateBaseLayer()
        {
            MapView.Layers.Clear();

            if (vectorStyleTileType == "raster")
            {
                Menu.Disable("OSM");

                string url = (vectorStyleName == "positron") ? Urls.Positron : Urls.DarkMatter;

                TileDataSource source = new HTTPTileDataSource(1, 19, url);
                var            layer  = new RasterTileLayer(source);

                MapView.Layers.Add(layer);
            }
            else
            {
                Menu.Enable("OSM");
                string selection = Menu.GetSelectedValueOf("OSM");

                CartoOnlineVectorTileLayer layer = null;

                if (selection == "nutiteq.osm")
                {
                    if (vectorStyleName.Split(':')[1] == "default")
                    {
                        layer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);
                    }
                    else
                    {
                        layer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDark);
                    }
                }
                else
                {
                    var styleAsset = AssetUtils.LoadAsset(vectorStyleName + ".zip");
                    layer = new CartoOnlineVectorTileLayer(vectorStyleOSM, new ZippedAssetPackage(styleAsset));
                }

                MapView.Layers.Add(layer);
            }
        }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            // read json from assets and add to map
            string json;

            using (System.IO.StreamReader sr = new System.IO.StreamReader(Assets.Open("capitals_3857.geojson")))
            {
                json = sr.ReadToEnd();
            }

            MapSetup.AddJsonLayer(MapView, json);
        }
Exemple #28
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource

            SetContentView(ViewResource);
            MapView = (MapView)FindViewById(MapViewResource);

            BaseProjection = new EPSG3857();

            // Initialize map
            var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            MapView.Layers.Add(baseLayer);

            Title = GetType().GetTitle();

            ActionBar.SetDisplayHomeAsUpEnabled(true);
        }
        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 override void ViewDidLoad()
        {
            base.ViewDidLoad();

            /// Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            // Create PackageManager instance for dealing with offline packages
            string folder = Utils.GetDocumentDirectory("routingpackages");

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
                Console.WriteLine("Directory: Does not exist... Creating");
            }
            else
            {
                Console.WriteLine("Directory: Exists");
            }

            packageManager  = new CartoPackageManager(ROUTING_PACKAGEMANAGER_SOURCE, folder);
            PackageListener = new RoutingPackageListener(packageManager, downloadablePackages);

            packageManager.PackageManagerListener = PackageListener;

            // Fetch list of available packages from server.
            // Note that this is asynchronous operation
            // and listener will be notified via onPackageListUpdated when this succeeds.
            packageManager.StartPackageListDownload();

            // Create offline routing service connected to package manager
            offlineRoutingService = new PackageManagerRoutingService(packageManager);

            // Create additional online routing service that will be used
            // when offline package is not yet downloaded or offline routing fails
            onlineRoutingService = new CartoOnlineRoutingService(ROUTING_SERVICE_SOURCE);

            // Define layer and datasource for route line and instructions
            routeDataSource = new LocalVectorDataSource(BaseProjection);
            VectorLayer routeLayer = new VectorLayer(routeDataSource);

            MapView.Layers.Add(routeLayer);

            // Define layer and datasource for route start and stop markers
            routeStartStopDataSource = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            VectorLayer vectorLayer = new VectorLayer(routeStartStopDataSource);

            // Add the previous vector layer to the map
            MapView.Layers.Add(vectorLayer);

            // Set visible zoom range for the vector layer
            vectorLayer.VisibleZoomRange = new MapRange(0, 22);

            MapListener = new RouteMapEventListener();
            MapView.MapEventListener = MapListener;

            // Create markers for start & end, and a layer for them
            MarkerStyleBuilder markerStyleBuilder = new MarkerStyleBuilder();

            markerStyleBuilder.Bitmap           = BitmapUtils.CreateBitmapFromUIImage(UIImage.FromFile("olmarker.png"));
            markerStyleBuilder.HideIfOverlapped = false;
            markerStyleBuilder.Size             = 30;

            markerStyleBuilder.Color = new Carto.Graphics.Color(0, 255, 0, 255);

            startMarker         = new Marker(new MapPos(0, 0), markerStyleBuilder.BuildStyle());
            startMarker.Visible = false;

            markerStyleBuilder.Color = new Carto.Graphics.Color(255, 0, 0, 255);

            stopMarker         = new Marker(new MapPos(0, 0), markerStyleBuilder.BuildStyle());
            stopMarker.Visible = false;

            routeStartStopDataSource.Add(startMarker);
            routeStartStopDataSource.Add(stopMarker);

            markerStyleBuilder.Color  = new Carto.Graphics.Color(255, 255, 255, 255);
            markerStyleBuilder.Bitmap = BitmapUtils.CreateBitmapFromUIImage(UIImage.FromFile("direction_up.png"));
            instructionUp             = markerStyleBuilder.BuildStyle();

            markerStyleBuilder.Bitmap = BitmapUtils.CreateBitmapFromUIImage(UIImage.FromFile("direction_upthenleft.png"));
            instructionLeft           = markerStyleBuilder.BuildStyle();

            markerStyleBuilder.Bitmap = BitmapUtils.CreateBitmapFromUIImage(UIImage.FromFile("direction_upthenright.png"));

            instructionRight = markerStyleBuilder.BuildStyle();

            // Style for instruction balloons
            balloonPopupStyleBuilder = new BalloonPopupStyleBuilder();
            balloonPopupStyleBuilder.TitleMargins = new BalloonPopupMargins(4, 4, 4, 4);

            // Finally animate map to Estonia
            MapView.FocusPos = BaseProjection.FromWgs84(new MapPos(25.662893, 58.919365));
            MapView.Zoom     = 7;

            Alert("Long-press on map to set route start and finish");
        }
 protected void AddOnlineBaseLayer(CartoBaseMapStyle style)
 {
     // Initialize map
     var baseLayer = new CartoOnlineVectorTileLayer(style);
     MapView.Layers.Add(baseLayer);
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            /// Set online base layer
            var styleAsset = AssetUtils.LoadAsset("nutibright-v2a.zip");
            var baseLayer  = new CartoOnlineVectorTileLayer("nutiteq.osm", new ZippedAssetPackage(styleAsset));

            MapView.Layers.Add(baseLayer);

            // Create PackageManager instance for dealing with offline packages
            var packageFolder = new File(GetExternalFilesDir(null), "routingpackages");

            if (!(packageFolder.Mkdirs() || packageFolder.IsDirectory))
            {
                Log.Fatal("Could not create package folder!");
            }

            packageManager = new CartoPackageManager(ROUTING_PACKAGEMANAGER_SOURCE, packageFolder.AbsolutePath);

            PackageListener = new RoutingPackageListener(packageManager, downloadablePackages);
            packageManager.PackageManagerListener = PackageListener;
            packageManager.Start();

            // Fetch list of available packages from server.
            // Note that this is asynchronous operation
            // and listener will be notified via onPackageListUpdated when this succeeds.
            packageManager.StartPackageListDownload();

            // create offline routing service connected to package manager
            offlineRoutingService = new PackageManagerRoutingService(packageManager);

            // Create additional online routing service that will be used
            // when offline package is not yet downloaded or offline routing fails
            onlineRoutingService = new CartoOnlineRoutingService(ROUTING_SERVICE_SOURCE);

            // Define layer and datasource for route line and instructions
            routeDataSource = new LocalVectorDataSource(BaseProjection);
            VectorLayer routeLayer = new VectorLayer(routeDataSource);

            MapView.Layers.Add(routeLayer);


            // Define layer and datasource for route start and stop markers
            routeStartStopDataSource = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            VectorLayer vectorLayer = new VectorLayer(routeStartStopDataSource);

            // Add the previous vector layer to the map
            MapView.Layers.Add(vectorLayer);

            // Set visible zoom range for the vector layer
            vectorLayer.VisibleZoomRange = new MapRange(0, 22);

            // Set route listener
            MapListener = new RouteMapEventListener();
            MapView.MapEventListener = MapListener;

            // Create markers for start & end, and a layer for them
            MarkerStyleBuilder markerStyleBuilder = new MarkerStyleBuilder();

            markerStyleBuilder.Bitmap = BitmapUtils
                                        .CreateBitmapFromAndroidBitmap(BitmapFactory.DecodeResource(
                                                                           Resources, Resource.Drawable.olmarker));
            markerStyleBuilder.HideIfOverlapped = false;
            markerStyleBuilder.Size             = 30;

            markerStyleBuilder.Color = new Carto.Graphics.Color(Android.Graphics.Color.Green);

            startMarker         = new Marker(new MapPos(0, 0), markerStyleBuilder.BuildStyle());
            startMarker.Visible = false;

            markerStyleBuilder.Color = new Carto.Graphics.Color(Android.Graphics.Color.Red);

            stopMarker         = new Marker(new MapPos(0, 0), markerStyleBuilder.BuildStyle());
            stopMarker.Visible = false;

            routeStartStopDataSource.Add(startMarker);
            routeStartStopDataSource.Add(stopMarker);

            markerStyleBuilder.Color  = new Carto.Graphics.Color(Android.Graphics.Color.White);
            markerStyleBuilder.Bitmap = BitmapUtils
                                        .CreateBitmapFromAndroidBitmap(BitmapFactory.DecodeResource(
                                                                           Resources, Resource.Drawable.direction_up));
            instructionUp = markerStyleBuilder.BuildStyle();

            markerStyleBuilder.Bitmap = BitmapUtils
                                        .CreateBitmapFromAndroidBitmap(BitmapFactory.DecodeResource(
                                                                           Resources, Resource.Drawable.direction_upthenleft));
            instructionLeft = markerStyleBuilder.BuildStyle();

            markerStyleBuilder.Bitmap = BitmapUtils
                                        .CreateBitmapFromAndroidBitmap(BitmapFactory.DecodeResource(
                                                                           Resources, Resource.Drawable.direction_upthenright));

            instructionRight = markerStyleBuilder.BuildStyle();

            // Style for instruction balloons
            balloonPopupStyleBuilder = new BalloonPopupStyleBuilder();
            balloonPopupStyleBuilder.TitleMargins = new BalloonPopupMargins(4, 4, 4, 4);

            // Finally animate map to Estonia
            MapView.FocusPos = BaseProjection.FromWgs84(new MapPos(25.662893, 58.919365));
            MapView.Zoom     = 7;

            Toast.MakeText(ApplicationContext, "Long-press on map to set route start and finish", ToastLength.Long).Show();
        }
        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;
        }
Exemple #34
0
        public static void AddOnlineBaseLayer(this MapView map, CartoBaseMapStyle style)
        {
            var layer = new CartoOnlineVectorTileLayer(style);

            map.Layers.Add(layer);
        }