Stopping Loading Layers

THL Toolbox > Developers' Zone > Gis Development > Stopping Loading Layers

Stopping Loading Layers

Contributor(s): Tom Benner

As of OpenLayers 2.8, the .destroy() method of the OpenLayers.Tile.Image class sets the src of the image to a blank GIF, so as to stop the tile image from continuing to load and use up resources when it is no longer necessary. As a result, when removing a layer, you can call .destroy() on the layer to completely stop any subsequent HTTP requests or image loading from occurring. With versions prior to 2.8, it would likely be necessary to edit the OL source, or add a lot of class extensions, for this to work.

To determine whether a layer is still loading or not, checking whether (layer.numLoadingTiles > 0) is true seems like it would work, but it doesn't seem to be accurate in certain cases. If you're using a custom layer class (as described here), a workaround is to add an "isLoaded" property with a default of "false", and set this property to true on the layer's "loadend" event by adding the following to the class's initialize() function:

this.events.register("loadend", this, function() {
	this.isLoaded = true;
});

Provided for unrestricted use by the external link: Tibetan and Himalayan Library