Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to Openlayers and GIS in general. I have a WMS request followed by the addLayer method, and surrounded by the addition and deletion of a 'loading' class to an HTML element:

Map.currentOverlay = new OpenLayers.Layer.WMS(name, Constants.webServices.wms, {
    format: 'image/png',
    tiled: false,
  }, {
    getURL: Projection.getDefaultOverlayUrl 
if (Map.currentOverlay != null) {
  Map.currentOverlay.initialZoom = map.zoom;
  Map.currentOverlay.isBaseLayer = false;
  Map.currentOverlay.visibility = true;{moveend: Map.__onZoomUpdate});

My goal is to add a loading gif in a dialog window (with CSS) while the layer is not displayed yet. According to this post: the request is done in the addLayer method. But it seems asynchronous: the class 'loading' is added and removed straight away, while the map is not yet displayed. Can I add a callback or something similar to addLayer ? If not, how do I do?

NB: I didn't produce the above code, I just added the "loading" behaviour. Do not hesitate to tell me if something seems wrong with it.

share|improve this question
up vote 3 down vote accepted

You can use the loadstart and loadend events on the layer to handle this. This example ( shows the basics of how to get it working.

share|improve this answer

You can find the following example useful:

Essentialy, the OpenLayers API gives you the layer events 'loadstart', 'loadend' and 'tileloaded'. When you register these events, you can 'hook' functions that, for example, can show a loading indicator.

share|improve this answer
Thanks to both of you. – pH Cito Nov 13 '12 at 13:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.