I am having trouble with the Overlays collection. I am creating LayerOverlays and I add each with a name using code similar to MapWindow.Overlays.Add(MyOverlay, MyOverlay.Name). At a later point I check for the existence of the overlay using code similar to MapWindow.Overlays.Contains(OverlayName) where OverlayName is the same as Overlay.Name above. Unfortunately, the Contains method returns false even though I can see an Overlay with that name in the collection with the Watch window. Am I doing something wrong here?
Charles
My bad. I had code in two places that added overlays, one with a key and one without. In both places the Overlay name was set, but the overlay couldn't be referenced by a key because it wasn't added with a key.
Charles
Double posting too. Not a good day.
Charles
Charles,
Thanks for your post!
I just want to make sure you are using the latest Desktop Edition version(3.0.307 RC)? In this version when added overlay to MapControl, it should be:
MapWindow.Overlays.Add(MyOverlay.Name, MyOverlay)
Instead of
MapWindow.Overlays.Add(MyOverlay, MyOverlay.Name)
I tested with following code and it works fine:
Overlay overlay1 = new LayerOverlay();
Overlay overlay2 = new LayerOverlay();
Overlay overlay3 = new LayerOverlay();
winformsMap1.Overlays.Add("Overlay1", overlay1);
winformsMap1.Overlays.Add("Overlay2", overlay2);
winformsMap1.Overlays.Add( overlay3);
bool contains1 = winformsMap1.Overlays.Contains("Overlay1");
bool contains2 = winformsMap1.Overlays.Contains("Overlay2");
One thing I want to point out is that when you added an Overlay without giving it a key, then it will add a GUID as key automatically.
Any more questions just let me know.
Thanks.
Yale