OpenLayers OpenLayers

Changeset 2200

Show
Ignore:
Timestamp:
02/04/07 11:13:15 (2 years ago)
Author:
euzuro
Message:

patch for #452 - Adding events to Layer class to signal the start, end, and cancelling of a layer load. Thanks to Bart for the idea and followthrough with this patch.

Files:

Legend:

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

    r2018 r2200  
    1818    /** @type DOMElement */ 
    1919    div: null, 
     20 
     21    /** supported application event types 
     22     *  
     23     * @type Array */ 
     24    EVENT_TYPES: [  
     25        "loadstart", "loadend", "loadcancel"], 
     26 
     27    /** @type OpenLayers.Events */ 
     28    events: null, 
    2029 
    2130    /** This variable is set when the layer is added to the map, via the  
     
    122131            this.div.id = this.id; 
    123132        } 
     133 
     134        this.events = new OpenLayers.Events(this, this.div, this.EVENT_TYPES); 
    124135    }, 
    125136     
     
    136147        this.div = null; 
    137148        this.options = null; 
     149        this.events = null; 
    138150    }, 
    139151     
  • trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js

    r2074 r2200  
    3131    /** @type OpenLayers.Tile.Image */ 
    3232    tile: null, 
    33      
     33 
     34    /** did the image finish loading before a new draw was initiated? 
     35     * @type Boolean */ 
     36    doneLoading: false, 
    3437 
    3538    /** 
     
    109112     */ 
    110113    moveTo:function(bounds, zoomChanged, dragging) { 
     114        if (!this.doneLoading) { 
     115            this.events.triggerEvent("loadcancel");  
     116            this.doneLoading = true;  
     117        } 
    111118        OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this,arguments); 
    112119         
     
    156163            } 
    157164 
     165            this.events.triggerEvent("loadstart"); 
     166            this.doneLoading = false; 
    158167            if (!this.tile) { 
    159168                this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,  
    160169                                                     url, tileSize); 
    161170                this.tile.draw(); 
     171                var onload = function() {  
     172                    this.doneLoading = true;  
     173                    this.events.triggerEvent("loadend");  
     174                } 
     175                OpenLayers.Event.observe(this.tile.imgDiv, 'load', 
     176                                         onload.bindAsEventListener(this)); 
    162177            } else { 
    163178                this.tile.moveTo(tileBounds, pos);