RectLatLng to a GMapPolygon or GMapRoute?

Topics: Help
Feb 1, 2012 at 8:22 PM

Is there a way to do this, i might not be understanding the basic math of a polygon :)

but it there a way to generate a "list of points" from a RectLatLng object?

Feb 1, 2012 at 8:35 PM
Edited Feb 1, 2012 at 8:35 PM

List<RectLatLng> points = new ... ?

Feb 2, 2012 at 12:54 AM

I don't want a list of RectLatLng objects, i want to convert the actual border of the rectangle into a GmapRoute or Polygon, basically turning the "border" into a shape.

I generate a RectLatLng object and i want to draw it on the map (sort of like your SelectedArea) to be a polygon on the map.

Feb 2, 2012 at 7:31 AM

so whats the problem?

Mar 5, 2012 at 11:46 AM
Edited Mar 5, 2012 at 11:47 AM

Try with that. It should allow you create new marker which will be added to the map. It will have associated polygon with shape created by mouse. Dirty hack in file GMapControl.cs

 

 

 protected override void OnMouseUp(MouseButtonEventArgs e)
      {
         if(isSelected)
         {
            isSelected = false;
         }

         if(Core.IsDragging)
         {
            if(isDragging)
            {
               Mouse.Capture(null);

               isDragging = false;
               Debug.WriteLine("IsDragging = " + isDragging);
               Cursor = cursorBefore;
            }
            Core.EndDrag();

            if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position))
            {
               if(Core.LastLocationInBounds.HasValue)
               {
                  Position = Core.LastLocationInBounds.Value;
               }
            }
         }
         else
         {
            if(!selectionEnd.IsZero && !selectionStart.IsZero)
            {
               if(!SelectedArea.IsEmpty && Keyboard.Modifiers == ModifierKeys.Shift)
               {
                  SetZoomToFitRect(SelectedArea);
               }
            }
            else
            {
               if(e.ChangedButton == DragButton)
               {
                  Core.mouseDown = GPoint.Empty;
               }
               InvalidateVisual();
            }
         }

         if ((!selectionEnd.IsZero) && (Keyboard.Modifiers == ModifierKeys.Alt))
         {
             GMap.NET.PointLatLng p1 = selectionStart;
             GMap.NET.PointLatLng p2 = selectionEnd;
            
             GMapMarker m = new GMapMarker(new PointLatLng(p1.Lat, p1.Lng));

             PointLatLng s1 = new PointLatLng(p1.Lat, p1.Lng);
             PointLatLng s2 = new PointLatLng(p2.Lat, p1.Lng);
             PointLatLng s3 = new PointLatLng(p2.Lat, p2.Lng);
             PointLatLng s4 = new PointLatLng(p1.Lat, p2.Lng);

             m.DrawColor = Brushes.DarkBlue;
             m.Polygon.Add(s1);
             

             m.Polygon.Add(s2);
             m.Polygon.Add(s3);
             m.Polygon.Add(s4);
             m.RegeneratePolygonShape(this);
             SelectedArea = RectLatLng.Empty;
             this.Markers.Add(m);
         }

         base.OnMouseUp(e);
      }
Mar 5, 2012 at 12:13 PM

..well with that you may generate thousand of shapes on each mouse move ;}

Mar 5, 2012 at 12:16 PM

I think, that this code is run only when you finish drag mouse with pressed left key and alt.

Mar 5, 2012 at 12:21 PM

mm, maybe you're right ;}