Quantcast
Viewing all articles
Browse latest Browse all 2341

New Post: Showing Point attributes

i tried to select a point and show their information.
then i found at http://www.mapwindow.org/documentation/mapwingis4.8/_tool_tip_8cs-example.html , and this is the codes (VB.NET) :
Public Partial Class MapMain
    ' the handle of the drawing layer
    Private m_drawingHandle As Integer = -1

    ' Opens a shapefile, registers event handler
    Public Sub ToolTip(axMap1 As AxMap, dataPath As String)
        Dim filename As String = dataPath & "point.shp"

        If Not File.Exists(filename) Then
            MessageBox.Show("Couldn't file the file: " & filename)
            Return
        End If

        Dim sf As New Shapefile()
        sf.Open(filename, Nothing)
        If Not sf.StartEditingShapes(True, Nothing) Then
            MessageBox.Show("Failed to start edit mode: " & sf.Table.get_ErrorMsg(sf.LastErrorCode))
        Else
            sf.UseQTree = True
            sf.Labels.Generate("[Name]", tkLabelPositioning.lpCentroid, False)

            axMap1.AddLayer(sf, True)
            axMap1.SendMouseMove = True
            axMap1.ShowRedrawTime = True
            axMap1.MapUnits = tkUnitsOfMeasure.umMeters
            axMap1.CurrentScale = 50000
            axMap1.CursorMode = tkCursorMode.cmNone
            MapEvents.MouseMoveEvent += New AxMapWinGIS._DMapEvents_MouseMoveEventHandler(AddressOf axMap1_MouseMoveEvent)
            ' change MapEvents to axMap1
            Dim m_drawingHandle As Integer = axMap1.NewDrawing(tkDrawReferenceList.dlScreenReferencedList)
            Dim labels As Labels = axMap1.get_DrawingLabels(m_drawingHandle)
            labels.FrameVisible = True
            labels.FrameType = tkLabelFrameType.lfRectangle
        End If
    End Sub


    ' Handles mouse move event. Determines which shape is under cursor. Calls drawing routine.
    Private Sub axMap1_MouseMoveEvent(sender As Object, e As _DMapEvents_MouseMoveEvent)
        Dim labels As Labels = axMap1.get_DrawingLabels(0)
        labels.Clear()

        ' it's assumed here that the layer we want to edit is the first 1 (with 0 index)
        Dim layerHandle As Integer = axMap1.get_LayerHandle(0)
        Dim sf As Shapefile = axMap1.get_Shapefile(layerHandle)
        If sf IsNot Nothing Then
            Dim projX As Double = 0.0
            Dim projY As Double = 0.0
            axMap1.PixelToProj(e.x, e.y, projX, projY)

            Dim result As Object = Nothing
            Dim ext As New Extents()
            ext.SetBounds(projX, projY, 0.0, projX, projY, 0.0)
            If sf.SelectShapes(ext, 0.0, SelectMode.INTERSECTION, result) Then
                Dim shapes As Integer() = TryCast(result, Integer())
                If shapes.Length = 1 Then
                    Dim s As String = ""
                    For i As Integer = 0 To sf.NumFields - 1
                        s += sf.Field(i).Name + ": " & sf.CellValue(i, shapes(0)) & vbLf
                    Next
                    labels.AddLabel(s, e.x + 80, e.y, 0.0, -1)

                    Dim shape As Shape = sf.Shape(shapes(0))
                End If
            End If
        End If

        axMap1.Refresh()
    End Sub
End Class
Unfortunately, i'm still get some error
  1. 'MapEvents' is not declared. It may be inaccessible due to its protection level
  2. labels.Clear() : Object reference not set to an instance of an object.
i'm newbie using mapwingis, please somebody can help me ?
Thank

Viewing all articles
Browse latest Browse all 2341

Trending Articles