OpenLayers OpenLayers

Changeset 3582

Show
Ignore:
Timestamp:
07/05/07 10:04:51 (1 year ago)
Author:
euzuro
Message:

fix for #795 - all layers now have a redraw() method that simply redraws them no matter whether the extent or parameters or zoom has changed. Big big thanks to tim schaub for not only taking the time to listen to my relentless (and often cracked) brainstorming about this ticket and for taking the time out to review the final patch.... but above and beyond the call of duty, adding *tests* for this patch. real ace. top knotch.

Files:

Legend:

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

    r3568 r3582  
    333333    onMapResize: function() { 
    334334        //this function can be implemented by subclasses   
     335    }, 
     336 
     337    /** 
     338     * APIMethod: redraw 
     339     * Redraws the layer.  Returns true if the layer was redrawn, false if not. 
     340     * 
     341     * Return: 
     342     * {Boolean} The layer was redrawn. 
     343     */ 
     344    redraw: function() { 
     345        var redrawn = false; 
     346        if (this.map) { 
     347 
     348            // min/max Range may have changed 
     349            this.inRange = this.calculateInRange(); 
     350 
     351            // map's center might not yet be set 
     352            var extent = this.getExtent(); 
     353 
     354            if (extent && this.inRange && this.visibility) { 
     355                this.moveTo(extent, true, false); 
     356                redrawn = true; 
     357            } 
     358        } 
     359        return redrawn; 
    335360    }, 
    336361 
     
    452477            this.visibility = visibility; 
    453478            this.display(visibility); 
    454             if (visibility && this.map != null) { 
    455                 var extent = this.map.getExtent(); 
    456                 if (extent != null) { 
    457                     this.moveTo(extent, true); 
    458                 } 
    459             } 
     479            this.redraw(); 
    460480            if ((this.map != null) &&  
    461481                ((noEvent == null) || (noEvent == false))) { 
  • trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js

    r3555 r3582  
    242242    setUrl: function(newUrl) { 
    243243        OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments); 
    244         this.moveTo(); 
     244        this.redraw(); 
    245245    }, 
    246246 
     
    255255        OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,  
    256256                                                                 [newParams]); 
    257         //redraw 
    258         this.moveTo(null, true); 
     257        this.redraw(); 
    259258    }, 
    260259     
  • trunk/openlayers/lib/OpenLayers/Layer/Markers.js

    r3578 r3582  
    7373 
    7474        if (zoomChanged || !this.drawn) { 
    75             this.redraw(); 
     75            for(i=0; i < this.markers.length; i++) { 
     76                this.drawMarker(this.markers[i]); 
     77            } 
    7678            this.drawn = true; 
    7779        } 
     
    117119    }, 
    118120 
    119     /** 
    120      * APIMethod: redraw 
    121      * Clear all the marker div's from the layer and then redraw all of them. 
    122      *    Use the map to recalculate new placement of markers. 
    123      */ 
    124     redraw: function() { 
    125         for(i=0; i < this.markers.length; i++) { 
    126             this.drawMarker(this.markers[i]); 
    127         } 
    128     }, 
    129  
    130121    /**  
    131122     * Method: drawMarker 
  • trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js

    r3555 r3582  
    258258    setUrl: function(newUrl) { 
    259259        OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments); 
    260         this.moveTo(); 
     260        this.redraw(); 
    261261    }, 
    262262 
     
    273273        OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,  
    274274                                                                 newArguments); 
    275         //redraw 
    276         this.moveTo(null, true); 
     275        this.redraw(); 
    277276    }, 
    278277     
  • trunk/openlayers/lib/OpenLayers/Map.js

    r3574 r3582  
    519519            } 
    520520        } else { 
    521             if (this.getCenter() != null) { 
    522                 layer.moveTo(this.getExtent(), true);    
    523             } 
     521            layer.redraw(); 
    524522        } 
    525523 
  • trunk/openlayers/tests/test_Layer.html

    r3041 r3582  
    166166    } 
    167167     
     168    function test_Layer_redraw(t) { 
     169        t.plan(8) 
     170 
     171        var name = 'Test Layer'; 
     172        var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 
     173        var params = { map: '/mapdata/vmap_wms.map',  
     174                       layers: 'basic',  
     175                       format: 'image/jpeg'}; 
     176 
     177        var layer = new OpenLayers.Layer.WMS(name, url, params); 
     178         
     179        t.ok(!layer.redraw(), 
     180             "redraw on an orphan layer returns false"); 
     181         
     182        var map = new OpenLayers.Map('map'); 
     183        map.addLayer(layer); 
     184 
     185        t.ok(!layer.redraw(), 
     186             "redraw returns false if map does not yet have a center"); 
     187        map.zoomToMaxExtent(); 
     188         
     189        t.ok(layer.redraw(), 
     190             "redraw returns true after map has a center"); 
     191         
     192        layer.setVisibility(false); 
     193        t.ok(!layer.redraw(), 
     194             "redraw returns false if a layer is not visible"); 
     195         
     196        layer.setVisibility(true); 
     197        t.ok(layer.redraw(), 
     198                "redraw returns true even if extent has not changed"); 
     199         
     200        layer.moveTo = function(bounds, zoomChanged, dragging) { 
     201            var extent = layer.map.getExtent(); 
     202            t.ok(bounds.equals(extent), 
     203                 "redraw calls moveTo with the map extent"); 
     204            t.ok(zoomChanged, 
     205                 "redraw calls moveTo with zoomChanged true"); 
     206            t.ok(!dragging, 
     207                 "redraw calls moveTo with dragging false"); 
     208        } 
     209        layer.redraw(); 
     210         
     211    } 
    168212     
    169213/******