[GIS] Triggering events when loading and finished loading from WMS

openlayersopenlayers-2

I'm currently creating a webgis application using OpenLayers 3.0.0, and I'm trying to display a loading gizmo when loading layers from a WMS. I've found examples for OL 2.1.0 that registers 'loadstart' and 'loadend' events.

However I haven't had any success with registering those events in OL 3.0.

Anyone got any pointers on how to do this or know if this is even possible to do in OL 3.0?

Thanks!

Best Answer

this works fine: Trigger event once layer is loaded

for example:

var wmssource =
new ol.source.ImageWMS({
    url: 'http://localhost:8080/geoserver/routing/wms',
    imageLoadFunction: function(image, src) {
        var imageElement = image.getImage();
        imageElement.onload = function() {
            console.log('loaded');
            $('#spinner').hide();
        };
        imageElement.src = src;
    }
});
var result = new ol.layer.Image({
source: wmssource
});
map.addLayer(result);
$('#spinner').show();