~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/BaseTypes/Bounds.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
 
2
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 
3
 * 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. All values are initialized to null, however,
 
9
 * you should make sure you set them before using the bounds for anything.
 
10
 * 
 
11
 * Possible use case:
 
12
 * > bounds = new OpenLayers.Bounds();
 
13
 * > bounds.extend(new OpenLayers.LonLat(4,5));
 
14
 * > bounds.extend(new OpenLayers.LonLat(5,6));
 
15
 * > bounds.toBBOX(); // returns 4,5,5,6
 
16
 */
 
17
OpenLayers.Bounds = OpenLayers.Class({
 
18
 
 
19
    /**
 
20
     * Property: left
 
21
     * {Number} Minimum horizontal coordinate.
 
22
     */
 
23
    left: null,
 
24
 
 
25
    /**
 
26
     * Property: bottom
 
27
     * {Number} Minimum vertical coordinate.
 
28
     */
 
29
    bottom: null,
 
30
 
 
31
    /**
 
32
     * Property: right
 
33
     * {Number} Maximum horizontal coordinate.
 
34
     */
 
35
    right: null,
 
36
 
 
37
    /**
 
38
     * Property: top
 
39
     * {Number} Maximum vertical coordinate.
 
40
     */
 
41
    top: null,
 
42
    
 
43
    /**
 
44
     * Property: centerLonLat
 
45
     * {<OpenLayers.LonLat>} A cached center location.  This should not be
 
46
     *     accessed directly.  Use <getCenterLonLat> instead.
 
47
     */
 
48
    centerLonLat: null,
 
49
 
 
50
    /**
 
51
     * Constructor: OpenLayers.Bounds
 
52
     * Construct a new bounds object.
 
53
     *
 
54
     * Parameters:
 
55
     * left - {Number} The left bounds of the box.  Note that for width
 
56
     *        calculations, this is assumed to be less than the right value.
 
57
     * bottom - {Number} The bottom bounds of the box.  Note that for height
 
58
     *          calculations, this is assumed to be more than the top value.
 
59
     * right - {Number} The right bounds.
 
60
     * top - {Number} The top bounds.
 
61
     */
 
62
    initialize: function(left, bottom, right, top) {
 
63
        if (left != null) {
 
64
            this.left = parseFloat(left);
 
65
        }
 
66
        if (bottom != null) {
 
67
            this.bottom = parseFloat(bottom);
 
68
        }
 
69
        if (right != null) {
 
70
            this.right = parseFloat(right);
 
71
        }
 
72
        if (top != null) {
 
73
            this.top = parseFloat(top);
 
74
        }
 
75
    },
 
76
 
 
77
    /**
 
78
     * Method: clone
 
79
     * Create a cloned instance of this bounds.
 
80
     *
 
81
     * Returns:
 
82
     * {<OpenLayers.Bounds>} A fresh copy of the bounds
 
83
     */
 
84
    clone:function() {
 
85
        return new OpenLayers.Bounds(this.left, this.bottom, 
 
86
                                     this.right, this.top);
 
87
    },
 
88
 
 
89
    /**
 
90
     * Method: equals
 
91
     * Test a two bounds for equivalence.
 
92
     *
 
93
     * Parameters:
 
94
     * bounds - {<OpenLayers.Bounds>}
 
95
     *
 
96
     * Returns:
 
97
     * {Boolean} The passed-in bounds object has the same left,
 
98
     *           right, top, bottom components as this.  Note that if bounds 
 
99
     *           passed in is null, returns false.
 
100
     */
 
101
    equals:function(bounds) {
 
102
        var equals = false;
 
103
        if (bounds != null) {
 
104
            equals = ((this.left == bounds.left) && 
 
105
                      (this.right == bounds.right) &&
 
106
                      (this.top == bounds.top) && 
 
107
                      (this.bottom == bounds.bottom));
 
108
        }
 
109
        return equals;
 
110
    },
 
111
 
 
112
    /** 
 
113
     * APIMethod: toString
 
114
     * 
 
115
     * Returns:
 
116
     * {String} String representation of bounds object. 
 
117
     *          (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>)
 
118
     */
 
119
    toString:function() {
 
120
        return ( "left-bottom=(" + this.left + "," + this.bottom + ")"
 
121
                 + " right-top=(" + this.right + "," + this.top + ")" );
 
122
    },
 
123
 
 
124
    /**
 
125
     * APIMethod: toArray
 
126
     *
 
127
     * Returns:
 
128
     * {Array} array of left, bottom, right, top
 
129
     */
 
130
    toArray: function() {
 
131
        return [this.left, this.bottom, this.right, this.top];
 
132
    },    
 
133
 
 
134
    /** 
 
135
     * APIMethod: toBBOX
 
136
     * 
 
137
     * Parameters:
 
138
     * decimal - {Integer} How many significant digits in the bbox coords?
 
139
     *                     Default is 6
 
140
     * 
 
141
     * Returns:
 
142
     * {String} Simple String representation of bounds object.
 
143
     *          (ex. <i>"5,42,10,45"</i>)
 
144
     */
 
145
    toBBOX:function(decimal) {
 
146
        if (decimal== null) {
 
147
            decimal = 6; 
 
148
        }
 
149
        var mult = Math.pow(10, decimal);
 
150
        var bbox = Math.round(this.left * mult) / mult + "," + 
 
151
                   Math.round(this.bottom * mult) / mult + "," + 
 
152
                   Math.round(this.right * mult) / mult + "," + 
 
153
                   Math.round(this.top * mult) / mult;
 
154
 
 
155
        return bbox;
 
156
    },
 
157
    
 
158
    /**
 
159
     * APIMethod: toGeometry
 
160
     * Create a new polygon geometry based on this bounds.
 
161
     *
 
162
     * Returns:
 
163
     * {<OpenLayers.Geometry.Polygon>} A new polygon with the coordinates
 
164
     *     of this bounds.
 
165
     */
 
166
    toGeometry: function() {
 
167
        return new OpenLayers.Geometry.Polygon([
 
168
            new OpenLayers.Geometry.LinearRing([
 
169
                new OpenLayers.Geometry.Point(this.left, this.bottom),
 
170
                new OpenLayers.Geometry.Point(this.right, this.bottom),
 
171
                new OpenLayers.Geometry.Point(this.right, this.top),
 
172
                new OpenLayers.Geometry.Point(this.left, this.top)
 
173
            ])
 
174
        ]);
 
175
    },
 
176
    
 
177
    /**
 
178
     * APIMethod: getWidth
 
179
     * 
 
180
     * Returns:
 
181
     * {Float} The width of the bounds
 
182
     */
 
183
    getWidth:function() {
 
184
        return (this.right - this.left);
 
185
    },
 
186
 
 
187
    /**
 
188
     * APIMethod: getHeight
 
189
     * 
 
190
     * Returns:
 
191
     * {Float} The height of the bounds (top minus bottom).
 
192
     */
 
193
    getHeight:function() {
 
194
        return (this.top - this.bottom);
 
195
    },
 
196
 
 
197
    /**
 
198
     * APIMethod: getSize
 
199
     * 
 
200
     * Returns:
 
201
     * {<OpenLayers.Size>} The size of the box.
 
202
     */
 
203
    getSize:function() {
 
204
        return new OpenLayers.Size(this.getWidth(), this.getHeight());
 
205
    },
 
206
 
 
207
    /**
 
208
     * APIMethod: getCenterPixel
 
209
     * 
 
210
     * Returns:
 
211
     * {<OpenLayers.Pixel>} The center of the bounds in pixel space.
 
212
     */
 
213
    getCenterPixel:function() {
 
214
        return new OpenLayers.Pixel( (this.left + this.right) / 2,
 
215
                                     (this.bottom + this.top) / 2);
 
216
    },
 
217
 
 
218
    /**
 
219
     * APIMethod: getCenterLonLat
 
220
     * 
 
221
     * Returns:
 
222
     * {<OpenLayers.LonLat>} The center of the bounds in map space.
 
223
     */
 
224
    getCenterLonLat:function() {
 
225
        if(!this.centerLonLat) {
 
226
            this.centerLonLat = new OpenLayers.LonLat(
 
227
                (this.left + this.right) / 2, (this.bottom + this.top) / 2
 
228
            );
 
229
        }
 
230
        return this.centerLonLat;
 
231
    },
 
232
 
 
233
    /**
 
234
     * Method: scale
 
235
     * Scales the bounds around a pixel or lonlat. Note that the new 
 
236
     *     bounds may return non-integer properties, even if a pixel
 
237
     *     is passed. 
 
238
     * 
 
239
     * Parameters:
 
240
     * ratio - {Float} 
 
241
     * origin - {<OpenLayers.Pixel> or <OpenLayers.LonLat>}
 
242
     *          Default is center.
 
243
     *
 
244
     * Returns:
 
245
     * {<OpenLayers.Bound>} A new bounds that is scaled by ratio
 
246
     *                      from origin.
 
247
     */
 
248
 
 
249
    scale: function(ratio, origin){
 
250
        if(origin == null){
 
251
            origin = this.getCenterLonLat();
 
252
        }
 
253
 
 
254
        var bounds = [];
 
255
        
 
256
        var origx,origy;
 
257
 
 
258
        // get origin coordinates
 
259
        if(origin.CLASS_NAME == "OpenLayers.LonLat"){
 
260
            origx = origin.lon;
 
261
            origy = origin.lat;
 
262
        } else {
 
263
            origx = origin.x;
 
264
            origy = origin.y;
 
265
        }
 
266
 
 
267
        var left = (this.left - origx) * ratio + origx;
 
268
        var bottom = (this.bottom - origy) * ratio + origy;
 
269
        var right = (this.right - origx) * ratio + origx;
 
270
        var top = (this.top - origy) * ratio + origy;
 
271
        
 
272
        return new OpenLayers.Bounds(left, bottom, right, top);
 
273
    },
 
274
 
 
275
    /**
 
276
     * APIMethod: add
 
277
     * 
 
278
     * Parameters:
 
279
     * x - {Float}
 
280
     * y - {Float}
 
281
     * 
 
282
     * Returns:
 
283
     * {<OpenLayers.Bounds>} A new bounds whose coordinates are the same as
 
284
     *     this, but shifted by the passed-in x and y values.
 
285
     */
 
286
    add:function(x, y) {
 
287
        if ( (x == null) || (y == null) ) {
 
288
            var msg = OpenLayers.i18n("boundsAddError");
 
289
            OpenLayers.Console.error(msg);
 
290
            return null;
 
291
        }
 
292
        return new OpenLayers.Bounds(this.left + x, this.bottom + y,
 
293
                                     this.right + x, this.top + y);
 
294
    },
 
295
    
 
296
    /**
 
297
     * APIMethod: extend
 
298
     * Extend the bounds to include the point, lonlat, or bounds specified.
 
299
     *     Note, this function assumes that left < right and bottom < top.
 
300
     * 
 
301
     * Parameters: 
 
302
     * object - {Object} Can be LonLat, Point, or Bounds
 
303
     */
 
304
    extend:function(object) {
 
305
        var bounds = null;
 
306
        if (object) {
 
307
            // clear cached center location
 
308
            switch(object.CLASS_NAME) {
 
309
                case "OpenLayers.LonLat":    
 
310
                    bounds = new OpenLayers.Bounds(object.lon, object.lat,
 
311
                                                    object.lon, object.lat);
 
312
                    break;
 
313
                case "OpenLayers.Geometry.Point":
 
314
                    bounds = new OpenLayers.Bounds(object.x, object.y,
 
315
                                                    object.x, object.y);
 
316
                    break;
 
317
                    
 
318
                case "OpenLayers.Bounds":    
 
319
                    bounds = object;
 
320
                    break;
 
321
            }
 
322
    
 
323
            if (bounds) {
 
324
                this.centerLonLat = null;
 
325
                if ( (this.left == null) || (bounds.left < this.left)) {
 
326
                    this.left = bounds.left;
 
327
                }
 
328
                if ( (this.bottom == null) || (bounds.bottom < this.bottom) ) {
 
329
                    this.bottom = bounds.bottom;
 
330
                } 
 
331
                if ( (this.right == null) || (bounds.right > this.right) ) {
 
332
                    this.right = bounds.right;
 
333
                }
 
334
                if ( (this.top == null) || (bounds.top > this.top) ) { 
 
335
                    this.top = bounds.top;
 
336
                }
 
337
            }
 
338
        }
 
339
    },
 
340
 
 
341
    /**
 
342
     * APIMethod: containsLonLat
 
343
     * 
 
344
     * Parameters:
 
345
     * ll - {<OpenLayers.LonLat>}
 
346
     * inclusive - {Boolean} Whether or not to include the border.
 
347
     *     Default is true.
 
348
     *
 
349
     * Returns:
 
350
     * {Boolean} The passed-in lonlat is within this bounds.
 
351
     */
 
352
    containsLonLat:function(ll, inclusive) {
 
353
        return this.contains(ll.lon, ll.lat, inclusive);
 
354
    },
 
355
 
 
356
    /**
 
357
     * APIMethod: containsPixel
 
358
     * 
 
359
     * Parameters:
 
360
     * px - {<OpenLayers.Pixel>}
 
361
     * inclusive - {Boolean} Whether or not to include the border. Default is
 
362
     *     true.
 
363
     *
 
364
     * Returns:
 
365
     * {Boolean} The passed-in pixel is within this bounds.
 
366
     */
 
367
    containsPixel:function(px, inclusive) {
 
368
        return this.contains(px.x, px.y, inclusive);
 
369
    },
 
370
    
 
371
    /**
 
372
     * APIMethod: contains
 
373
     * 
 
374
     * Parameters:
 
375
     * x - {Float}
 
376
     * y - {Float}
 
377
     * inclusive - {Boolean} Whether or not to include the border. Default is
 
378
     *     true.
 
379
     *
 
380
     * Returns:
 
381
     * {Boolean} Whether or not the passed-in coordinates are within this
 
382
     *     bounds.
 
383
     */
 
384
    contains:function(x, y, inclusive) {
 
385
    
 
386
        //set default
 
387
        if (inclusive == null) {
 
388
            inclusive = true;
 
389
        }
 
390
        
 
391
        var contains = false;
 
392
        if (inclusive) {
 
393
            contains = ((x >= this.left) && (x <= this.right) && 
 
394
                        (y >= this.bottom) && (y <= this.top));
 
395
        } else {
 
396
            contains = ((x > this.left) && (x < this.right) && 
 
397
                        (y > this.bottom) && (y < this.top));
 
398
        }              
 
399
        return contains;
 
400
    },
 
401
 
 
402
    /**
 
403
     * APIMethod: intersectsBounds
 
404
     * 
 
405
     * Parameters:
 
406
     * bounds - {<OpenLayers.Bounds>}
 
407
     * inclusive - {Boolean} Whether or not to include the border.  Default
 
408
     *     is true.
 
409
     *
 
410
     * Returns:
 
411
     * {Boolean} The passed-in OpenLayers.Bounds object intersects this bounds.
 
412
     *     Simple math just check if either contains the other, allowing for
 
413
     *     partial.
 
414
     */
 
415
    intersectsBounds:function(bounds, inclusive) {
 
416
 
 
417
        if (inclusive == null) {
 
418
            inclusive = true;
 
419
        }
 
420
        var inBottom = (bounds.bottom == this.bottom && bounds.top == this.top) ?
 
421
                    true : (((bounds.bottom > this.bottom) && (bounds.bottom < this.top)) || 
 
422
                           ((this.bottom > bounds.bottom) && (this.bottom < bounds.top))); 
 
423
        var inTop = (bounds.bottom == this.bottom && bounds.top == this.top) ?
 
424
                    true : (((bounds.top > this.bottom) && (bounds.top < this.top)) ||
 
425
                           ((this.top > bounds.bottom) && (this.top < bounds.top))); 
 
426
        var inRight = (bounds.right == this.right && bounds.left == this.left) ?
 
427
                    true : (((bounds.right > this.left) && (bounds.right < this.right)) ||
 
428
                           ((this.right > bounds.left) && (this.right < bounds.right))); 
 
429
        var inLeft = (bounds.right == this.right && bounds.left == this.left) ?
 
430
                    true : (((bounds.left > this.left) && (bounds.left < this.right)) || 
 
431
                           ((this.left > bounds.left) && (this.left < bounds.right))); 
 
432
 
 
433
        return (this.containsBounds(bounds, true, inclusive) ||
 
434
                bounds.containsBounds(this, true, inclusive) ||
 
435
                ((inTop || inBottom ) && (inLeft || inRight )));
 
436
    },
 
437
    
 
438
    /**
 
439
     * APIMethod: containsBounds
 
440
     * 
 
441
     * bounds - {<OpenLayers.Bounds>}
 
442
     * partial - {Boolean} If true, only part of passed-in bounds needs be
 
443
     *     within this bounds.  If false, the entire passed-in bounds must be
 
444
     *     within. Default is false
 
445
     * inclusive - {Boolean} Whether or not to include the border. Default is
 
446
     *     true.
 
447
     *
 
448
     * Returns:
 
449
     * {Boolean} The passed-in bounds object is contained within this bounds. 
 
450
     */
 
451
    containsBounds:function(bounds, partial, inclusive) {
 
452
 
 
453
        //set defaults
 
454
        if (partial == null) {
 
455
            partial = false;
 
456
        }
 
457
        if (inclusive == null) {
 
458
            inclusive = true;
 
459
        }
 
460
 
 
461
        var inLeft;
 
462
        var inTop;
 
463
        var inRight;
 
464
        var inBottom;
 
465
        
 
466
        if (inclusive) {
 
467
            inLeft = (bounds.left >= this.left) && (bounds.left <= this.right);
 
468
            inTop = (bounds.top >= this.bottom) && (bounds.top <= this.top);
 
469
            inRight= (bounds.right >= this.left) && (bounds.right <= this.right);
 
470
            inBottom = (bounds.bottom >= this.bottom) && (bounds.bottom <= this.top);
 
471
        } else {
 
472
            inLeft = (bounds.left > this.left) && (bounds.left < this.right);
 
473
            inTop = (bounds.top > this.bottom) && (bounds.top < this.top);
 
474
            inRight= (bounds.right > this.left) && (bounds.right < this.right);
 
475
            inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top);
 
476
        }
 
477
        
 
478
        return (partial) ? (inTop || inBottom ) && (inLeft || inRight ) 
 
479
                         : (inTop && inLeft && inBottom && inRight);
 
480
    },
 
481
 
 
482
    /** 
 
483
     * APIMethod: determineQuadrant
 
484
     * 
 
485
     * Parameters:
 
486
     * lonlat - {<OpenLayers.LonLat>}
 
487
     * 
 
488
     * Returns:
 
489
     * {String} The quadrant ("br" "tr" "tl" "bl") of the bounds in which the
 
490
     *     coordinate lies.
 
491
     */
 
492
    determineQuadrant: function(lonlat) {
 
493
    
 
494
        var quadrant = "";
 
495
        var center = this.getCenterLonLat();
 
496
        
 
497
        quadrant += (lonlat.lat < center.lat) ? "b" : "t";
 
498
        quadrant += (lonlat.lon < center.lon) ? "l" : "r";
 
499
    
 
500
        return quadrant; 
 
501
    },
 
502
    
 
503
    /**
 
504
     * APIMethod: transform
 
505
     * Transform the Bounds object from source to dest. 
 
506
     *
 
507
     * Parameters: 
 
508
     * source - {<OpenLayers.Projection>} Source projection. 
 
509
     * dest   - {<OpenLayers.Projection>} Destination projection. 
 
510
     *
 
511
     * Returns:
 
512
     * {<OpenLayers.Bounds>} Itself, for use in chaining operations.
 
513
     */
 
514
    transform: function(source, dest) {
 
515
        // clear cached center location
 
516
        this.centerLonLat = null;
 
517
        var ll = OpenLayers.Projection.transform(
 
518
            {'x': this.left, 'y': this.bottom}, source, dest);
 
519
        var lr = OpenLayers.Projection.transform(
 
520
            {'x': this.right, 'y': this.bottom}, source, dest);
 
521
        var ul = OpenLayers.Projection.transform(
 
522
            {'x': this.left, 'y': this.top}, source, dest);
 
523
        var ur = OpenLayers.Projection.transform(
 
524
            {'x': this.right, 'y': this.top}, source, dest);
 
525
        this.left   = Math.min(ll.x, ul.x);
 
526
        this.bottom = Math.min(ll.y, lr.y);
 
527
        this.right  = Math.max(lr.x, ur.x);
 
528
        this.top    = Math.max(ul.y, ur.y);
 
529
        return this;
 
530
    },
 
531
 
 
532
    /**
 
533
     * APIMethod: wrapDateLine
 
534
     *  
 
535
     * Parameters:
 
536
     * maxExtent - {<OpenLayers.Bounds>}
 
537
     * options - {Object} Some possible options are:
 
538
     *                    leftTolerance - {float} Allow for a margin of error 
 
539
     *                                            with the 'left' value of this 
 
540
     *                                            bound.
 
541
     *                                            Default is 0.
 
542
     *                    rightTolerance - {float} Allow for a margin of error 
 
543
     *                                             with the 'right' value of 
 
544
     *                                             this bound.
 
545
     *                                             Default is 0.
 
546
     * 
 
547
     * Returns:
 
548
     * {<OpenLayers.Bounds>} A copy of this bounds, but wrapped around the 
 
549
     *                       "dateline" (as specified by the borders of 
 
550
     *                       maxExtent). Note that this function only returns 
 
551
     *                       a different bounds value if this bounds is 
 
552
     *                       *entirely* outside of the maxExtent. If this 
 
553
     *                       bounds straddles the dateline (is part in/part 
 
554
     *                       out of maxExtent), the returned bounds will be 
 
555
     *                       merely a copy of this one.
 
556
     */
 
557
    wrapDateLine: function(maxExtent, options) {    
 
558
        options = options || {};
 
559
        
 
560
        var leftTolerance = options.leftTolerance || 0;
 
561
        var rightTolerance = options.rightTolerance || 0;
 
562
 
 
563
        var newBounds = this.clone();
 
564
    
 
565
        if (maxExtent) {
 
566
 
 
567
           //shift right?
 
568
           while ( newBounds.left < maxExtent.left && 
 
569
                   (newBounds.right - rightTolerance) <= maxExtent.left ) { 
 
570
                newBounds = newBounds.add(maxExtent.getWidth(), 0);
 
571
           }
 
572
 
 
573
           //shift left?
 
574
           while ( (newBounds.left + leftTolerance) >= maxExtent.right && 
 
575
                   newBounds.right > maxExtent.right ) { 
 
576
                newBounds = newBounds.add(-maxExtent.getWidth(), 0);
 
577
           }
 
578
        }
 
579
                
 
580
        return newBounds;
 
581
    },
 
582
 
 
583
    CLASS_NAME: "OpenLayers.Bounds"
 
584
});
 
585
 
 
586
/** 
 
587
 * APIFunction: fromString
 
588
 * Alternative constructor that builds a new OpenLayers.Bounds from a 
 
589
 *     parameter string
 
590
 * 
 
591
 * Parameters: 
 
592
 * str - {String}Comma-separated bounds string. (ex. <i>"5,42,10,45"</i>)
 
593
 * 
 
594
 * Returns:
 
595
 * {<OpenLayers.Bounds>} New bounds object built from the 
 
596
 *                       passed-in String.
 
597
 */
 
598
OpenLayers.Bounds.fromString = function(str) {
 
599
    var bounds = str.split(",");
 
600
    return OpenLayers.Bounds.fromArray(bounds);
 
601
};
 
602
 
 
603
/** 
 
604
 * APIFunction: fromArray
 
605
 * Alternative constructor that builds a new OpenLayers.Bounds
 
606
 *     from an array
 
607
 * 
 
608
 * Parameters:
 
609
 * bbox - {Array(Float)} Array of bounds values (ex. <i>[5,42,10,45]</i>)
 
610
 *
 
611
 * Returns:
 
612
 * {<OpenLayers.Bounds>} New bounds object built from the passed-in Array.
 
613
 */
 
614
OpenLayers.Bounds.fromArray = function(bbox) {
 
615
    return new OpenLayers.Bounds(parseFloat(bbox[0]),
 
616
                                 parseFloat(bbox[1]),
 
617
                                 parseFloat(bbox[2]),
 
618
                                 parseFloat(bbox[3]));
 
619
};
 
620
 
 
621
/** 
 
622
 * APIFunction: fromSize
 
623
 * Alternative constructor that builds a new OpenLayers.Bounds
 
624
 *     from a size
 
625
 * 
 
626
 * Parameters:
 
627
 * size - {<OpenLayers.Size>} 
 
628
 *
 
629
 * Returns:
 
630
 * {<OpenLayers.Bounds>} New bounds object built from the passed-in size.
 
631
 */
 
632
OpenLayers.Bounds.fromSize = function(size) {
 
633
    return new OpenLayers.Bounds(0,
 
634
                                 size.h,
 
635
                                 size.w,
 
636
                                 0);
 
637
};
 
638
 
 
639
/**
 
640
 * Function: oppositeQuadrant
 
641
 * Get the opposite quadrant for a given quadrant string.
 
642
 *
 
643
 * Parameters:
 
644
 * quadrant - {String} two character quadrant shortstring
 
645
 *
 
646
 * Returns:
 
647
 * {String} The opposing quadrant ("br" "tr" "tl" "bl"). For Example, if 
 
648
 *          you pass in "bl" it returns "tr", if you pass in "br" it 
 
649
 *          returns "tl", etc.
 
650
 */
 
651
OpenLayers.Bounds.oppositeQuadrant = function(quadrant) {
 
652
    var opp = "";
 
653
    
 
654
    opp += (quadrant.charAt(0) == 't') ? 'b' : 't';
 
655
    opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l';
 
656
    
 
657
    return opp;
 
658
};