コード例 #1
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Remove default baselayer
            MapView.Layers.Clear();

            var decoder = CartoVectorTileLayer.CreateTileDecoder(CartoBaseMapStyle.CartoBasemapStyleVoyager);

            // Do the actual copying and source creation on another thread so it wouldn't block the main thread
            System.Threading.Tasks.Task.Run(delegate
            {
                TileDataSource source = FileUtils.CreateTileDataSource(this, "rome_carto-streets.mbtiles");

                var layer = new VectorTileLayer(source, decoder);

                RunOnUiThread(delegate
                {
                    // However, actual layer insertion should be done on the main thread
                    MapView.Layers.Insert(0, layer);
                });
            });

            // Zoom to the correct location
            MapPos rome = BaseProjection.FromWgs84(new MapPos(12.4807, 41.8962));

            MapView.SetFocusPos(rome, 0);
            MapView.SetZoom(13, 0);
        }
コード例 #2
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            TileDataSource source = CreateTileDataSource();

            // Get decoder from current layer,
            // so we wouldn't need a style asset to create a decoder from scratch
            MBVectorTileDecoder decoder = (MBVectorTileDecoder)(MapView.Layers[0] as VectorTileLayer).TileDecoder;

            // Remove default baselayer
            MapView.Layers.Clear();

            // Add our new layer
            var layer = new VectorTileLayer(source, decoder);

            MapView.Layers.Insert(0, layer);

            // Zoom to the correct location
            MapPos rome = BaseProjection.FromWgs84(new MapPos(12.4807, 41.8962));

            MapView.SetFocusPos(rome, 0);
            MapView.SetZoom(13, 0);
        }
コード例 #3
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // Get decoder from current layer,
            // so we wouldn't need a style asset to create a decoder from scratch
            MBVectorTileDecoder decoder = (MBVectorTileDecoder)(MapView.Layers[0] as VectorTileLayer).TileDecoder;

            // Remove default baselayer
            MapView.Layers.Clear();

            // Do the actual copying and source creation on another thread so it wouldn't block the main thread
            System.Threading.Tasks.Task.Run(delegate
            {
                TileDataSource source = CreateTileDataSource();

                var layer = new VectorTileLayer(source, decoder);

                RunOnUiThread(delegate
                {
                    // However, actual layer insertion should be done on the main thread
                    MapView.Layers.Insert(0, layer);
                });
            });

            // Zoom to the correct location
            MapPos rome = BaseProjection.FromWgs84(new MapPos(12.4807, 41.8962));

            MapView.SetFocusPos(rome, 0);
            MapView.SetZoom(13, 0);
        }
コード例 #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Menu       = new BaseMapSectionMenu();
            Menu.Items = Sections.List;

            MenuButton = new MenuButton("icons/icon_more.png", new CGRect(0, 10, 20, 30));
            NavigationItem.RightBarButtonItem = MenuButton;

            // Set initial style
            Menu.SetInitialItem(Sections.Nutiteq);
            Menu.SetInitialItem(Sections.Language);

            UpdateBaseLayer(Sections.Nutiteq, Sections.BaseStyleValue);
            UpdateLanguage(Sections.BaseLanguageCode);

            // Zoom to Central Europe so some texts would be visible
            MapPos europe = BaseProjection.FromWgs84(new MapPos(15.2551, 54.5260));

            MapView.SetFocusPos(europe, 0);
            MapView.Zoom = 5;

            recognizer = new ForceTouchRecognizer();
            MapView.AddGestureRecognizer(recognizer);
        }
コード例 #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Add default base layer
            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager);

            // Load ground overlay bitmap
            //Bitmap androidMarkerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.jefferson);
            //com.carto.graphics.Bitmap overlayBitmap = BitmapUtils.createBitmapFromAndroidBitmap(androidMarkerBitmap);
            Bitmap overlayBitmap = BitmapUtils.LoadBitmapFromFile("jefferson-building-ground-floor.jpg");

            // Create two vectors containing geographical positions and corresponding raster image pixel coordinates.
            // 2, 3 or 4 points may be specified. Usually 2 points are enough (for conformal mapping).
            MapPos pos    = BaseProjection.FromWgs84(new MapPos(-77.004590, 38.888702));
            double sizeNS = 110;
            double sizeWE = 100;

            MapPosVector mapPoses = new MapPosVector();

            mapPoses.Add(new MapPos(pos.X - sizeWE, pos.Y + sizeNS));
            mapPoses.Add(new MapPos(pos.X + sizeWE, pos.Y + sizeNS));
            mapPoses.Add(new MapPos(pos.X + sizeWE, pos.Y - sizeNS));
            mapPoses.Add(new MapPos(pos.X - sizeWE, pos.Y - sizeNS));

            ScreenPosVector bitmapPoses = new ScreenPosVector();

            bitmapPoses.Add(new ScreenPos(0, 0));
            bitmapPoses.Add(new ScreenPos(0, overlayBitmap.Height));
            bitmapPoses.Add(new ScreenPos(overlayBitmap.Width, overlayBitmap.Height));
            bitmapPoses.Add(new ScreenPos(overlayBitmap.Width, 0));

            // Create bitmap overlay raster tile data source
            BitmapOverlayRasterTileDataSource rasterDataSource = new BitmapOverlayRasterTileDataSource(
                0, 20, overlayBitmap, BaseProjection, mapPoses, bitmapPoses
                );

            RasterTileLayer rasterLayer = new RasterTileLayer(rasterDataSource);

            MapView.Layers.Add(rasterLayer);

            // Apply zoom level bias to the raster layer.
            // By default, bitmaps are upsampled on high-DPI screens.
            // We will correct this by applying appropriate bias
            float zoomLevelBias = (float)(Math.Log(MapView.Options.DPI / 160.0f) / Math.Log(2));

            rasterLayer.ZoomLevelBias          = zoomLevelBias * 0.75f;
            rasterLayer.TileSubstitutionPolicy = TileSubstitutionPolicy.TileSubstitutionPolicyVisible;

            MapView.SetFocusPos(pos, 0);
            MapView.SetZoom(15.5f, 0);
        }
コード例 #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // MapSampleBaseActivity creates and configures mapView
            base.OnCreate(savedInstanceState);

            // Define style for vector objects. Note that all objects must have same style here, which can be big limitation
            PointStyleBuilder pointStyleBuilder = new PointStyleBuilder();

            pointStyleBuilder.Color = new Color(0, 0, 255, 255);
            pointStyleBuilder.Size  = 10;

            // Initialize a local vector data source
            string query =
                "SELECT cartodb_id,the_geom_webmercator AS the_geom,name,address,bikes,slot," +
                "field_8,field_9,field_16,field_17,field_18 FROM stations_1 WHERE !bbox!";

            CartoDBSQLDataSource vectorDataSource1 = new CartoDBSQLDataSource(
                BaseProjection,
                BaseUrl,
                query,
                pointStyleBuilder.BuildStyle()
                );

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

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

            // Set visible zoom range for the vector layer
            vectorLayer1.VisibleZoomRange = new MapRange(14, 23);


            // Set listener to get point click popups

            // Initialize a local vector data source and layer for click Balloons
            LocalVectorDataSource vectorDataSource = new LocalVectorDataSource(BaseProjection);

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

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

            MapView.MapEventListener = new MyMapEventListener(MapView, vectorDataSource);

            // Animate map to the marker
            MapView.SetFocusPos(BaseProjection.FromWgs84(new MapPos(-74.0059, 40.7127)), 1);
            MapView.SetZoom(15, 1);
        }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleGray);

            // You need to change these according to your DB
            string sql      = "select * from table_46g";
            string cartoCSS = "#table_46g {raster-opacity: 0.5;}";

            string config = JsonUtils.GetRasterLayerConfigJson(sql, cartoCSS).ToString();

            // Use the Maps service to configure layers. Note that this must be done
            // in a separate thread on Android, as Maps API requires connecting to server
            // which is not allowed in main thread.

            CartoMapsService mapsService = new CartoMapsService();

            mapsService.Username = "******";

            // Use raster layers, not vector layers
            mapsService.DefaultVectorLayerMode = false;

            System.Threading.Tasks.Task.Run(delegate
            {
                try
                {
                    LayerVector layers = mapsService.BuildMap(Variant.FromString(config));
                    for (int i = 0; i < layers.Count; i++)
                    {
                        MapView.Layers.Add(layers[i]);
                    }
                }
                catch (IOException e)
                {
                    Carto.Utils.Log.Debug("EXCEPTION: Exception: " + e);
                }
            });

            // Zoom map to the content area
            MapPos hiiumaa = BaseProjection.FromWgs84(new MapPos(22.7478235498916, 58.8330577553785));

            MapView.SetFocusPos(hiiumaa, 0);
            MapView.SetZoom(11, 0);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initialize hillshading raster data source, better visible in mountain ranges
            HTTPTileDataSource source1 = new HTTPTileDataSource(0, 24, TiledRasterUrl);
            HTTPTileDataSource source2 = new HTTPTileDataSource(0, 24, HillsideRasterUrl);

            MergedRasterTileDataSource mergedSource = new MergedRasterTileDataSource(source1, source2);

            var layer = new RasterTileLayer(mergedSource);

            MapView.Layers.Add(layer);

            // Animate map to a nice place
            MapView.SetFocusPos(BaseProjection.FromWgs84(new MapPos(-122.4323, 37.7582)), 1);
            MapView.SetZoom(13, 1);
        }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Initialize hillshading raster data source, better visible in mountain ranges
            HTTPTileDataSource source1 = new HTTPTileDataSource(0, 24, TiledRasterUrl);
            HTTPTileDataSource source2 = new HTTPTileDataSource(0, 24, HillsideRasterUrl);

            MergedRasterTileDataSource mergedSource = new MergedRasterTileDataSource(source1, source2);

            var layer = new RasterTileLayer(mergedSource);

            MapView.Layers.Add(layer);

            // Animate map to a nice place
            MapView.SetFocusPos(BaseProjection.FromWgs84(new MapPos(-122.4323, 37.7582)), 1);
            MapView.SetZoom(13, 1);
        }
コード例 #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleGray);

            // You need to change these according to your DB
            string sql      = "select * from table_46g";
            string cartoCSS = "#table_46g { raster-opacity: 0.5; }";
            string config   = JsonUtils.GetRasterLayerConfigJson(sql, cartoCSS).ToString();

            CartoMapsService mapsService = new CartoMapsService();

            mapsService.Username = "******";

            // Use raster layers, not vector layers
            mapsService.DefaultVectorLayerMode = false;

            // Use the Maps service to configure layers.
            // Note that Maps API requires connecting to server,
            // which shouldn't be done on the main thread

            InvokeInBackground(delegate
            {
                try
                {
                    LayerVector layers = mapsService.BuildMap(Variant.FromString(config));
                    for (int i = 0; i < layers.Count; i++)
                    {
                        MapView.Layers.Add(layers[i]);
                    }
                }
                catch (IOException e)
                {
                    Carto.Utils.Log.Debug("EXCEPTION: Exception: " + e);
                }
            });

            // Zoom map to the content area
            MapPos hiiumaa = BaseProjection.FromWgs84(new MapPos(22.7478235498916, 58.8330577553785));

            MapView.SetFocusPos(hiiumaa, 0);
            MapView.SetZoom(10, 0);
        }
コード例 #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Define style for vector objects.
            // Note that all objects must have same style here, which can be big limitation
            PointStyleBuilder builder = new PointStyleBuilder();

            builder.Color = new Color(0, 0, 255, 255);
            builder.Size  = 10;

            PointStyle style = builder.BuildStyle();

            // Initialize a local vector data source
            CartoDBSQLDataSource dataSource = new CartoDBSQLDataSource(BaseProjection, BaseUrl, Query, style);

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

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

            // Set visible zoom range for the vector layer
            vectorLayer1.VisibleZoomRange = new MapRange(14, 23);

            // Initialize a local vector data source and layer for click Balloons
            LocalVectorDataSource vectorDataSource = new LocalVectorDataSource(BaseProjection);

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

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

            // Set listener to get point click popups
            MapView.MapEventListener = new MyMapEventListener(MapView, vectorDataSource);

            // Animate map to the marker
            MapPos newYork = BaseProjection.FromWgs84(new MapPos(-74.0059, 40.7127));

            MapView.SetFocusPos(newYork, 1);
            MapView.SetZoom(15, 1);
        }
コード例 #12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Add default base layer
            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // Initialize a local vector data source
            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);

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

            // Add the previous vector layer to the map
            MapView.Layers.Add(layer);
            // Set visible zoom range for the vector layer
            layer.VisibleZoomRange = new MapRange(0, 18);

            // Create marker style
            UIImage image        = UIImage.FromFile("icons/marker.png");
            Bitmap  markerBitmap = BitmapUtils.CreateBitmapFromUIImage(image);

            MarkerStyleBuilder builder = new MarkerStyleBuilder();

            builder.Bitmap = markerBitmap;
            builder.Size   = 30;
            MarkerStyle style = builder.BuildStyle();

            // Add marker
            MapPos washington = BaseProjection.FromWgs84(new MapPos(-77.0369, 38.9072));
            Marker marker     = new Marker(washington, style);

            source.Add(marker);

            // Animate map to the marker
            MapView.SetFocusPos(washington, 1);
            MapView.SetZoom(12, 1);

            listener = new RenderListener(this, MapView);
            MapView.MapRenderer.CaptureRendering(listener, true);
        }
コード例 #13
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Initialize hillshading raster data source, better visible in mountain ranges
            HTTPTileDataSource hillsRasterTileDataSource = new HTTPTileDataSource(0, 24, HillsideRasterUrl);

            // Add persistent caching datasource, tiles will be stored locally on persistent storage
            PersistentCacheTileDataSource cachedDataSource =
                new PersistentCacheTileDataSource(hillsRasterTileDataSource, GetExternalFilesDir(null) + "/mapcache_hills.db");

            // Initialize a raster layer with the previous data source
            RasterTileLayer hillshadeLayer = new RasterTileLayer(cachedDataSource);

            // Add the previous raster layer to the map
            MapView.Layers.Add(hillshadeLayer);

            // Animate map to a nice place
            MapView.SetFocusPos(BaseProjection.FromWgs84(new MapPos(-122.4323, 37.7582)), 1);
            MapView.SetZoom(13, 1);
        }
コード例 #14
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initialize hillshading raster data source, better visible in mountain ranges
            HTTPTileDataSource tileSource = new HTTPTileDataSource(0, 24, HillsideRasterUrl);

            // Add persistent caching datasource, tiles will be stored locally on persistent storage
            PersistentCacheTileDataSource cachedSource =
                new PersistentCacheTileDataSource(tileSource, Utils.GetDocumentDirectory() + "mapcache_hills.db");

            // Initialize a raster layer with the previous data source
            RasterTileLayer hillshadeLayer = new RasterTileLayer(cachedSource);

            // Add the previous raster layer to the map
            MapView.Layers.Add(hillshadeLayer);

            // Animate map to a nice place
            MapView.SetFocusPos(BaseProjection.FromWgs84(new MapPos(-122.4323, 37.7582)), 1);
            MapView.SetZoom(13, 1);
        }
コード例 #15
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // Initialize a local vector data source
            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);

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

            // Add the previous vector layer to the map
            MapView.Layers.Add(layer);
            // Set visible zoom range for the vector layer
            layer.VisibleZoomRange = new MapRange(0, 18);

            // Create marker style
            Android.Graphics.Bitmap image        = Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.marker);
            Carto.Graphics.Bitmap   markerBitmap = BitmapUtils.CreateBitmapFromAndroidBitmap(image);

            MarkerStyleBuilder builder = new MarkerStyleBuilder();

            builder.Bitmap = markerBitmap;
            builder.Size   = 30;
            MarkerStyle style = builder.BuildStyle();

            // Add marker
            MapPos berlin = BaseProjection.FromWgs84(new MapPos(13.38933, 52.51704));
            Marker marker = new Marker(berlin, style);

            source.Add(marker);

            // Animate map to the marker
            MapView.SetFocusPos(berlin, 1);
            MapView.SetZoom(12, 1);

            listener = new RenderListener(this, MapView);
            MapView.MapRenderer.CaptureRendering(listener, true);
        }
コード例 #16
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // USGS Base map: http://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer
            string url    = "http://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WmsServer?";
            string layers = "0";

            HttpWmsTileDataSource wms      = new HttpWmsTileDataSource(0, 14, BaseProjection, false, url, "", layers, "image/png8");
            RasterTileLayer       wmsLayer = new RasterTileLayer(wms);

            // Calculate zoom bias, basically this is needed to 'undo' automatic DPI scaling,
            // we will display original raster with close to 1:1 pixel density
            double zoomLevelBias = Math.Log(MapView.Options.DPI / 160) / Math.Log(2);

            wmsLayer.ZoomLevelBias = (float)zoomLevelBias;

            MapView.Layers.Add(wmsLayer);

            // Animate map to map coverage
            MapView.SetFocusPos(BaseProjection.FromWgs84(new MapPos(-100, 40)), 1);
            MapView.SetZoom(5, 1);
        }
コード例 #17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Add default base layer
            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);
            VectorLayer           layer  = new VectorLayer(source);

            MapView.Layers.Add(layer);

            MarkerStyleBuilder builder = new MarkerStyleBuilder();

            builder.Bitmap = Bitmap;
            builder.Size   = 20;

            // Add marker
            MapPos position = BaseProjection.FromWgs84(new MapPos(24.646469, 59.426939));
            Marker marker   = new Marker(position, builder.BuildStyle());

            source.Add(marker);

            // Custom popup
            PopupStyleBuilder popupBuilder = new PopupStyleBuilder();

            popupBuilder.SetAttachAnchorPoint(0.5f, 0);

            // Initialize our custom handler, cf. class below
            MyCustomPopupHandler handler = new MyCustomPopupHandler();

            CustomPopup popup = new CustomPopup(marker, popupBuilder.BuildStyle(), handler);

            popup.SetAnchorPoint(-1.0f, 0.0f);
            source.Add(popup);
        }
コード例 #18
0
 void ZoomTo(MapPos position)
 {
     MapView.FocusPos = BaseProjection.FromWgs84(position);
     MapView.SetZoom(12, 2);
 }
コード例 #19
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // 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(ManagerSource, 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(ServiceSource);

            // 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 markerBuilder = new MarkerStyleBuilder();

            markerBuilder.Bitmap           = CreateBitmap(Resource.Drawable.olmarker);
            markerBuilder.HideIfOverlapped = false;
            markerBuilder.Size             = 30;
            markerBuilder.Color            = new Carto.Graphics.Color(Android.Graphics.Color.Green);

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

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

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

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

            markerBuilder.Color  = new Carto.Graphics.Color(Android.Graphics.Color.White);
            markerBuilder.Bitmap = CreateBitmap(Resource.Drawable.direction_up);
            instructionUp        = markerBuilder.BuildStyle();

            markerBuilder.Bitmap = CreateBitmap(Resource.Drawable.direction_upthenleft);
            instructionLeft      = markerBuilder.BuildStyle();

            markerBuilder.Bitmap = CreateBitmap(Resource.Drawable.direction_upthenright);
            instructionRight     = markerBuilder.BuildStyle();

            // Style for instruction balloons
            balloonBuilder = new BalloonPopupStyleBuilder();
            balloonBuilder.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");
        }
コード例 #20
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // 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("icons/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("icons/direction_up.png"));
            instructionUp             = markerStyleBuilder.BuildStyle();

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

            markerStyleBuilder.Bitmap = BitmapUtils.CreateBitmapFromUIImage(UIImage.FromFile("icons/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");
        }