How to download part of a .tpk file in latest version of xamarin SDK 100.0.0.

1699
1
Jump to solution
01-02-2017 10:17 PM
VinayPrabhakar
New Contributor

How to download part of a .tpk file in  latest version of xamarin SDK 100.0.0.

In earlier version I have used this .NET Xamarin gist to download ArcGIS basemap tiles for offline use. · GitHub 

it has worked fine but after updating the SDK getting build errors

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
AnttiKajanus1
Regular Contributor II

Something like this


var overlay = MyMapView.GraphicsOverlays["areaOfInterestOverlay"];
if (overlay.Graphics.Count == 0) return;

var basemap = MyMapView.Map.Basemap.BaseLayers.OfType<ArcGISTiledLayer>().First();
var lods = basemap.ServiceInfo.TileInfo.LevelsOfDetail;

ExportTileCacheTask estimateTilesTask = null;
ExportTileCacheJob job = null;
try
{
    estimateTilesTask = await ExportTileCacheTask.CreateAsync(basemap.Source, Authenticat    ionManager.Current.Credentials.FirstOrDefault());
    var parameters = await estimateTilesTask.CreateDefaultExportTileCacheParametersAsync(    overlay.Graphics.First().Geometry.Extent, lods[0].Scale, lods[10].Scale);
    job = estimateTilesTask.ExportTileCache(parameters, @"yourpathtothetpk.tpk");
    var result = await job.GetResultAsync();
    //await result.LoadAsync();
    // Do something with loaded tile cache
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
}
foreach (var joMessage in job.Messages)
{
    Debug.WriteLine(joMessage.Message);
}

View solution in original post

1 Reply
AnttiKajanus1
Regular Contributor II

Something like this


var overlay = MyMapView.GraphicsOverlays["areaOfInterestOverlay"];
if (overlay.Graphics.Count == 0) return;

var basemap = MyMapView.Map.Basemap.BaseLayers.OfType<ArcGISTiledLayer>().First();
var lods = basemap.ServiceInfo.TileInfo.LevelsOfDetail;

ExportTileCacheTask estimateTilesTask = null;
ExportTileCacheJob job = null;
try
{
    estimateTilesTask = await ExportTileCacheTask.CreateAsync(basemap.Source, Authenticat    ionManager.Current.Credentials.FirstOrDefault());
    var parameters = await estimateTilesTask.CreateDefaultExportTileCacheParametersAsync(    overlay.Graphics.First().Geometry.Extent, lods[0].Scale, lods[10].Scale);
    job = estimateTilesTask.ExportTileCache(parameters, @"yourpathtothetpk.tpk");
    var result = await job.GetResultAsync();
    //await result.LoadAsync();
    // Do something with loaded tile cache
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
}
foreach (var joMessage in job.Messages)
{
    Debug.WriteLine(joMessage.Message);
}