maplibre-gl
Version:
BSD licensed community fork of mapbox-gl, a WebGL interactive maps library
45 lines (36 loc) • 1.23 kB
text/typescript
import type {Map} from '../map';
import type {PointLike} from '../camera';
import type {IReadonlyTransform} from '../../geo/transform_interface';
import Point from '@mapbox/point-geometry';
import {type LngLat} from '../../geo/lng_lat';
/**
* @internal
* Shared utilities for the Handler classes to access the correct camera state.
* If Camera.transformCameraUpdate is specified or terrain is enabled, the
* "desired state" of camera may differ from the state used for rendering. The
* handlers need the "desired state" to track accumulated changes.
*/
export class TransformProvider {
_map: Map;
constructor(map: Map) {
this._map = map;
}
get transform(): IReadonlyTransform {
return this._map._requestedCameraState || this._map.transform;
}
get center() {
return {lng: this.transform.center.lng, lat: this.transform.center.lat};
}
get zoom() {
return this.transform.zoom;
}
get pitch() {
return this.transform.pitch;
}
get bearing() {
return this.transform.bearing;
}
unproject(point: PointLike): LngLat {
return this.transform.screenPointToLocation(Point.convert(point), this._map.terrain);
}
}