Select to view content in your preferred language

View all ArcGIS Server services layers in a treeview control(WPF)?

3668
18
06-07-2010 07:57 PM
linusang
Emerging Contributor
Hi,

My application requires to view all my server's services layers, preferably in a treeview control, and the user will then have the ability to choose which layers he wants to add onto the map.

My department has a number of categories in different subfolders. However, ArcGIS server does not allow subfolders creation to organize my department's mxd files.

i've briefly looked at the Table of Content sample. but realize it only show the TOC in mxd files when it is already added onto the map.

So how can i best implement this feature for my WPF ArcGIS app? Any examples or samples or guides would be very much appreciated.

thanks
0 Kudos
18 Replies
DominiqueBroux
Esri Frequent Contributor
Sample of a server explorer showing in a treeview a dynamic catalog of the ArcGIS Server map services : http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=162...

You can also test it live : http://maps.esri.com/serverexplorer/default.htm
0 Kudos
linusang
Emerging Contributor
thanks for the link.

however, when i tried putting my server's url, it doesn't work... it shows a exclamation icon....

and will the code work for wpf?

i opened the sln file and there the reference to ESRI.ArcGIS is missing.. where can i find this reference?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
when i tried putting my server's url, it doesn't work... it shows a exclamation icon....


It should work if your server is visible from the server hosting the Silverlight application. This is probably not the case if you are using the live link.

will the code work for wpf?


The sample is only Silverlight, but I guess it's possible to adapt it for WPF.

the reference to ESRI.ArcGIS is missing.


This sample is a little bit old. Some namespaces have changed : ESRI.ArcGIS is now ESRI.ArcGIS.Client and it's now no more useful to use the System.Windows.Controls.Toolkit to get a TreeView.
So, you have :
[INDENT]- in the references :[/INDENT]
[INDENT][INDENT]. to replace ESRI.ArcGIS by ESRI.ArcGIS.Client[/INDENT][/INDENT]
[INDENT][INDENT]. to remove System.Windows.Controls.Toolkit[/INDENT][/INDENT]
[INDENT]- in MapServiceInfo.cs :[/INDENT]
[INDENT][INDENT]. to replace using ESRI.ArcGIS.Geometry by using ESRI.ArcGIS.Client.Geometry[/INDENT][/INDENT]
[INDENT]- to add using ESRI.ArcGIS.Client in TileInfoInfo.cs, LayerEventArgs.cs and ServerTreeView.xaml.cs[/INDENT]
[INDENT]- to replace Controls.Toolkit by Controls in ServerTreeView.xaml[/INDENT]
0 Kudos
linusang
Emerging Contributor
hi thanks.. managed to run it in WPF...

how can i display the sublayers(feature layer type) in the explorer as well?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Great:)

Concerning the sublayers, MapServiceInfo.Layers is an array of LayerInfo giving the basic information about the sublayers.
So you could display the layers by replacing in Page.xaml, the textbox giving the info about the map cache by a listbox binded to 'MapServiceInfo.Layers' (it's just an example).

                <!--<TextBox Grid.Column="1" Grid.Row="3" Foreground="White" FontWeight="Normal" FontStyle="Italic" TextWrapping="Wrap" BorderBrush="Transparent" Background="Transparent" Text="{Binding Path=MapServiceInfo.SingleFusedMapCache, Mode=OneWay}"/>-->
                <TextBox Grid.Column="0" Grid.Row="3" Foreground="White" FontWeight="Bold" FontStyle="Normal" TextWrapping="Wrap" BorderBrush="Transparent" Background="Transparent" Text="Layers"/>
                <ListBox Grid.Column="1" Grid.Row="3" FontWeight="Bold" FontStyle="Normal" BorderBrush="Transparent" Background="Transparent"
                         ItemsSource="{Binding MapServiceInfo.Layers}" DisplayMemberPath="Name"/>
0 Kudos
linusang
Emerging Contributor
Is there a way to retrieve the type of the sublayer? as i need to differentiate between raster and feature layer
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Not sure what you mean by the type of the sublayer (raster and feature layer?).
The sublayers are mainly depending on the service.
With a DynamicMapServiceLayer, the rendering is done on the server, and the client is just displaying the image coming from the server.
With a feature layer service, there is no sublayers and the rendering is done on client.
0 Kudos
linusang
Emerging Contributor
i would like to add the appropriate layer(raster or feature) on to the map via the server explorer... if the user chooses a raster sublayer to add onto the map, my code should do the appropriate instantiation then add to the map? currently i instantiate a new FeatureLayer(). however when i add a raster layer, it gives me an error... therefore i need to know what type of layer the user choses to add so i can instantiate the appropriate layer?

not sure if that makes sense.... 😛
0 Kudos
DominiqueBroux
Esri Frequent Contributor
My understanding is that you need to make the difference between a map server and a feature server in order to know if you need to instantiate an ArcGISMapServiceLayer or FeatureLayers.

Note that the REST API is giving this info. For example looks at : http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes?f=pjson

The serverExplorer sample is deserializing this info in the class Service (Property 'Type'), but it's only taking care of MapServer service (when the sample has been done, FeatureServer was not existing yet).
So you have to extent the sample to take care of feature services. Look at the server.cs code:

foreach (Service service in catalog.Services) {
      switch (service.Type) {
            case MapService.TYPE:
........
0 Kudos