Quantcast
Channel: GMap.NET - Great Maps for Windows Forms & Presentation
Viewing all articles
Browse latest Browse all 3384

New Post: Extending maps

$
0
0
Changes to GMapControl.cs continued.

Changes to OnMouseDown:
        else if (!isSelected)
        {
          isSelected = true;
          SelectedArea = RectLatLng.Empty;
#if JpContinuousMap
          selectionEnd = Point.Empty;
          selectionStart = e.Location;
#else // JpContinuousMap
          selectionEnd = PointLatLng.Empty;
          selectionStart = FromLocalToLatLng(e.X, e.Y);
#endif // JpContinuousMap
        }
Changes to OnMouseUp:
          if (OnSelectionChange != null)
          {
            OnSelectionChange(SelectedArea, zoomtofit);
          }
#if JpContinuousMap
          // Clear selection
          selectionStart = Point.Empty;
          selectionEnd = Point.Empty;
          SelectedArea = RectLatLng.Empty;
#endif // JpContinuousMap
Changes to OnMouseClick:
      if (!Core.IsDragging)
      {
#if JpContinuousMap
        // Translate mouse position as if it is over the original map section
        Point mouse = ContinuousMapPosition(e.X, e.Y);
        e = new MouseEventArgs(e.Button, e.Clicks, mouse.X, mouse.Y, e.Delta);
#endif // JpContinuousMap
Changes to OnMouseMove:
        if (isSelected && !selectionStart.IsEmpty && (Form.ModifierKeys == Keys.Alt || Form.ModifierKeys == Keys.Shift || DisableAltForSelection))
        {
#if JpContinuousMap
          selectionEnd = e.Location;

          // Limit selection to map control width
          if (selectionEnd.X > Width)
          {
            selectionEnd.X = Width;
          }
          if (selectionEnd.X < 0)
          {
            selectionEnd.X = 0;
          }

          // Limit the selection to the map width
          if (selectionEnd.X - selectionStart.X >= Core.MapWidthPixels)
          {
            selectionEnd.X = selectionStart.X + (int) Core.MapWidthPixels - 1;
          }
          else if (selectionStart.X - selectionEnd.X >= Core.MapWidthPixels)
          {
            selectionEnd.X = selectionStart.X - (int) Core.MapWidthPixels + 1;
          }

          // Make sure the start is left of end and top is above bottom
          Point pointStart = selectionStart;
          Point pointEnd = selectionEnd;

          if (pointEnd.X < pointStart.X)
          {
            int temp = pointStart.X;
            pointStart.X = pointEnd.X;
            pointEnd.X = temp;
          }
          if (pointEnd.Y < pointStart.Y)
          {
            int temp = pointStart.Y;
            pointStart.Y = pointEnd.Y;
            pointEnd.Y = temp;
          }

          // Convert latitude/longitude pairs
          PointLatLng positionStart = FromLocalToLatLng(pointStart.X, pointStart.Y);
          PointLatLng positionEnd = FromLocalToLatLng(pointEnd.X, pointEnd.Y);

          double width = positionEnd.Lng - positionStart.Lng;
          double height = positionStart.Lat - positionEnd.Lat;

          if (positionStart.Lng > positionEnd.Lng)
          {
            // The selection must have crossed the map boundary
            width += Core.Provider.Projection.Bounds.WidthLng;
          }
          SelectedArea = new RectLatLng(positionStart.Lat, positionStart.Lng, width, height);
#else // JpContinuousMap
          selectionEnd = FromLocalToLatLng(e.X, e.Y);
          {
            GMap.NET.PointLatLng p1 = selectionStart;
            GMap.NET.PointLatLng p2 = selectionEnd;

            double x1 = Math.Min(p1.Lng, p2.Lng);
            double y1 = Math.Max(p1.Lat, p2.Lat);
            double x2 = Math.Max(p1.Lng, p2.Lng);
            double y2 = Math.Min(p1.Lat, p2.Lat);

            SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2);
          }
#endif // JpContinuousMap
        }
        else
#endif
          if (Core.mouseDown.IsEmpty)
          {
#if JpContinuousMap
            // Translate mouse position as if it is over the original map section
            Point mouse = ContinuousMapPosition(e.X, e.Y);
            e = new MouseEventArgs(e.Button, e.Clicks, mouse.X, mouse.Y, e.Delta);
#endif // JpContinuousMap
Changes to FromLocalToLatLng:
    public PointLatLng FromLocalToLatLng(int x, int y)
    {
#if JpContinuousMap
      // Translate position as if it is over the original map section
      Point point = ContinuousMapPosition(x, y);
      x = point.X;
      y = point.Y;
#endif // JpContinuousMap
Changes to MapProvider:
          RectLatLng viewarea = SelectedArea;
#if JpContinuousMap
          if (viewarea != RectLatLng.Empty)
          {
            PointLatLng center = new PointLatLng(viewarea.LocationMiddle.Lat, viewarea.LocationMiddle.Lng);
            // Correct center if it is outside the map boundary
            if (center.Lng > Core.Provider.Projection.Bounds.Right)
            {
              center.Lng -= Core.Provider.Projection.Bounds.WidthLng;
            }
            else if (center.Lng < Core.Provider.Projection.Bounds.Left)
            {
              center.Lng += Core.Provider.Projection.Bounds.WidthLng;
            }
            Position = center;
          }
#else // JpContinuousMap
          if (viewarea != RectLatLng.Empty)
          {
            Position = new PointLatLng(viewarea.Lat - viewarea.HeightLat / 2, viewarea.Lng + viewarea.WidthLng / 2);
          }
#endif // JpContinuousMap

Viewing all articles
Browse latest Browse all 3384


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>