using System; using System.Drawing; namespace FlickrNet { /// /// Summary description for BoundaryBox. /// public class BoundaryBox { private GeoAccuracy _accuracy = GeoAccuracy.Street; private bool _isSet = false; private double _minimumLat = -90; private double _minimumLon = -180; private double _maximumLat = 90; private double _maximumLon = 180; /// /// Gets weither the boundary box has been set or not. /// internal bool IsSet { get { return _isSet; } } /// /// The search accuracy - optional. Defaults to . /// public GeoAccuracy Accuracy { get { return _accuracy; } set { _accuracy = value; } } /// /// The minimum latitude of the boundary box, i.e. bottom left hand corner. /// public double MinimumLatitude { get { return _minimumLat; } set { if( value < -90 || value > 90 ) throw new ArgumentOutOfRangeException("MinimumLatitude", value, "Must be between -90 and 90"); _isSet = true; _minimumLat = value; } } /// /// The minimum longitude of the boundary box, i.e. bottom left hand corner. Range of -180 to 180 allowed. /// public double MinimumLongitude { get { return _minimumLon; } set { if( value < -180 || value > 180 ) throw new ArgumentOutOfRangeException("MinimumLongitude", value, "Must be between -180 and 180"); _isSet = true; _minimumLon = value; } } /// /// The maximum latitude of the boundary box, i.e. top right hand corner. Range of -90 to 90 allowed. /// public double MaximumLatitude { get { return _maximumLat; } set { if( value < -90 || value > 90 ) throw new ArgumentOutOfRangeException("MaximumLatitude", value, "Must be between -90 and 90"); _isSet = true; _maximumLat = value; } } /// /// The maximum longitude of the boundary box, i.e. top right hand corner. Range of -180 to 180 allowed. /// public double MaximumLongitude { get { return _maximumLon; } set { if( value < -180 || value > 180 ) throw new ArgumentOutOfRangeException("MaximumLongitude", value, "Must be between -180 and 180"); _isSet = true; _maximumLon = value; } } /// /// Default constructor /// public BoundaryBox() { } /// /// Default constructor, specifying only the accuracy level. /// /// The of the search parameter. public BoundaryBox(GeoAccuracy accuracy) { _accuracy = accuracy; } /// /// Constructor for the /// /// A comma seperated list of co-ordinates defining the boundary box. /// The of the search parameter. public BoundaryBox(string points, GeoAccuracy accuracy) : this(points) { _accuracy = accuracy; } /// /// Constructor for the /// /// A comma seperated list of co-ordinates defining the boundary box. public BoundaryBox(string points) { if( points == null ) throw new ArgumentNullException("points"); string[] splits = points.Split(','); if( splits.Length != 4 ) throw new ArgumentException("Parameter must contain 4 values, seperated by commas.", "points"); try { MinimumLongitude = double.Parse(splits[0]); MinimumLatitude = double.Parse(splits[1]); MaximumLongitude = double.Parse(splits[2]); MaximumLatitude = double.Parse(splits[3]); } catch(FormatException) { throw new ArgumentException("Unable to parse points as integer values", "points"); } } /// /// Constructor for the . /// /// The minimum longitude of the boundary box. Range of -180 to 180 allowed. /// The minimum latitude of the boundary box. Range of -90 to 90 allowed. /// The maximum longitude of the boundary box. Range of -180 to 180 allowed. /// The maximum latitude of the boundary box. Range of -90 to 90 allowed. /// The of the search parameter. public BoundaryBox(double minimumLongitude, double minimumLatitude, double maximumLongitude, double maximumLatitude, GeoAccuracy accuracy) : this(minimumLongitude, minimumLatitude, maximumLongitude, maximumLatitude) { _accuracy = accuracy; } /// /// Constructor for the . /// /// The minimum longitude of the boundary box. Range of -180 to 180 allowed. /// The minimum latitude of the boundary box. Range of -90 to 90 allowed. /// The maximum longitude of the boundary box. Range of -180 to 180 allowed. /// The maximum latitude of the boundary box. Range of -90 to 90 allowed. public BoundaryBox(double minimumLongitude, double minimumLatitude, double maximumLongitude, double maximumLatitude) { MinimumLatitude = minimumLatitude; MinimumLongitude = minimumLongitude; MaximumLatitude = maximumLatitude; MaximumLongitude = maximumLongitude; } /// /// Overrides the ToString method. /// /// A comma seperated list of co-ordinates defining the boundary box. public override string ToString() { return String.Format("{0},{1},{2},{3}", MinimumLongitude, MinimumLatitude, MaximumLongitude, MaximumLatitude); } /// /// Example boundary box for the UK. /// public static BoundaryBox UK { get { return new BoundaryBox(-11.118164, 49.809632, 1.625977, 62.613562); } } /// /// Example boundary box for Newcastle upon Tyne, England. /// public static BoundaryBox UKNewcastle { get { return new BoundaryBox(-1.71936, 54.935821, -1.389771, 55.145919); } } /// /// Example boundary box for the USA (excludes Hawaii and Alaska). /// public static BoundaryBox USA { get { return new BoundaryBox(-130.429687, 22.43134, -58.535156, 49.382373); } } /// /// Example boundary box for Canada. /// public static BoundaryBox Canada { get { return new BoundaryBox(-143.085937, 41.640078, -58.535156, 73.578167); } } /// /// Example boundary box for the whole world. /// public static BoundaryBox World { get { return new BoundaryBox(-180, -90, 180, 90); } } } }