Using Tile Packages in Engine

660
2
10-01-2012 01:36 PM
ManoSadeh
New Contributor II
Hey,

Is it possible to open a Tile Package File (*.tpk) with Engine. We have an Engine application and would like to be able to add a Tile Package to the MapControl.

We know Tile Packages are new in 10.1, but still would like to know if this is availble via ArcObjects and a MapControl.

Thanks and regards,
Mano
0 Kudos
2 Replies
DavidLednik
Occasional Contributor II
Hi,

It works in Desktop with 10.1 so it shouldn't be a problem with 10.1 engine.

Regards,
David
0 Kudos
JohnHauck
Occasional Contributor II
You can make use of IPackageFile.Unpack to unpack the TPK prior to adding its layer:

string unpackPath = "";
IPackageFile pkFile = new PackageFileClass();
pkFile.Unpack(@"C:\temp\tpk\TPK_Map.tpk", ref unpackPath);

axMapControl1.AddLayerFromFile(unpackPath + "\\Layers.lyr");


I like to enable OLEDrop and click/drag them to the map control, here is a trimmed down version of that code:

private void axMapControl1_OnOleDrop(object sender, IMapControlEvents2_OnOleDropEvent e)
{
    IDataObjectHelper dataObject = (IDataObjectHelper)e.dataObjectHelper;

    if (e.dropAction == esriControlsDropAction.esriDropped)
    {
        if (dataObject.CanGetFiles())
        {
            System.Array filePaths = System.Array.CreateInstance(typeof(string), 0, 0);
            filePaths = (System.Array)dataObject.GetFiles();

            for (int i = 0; i <= filePaths.Length - 1; i++)
            {
                string filePath = filePaths.GetValue(i).ToString();
                if (filePath.Contains(".tpk"))
                {
                    string unpackPath = "";
                    IPackageFile pkFile = new PackageFileClass();
                    pkFile.Unpack(@"C:\temp\tpk\TPK_Map.tpk", ref unpackPath);

                    axMapControl1.AddLayerFromFile(unpackPath + "\\Layers.lyr");
                }
            }
        }
    }
}
0 Kudos