Search code examples
openlayersopenlayers-3

Check for a pending map redraw


Is there a way to detect a pending map redraw? For example

map.getView.setCenter([x, y])

will not cause a map redraw if x and y are the same as current center, but will cause a redraw if they are different than the current view center. (At least that seems to be what I'm seeing, please correct me if I'm mistaken).

So I want to check the map to see if a redraw will happen. Obviously in this simple example I could test the x,y values for myself, but I have several similar things that I'm doing so it would be cleaner if I could just check the map once at the end.


Solution

  • This does what I want. I still feel like there should be a better way

    var pendingRedraw = false;
    var movestartHandler = map.on('movestart',  function(evt)  {
        pendingRedraw = true;
    });
    /*
        code that may, or may not, trigger a map redraw
    */
    unByKey(movestartHandler);  // un-register the handler
    if (pendingRedraw) {
        // now I know what I want to know! 
    }