I want to create basemap using my local tpk file in wpf app. How can i do it?

920
3
Jump to solution
09-24-2020 01:34 AM
VanyaIvanov
Occasional Contributor

I've found some code for Map case: 

Map myMap = new Map();

String filepath = "location_of_raster_file" ;

Raster myRasterFile = new Raster(filepath);


RasterLayer myRasterLayer = new RasterLayer(myRasterFile);
await myRasterLayer.LoadAsync();

myMap.Basemap.BaseLayers.Add(myRasterLayer);

 

But it doesn't work for Scene:

Scene newScene = new Scene();

String filepath = "C:\\Users\\user\\Desktop\\City.tpk";

Raster myRasterFile = new Raster(filepath);


RasterLayer myRasterLayer = new RasterLayer(myRasterFile);
await myRasterLayer.LoadAsync();

newScene.Basemap.BaseLayers.Add(myRasterLayer);

0 Kudos
1 Solution

Accepted Solutions
CavronJeremy
New Contributor III

You can also with : 

private const string MAP = "map.tpk";
 .... 
..... 
Uri uri = new Uri(MAP); 
// Create a tile cache from the local data. 
TileCache cache = new TileCache(uri.LocalPath); 
// Use the tile cache to create an ArcGISTiledLayer. 
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(cache); 
// Display the tiled layer as a basemap. 
MyMapView.Map = new Map(new Basemap(tiledLayer)); 

View solution in original post

3 Replies
Nicholas-Furness
Esri Regular Contributor

Hi Vanya Ivanov,‌

To use a TPK, do not use a RasterLayer. Instead use an ArcGISTiledLayer with a TileCache initialized with the TPK.

See the example here: ArcGISTiledLayer Constructor (TileCache) 

Hope this helps.

JoeHershman
MVP Regular Contributor
var tileCache = new TileCache(Constants.Settings.ImageryLocation);
ArcGISTiledLayer imageLayer = new ArcGISTiledLayer(tileCache);

var map = new Esri.ArcGISRuntime.Mapping.Map(new Basemap(imageLayer))
{
	InitialViewpoint = new Viewpoint(extent)
};‍‍‍‍‍‍‍
Thanks,
-Joe
CavronJeremy
New Contributor III

You can also with : 

private const string MAP = "map.tpk";
 .... 
..... 
Uri uri = new Uri(MAP); 
// Create a tile cache from the local data. 
TileCache cache = new TileCache(uri.LocalPath); 
// Use the tile cache to create an ArcGISTiledLayer. 
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(cache); 
// Display the tiled layer as a basemap. 
MyMapView.Map = new Map(new Basemap(tiledLayer));