This project is read-only.

Showing Point attributes

Feb 20, 2014 at 3:01 AM
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
Feb 20, 2014 at 12:37 PM
Hello Charista,
maybe you have to set AxMap1.sendMouseMove=true (in VB it may be different). That could solve one of your problems.
Greetings Maurits


2014-02-20 4:01 GMT+01:00 Charista <[email removed]>:

From: Charista

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

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Feb 20, 2014 at 12:39 PM
Hello Charista,
now I see that is done.orry.
Gr.Maurits


2014-02-20 13:37 GMT+01:00 Maurits van Ravesteijn <[email removed]>:
Hello Charista,
maybe you have to set AxMap1.sendMouseMove=true (in VB it may be different). That could solve one of your problems.
Greetings Maurits


2014-02-20 4:01 GMT+01:00 Charista <[email removed]>:

From: Charista

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

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com



Nov 2, 2015 at 3:08 AM
Hello,

Sorry for this so very late post, but I came with a solution for this, in VB and in C#:

What's important though is that it's not a mapwinGIS problem. It's about windows event handlers.

In VB, the event handling subs (such as "control_MousMoveEvent") usually have their handles associated automaticallly, like in this line of code:
Private Sub AxMap1_MouseDownEvent(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent
You see, the "Handles..." takes care of the handling and you don't have to bother with assigning a handle to the event. In your code, there is no mention to that handle. So the author wrote the code for the handle himself. This MapEvents variable was probably declared somewhere else in his project, so it's not clear what it means. But it's surely related to windows and not to MapWinGIS, as I'll show in the C# example that follows.

The easiest solution in this case would be to put the "Handles AxMap1..." in your code as shown above and delete the line referring to MapEvents.

In C#, you create the event handling method and associate a mouse handler to it, as shown in the following code just after the main form declaration, at the beginning of the class declaration:
      public fmMain()
    {
        InitializeComponent();
        ...
        AxMap1.MouseDownEvent += new AxMapWinGIS._DMapEvents_MouseDownEventHandler(AxMap1_MouseDown);

With this line, I assign a handler to the method "AxMap1_MouseDown", which is a customized MouseDownEvent method where I put the code to do whatever I want to do when the user clicks the mouse...

Of course, the "axMap.SendMouseMove = True" applies, in both languages. And you can also set it to "TRUE" in design time, as it's a property of the axMap control.

Et voilá, it works!! At least for me, both in VB and C#.

Hope I was of some help... and since I came upon this thread over the same "MapEvents" issue, I hope it gives some answers to others who face the same problem, particularly newbies as myself, relying on the MapWinGIS documentation code to reduce the learning curve...

Regards,

PGSCosta
Jan 21, 2016 at 4:29 PM
Thanks for sharing your code. It looks fine to me.

What is the status of your development project? Is it finished, still ongoing, abandoned?

If it is finished or still ongoing you might want to consider migrating your application to a MapWindow5 plug-in.

Regards,

Paul
Jan 26, 2016 at 8:56 PM
Dear Paul,

Thanks for the feedback! I hope that code can help others... My project is still ongoing and my clients are very happy with the solutions I am developing using MapWinGis. I will take a look at the MapWindows5 plugin!

Regards,

P. Costa

2016-01-21 14:29 GMT-02:00 pmeems <[email removed]>:

From: pmeems

Thanks for sharing your code. It looks fine to me.

What is the status of your development project? Is it finished, still ongoing, abandoned?

If it is finished or still ongoing you might want to consider migrating your application to a MapWindow5 plug-in.

Regards,

Paul

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com