[OpenLayers-Users] spinner for WMS Untiled

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Tue Jan 9 08:55:34 EST 2007


Hi list,

I have finally gotten things to work for having a spinner image for WMS
Untiled. Note this only works for WMS Untiled, but I guess for loading tiles
the user will have enough visual effect anyway of what's going on.

I have added a patch to ticket 452 (http://trac.openlayers.org/ticket/452),
hopefully somebody can review this. I have no problems signing the
contributor agreement if necessary.

If this will be accepted, I can add a section to the Wiki on how this event
can be used within an application. I will do that in this e-mail as well to
start with.

The application should hold a counter variable:

var layerloadcounter = 0;

Three counter functions are necessary:

function setcounterbynumlayers(){
      var layers = map.layers.slice();
      layerloadcounter = layers.length;
      if (layerloadcounter > 0 && activitydiv) { activitydiv.style.zIndex =
1000; }
}
function increasecounter(){
      layerloadcounter++;
      if (layerloadcounter > 0 && activitydiv) { activitydiv.style.zIndex =
1000; }
}
function decreasecounter(){
      if (layerloadcounter > 0) layerloadcounter--;
      if (layerloadcounter == 0 && activitydiv) { activitydiv.style.zIndex =
-1000; }
}

which are tied to OpenLayers events:

map.events.register( 'addlayer', this, increasecounter);
map.events.register( 'removelayer', this, decreasecounter);
map.events.register( 'layerloaded', this, decreasecounter);
map.events.register( 'moveend', this, setcounterbynumlayers);

Finally, there needs to be a div showing the image:

var gMapDHTMLWaitImage = 'yourimageurlgoeshere';
sz = new OpenLayers.Size();
sz.h = 246;
sz.w = 50; 
activitydiv = OpenLayers.Util.createDiv("ActivityLayer", null, sz,
gMapDHTMLWaitImage);
map.viewPortDiv.appendChild(activitydiv);

Best regards,
Bart

--
Bart van den Eijnden
OSGIS, Open Source GIS
http://www.osgis.nl








More information about the Users mailing list