private void DrawRegion(MapPen mapPen, MapBrush mapBrush, GeoPolygon region) { Pen pen = new Pen(Color.FromArgb((int)(mapPen.Color | 0xFF000000)), mapPen.Width); Brush brush = GetBrush(mapBrush); GeoBounds bounds = new GeoBounds(118.808451, 31.907395, 0.003907, 0.0035); ArrayList clippedPts = _sutherlandHodgman.ClipRegion(region.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 2) { { int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Point[] points = new Point[xpoints.Length]; for (int i = 0; i < points.Length; i++) { points[i] = new Point(xpoints[i], ypoints[i]); } SharedGraphics2D.Graphics.DrawPolygon(pen, points); SharedGraphics2D.Graphics.FillPolygon(brush, points); } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * check if this rectangle Intersects given rectangle. * @param r the rectangle to be checked. * @return true, it Intersects given rectangle. */ public bool Intersects(GeoBounds r) { return Intersects(r.GetX(), r.GetY(), r.GetWidth(), r.GetHeight()); }
private void AddMapName(TextPosInfo textPosInfo) { //check if there's collide foreach (var o in _textInfos) { foreach(var p in textPosInfo._rectangles) { foreach(var q in o._rectangles) { if(p.IntersectsWith(q)) { return; } } } } bool somethingInScreen = true; foreach(var p in textPosInfo._rectangles) { GeoBounds geoBounds = new GeoBounds(p.X, p.Y, p.Width, p.Height); if (!_mapSize.Contains(geoBounds)) { somethingInScreen = false; break; } } if(somethingInScreen) { _textInfos.Add(textPosInfo); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Create the intersection rectangle between this rectangle and r rectangle. * @param r the other rectangle * @return the intersection rectangle. */ public GeoBounds CreateIntersection(GeoBounds r) { GeoBounds dest = new GeoBounds(); Intersect(this, r, dest); return dest; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * create the Union rectangle of the two rectangles. * @param r the other rectangle. * @return Union rectangle of the two rectangles. */ public GeoBounds CreateUnion(GeoBounds r) { GeoBounds dest = new GeoBounds(); Union(this, r, dest); return dest; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * check if this rectangle Contains given rectangle. * @param r the rectangle to be checked. * @return true, it totally Contains given rectangle. */ public bool Contains(GeoBounds r) { return Contains(r.GetX(), r.GetY(), r.GetWidth(), r.GetHeight()); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Check whether the current rectangle entirely Contains other rectangle. * @param other the other rectangle. * @return true if the passed rectangular area is entirely contained * in this rectangular area. */ public bool ContainsBounds(GeoBounds other) { SetBounds(MinX, MinY, MaxX - MinX, MaxY - MinY); return Contains(other.MinX, other.MinY, other.MaxX - other.MinX, other.MaxY - other.MinY); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Unions the pair of source <code>GeoBounds</code> objects * and puts the result into the specified destination * <code>GeoBounds</code> object. One of the source rectangles * can also be the destination to avoid creating a third GeoBounds * object, but in this case the original points of this source * rectangle will be overwritten by this method. * @param src1 the first of a pair of <code>GeoBounds</code> * objects to be combined with each other * @param src2 the second of a pair of <code>GeoBounds</code> * objects to be combined with each other * @param dest the <code>GeoBounds</code> that holds the * results of the Union of <code>src1</code> and * <code>src2</code> */ public static void Union(GeoBounds src1, GeoBounds src2, GeoBounds dest) { double x1 = Math.Min(src1.GetMinX(), src2.GetMinX()); double y1 = Math.Min(src1.GetMinY(), src2.GetMinY()); double x2 = Math.Max(src1.GetMaxX(), src2.GetMaxX()); double y2 = Math.Max(src1.GetMaxY(), src2.GetMaxY()); dest.SetFrameFromDiagonal(x1, y1, x2, y2); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Adds a <code>GeoBounds</code> object to this * <code>GeoBounds</code>. The resulting <code>GeoBounds</code> * is the Union of the two <code>GeoBounds</code> objects. * @param r the <code>GeoBounds</code> to Add to this * <code>GeoBounds</code>. */ public void Add(GeoBounds r) { double x1 = Math.Min(GetMinX(), r.GetMinX()); double x2 = Math.Max(GetMaxX(), r.GetMaxX()); double y1 = Math.Min(GetMinY(), r.GetMinY()); double y2 = Math.Max(GetMaxY(), r.GetMaxY()); SetRect(x1, y1, x2 - x1, y2 - y1); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Intersects the pair of specified source <code>GeoBounds</code> * objects and puts the result into the specified destination * <code>GeoBounds</code> object. One of the source rectangles * can also be the destination to avoid creating a third GeoBounds * object, but in this case the original points of this source * rectangle will be overwritten by this method. * @param src1 the first of a pair of <code>GeoBounds</code> * objects to be intersected with each other * @param src2 the second of a pair of <code>GeoBounds</code> * objects to be intersected with each other * @param dest the <code>GeoBounds</code> that holds the * results of the intersection of <code>src1</code> and * <code>src2</code> */ public static void Intersect(GeoBounds src1, GeoBounds src2, GeoBounds dest) { double x1 = Math.Max(src1.GetMinX(), src2.GetMinX()); double y1 = Math.Max(src1.GetMinY(), src2.GetMinY()); double x2 = Math.Min(src1.GetMaxX(), src2.GetMaxX()); double y2 = Math.Min(src1.GetMaxY(), src2.GetMaxY()); dest.SetFrame(x1, y1, x2 - x1, y2 - y1); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Constructs a new <code>GeoBounds</code>, initialized to match * the values of the specified <code>GeoBounds</code>. * @param r the <code>GeoBounds</code> from which to copy initial values * to a newly constructed <code>GeoBounds</code> */ public GeoBounds(GeoBounds r) : this(r.X, r.Y, r.Width, r.Height) { }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Reset the geo bound with same position and size with given geo bound. * @param r the geo bound to copy from. */ public void SetRect(GeoBounds r) { X = r.GetX(); Y = r.GetY(); Width = r.GetWidth(); Height = r.GetHeight(); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Sets the framing rectangle of this <code>IShape</code> to * be the specified <code>GeoBounds</code>. The framing rectangle is * used by the subclasses of <code>RectangularShape</code> to define * their geometry. * @param r the specified <code>GeoBounds</code> */ public void SetFrame(GeoBounds r) { SetFrame(r.GetX(), r.GetY(), r.GetWidth(), r.GetHeight()); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Sets the bounding <code>GeoSize</code> of this <code>GeoSize</code> * to match the specified <code>GeoSize</code>. * <p> * This method is included for completeness, to parallel the * <code>SetBounds</code> method of <code>Component</code>. * @param r the specified <code>GeoSize</code> */ public void SetBounds(GeoBounds r) { SetBounds(r.X, r.Y, r.Width, r.Height); }