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

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

            Projection projection = MapView.Options.BaseProjection;

            TileDataSource source = FileUtils.CreateTileDataSource("rome_carto-streets", "mbtiles");

            // 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 = projection.FromWgs84(new MapPos(12.4807, 41.8962));

            MapView.SetFocusPos(rome, 0);
            MapView.SetZoom(13, 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);
        }
Beispiel #3
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);
        }
        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);
        }
        protected virtual void UpdateBaseLayer()
        {
            string styleAssetName   = vectorStyleName + ".zip";
            bool   styleBuildings3D = false;

            if (vectorStyleName.Equals("nutibright3d"))
            {
                styleAssetName   = BaseStyleFile;
                styleBuildings3D = true;
            }

            BinaryData styleBytes = AssetUtils.LoadAsset(styleAssetName);

            if (styleBytes == null)
            {
                Toast.MakeText(this, "Map style file must be in project assets: " + vectorStyleName, ToastLength.Short).Show();
                return;
            }

            // Create style set
            CompiledStyleSet vectorTileStyleSet = new CompiledStyleSet(new ZippedAssetPackage(styleBytes));

            vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);

            // Set language, language-specific texts from vector tiles will be used
            vectorTileDecoder.SetStyleParameter("lang", vectorStyleLang);

            // OSM Bright style set supports choosing between 2d/3d buildings. Set corresponding parameter.
            if (styleAssetName.Equals(BaseStyleFile))
            {
                vectorTileDecoder.SetStyleParameter("buildings3d", styleBuildings3D ? "1" : "0");
                vectorTileDecoder.SetStyleParameter("markers3d", styleBuildings3D ? "1" : "0");
                vectorTileDecoder.SetStyleParameter("texts3d", styleBuildings3D ? "1" : "0");
            }

            // Create tile data source for vector tiles
            if (vectorTileDataSource == null)
            {
                vectorTileDataSource = CreateTileDataSource();
            }

            // Remove old base layer, create new base layer
            if (BaseLayer != null)
            {
                MapView.Layers.Remove(BaseLayer);
            }

            BaseLayer = new VectorTileLayer(vectorTileDataSource, vectorTileDecoder);
            MapView.Layers.Insert(0, BaseLayer);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            BinaryData         bytes   = AssetUtils.LoadAsset("carto-fonts.zip");
            ZippedAssetPackage package = new ZippedAssetPackage(bytes);

            string css     = JsonUtils.OfflinePackageCartoCSS;
            var    decoder = new MBVectorTileDecoder(new CartoCSSStyleSet(css, package));

            TileDataSource source = FileUtils.CreateTileDataSource("offline-packages", "mbtiles");

            var layer = new VectorTileLayer(source, decoder);

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

            BinaryData         bytes   = AssetUtils.LoadAsset("carto-fonts.zip");
            ZippedAssetPackage package = new ZippedAssetPackage(bytes);

            string css     = JsonUtils.OfflinePackageCartoCSS;
            var    decoder = new MBVectorTileDecoder(new CartoCSSStyleSet(css, package));

            TileDataSource source = FileUtils.CreateTileDataSource(this, "offline-packages.mbtiles");

            var layer = new VectorTileLayer(source, decoder);

            MapView.Layers.Add(layer);
        }
        protected virtual TileDataSource CreateTileDataSource()
        {
            TileDataSource vectorTileDataSource = new CartoOnlineTileDataSource("nutiteq.osm");

            // We don't use vectorTileDataSource directly (this would be also option),
            // but via caching to cache data locally persistently/non-persistently
            // Note that persistent cache requires WRITE_EXTERNAL_STORAGE permission
            TileDataSource cacheDataSource = vectorTileDataSource;

            if (persistentTileCache)
            {
                string cacheFile = GetExternalFilesDir(null) + "/mapcache.db";
                cacheDataSource = new PersistentCacheTileDataSource(vectorTileDataSource, cacheFile);
            }
            else
            {
                cacheDataSource = new MemoryCacheTileDataSource(vectorTileDataSource);
            }

            return(cacheDataSource);
        }