How do I subscribe to OpenLayers 5.3.0 events in JavaScript?

by Christopher Stevens   Last Updated May 21, 2019 21:22 PM

I see that OpenLayers 5.3.0 is making use of observables. The docs also cover events.

How would I alter this starting example to .subscribe() to events in general? I'm struggling bridging the gap between docs and use.

import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';

new Map({
  target: 'map',
  layers: [
    new TileLayer({
      source: new XYZ({
        url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
      })
    })
  ],
  view: new View({
    center: [0, 0],
    zoom: 2
  })
});

I did see a more recent, similar question here with helpful resources listed. I could use a script example to help get started.



Related Questions


Updated August 09, 2015 17:09 PM

Updated May 24, 2017 06:22 AM

Updated June 09, 2017 15:22 PM

Updated November 20, 2018 13:22 PM

Updated September 23, 2017 04:22 AM