Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Layers 3 Zoom map event handler

I need to handle a zoom event in Open Layers 3.

The following is my code:

map_object = new ol.Map({
target: 'map',
controls: controls_list,
interactions: interactions_list,
overlays: [overlay],
layers: [OSM_raster, WFS_layer],
    view: view
});


map_object.on("Zoom", function() {
  console.log('Zooming...');
});

This code runs with no errors and shows a map, but there is no output to the console, suggesting this function isn't firing.

I have also tried:

map_object.on("drag", function() {
  console.log('Dragging...');
});

And this too does nothing.

Any help as to how to handle map control events in OL3 would be much appreciated (particularly zooming!). Note I have tried 'zoom' as well as 'Zoom' for the type field of the on method.

like image 628
Single Entity Avatar asked Nov 04 '14 11:11

Single Entity


2 Answers

Just to add to this, you can check variations of events available with 'propertychange', from what I am seeing, there is no explicit .on ('zoom', ...) but rather you can access 'resolution' and other properties as mentioned in previous comments:

map.getView().on('propertychange', function(e) {
   switch (e.key) {
      case 'resolution':
        console.log(e.oldValue);
        break;
   }
});
like image 70
ako977 Avatar answered Nov 02 '22 02:11

ako977


try with moveend event. (see https://openlayers.org/en/latest/apidoc/module-ol_MapEvent-MapEvent.html#event:moveend).

like image 41
tonio Avatar answered Nov 02 '22 04:11

tonio