Enable/Disable Map Selection

Topics: Feature Requests, Windows Forms
Jun 27, 2012 at 8:15 PM
Edited Jun 28, 2012 at 1:03 PM

I was looking for a way to Enable/Disable the selection utility the map has, but I couldn't find any option.

So I downloaded the source code and made a tiny modification, as follows:

1. I added this property 

      /// <summary>
      /// is selection enabled. Default is false
      /// </summary>
      [Category( "GMap.NET" )]
      public bool DisableSelectArea { get; set; }

 

2. Then I modified the following method on GMap.NET.WindowsForms.GMapControl.cs:

 

      protected override void OnMouseDown(MouseEventArgs e)
      {
         if(!IsMouseOverMarker)
         {
#if !PocketPC
            if(e.Button == DragButton && CanDragMap)
#else
            if (CanDragMap)
#endif
            {
#if !PocketPC
               Core.mouseDown = ApplyRotationInversion(e.X, e.Y);
#else
               Core.mouseDown = new GPoint(e.X, e.Y);
#endif
               this.Invalidate();
            }
            else if(!isSelected && !DisableSelectArea) //I added the disable option
            {
               isSelected = true;
               SelectedArea = RectLatLng.Empty;
               selectionEnd = PointLatLng.Empty;
               selectionStart = FromLocalToLatLng(e.X, e.Y);
            }
         }

         base.OnMouseDown(e);
      }

I'd like to suggest the implementation of this option in future buildings.

I hope my code is useful.

 

Thanks,

Cleverson Nascimento