TileDataSource CreateTileDataSource() { // offline map data source string fileName = "rome_ntvt.mbtiles"; try { string directory = GetExternalFilesDir(null).ToString(); string path = directory + "/" + fileName; Assets.CopyAssetToSDCard(fileName, path); Log.Debug("Copy done to " + path); MBTilesTileDataSource source = new MBTilesTileDataSource(0, 14, path); return(new MemoryCacheTileDataSource(source)); } catch (IOException e) { Log.Debug("MbTileFile cannot be copied: " + fileName); Log.Debug("Message" + e.LocalizedMessage); } return(null); }
public MapContainer() { Map = new MapView(); var timer = new Stopwatch(); timer.Start(); // NOTE: Uncomment the timer creation and BeginInvokeOnMainThread to apply a workaround //var startTimer = new System.Threading.Timer((_) => //{ // Device.BeginInvokeOnMainThread(() => // { MBTilesTileDataSource testDataSource = new MBTilesTileDataSource(((App)App.Current).CityDataFile); CompiledStyleSet styleSet = new CompiledStyleSet(new ZippedAssetPackage(AssetUtils.LoadAsset("nutibright-v3.zip"))); MBVectorTileDecoder decoder = new MBVectorTileDecoder(styleSet); VectorTileLayer testLayer = new VectorTileLayer(testDataSource, decoder); Map.Layers.Add(testLayer); // }); //}, null, 10, System.Threading.Timeout.Infinite); timer.Stop(); Debug.WriteLine($"Done map initialization in {timer.ElapsedMilliseconds}ms"); MapPos pos = Map.Options.BaseProjection.FromWgs84(new MapPos(App.CITY_POS_X, App.CITY_POS_Y)); Map.SetFocusPos(pos, 0); Map.SetZoom(15, 0); Content = Map.ToView(); }
protected override TileDataSource CreateTileDataSource(string osm) { //string fileName = "world_zoom5"; string fileName = "rome_ntvt"; string extension = "mbtiles"; string packageDirectory = SupportDirectory; string fullWritePath = Path.Combine(packageDirectory, fileName + "." + extension); string resourceDirectory = NSBundle.MainBundle.PathForResource(fileName, extension); return(new MBTilesTileDataSource(0, 4, resourceDirectory)); if (!Directory.Exists(packageDirectory)) { Directory.CreateDirectory(packageDirectory); Console.WriteLine("Directory: Does not exist... Creating"); } else { Console.WriteLine("Directory: Exists"); } try { // Copy bundled tile data to file system so it can be imported by package manager using (var input = new FileStream(resourceDirectory, FileMode.Open, FileAccess.Read)) { using (var output = new FileStream(fullWritePath, FileMode.Create, FileAccess.Write)) { input.CopyTo(output); } } MBTilesTileDataSource source = new MBTilesTileDataSource(0, 4, fullWritePath); return(source); } catch { return(null); } }
public static TileDataSource CreateTileDataSource(Android.Content.Context context, string fileName) { try { string directory = context.GetExternalFilesDir(null).ToString(); string path = directory + "/" + fileName; context.Assets.CopyAssetToSDCard(fileName, path); Log.Debug("Copy done to " + path); MBTilesTileDataSource source = new MBTilesTileDataSource(0, 14, path); return(new MemoryCacheTileDataSource(source)); } catch (IOException e) { Log.Debug("MbTileFile cannot be copied: " + fileName); Log.Debug("Message" + e.Message); } return(null); }