This project has moved and is read-only. For the latest updates, please go here.

IndexOf no longer available in LayerCollection?

Topics: SharpMap v0.9 / v1.x
Aug 3, 2007 at 4:01 PM
My app was relying on IndexOf to get the Index of a Layer in a LayerColection from it's name. Since upgrading to changeset 24127 I get:
'IndexOf ' is not a member of 'Sharpmap.Layers.LayerCollection'

Here's the kind of code I was using:
MapImage1.QueryLayerIndex = MapImage1.Map.Layers.IndexOf(MapImage1.Map.GetLayerByName("streets"))

Why was IndexOf removed and any suggestions for an alternate way to do this?
Aug 6, 2007 at 4:58 AM
Edited Aug 16, 2007 at 5:06 PM
It was not implemented when the layers functionality was moved to a separate collection class. I'll copy it to a work item and try to remember to close it next week (unless someone beats me to it).

If I drop the ball, just ping this thread.
Aug 6, 2007 at 4:58 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Aug 6, 2007 at 6:44 AM
Thanks very much.
Aug 6, 2007 at 8:27 PM
Edited Aug 6, 2007 at 8:28 PM
Try putting this code:

public int IndexOf(ILayer layer)
for (int i = 0; i < List.Count; i++)
if (List[i] == layer)
return i;

return -1;

in LayerCollection.cs (under SharpMap/Layers)
Aug 16, 2007 at 7:44 AM
This is now added to the trunk. See change set 25708.

There have been a few other enhancements to LayerCollection which might be helpful as well, including XML comments for intellisense and a app-specific exception type - DuplicateLayerException - so you can be more granular in handling the scenario when a layer with a duplicate name is attempted to be inserted.
Aug 16, 2007 at 1:03 PM
Great, thanks. I only got around to recompiling with the above code snippet yesterday (worked, of course, thanks dan3258). First I was working on a couple of other issues not relevant to this thread,then I had to backup the laptop to send to the warranty repair and reinstall everything on a temporary one (which I also had to backup first). Spent 3 days compressing and burning stuff because the external HDD was half full already, then reformatting and reinstalling from scratch.