This project is read-only.

Selecting Shape on MouseDown

Jun 7, 2013 at 8:30 AM
Edited Jun 8, 2013 at 1:47 AM
HI, the code provided by Shade1974

is not working for me can anybody help me,
    Dim ext As New MapWinGIS.Extents
    Dim TL, BR As MapWinGIS.Point
    Dim shapes As Object 'Or Variant type in VB6
    Dim shp As Integer
    Dim Buffer As Integer
    TL = New MapWinGIS.Point 'Top Left Projected
    BR = New MapWinGIS.Point 'Bottom Right Projected
    Buffer = 5 'For points and lines give a 5 pixel buffer for selecting the shapes
    'For polygons, select shapes exactly
    If get_myClass() = "Polygon" Then Buffer = 0

    MainMap.PixelToProj(e.x - Buffer, e.y + Buffer, TL.x, TL.y)
    MainMap.PixelToProj(e.x + Buffer, e.y - Buffer, BR.x, BR.y)
    ext = New MapWinGIS.Extents
    ext.SetBounds(TL.x, BR.y, 0, BR.x, TL.y, 0)

    If Not MainParcel.SelectShapes(ext, 0, MapWinGIS.SelectMode.INTERSECTION, shapes) = False Then

        Dim xxx As String
        For shp = 0 To shapes.GetUpperBound(0)
            Dim xx As Integer
            xx = 0

            xxx = MainParcel.Field(2).Name.ToString & " : " & MainParcel.CellValue(2, shapes(shp).ToString)
            Me.TopMost = False
            'Me.AxMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone
            'Me.AxMap1.SendMouseDown = 0
        Next shp
    End If

but when i increase the tolerance the it returns the surrounding shape along with the shape i selected
what happen,:(
I mean, the code doesnt work on polygon,
Jun 9, 2013 at 7:58 PM
Hi Pein,

I am not entirely certain from your description what is the exact problem you're having, but if what you're experiencing is false positives from SelectShapes (shapes are selected that are outside your proximity tolerance) there is a bug in the code for that function that can cause these problems. Paul had indicated this bug was fixed in the latest beta release of the map control, but I am still experiencing problems with shapes being selected that should not be.

This is my workaround, which is working great for me. Sorry it's not in VB, but of course easy to convert:
            if (sf.SelectShapes(ext, proximityTolerance, SelectMode.INTERSECTION, ref result)) {
                 int[] candidateShapes = result as int[]; //these shapes might be close
                ArrayList qualifyingShapes = new ArrayList(); //these shapes definitely are close

                Shape selectedShape = new Shape();

                for (int i = 0; i < candidateShapes.Length; i++) {
                    selectedShape = sf.get_Shape((int)candidateShapes[i]);
                    // Compute distance to point that represents mouse location
                    if (selectedShape.Distance(shpMouseLocation) < proximityTolerance) {
                        // Passed the test, so add to list of qualifying shapes
Don Rahmlow
Readfield, ME US
Jun 14, 2013 at 5:57 AM
Hi Don,

it seems that the problem is in my shape file i dunno, i tried loading a different shape file, and it is working, wth,
anyways thanks for dropping by ^ ^