Search code examples
javascriptopenlayers-3

openlayers-3 change cursor while waiting


How can I change the cursor while waiting for some action to end ? With the code below, the cursor does not change. I think I need to refresh, but I don't know how to trigger that.

map.on('singleclick', function(evt) {
    myfunc(evt); });

myfunc(evt) {
    map.getViewport().style.cursor = 'wait';
    // do some lengthy processing
    map.getViewport().style.cursor = 'pointer';
    }

Solution

  • map.on('singleclick', myfunc);
    
    var myfunc = function(evt) {
        map.getTargetElement().style.cursor = 'wait';
        // do some lengthy processing
        map.getTargetElement().style.cursor = 'pointer';
    }
    

    Use getTargetElement(). Also, no need to create an anonymous function.