| | 1 | /* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. |
|---|
| | 2 | * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt |
|---|
| | 3 | * for the full text of the license. */ |
|---|
| | 4 | |
|---|
| | 5 | /** |
|---|
| | 6 | * Class: OpenLayers.Bounds |
|---|
| | 7 | * Instances of this class represent bounding boxes. Data stored as left, |
|---|
| | 8 | * bottom, right, top floats |
|---|
| | 9 | */ |
|---|
| | 10 | OpenLayers.Bounds = OpenLayers.Class.create(); |
|---|
| | 11 | OpenLayers.Bounds.prototype = { |
|---|
| | 12 | |
|---|
| | 13 | /** |
|---|
| | 14 | * Property: left |
|---|
| | 15 | * {Number} |
|---|
| | 16 | */ |
|---|
| | 17 | left: 0.0, |
|---|
| | 18 | |
|---|
| | 19 | /** |
|---|
| | 20 | * Property: bottom |
|---|
| | 21 | * {Number} |
|---|
| | 22 | */ |
|---|
| | 23 | bottom: 0.0, |
|---|
| | 24 | |
|---|
| | 25 | /** |
|---|
| | 26 | * Property: right |
|---|
| | 27 | * {Number} |
|---|
| | 28 | */ |
|---|
| | 29 | right: 0.0, |
|---|
| | 30 | |
|---|
| | 31 | /** |
|---|
| | 32 | * Property: top |
|---|
| | 33 | * {Number} |
|---|
| | 34 | */ |
|---|
| | 35 | top: 0.0, |
|---|
| | 36 | |
|---|
| | 37 | /** |
|---|
| | 38 | * Constructor: OpenLayers.Bounds |
|---|
| | 39 | * Construct a new bounds object. |
|---|
| | 40 | * |
|---|
| | 41 | * Parameters: |
|---|
| | 42 | * left - {Number} The left bounds of the box. Note that for width |
|---|
| | 43 | * calculations, this is assumed to be less than the right value. |
|---|
| | 44 | * bottom - {Number} The bottom bounds of the box. Note that for height |
|---|
| | 45 | * calculations, this is assumed to be more than the top value. |
|---|
| | 46 | * right - {Number} The right bounds. |
|---|
| | 47 | * top - {Number} The top bounds. |
|---|
| | 48 | */ |
|---|
| | 49 | initialize: function(left, bottom, right, top) { |
|---|
| | 50 | this.left = parseFloat(left); |
|---|
| | 51 | this.bottom = parseFloat(bottom); |
|---|
| | 52 | this.right = parseFloat(right); |
|---|
| | 53 | this.top = parseFloat(top); |
|---|
| | 54 | }, |
|---|
| | 55 | |
|---|
| | 56 | /** |
|---|
| | 57 | * Method: clone |
|---|
| | 58 | * Create a cloned instance of this bounds. |
|---|
| | 59 | * |
|---|
| | 60 | * Return: |
|---|
| | 61 | * {<OpenLayers.Bounds>} A fresh copy of the bounds |
|---|
| | 62 | */ |
|---|
| | 63 | clone:function() { |
|---|
| | 64 | return new OpenLayers.Bounds(this.left, this.bottom, |
|---|
| | 65 | this.right, this.top); |
|---|
| | 66 | }, |
|---|
| | 67 | |
|---|
| | 68 | /** |
|---|
| | 69 | * Method: equals |
|---|
| | 70 | * Test a two bounds for equivalence |
|---|
| | 71 | * |
|---|
| | 72 | * Parameters: |
|---|
| | 73 | * bounds - {<OpenLayers.Bounds>} |
|---|
| | 74 | * |
|---|
| | 75 | * Return: |
|---|
| | 76 | * {Boolean} The passed-in OpenLayers.Bounds object has the same left, |
|---|
| | 77 | * right, top, bottom components as this. Note that if bounds |
|---|
| | 78 | * passed in is null, returns false. |
|---|
| | 79 | */ |
|---|
| | 80 | equals:function(bounds) { |
|---|
| | 81 | var equals = false; |
|---|
| | 82 | if (bounds != null) { |
|---|
| | 83 | equals = ((this.left == bounds.left) && |
|---|
| | 84 | (this.right == bounds.right) && |
|---|
| | 85 | (this.top == bounds.top) && |
|---|
| | 86 | (this.bottom == bounds.bottom)); |
|---|
| | 87 | } |
|---|
| | 88 | return equals; |
|---|
| | 89 | }, |
|---|
| | 90 | |
|---|
| | 91 | /** |
|---|
| | 92 | * APIMethod: toString |
|---|
| | 93 | * |
|---|
| | 94 | * Return: |
|---|
| | 95 | * {String} String representation of OpenLayers.Bounds object. |
|---|
| | 96 | * (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>) |
|---|
| | 97 | */ |
|---|
| | 98 | toString:function() { |
|---|
| | 99 | return ( "left-bottom=(" + this.left + "," + this.bottom + ")" |
|---|
| | 100 | + " right-top=(" + this.right + "," + this.top + ")" ); |
|---|
| | 101 | }, |
|---|
| | 102 | |
|---|
| | 103 | /** |
|---|
| | 104 | * APIMethod: toBBOX |
|---|
| | 105 | * |
|---|
| | 106 | * Parameters: |
|---|
| | 107 | * decimal - {Integer} How many significant digits in the bbox coords? |
|---|
| | 108 | * Default is 6 |
|---|
| | 109 | * |
|---|
| | 110 | * Return: |
|---|
| | 111 | * {String} Simple String representation of OpenLayers.Bounds object. |
|---|
| | 112 | * (ex. <i>"5,42,10,45"</i>) |
|---|
| | 113 | */ |
|---|
| | 114 | toBBOX:function(decimal) { |
|---|
| | 115 | if (decimal== null) { |
|---|
| | 116 | decimal = 6; |
|---|
| | 117 | } |
|---|
| | 118 | var mult = Math.pow(10, decimal); |
|---|
| | 119 | var bbox = Math.round(this.left * mult) / mult + "," + |
|---|
| | 120 | Math.round(this.bottom * mult) / mult + "," + |
|---|
| | 121 | Math.round(this.right * mult) / mult + "," + |
|---|
| | 122 | Math.round(this.top * mult) / mult; |
|---|
| | 123 | |
|---|
| | 124 | return bbox; |
|---|
| | 125 | }, |
|---|
| | 126 | |
|---|
| | 127 | /** |
|---|
| | 128 | * APIMethod: getWidth |
|---|
| | 129 | * |
|---|
| | 130 | * Return: |
|---|
| | 131 | * {Float} The width of the bounds |
|---|
| | 132 | */ |
|---|
| | 133 | getWidth:function() { |
|---|
| | 134 | return (this.right - this.left); |
|---|
| | 135 | }, |
|---|
| | 136 | |
|---|
| | 137 | /** |
|---|
| | 138 | * APIMethod: getHeight |
|---|
| | 139 | * |
|---|
| | 140 | * Return: |
|---|
| | 141 | * {Float} The height of the bounds |
|---|
| | 142 | */ |
|---|
| | 143 | getHeight:function() { |
|---|
| | 144 | return (this.top - this.bottom); |
|---|
| | 145 | }, |
|---|
| | 146 | |
|---|
| | 147 | /** |
|---|
| | 148 | * APIMethod: getSize |
|---|
| | 149 | * |
|---|
| | 150 | * Return: |
|---|
| | 151 | * {<OpenLayers.Size>} An <OpenLayers.Size> which represents the size of the box |
|---|
| | 152 | */ |
|---|
| | 153 | getSize:function() { |
|---|
| | 154 | return new OpenLayers.Size(this.getWidth(), this.getHeight()); |
|---|
| | 155 | }, |
|---|
| | 156 | |
|---|
| | 157 | /** |
|---|
| | 158 | * APIMethod: getCenterPixel |
|---|
| | 159 | * |
|---|
| | 160 | * Return: |
|---|
| | 161 | * {<OpenLayers.Pixel>} An <OpenLayers.Pixel> which represents the center |
|---|
| | 162 | * of the bounds |
|---|
| | 163 | */ |
|---|
| | 164 | getCenterPixel:function() { |
|---|
| | 165 | return new OpenLayers.Pixel( (this.left + this.right) / 2, |
|---|
| | 166 | (this.bottom + this.top) / 2); |
|---|
| | 167 | }, |
|---|
| | 168 | |
|---|
| | 169 | /** |
|---|
| | 170 | * APIMethod: getCenterLonLat |
|---|
| | 171 | * |
|---|
| | 172 | * Return: |
|---|
| | 173 | * {<OpenLayers.LonLat>} An <OpenLayers.LonLat> which represents the center |
|---|
| | 174 | * of the bounds |
|---|
| | 175 | */ |
|---|
| | 176 | getCenterLonLat:function() { |
|---|
| | 177 | return new OpenLayers.LonLat( (this.left + this.right) / 2, |
|---|
| | 178 | (this.bottom + this.top) / 2); |
|---|
| | 179 | }, |
|---|
| | 180 | |
|---|
| | 181 | /** |
|---|
| | 182 | * APIMethod: add |
|---|
| | 183 | * |
|---|
| | 184 | * Parameters: |
|---|
| | 185 | * x - {Float} |
|---|
| | 186 | * y - {Float} |
|---|
| | 187 | * |
|---|
| | 188 | * Return: |
|---|
| | 189 | * {<OpenLayers.Bounds>} A new <OpenLayers.Bounds> whose coordinates are |
|---|
| | 190 | * the same as this, but shifted by the passed-in |
|---|
| | 191 | * x and y values |
|---|
| | 192 | */ |
|---|
| | 193 | add:function(x, y) { |
|---|
| | 194 | return new OpenLayers.Bounds(this.left + x, this.bottom + y, |
|---|
| | 195 | this.right + x, this.top + y); |
|---|
| | 196 | }, |
|---|
| | 197 | |
|---|
| | 198 | /** |
|---|
| | 199 | * APIMethod: extend |
|---|
| | 200 | * Extend the bounds to include the point, lonlat, or bounds specified. |
|---|
| | 201 | * Note: This function assumes that left<right and bottom<top. |
|---|
| | 202 | * |
|---|
| | 203 | * |
|---|
| | 204 | * Parameters: |
|---|
| | 205 | * object - {Object} Can be LonLat, Point, or Bounds |
|---|
| | 206 | */ |
|---|
| | 207 | extend:function(object) { |
|---|
| | 208 | var bounds = null; |
|---|
| | 209 | if (object) { |
|---|
| | 210 | switch(object.CLASS_NAME) { |
|---|
| | 211 | case "OpenLayers.LonLat": |
|---|
| | 212 | bounds = new OpenLayers.Bounds(object.lon, object.lat, |
|---|
| | 213 | object.lon, object.lat); |
|---|
| | 214 | break; |
|---|
| | 215 | case "OpenLayers.Geometry.Point": |
|---|
| | 216 | bounds = new OpenLayers.Bounds(object.x, object.y, |
|---|
| | 217 | object.x, object.y); |
|---|
| | 218 | break; |
|---|
| | 219 | |
|---|
| | 220 | case "OpenLayers.Bounds": |
|---|
| | 221 | bounds = object; |
|---|
| | 222 | break; |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| | 225 | if (bounds) { |
|---|
| | 226 | this.left = (bounds.left < this.left) ? bounds.left |
|---|
| | 227 | : this.left; |
|---|
| | 228 | this.bottom = (bounds.bottom < this.bottom) ? bounds.bottom |
|---|
| | 229 | : this.bottom; |
|---|
| | 230 | this.right = (bounds.right > this.right) ? bounds.right |
|---|
| | 231 | : this.right; |
|---|
| | 232 | this.top = (bounds.top > this.top) ? bounds.top |
|---|
| | 233 | : this.top; |
|---|
| | 234 | } |
|---|
| | 235 | } |
|---|
| | 236 | }, |
|---|
| | 237 | |
|---|
| | 238 | /** |
|---|
| | 239 | * APIMethod: containsLonLat |
|---|
| | 240 | * |
|---|
| | 241 | * Parameters: |
|---|
| | 242 | * ll - {<OpenLayers.LonLat>} |
|---|
| | 243 | * inclusive - {Boolean} Whether or not to include the border. |
|---|
| | 244 | * Default is true. |
|---|
| | 245 | * |
|---|
| | 246 | * Return: |
|---|
| | 247 | * {Boolean} Whether or not the passed-in lonlat is within this bounds. |
|---|
| | 248 | */ |
|---|
| | 249 | containsLonLat:function(ll, inclusive) { |
|---|
| | 250 | return this.contains(ll.lon, ll.lat, inclusive); |
|---|
| | 251 | }, |
|---|
| | 252 | |
|---|
| | 253 | /** |
|---|
| | 254 | * APIMethod: containsPixel |
|---|
| | 255 | * |
|---|
| | 256 | * Parameters: |
|---|
| | 257 | * px - {<OpenLayers.Pixel>} |
|---|
| | 258 | * inclusive - {Boolean} Whether or not to include the border. |
|---|
| | 259 | * Default is true. |
|---|
| | 260 | * |
|---|
| | 261 | * Return: |
|---|
| | 262 | * {Boolean} Whether or not the passed-in pixel is within this bounds. |
|---|
| | 263 | */ |
|---|
| | 264 | containsPixel:function(px, inclusive) { |
|---|
| | 265 | return this.contains(px.x, px.y, inclusive); |
|---|
| | 266 | }, |
|---|
| | 267 | |
|---|
| | 268 | /** |
|---|
| | 269 | * APIMethod: contains |
|---|
| | 270 | * |
|---|
| | 271 | * Parameters: |
|---|
| | 272 | * x - {Float} |
|---|
| | 273 | * y - {Float} |
|---|
| | 274 | * inclusive - {Boolean} Whether or not to include the border. |
|---|
| | 275 | * Default is true. |
|---|
| | 276 | * |
|---|
| | 277 | * Return: |
|---|
| | 278 | * {Boolean} Whether or not the passed-in coordinates are within this |
|---|
| | 279 | * bounds. |
|---|
| | 280 | */ |
|---|
| | 281 | contains:function(x, y, inclusive) { |
|---|
| | 282 | |
|---|
| | 283 | //set default |
|---|
| | 284 | if (inclusive == null) { |
|---|
| | 285 | inclusive = true; |
|---|
| | 286 | } |
|---|
| | 287 | |
|---|
| | 288 | var contains = false; |
|---|
| | 289 | if (inclusive) { |
|---|
| | 290 | contains = ((x >= this.left) && (x <= this.right) && |
|---|
| | 291 | (y >= this.bottom) && (y <= this.top)); |
|---|
| | 292 | } else { |
|---|
| | 293 | contains = ((x > this.left) && (x < this.right) && |
|---|
| | 294 | (y > this.bottom) && (y < this.top)); |
|---|
| | 295 | } |
|---|
| | 296 | return contains; |
|---|
| | 297 | }, |
|---|
| | 298 | |
|---|
| | 299 | /** |
|---|
| | 300 | * APIMethod: intersectsBounds |
|---|
| | 301 | * |
|---|
| | 302 | * Parameters: |
|---|
| | 303 | * bounds - {<OpenLayers.Bounds>} |
|---|
| | 304 | * inclusive - {<Boolean>} Whether or not to include the border. |
|---|
| | 305 | * Default is true. |
|---|
| | 306 | * |
|---|
| | 307 | * Return: |
|---|
| | 308 | * {Boolean} Whether or not the passed-in OpenLayers.Bounds object |
|---|
| | 309 | * intersects this bounds. Simple math just check if either |
|---|
| | 310 | * contains the other, allowing for partial. |
|---|
| | 311 | */ |
|---|
| | 312 | intersectsBounds:function(bounds, inclusive) { |
|---|
| | 313 | |
|---|
| | 314 | if (inclusive == null) { |
|---|
| | 315 | inclusive = true; |
|---|
| | 316 | } |
|---|
| | 317 | var inBottom = (bounds.bottom == this.bottom && bounds.top == this.top) ? |
|---|
| | 318 | true : (((bounds.bottom > this.bottom) && (bounds.bottom < this.top)) || |
|---|
| | 319 | ((this.bottom > bounds.bottom) && (this.bottom < bounds.top))); |
|---|
| | 320 | var inTop = (bounds.bottom == this.bottom && bounds.top == this.top) ? |
|---|
| | 321 | true : (((bounds.top > this.bottom) && (bounds.top < this.top)) || |
|---|
| | 322 | ((this.top > bounds.bottom) && (this.top < bounds.top))); |
|---|
| | 323 | var inRight = (bounds.right == this.right && bounds.left == this.left) ? |
|---|
| | 324 | true : (((bounds.right > this.left) && (bounds.right < this.right)) || |
|---|
| | 325 | ((this.right > bounds.left) && (this.right < bounds.right))); |
|---|
| | 326 | var inLeft = (bounds.right == this.right && bounds.left == this.left) ? |
|---|
| | 327 | true : (((bounds.left > this.left) && (bounds.left < this.right)) || |
|---|
| | 328 | ((this.left > bounds.left) && (this.left < bounds.right))); |
|---|
| | 329 | |
|---|
| | 330 | return (this.containsBounds(bounds, true, inclusive) || |
|---|
| | 331 | bounds.containsBounds(this, true, inclusive) || |
|---|
| | 332 | ((inTop || inBottom ) && (inLeft || inRight ))); |
|---|
| | 333 | }, |
|---|
| | 334 | |
|---|
| | 335 | /** |
|---|
| | 336 | * APIMethod: containsBounds |
|---|
| | 337 | * |
|---|
| | 338 | * bounds - {<OpenLayers.Bounds>} |
|---|
| | 339 | * partial - {<Boolean>} If true, only part of passed-in |
|---|
| | 340 | * <OpenLayers.Bounds> needs be within this bounds. |
|---|
| | 341 | * If false, the entire passed-in bounds must be |
|---|
| | 342 | * within. Default is false |
|---|
| | 343 | * inclusive - {<Boolean>} Whether or not to include the border. |
|---|
| | 344 | * Default is true. |
|---|
| | 345 | * |
|---|
| | 346 | * Return: |
|---|
| | 347 | * {Boolean} Whether or not the passed-in OpenLayers.Bounds object is |
|---|
| | 348 | * contained within this bounds. |
|---|
| | 349 | */ |
|---|
| | 350 | containsBounds:function(bounds, partial, inclusive) { |
|---|
| | 351 | |
|---|
| | 352 | //set defaults |
|---|
| | 353 | if (partial == null) { |
|---|
| | 354 | partial = false; |
|---|
| | 355 | } |
|---|
| | 356 | if (inclusive == null) { |
|---|
| | 357 | inclusive = true; |
|---|
| | 358 | } |
|---|
| | 359 | |
|---|
| | 360 | var inLeft; |
|---|
| | 361 | var inTop; |
|---|
| | 362 | var inRight; |
|---|
| | 363 | var inBottom; |
|---|
| | 364 | |
|---|
| | 365 | if (inclusive) { |
|---|
| | 366 | inLeft = (bounds.left >= this.left) && (bounds.left <= this.right); |
|---|
| | 367 | inTop = (bounds.top >= this.bottom) && (bounds.top <= this.top); |
|---|
| | 368 | inRight= (bounds.right >= this.left) && (bounds.right <= this.right); |
|---|
| | 369 | inBottom = (bounds.bottom >= this.bottom) && (bounds.bottom <= this.top); |
|---|
| | 370 | } else { |
|---|
| | 371 | inLeft = (bounds.left > this.left) && (bounds.left < this.right); |
|---|
| | 372 | inTop = (bounds.top > this.bottom) && (bounds.top < this.top); |
|---|
| | 373 | inRight= (bounds.right > this.left) && (bounds.right < this.right); |
|---|
| | 374 | inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top); |
|---|
| | 375 | } |
|---|
| | 376 | |
|---|
| | 377 | return (partial) ? (inTop || inBottom ) && (inLeft || inRight ) |
|---|
| | 378 | : (inTop && inLeft && inBottom && inRight); |
|---|
| | 379 | }, |
|---|
| | 380 | |
|---|
| | 381 | /** |
|---|
| | 382 | * APIMethod: determineQuadrant |
|---|
| | 383 | * |
|---|
| | 384 | * Parameters: |
|---|
| | 385 | * lonlat - {<OpenLayers.LonLat>} |
|---|
| | 386 | * |
|---|
| | 387 | * Return: |
|---|
| | 388 | * {String} The quadrant ("br" "tr" "tl" "bl") of the bounds in which |
|---|
| | 389 | * the coordinate lies. |
|---|
| | 390 | */ |
|---|
| | 391 | determineQuadrant: function(lonlat) { |
|---|
| | 392 | |
|---|
| | 393 | var quadrant = ""; |
|---|
| | 394 | var center = this.getCenterLonLat(); |
|---|
| | 395 | |
|---|
| | 396 | quadrant += (lonlat.lat < center.lat) ? "b" : "t"; |
|---|
| | 397 | quadrant += (lonlat.lon < center.lon) ? "l" : "r"; |
|---|
| | 398 | |
|---|
| | 399 | return quadrant; |
|---|
| | 400 | }, |
|---|
| | 401 | |
|---|
| | 402 | /** |
|---|
| | 403 | * APIMethod: wrapDateLine |
|---|
| | 404 | * |
|---|
| | 405 | * Parameters: |
|---|
| | 406 | * maxExtent - {<OpenLayers.Bounds>} |
|---|
| | 407 | * options - {Object} Some possible options are: |
|---|
| | 408 | * leftTolerance - {float} Allow for a margin of error |
|---|
| | 409 | * with the 'left' value of this |
|---|
| | 410 | * bound. |
|---|
| | 411 | * Default is 0. |
|---|
| | 412 | * rightTolerance - {float} Allow for a margin of error |
|---|
| | 413 | * with the 'right' value of |
|---|
| | 414 | * this bound. |
|---|
| | 415 | * Default is 0. |
|---|
| | 416 | * |
|---|
| | 417 | * Return: |
|---|
| | 418 | * {<OpenLayers.Bounds>} A copy of this bounds, but wrapped around the |
|---|
| | 419 | * "dateline" (as specified by the borders of |
|---|
| | 420 | * maxExtent). Note that this function only returns |
|---|
| | 421 | * a different bounds value if this bounds is |
|---|
| | 422 | * *entirely* outside of the maxExtent. If this |
|---|
| | 423 | * bounds straddles the dateline (is part in/part |
|---|
| | 424 | * out of maxExtent), the returned bounds will be |
|---|
| | 425 | * merely a copy of this one. |
|---|
| | 426 | */ |
|---|
| | 427 | wrapDateLine: function(maxExtent, options) { |
|---|
| | 428 | options = options || new Object(); |
|---|
| | 429 | |
|---|
| | 430 | var leftTolerance = options.leftTolerance || 0; |
|---|
| | 431 | var rightTolerance = options.rightTolerance || 0; |
|---|
| | 432 | |
|---|
| | 433 | var newBounds = this.clone(); |
|---|
| | 434 | |
|---|
| | 435 | if (maxExtent) { |
|---|
| | 436 | |
|---|
| | 437 | //shift right? |
|---|
| | 438 | while ( newBounds.left < maxExtent.left && |
|---|
| | 439 | (newBounds.right - rightTolerance) <= maxExtent.left ) { |
|---|
| | 440 | newBounds = newBounds.add(maxExtent.getWidth(), 0); |
|---|
| | 441 | } |
|---|
| | 442 | |
|---|
| | 443 | //shift left? |
|---|
| | 444 | while ( (newBounds.left + leftTolerance) >= maxExtent.right && |
|---|
| | 445 | newBounds.right > maxExtent.right ) { |
|---|
| | 446 | newBounds = newBounds.add(-maxExtent.getWidth(), 0); |
|---|
| | 447 | } |
|---|
| | 448 | } |
|---|
| | 449 | |
|---|
| | 450 | return newBounds; |
|---|
| | 451 | }, |
|---|
| | 452 | |
|---|
| | 453 | /** @final @type String */ |
|---|
| | 454 | CLASS_NAME: "OpenLayers.Bounds" |
|---|
| | 455 | }; |
|---|
| | 456 | |
|---|
| | 457 | /** |
|---|
| | 458 | * APIFunction: fromString |
|---|
| | 459 | * Alternative constructor that builds a new OpenLayers.Bounds from a |
|---|
| | 460 | * parameter string |
|---|
| | 461 | * |
|---|
| | 462 | * Parameters: |
|---|
| | 463 | * str - {String}Comma-separated bounds string. (ex. <i>"5,42,10,45"</i>) |
|---|
| | 464 | * |
|---|
| | 465 | * Return: |
|---|
| | 466 | * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the |
|---|
| | 467 | * passed-in String. |
|---|
| | 468 | */ |
|---|
| | 469 | OpenLayers.Bounds.fromString = function(str) { |
|---|
| | 470 | var bounds = str.split(","); |
|---|
| | 471 | return OpenLayers.Bounds.fromArray(bounds); |
|---|
| | 472 | }; |
|---|
| | 473 | |
|---|
| | 474 | /** |
|---|
| | 475 | * APIFunction: fromArray |
|---|
| | 476 | * Alternative constructor that builds a new OpenLayers.Bounds |
|---|
| | 477 | * from an array |
|---|
| | 478 | * |
|---|
| | 479 | * Parameters: |
|---|
| | 480 | * bbox - {Array} Array of bounds values (ex. <i>[5,42,10,45]</i>) |
|---|
| | 481 | * |
|---|
| | 482 | * Return: |
|---|
| | 483 | * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the |
|---|
| | 484 | * passed-in Array. |
|---|
| | 485 | */ |
|---|
| | 486 | OpenLayers.Bounds.fromArray = function(bbox) { |
|---|
| | 487 | return new OpenLayers.Bounds(parseFloat(bbox[0]), |
|---|
| | 488 | parseFloat(bbox[1]), |
|---|
| | 489 | parseFloat(bbox[2]), |
|---|
| | 490 | parseFloat(bbox[3])); |
|---|
| | 491 | }; |
|---|
| | 492 | |
|---|
| | 493 | /** |
|---|
| | 494 | * APIFunction: fromSize |
|---|
| | 495 | * Alternative constructor that builds a new OpenLayers.Bounds |
|---|
| | 496 | * from a size |
|---|
| | 497 | * |
|---|
| | 498 | * Parameters: |
|---|
| | 499 | * size - {<OpenLayers.Size>} |
|---|
| | 500 | * |
|---|
| | 501 | * Return: |
|---|
| | 502 | * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the |
|---|
| | 503 | * passed-in size. |
|---|
| | 504 | */ |
|---|
| | 505 | OpenLayers.Bounds.fromSize = function(size) { |
|---|
| | 506 | return new OpenLayers.Bounds(0, |
|---|
| | 507 | size.h, |
|---|
| | 508 | size.w, |
|---|
| | 509 | 0); |
|---|
| | 510 | }; |
|---|
| | 511 | |
|---|
| | 512 | /** |
|---|
| | 513 | * Function: oppositeQuadrant |
|---|
| | 514 | * Get the opposite quadrant for a given quadrant string. |
|---|
| | 515 | * |
|---|
| | 516 | * Parameters: |
|---|
| | 517 | * quadrant - {String} two character quadrant shortstring |
|---|
| | 518 | * |
|---|
| | 519 | * Return: |
|---|
| | 520 | * {String} The opposing quadrant ("br" "tr" "tl" "bl"). For Example, if |
|---|
| | 521 | * you pass in "bl" it returns "tr", if you pass in "br" it |
|---|
| | 522 | * returns "tl", etc. |
|---|
| | 523 | */ |
|---|
| | 524 | OpenLayers.Bounds.oppositeQuadrant = function(quadrant) { |
|---|
| | 525 | var opp = ""; |
|---|
| | 526 | |
|---|
| | 527 | opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; |
|---|
| | 528 | opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; |
|---|
| | 529 | |
|---|
| | 530 | return opp; |
|---|
| | 531 | }; |