Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to link drawings on on-line maps to the map

How to link drawings on on-line maps to the map

Scheduled Pinned Locked Moved Windows Forms
csharpgraphicshelptutorial
5 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 8399865
    wrote on last edited by
    #1

    I'm using Visual C# 2010 Express. I've written code to display Provider maps on my form. I can draw lines on the maps, and capture the latitude / longitude from the map. My problem is that when I pan or zoom the map, my drawn line stays in one place; it doesn't move or resize with the map. I'm using a gMap control to load the provider maps as below:

    private void Form1_Load(object sender, EventArgs e)
    {
    // Initialize map:
    //gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
    gMapControl1.MapProvider = GMap.NET.MapProviders.ArcGIS_Topo_US_2D_MapProvider.Instance;
    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
    gMapControl1.Position = new GMap.NET.PointLatLng(39.401389, -077.986111); //mrb
    gMapControl1.Zoom = 10;

    I've created an Overlay for my form, and I'm drawing on the overlay as below:

    private void graphicalOverlay1_Paint(object sender, PaintEventArgs e)
    {
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    Pen fl = new Pen(Color.Red, 3.0f);
    e.Graphics.DrawLine(fl, x_start, y_start, xx, yy);

        }
    

    Perhaps I shouldn't be drawing on the Overlay. But I don't know how to just draw on the providers image. Any direction to "lock" my drawn lines with the map would be appreciated. Thanks AW

    B 1 Reply Last reply
    0
    • U User 8399865

      I'm using Visual C# 2010 Express. I've written code to display Provider maps on my form. I can draw lines on the maps, and capture the latitude / longitude from the map. My problem is that when I pan or zoom the map, my drawn line stays in one place; it doesn't move or resize with the map. I'm using a gMap control to load the provider maps as below:

      private void Form1_Load(object sender, EventArgs e)
      {
      // Initialize map:
      //gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
      gMapControl1.MapProvider = GMap.NET.MapProviders.ArcGIS_Topo_US_2D_MapProvider.Instance;
      GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
      gMapControl1.Position = new GMap.NET.PointLatLng(39.401389, -077.986111); //mrb
      gMapControl1.Zoom = 10;

      I've created an Overlay for my form, and I'm drawing on the overlay as below:

      private void graphicalOverlay1_Paint(object sender, PaintEventArgs e)
      {
      e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
      Pen fl = new Pen(Color.Red, 3.0f);
      e.Graphics.DrawLine(fl, x_start, y_start, xx, yy);

          }
      

      Perhaps I shouldn't be drawing on the Overlay. But I don't know how to just draw on the providers image. Any direction to "lock" my drawn lines with the map would be appreciated. Thanks AW

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      e.Graphics.DrawLine(fl, x_start, y_start, xx, yy); uses pixel values, not geo coordinates. You have to get the latitude/longitude values for your lines, the transform them into pixels using the zoom and offset values of the underlying map.

      U 1 Reply Last reply
      0
      • B Bernhard Hiller

        e.Graphics.DrawLine(fl, x_start, y_start, xx, yy); uses pixel values, not geo coordinates. You have to get the latitude/longitude values for your lines, the transform them into pixels using the zoom and offset values of the underlying map.

        U Offline
        U Offline
        User 8399865
        wrote on last edited by
        #3

        Bernhard; Thank you for reading my post question and replying. I'm getting the lat/long coordinates with this:

           private void gMapControl1\_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    double lat = gMapControl1.FromLocalToLatLng(e.X, e.Y).Lat;
                    double lng = gMapControl1.FromLocalToLatLng(e.X, e.Y).Lng;
                    //------------------------------------------------
        

        This returns decimal degrees which I then convert to dd-mm-ss.sss. I was using the following to paint my lines on the provider map, which does work to paint the lines;

            private void gMapControl1\_Paint(object sender, PaintEventArgs e)
            {
        
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                Pen fl = new Pen(Color.Red, 3.0f);
                e.Graphics.DrawLine(fl, x\_start, y\_start, xx, yy);
        

        But x_start, y_start, xx, yy are nothing more than screen coordinates; just like with the overlay code. And when I pan or zoom, the map moves but my drawn lines stay in the same place relative to the screen.

                   x\_start = e.X;
                    y\_start = e.Y
        

        Are you saying that I need to pass the geo coordinates to xx, yy to draw the lines on the providers map? I don't understand your statement; "then transform them into pixels using the zoom and offset values of the underlying map".

        U 1 Reply Last reply
        0
        • U User 8399865

          Bernhard; Thank you for reading my post question and replying. I'm getting the lat/long coordinates with this:

             private void gMapControl1\_MouseClick(object sender, MouseEventArgs e)
              {
                  if (e.Button == MouseButtons.Left)
                  {
                      double lat = gMapControl1.FromLocalToLatLng(e.X, e.Y).Lat;
                      double lng = gMapControl1.FromLocalToLatLng(e.X, e.Y).Lng;
                      //------------------------------------------------
          

          This returns decimal degrees which I then convert to dd-mm-ss.sss. I was using the following to paint my lines on the provider map, which does work to paint the lines;

              private void gMapControl1\_Paint(object sender, PaintEventArgs e)
              {
          
                  e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                  Pen fl = new Pen(Color.Red, 3.0f);
                  e.Graphics.DrawLine(fl, x\_start, y\_start, xx, yy);
          

          But x_start, y_start, xx, yy are nothing more than screen coordinates; just like with the overlay code. And when I pan or zoom, the map moves but my drawn lines stay in the same place relative to the screen.

                     x\_start = e.X;
                      y\_start = e.Y
          

          Are you saying that I need to pass the geo coordinates to xx, yy to draw the lines on the providers map? I don't understand your statement; "then transform them into pixels using the zoom and offset values of the underlying map".

          U Offline
          U Offline
          User 8399865
          wrote on last edited by
          #4

          Oh, I think I understand what you meant! I need to do something like Double map_x equals gMapControl1.FromMapLatLngToLocal(PiontLatLng Point); Then when I pan or zoom, just redraw my lines. Can you provide the proper syntax for MapLatToLocal ?

          B 1 Reply Last reply
          0
          • U User 8399865

            Oh, I think I understand what you meant! I need to do something like Double map_x equals gMapControl1.FromMapLatLngToLocal(PiontLatLng Point); Then when I pan or zoom, just redraw my lines. Can you provide the proper syntax for MapLatToLocal ?

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            That's the way to go. But I do not know the functions provided by the control. Why don't you ask the author - there is a section below his article for taht purposes, isn't it?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups