Using Tile Packages in Engine

395
2
10-01-2012 01:36 PM
Highlighted
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
Reply
0 Kudos
2 Replies
Highlighted
Occasional Contributor II
Hi,

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

Regards,
David
Reply
0 Kudos
Highlighted
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");
                }
            }
        }
    }
}
Reply
0 Kudos