Options
All
  • Public
  • Public/Protected
  • All
Menu

The classes in this module need to be seeded with an OpenLayers Map or View.

They do not require it in the constructor, but instead allow for a lazy hook once the Map or View has been created (say, based on an asynchronously loaded capabilities file).

I.e. you can instantiate them – typically carried in a singleton-style service orchestrating the needed utilities – and pass them to the rest of the application, wiring your own functionality to them. They will begin working and emitting data once they are hooked into a map with the setMap or setView methods.

example

E.g. an application could be bootstrapped something like this:

import { MapLocationAnchor, MouseEvents } from '../map-utilities';
import { Map } from 'ol';

window.addEventListener('DOMContentLoaded', () => {
  new MyApplication(new MapService());
});

class MapService {
  readonly mouseEvents = new MouseEvents();
  readonly mapLocationAnchor = new MapLocationAnchor();

  constructor() {
    this.createMapAsynchronously()
      .then(map => {
        this.mouseEvents.setMap(map);
        this.mapLocationAnchor.setView(map.getView());
      })
  }

  private createMapAsynchronously(): Promise<Map> {
    ...
  }
}

class MyApplication {
  constructor(mapService: MapService) {
    mapService.mouseEvents.clicks
      .subscribe(click => {
        ...
      });
    ...
  }
}

Index

Functions

mouseCoordinateConverter

  • mouseCoordinateConverter(targetProjectionLike: ProjectionLike): (e: MapBrowserEvent) => Coordinate
  • Creates a function which maps the coordinates in a MapBrowserEvent to coordinates in a given CRS, automatically taking into account with the map view's CRS is.

    example
    this.mapService.mouseEvents.clicks.pipe(
      map(mouseCoordinateConverter('epsg:25832'))
    )
    

    If the event can be undefined (such as when using the MouseEvents.moves), wrap the function in a null-safe wrapper, e.g. using Ginnungagap:

    example
    this.mapService.mouseEvents.moves.pipe(
      map(nullSafe(mouseCoordinateConverter('epsg:25832')))
    )
    

    Parameters

    • targetProjectionLike: ProjectionLike

    Returns (e: MapBrowserEvent) => Coordinate

      • (e: MapBrowserEvent): Coordinate
      • Parameters

        • e: MapBrowserEvent

        Returns Coordinate