bool CacheTiles(ref MapType[] types, int zoom, GMap.NET.Point p) { foreach (MapType type in types) { Exception ex; PureImage img; // tile number inversion(BottomLeft -> TopLeft) for pergo maps if (type == MapType.PergoTurkeyMap) { img = GMaps.Instance.GetImageFrom(type, new GMap.NET.Point(p.X, maxOfTiles.Height - p.Y), zoom, out ex); } else // ok { img = GMaps.Instance.GetImageFrom(type, p, zoom, out ex); } if (img != null) { img.Dispose(); img = null; } else { return(false); } } return(true); }
void bg_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; GMap.NET.Point p = (GMap.NET.Point)e.UserState; this.Text = "Static Map maker: Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count; }
private GMap.NET.Point rotatePt(double rotationAngle, GMap.NET.Point pointU) { //rotation angle in radians GMap.NET.Point point = new GMap.NET.Point(); point.X = (int)(pointU.X * Math.Cos(rotationAngle) - pointU.Y * Math.Sin(rotationAngle)); point.Y = (int)(pointU.X * Math.Sin(rotationAngle) + pointU.Y * Math.Cos(rotationAngle)); return(point); //throw new NotImplementedException(); }
/// <summary> /// updates marker position, internal access usualy /// </summary> internal void UpdateLocalPosition() { if (Map != null) { GMap.NET.Point p = Map.FromLatLngToLocal(Position); LocalPositionX = p.X + (int)Offset.X; LocalPositionY = p.Y + (int)Offset.Y; } }
void worker_DoWork(object sender, DoWorkEventArgs e) { if (list != null) { list.Clear(); list = null; } list = prj.GetAreaTileList(area, zoom, 0); maxOfTiles = prj.GetTileMatrixMaxXY(zoom); all = list.Count; int countOk = 0; int retry = 0; Stuff.Shuffle <GMap.NET.Point>(list); var types = GMaps.Instance.GetAllLayersOfType(type); for (int i = 0; i < all; i++) { if (worker.CancellationPending) { break; } GMap.NET.Point p = list[i]; { if (CacheTiles(ref types, zoom, p)) { countOk++; retry = 0; } else { if (++retry <= 1) // retry only one { i--; System.Threading.Thread.Sleep(1111); continue; } else { retry = 0; } } } worker.ReportProgress((int)((i + 1) * 100 / all), i + 1); System.Threading.Thread.Sleep(sleep); } e.Result = countOk; }
public GMap.NET.Point AdjustMapPixelsToTilePixels(GMap.NET.Point tileXYPoint, GMap.NET.Point mapPixelPoint) { if (tileXYPoint == null) { throw new ArgumentNullException("Tile X Y Point"); } if (mapPixelPoint == null) { throw new ArgumentNullException("Map Pixel Point"); } return(_pointRepository.AdjustMapPixelsToTilePixels(tileXYPoint, mapPixelPoint)); }
public GMap.NET.Point[] GetPointsForTile(int x, int y, Bitmap dot, int zoom, IEnumerable <PointLatLng> _points) { List <GMap.NET.Point> points = new List <GMap.NET.Point>(); GMap.NET.Size maxTileSize; GMap.NET.Point adjustedPoint; GMap.NET.Point pixelCoordinate; GMap.NET.Point mapPoint; maxTileSize = _projection.GetTileMatrixMaxXY(zoom); //Top Left Bounds GMap.NET.Point tlb = _projection.FromTileXYToPixel(new GMap.NET.Point(x, y)); maxTileSize = new GMap.NET.Size(SIZE, SIZE); //Lower right bounds GMap.NET.Point lrb = new GMap.NET.Point((tlb.X + maxTileSize.Width) + dot.Width, (tlb.Y + maxTileSize.Height) + dot.Width); //pad the Top left bounds tlb = new GMap.NET.Point(tlb.X - dot.Width, tlb.Y - dot.Height); //Go throught the list and convert the points to pixel cooridents foreach (GMap.NET.PointLatLng llPoint in GetList(tlb, lrb, zoom, _points)) { //Now go through the list and turn it into pixel points pixelCoordinate = _projection.FromLatLngToPixel(llPoint.Lat, llPoint.Lng, zoom); //Make sure the weight and data is still pointing after the conversion pixelCoordinate.Data = llPoint.Data; pixelCoordinate.Weight = llPoint.Weight; mapPoint = _projection.FromPixelToTileXY(pixelCoordinate); mapPoint.Data = pixelCoordinate.Data; //Adjust the point to the specific tile adjustedPoint = AdjustMapPixelsToTilePixels(new GMap.NET.Point(x, y), pixelCoordinate); //Make sure the weight and data is still pointing after the conversion adjustedPoint.Data = pixelCoordinate.Data; adjustedPoint.Weight = pixelCoordinate.Weight; //Add the point to the list points.Add(adjustedPoint); } return(points.ToArray()); }
public GMap.NET.Point FromLatLngToLocal(PointLatLng point) { GMap.NET.Point ret = Core.FromLatLngToLocal(point); if (MapRenderTransform != null) { var tp = MapRenderTransform.Transform(new System.Windows.Point(ret.X, ret.Y)); ret.X = (int)tp.X; ret.Y = (int)tp.Y; } if (MapTranslateTransform != null) { ret.Offset(-(int)MapTranslateTransform.X, -(int)MapTranslateTransform.Y); } return(ret); }
public PointLatLng[] GetList(GMap.NET.Point tlb, GMap.NET.Point lrb, int zoom, IEnumerable <PointLatLng> _points) { IEnumerable <PointLatLng> _llList; GMap.NET.PointLatLng ptlb; GMap.NET.PointLatLng plrb; ptlb = _projection.FromPixelToLatLng(tlb, zoom); plrb = _projection.FromPixelToLatLng(lrb, zoom); _llList = from point in _points where point.Lat <= ptlb.Lat && point.Lng >= ptlb.Lng && point.Lat >= plrb.Lat && point.Lng <= plrb.Lng select point; return(_llList.ToArray()); }
public GMap.NET.Point AdjustMapPixelsToTilePixels(GMap.NET.Point tileXYPoint, GMap.NET.Point mapPixelPoint) { return(new GMap.NET.Point(mapPixelPoint.X - (tileXYPoint.X * SIZE), mapPixelPoint.Y - (tileXYPoint.Y * SIZE))); }
public Size(Point pt) { width = pt.X; height = pt.Y; }
static void Main(string[] args) { GMaps.Instance.Mode = AccessMode.ServerAndCache; GMaps.Instance.ImageProxy = new WindowsFormsImageProxy(); MapType type = MapType.GoogleMap; PureProjection prj = null; int maxZoom; GMaps.Instance.AdjustProjection(type, ref prj, out maxZoom); int zoom = 12; RectLatLng area = RectLatLng.FromLTRB(25.013809204101563, 54.832138557519563, 25.506134033203125, 54.615623046071839); if(!area.IsEmpty) { try { List<GMap.NET.Point> tileArea = prj.GetAreaTileList(area, zoom, 0); string bigImage = zoom + "-" + type + "-vilnius.png"; Console.WriteLine("Preparing: " + bigImage); Console.WriteLine("Zoom: " + zoom); Console.WriteLine("Type: " + type.ToString()); Console.WriteLine("Area: " + area); var types = GMaps.Instance.GetAllLayersOfType(type); // current area GMap.NET.Point topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom); GMap.NET.Point rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom); GMap.NET.Point pxDelta = new GMap.NET.Point(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y); int padding = 22; { using(Bitmap bmpDestination = new Bitmap(pxDelta.X + padding*2, pxDelta.Y + padding*2)) { using(Graphics gfx = Graphics.FromImage(bmpDestination)) { gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; // get tiles & combine into one foreach(var p in tileArea) { Console.WriteLine("Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count); foreach(MapType tp in types) { Exception ex; WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as WindowsFormsImage; if(tile != null) { using(tile) { int x = p.X*prj.TileSize.Width - topLeftPx.X + padding; int y = p.Y*prj.TileSize.Width - topLeftPx.Y + padding; { gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height); } } } } } } // draw info { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); { rect.Location = new System.Drawing.Point(padding, padding); rect.Size = new System.Drawing.Size(pxDelta.X, pxDelta.Y); } using(Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold)) using(Graphics gfx = Graphics.FromImage(bmpDestination)) { // draw bounds & coordinates using(Pen p = new Pen(Brushes.Red, 3)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; gfx.DrawRectangle(p, rect); string topleft = area.LocationTopLeft.ToString(); SizeF s = gfx.MeasureString(topleft, f); gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height/2, rect.Y + s.Height/2); string rightBottom = new PointLatLng(area.Bottom, area.Right).ToString(); SizeF s2 = gfx.MeasureString(rightBottom, f); gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height/2, rect.Bottom - s2.Height - s2.Height/2); } // draw scale using(Pen p = new Pen(Brushes.Blue, 1)) { double rez = prj.GetGroundResolution(zoom, area.Bottom); int px100 = (int) (100.0 / rez); // 100 meters int px1000 = (int) (1000.0 / rez); // 1km gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10); gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10); string leftBottom = "scale: 100m | 1Km"; SizeF s = gfx.MeasureString(leftBottom, f); gfx.DrawString(leftBottom, f, p.Brush, rect.X+10, rect.Bottom - s.Height - 20); } } } bmpDestination.Save(bigImage, System.Drawing.Imaging.ImageFormat.Png); } } // ok, lets see what we get { Console.WriteLine("Done! Starting Image: " + bigImage); Process.Start(bigImage); } } catch(Exception ex) { Console.WriteLine("Error: " + ex.ToString()); Console.ReadLine(); } } }
private GMap.NET.Point rotatePt(double rotationAngle, GMap.NET.Point pointU) { //rotation angle in radians GMap.NET.Point point = new GMap.NET.Point(); point.X = (int)(pointU.X * Math.Cos(rotationAngle) - pointU.Y * Math.Sin(rotationAngle)); point.Y = (int) (pointU.X * Math.Sin(rotationAngle) + pointU.Y * Math.Cos(rotationAngle)); return point; //throw new NotImplementedException(); }
private void btnSelectWater_Click(object sender, EventArgs e) { try { if ((firstBeachMarker == null) || (secondBeachMarker == null)) return; btnSelectWater.Enabled = true; string addMarker = "Add Water Marker"; string removeMarker = "Remove Water Marker"; //GMap.NET.Point pointH2O = new GMap.NET.Point(); GMap.NET.Point pointH20 = new GMap.NET.Point(); //GMapNET.Point pointPerpendicular = new GMapNET.Point(); //GMap.NET.Point pointPerpendicular = new GMap.NET.Point(); if (btnSelectWater.Text == addMarker) { waterMarker = new GMapMarkerGoogleGreen(currentMarker.Position); //waterMarker = new GMapMarkerGoogleGreen(MainMap.CurrentPosition); //MainMap.Markers.Add(waterMarker); top.Markers.Add(waterMarker); btnSelectWater.Text = removeMarker; pointH20 = MainMap.FromLatLngToLocal(waterMarker.Position); //pointPerpendicular = CoordinatePerpendicular(); } else { btnSelectWater.Text = addMarker; //MainMap.Markers.Remove(waterMarker); top.Markers.Remove(waterMarker); waterMarker = null; txtBeachAngle.Text = string.Empty; return; } ////////////////////////////////////////////// GMap.NET.Point pointA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); GMap.NET.Point pointB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); GMap.NET.Point pointWM = MainMap.FromLatLngToLocal(waterMarker.Position); //GMapNET.Point pointA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); //GMapNET.Point pointB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); int side = CoordinatePerpendicular(); ////rotate marker points thru -pi/2 since we want due N as zero //GMap.NET.Point Aprime = rotatePt(-Math.PI / 2, pointA); //GMap.NET.Point Bprime = rotatePt(-Math.PI / 2, pointB); //GMap.NET.Point WMprime = rotatePt(-Math.PI / 2, pointWM); //returns negative angles ccw from pos x axis thru -pi (quads I and II), //returns positive angles cw from pos x axis thru pi (quads IV and III) double angle = Math.Atan2(pointB.Y - pointA.Y, pointB.X - pointA.X); double deg = RadianToDegree((float)angle); //double angle = Math.Atan2(Bprime.Y - Aprime.Y, Bprime.X - Aprime.X); //double deg = RadianToDegree((float)angle); //slope //double deltaX = Bprime.X - Aprime.X; //double slope = double.NaN; //if (deltaX != 0) slope = (Bprime.Y - Aprime.Y) / deltaX; double deltaX = pointB.X - pointA.X; double slope = double.NaN; if (deltaX != 0) slope = (pointB.Y - pointA.Y) / deltaX; //negates order of pts for angle calc; computes -90 < deg < 90 if (slope.Equals(double.NaN)) { deg = 90.0; if (pointA.Y > pointB.Y) deg = -90; } else if (slope > 0) { if (deg < 0) deg = deg + 180.0; } else if (slope < 0) { if (deg > 0) deg = deg - 180.0; } else { deg = 0.0; } //get angle relative to N (N==0deg) and relative to side of line user selects if (side > 0) { deg = deg + 90.0; //translate quadrant i to quadrant iii in ccw direction (i.e., make 135 == -270) //correct??? makes MC's angles as documented. //if (deg > 90.0 && deg <= 135.0) deg = deg - 360.0; } else { deg = deg - 90.0; } txtBeachAngle.Text = deg.ToString("####0.##"); _site = new Site(); _site.Orientation = deg; _site.Location.Latitude = Convert.ToDouble(textBoxCurrLat.Text); _site.Location.Longitude = Convert.ToDouble(textBoxCurrLng.Text); _site.LeftMarker.Latitude = firstBeachMarker.Position.Lat;//marker1.Lat; _site.LeftMarker.Longitude = firstBeachMarker.Position.Lng;//marker1.Long; _site.RightMarker.Latitude = secondBeachMarker.Position.Lat;//marker2.Lat; _site.RightMarker.Longitude = secondBeachMarker.Position.Lng;//marker2.Long; _site.WaterMarker.Latitude = waterMarker.Position.Lat;//watermark.Lat; _site.WaterMarker.Longitude = waterMarker.Position.Lng;//watermark.Long; if (_plugin != null) { //VBCommon.Interfaces.IBeachSite site = _plugin as VBCommon.Interfaces.IBeachSite; _plugin.Site = _site.Clone(); } } catch (Exception ex) { string message = ex.Message; } return; }
public static Point Add(Point pt, Size sz) { return new Point(pt.X + sz.Width, pt.Y + sz.Height); }
private void btnSelectWater_Click(object sender, EventArgs e) { try { if ((firstBeachMarker == null) || (secondBeachMarker == null)) { return; } btnSelectWater.Enabled = true; string addMarker = "Add Water Marker"; string removeMarker = "Remove Water Marker"; //GMap.NET.Point pointH2O = new GMap.NET.Point(); GMap.NET.Point pointH20 = new GMap.NET.Point(); //GMapNET.Point pointPerpendicular = new GMapNET.Point(); //GMap.NET.Point pointPerpendicular = new GMap.NET.Point(); if (btnSelectWater.Text == addMarker) { waterMarker = new GMapMarkerGoogleGreen(currentMarker.Position); //waterMarker = new GMapMarkerGoogleGreen(MainMap.CurrentPosition); //MainMap.Markers.Add(waterMarker); top.Markers.Add(waterMarker); btnSelectWater.Text = removeMarker; pointH20 = MainMap.FromLatLngToLocal(waterMarker.Position); //pointPerpendicular = CoordinatePerpendicular(); } else { btnSelectWater.Text = addMarker; //MainMap.Markers.Remove(waterMarker); top.Markers.Remove(waterMarker); waterMarker = null; txtBeachAngle.Text = string.Empty; return; } ////////////////////////////////////////////// GMap.NET.Point pointA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); GMap.NET.Point pointB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); GMap.NET.Point pointWM = MainMap.FromLatLngToLocal(waterMarker.Position); //GMapNET.Point pointA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); //GMapNET.Point pointB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); int side = CoordinatePerpendicular(); ////rotate marker points thru -pi/2 since we want due N as zero //GMap.NET.Point Aprime = rotatePt(-Math.PI / 2, pointA); //GMap.NET.Point Bprime = rotatePt(-Math.PI / 2, pointB); //GMap.NET.Point WMprime = rotatePt(-Math.PI / 2, pointWM); //returns negative angles ccw from pos x axis thru -pi (quads I and II), //returns positive angles cw from pos x axis thru pi (quads IV and III) double angle = Math.Atan2(pointB.Y - pointA.Y, pointB.X - pointA.X); double deg = RadianToDegree((float)angle); //double angle = Math.Atan2(Bprime.Y - Aprime.Y, Bprime.X - Aprime.X); //double deg = RadianToDegree((float)angle); //slope //double deltaX = Bprime.X - Aprime.X; //double slope = double.NaN; //if (deltaX != 0) slope = (Bprime.Y - Aprime.Y) / deltaX; double deltaX = pointB.X - pointA.X; double slope = double.NaN; if (deltaX != 0) { slope = (pointB.Y - pointA.Y) / deltaX; } //negates order of pts for angle calc; computes -90 < deg < 90 if (slope.Equals(double.NaN)) { deg = 90.0; if (pointA.Y > pointB.Y) { deg = -90; } } else if (slope > 0) { if (deg < 0) { deg = deg + 180.0; } } else if (slope < 0) { if (deg > 0) { deg = deg - 180.0; } } else { deg = 0.0; } //get angle relative to N (N==0deg) and relative to side of line user selects if (side > 0) { deg = deg + 90.0; //translate quadrant i to quadrant iii in ccw direction (i.e., make 135 == -270) //correct??? makes MC's angles as documented. //if (deg > 90.0 && deg <= 135.0) deg = deg - 360.0; } else { deg = deg - 90.0; } txtBeachAngle.Text = deg.ToString("####0.##"); _site = new Site(); _site.Orientation = deg; _site.Location.Latitude = Convert.ToDouble(textBoxCurrLat.Text); _site.Location.Longitude = Convert.ToDouble(textBoxCurrLng.Text); _site.LeftMarker.Latitude = firstBeachMarker.Position.Lat; //marker1.Lat; _site.LeftMarker.Longitude = firstBeachMarker.Position.Lng; //marker1.Long; _site.RightMarker.Latitude = secondBeachMarker.Position.Lat; //marker2.Lat; _site.RightMarker.Longitude = secondBeachMarker.Position.Lng; //marker2.Long; _site.WaterMarker.Latitude = waterMarker.Position.Lat; //watermark.Lat; _site.WaterMarker.Longitude = waterMarker.Position.Lng; //watermark.Long; if (_plugin != null) { //VBCommon.Interfaces.IBeachSite site = _plugin as VBCommon.Interfaces.IBeachSite; _plugin.Site = _site.Clone(); } } catch (Exception ex) { string message = ex.Message; } return; }
//private GMapNET.Point CoordinatePerpendicular() private int CoordinatePerpendicular() { GMap.NET.Point pointA = new GMap.NET.Point(); GMap.NET.Point pointB = new GMap.NET.Point(); if ((firstBeachMarker == null) || (secondBeachMarker == null) || (waterMarker == null)) { pointA.X = -1; pointA.Y = -1; //return pointA; return(-999); } GMap.NET.Point pointTmpA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); GMap.NET.Point pointTmpB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); GMap.NET.Point pointH20 = MainMap.FromLatLngToLocal(waterMarker.Position); //Order points from left to right if (pointTmpA.X <= pointTmpB.X) { pointA = pointTmpA; pointB = pointTmpB; } else { pointA = pointTmpB; pointB = pointTmpA; } double slope = 0.0; double perpSlope = 0.0; int side = 1; if ((pointB.X - pointA.X) > 0) { slope = (double)(pointA.Y - pointB.Y) / (double)(pointA.X - pointB.X); perpSlope = -1 / slope; double b = (double)pointA.Y - (slope * (double)pointA.X); double bNew = (double)pointH20.Y - (slope * (double)pointH20.X); if (bNew > b) { side = 1; } else { side = -1; } } //added clauses for due N side selection (mog 5/10) else if (pointH20.X > pointA.X) { if (pointA.Y < pointB.Y) { side = -1; } else { side = 1; } } else if (pointH20.X < pointA.X) { if (pointA.Y < pointB.Y) { side = 1; } else { side = -1; } } return(side); }
private void MainMap_Paint(object sender, PaintEventArgs e) { if ((firstBeachMarker != null) && (secondBeachMarker != null)) { Graphics g = e.Graphics; GMap.NET.Point pointTmpA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); GMap.NET.Point pointTmpB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); GMap.NET.Point pointA = new GMap.NET.Point(); GMap.NET.Point pointB = new GMap.NET.Point(); GMap.NET.Point pointMid = new GMap.NET.Point(); GMap.NET.Point pointNew = new GMap.NET.Point(); //Order points from left to right if (pointTmpA.X <= pointTmpB.X) { pointA = pointTmpA; pointB = pointTmpB; } else { pointA = pointTmpB; pointB = pointTmpA; } Pen pen = new Pen(Color.LimeGreen, 5); g.DrawLine(pen, pointA.X, pointA.Y, pointB.X, pointB.Y); if (waterMarker != null) { double angle = Math.Atan2(pointB.Y - pointA.Y, pointB.X - pointA.X); //Console.Write("**MAngle = " + angle + "\n"); Matrix matrix = new Matrix(); float deg = RadianToDegree((float)angle); double dist = Math.Sqrt((Math.Pow(pointA.Y - pointB.Y, 2) + Math.Pow(pointA.X - pointB.X, 2))); //Console.Write("**MDist = " + dist + "\n"); PointF rotPoint = new PointF(pointA.X, pointA.Y); int side = CoordinatePerpendicular(); //Console.Write("**MSide = " + side + "\n"); matrix.RotateAt(deg, rotPoint); LinearGradientBrush lgb = null; RectangleF rect = new RectangleF(pointA.X, pointA.Y, Convert.ToInt32(dist), Convert.ToInt32(dist / 2)); if (side < 0) { matrix.Translate(0, (side) * (float)dist / 2); if (rect.Width > 0 && rect.Height > 0) { lgb = new LinearGradientBrush(rect, Color.DarkBlue, Color.LightBlue, LinearGradientMode.Vertical); } } //added else clause to get gradient right (mog 8/8) else { if (rect.Width > 0 && rect.Height > 0) { lgb = new LinearGradientBrush(rect, Color.LightBlue, Color.DarkBlue, LinearGradientMode.Vertical); } } //else ... commented out by mog - was only getting the water rect on one side of the line... // the gradient is still wrong.... if (rect.Width > 0 && rect.Height > 0) { //lgb = new LinearGradientBrush(rect, Color.LightBlue, Color.DarkBlue, LinearGradientMode.Vertical); g.Transform = matrix; //LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.DarkBlue, Color.LightBlue, LinearGradientMode.Vertical); //pen = new Pen(Color.Blue); g.FillRectangle(lgb, rect); //g.DrawRectangle(pen, pointA.X, pointA.Y, Convert.ToInt32(dist), (Convert.ToInt32(dist / 2))); //pointMid.X = (pointA.X + pointB.X) / 2; //pointMid.Y = (pointA.Y + pointB.Y) / 2; g.ResetTransform(); } } } }
//private GMapNET.Point CoordinatePerpendicular() private int CoordinatePerpendicular() { GMap.NET.Point pointA = new GMap.NET.Point(); GMap.NET.Point pointB = new GMap.NET.Point(); if ((firstBeachMarker == null) || (secondBeachMarker == null) || (waterMarker == null)) { pointA.X = -1; pointA.Y = -1; //return pointA; return -999; } GMap.NET.Point pointTmpA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); GMap.NET.Point pointTmpB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); GMap.NET.Point pointH20 = MainMap.FromLatLngToLocal(waterMarker.Position); //Order points from left to right if (pointTmpA.X <= pointTmpB.X) { pointA = pointTmpA; pointB = pointTmpB; } else { pointA = pointTmpB; pointB = pointTmpA; } double slope = 0.0; double perpSlope = 0.0; int side = 1; if ((pointB.X - pointA.X) > 0) { slope = (double)(pointA.Y - pointB.Y) / (double)(pointA.X - pointB.X); perpSlope = -1 / slope; double b = (double)pointA.Y - (slope * (double)pointA.X); double bNew = (double)pointH20.Y - (slope * (double)pointH20.X); if (bNew > b) side = 1; else side = -1; } //added clauses for due N side selection (mog 5/10) else if (pointH20.X > pointA.X) { if (pointA.Y < pointB.Y) side = -1; else side = 1; } else if (pointH20.X < pointA.X) { if (pointA.Y < pointB.Y) side = 1; else side = -1; } return side; }
void bg_DoWork(object sender, DoWorkEventArgs e) { MapInfo info = e.Argument as MapInfo; if(!info.Area.IsEmpty) { string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap-" + DateTime.Now.Ticks + ".png"; e.Result = bigImage; List<MapType> types = GMaps.Instance.GetAllLayersOfType(info.Type); // current area GMap.NET.Point topLeftPx = info.Projection.FromLatLngToPixel(info.Area.LocationTopLeft, info.Zoom); GMap.NET.Point rightButtomPx = info.Projection.FromLatLngToPixel(info.Area.Bottom, info.Area.Right, info.Zoom); GMap.NET.Point pxDelta = new GMap.NET.Point(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y); int padding = 22; { using(Bitmap bmpDestination = new Bitmap(pxDelta.X + padding*2, pxDelta.Y + padding*2)) { using(Graphics gfx = Graphics.FromImage(bmpDestination)) { gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; int i = 0; // get tiles & combine into one lock(tileArea) { foreach(var p in tileArea) { if(bg.CancellationPending) { e.Cancel = true; return; } int pc = (int) (((double) ++i / tileArea.Count)*100); bg.ReportProgress(pc, p); foreach(MapType tp in types) { WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, info.Zoom) as WindowsFormsImage; if(tile != null) { using(tile) { int x = p.X*info.Projection.TileSize.Width - topLeftPx.X + padding; int y = p.Y*info.Projection.TileSize.Width - topLeftPx.Y + padding; { gfx.DrawImage(tile.Img, x, y, info.Projection.TileSize.Width, info.Projection.TileSize.Height); } } } } } } } // draw info { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); { rect.Location = new System.Drawing.Point(padding, padding); rect.Size = new System.Drawing.Size(pxDelta.X, pxDelta.Y); } using(Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold)) using(Graphics gfx = Graphics.FromImage(bmpDestination)) { gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // draw bounds & coordinates using(Pen p = new Pen(Brushes.Red, 3)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; gfx.DrawRectangle(p, rect); string topleft = info.Area.LocationTopLeft.ToString(); SizeF s = gfx.MeasureString(topleft, f); gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height/2, rect.Y + s.Height/2); string rightBottom = new PointLatLng(info.Area.Bottom, info.Area.Right).ToString(); SizeF s2 = gfx.MeasureString(rightBottom, f); gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height/2, rect.Bottom - s2.Height - s2.Height/2); } // draw scale using(Pen p = new Pen(Brushes.Blue, 1)) { double rez = info.Projection.GetGroundResolution(info.Zoom, info.Area.Bottom); int px100 = (int) (100.0 / rez); // 100 meters int px1000 = (int) (1000.0 / rez); // 1km gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10); gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10); string leftBottom = "scale: 100m | 1Km"; SizeF s = gfx.MeasureString(leftBottom, f); gfx.DrawString(leftBottom, f, p.Brush, rect.X+10, rect.Bottom - s.Height - 20); } } } bmpDestination.Save(bigImage, ImageFormat.Png); } } } }
public void Offset(Point p) { Offset(p.X, p.Y); }
private double CalcAngle(GMap.NET.Point point, GMap.NET.Point point2) { return(0.0); }
public static Point Subtract(Point pt, Size sz) { return new Point(pt.X - sz.Width, pt.Y - sz.Height); }
// empty tile displayed void MainMap_OnEmptyTileError(int zoom, GMap.NET.Point pos) { //MessageBox.Show("OnEmptyTileError, Zoom: " + zoom + ", " + pos.ToString(), "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
void bg_DoWork(object sender, DoWorkEventArgs e) { MapInfo info = e.Argument as MapInfo; if (!info.Area.IsEmpty) { string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap-" + DateTime.Now.Ticks + ".png"; e.Result = bigImage; List <MapType> types = GMaps.Instance.GetAllLayersOfType(info.Type); // current area GMap.NET.Point topLeftPx = info.Projection.FromLatLngToPixel(info.Area.LocationTopLeft, info.Zoom); GMap.NET.Point rightButtomPx = info.Projection.FromLatLngToPixel(info.Area.Bottom, info.Area.Right, info.Zoom); GMap.NET.Point pxDelta = new GMap.NET.Point(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y); int padding = 22; { using (Bitmap bmpDestination = new Bitmap(pxDelta.X + padding * 2, pxDelta.Y + padding * 2)) { using (Graphics gfx = Graphics.FromImage(bmpDestination)) { gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; int i = 0; // get tiles & combine into one lock (tileArea) { foreach (var p in tileArea) { if (bg.CancellationPending) { e.Cancel = true; return; } int pc = (int)(((double)++i / tileArea.Count) * 100); bg.ReportProgress(pc, p); foreach (MapType tp in types) { WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, info.Zoom) as WindowsFormsImage; if (tile != null) { using (tile) { int x = p.X * info.Projection.TileSize.Width - topLeftPx.X + padding; int y = p.Y * info.Projection.TileSize.Width - topLeftPx.Y + padding; { gfx.DrawImage(tile.Img, x, y, info.Projection.TileSize.Width, info.Projection.TileSize.Height); } } } } } } } // draw info { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); { rect.Location = new System.Drawing.Point(padding, padding); rect.Size = new System.Drawing.Size(pxDelta.X, pxDelta.Y); } using (Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold)) using (Graphics gfx = Graphics.FromImage(bmpDestination)) { gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // draw bounds & coordinates using (Pen p = new Pen(Brushes.Red, 3)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; gfx.DrawRectangle(p, rect); string topleft = info.Area.LocationTopLeft.ToString(); SizeF s = gfx.MeasureString(topleft, f); gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height / 2, rect.Y + s.Height / 2); string rightBottom = new PointLatLng(info.Area.Bottom, info.Area.Right).ToString(); SizeF s2 = gfx.MeasureString(rightBottom, f); gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height / 2, rect.Bottom - s2.Height - s2.Height / 2); } // draw scale using (Pen p = new Pen(Brushes.Blue, 1)) { double rez = info.Projection.GetGroundResolution(info.Zoom, info.Area.Bottom); int px100 = (int)(100.0 / rez); // 100 meters int px1000 = (int)(1000.0 / rez); // 1km gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10); gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10); string leftBottom = "scale: 100m | 1Km"; SizeF s = gfx.MeasureString(leftBottom, f); gfx.DrawString(leftBottom, f, p.Brush, rect.X + 10, rect.Bottom - s.Height - 20); } } } bmpDestination.Save(bigImage, ImageFormat.Png); } } } }
private void MainMap_Paint(object sender, PaintEventArgs e) { if ((firstBeachMarker != null) && (secondBeachMarker != null)) { Graphics g = e.Graphics; GMap.NET.Point pointTmpA = MainMap.FromLatLngToLocal(firstBeachMarker.Position); GMap.NET.Point pointTmpB = MainMap.FromLatLngToLocal(secondBeachMarker.Position); GMap.NET.Point pointA = new GMap.NET.Point(); GMap.NET.Point pointB = new GMap.NET.Point(); GMap.NET.Point pointMid = new GMap.NET.Point(); GMap.NET.Point pointNew = new GMap.NET.Point(); //Order points from left to right if (pointTmpA.X <= pointTmpB.X) { pointA = pointTmpA; pointB = pointTmpB; } else { pointA = pointTmpB; pointB = pointTmpA; } Pen pen = new Pen(Color.LimeGreen, 5); g.DrawLine(pen, pointA.X, pointA.Y, pointB.X, pointB.Y); if (waterMarker != null) { double angle = Math.Atan2(pointB.Y - pointA.Y, pointB.X - pointA.X); //Console.Write("**MAngle = " + angle + "\n"); Matrix matrix = new Matrix(); float deg = RadianToDegree((float)angle); double dist = Math.Sqrt((Math.Pow(pointA.Y - pointB.Y, 2) + Math.Pow(pointA.X - pointB.X, 2))); //Console.Write("**MDist = " + dist + "\n"); PointF rotPoint = new PointF(pointA.X, pointA.Y); int side = CoordinatePerpendicular(); //Console.Write("**MSide = " + side + "\n"); matrix.RotateAt(deg, rotPoint); LinearGradientBrush lgb = null; RectangleF rect = new RectangleF(pointA.X, pointA.Y, Convert.ToInt32(dist), Convert.ToInt32(dist / 2)); if (side < 0) { matrix.Translate(0, (side) * (float)dist / 2); if (rect.Width > 0 && rect.Height > 0) lgb = new LinearGradientBrush(rect, Color.DarkBlue, Color.LightBlue, LinearGradientMode.Vertical); } //added else clause to get gradient right (mog 8/8) else { if (rect.Width > 0 && rect.Height > 0) lgb = new LinearGradientBrush(rect, Color.LightBlue, Color.DarkBlue, LinearGradientMode.Vertical); } //else ... commented out by mog - was only getting the water rect on one side of the line... // the gradient is still wrong.... if (rect.Width > 0 && rect.Height > 0) { //lgb = new LinearGradientBrush(rect, Color.LightBlue, Color.DarkBlue, LinearGradientMode.Vertical); g.Transform = matrix; //LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.DarkBlue, Color.LightBlue, LinearGradientMode.Vertical); //pen = new Pen(Color.Blue); g.FillRectangle(lgb, rect); //g.DrawRectangle(pen, pointA.X, pointA.Y, Convert.ToInt32(dist), (Convert.ToInt32(dist / 2))); //pointMid.X = (pointA.X + pointB.X) / 2; //pointMid.Y = (pointA.Y + pointB.Y) / 2; g.ResetTransform(); } } } }