diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 8a80a24b83..d71754a957 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -971,6 +971,35 @@ declare namespace mapboxgl { static convert(a: PointLike): Point; } + /** + * MercatorCoordinate + */ + export class MercatorCoordinate { + /** The x component of the position. */ + x: number; + + /** The y component of the position. */ + y: number; + + /** + * The z component of the position. + * + * @default 0 + */ + z?: number; + + constructor(x: number, y: number, z?: number); + + /** Returns the altitude in meters of the coordinate. */ + toAltitude(): number; + + /** Returns the LngLat for the coordinate. */ + toLngLat(): LngLat; + + /** Project a LngLat to a MercatorCoordinate. */ + static fromLngLat(lngLatLike: LngLatLike, altitude?: number): MercatorCoordinate; + } + /** * Marker */ diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts index 92f0c6c7c7..02325c4e8c 100644 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ b/types/mapbox-gl/mapbox-gl-tests.ts @@ -407,6 +407,7 @@ attributionControl.on('click', () => {}); declare var lnglat: mapboxgl.LngLat; declare var lnglatlike: mapboxgl.LngLatLike; declare var lnglatboundslike: mapboxgl.LngLatBoundsLike; +declare var mercatorcoordinate: mapboxgl.MercatorCoordinate; declare var pointlike: mapboxgl.PointLike; function expectType(value: T) { /* let the compiler handle things */ } @@ -460,6 +461,17 @@ expectType([0, 0]); new mapboxgl.Point(0, 0); expectType(mapboxgl.Point.convert(pointlike)); +/* + * MercatorCoordinate + */ + +new mapboxgl.MercatorCoordinate(0, 0); +new mapboxgl.MercatorCoordinate(0, 0, 0); +expectType(mercatorcoordinate.toAltitude()); +expectType(mercatorcoordinate.toLngLat()); +expectType(mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike)); +expectType(mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike, 0)); + /* * TransformRequestFunction */