My WMS service has three layers - roads, hybrid and satellite. At present, when the WMS layer loads, it only displays satellite. How can I switch between the three layers? Is there an equivalent to the overlay switcher from the web edition that I can use in the desktop edition?
Equivalent of OverlaySwitcher in desktop edition?
Gregory,
I think the solution lies in the Property:
wmsImageLayer.ActiveLayerNames
When you want to show all the layers of the WmsServer, you can write as following way:
wmsImageLayer.Open();
foreach (string layerName in wmsImageLayer.GetServerLayerNames())
{
wmsImageLayer.ActiveLayerNames.Add(layerName);
}
While when you do the switcher or only show portion of the layers, you only need to add the target layers to the ActiveLayersNames.
If I am not clear enough or misunderstanding, please feel free to let me know.
Thanks.
Yale
Yale, thanks for your reply. I have this code in place, but do not see how I can easily switch from displaying one layer to the next. For example, the map displays the satellite layer. I would like the user to switch to roads layer and view that instead of satellite layer.
By the way, if I enable all three layers (roads, satellite and hybrid) it doesn’t fetch all three layers at once, does it? My layers are fully opaque and I want to display only one layer at a time.
Gregory,
Let’s take your example as example:)
Currently you view the satellite layer (suppose its name is “SatelliteLayer”), when you want to switch RoadsLayer(suppose its name is “RoadLayer”).
What you need to do is:
wmsImageLayer.ActiveLayerNames.Remove(“SatelliteLayer”);
wmsImageLayer.ActiveLayerNames.Add (“RoadLayer”);
If you enable all three layers (Roads, satellite and hybrid), it will only fetch ONCE from the server, so they are drawn at the same time.
If you want to display one layer, you only need to add that layer to the ActiveLayerNames.
If I am not clear enough please feel free to let me know.
Thanks.
Yale
Thanks, Yale. I have a combobox that stores the roads, satellite and hybrid items and when you click on one of the combobox items, I run the code you suggested. You can see the code below. I can verify through the debugger that the prior active layer is removed, and the new one added (for example, “Roads” is removed and “Hybrid” added). However, when the map refreshes, it still displays ONLY Roads and not hybrid. In other words, it only displays the first layer name I set.
Further, I use the FileBitmapTileCache. All three layers (roads, satellite and hybrid) appear in the map cache folders, intermingled (e.g. there will be an image in roads view, and onother image that is satellite view). What’s the best way to separate these so they are stored in different folders based on the layer name?
Thanks again.
if (rasterLayer.ActiveLayerNames.Count > 0)
{
rasterLayer.ActiveLayerNames.RemoveAt(0);
}
rasterLayer.ActiveLayerNames.Add(layerName);
wpfMap1.Refresh();
Gregory,
I am chiming in here as reading the previous post a bit quickly I think I understand what you want. First I would suggest that you have each layer that you want to switch between as its own Overlay in the system. There are two reasons for this. The first is that each one can have its own seperate FileBitmapTileCache instance. You can set the directories to separate places for each overlay and they will cache separately. The second reason is that you can easily just set the IsVisible to turn off the Overlays you do not need.
You could do it in one Overlay is that is really important to you however what you need to do if when you switch the layers on and off, using the IsVisible property, you need to go to the FileBitmapTileCache and change the CacheID to something else. I would suggest if you went this route you set the CacheID to "Hybrid", "Roads", or "Sat" etc depending on what they user picked. The way the CacheId works is it is a sub directory under the CacheDirectory you chose for the FileBitmapTileCache and will be created on the fly if it does not exist. In this way you can easily switch between caches and keep your images separate from each other but still have it in one overlay. I hope this is clear enough.
David
David, it works as advertised! I created three overlays, one for each layer (roads, satellite and hybrid) and provide a separate cache folder for each one. I also have a combobox to allow the user to change the active layer. When the combobox changes I simply set the visible flag of the corresponding overlay to true (and all others to false). It works flawlessly!
Greg,
Glad that works. You get a big speed boost from having the cache. Let me know if anythings else comes up.
David