Adding a tpk Layer Dynamically

3542
6
07-28-2013 08:23 AM
PhilipCollier
New Contributor II
Hi all,

I have just begun using the runtime SDK for WPF.  Within my application I am attempting to load another tpk file (ArcGISLocalTiledLayer).  Just using my some of the sdk sample data, on init the application loads the topographic.tpk into my map.  So then I have it set up that the user can select another tpk from a file dialog.  In the code I use layer.clear() and map.add() to try and achieve this.  In my test I attempted to load the sanfrancisco.tpk.  All I get is a blank map.  However if I try and re-load the original topographic.tpk, it will display fine.  It seems that the first tpk you load is the only one that can be re-loaded.  I tried the example "Adding a dynamic layer" from the samples application.  This yielded the same result.  Any ideas on where I am going wrong would be much appreciated.  I am using ArcGIS Runtime 10.1.1 with Visual Studio 2012.

Many thanks

Phil Collier.
0 Kudos
6 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

Can you post your code? - most folk on the forum here will have the sample data so we should be able to able to help you out pretty easily I hope.

Cheers

Mike
0 Kudos
PhilipCollier
New Contributor II
Hi,

Can you post your code? - most folk on the forum here will have the sample data so we should be able to able to help you out pretty easily I hope.

Cheers

Mike


Mike,

Thanks for your reply.

For the xaml just use

<esri:Map x:Name="DefaultMap" WrapAround="True", MinimumResolution="2445.98490512499">
    <esri:ArcGISLocalTiledLayer ID="BaseMap", Path="C:\Program Files (x86)\ArcGIS\WPF10.1.1\SDK\Samples\Data\TPKs\Topographic.tpk" />
<esri:Map/>

Then just add a button to the map and set the click to the following method,

private void BrowsMap(object sender, RoutedEventArgs e)

    Microsoft.Win32.OpenFileDialog openDialog = new OpenFileDialog();

    openFileDialog.DefaultExt = "*.tpk";
    openFileDialog.Filter = "Map Documents (.tpk)|*.tpk";

    Nullable<bool> result = openDialog.ShowDialog();

    if(result == true)
    {
        ArcGISLocalTileLayer newTiledLayer = new ArcGISLocalTiledLayer();
        newTiledLayer.Path = openDialog.FileName;
        DefaultMap.Layers.Clear();
        DefaultMap.Layers.Add(newTiledLayer);
    }
}


This is pretty much the same xaml/code as the example from the samples application titled "Add Layer Dynamically".  This example doesn't seem to work either.  After the first tpk is loaded it doesn't seem to let you load a different one.

Many thanks for any assistance you can provide.

Phil.
0 Kudos
BKuiper
Occasional Contributor III
Mike,
...

Many thanks for any assistance you can provide.

Phil.


Hi Phil,

your TPKs probably have a different projection/Spatial Reference. Whenever the first layer is loaded the Map's projection will be set. You have to explicitly change it after that. I'm pretty sure if you use TPKs with the same projection, it will work.

for example, look at the "tiled" layers here.

http://viewer.nationalmap.gov/example/services.html

http://basemap.nationalmap.gov/ArcGIS/rest/services/USGSTopo/MapServer
has projection / WKID of Spatial Reference: 102100 (3857)

http://gis1.usgs.gov/arcgis/rest/services/gap/PADUS_Owner/MapServer
has projection Spatial Reference: 102113

and will not be able to be viewed on the same map at the same time.
0 Kudos
PhilipCollier
New Contributor II
Hi Phil,

your TPKs probably have a different projection/Spatial Reference. Whenever the first layer is loaded the Map's projection will be set. You have to explicitly change it after that. I'm pretty sure if you use TPKs with the same projection, it will work.

for example, look at the "tiled" layers here.

http://viewer.nationalmap.gov/example/services.html

http://basemap.nationalmap.gov/ArcGIS/rest/services/USGSTopo/MapServer
has projection / WKID of Spatial Reference: 102100 (3857)

http://gis1.usgs.gov/arcgis/rest/services/gap/PADUS_Owner/MapServer
has projection Spatial Reference: 102113

and will not be able to be viewed on the same map at the same time.


Thanks for your advice, this makes alot of sense.  I did a bit of digging and it seems that the local tiled tpks cannot be reprojected once they are added to the map.  Is there anyway of removing the maps projection after all the layers have been cleared?

Many Thanks

Phil Collier.
0 Kudos
BKuiper
Occasional Contributor III
i haven't tried it, but you could try to reset the Map.SpatialReference to null.
0 Kudos
JeremyBridges
Occasional Contributor
We are running into very similar issues.  We want to give the user the option to configure a series of base maps that may not be in the same spatial reference.  When switching between these, we've seen that those layers that are not in the same spatial reference as the first layer will not be displayed.  This is expected.

But, we want to clear the map so that they can be reloaded and displayed.  We are calling Map.Layers.Clear.  But, this doesn't do it.  Map.SpatialReference has no setter.  So, there is no way to set it to null.  How do we ask the map to clear its initial spatial reference?
0 Kudos