on method

MapboxMap on(
  1. String type,
  2. [dynamic layerIdOrListener,
  3. Listener? listener]
)

Adds a listener to a specified event type.

@param {string} type The event type to add a listen for. @param {Function} listener The function to be called when the event is fired. The listener function is called with the data object passed to fire, extended with target and type properties. @returns {Object} this

Implementation

MapboxMap on(String type, [dynamic layerIdOrListener, Listener? listener]) {
  if (this is GeolocateControl && layerIdOrListener is GeoListener) {
    return MapboxMap.fromJsObject(
      jsObject.on(type, allowInterop(
        (dynamic position) {
          layerIdOrListener(position);
        },
      )),
    );
  }
  if (layerIdOrListener is Listener) {
    return MapboxMap.fromJsObject(
      jsObject.on(type, allowInterop(
        (EventJsImpl object) {
          layerIdOrListener(Event.fromJsObject(object));
        },
      )),
    );
  }
  return MapboxMap.fromJsObject(
      jsObject.on(type, layerIdOrListener, allowInterop(
    (EventJsImpl object) {
      listener!(Event.fromJsObject(object));
    },
  )));
}