OpenLayers OpenLayers

Ticket #795: redraw.4.patch

File redraw.4.patch, 6.2 kB (added by tschaub, 1 year ago)

same as 3 above but with tests and 2 other cases where redraw could be used

  • tests/test_Layer.html

    old new  
    165165 
    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/****** 
    170214 *  
  • lib/OpenLayers/Layer.js

    old new  
    335335    }, 
    336336 
    337337    /** 
     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; 
     360    }, 
     361 
     362    /** 
    338363     * Method: moveTo 
    339364     *  
    340365     * Parameters: 
     
    451476        if (visibility != this.visibility) { 
    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))) { 
    462482                this.map.events.triggerEvent("changelayer"); 
  • lib/OpenLayers/Map.js

    old new  
    518518                layer.setVisibility(false); 
    519519            } 
    520520        } else { 
    521             if (this.getCenter() != null) { 
    522                 layer.moveTo(this.getExtent(), true);    
    523             } 
     521            layer.redraw(); 
    524522        } 
    525523 
    526524        this.events.triggerEvent("addlayer"); 
  • lib/OpenLayers/Layer/Markers.js

    old new  
    7272        OpenLayers.Layer.prototype.moveTo.apply(this, arguments); 
    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        } 
    7880    }, 
     
    116118        } 
    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 
    132123     * Calculate the pixel location for the marker, create it, and  
  • lib/OpenLayers/Layer/MapServer/Untiled.js

    old new  
    241241     */ 
    242242    setUrl: function(newUrl) { 
    243243        OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments); 
    244         this.moveTo(); 
     244        this.redraw(); 
    245245    }, 
    246246 
    247247    /**  
     
    254254    mergeNewParams:function(newParams) { 
    255255        OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,  
    256256                                                                 [newParams]); 
    257         //redraw 
    258         this.moveTo(null, true); 
     257        this.redraw(); 
    259258    }, 
    260259     
    261260    /**  
  • lib/OpenLayers/Layer/WMS/Untiled.js

    old new  
    257257     */ 
    258258    setUrl: function(newUrl) { 
    259259        OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments); 
    260         this.moveTo(); 
     260        this.redraw(); 
    261261    }, 
    262262 
    263263    /** 
     
    272272        var newArguments = [upperParams]; 
    273273        OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,  
    274274                                                                 newArguments); 
    275         //redraw 
    276         this.moveTo(null, true); 
     275        this.redraw(); 
    277276    }, 
    278277     
    279278    /**