How to hover over a shape with the mouse

May 3, 2011 at 6:57 AM

Hello!!

I have a problem. I don´t know how can I search a shape in the map. I mean, I want to detect when I'm hovering over a shape.

I don´t know how to detect a shape in the map.

 

Thank you very much!!

May 3, 2011 at 7:28 AM

hi

you can use the MouseMove events of the map control, and convert the x and y to projected coordinates

with VB6 it coud be like that:

Private Sub map_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)

Dim xProj As Double, yProj As Double
dim result as variant
dim xt as new extents
dim ret as boolean

   Map.PixelToProj x, y, xProj, yProj
   xt.SetBounds(xproj, yproj,0,xproj,yproj,0)
  ret= sf.selectshapes(xt,0,intersection)
   if not ret then exit sub

   for i = 0 to ubound(result)
      map.shapefillcolor(sfhandle,i)=rgb(255,0,0)'coloring the shape under the mouse in red
   next i

end sub

 

May 3, 2011 at 8:18 AM

Thak you for your fast response, but I'm programming in C# and i have problems.

I show you my code:

private void axMap1_MouseMoveEvent(object sender, AxMapWinGIS._DMapEvents_MouseMoveEvent e)
        {
            double xLocation = 0;
            double yLocation = 0;
            Extents ext = new Extents();
            object resul = new object();
            bool esta;

            axMap1.PixelToProj(e.x, e.y, ref xLocation, ref yLocation);
        
            MapWinGIS.Shapefile shp = new MapWinGIS.Shapefile();
            shp.Open(@"D:\MapWindow2\Prueba_Mapa2\Prueba_Mapa2\shapes\barcos.shp", null);

            ext.SetBounds(xLocation, yLocation, 0, xLocation, yLocation, 0);

            esta = shp.SelectShapes(ext, 0, SelectMode.INTERSECTION, ref resul);

            if (esta)
            {
                MessageBox.Show("Esta");
                for (int ind = 0; ind < shp.NumShapes; ind++)
                {
                         axMap1.set_ShapePointColor(shp, ind,
                           (UInt32)(System.Drawing.ColorTranslator.ToOle
                           (System.Drawing.Color.Chocolate)));
                   }
            }
       
            string pointLocation = "Localizacion Cursor Mapa: " +  Math.Round(xLocation, 3) + " | " + Math.Round(yLocation, 3) + "<->" + esta;
            toolStripStatusLabel1.Text = pointLocation;
       }

 

 

Thank you!

May 3, 2011 at 8:46 AM
Edited May 3, 2011 at 9:24 AM

I correct the problem.

The problem was on the field "tolerance" that was of 0.       I have changed this field to 2.0 on the result is OK.

Thank you, very much!