Hi.
There are few types of overlays in MapSuite Desktop Edition. If I'd like to iterate through them, I have to manually iterate through each type, is there something on higher level, like map.overlays?
Thanks
Hi.
There are few types of overlays in MapSuite Desktop Edition. If I'd like to iterate through them, I have to manually iterate through each type, is there something on higher level, like map.overlays?
Thanks
Łukasz,
We have winformsMap1.CustomOverlays which is the collection of Overlay. Overlay is the base class of all the Overlay classes
Thanks,
ThinkGeo Support
Thanks, Lee.
Now I see the idea ;)
But now I have another question, how to get overlay for layer?
Regards
Łukasz,
You can add layers into LayerOverlay as there is no Layers property in base class Overlay.
Following code shows how to add Overlay into CustomerOverlay and get it back by index or by key.
LayerOverlay overlay1 = new LayerOverlay();
overlay1.Layers.Add("layer1", new ShapeFileFeatureLayer());
winformsMap1.CustomOverlays.Add("FirstOverlay", overlay1);
LayerOverlay overlay2 = new LayerOverlay();
overlay2.Layers.Add("layer2", new ShapeFileFeatureLayer());
winformsMap1.CustomOverlays.Add("SecondOverlay", overlay2);
// Get overlay by index.
LayerOverlay overlayA = (LayerOverlay)winformsMap1.CustomOverlays[0];
// Get overlay by key.
LayerOverlay overlayB = (LayerOverlay)winformsMap1.CustomOverlays["FirstOverlay"];
Is that what you want?
Thanks,
ThinkGeo Support
Hi.
It would be better for me if there was something like this: MapControl.FindFeatureLayer("layer2").getLayerOverlay, because not always the overlay key or index is known for me.
Regards
Łukasz,
You can always know the key of a layer or an overlay when you adding it to the collection. There are two overloads in the add method. One is using the specified string as the key, and the other is using GUID.
overlay.Layers.Add(new ShapeFileFeatureLayer());
overlay.Layers.Add("layer1", new ShapeFileFeatureLayer());
winformsMap1.CustomOverlays.Add(overlay);
winformsMap1.CustomOverlays.Add("overlay1", overlay);
Also you can implement the MapControl.FindFeatureLayer("layer2").getLayerOverlay by the following code.
private LayerOverlay GetLayerOverlayByLayerName(string layerName)
{
LayerOverlay returnOverlay = null;
if (winformsMap1.CustomOverlays.Count > 0)
{
foreach (Overlay overlay in winformsMap1.CustomOverlays)
{
LayerOverlay currentOverlay = overlay as LayerOverlay;
if (currentOverlay != null)
{
// if you want to search the overlay by key, you can use this code instead.
//if (currentOverlay.Layers.Contains(Key))
//{
// returnOverlay = currentOverlay;
//}
foreach (Layer layer in currentOverlay.Layers)
{
if (layer.Name == layerName)
{
returnOverlay = currentOverlay;
}
}
}
}
}
else
{
// do the same loop in StaticOverlay and DynamicOverlay.
}
return returnOverlay;
}
Thanks,
ThinkGeo Support
Thanks. Lee.
This implementation with looping through each type of overlay seems to be good for me.
Regards
You are welcome.
ThinkGeo Support