OpenLayers OpenLayers

Changeset 2134

Show
Ignore:
Timestamp:
01/10/07 00:11:02 (2 years ago)
Author:
tschaub
Message:

let tiles have gutters!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/gutter/lib/OpenLayers/Layer.js

    r2133 r2134  
    545545        this.opacity = opacity; 
    546546        for(var i=0; i<this.div.childNodes.length; ++i) { 
    547             var element = this.div.childNodes[i]
     547            var element = this.div.childNodes[i].firstChild
    548548            OpenLayers.Util.modifyDOMElement(element, null, null, null,  
    549549                                             null, null, null, opacity); 
  • sandbox/tschaub/gutter/lib/OpenLayers/Layer/WMS.js

    r2133 r2134  
    2424     
    2525    reproject: true, 
     26     
     27    /** Determines the width (in pixels) of the gutter around image tiles 
     28     * to ignore.  By setting this property to a non-zero value, images 
     29     * will be requested that are wider and taller than the tile size by 
     30     * a value of 2 x gutter.  This allows artifacts of rendering at tile 
     31     * edges to be ignored.  Set a gutter value that is equal to half the size 
     32     * of the widest symbol that needs to be displayed.  Defaults to zero. 
     33     *  
     34     * @type int 
     35    */ 
     36    gutter: 0, 
    2637 
    2738    /** 
     
    93104     */ 
    94105    getURL: function (bounds) { 
     106        if(!this.gutter) { 
     107            return this.getFullRequestString( 
     108                         {BBOX:bounds.toBBOX(), 
     109                          WIDTH:this.tileSize.w, 
     110                          HEIGHT:this.tileSize.h}); 
     111        } 
     112        var tileMapLT = new OpenLayers.LonLat(bounds.left, bounds.top); 
     113        var tileMapRB = new OpenLayers.LonLat(bounds.right, bounds.bottom); 
     114        var tilePixelLT = this.getViewPortPxFromLonLat(tileMapLT); 
     115        var tilePixelRB = this.getViewPortPxFromLonLat(tileMapRB); 
     116        var imagePixelLT = new OpenLayers.Pixel(tilePixelLT.x - this.gutter, 
     117                                                tilePixelLT.y - this.gutter); 
     118        var imagePixelRB = new OpenLayers.Pixel(tilePixelRB.x + this.gutter, 
     119                                                tilePixelRB.y + this.gutter); 
     120        var imageMapLT = this.getLonLatFromViewPortPx(imagePixelLT); 
     121        var imageMapRB = this.getLonLatFromViewPortPx(imagePixelRB); 
     122        var imageBounds = new OpenLayers.Bounds(imageMapLT.lon, imageMapRB.lat, 
     123                                                imageMapRB.lon, imageMapLT.lat); 
    95124        return this.getFullRequestString( 
    96                      {BBOX:bounds.toBBOX(), 
    97                       WIDTH:this.tileSize.w
    98                       HEIGHT:this.tileSize.h}); 
     125                     {BBOX:imageBounds.toBBOX(), 
     126                      WIDTH:this.tileSize.w + (2 * this.gutter)
     127                      HEIGHT:this.tileSize.h + (2 * this.gutter)}); 
    99128    }, 
    100129 
  • sandbox/tschaub/gutter/lib/OpenLayers/Tile/Image.js

    r2133 r2134  
    1515    /** @type DOMElement img */ 
    1616    imgDiv: null, 
     17     
     18    /** The image element is appended to the frame.  Any gutter on the image 
     19     * will be hidden behind the frame. 
     20     * 
     21     * @type DOMElement div */ 
     22    frame: null, 
    1723 
    1824    /**  
     
    2733    initialize: function(layer, position, bounds, url, size) { 
    2834        OpenLayers.Tile.prototype.initialize.apply(this, arguments); 
     35        this.frame = document.createElement('div'); 
     36        this.frame.style.overflow = 'hidden'; 
     37        this.frame.style.position = 'absolute'; 
     38        if(layer.gutter) { 
     39            this.imageOffset = new OpenLayers.Pixel(-layer.gutter, -layer.gutter); 
     40            this.imageSize = new OpenLayers.Size(this.size.w + (2 * layer.gutter), 
     41                                                 this.size.h + (2 * layer.gutter)); 
     42        } else { 
     43            this.imageOffset = new OpenLayers.Pixel(0, 0); 
     44            this.imageSize = this.size.clone(); 
     45        } 
    2946    }, 
    3047 
     
    3350     */ 
    3451    destroy: function() { 
    35         if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.layer.div)) { 
    36             this.layer.div.removeChild(this.imgDiv); 
     52        if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.frame)) { 
     53            this.frame.removeChild(this.imgDiv); 
    3754        } 
    3855        this.imgDiv = null; 
     56        if ((this.frame != null) && (this.frame.parentNode == this.layer.div)) { 
     57            this.layer.div.removeChild(this.frame); 
     58        } 
     59        this.frame = null; 
    3960        OpenLayers.Tile.prototype.destroy.apply(this, arguments); 
    4061    }, 
     
    5576         
    5677        this.url = this.layer.getURL(this.bounds); 
    57    
     78        // position the frame 
     79        OpenLayers.Util.modifyDOMElement(this.frame, 
     80                                         null, this.position, this.size); 
    5881        if (this.layer.alpha) { 
    5982            OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, 
    60                     null, this.position, this.size, this.url); 
     83                    null, null, this.imageSize, this.url); 
    6184        } else { 
    6285            this.imgDiv.src = this.url; 
    6386            OpenLayers.Util.modifyDOMElement(this.imgDiv, 
    64                     null, this.position, this.size) ; 
     87                    null, null, this.imageSize) ; 
    6588        } 
    6689        this.drawn = true; 
     
    97120        if (this.layer.alpha) { 
    98121            this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, 
    99                                                            this.position
    100                                                            this.size, 
     122                                                           this.imageOffset
     123                                                           this.imageSize, 
    101124                                                           null, 
    102                                                            "absolute", 
     125                                                           "relative", 
    103126                                                           null, 
    104127                                                           null, 
     
    107130        } else { 
    108131            this.imgDiv = OpenLayers.Util.createImage(null, 
    109                                                       this.position
    110                                                       this.size, 
     132                                                      this.imageOffset
     133                                                      this.imageSize, 
    111134                                                      null, 
    112                                                       "absolute", 
     135                                                      "relative", 
    113136                                                      null, 
    114137                                                      null, 
     
    124147                        this.checkImgURL.bindAsEventListener(this) ); 
    125148 
    126         this.layer.div.appendChild(this.imgDiv); 
     149        this.frame.appendChild(this.imgDiv); 
     150        this.layer.div.appendChild(this.frame); 
     151 
    127152        if(this.layer.opacity != null) { 
    128153             
  • sandbox/tschaub/gutter/tests/test_Layer_WMS.html

    r2133 r2134  
    5151             url + "?" + OpenLayers.Util.getParameterString(tParams), 
    5252             "image src is created correctly via addtile" ); 
    53         t.eq( tile.imgDiv.style.top, "6px", "image top is set correctly via addtile" ); 
    54         t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" ); 
    55  
    56         var firstChild = layer.div.firstChild
     53        t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" ); 
     54        t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" ); 
     55 
     56        var firstChild = layer.div.firstChild.firstChild
    5757        if (!isMozilla) 
    5858            t.ok( true, "skipping element test outside of Mozilla"); 
     
    182182        map.zoomToMaxExtent(); 
    183183        t.eq(tLayer.opacity, "0.5", "Opacity is set correctly"); 
    184         t.eq(parseFloat(tLayer.div.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); 
     184        t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); 
    185185        tLayer.setOpacity("0.6"); 
    186186        t.eq(tLayer.opacity, "0.6", "setOpacity works properly"); 
    187         t.eq(parseFloat(tLayer.div.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); 
     187        t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); 
    188188        var pixel = new OpenLayers.Pixel(5,6); 
    189189        var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);