[OpenLayers-Commits] r2320 - sandbox/vector-2.4/lib/OpenLayers

commits at openlayers.org commits at openlayers.org
Mon Mar 5 12:33:59 EST 2007


Author: crschmidt
Date: 2007-03-05 12:33:56 -0500 (Mon, 05 Mar 2007)
New Revision: 2320

Modified:
   sandbox/vector-2.4/lib/OpenLayers/BaseTypes.js
Log:
Merge in vector branch BaseTypes: extendBounds function now takes one of a
number of geometry types, rather than four parameters, and extends the bounds
to include them.


Modified: sandbox/vector-2.4/lib/OpenLayers/BaseTypes.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/BaseTypes.js	2007-03-05 17:32:55 UTC (rev 2319)
+++ sandbox/vector-2.4/lib/OpenLayers/BaseTypes.js	2007-03-05 17:33:56 UTC (rev 2320)
@@ -388,7 +388,7 @@
     *         (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>)
     * @type String
     */
-    toString:function(){
+    toString:function() {
         return ( "left-bottom=(" + this.left + "," + this.bottom + ")"
                  + " right-top=(" + this.right + "," + this.top + ")" );
     },
@@ -464,10 +464,38 @@
     *          but shifted by the passed-in x and y values
     * @type OpenLayers.Bounds
     */
-    add:function(x, y){
+    add:function(x, y) {
         return new OpenLayers.Bounds(this.left + x, this.bottom + y,
                                      this.right + x, this.top + y);
     },
+    
+    /**
+     * Extend the bounds to include the box specificated.
+     * Can be used to extend the bounds to a point as well
+     * using extendBounds(x,y).
+     * This function assumes that left<right and bottom<top.
+     * @param {OpenLayers.LonLat} 
+     */
+    extendBounds:function(geometry){
+        switch(geometry.CLASS_NAME) {
+            case "OpenLayers.Geometry.Point":
+            case "OpenLayers.LonLat":    
+                var left = geometry.lon;
+                var bottom = geometry.lat;
+                this.left = (left < this.left) ? left : this.left;
+                this.bottom = (bottom < this.bottom) ? bottom : this.bottom;
+                this.right = (left > this.right) ? left : this.right;
+                this.top = (bottom > this.top) ? bottom : this.top;
+                break;    
+            case "OpenLayers.Bounds":    
+               this.left = (geometry.left < this.left) ? geometry.left : this.left;
+               this.bottom = (geometry.bottom < this.bottom) ? bottom : this.bottom;
+               this.right = (geometry.right > this.right) ? geometry.right : this.right;
+               this.top = (geometry.top > this.top) ? top : this.top;
+               break;
+               
+        }
+    },
 
     /**
      * @param {OpenLayers.LonLat} ll
@@ -781,7 +809,7 @@
 * @returns Whether or not this string starts with the string passed in.
 * @type Boolean
 */
-String.prototype.startsWith = function(sStart){
+String.prototype.startsWith = function(sStart) {
     return (this.substr(0,sStart.length) == sStart);
 };
 
@@ -791,7 +819,7 @@
 * @returns Whether or not this string contains with the string passed in.
 * @type Boolean
 */
-String.prototype.contains = function(str){
+String.prototype.contains = function(str) {
     return (this.indexOf(str) != -1);
 };
 



More information about the Commits mailing list