Search code examples
javascriptobservableopenlayersopenlayers-5

Openlayers 5 How to watch for view.center changes


I'm currently working on a project to use openlayers 5's observable to observe some items in the map and respond accordingly.

http://openlayers.org/en/latest/apidoc/module-ol_Observable-Observable.html

What I want to do is every time the view's center changes, I want to call a function. I'm doing this currently (but its not working).

view.on('center', function(event){
    // do something with the center
});

Any tips?


Solution

  • Got it. I was missing the text "change".

    view.on('change:center', function(){});