Layer.Visible odd behavior on a ServiceChildLayer

500
2
08-09-2011 10:52 AM
ChrisEaton
New Contributor
I've seen this posted once before, but I'm looking for some ideas on how to deal with it.

What I'm trying to do is write an addin that uses a map service with a bunch of different layers. Each layer represents a flood at a given stage, modelled by the GIS guys on some climate data. The addin is a simple UI that lets the user pick a given climate change scenario, then runs through the appropriate layers gradually showing how climate change affects the area over time. (We first did this as a widget in the Flex viewer, now we're trying to do something similar for AGX users.)

The difficulty I'm having is that in order to show the progression, I need to turn layers on and off based on the scenario and on a timer. But setting ServiceChildLayer.Visible doesn't redraw the layer on the map. In order to cause the layer to update on screen, you also have to call ServiceLayer.ClearCache(), which removes it entirely for a second before drawing the new version and makes it really jerky looking (rather then a smooth progression as the next layer is turned on, which is what we get in the web version).

This behavior doesn't make sense to me, because I can see the layers being enabled in the TOC on the left of AGX. If I do the same thing by clicking the layers manually instead of using the addin, it works fine. So the behavior is different even if it *looks* in the TOC like it's doing the same thing (and the result is a TOC that's not reflective of what is actually showing on the map). It seems to be related to AGX's cache not realizing that the display has changed and just keeping the cached version around until something (like ClearCache() or zooming the map) forces it to redraw.

Anybody have any suggestions on how to get around this and get a smoother looking progression as layers are turned on in code?

Thanks!
0 Kudos
2 Replies
MarkBockenhauer
Esri Regular Contributor
You could try authoring the map so that setting visibility on the parent node, will give you what you want.  When you set visibility on child nodes of a service it builds a cache for the nodes that are turned on, and will do this for each combination.  Once cache is built up locally for each combination, when you change layer visibility, it still disconnect and reconnects to the local cache, which does stutter a bit and refresh the display.

When you set visibility on a parent level node, it doesn't change the connection to cache, or do anything with the cache, so it is much faster and smoother, and will likely meet the needs of what you are trying to do.

I have attached a map.  It references the same service twice, but the visiblity of child nodes is different in each.  I also changed the name in the table of contents, to match the child nodes that are turned on.  Toggling the visibility of the parent nodes should give you the performance you are looking for.
0 Kudos
ChrisEaton
New Contributor
hmm. Alright I'll give that a try, thanks. 🙂
0 Kudos