OpenLayers OpenLayers

Changeset 4221

Show
Ignore:
Timestamp:
09/11/07 16:16:28 (11 months ago)
Author:
crschmidt
Message:

With review from elem, and oversight from tschaub, rolling in
SphericalMercator changes. Note that this explicitly does *not* include
r4182 , so as to keep changes to a single logical set: that should be
filed in a seperate bug if it can be reproduced against trunk after this
commit. Hooray for Tim, thanks for all the feedback, onward and upward!
(Closes #686)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers.js

    r4205 r4221  
    8989            "OpenLayers/Tile/WFS.js", 
    9090            "OpenLayers/Layer/Image.js", 
     91            "OpenLayers/Layer/SphericalMercator.js", 
    9192            "OpenLayers/Layer/EventPane.js", 
    9293            "OpenLayers/Layer/FixedZoomLevels.js", 
  • trunk/openlayers/lib/OpenLayers/Layer/Google.js

    r4110 r4221  
    55 
    66/** 
     7 * @requires OpenLayers/Layer/SphericalMercator.js 
    78 * @requires OpenLayers/Layer/EventPane.js 
    89 * @requires OpenLayers/Layer/FixedZoomLevels.js 
     
    1112 *  
    1213 * Inherits: 
     14 *  - <OpenLayers.Layer.SphericalMercator> 
    1315 *  - <OpenLayers.Layer.EventPane> 
    1416 *  - <OpenLayers.Layer.FixedZoomLevels> 
    1517 */ 
    16 OpenLayers.Layer.Google = OpenLayers.Class(OpenLayers.Layer.EventPane,  
    17                                            OpenLayers.Layer.FixedZoomLevels, { 
     18OpenLayers.Layer.Google = OpenLayers.Class( 
     19    OpenLayers.Layer.EventPane,  
     20    OpenLayers.Layer.FixedZoomLevels, { 
    1821     
    1922    /**  
     
    6366    type: null, 
    6467 
     68    /** 
     69     * APIProperty: sphericalMercator 
     70     * {Boolean} Should the map act as a mercator-projected map? This will 
     71     * cause all interactions with the map to be in the actual map projection, 
     72     * which allows support for vector drawing, overlaying other maps, etc.  
     73     */ 
     74    sphericalMercator: false,  
     75 
    6576    /**  
    6677     * Constructor: OpenLayers.Layer.Google 
     
    7586                                                                    arguments); 
    7687        this.addContainerPxFunction(); 
     88        if (this.sphericalMercator) { 
     89            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator); 
     90            this.initMercatorParameters(); 
     91        }     
    7792    }, 
    7893     
     
    152167    }, 
    153168 
    154  
    155169    /** 
    156170     * APIMethod: getZoomForExtent 
     
    200214            var sw = moBounds.getSouthWest(); 
    201215            var ne = moBounds.getNorthEast(); 
    202             olBounds = new OpenLayers.Bounds(sw.lng(),  
    203                                              sw.lat(),  
    204                                              ne.lng(),  
    205                                              ne.lat() ); 
     216            if (this.sphericalMercator) { 
     217                sw = this.forwardMercator(sw.lng(), sw.lat()); 
     218                ne = this.forwardMercator(ne.lng(), ne.lat()); 
     219            } else { 
     220                sw = new OpenLayers.LonLat(sw.lng(), sw.lat());  
     221                ne = new OpenLayers.LonLat(ne.lng(), ne.lat());  
     222            }     
     223            olBounds = new OpenLayers.Bounds(sw.lon,  
     224                                             sw.lat,  
     225                                             ne.lon,  
     226                                             ne.lat ); 
    206227        } 
    207228        return olBounds; 
     
    221242        var moBounds = null; 
    222243        if (olBounds != null) { 
    223             var sw = new GLatLng(olBounds.bottom, olBounds.left); 
    224             var ne = new GLatLng(olBounds.top, olBounds.right); 
    225             moBounds = new GLatLngBounds(sw, ne); 
     244            var sw = this.sphericalMercator ?  
     245              this.inverseMercator(olBounds.bottom, olBounds.left) :  
     246              new OpenLayers.LonLat(olBounds.bottom, olBounds.left); 
     247            var ne = this.sphericalMercator ?  
     248              this.inverseMercator(olBounds.top, olBounds.right) :  
     249              new OpenLayers.LonLat(olBounds.top, olBounds.right); 
     250            moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon), 
     251                                         new GLatLng(ne.lat, ne.lon)); 
    226252        } 
    227253        return moBounds; 
    228254    }, 
    229      
    230  
    231  
    232  
    233255 
    234256    /**  
     
    397419     */ 
    398420    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    399         return moLonLat.lng();   
     421        return this.sphericalMercator ?  
     422          this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lon : 
     423          moLonLat.lng();   
    400424    }, 
    401425 
     
    410434     */ 
    411435    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    412         return moLonLat.lat();   
     436        var lat = this.sphericalMercator ?  
     437          this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lat : 
     438          moLonLat.lat();  
     439        return lat;   
    413440    }, 
    414441     
     
    424451     */ 
    425452    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    426         return new GLatLng(lat, lon); 
     453        var gLatLng; 
     454        if(this.sphericalMercator) { 
     455            var lonlat = this.inverseMercator(lon, lat); 
     456            gLatLng = new GLatLng(lonlat.lat, lonlat.lon); 
     457        } else { 
     458            gLatLng = new GLatLng(lat, lon); 
     459        } 
     460        return gLatLng; 
    427461    }, 
    428462 
  • trunk/openlayers/lib/OpenLayers/Layer/MultiMap.js

    r4110 r4221  
    88 *  
    99 * Class: OpenLayers.Layer.MultiMap 
     10 * Note that MultiMap does not fully support the sphericalMercator 
     11 * option. See Ticket #953 for more details. 
    1012 *  
    1113 * Inherits: 
     
    7072        OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,  
    7173                                                                    arguments); 
     74        if (this.sphericalMercator) { 
     75            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator); 
     76            this.initMercatorParameters(); 
     77            this.RESOLUTIONS.unshift(10);  
     78        }     
    7279    }, 
    7380     
     
    202209     */ 
    203210    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    204         return moLonLat.lon; 
     211        return this.sphericalMercator ?  
     212            this.forwardMercator(moLonLat.lon, moLonLat.lat).lon : 
     213            moLonLat.lon; 
    205214    }, 
    206215 
     
    215224     */ 
    216225    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    217         return moLonLat.lat; 
     226        return this.sphericalMercator ?  
     227            this.forwardMercator(moLonLat.lon, moLonLat.lat).lat : 
     228            moLonLat.lat; 
    218229    }, 
    219230 
     
    229240     */ 
    230241    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    231         return new MMLatLon(lat, lon); 
     242        var mmLatLon; 
     243        if(this.sphericalMercator) { 
     244            var lonlat = this.inverseMercator(lon, lat); 
     245            mmLatLon = new MMLatLon(lonlat.lat, lonlat.lon); 
     246        } else { 
     247            mmLatLon = new MMLatLon(lat, lon); 
     248        } 
     249        return mmLatLon; 
    232250    }, 
    233251 
  • trunk/openlayers/lib/OpenLayers/Layer/VirtualEarth.js

    r4110 r4221  
    1515 */ 
    1616OpenLayers.Layer.VirtualEarth = OpenLayers.Class( 
    17   OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, { 
     17    OpenLayers.Layer.EventPane, 
     18    OpenLayers.Layer.FixedZoomLevels, { 
    1819     
    1920    /**  
     
    5960    type: null, 
    6061 
     62    /** 
     63     * APIProperty: sphericalMercator 
     64     * {Boolean} Should the map act as a mercator-projected map? This will 
     65     *     cause all interactions with the map to be in the actual map 
     66     *     projection, which allows support for vector drawing, overlaying 
     67     *     other maps, etc.  
     68     */ 
     69    sphericalMercator: false,  
     70 
    6171    /**  
    6272     * Constructor: OpenLayers.Layer.VirtualEarth 
     
    7080        OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,  
    7181                                                                    arguments); 
     82        if(this.sphericalMercator) { 
     83            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator); 
     84            this.initMercatorParameters(); 
     85        } 
    7286    }, 
    7387     
     
    215229     */ 
    216230    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    217         return moLonLat.Longitude; 
     231        return this.sphericalMercator ?  
     232            this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lon : 
     233            moLonLat.Longitude; 
    218234    }, 
    219235 
     
    228244     */ 
    229245    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    230         return moLonLat.Latitude; 
     246        return this.sphericalMercator ?  
     247            this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lat : 
     248            moLonLat.Latitude; 
    231249    }, 
    232250 
     
    242260     */ 
    243261    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    244         return new VELatLong(lat, lon); 
     262        var veLatLong; 
     263        if(this.sphericalMercator) { 
     264            var lonlat = this.inverseMercator(lon, lat); 
     265            veLatLong = new VELatLong(lonlat.lat, lonlat.lon); 
     266        } else { 
     267            veLatLong = new VELatLong(lat, lon); 
     268        } 
     269        return veLatLong; 
    245270    }, 
    246271 
  • trunk/openlayers/lib/OpenLayers/Layer/Yahoo.js

    r4110 r4221  
    5858     */ 
    5959    type: null, 
     60     
     61    /** 
     62     * APIProperty: sphericalMercator 
     63     * {Boolean} Should the map act as a mercator-projected map? This will 
     64     * cause all interactions with the map to be in the actual map projection, 
     65     * which allows support for vector drawing, overlaying other maps, etc.  
     66     */ 
     67    sphericalMercator: false,  
    6068 
    6169    /**  
     
    7078        OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,  
    7179                                                                    arguments); 
     80        if(this.sphericalMercator) { 
     81            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator); 
     82            this.initMercatorParameters(); 
     83        } 
    7284    }, 
    7385     
     
    295307     */ 
    296308    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    297         return moLonLat.Lon; 
     309        return this.sphericalMercator ?  
     310            this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon : 
     311            moLonLat.Lon; 
    298312    }, 
    299313 
     
    308322     */ 
    309323    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    310         return moLonLat.Lat; 
     324        return this.sphericalMercator ?  
     325            this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat : 
     326            moLonLat.Lat; 
    311327    }, 
    312328 
     
    322338     */ 
    323339    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    324         return new YGeoPoint(lat, lon); 
     340        var yLatLong; 
     341        if(this.sphericalMercator) { 
     342            var lonlat = this.inverseMercator(lon, lat); 
     343            yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon); 
     344        } else { 
     345            yLatLong = new YGeoPoint(lat, lon); 
     346        } 
     347        return yLatLong; 
    325348    }, 
    326349 
  • trunk/openlayers/tests/Layer/test_Google.html

    r4087 r4221  
    129129        } 
    130130    } 
     131     
     132    function test_Layer_Goole_forwardMercator(t){ 
     133        t.plan(2); 
     134        //Just test that the fowardMercator function still exists. 
     135        var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true}); 
     136        layer.forwardMercator = function(evt) { 
     137                                    t.ok( true, "GoogleMercator.forwardMercator was called and executed." ); 
     138                                    return; 
     139                                } 
     140        layer.forwardMercator(); 
     141        //Now test the fowardMercator returns the expected LonLat object 
     142        var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true}); 
     143        var lonlat2 = new OpenLayers.LonLat(Math.random(),Math.random()); 
     144        var result = layer.forwardMercator(lonlat2.lon, lonlat2.lat); 
     145        t.ok( result instanceof OpenLayers.LonLat, "OpenLayers.Google.fowardMercator returns LonLat object" ); 
     146         
     147    } 
    131148 
    132149    function test_Layer_Google_overlay(t) { 
  • trunk/openlayers/tests/list-tests.html

    r4218 r4221  
    4141    <li>Layer/test_FixedZoomLevels.html</li> 
    4242    <li>Layer/test_GeoRSS.html</li> 
     43    <li>Layer/test_SphericalMercator.html</li> 
    4344    <li>Layer/test_Google.html</li> 
    4445    <li>Layer/test_Grid.html</li>