Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CompositeLayer,
CompositeLayerProps,
COORDINATE_SYSTEM,
CoordinateSystem,
FilterContext,
GetPickingInfoParams,
Layer,
Expand All @@ -32,6 +33,30 @@ import {Tiles3DLoader} from '@loaders.gl/3d-tiles';

const SINGLE_DATA = [0];

/**
* Numeric `COORDINATE_SYSTEM` values used by deck.gl before v9.3, still emitted on tile content by
* released versions of loaders such as `@loaders.gl/i3s`. Mapped back to the string constants that
* the layers understand.
*/
const LEGACY_COORDINATE_SYSTEMS: Record<number, CoordinateSystem> = {
[-1]: COORDINATE_SYSTEM.DEFAULT,
0: COORDINATE_SYSTEM.CARTESIAN,
1: COORDINATE_SYSTEM.LNGLAT,
2: COORDINATE_SYSTEM.METER_OFFSETS,
3: COORDINATE_SYSTEM.LNGLAT_OFFSETS
};

/** @internal Exported for testing. */
export function normalizeCoordinateSystem(
coordinateSystem: CoordinateSystem | number
): CoordinateSystem | number {
if (typeof coordinateSystem === 'number') {
// Unrecognized values are passed through so that the core reports `Invalid coordinateSystem`
return LEGACY_COORDINATE_SYSTEMS[coordinateSystem] ?? coordinateSystem;
}
return coordinateSystem;
}

const defaultProps: DefaultProps<Tile3DLayerProps> = {
getPointColor: {type: 'accessor', value: [0, 0, 0, 255]},
pointSize: 1.0,
Expand Down Expand Up @@ -419,7 +444,7 @@ export default class Tile3DLayer<DataT = any, ExtraPropsT extends {} = {}> exten
pbrMaterial: material,
modelMatrix,
coordinateOrigin: cartographicOrigin,
coordinateSystem,
coordinateSystem: normalizeCoordinateSystem(coordinateSystem),
featureIds,
_offset: 0
}
Expand Down
21 changes: 20 additions & 1 deletion test/modules/geo-layers/tile-3d-layer/tile-3d-layer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ import {test, expect} from 'vitest';

import {LayerTestCase, testLayerAsync} from '@deck.gl/test-utils/vitest';
import {Tile3DLayer} from '@deck.gl/geo-layers';
import {WebMercatorViewport} from '@deck.gl/core';
import {normalizeCoordinateSystem} from '@deck.gl/geo-layers/tile-3d-layer/tile-3d-layer';
import {COORDINATE_SYSTEM, WebMercatorViewport} from '@deck.gl/core';

test('Tile3DLayer#normalizeCoordinateSystem', () => {
// Loaders that predate the v9.3 string constants report numeric values, see issue #10368
expect(normalizeCoordinateSystem(-1)).toBe(COORDINATE_SYSTEM.DEFAULT);
expect(normalizeCoordinateSystem(0)).toBe(COORDINATE_SYSTEM.CARTESIAN);
expect(normalizeCoordinateSystem(1)).toBe(COORDINATE_SYSTEM.LNGLAT);
expect(normalizeCoordinateSystem(2)).toBe(COORDINATE_SYSTEM.METER_OFFSETS);
expect(normalizeCoordinateSystem(3)).toBe(COORDINATE_SYSTEM.LNGLAT_OFFSETS);

// String constants pass through untouched
expect(normalizeCoordinateSystem(COORDINATE_SYSTEM.METER_OFFSETS)).toBe(
COORDINATE_SYSTEM.METER_OFFSETS
);
expect(normalizeCoordinateSystem(COORDINATE_SYSTEM.LNGLAT)).toBe(COORDINATE_SYSTEM.LNGLAT);

// Unknown numeric values are passed through so that the core validation reports them
expect(normalizeCoordinateSystem(42)).toBe(42);
});

test('Tile3DLayer', async () => {
const testCases: LayerTestCase<Tile3DLayer>[] = [
Expand Down