Closed petr-pokorny-1 closed 5 years ago
I was able to accomplish this by using the "FromSyncImage" method. You can store your images in your XamarinForm Project and rather than the native projects. Make sure you sent their build types to "Embedded Resource". I believe in "Droid" the folder path name to the resource files requires an "_". Check the code below. Hope this helps.
objTile = TileLayer.FromSyncImage((int x, int y, int zoom) =>
{
var assembly = this.GetType().GetTypeInfo().Assembly; byte[] buffer;
Stream stream = null;
try
{
stream = assembly.GetManifestResourceStream($"XamarimFormProjectNamespace.Res._{zoom}._{x}.{y}.png");
long length = stream.Length;
buffer = new byte[length];
stream.Read(buffer, 0, (int)length);
return buffer;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
if (stream != null)
stream.Close();
}
return appImage;
});
Google Maps can not read "MbTiles" .
MbTiles is "MapBox Binary VECTOR Tile", but Google Maps can not render vector tile.
Google Maps can not read "MbTiles" .
MbTiles is "MapBox Binary VECTOR Tile", but Google Maps can not render vector tile.
Thanks, but your comment is not accurate, MBTiles format is designed to support both raster and vector data.
Raster version is used quite often
Hi @spatialguy, sorry you're correct.
If you want to use format: png/jpeg/etc
, you can use @tekinc 's suggested code.
stream = assembly.GetManifestResourceStream(...
Hi @spatialguy, sorry you're correct.
If you want to use
format: png/jpeg/etc
, you can use @tekinc 's suggested code.
- Read MBTile file using
stream = assembly.GetManifestResourceStream(...
- Get image from MBTile file.
- Return image's byte array.
Thanks @tekinc , @amay077 . I was able to get it working using BruTile library. The trick is to correctly convert tile coordinates between Google Maps and TMS:
var mbTiles = _mbTiles.Value; // open mbTiles file using brutile
var layer = TileLayer.FromSyncImage((int x, int y, int zoom) =>
{
var yMax = 1 << zoom;
var y1 = yMax - y - 1; // from Google Maps tiling to TMS
var tileIndex = new TileIndex(x, y1, zoom.ToString());
var tileInfo = new TileInfo {Index = tileIndex};
var data = mbTiles.GetTile(tileInfo);
return data;
});
and code to open MbTiles file:
private readonly Lazy<MbTilesTileSource> _mbTiles = new Lazy<MbTilesTileSource>(
() =>
{
return new MbTilesTileSource(
new SQLiteConnectionString(ResourcesDeployService.MbTilesFilePath, false));
}) ;
@spatialguy Thanks for those pieces of code, it helped me out with loading an mbtiles file. I'm trying to load multiple mbtiles together, to use as layering (for example I have a custom map base layer, I want to ability to toggle on/off another layer for parking meters). I have issue where the parking meter layout transparent segments are blacked out like this This causes my base layout to not show. Have you had any experience with this issue? I appreciate any help I can get, thanks.
This is rather question that bug report. Is there any code sample showing how to display raster layer using tiles from local MbTiles file?