private GeoLatLng ComputeFormDir(GeoLatLng pt1, double distance, double crs) { //get select values double lat2, lon2; /* Input and validate data */ double lat1 = pt1.LatRadians(); double lon1 = -pt1.LngRadians(); double d12 = distance; double dc = _currentUnit == UNIT_NM ? 1 : 1.852; d12 /= dc; double crs12 = crs * MathEx.PI / 180.0; if (_currentEarthMode == EARTH_MODEL_SPHERE) { // spherical code d12 /= (180 * 60 / MathEx.PI); // in radians DirectResult cd = Direct(lat1, lon1, crs12, d12); lat2 = cd._lat * (180 / MathEx.PI); lon2 = cd._lon * (180 / MathEx.PI); } else { // elliptic code// ellipse uses East negative DirectResult cde = DirectEll(lat1, -lon1, crs12, d12, _currentEarthMode); lat2 = cde._lat * (180 / MathEx.PI); lon2 = -cde._lon * (180 / MathEx.PI);// ellipse uses East negative } double retLat = lat2; double retLon = -lon2; return(new GeoLatLng(retLat, retLon)); }
private CrsdistResult ComputeFormCD(GeoLatLng pt1, GeoLatLng pt2) { double d, crs12, crs21; CrsdistResult outValue = new CrsdistResult(); double lat1 = pt1.LatRadians(); double lat2 = pt2.LatRadians(); double lon1 = -pt1.LngRadians(); double lon2 = -pt2.LngRadians(); double dc = _currentUnit == UNIT_NM ? 1 : 1.852; if (_currentEarthMode == EARTH_MODEL_SPHERE) { // spherical code// compute crs and Distance CrsdistResult cd = Crsdist(lat1, lon1, lat2, lon2); crs12 = cd._crs12 * (180 / MathEx.PI); crs21 = cd._crs21 * (180 / MathEx.PI); d = cd._d * (180 / MathEx.PI) * 60 * dc; // go to physical units } else { // elliptic code // ellipse uses East negative CrsdistResult cde = CrsdistEll(lat1, -lon1, lat2, -lon2, _currentEarthMode); crs12 = cde._crs12 * (180 / MathEx.PI); crs21 = cde._crs21 * (180 / MathEx.PI); d = cde._d * dc; // go to physical units } outValue._crs12 = crs12; outValue._crs21 = crs21; outValue._d = d; return(outValue); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Calculate the Distance between two point in great circle. * @param pt1 the first location. * @param pt2 the second location. * @return the Distance and course between the 2 point. */ internal GeoLatLng CalculateDistanceAndCourse(GeoLatLng pt1, GeoLatLng pt2) { CrsdistResult ret = ComputeFormCD(pt1, pt2); GeoLatLng ret1 = new GeoLatLng(ret._crs12, ret._d); return(ret1); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param mapPoint map object copy from. */ public MapPoint(MapPoint mapPoint) : base(mapPoint) { SetMapObjectType(POINT); SymbolType = new MapSymbol(mapPoint.SymbolType); Point = new GeoLatLng(mapPoint.Point); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the Distance, in meters, from this point to the given point. * By default, this Distance is calculated given the default equatorial * earth radius of 6378137 meters. The earth is approximated as a sphere, * hence the Distance could be off as much as 0.3%, * especially in the polar extremes. * @param pt1 the first point. * @param pt2 the other point. * @return the Distance, in kilo meters. */ public static double Distance(GeoLatLng pt1, GeoLatLng pt2) { GreateCircleCalculator cal = new GreateCircleCalculator( GreateCircleCalculator.EARTH_MODEL_WGS84, GreateCircleCalculator.UNIT_KM); return(cal.CalculateDistance(pt1, pt2)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the Distance, in meters, from this point to the given point. * By default, this Distance is calculated given the default equatorial * earth radius of 6378137 meters. The earth is approximated as a sphere, * hence the Distance could be off as much as 0.3%, * especially in the polar extremes. * @param other the other point. * @return the Distance, in meters. */ public double DistanceFrom(GeoLatLng other) { GreateCircleCalculator cal = new GreateCircleCalculator( GreateCircleCalculator.EARTH_MODEL_WGS84, GreateCircleCalculator.UNIT_KM); return(cal.CalculateDistance(this, other)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param region map object copy from. */ public MapRegion(MapRegion region) : base(region) { SetMapObjectType(REGION); PenStyle = new MapPen(region.PenStyle); BrushStyle = new MapBrush(region.BrushStyle); Region = new GeoPolygon(region.Region); CenterPt = new GeoLatLng(region.CenterPt); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Determines whether or not two points are equal. Two instances of * <code>GeoLatLng</code> are equal if the values of their * <code>X</code> and <code>Y</code> member fields, representing * their position in the coordinate space, are the same. * @param obj an object to be compared with this <code>GeoLatLng</code> * @return <code>true</code> if the object to be compared is * an instance of <code>GeoLatLng</code> and has * the same values; <code>false</code> otherwise. */ public new bool Equals(Object obj) { if (obj is GeoLatLng) { GeoLatLng p2D = (GeoLatLng)obj; return((GetX() == p2D.GetX()) && (GetY() == p2D.GetY())); } return(base.Equals(obj)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Creates a polygon from an array of vertices. The weight is the Width of * the line in pixels. The opacity is given as a number between 0 and 1. * The line will be antialiased and semitransparent. * @param _latlngs array of points. * @param _strokeColor the color of the polygon stroke. * @param _strokeWeight the Width of the polygon stroke. * @param _strokeOpacity the opacity of the polygon stroke. * @param _fillColor the inner color of the polygon. * @param _fillOpacity the inner opacity of the polygon. */ public GeoPolygon(GeoLatLng[] latlngs, int strokeColor, int strokeWeight, double strokeOpacity, int fillColor, double fillOpacity) { if (latlngs != null) { _latlngs = new GeoLatLng[latlngs.Length]; Array.Copy(latlngs, 0, _latlngs, 0, latlngs.Length); _levels = new int[latlngs.Length]; for (int i = 0; i < _levels.Length; i++) { _levels[i] = 0; } double maxlat = 0, minlat = 0, maxlon = 0, minlon = 0; GeoLatLng[] points = _latlngs; for (int i = 0; i < points.Length; i++) { // determin _bounds (Max/Min Lat/lon) if (i == 0) { maxlat = minlat = points[i].Lat(); maxlon = minlon = points[i].Lng(); } else { if (points[i].Lat() > maxlat) { maxlat = points[i].Lat(); } else if (points[i].Lat() < minlat) { minlat = points[i].Lat(); } else if (points[i].Lng() > maxlon) { maxlon = points[i].Lng(); } else if (points[i].Lng() < minlon) { minlon = points[i].Lng(); } } } GeoLatLng sw, ne; sw = new GeoLatLng(minlat, minlon); ne = new GeoLatLng(maxlat, maxlon); _bounds = new GeoLatLngBounds(sw, ne); } _strokeColor = strokeColor; _strokeOpacity = strokeOpacity; _strokeWeight = strokeWeight; _fillColor = fillColor; _fillOpacity = fillOpacity; _zoomFactor = 1; _numLevels = 0; _visible = true; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param mapPoints map object copy from. */ public MapMultiPoint(MapMultiPoint mapPoints) : base(mapPoints) { SetMapObjectType(MULTIPOINT); SymbolType = new MapSymbol(mapPoints.SymbolType); Points = new GeoLatLng[mapPoints.Points.Length]; for (int i = 0; i < Points.Length; i++) { Points[i] = new GeoLatLng(mapPoints.Points[i]); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Creates a polyline from an array of vertices. The _weight is the Width of * the line in pixels. The _opacity is given as a number between 0 and 1. * The line will be antialiased and semitransparent. * @param _latlngs array of points. * @param _color the _color of the polyline. * @param _weight the Width of the polyline. * @param _opacity the _opacity of the polyline. */ public GeoPolyline(GeoLatLng[] latlngs, int color, int weight, double opacity) { if (latlngs != null) { _latlngs = new GeoLatLng[latlngs.Length]; Array.Copy(latlngs, 0, _latlngs, 0, latlngs.Length); _levels = new int[latlngs.Length]; for (int i = 0; i < _levels.Length; i++) { _levels[i] = 0; } double maxlat = 0, minlat = 0, maxlon = 0, minlon = 0; GeoLatLng[] points = _latlngs; for (int i = 0; i < points.Length; i++) { // determin bounds (Max/Min Lat/lon) if (i == 0) { maxlat = minlat = points[i].Lat(); maxlon = minlon = points[i].Lng(); } else { if (points[i].Lat() > maxlat) { maxlat = points[i].Lat(); } else if (points[i].Lat() < minlat) { minlat = points[i].Lat(); } else if (points[i].Lng() > maxlon) { maxlon = points[i].Lng(); } else if (points[i].Lng() < minlon) { minlon = points[i].Lng(); } } } GeoLatLng sw = new GeoLatLng(minlat, minlon); GeoLatLng ne = new GeoLatLng(maxlat, maxlon); _bounds = new GeoLatLngBounds(sw, ne); } _color = color; _weight = weight; _opacity = opacity; ZoomFactor = 1; NumLevels = 0; _visible = true; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param multiRegion map object copy from. */ public MapMultiRegion(MapMultiRegion multiRegion) : base(multiRegion) { SetMapObjectType(MULTIREGION); PenStyle = new MapPen(multiRegion.PenStyle); BrushStyle = new MapBrush(multiRegion.BrushStyle); Regions = new GeoPolygon[multiRegion.Regions.Length]; for (int i = 0; i < Regions.Length; i++) { Regions[i] = new GeoPolygon(multiRegion.Regions[i]); } CenterPt = new GeoLatLng(multiRegion.CenterPt); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the length (in meters) of the polyline along the surface of a * spherical Earth * @return the length (in meters) of the polyline. */ public int GetLength() { int len = 0; if (_latlngs != null) { double length = 0; GeoLatLng pt1 = new GeoLatLng(_latlngs[0].Lat(), _latlngs[0].Lng()); for (int i = 1; i < _latlngs.Length; i++) { GeoLatLng pt2 = new GeoLatLng(_latlngs[i].Lat(), _latlngs[i].Lng()); length += pt1.DistanceFrom(pt2); pt1 = pt2; } len = (int)(length * 1000.0 + 0.5); } return(len); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Creates a polyline from encoded strings of aggregated points and levels. * ZoomFactor and NumLevels these two values determine the precision * of the levels within an encoded polyline. * @param _color the _color of the polyline. * @param _weight Width of the line in pixels. * @param _opacity the _opacity of the polyline. * @param points a string containing the encoded latitude and longitude * coordinates. * @param ZoomFactor the magnification between adjacent sets of zoom levels * in the encoded levels string. * @param levels a string containing the encoded polyline zoom level groups. * @param NumLevels the number of zoom levels contained in the encoded * levels string. * @return Geo polyline object. */ public static GeoPolyline FromEncoded(int color, int weight, double opacity, String points, int zoomFactor, String levels, int numLevels) { ArrayList trk = PolylineEncoder.CreateDecodings(points); GeoLatLng[] array = new GeoLatLng[trk.Count]; var temp = trk.ToArray(); for (int i = 0; i < temp.Length; i++) { array[i] = (GeoLatLng)temp[i]; } GeoPolyline polyline = new GeoPolyline(array, color, weight, opacity); polyline._levels = PolylineEncoder.DecodeLevel(levels); polyline.ZoomFactor = zoomFactor; polyline.NumLevels = numLevels; return(polyline); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * copy constructor. * @param pline pline object copied from. */ public GeoPolyline(GeoPolyline pline) { if (pline._latlngs != null) { _latlngs = new GeoLatLng[pline._latlngs.Length]; Array.Copy(_latlngs, 0, _latlngs, 0, _latlngs.Length); _levels = new int[pline._levels.Length]; for (int i = 0; i < _levels.Length; i++) { _levels[i] = pline._levels[i]; } _bounds = new GeoLatLngBounds(pline._bounds); } _color = pline._color; _weight = pline._weight; _opacity = pline._opacity; ZoomFactor = pline.ZoomFactor; NumLevels = pline.NumLevels; _visible = pline._visible; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Creates a polygon from encoded strings of aggregated points and _levels. * _zoomFactor and _numLevels these two values determine the precision * of the _levels within an encoded polygon. * @param _strokeColor the color of the polygon. * @param _strokeWeight Width of the line in pixels. * @param _strokeOpacity the opacity of the polygon. * @param _fillColor the inner color of the polygon. * @param _fillOpacity the inner opacity of the polygon. * @param points a string containing the encoded latitude and longitude * coordinates. * @param _zoomFactor the magnification between adjacent sets of zoom _levels * in the encoded _levels string. * @param _levels a string containing the encoded polygon zoom level groups. * @param _numLevels the number of zoom _levels contained in the encoded _levels string. * @return Geo polygon object. */ public static GeoPolygon FromEncoded(int strokeColor, int strokeWeight, double strokeOpacity, int fillColor, double fillOpacity, String points, int zoomFactor, String levels, int numLevels) { ArrayList trk = PolylineEncoder.CreateDecodings(points); GeoLatLng[] array = new GeoLatLng[trk.Count]; var temp = trk.ToArray(); for (int i = 0; i < temp.Length; i++) { array[i] = (GeoLatLng)temp[i]; } GeoPolygon polygon = new GeoPolygon(array, strokeColor, strokeWeight, strokeOpacity, fillColor, fillOpacity); polygon._levels = PolylineEncoder.DecodeLevel(levels); polygon._zoomFactor = zoomFactor; polygon._numLevels = numLevels; return(polygon); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * copy constructor. * @param polygon polygon object copied from. */ public GeoPolygon(GeoPolygon polygon) { if (polygon._latlngs != null) { _latlngs = new GeoLatLng[polygon._latlngs.Length]; Array.Copy(_latlngs, 0, _latlngs, 0, _latlngs.Length); _levels = new int[polygon._levels.Length]; for (int i = 0; i < _levels.Length; i++) { _levels[i] = polygon._levels[i]; } _bounds = new GeoLatLngBounds(polygon._bounds); } _strokeColor = polygon._strokeColor; _strokeOpacity = polygon._strokeOpacity; _strokeWeight = polygon._strokeWeight; _fillColor = polygon._fillColor; _fillOpacity = polygon._fillOpacity; _zoomFactor = polygon._zoomFactor; _numLevels = polygon._numLevels; _visible = polygon._visible; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Calculate the Distance between two point in great circle. * @param pt1 the first location. * @param pt2 the second location. * @return the Distance and course between the 2 point. */ internal GeoLatLng CalculateDistanceAndCourse(GeoLatLng pt1, GeoLatLng pt2) { CrsdistResult ret = ComputeFormCD(pt1, pt2); GeoLatLng ret1 = new GeoLatLng(ret._crs12, ret._d); return ret1; }
private CrsdistResult ComputeFormCD(GeoLatLng pt1, GeoLatLng pt2) { double d, crs12, crs21; CrsdistResult outValue = new CrsdistResult(); double lat1 = pt1.LatRadians(); double lat2 = pt2.LatRadians(); double lon1 = -pt1.LngRadians(); double lon2 = -pt2.LngRadians(); double dc = _currentUnit == UNIT_NM ? 1 : 1.852; if (_currentEarthMode == EARTH_MODEL_SPHERE) { // spherical code// compute crs and Distance CrsdistResult cd = Crsdist(lat1, lon1, lat2, lon2); crs12 = cd._crs12 * (180 / MathEx.PI); crs21 = cd._crs21 * (180 / MathEx.PI); d = cd._d * (180 / MathEx.PI) * 60 * dc; // go to physical units } else { // elliptic code // ellipse uses East negative CrsdistResult cde = CrsdistEll(lat1, -lon1, lat2, -lon2, _currentEarthMode); crs12 = cde._crs12 * (180 / MathEx.PI); crs21 = cde._crs21 * (180 / MathEx.PI); d = cde._d * dc; // go to physical units } outValue._crs12 = crs12; outValue._crs21 = crs21; outValue._d = d; return outValue; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Computes the pixel coordinates of the given geographical point in the map. * @param latlng the geographical coordinates. * @return the pixel coordinates in the map. */ public GeoPoint FromLatLngToMapPixel(GeoLatLng latlng) { GeoPoint center = FromLatLngToPixel(_mapCenterPt, _mapZoomLevel); GeoPoint topLeft = new GeoPoint(center.X - _mapSize.Width / 2.0, center.Y - _mapSize.Height / 2.0); GeoPoint pointPos = FromLatLngToPixel(latlng, _mapZoomLevel); pointPos.X -= topLeft.X; pointPos.Y -= topLeft.Y; return new GeoPoint((int)(pointPos.X + 0.5), (int)(pointPos.Y + 0.5)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the length (in meters) of the polyline along the surface of a * spherical Earth * @return the length (in meters) of the polyline. */ public int GetLength() { int len = 0; if (_latlngs != null) { double length = 0; GeoLatLng pt1 = new GeoLatLng(_latlngs[0].Lat(), _latlngs[0].Lng()); for (int i = 1; i < _latlngs.Length; i++) { GeoLatLng pt2 = new GeoLatLng(_latlngs[i].Lat(), _latlngs[i].Lng()); length += pt1.DistanceFrom(pt2); pt1 = pt2; } len = (int)(length * 1000.0 + 0.5); } return len; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * draw a map object. * @param mapObject the map object to be drawing. * @param drawBoundary the drawing boundry. * @param zoomLevel the current zoomLevel. */ public override void DrawMapObject(MapObject mapObject, GeoLatLngBounds drawBoundary, int zoomLevel) { GeoLatLng drawPt = new GeoLatLng(); _sutherlandHodgman = new SutherlandHodgman(drawBoundary); _mapZoomLevel = zoomLevel; _mapCenterPt.X = drawBoundary.GetCenterX(); _mapCenterPt.Y = drawBoundary.GetCenterY(); bool pointFound = false; switch (mapObject.GetMapObjectType()) { case MapObject.NONE: break; case MapObject.POINT: { MapPoint mapPoint = (MapPoint)mapObject; DrawPoint(mapPoint); drawPt.X = mapPoint.Point.X; drawPt.Y = mapPoint.Point.Y; pointFound = true; } break; case MapObject.MULTIPOINT: { MapMultiPoint mapMultiPoint = (MapMultiPoint)mapObject; for (int i = 0; i < mapMultiPoint.Points.Length; i++) { MapPoint mapPoint = new MapPoint { SymbolType = mapMultiPoint.SymbolType, Point = new GeoLatLng(mapMultiPoint.Points[i]) }; DrawPoint(mapPoint); } for (int i = 0; i < mapMultiPoint.Points.Length; i++) { if (drawBoundary.Contains(mapMultiPoint.Points[i])) { drawPt.X = mapMultiPoint.Points[i].X; drawPt.Y = mapMultiPoint.Points[i].Y; pointFound = true; break; } } } break; case MapObject.PLINE: { MapPline mapPline = (MapPline)mapObject; DrawPline(mapPline.PenStyle, mapPline.Pline); for (int i = 0; i < mapPline.Pline.GetVertexCount(); i++) { if (drawBoundary.Contains(mapPline.Pline.GetVertex(i))) { drawPt.X = mapPline.Pline.GetVertex(i).X; drawPt.Y = mapPline.Pline.GetVertex(i).Y; pointFound = true; break; } } } break; case MapObject.MULTIPLINE: { MapMultiPline mapMultiPline = (MapMultiPline)mapObject; for (int i = 0; i < mapMultiPline.Plines.Length; i++) { DrawPline(mapMultiPline.PenStyle, mapMultiPline.Plines[i]); for (int j = 0; j < mapMultiPline.Plines[i].GetVertexCount(); j++) { if (drawBoundary.Contains(mapMultiPline.Plines[i].GetVertex(j))) { drawPt.X = mapMultiPline.Plines[i].GetVertex(j).X; drawPt.Y = mapMultiPline.Plines[i].GetVertex(j).Y; pointFound = true; break; } } } } break; case MapObject.REGION: { MapRegion mapRegion = (MapRegion)mapObject; DrawRegion(mapRegion.PenStyle, mapRegion.BrushStyle, mapRegion.Region); drawPt.X = mapRegion.CenterPt.X; drawPt.Y = mapRegion.CenterPt.Y; pointFound = true; } break; case MapObject.MULTIREGION: { MapMultiRegion mapMultiRegion = (MapMultiRegion)mapObject; for (int i = 0; i < mapMultiRegion.Regions.Length; i++) { DrawRegion(mapMultiRegion.PenStyle, mapMultiRegion.BrushStyle, mapMultiRegion.Regions[i]); } drawPt.X = mapMultiRegion.CenterPt.X; drawPt.Y = mapMultiRegion.CenterPt.Y; pointFound = true; } break; case MapObject.COLLECTION: { MapCollection mapCollection = (MapCollection)mapObject; if (mapCollection.MultiRegion != null) { MapMultiRegion mapMultiRegion = mapCollection.MultiRegion; for (int i = 0; i < mapMultiRegion.Regions.Length; i++) { DrawRegion(mapMultiRegion.PenStyle, mapMultiRegion.BrushStyle, mapMultiRegion.Regions[i]); } } if (mapCollection.MultiPline != null) { MapMultiPline mapMultiPline = mapCollection.MultiPline; for (int i = 0; i < mapMultiPline.Plines.Length; i++) { DrawPline(mapMultiPline.PenStyle, mapMultiPline.Plines[i]); } } if (mapCollection.MultiPoint != null) { MapMultiPoint mapMultiPoint = mapCollection.MultiPoint; for (int i = 0; i < mapMultiPoint.Points.Length; i++) { MapPoint mapPoint = new MapPoint { SymbolType = mapMultiPoint.SymbolType, Point = new GeoLatLng(mapMultiPoint.Points[i]) }; DrawPoint(mapPoint); } } pointFound = true; drawPt.X = mapCollection.Bounds.X + mapCollection.Bounds.Width / 2; drawPt.Y = mapCollection.Bounds.Y + mapCollection.Bounds.Height / 2; } break; case MapObject.TEXT: { MapText mapText = (MapText)mapObject; drawPt.X = mapText.Point.X; drawPt.Y = mapText.Point.Y; pointFound = true; } break; } if (!mapObject.Name.ToLower().Equals("unknown") && pointFound) { MapText mapName = new MapText {Font = _font}; mapName.SetForeColor(_fontColor); mapName.TextString = mapObject.Name; GeoPoint screenPt = FromLatLngToMapPixel(drawPt); mapName.Point.X = screenPt.X; mapName.Point.Y = screenPt.Y; mapName.Bounds.X = mapName.Point.X; mapName.Bounds.Y = mapName.Point.Y; if (_font != null) { mapName.Bounds.Height = IMAGE_PATERN_WIDTH; mapName.Bounds.Width = _font.CharsWidth(mapObject.Name.ToCharArray(), 0, mapObject.Name.ToCharArray().Length); } AddMapName(mapName); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * default constructor. */ public MapRegion() { SetMapObjectType(REGION); PenStyle = new MapPen(); BrushStyle = new MapBrush(); CenterPt = new GeoLatLng(); Region = null; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Changes the center point of the map to the given point. * @param center a new center point of the map. */ public override void PanTo(GeoLatLng center) { lock (_mapLayers) { for (int i = 0; i < _mapLayers.Count; i++) { MapLayer mapLayer = (MapLayer)_mapLayers[i]; mapLayer.PanTo(center); } } base.PanTo(center); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Empty constructor. */ public MapText() { SetMapObjectType(TEXT); Point = new GeoLatLng(); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Set the location of the map points. * @param pts the location */ public void SetPoint(GeoLatLng[] pts) { Points = pts; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Constructs and initializes a point with the same location as * the specified <code>GeoLatLng</code> object. * @param p a point */ public GeoLatLng(GeoLatLng p) : this(p.Lat(), p.Lng()) { }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 03JAN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Empty constructor. */ public MapPoint() { SetMapObjectType(POINT); SymbolType = new MapSymbol(); Point = new GeoLatLng(); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * set the array of points which consist of the line. * @param points array of points */ public void SetPoints(GeoLatLng[] points) { _latlngs = points; }
private GeoLatLng ComputeFormDir(GeoLatLng pt1, double distance, double crs) { //get select values double lat2, lon2; /* Input and validate data */ double lat1 = pt1.LatRadians(); double lon1 = -pt1.LngRadians(); double d12 = distance; double dc = _currentUnit == UNIT_NM ? 1 : 1.852; d12 /= dc; double crs12 = crs * MathEx.PI / 180.0; if (_currentEarthMode == EARTH_MODEL_SPHERE) { // spherical code d12 /= (180 * 60 / MathEx.PI); // in radians DirectResult cd = Direct(lat1, lon1, crs12, d12); lat2 = cd._lat * (180 / MathEx.PI); lon2 = cd._lon * (180 / MathEx.PI); } else { // elliptic code// ellipse uses East negative DirectResult cde = DirectEll(lat1, -lon1, crs12, d12, _currentEarthMode); lat2 = cde._lat * (180 / MathEx.PI); lon2 = -cde._lon * (180 / MathEx.PI);// ellipse uses East negative } double retLat = lat2; double retLon = -lon2; return new GeoLatLng(retLat, retLon); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Sets the map view to the given center. * @param center the center latitude,longitude of the map. * @param zoomLevel the zoom Level of the map [0,17]. */ public override void SetCenter(GeoLatLng center, int zoomLevel) { lock (_mapLayers) { for (int i = 0; i < _mapLayers.Count; i++) { MapLayer mapLayer = (MapLayer)_mapLayers[i]; mapLayer.SetCenter(center, zoomLevel); } } base.SetCenter(center, zoomLevel); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param mapText map object copy from. */ public MapText(MapText mapText) : base(mapText) { SetMapObjectType(TEXT); Point = new GeoLatLng(mapText.Point); Angle = mapText.Angle; BackColor = mapText.BackColor; ForeColor = mapText.ForeColor; Justification = mapText.Justification; Spacing = mapText.Spacing; LineType = mapText.LineType; TextString = mapText.TextString; Font = mapText.Font; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * is the point in current screen (is shown or not). * @param pt point to be tested. * @return true is in screen range. */ public virtual bool IsPointVisible(GeoLatLng pt) { GeoPoint screenPt = FromLatLngToMapPixel(pt); return _mapSize.Contains((int)screenPt.X, (int)screenPt.Y); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Set the location of the map point. * @param p the location */ public void SetPoint(GeoLatLng p) { Point = new GeoLatLng(p); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Resize the map to a level that include given bounds * @param bounds new bound. */ public virtual void Resize(GeoLatLngBounds bounds) { lock (_syncObject) { GeoLatLng sw = bounds.GetSouthWest(); GeoLatLng ne = bounds.GetNorthEast(); GeoLatLng center = new GeoLatLng {X = (sw.X + ne.X)/2.0, Y = (sw.Y + ne.Y)/2.0}; GeoPoint pt1, pt2; for (int i = MAX_ZOOMLEVEL; i >= MIN_ZOOMLEVEL; i--) { pt1 = FromLatLngToPixel(sw, i); pt2 = FromLatLngToPixel(ne, i); double dblWidth = Math.Abs(pt1.X - pt2.X); double dblHeight = Math.Abs(pt1.Y - pt2.Y); if (dblWidth < _mapSize.Width && dblHeight < _mapSize.Height) { _mapZoomLevel = i; SetCenter(center, i); break; } } } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get a location with given Distance ,direction of one point. * @param pt1 the first location. * @param Distance the Distance to the first point. * @param direction the direction to the first point. * @return the second point. */ public GeoLatLng GetLocationWithDistance(GeoLatLng pt1, double distance, double direction) { return(ComputeFormDir(pt1, distance, direction)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Calculate the Distance between two point in great circle. * @param pt1 the first location. * @param pt2 the second location. * @return the Distance between the two points. */ public double CalculateDistance(GeoLatLng pt1, GeoLatLng pt2) { CrsdistResult ret = ComputeFormCD(pt1, pt2); return(ret._d); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Computes the pixel coordinates of the given geographical point . * @param latLng latitude,longitude pair of give point * @param zoomLevel current zoom level * @return the pixel coordinates. */ public static GeoPoint FromLatLngToPixel(GeoLatLng latLng, int zoomLevel) { //double latitude = latLng.Lat(); //double longitude = latLng.Lng(); //double power = 8 + zoomLevel; //double mapsize = MathEx.Pow(2, power); //double origin = mapsize / 2; //double longdeg = MathEx.Abs(-180 - longitude); //double longppd = mapsize / 360; //double longppdrad = mapsize / (2 * Math.PI); //double pixelx = longdeg * longppd; //double e = MathEx.Sin(latitude * (1 / 180.0 * MathEx.PI)); //if (e > 0.9999) //{ // e = 0.9999; //} //if (e < -0.9999) //{ // e = -0.9999; //} //double pixely = origin + 0.5 * MathEx.Log2((1 + e) / (1 - e)) * (-longppdrad); //return new GeoPoint(pixelx, pixely); int pixelX, pixelY; TileSystem.LatLongToPixelXY(latLng.Lat(), latLng.Lng(), zoomLevel, out pixelX, out pixelY); return new GeoPoint(pixelX, pixelY); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get a location with given Distance ,direction of one point. * @param pt1 the first location. * @param Distance the Distance to the first point. * @param direction the direction to the first point. * @return the second point. */ public GeoLatLng GetLocationWithDistance(GeoLatLng pt1, double distance, double direction) { return ComputeFormDir(pt1, distance, direction); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * return screen boundary in geo coordinates. * @param pt the center of the screen. * @return screen boundary in geo coordinates. */ public GeoLatLngBounds GetScreenBounds(GeoLatLng pt) { lock (_syncObject) { GeoPoint center = FromLatLngToPixel(pt, _mapZoomLevel); int shiftWidth = _screenSize.Width; GeoPoint topLeft = new GeoPoint(center.X - _screenSize.Width / 2.0 - shiftWidth, center.Y - _screenSize.Height / 2.0 - _screenSize.Height); GeoPoint bottomRight = new GeoPoint(center.X + _screenSize.Width / 2.0 + shiftWidth, center.Y + _screenSize.Height / 2.0 + _screenSize.Height); GeoLatLng topLeftLatLng = FromPixelToLatLng(topLeft, _mapZoomLevel); GeoLatLng bottomRightLatLng = FromPixelToLatLng(bottomRight, _mapZoomLevel); double minY = Math.Min(bottomRightLatLng.Lat(), topLeftLatLng.Lat()); double maxY = Math.Max(bottomRightLatLng.Lat(), topLeftLatLng.Lat()); double minX = Math.Min(bottomRightLatLng.Lng(), topLeftLatLng.Lng()); double maxX = Math.Max(bottomRightLatLng.Lng(), topLeftLatLng.Lng()); return new GeoLatLngBounds(minX, minY, maxX - minX, maxY - minY); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Creates a polyline from encoded strings of aggregated points and levels. * ZoomFactor and NumLevels these two values determine the precision * of the levels within an encoded polyline. * @param _color the _color of the polyline. * @param _weight Width of the line in pixels. * @param _opacity the _opacity of the polyline. * @param points a string containing the encoded latitude and longitude * coordinates. * @param ZoomFactor the magnification between adjacent sets of zoom levels * in the encoded levels string. * @param levels a string containing the encoded polyline zoom level groups. * @param NumLevels the number of zoom levels contained in the encoded * levels string. * @return Geo polyline object. */ public static GeoPolyline FromEncoded(int color, int weight, double opacity, String points, int zoomFactor, String levels, int numLevels) { ArrayList trk = PolylineEncoder.CreateDecodings(points); GeoLatLng[] array = new GeoLatLng[trk.Count]; var temp = trk.ToArray(); for (int i = 0; i < temp.Length; i++) { array[i] = (GeoLatLng)temp[i]; } GeoPolyline polyline = new GeoPolyline(array, color, weight, opacity); polyline._levels = PolylineEncoder.DecodeLevel(levels); polyline.ZoomFactor = zoomFactor; polyline.NumLevels = numLevels; return polyline; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Changes the center point of the map to the given point. * @param center a new center point of the map. */ public virtual void PanTo(GeoLatLng center) { lock (_syncObject) { _mapCenterPt.X = center.X; _mapCenterPt.Y = center.Y; DrawMapCanvas(); } }
private void MainWindow_Load(object sender, EventArgs e) { var center = new GeoLatLng(32.0176410, 118.7273120); _rasterMap.SetCenter(center, 2, _rasterMap.GetMapType()); btnReset_Click(sender,e); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Sets the map view to the given center. * @param center the center latitude,longitude of the map. * @param zoomLevel the zoom Level of the map [0,17]. */ public virtual void SetCenter(GeoLatLng center, int zoomLevel) { lock (_syncObject) { _mapZoomLevel = zoomLevel; _mapCenterPt.X = center.X; _mapCenterPt.Y = center.Y; DrawMapCanvas(); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Calculate the Distance between two point in great circle. * @param pt1 the first location. * @param pt2 the second location. * @return the Distance between the two points. */ public double CalculateDistance(GeoLatLng pt1, GeoLatLng pt2) { CrsdistResult ret = ComputeFormCD(pt1, pt2); return ret._d; }