This project is read-only.


Nov 15, 2010 at 8:44 AM

How to get the shape the user clicked on?

Something like a GetShape(X,Y)

Nov 15, 2010 at 4:23 PM

So if you are responding to the MapMouseUp kind of event, you should get both an X,Y pixel coord and the event argument should have the geographic coordinate as well.  You should have access to the Map directly as a variable of some kind like map1.  So you can get the active layer via:

foreach(ILayer layer in map1.GetLayers())
   // this part is optional, but you can restrict what layers to check
   // to just the layers selected in the legend.
      // test if it is a vector layer
      IFeatureLayer fl = layer as IFeatureLayer;
      if(fl == null)continue;
      IFeatureSet fs = layer.DataSet;
      IList<IFeature> results = fs.Select(...appropriate envelopes etc)

The steps above are easier if keep track of the layer you care about as a class level variable in your form.  So in other words,  if they are only supposed to be working with one layer, then just keep a reference to the FeatureSet around that they should be interacting with and use the Select method.  A point clicked is still an envelope, just one with a width and height of 0.  That works for polygons, but I'd expand it by about 8 pixels in either direction for working with points or lines.  You can take advantage of the map1.PixelToProj and map1.ProjToPixel approaches to go back and forth between say a rectangle in pixels and an Extent.  (Extent in the lastest release, IEnvelope in previous releases).




Nov 16, 2010 at 5:56 AM

Thanks for the reply.

My approach is nearly the same:

Dim cCoor As Coordinate = Map1.PixelToProj(e.Location)
Dim Ex As New Extent(cCoor.X, cCoor.Y, cCoor.X, cCoor.Y)
Dim en As DotSpatial.Topology.IEnvelope = Ex.ToEnvelope
mLayer = Map1.Layers(0)
Dim affectedArea As Envelope = Nothing
mLayer.Select(Map1.ViewExtents.ToEnvelope, en, DotSpatial.Symbology.SelectionMode.IntersectsExtent, affectedArea)

But sometimes it is selecting 2 polygons, if I click near the border of both polygons! (No, the polygons doesn't overlap)

Would you know the reason for this?