Skip to content

Commit 6a00b9c

Browse files
committed
fix: mapbox-gl v3 incompatibility
- Fixes code incompatible with `mapbox-gl` v3.0.1: - Renames `Style._getLayerSourceCache` to `Style.getOwnLayerSourceCache` - Changes the signature of `CollisionIndex.projectAndGetPerspectiveRatio`. Expands the second parameter to three parameters [x, y, z]. Updates `calculateCollisionBox` to align with the latest `mapbox-gl` code. issue #3
1 parent ab8f477 commit 6a00b9c

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function collectCollisionBoxesAndFeatures(
6868
throw new RangeError(`layer "${layerId}" is not a symbol layer`);
6969
}
7070
await waitForPlacement(placement, PLACEMENT_TIMEOUT_IN_MS);
71-
const sourceCache = style._getLayerSourceCache(layer);
71+
const sourceCache = style.getOwnLayerSourceCache(layer);
7272
if (sourceCache == null) {
7373
throw new Error(`no SourceCache available`);
7474
}

src/private/collision-index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
*
1616
* This function mocks the collision box calculation of
1717
* `CollisionIndex#placeCollisionBox`.
18-
* https://github.com/mapbox/mapbox-gl-js/blob/e29e113ff5e1f4c073f84b8cbe546006d2fb604f/src/symbol/collision_index.js#L94-L143
18+
* https://github.com/mapbox/mapbox-gl-js/blob/922da6dd02dbcc1ccd852cebba8b830a070d46ca/src/symbol/collision_index.js#L90-L140
1919
*
2020
* @beta
2121
*/
@@ -36,29 +36,30 @@ export function calculateCollisionBox(
3636
let anchorY = box.projectedAnchorY;
3737
let anchorZ = box.projectedAnchorZ;
3838
const { elevation, tileID } = box;
39+
const projection = bucket.getProjection()
3940
if (elevation && tileID) {
40-
const up = bucket
41-
.getProjection()
41+
const [ux, uy, uz] = projection
4242
.upVector(tileID.canonical, box.tileAnchorX, box.tileAnchorY);
43-
const upScale = bucket
44-
.getProjection()
43+
const upScale = projection
4544
.upVectorScale(
4645
tileID.canonical,
4746
collisionIndex.transform.center.lat,
4847
collisionIndex.transform.worldSize,
4948
)
5049
.metersToTile;
51-
anchorX += up[0] * elevation * upScale;
52-
anchorY += up[1] * elevation * upScale;
53-
anchorZ += up[2] * elevation * upScale;
50+
anchorX += ux * elevation * upScale;
51+
anchorY += uy * elevation * upScale;
52+
anchorZ += uz * elevation * upScale;
5453
}
5554
const checkOcclusion =
5655
bucket.projection.name === 'globe' ||
5756
!!elevation ||
5857
collisionIndex.transform.pitch > 0;
5958
const projectedPoint = collisionIndex.projectAndGetPerspectiveRatio(
6059
posMatrix,
61-
[anchorX, anchorY, anchorZ],
60+
anchorX,
61+
anchorY,
62+
anchorZ,
6263
box.tileID,
6364
checkOcclusion,
6465
bucket.getProjection(),

src/private/mapbox-types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare module 'mapbox-gl' {
3333
_serializedLayers: { [layerId: string]: StyleLayer };
3434
_availableImages: string[];
3535

36-
_getLayerSourceCache(layer: StyleLayer): SourceCache | undefined;
36+
getOwnLayerSourceCache(layer: StyleLayer): SourceCache | undefined;
3737
}
3838
}
3939

@@ -56,7 +56,9 @@ export interface CollisionIndex {
5656

5757
projectAndGetPerspectiveRatio(
5858
posMatrix: mat4,
59-
point: vec3,
59+
x: number,
60+
y: number,
61+
z: number,
6062
tileID: OverscaledTileID | undefined | null,
6163
checkOcclusiion: boolean,
6264
bucketProjection: Projection,

0 commit comments

Comments
 (0)