Select to view content in your preferred language

Bind checkbox to visible layers on map

5091
11
Jump to solution
04-20-2011 05:07 AM
by Anonymous User
Not applicable
Original User: Toosters

Hi

Can someone please tell me how to bind checkbox is checked to visible layers on map (not defaultvisibility on mapservice, IsChecked="{Binding DefaultVisibility}" ).

I'm using sublayer list example (interactive samples, 9.3 arcgisserver). I have got the listbox binded in code to chosen mapservice layer: listbox.ItemsSource = layerInfoArray. I have also got all, on map, visible layers(from selected mapservice) in a list: layer.VisibleLayers.ToList(). I want to bind theese layerids from visiblelayerlist to checkbox so that if i close sublayerlist and opens again checkbox.ischecked should then be binded to the layers that actual are visible on map(visibleLayers list).

Thankful for suggestions or examples
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
Finally implementing a new view model class is not that complex and is a much cleaner approach.

I did it in the sublayerlist sample by adding a combox allowing the user to select the Layer whose the sublayers will be displayed.

Attached is the code and a screen shot

View solution in original post

0 Kudos
11 Replies
by Anonymous User
Not applicable
Original User: jenniferdnery

You can look at this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LayerList

Note the following, IsChecked is bound to map layer Visible property.
<ListBox x:Name="MyList" ItemsSource="{Binding ElementName=MyMap, Path=Layers}">
<!--more code goes here-->
<CheckBox IsChecked="{Binding Visible, Mode=TwoWay}" />
0 Kudos
by Anonymous User
Not applicable
Original User: Toosters

Thx for your answer

But I mean layers in a mapservice, like in this example: SubLayerList.

The binding to mapservice's visible layers (on map!) should be binded in code behind. The layers' visibility on map works but the checkbox need to be in sync with that, and that is not the case.

When I close the sublayer list and open it again and initialize the mapservice again, then the defaultvisibility is binded to the checkbox IsChecked, and that is not the truth, because more layers are visible than the default.
0 Kudos
SteveVidal
Emerging Contributor
I have got the listbox binded in code to chosen mapservice layer: listbox.ItemsSource = layerInfoArray.


You could maintain your own binding collection in code if you really wanted but there is no need for that because the legend control binding to the map control takes care of everything.
0 Kudos
by Anonymous User
Not applicable
Original User: vipulsoni

Thx for your answer

But I mean layers in a mapservice, like in this example: SubLayerList.

The binding to mapservice's visible layers (on map!) should be binded in code behind. The layers' visibility on map works but the checkbox need to be in sync with that, and that is not the case.

When I close the sublayer list and open it again and initialize the mapservice again, then the defaultvisibility is binded to the checkbox IsChecked, and that is not the truth, because more layers are visible than the default.


I guess what you are asking is answered in the following forum post and also the source code is given in the zip to download.. I have used the same zip code and it works too..

http://forums.arcgis.com/threads/9141-Get-Layer-Legends-for-Rest-service
0 Kudos
by Anonymous User
Not applicable
Original User: Toosters

I'm using ArcGIS 9.3.1 REST API 1.2 and the legend control is only available in arcgis 10?

So how could I get the dynamic layer's VisibleLayers binding to their checkboxes in code when the layer is being Initialized. The legend is unnecessary at this point.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I'm using ArcGIS 9.3.1 REST API 1.2 and the legend control is only available in arcgis 10?


The legend control is available from SL API version 2.1 but can work with ArcGIS 9.3.1 if your service is public (arcgis.com fallback mechanism).


So how could I get the dynamic layer's VisibleLayers binding to their checkboxes in code when the layer is being Initialized. The legend is unnecessary at this point.


Looks very close of what is doing this sample : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList
What is the issue with this sample?
0 Kudos
by Anonymous User
Not applicable
Original User: Toosters

Thanx for the response

I have a combobox where the user can select mapservices and the sublayerlist is then being loaded. The user can then check and uncheck layers from checkboxes and everything works fine. The problem is when user select another mapservice from the combobox and then again return to the first. The sublayer list loads and "defaultvisibility" determines which checkboxes are checked although other layers are visible on the map.

So I would like to bind checkbox to visiblelayers. Thats the difference from the sample.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
OK I got it.

You can't easily use a binding (except by creating your own view model class). I suggest you initialize the checkboxes by code when the user selects a map service.

Note : using the legend control, which is done for that, would be simpler 🙂 (and more generic since the sublayerlist sample is not taking care of the group layers).
0 Kudos
by Anonymous User
Not applicable
Original User: Toosters

We will soon update to arcgis 10 but until that I have to use another solution 😞

I have a little problem with the initialization of the checkboxes. When selecting mapservice I get the visible layers but how do I proceed from that and get the checkboxes checked if they are in the visiblelist? Could you please help me with the iniatilize of the checkboxes?

Thanx again
0 Kudos