openlayers 3 - How to execute some code whenever the user interacts with the map? -


i have openlayers 3.9.0 map. have pair of lonlat coordinates tracking external source , updating onto map. continuously re-centering map on these coordinates:

function gets_called_when_i_have_updated_coords() {     map.getview.setcenter(coords); } 

what want disable auto-centering whenever user interacts map. in other words, want this:

var auto_center = true;  function gets_called_when_i_have_updated_coords() {     if (auto_center) {         map.getview.setcenter(coords);     } }  function user_started_interacting() {     auto_center = false; } // should function attached to? // where.on('what?', user_started_interacting); 

i don't know how detect user interaction.

i expected the default interactions had kind of event, when user starts dragging/rotating/zooming map, event triggered , code run. not find such event.

here, user dragging:

map.on('pointermove', function(evt){     if(evt.dragging){         //user interacting         console.info('dragging');     } }); 

here, user changing resolution:

map.getview().on('change:resolution', function(evt){     console.info(evt); }); 

update

some options detect keyboard interaction:

//unofficial && undocumented map.on('key', function(evt){     console.info(evt);     console.info(evt.originalevent.keyidentifier); }); //dom listener map.gettargetelement().addeventlistener('keydown', function(evt){     console.info(evt);     console.info(evt.keyidentifier); }); 

a fiddle test.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -