I’m currently trying to achieve that i can select shapes from a layer within a polygon. The problem is that i’m not sure how to get the selected polygon corner points correctly. I saw a forum post here (Selection by polygon) and also checked out the MapWindow implementation (https://github.com/MapWindow/MapWindow5/blob/aa545a06ad5e730947374d2c828a95f3ddab1dfb/src/Plugins/MW5.ShapeEditor/MapListener.cs#L101) but i don’t get how to get the points of the polygon which i am drawing from those examples. On the map i select the points with left click and end the selection with CTRL + left click. The CTRL + left click invokes the ChooseLayerEvent but from there on i haven’t a good clue how to continue.
Thanks for the response @jerryfaust
I now understood how to select the shapes with the tkCursorMode.cmSelectByPolygon Mode.
There were also two other important steps i was missing out, they were already mentioned in the forum post in the link above:
To be able to select shapes in a layer the shapefile’s Selectable property has to be set to true before using the selection
The CTRL + left click triggers the ChooseLayer Event (this is stated in the documentation). Since i wanted to select all shapes in the polygon area of all my layers on the map i had to set the e.layerHandle to -1 (this wasn’t stated explicitly in the documentation):
However i’m also trying to achieve a second goal which i might not stated clearly in my first post:
When finishing the polygon selection i want to get the polygon coordinates as e. g. a list of points.
I thought about capturing the MouseUpEvent and then adding the points to the list when i’m in the SelectByPolygon Mode. However this might be a bit error prone and if there is a way to retrieve the polygon directly after finishing the selection from another event please let me know.
Glad you got that going. Just FYI, the OCX initializes the LayerHandle to -1 before raising the ChooseLayer event, so it will automatically be -1 unless you change it. In your case, you can simply omit the handler and it will work fine.
Regarding the points of the user-drawn polygon; those are not available publically. You can get them if you customize the OCX code. I once did this for a customer to expose the click points of the measuring tool.
through other requirements i came across the Map.ShapeEditor which seems to be the location for the selected polygon shape. When listening to the AxMap.DblClick event the selected polygon can be read by using the Map.ShapeEditor.ValidatedShape Property. Also if there are errors (self-intersection or only two points but the polygon shape requires three points) the Map.ShapeValidationFailed event is fired which can be handled in user code. Unfortunately when the OnChooseLayer Event is fired, the ValidatedShape Property doesn’t contain the polygon shape anymore. So this workaround did avoid changing the OCX code for me just for your interest.
I’m sorry, but I’m not sure what you’re asking. Are you asking for a VB6 code example of the above snippet? All of this can be done in VB6, but the syntax is a little different. For instance, many of the functions that are prefixed with get_ will not have the prefix in VB 6. So something like:
Dim sf As Shapefile
Set sf = axMap1.Shapefile(e.LayerHandle)
Dim i As Integer
For i = 0 To sf.numShapes - 1
If sf.ShapeSelected(i) Then
'' do something
End If
Next i