> Yes, please post your code. I may not be able to use it but someone
> else could.
Here's my very rough code, rough but it works!
///set up the image
System.Drawing.Image img = new System.Drawing.Bitmap(640,
640);
System.Drawing.Graphics grf =
System.Drawing.Graphics.FromImage(img);
System.Drawing.Pen pen = new
System.Drawing.Pen(System.Drawing.Brushes.Blue);
pen.Width = 5;
//List to hold all the GPoints in the boundary
List<GPoint> points = new List<GPoint>();
//extract the points from the database
using (SqlConnection conn = new SqlConnection("..."))
{
System.Data.SqlClient.SqlCommand cmd =
conn.CreateCommand();
cmd.CommandText = @"SELECT
Point.Longitude,
Point.Latitude
FROM Boundary INNER JOIN
Point ON Boundary.Id =
Point.Boundary
WHERE (Boundary.Code = 'AA')";
cmd.CommandType = System.Data.CommandType.Text;
conn.Open();
using (System.Data.SqlClient.SqlDataReader r =
cmd.ExecuteReader())
{
while (r.Read())
{
points.Add(new
GPoint((double)r["Latitude"], (double)r["Longitude"]));
}
}
}
//Set the centre point for the image and the image
properties
GPoint centre = new GPoint(53.605544, -1.428223);
int zoomLevel = 10;
int imageHeight = 640;
int imageWidth = 640;
GPoint previous = null;
//Loop through each point drawing a line between them.
//Could be optimised here to only draw points that are
visible on the output image
foreach (GPoint gp in points)
{
if (previous != null)
{
//PointOnImage returns a Point with the X,Y in
pixels on the output images.
System.Drawing.Point start =
previous.PointOnImage(centre, zoomLevel, imageWidth, imageHeight);
System.Drawing.Point end =
gp.PointOnImage(centre, zoomLevel, imageWidth, imageHeight);
grf.DrawLine(pen, start, end);
}
previous = gp;
}
//Save the image
img.Save(@"C:\tst.gif",
System.Drawing.Imaging.ImageFormat.Gif);
The code uses my own GPoint class, which includes the code from your
js
private class GPoint
{
#region public properties
private double _Latitude;
/// <summary>
/// WGS84 Latitude
/// </summary>
public double Latitude
{
get { return _Latitude; }
}
private double _Longitude;
/// <summary>
/// WGS84 Longitude
/// </summary>
public double Longitude
{
get { return _Longitude; }
}
private int _X;
/// <summary>
/// Google map Pixel x co-ordinate
/// </summary>
public int X
{
get { return _X; }
}
private int _Y;
/// <summary>
/// Google map Pixel y co-ordinate
/// </summary>
public int Y
{
get { return _Y; }
}
#endregion
#region Constructors
/// <summary>
/// Takes a Lat/Lng and calculates the X & Y values
/// </summary>
/// <param name="latitude"><see cref="Latitude"/></param>
/// <param name="longitude"><see cref="Longitude"/></
param>
public GPoint(double latitude, double longitude)
{
this._Latitude = latitude;
this._Longitude=longitude;
//convert the lat/lng to GMap pixels
this._X = GPoint.LonToX(longitude);
this._Y = GPoint.LatToY(latitude);
}
#region methods for calculation X & Y
private const int offset = 268435456;
private const double radius = offset / Math.PI;
private static int LonToX(double longitude)
{
return (int)Math.Round(offset + radius * longitude *
Math.PI / 180,0);
}
private static int LatToY(double latitude)
{
return (int)Math.Round(offset - radius * Math.Log((1 +
Math.Sin(latitude * Math.PI / 180)) / (1 - Math.Sin(latitude *
Math.PI / 180))) / 2,0);
}
#endregion
#endregion
#region Public methods
/// <summary>
/// Takes some image properties and returns the pixel co-
ordinates for this <see cref="GPoint"/>
/// </summary>
/// <param name="mapCenter">A <see cref="GPoint"/>
representing the centre point of the image</param>
/// <param name="zoomLevel">The Google Maps zoom level
(currently 0 to 21)</param>
/// <param name="imageWidth">Image width in pixels</param>
/// <param name="imageHeight">Image height in pixels</
param>
/// <returns></returns>
public System.Drawing.Point PointOnImage(GPoint mapCenter,
int zoomLevel, int imageWidth, int imageHeight)
{
int deltaY=(this.Y-mapCenter.Y)>>(21-zoomLevel);
int deltaX=(this.X-mapCenter.X)>>(21-zoomLevel);
int center_offset_x =
(int)Math.Round((double)imageWidth / 2,0);
int center_offset_y =
(int)Math.Round((double)imageHeight / 2, 0);
return new System.Drawing.Point(center_offset_x +
deltaX, center_offset_y + deltaY);
}
#endregion
}
>
> I updated "adjust.js" a few days ago. It now has inverse functions:
>
> LLToXY
> XYToLL
Thanks for them, they could be very useful.
> I agree with your desire to combine Google's map with your markers at
> your server but it is unlikely to happen. It is much more efficient
> to send one file than several over a potentially slow link. Combining
> overlays in the browser impedes both panning & zooming.
When I get it a bit more ironed out and more generic, I may look at
uploading it as a control on google code or such like. I also plan on
using similar code to generate automatic imagemaps and if I can't
alter the google image, generate the code to overlay images.
Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---