Custom Selection

Nov 19, 2010 at 11:18 PM

I'd like to implement a custom selection tool. I'd like to click on the map and get the attributes from the selected feature.

Developer
Nov 19, 2010 at 11:37 PM

Look at, I think it's called MapFunctionIdentify or something in DotSpatial.Controls.  It is the feature identifier for when you click on the map, but it doesn't care about your selection, it just returns results for everything.  You can subclass the MapFunction class, override the mouse events to your liking.  To add it, use the constructor with the Map if you want to use the "Map" variable internally like: CustomMapFunction myInstance = new CustomMapFunction(map1);  In your constructor you call the base MapFunction constructor with the Map parameter like:

Public CustomFunction(IMap map):base(map)

To make your function work you need to add the instance to the maps MapFunctions

map1.MapFunctions.Add(myInstance);

You can enable it directly, but I'd recommend using the activate method.  I'm winging this off the top of my head so it might not be exact, but it's something like

map1.ActivateFunction(myInstance);

This method should also turn off anything that conflicts.  Declare conflicts by setting the "YieldTypes" enumeration.  This has the flags setting so that you can support multiple forms of user interface.

 

Basically you can look at the existing code in MapFunctionIdentify and replicate almost everything there.

 

Ted

 

Nov 20, 2010 at 1:46 PM

A quick and easy way is to use the normal selection tool and the maps SelectionChanged event.

In the event use the Layer.Selection.GetAttributes method to get the datatable.

Developer
Nov 20, 2010 at 3:37 PM

Thank you dotnetsa!  I tend to over engineer my solutions ;)  Ask me to make the MapWindow ActiveX work as a .Net control and instead of a 1 to 1 translation into .Net,  you get an entire DotSpatial framework.  The way I solve problems may be overkill in many cases =)

 

Ted