OpenLayers OpenLayers

Ticket #571: no_more_lonlat.2.patch

File no_more_lonlat.2.patch, 11.2 kB (added by crschmidt, 2 years ago)
  • tests/Geometry/test_Curve.html

    old new  
    9696        t.eq( curve.components.length, 4, "new point added to array" ); 
    9797        t.eq( bounds.bottom, -30, "bottom bound is -30 after 2nd addComponent" ); 
    9898        t.eq( bounds.left, -20, "left bound is 20 after 2nd addComponent" ); 
    99         t.eq( curve.components[1].lon, -20,  "new point.lon is -20 (index worked)" ); 
    100         t.eq( curve.components[1].lat, -30,  "new point.lat is -30 (index worked)" ); 
     99        t.eq( curve.components[1].x, -20,  "new point.lon is -20 (index worked)" ); 
     100        t.eq( curve.components[1].y, -30,  "new point.lat is -30 (index worked)" ); 
    101101    } 
    102102 
    103103    function test_05_Curve_removeComponent (t) { 
  • tests/Geometry/test_MultiPoint.html

    old new  
    2121    } 
    2222 
    2323    function test_02_MultiPoint_move(t) { 
    24         t.plan(4); 
     24        t.plan(2); 
    2525         
    2626        var multipoint = new OpenLayers.Geometry.MultiPoint([point]); 
    2727        var x = point.x; 
     
    3232        multipoint.move(dx, dy); 
    3333        t.eq(multipoint.components[0].x, x + dx, "move() correctly modifies x"); 
    3434        t.eq(multipoint.components[0].y, y + dy, "move() correctly modifies y"); 
    35         t.eq(multipoint.components[0].lon, x + dx, "move() correctly modifies lon"); 
    36         t.eq(multipoint.components[0].lat, y + dy, "move() correctly modifies lat"); 
    3735    } 
    3836 
    3937    function test_MultiPoint_equals(t) { 
  • tests/Geometry/test_Point.html

    old new  
    2020        t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly"); 
    2121        t.eq( point.x, x, "point.x is set correctly"); 
    2222        t.eq( point.y, y, "point.y is set correctly"); 
    23         t.eq( point.lon, x, "point.lon is set correctly"); 
    24         t.eq( point.lat, y, "point.lat is set correctly"); 
     23        t.eq( point.lon, null, "point.lon is not set"); 
     24        t.eq( point.lat, null, "point.lat is not set"); 
    2525    } 
    2626 
    27     function test_02_Point_accessors(t) { 
    28         t.plan( 6 ) 
    29                  
    30       //valid 
    31         var x = 10; 
    32         var y = 20; 
    33         point = new OpenLayers.Geometry.Point(x, y); 
    34  
    35         t.eq( point.getX(), x, "point.x is get() correctly"); 
    36         t.eq( point.getY(), y, "point.y is get() correctly"); 
    37  
    38         var x1 = 55; 
    39         var y1 = 73; 
    40          
    41         point.setX(x1); 
    42         point.setY(y1); 
    43          
    44         t.eq( point.x, x1, "point.x is set() correctly"); 
    45         t.eq( point.y, y1, "point.y is set() correctly"); 
    46         t.eq( point.lon, x1, "point.lon is set() correctly"); 
    47         t.eq( point.lat, y1, "point.lat is set() correctly"); 
    48  
    49     } 
    50      
    5127    function test_03_Point_calculateBounds (t) { 
    5228        t.plan(4); 
    5329 
     
    8965    } 
    9066     
    9167    function test_06_Point_move(t) { 
    92         t.plan(4); 
     68        t.plan(2); 
    9369         
    9470        var x = 10; 
    9571        var y = 20; 
     
    10076        point.move(dx, dy); 
    10177        t.eq(point.x, x + dx, "move() correctly modifies x"); 
    10278        t.eq(point.y, y + dy, "move() correctly modifies y"); 
    103         t.eq(point.lon, x + dx, "move() correctly modifies lon"); 
    104         t.eq(point.lat, y + dy, "move() correctly modifies lat"); 
    10579    } 
    10680 
    10781    function test_Point_equals(t) { 
  • tests/BaseTypes/test_Bounds.html

    old new  
    361361         
    362362        bounds.extend(object); 
    363363                
    364         t.ok( ((bounds.left == object.lon) && 
    365                (bounds.bottom == object.lat) && 
     364        t.ok( ((bounds.left == object.x) && 
     365               (bounds.bottom == object.y) && 
    366366               (bounds.right == originalBounds.right) && 
    367367               (bounds.top == originalBounds.top)), "obj Point to extends correclty modifies left and bottom"); 
    368368               
     
    375375 
    376376        t.ok( ((bounds.left == originalBounds.left) && 
    377377               (bounds.bottom == originalBounds.bottom) && 
    378                (bounds.right == object.lon) && 
    379                (bounds.top == object.lat)), "obj Point to extends correclty modifies right and top"); 
     378               (bounds.right == object.x) && 
     379               (bounds.top == object.y)), "obj Point to extends correclty modifies right and top"); 
    380380 
    381381     } 
    382382 
  • lib/OpenLayers/Geometry/Point.js

    old new  
    44 
    55/** 
    66 * @class 
    7  * 
    8  * The Point class is a subclass of Geometry and also a subclass of the 
    9  * non-vector OpenLayers.LonLat class. The basic functionality that this adds 
    10  * is the ability to switch between lon/lat and x/y at will, as well some  
    11  * convenience functions to create a Bounds from a point and measure the  
    12  * distance between two points.  
    137 *  
    14  * getX() and setX() should be used to access the x or lon variables. 
    15  *  
    16  * @requires OpenLayers/BaseTypes.js 
    178 * @requires OpenLayers/Geometry.js 
    189 */ 
    1910OpenLayers.Geometry.Point = OpenLayers.Class.create(); 
    2011OpenLayers.Geometry.Point.prototype = 
    21     OpenLayers.Class.inherit(OpenLayers.Geometry, OpenLayers.LonLat,
     12    OpenLayers.Class.inherit(OpenLayers.Geometry,
    2213 
    2314    /** @type float */ 
    2415    x: null, 
     
    3425     */ 
    3526    initialize: function(x, y) { 
    3627        OpenLayers.Geometry.prototype.initialize.apply(this, arguments); 
    37         OpenLayers.LonLat.prototype.initialize.apply(this, arguments); 
    3828         
    39         this.x = this.lon
    40         this.y = this.lat
     29        this.x = parseFloat(x)
     30        this.y = parseFloat(y)
    4131    }, 
    4232 
    4333    /** 
     
    5545        return obj; 
    5646    }, 
    5747 
    58     /** 
    59      * Sets the x coordinate 
    60      * 
    61      * @param {float} x 
    62      */ 
    63     setX: function(x) { 
    64         this.lon = x; 
    65         this.x = x; 
    66     }, 
    67  
    68     /** 
    69      * Sets the y coordinate 
    70      * 
    71      * @param {float} y 
    72      */ 
    73     setY: function(y) { 
    74         this.lat = y; 
    75         this.y = y; 
    76     }, 
    77  
    78     /** 
    79      * @type float 
    80      */ 
    81     getX: function() { 
    82        return this.lon; 
    83     }, 
    84  
    85     /** 
    86      * @type float 
    87      */ 
    88     getY: function() { 
    89        return this.lat; 
    90     }, 
    91  
    9248    /** Create a new Bounds based on the lon/lat 
    9349     *  
    9450     */ 
    9551    calculateBounds: function () { 
    96         this.bounds = new OpenLayers.Bounds(this.lon, this.lat
    97                                             this.lon, this.lat); 
     52        this.bounds = new OpenLayers.Bounds(this.x, this.y
     53                                            this.x, this.y); 
    9854    }, 
    9955 
    10056    /** 
     
    11167        } 
    11268        return distance; 
    11369    }, 
     70     
     71    /**  
     72    * @param {OpenLayers.Geometry} xy 
     73    * @returns Boolean value indicating whether the passed-in  
     74    *          OpenLayers.Geometryobject has the same  components as this 
     75    *          note that if ll passed in is null, returns false 
     76    * 
     77    * @type bool 
     78    */ 
     79    equals:function(geom) { 
     80        var equals = false; 
     81        if (geom != null) { 
     82            equals = ((this.x == geom.x && this.y == geom.y) || 
     83                      (isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y))); 
     84        } 
     85        return equals; 
     86    }, 
    11487 
    11588    /** 
    11689     * @returns the coordinates as a string 
     
    12194    }, 
    12295     
    12396    /** 
     97     * @return Shortened String representation of Point object.  
     98     *         (ex. <i>"5, 42"</i>) 
     99     * @type String 
     100     */ 
     101    toShortString: function() { 
     102        return (this.x + ", " + this.y); 
     103    }, 
     104     
     105    /** 
    124106     * Moves a point in place 
    125107     * @param {Float} x 
    126108     * @param {Float} y 
    127109     */ 
    128110    move: function(x, y) { 
    129         this.setX(this.x + x)
    130         this.setY(this.y + y)
     111        this.x = this.x + x
     112        this.y = this.y + y
    131113    }, 
    132114 
    133115    /** @final @type String */ 
  • lib/OpenLayers/BaseTypes.js

    old new  
    492492        var bounds = null; 
    493493        if (object) { 
    494494            switch(object.CLASS_NAME) { 
    495                 case "OpenLayers.Geometry.Point": 
    496495                case "OpenLayers.LonLat":     
    497496                    bounds = new OpenLayers.Bounds(object.lon, object.lat, 
    498497                                                    object.lon, object.lat); 
    499498                    break; 
     499                case "OpenLayers.Geometry.Point": 
     500                    bounds = new OpenLayers.Bounds(object.x, object.y, 
     501                                                    object.x, object.y); 
     502                    break; 
    500503                     
    501504                case "OpenLayers.Bounds":     
    502505                    bounds = object; 
  • lib/OpenLayers/Renderer/VML.js

    old new  
    333333 
    334334        var path = "m"; 
    335335        for (var i = 0; i < geometry.components.length; i++) { 
    336             var x = (geometry.components[i].getX()/resolution); 
    337             var y = (geometry.components[i].getY()/resolution); 
     336            var x = (geometry.components[i].x/resolution); 
     337            var y = (geometry.components[i].y/resolution); 
    338338            path += " " + x.toFixed() + "," + y.toFixed() + " l "; 
    339339        } 
    340340        if (closeLine) { 
     
    360360 
    361361            path += "m"; 
    362362            for (var i = 0; i < linearRing.components.length; i++) { 
    363                 var x = linearRing.components[i].getX() / resolution; 
    364                 var y = linearRing.components[i].getY() / resolution; 
     363                var x = linearRing.components[i].x / resolution; 
     364                var y = linearRing.components[i].y / resolution; 
    365365                path += " " + x.toFixed() + "," + y.toFixed(); 
    366366                if (i==0) { 
    367367                    path += " l"; 
     
    399399     
    400400        var path = ""; 
    401401        for (var i = 0; i < geometry.components.length; i++) { 
    402             var x = geometry.components[i].getX() / resolution; 
    403             var y = geometry.components[i].getY() / resolution; 
     402            var x = geometry.components[i].x / resolution; 
     403            var y = geometry.components[i].y / resolution; 
    404404     
    405405            if ((i%3)==0 && (i/3)==0) { 
    406406                path += "m" 
     
    426426     
    427427        var path = ""; 
    428428        for (var i = 0; i < geometry.components.length; i++) { 
    429             var x = geometry.components[i].getX() / resolution; 
    430             var y = geometry.components[i].getY() / resolution; 
     429            var x = geometry.components[i].x / resolution; 
     430            var y = geometry.components[i].y / resolution; 
    431431            if ((i%3)==0 && (i/3)==0) { 
    432432                path += "m"; 
    433433            } else if ((i%3)==1) {