OpenLayers OpenLayers

Changeset 1198

Show
Ignore:
Timestamp:
08/12/06 11:54:51 (2 years ago)
Author:
euzuro
Message:

added 'drawn' property to all tiles. removed redraw() and adapted all draw()s to auto handle redraw. remove getPosition() accessor that noone was using. set generic Tile's moveTo() to auto trigger the clear() and the redraw() (if desired). Update Image and WFS tile classes correspondingly. also update tests

Files:

Legend:

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

    r1149 r1198  
    3232    * @type OpenLayers.Pixel */ 
    3333    position:null, 
     34 
     35    /** @type Boolean */ 
     36    drawn: false, 
    3437 
    3538    /** 
     
    6770    */ 
    6871    draw:function() { 
     72        this.drawn = true; 
    6973    }, 
    70  
    71     redraw: function () { 
    72         this.draw(); 
    73     }, 
    74  
     74     
    7575    /**  
    7676     * @param {OpenLayers.Bounds} 
    7777     * @param {OpenLayers.pixel} position 
     78     * @param {Boolean} redraw Redraw tile after moving?  
     79     *                         Default is true 
    7880     */ 
    79     moveTo: function (bounds, position) { 
     81    moveTo: function (bounds, position, redraw) { 
     82        if (redraw == null) { 
     83            redraw = true; 
     84        } 
     85 
     86        this.clear(); 
    8087        this.bounds = bounds.clone(); 
    8188        this.position = position.clone(); 
    82         this.redraw(); 
     89        if (redraw) { 
     90            this.draw(); 
     91        } 
    8392    }, 
    84  
    8593 
    8694    /** Clear the tile of any bounds/position-related data so that it can  
     
    8896     */ 
    8997    clear: function() { 
    90         this.bounds = null; 
    91         this.position = null; 
     98        this.drawn = false; 
    9299    }, 
    93100 
    94     /** 
    95     * @type OpenLayers.Pixel 
    96     */ 
    97     getPosition: function() { 
    98         return this.position; 
    99     }, 
    100      
    101101    /** @final @type String */ 
    102102    CLASS_NAME: "OpenLayers.Tile" 
  • trunk/openlayers/lib/OpenLayers/Tile/Image.js

    r1155 r1198  
    22 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full 
    33 * text of the license. */ 
     4 
    45// @require: OpenLayers/Tile.js 
     6 
    57/** 
    68* @class 
     
    2527        OpenLayers.Tile.prototype.initialize.apply(this, arguments); 
    2628    }, 
    27  
     29     
     30    /** 
     31     *  
     32     */ 
    2833    destroy: function() { 
    2934        if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.layer.div)) { 
     
    3540 
    3641    /** 
    37     */ 
     42     *  
     43     */ 
    3844    draw:function() { 
    39         if (this.layer.alpha) { 
    40             this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, 
    41                                                            this.position, 
    42                                                            this.size, 
    43                                                            this.url, 
    44                                                            "absolute", 
    45                                                            null, 
    46                                                            null, 
    47                                                            true); 
    48         } else { 
    49             this.imgDiv = OpenLayers.Util.createImage(null, 
    50                                                       this.position, 
    51                                                       this.size, 
    52                                                       this.url, 
    53                                                       "absolute", 
    54                                                       null, 
    55                                                       true); 
     45        OpenLayers.Tile.prototype.draw.apply(this, arguments); 
     46 
     47        if (this.imgDiv == null) { 
     48            this.initImgDiv(); 
    5649        } 
    57         this.layer.div.appendChild(this.imgDiv); 
    58     }, 
    5950 
    60     /** Clear the tile of any bounds/position-related data so that it can  
    61      *   be reused in a new location. 
    62      */ 
    63     clear: function() { 
    64         this.imgDiv.style.display = "none"; 
    65     }, 
    66  
    67     /**  
    68      * @param {OpenLayers.Bounds} 
    69      * @param {OpenLayers.pixel} position 
    70      */ 
    71     moveTo: function (bounds, position) { 
    72         this.url = this.layer.getURL(bounds); 
    73         OpenLayers.Tile.prototype.moveTo.apply(this, arguments); 
    74     }, 
    75  
    76     redraw: function () { 
    7751        this.imgDiv.style.display = "none"; 
    7852        if (this.layer.alpha) { 
     
    8660    }, 
    8761 
     62    /** Clear the tile of any bounds/position-related data so that it can  
     63     *   be reused in a new location. 
     64     */ 
     65    clear: function() { 
     66        OpenLayers.Tile.prototype.clear.apply(this, arguments); 
     67        this.imgDiv.style.display = "none"; 
     68    }, 
     69 
     70    /**  
     71     * @param {OpenLayers.Bounds} 
     72     * @param {OpenLayers.pixel} position 
     73     * @param {Boolean} redraw 
     74     */ 
     75    moveTo: function (bounds, position, redraw) { 
     76        this.url = this.layer.getURL(bounds); 
     77        OpenLayers.Tile.prototype.moveTo.apply(this, arguments); 
     78    }, 
     79 
     80    /** 
     81     *  
     82     */ 
     83    initImgDiv: function() { 
     84        if (this.layer.alpha) { 
     85            this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, 
     86                                                           this.position, 
     87                                                           this.size, 
     88                                                           null, 
     89                                                           "absolute", 
     90                                                           null, 
     91                                                           null, 
     92                                                           true); 
     93        } else { 
     94            this.imgDiv = OpenLayers.Util.createImage(null, 
     95                                                      this.position, 
     96                                                      this.size, 
     97                                                      null, 
     98                                                      "absolute", 
     99                                                      null, 
     100                                                      true); 
     101        } 
     102        this.layer.div.appendChild(this.imgDiv); 
     103    }, 
     104 
    88105    /** @final @type String */ 
    89106    CLASS_NAME: "OpenLayers.Tile.Image" 
  • trunk/openlayers/lib/OpenLayers/Tile/WFS.js

    r1189 r1198  
    4040     */ 
    4141    destroy: function() { 
    42         this.clear(); 
     42        OpenLayers.Tile.prototype.destroy.apply(this, arguments); 
     43        this.destroyAllFeatures(); 
     44        this.features = null; 
    4345        this.urls = null; 
    44         OpenLayers.Tile.prototype.destroy.apply(this, arguments); 
    4546    }, 
    4647 
     
    4950     */ 
    5051    clear: function() { 
    51         while(this.features.length > 0) { 
    52             var feature = this.features.shift(); 
    53             feature.destroy(); 
    54         } 
     52        OpenLayers.Tile.prototype.clear.apply(this, arguments); 
     53        this.destroyAllFeatures(); 
    5554    }, 
    5655     
    5756    /** 
    58     */ 
     57     *  
     58     */ 
    5959    draw:function() { 
     60        if (this.drawn) { 
     61            this.clear(); 
     62        } 
     63        OpenLayers.Tile.prototype.draw.apply(this, arguments); 
    6064        this.loadFeaturesForRegion(this.requestSuccess);         
    6165    }, 
    6266 
    63     /**  
    64      * @param {OpenLayers.Bounds} 
    65      * @param {OpenLayers.pixel} position 
    66      */ 
    67     moveTo: function (bounds, position) { 
    68          
    69         this.loaded = false; 
    70          
    71         OpenLayers.Tile.prototype.moveTo.apply(this, arguments); 
    72     }, 
    73      
    7467    /** get the full request string from the ds and the tile params  
    7568    *     and call the AJAX loadURL().  
     
    8275    loadFeaturesForRegion:function(success, failure) { 
    8376 
    84         if (!this.loaded) { 
     77        if (this.urls != null) { 
    8578         
    86             if (this.urls != null) { 
    87          
    88                 // TODO: Hmmm, this stops multiple loads of the data when a  
    89                 //       result isn't immediately retrieved, but it's hacky.  
    90                 //       Do it better. 
    91                 this.loaded = true;  
    92                  
    93                 for(var i=0; i < this.urls.length; i++) { 
    94                     var params ={ BBOX:bounds.toBBOX() }; 
    95                     var url = this.urls[i] +  
    96                               OpenLayers.Util.getParameterString(params); 
    97                     OpenLayers.loadURL(url, null, this,  
    98                                        success, failure); 
    99                 } 
     79            for(var i=0; i < this.urls.length; i++) { 
     80                var params = { BBOX:bounds.toBBOX() }; 
     81                var url = this.urls[i] +  
     82                          OpenLayers.Util.getParameterString(params); 
     83                OpenLayers.loadURL(url, null, this, success, failure); 
    10084            } 
    10185        } 
     
    122106     */ 
    123107    addResults: function(results) { 
    124  
    125108        for (var i=0; i < results.length; i++) { 
    126          
    127109            var feature = new this.layer.featureClass(this.layer,  
    128110                                                      results[i]); 
    129111            this.features.push(feature); 
    130112        } 
    131          
    132113    }, 
    133114 
     115    /** Iterate through and call destroy() on each feature, removing it from 
     116     *   the local array 
     117     *  
     118     * @private 
     119     */ 
     120    destroyAllFeatures: function() { 
     121        while(this.features.length > 0) { 
     122            var feature = this.features.shift(); 
     123            feature.destroy(); 
     124        } 
     125    }, 
     126     
    134127    /** @final @type String */ 
    135128    CLASS_NAME: "OpenLayers.Tile.WFS" 
  • trunk/openlayers/tests/test_Tile_Image.html

    r688 r1198  
    99        t.plan( 6 ); 
    1010         
    11         var layer = new Object(); //bogus layer 
     11        var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     12            "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});  
     13 
    1214        var position = new OpenLayers.Pixel(20,30); 
    1315        var bounds = new OpenLayers.Bounds(1,2,3,4); 
     
    1719         
    1820        t.ok( tile instanceof OpenLayers.Tile.Image, "new OpenLayers.Tile returns Tile object" ); 
    19         t.eq( tile.layer, layer, "tile.layer is set correctly"); 
     21        t.ok( tile.layer == layer, "tile.layer is set correctly"); 
    2022        t.ok( tile.position.equals(position), "tile.position is set correctly"); 
    2123        t.ok( tile.bounds.equals(bounds), "tile.bounds is set correctly");