How draw a mark in a static map image from coordinates?

Nov 8, 2009 at 5:06 PM

I try to draw mark in a static map image from a coordinates.

 

But the conversion from the coordinates to pixel is not successful.

in the bg_DoWork method of the StaticImage form, I add this:

using (Graphics gfx = Graphics.FromImage(bmpDestination))
{        
         gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
         GMap.NET.Point point = info.Projection.FromLatLngToPixel(customMark.Position, info.Zoom);
         gfx.DrawIcon(icon1, point.X, point.Y);

}

 

but this dont work

I know the coordinates of the custom mark are in the rectangle of the map.

 

what is wrong?

 

Coordinator
Nov 8, 2009 at 5:55 PM

try MainMap.FromLocaltoLatLng

Nov 9, 2009 at 1:19 AM

does not work. neither FromLatLngToLocal method

 

Coordinator
Nov 9, 2009 at 9:22 AM

well it's complicated, what do you want exactly?

Nov 13, 2009 at 6:12 PM

 

is work! i do this

in the bg_DoWork method of the StaticImage form

 

 

using (Graphics gfx = Graphics.FromImage(bmpDestination))

{

   gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

   IntPtr iconHandle2 = Properties.Resources.marker99.GetHicon();

   Icon icon2 = Icon.FromHandle(iconHandle2);

   foreach (var marker in info.Markers)

   {

	   if (marker.GetType() == typeof(GMapMarkerCustom))

	   {

		   GMapMarkerCustom customMark = (GMapMarkerCustom)marker;

		   IntPtr iconHandle1 = Properties.Resources.legendIcon.GetHicon();

		   Icon icon1 = Icon.FromHandle(iconHandle1);

		   

		   int x, y = 0;

		   FromLatLngToLocal(info, rect.Height, rect.Width, customMark.Position.Lat, customMark.Position.Lng, out x, out y);



		   gfx.DrawIcon(icon1, x, y);

		   gfx.DrawString(marker.Tag.ToString(), SystemFonts.DefaultFont, Brushes.Red, x + 10, y - 10);

	   }



	   if (marker.GetType() == typeof(GMapMarkerPolygon))

	   {

		   GMapMarkerPolygon customMark = (GMapMarkerPolygon)marker;





		   List<System.Drawing.Point> points = new List<System.Drawing.Point>();

		   foreach (var gPoint in customMark.GeoPoints)

		   {

			   int x, y = 0;

			   FromLatLngToLocal(info, rect.Height, rect.Width, gPoint.Lat, gPoint.Lng, out x, out y);

			   points.Add(new System.Drawing.Point(x, y));

		   }

		   Pen pen = new Pen(Color.Blue, 4);

		   pen.DashStyle = DashStyle.DashDotDot;



		   gfx.DrawPolygon(pen, points.ToArray());

	   }

   }

}

 

and:

 

 

private void FromLatLngToLocal(MapInfo info, int imageHeigth, int imageWidth, double lat, double lng, out int x, out int y)

{

	//

	double heigthLat = lat - info.Area.LocationRightBottom.Lat;

	double widthLng = lng - info.Area.LocationTopLeft.Lng;



	y = Convert.ToInt32((heigthLat * imageHeigth) / info.Area.HeightLat);

	x = Convert.ToInt32((widthLng * imageWidth) / info.Area.WidthLng);



	y = imageHeigth - y;



	//calculo un 1% del tamaño de la imágen

	int heigthPer = Convert.ToInt32(imageHeigth * 0.01);

	int widthPer = Convert.ToInt32(imageWidth * 0.01);

	//le sumo un 1%

	y = y + heigthPer;

	x = x + heigthPer;

}

 

 

 

 

 

using (Graphics gfx = Graphics.FromImage(bmpDestination))
{
   gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
   IntPtr iconHandle2 = Properties.Resources.marker99.GetHicon();
   Icon icon2 = Icon.FromHandle(iconHandle2);
   foreach (var marker in info.Markers)
   {
  if (marker.GetType() == typeof(GMapMarkerCustom))
  {
  GMapMarkerCustom customMark = (GMapMarkerCustom)marker;
  IntPtr iconHandle1 = Properties.Resources.legendIcon.GetHicon();
  Icon icon1 = Icon.FromHandle(iconHandle1);
  
  int x, y = 0;
  FromLatLngToLocal(info, rect.Height, rect.Width, customMark.Position.Lat, customMark.Position.Lng, out x, out y);
  gfx.DrawIcon(icon1, x, y);
  gfx.DrawString(marker.Tag.ToString(), SystemFonts.DefaultFont, Brushes.Red, x + 10, y - 10);
  }
  if (marker.GetType() == typeof(GMapMarkerPolygon))
  {
  GMapMarkerPolygon customMark = (GMapMarkerPolygon)marker;
  List<System.Drawing.Point> points = new List<System.Drawing.Point>();
  foreach (var gPoint in customMark.GeoPoints)
  {
  int x, y = 0;
  FromLatLngToLocal(info, rect.Height, rect.Width, gPoint.Lat, gPoint.Lng, out x, out y);
  points.Add(new System.Drawing.Point(x, y));
  }
  Pen pen = new Pen(Color.Blue, 4);
  pen.DashStyle = DashStyle.DashDotDot;
  gfx.DrawPolygon(pen, points.ToArray());
  }
   }
}
private void FromLatLngToLocal(MapInfo info, int imageHeigth, int imageWidth, double lat, double lng, out int x, out int y)
{
//
double heigthLat = lat - info.Area.LocationRightBottom.Lat;
double widthLng = lng - info.Area.LocationTopLeft.Lng;
y = Convert.ToInt32((heigthLat * imageHeigth) / info.Area.HeightLat);
x = Convert.ToInt32((widthLng * imageWidth) / info.Area.WidthLng);
y = imageHeigth - y;
//calculo un 1% del tamaño de la imágen
int heigthPer = Convert.ToInt32(imageHeigth * 0.01);
int widthPer = Convert.ToInt32(imageWidth * 0.01);
//le sumo un 1%
y = y + heigthPer;
x = x + heigthPer;
}

 

 

Coordinator
Nov 13, 2009 at 6:15 PM

great! ;}