OpenLayers OpenLayers

Ticket #1019: spherical.3.patch

File spherical.3.patch, 9.7 kB (added by euzuro, 1 year ago)

fix getExtent() issue

  • lib/OpenLayers/Layer/SphericalMercator.js

    old new  
    3030 */ 
    3131OpenLayers.Layer.SphericalMercator = { 
    3232 
    33     /** 
    34      * Method: getExtent 
    35      * Get the map's extent. 
    36      * 
    37      * Returns: 
    38      * {<OpenLayers.Bounds>} The map extent. 
    39      */ 
    40     getExtent: function() { 
    41         var extent = null; 
    42         if (this.sphericalMercator) { 
    43             extent = this.map.calculateBounds(); 
    44         } else { 
    45             extent = OpenLayers.Layer.FixedZoomLevels.prototype.getExtent.apply(this); 
    46         } 
    47         return extent; 
    48     }, 
    49  
    5033    /**  
    5134     * Method: initMercatorParameters  
    5235     * Set up the mercator parameters on the layer: resolutions, 
     
    6144        } 
    6245        this.units = "m"; 
    6346        this.projection = "EPSG:900913"; 
    64     }, 
    6547 
     48 
     49 
     50        //translation functions 
     51 
     52         
     53      //instead of using FixedZoomLevels to calculate bounds, use map 
     54        this.getExtent = function() { 
     55            return this.map.calculateBounds(); 
     56        }; 
     57 
     58      //lon from maplonlat 
     59        var oldGetLon = this.getLongitudeFromMapObjectLonLat; 
     60        this.getLongitudeFromMapObjectLonLat = function(moLonLat) { 
     61            var lon = oldGetLon(moLonLat); 
     62            return this.forwardMercator(lon, 1).lon; 
     63        }; 
     64         
     65      //lat from maplonlat 
     66        var oldGetLat = this.getLatitudeFromMapObjectLonLat; 
     67        this.getLatitudeFromMapObjectLonLat = function(moLonLat) { 
     68            var lat = oldGetLat(moLonLat); 
     69            return this.forwardMercator(1, lat).lat; 
     70        }; 
     71 
     72      //maplonlat from lonlat 
     73        var oldGetLonLat = this.getMapObjectLonLatFromLonLat; 
     74        this.getMapObjectLonLatFromLonLat = function(lon, lat) { 
     75            var newLonLat = this.inverseMercator(lon, lat); 
     76            return oldGetLonLat(newLonLat.lon, newLonLat.lat);   
     77        }; 
     78     
     79    },         
     80 
     81 
    6682    /** 
    6783     * Method: forwardMercator 
    6884     * Given a lon,lat in EPSG:4326, return a point in Spherical Mercator. 
  • lib/OpenLayers/Layer/VirtualEarth.js

    old new  
    228228     * {Float} Longitude of the given MapObject LonLat 
    229229     */ 
    230230    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    231         return this.sphericalMercator ?  
    232             this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lon : 
    233             moLonLat.Longitude; 
     231        return moLonLat.Longitude; 
    234232    }, 
    235233 
    236234    /** 
     
    243241     * {Float} Latitude of the given MapObject LonLat 
    244242     */ 
    245243    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    246         return this.sphericalMercator ?  
    247             this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lat : 
    248             moLonLat.Latitude; 
     244        return moLonLat.Latitude; 
    249245    }, 
    250246 
    251247    /** 
     
    259255     * {Object} MapObject LonLat built from lon and lat params 
    260256     */ 
    261257    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    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         } 
     258        var veLatLong = new VELatLong(lat, lon); 
    269259        return veLatLong; 
    270260    }, 
    271261 
  • lib/OpenLayers/Layer/Google.js

    old new  
    211211    getOLBoundsFromMapObjectBounds: function(moBounds) { 
    212212        var olBounds = null; 
    213213        if (moBounds != null) { 
     214 
    214215            var sw = moBounds.getSouthWest(); 
     216            left = this.getLongitudeFromMapObjectLonLat(sw); 
     217            bottom = this.getLatitudeFromMapObjectLonLat(sw); 
     218 
    215219            var ne = moBounds.getNorthEast(); 
    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 ); 
     220            right = this.getLongitudeFromMapObjectLonLat(ne); 
     221            top = this.getLatitudeFromMapObjectLonLat(ne); 
     222 
     223            olBounds = new OpenLayers.Bounds(left, bottom, right, top); 
    227224        } 
    228225        return olBounds; 
    229226    }, 
     
    241238    getMapObjectBoundsFromOLBounds: function(olBounds) { 
    242239        var moBounds = null; 
    243240        if (olBounds != null) { 
    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)); 
     241            var sw = new OpenLayers.LonLat(olBounds.bottom, olBounds.left); 
     242            var gSw = this.getMapObjectLonLatFromLonLat(sw); 
     243 
     244            var ne = new OpenLayers.LonLat(olBounds.top, olBounds.right); 
     245            var gNe = this.getMapObjectLonLatFromLonLat(ne); 
     246 
     247            moBounds = new GLatLngBounds(sw, ne); 
    252248        } 
    253249        return moBounds; 
    254250    }, 
     
    418414     * {Float} Longitude of the given MapObject LonLat 
    419415     */ 
    420416    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    421         return this.sphericalMercator ?  
    422           this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lon : 
    423           moLonLat.lng();   
     417        return moLonLat.lng();   
    424418    }, 
    425419 
    426420    /** 
     
    433427     * {Float} Latitude of the given MapObject LonLat 
    434428     */ 
    435429    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    436         var lat = this.sphericalMercator ?  
    437           this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lat : 
    438           moLonLat.lat();  
    439         return lat;   
     430        return moLonLat.lat();  
    440431    }, 
    441432     
    442433    /** 
     
    450441     * {Object} MapObject LonLat built from lon and lat params 
    451442     */ 
    452443    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    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         } 
     444        var gLatLng = new GLatLng(lat, lon); 
    460445        return gLatLng; 
    461446    }, 
    462447 
  • lib/OpenLayers/Layer/Yahoo.js

    old new  
    306306     * {Float} Longitude of the given MapObject LonLat 
    307307     */ 
    308308    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    309         return this.sphericalMercator ?  
    310             this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon : 
    311             moLonLat.Lon; 
     309        return moLonLat.Lon; 
    312310    }, 
    313311 
    314312    /** 
     
    321319     * {Float} Latitude of the given MapObject LonLat 
    322320     */ 
    323321    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    324         return this.sphericalMercator ?  
    325             this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat : 
    326             moLonLat.Lat; 
     322        return moLonLat.Lat; 
    327323    }, 
    328324 
    329325    /** 
     
    337333     * {Object} MapObject LonLat built from lon and lat params 
    338334     */ 
    339335    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    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         } 
     336        var yLatLong = new YGeoPoint(lat, lon); 
    347337        return yLatLong; 
    348338    }, 
    349339 
  • lib/OpenLayers/Layer/MultiMap.js

    old new  
    208208     * {Float} Longitude of the given MapObject LonLat 
    209209     */ 
    210210    getLongitudeFromMapObjectLonLat: function(moLonLat) { 
    211         return this.sphericalMercator ?  
    212             this.forwardMercator(moLonLat.lon, moLonLat.lat).lon : 
    213             moLonLat.lon; 
     211        return moLonLat.lon; 
    214212    }, 
    215213 
    216214    /** 
     
    223221     * {Float} Latitude of the given MapObject LonLat 
    224222     */ 
    225223    getLatitudeFromMapObjectLonLat: function(moLonLat) { 
    226         return this.sphericalMercator ?  
    227             this.forwardMercator(moLonLat.lon, moLonLat.lat).lat : 
    228             moLonLat.lat; 
     224        return moLonLat.lat; 
    229225    }, 
    230226 
    231227    /** 
     
    239235     * {Object} MapObject LonLat built from lon and lat params 
    240236     */ 
    241237    getMapObjectLonLatFromLonLat: function(lon, lat) { 
    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         } 
     238        var mmLatLon = new MMLatLon(lat, lon); 
    249239        return mmLatLon; 
    250240    }, 
    251241