OpenLayers OpenLayers

Changeset 3832

Show
Ignore:
Timestamp:
08/01/07 08:33:01 (1 year ago)
Author:
jachym
Message:

new stretching funtionality of the maps, which are in WGS84 projection. Maps can be streched according to Latitude of their center

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/jachym/openlayers/lib/OpenLayers/Layer.js

    r3819 r3832  
    758758            var center = this.map.getCenter(); 
    759759            if (center) { 
    760                 var res  = this.map.getResolution(); 
     760                var resx; 
     761                var resy; 
     762                resx =  resy = this.map.getResolution(); 
    761763         
    762764                var delta_x = viewPortPx.x - (size.w / 2); 
    763765                var delta_y = viewPortPx.y - (size.h / 2); 
     766 
     767                // strech the map  according to lat 
     768                if (this.map.stretch && (this.map.units == "dd" || this.map.units == "degrees")) { 
     769                    resy *= this.map.stretchConts; 
     770                } 
    764771             
    765                 lonlat = new OpenLayers.LonLat(center.lon + delta_x * res
    766                                              center.lat - delta_y * res);  
     772                lonlat = new OpenLayers.LonLat(center.lon + delta_x * resx
     773                                             center.lat - delta_y * resy);  
    767774 
    768775                if (this.wrapDateLine) { 
     
    788795        var px = null;  
    789796        if (lonlat != null) { 
    790             var resolution = this.map.getResolution(); 
     797            var xres; 
     798            var yres; 
     799            xres = yres = this.map.getResolution(); 
    791800            var extent = this.map.getExtent(); 
     801 
     802            // strech the map  according to lat 
     803            if (this.map.stretch && (this.map.units == "dd" || this.map.units == "degrees")) { 
     804                 yres*= this.map.stretchConts; 
     805            } 
    792806            px = new OpenLayers.Pixel( 
    793                            Math.round(1/resolution * (lonlat.lon - extent.left)), 
    794                            Math.round(1/resolution * (extent.top - lonlat.lat)) 
     807                           Math.round(1/xres * (lonlat.lon - extent.left)), 
     808                           Math.round(1/yres * (extent.top - lonlat.lat)) 
    795809                           );     
    796810        } 
     
    842856            // Adjust the extent of a bounds in map units by the  
    843857            // layer's gutter in pixels. 
    844             var mapGutter = this.gutter * this.map.getResolution(); 
    845             bounds = new OpenLayers.Bounds(bounds.left - mapGutter, 
    846                                            bounds.bottom - mapGutter, 
    847                                            bounds.right + mapGutter, 
    848                                            bounds.top + mapGutter); 
     858            var mapGutterX; 
     859            var mapGutterY; 
     860            mapGutterX = mapGutterY = this.gutter * this.map.getResolution(); 
     861 
     862            // strech the map  according to lat 
     863            if (this.map.stretch && (this.map.units == "dd" || this.map.units == "degrees")) { 
     864                mapGutterY *= this.map.stretchConts; 
     865            } 
     866            bounds = new OpenLayers.Bounds(bounds.left - mapGutterX, 
     867                                           bounds.bottom - mapGutterY, 
     868                                           bounds.right + mapGutterX, 
     869                                           bounds.top + mapGutterY); 
    849870        } 
    850871 
  • sandbox/jachym/openlayers/lib/OpenLayers/Layer/Grid.js

    r3829 r3832  
    307307        var tilelon = resolution * this.tileSize.w; 
    308308        var tilelat = resolution * this.tileSize.h; 
     309 
     310        // strech the map  according to lat 
     311        if (this.map.stretch && (this.map.units == "dd" || this.map.units == "degrees")) { 
     312            tilelat *= this.map.stretchConts; 
     313        } 
    309314         
    310315        var offsetlon = bounds.left - extent.left; 
     
    567572        var deltaLat = resolution * -deltaY; 
    568573 
     574        // strech the map  according to lat 
     575        if (this.map.stretch && (this.map.units == "dd" || this.map.units == "degrees")) { 
     576            deltaLat *= this.map.stretchConts; 
     577        } 
     578 
    569579        var row = (prepend) ? this.grid.pop() : this.grid.shift(); 
    570580 
  • sandbox/jachym/openlayers/lib/OpenLayers/Map.js

    r3829 r3832  
    230230     */ 
    231231    fallThrough: false, 
     232 
     233    /** Should the map be "streched" if units are degrees (assuming EPSG: 
     234     * 4326 projection) ? 
     235     *   Default is no. 
     236     *  
     237     * @type boolean  
     238     */ 
     239     stretch: false, 
     240 
     241    /** This constant should be initialized at the beginning 
     242     *  
     243     * @type Integer  
     244     */ 
     245     stretchConts: null, 
     246 
    232247 
    233248    /** 
     
    956971            var w_deg = size.w * resolution; 
    957972            var h_deg = size.h * resolution; 
     973 
     974            // strech the map  according to lat 
     975            if (this.stretch && (this.units == "dd" || this.units == "degrees")) { 
     976                if (!this.stretchConts) {  
     977                        this.stretchConts =  Math.cos(center.lat/180*Math.PI); 
     978                } 
     979                h_deg *= this.stretchConts; 
     980            } 
    958981         
    959982            extent = new OpenLayers.Bounds(center.lon - w_deg / 2,