Skip to content

Commit 21dd7c1

Browse files
committed
Fix queryTerrainElevation (#1922)
1 parent ab4ce5d commit 21dd7c1

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/mapbox/create-ref.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {MapboxMap, LngLatLike, PointLike} from '../types';
1+
import type {MapboxMap, LngLatLike, PointLike, ElevationQueryOptions} from '../types';
22
import type Mapbox from './mapbox';
33

44
/** These methods may break the react binding if called directly */
@@ -50,6 +50,16 @@ export default function createRef(mapInstance: Mapbox, mapLib: any): MapRef {
5050
},
5151
unproject: (point: PointLike) => {
5252
return mapInstance.transform.pointLocation(mapLib.Point.convert(point));
53+
},
54+
queryTerrainElevation: (lnglat: LngLatLike, options: ElevationQueryOptions) => {
55+
// @ts-ignore transform not defined
56+
const tr = map.transform;
57+
// @ts-ignore transform not defined
58+
map.transform = mapInstance.transform;
59+
const result = map.queryTerrainElevation(lnglat, options);
60+
// @ts-ignore transform not defined
61+
map.transform = tr;
62+
return result;
5363
}
5464
};
5565

src/mapbox/mapbox.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -612,18 +612,6 @@ export default class Mapbox {
612612
const renderTransform = cloneTransform(map.transform);
613613
map.painter.transform = renderTransform;
614614

615-
// Terrain update is called by the painter
616-
// Elevation changes must be reflected back to the original transform so that input handlers work correctly
617-
// @ts-ignore method may be undefined
618-
const updateElevation = renderTransform.updateElevation;
619-
if (updateElevation) {
620-
// @ts-ignore
621-
renderTransform.updateElevation = arg => {
622-
map.transform.elevation = renderTransform.elevation;
623-
updateElevation.call(renderTransform, arg);
624-
updateElevation.call(map.transform, arg);
625-
};
626-
}
627615
this._renderTransform = renderTransform;
628616
}
629617

src/types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export type {
1414
FullscreenControl as MapboxFullscreenControl,
1515
GeolocateControl as MapboxGeolocateControl,
1616
NavigationControl as MapboxNavigationControl,
17-
ScaleControl as MapboxScaleControl
17+
ScaleControl as MapboxScaleControl,
18+
ElevationQueryOptions
1819
} from 'mapbox-gl';
1920

2021
/**

0 commit comments

Comments
 (0)