Skip to content

Commit 3b5549e

Browse files
aleksprogergithub-actions[bot]
authored andcommitted
Adopt latest schema for indoor metadata (internal-10317)
GitOrigin-RevId: b930452da7b96d26ad797da552707f0ecb2fbc06
1 parent ee65ba9 commit 3b5549e

2 files changed

Lines changed: 126 additions & 4 deletions

File tree

src/render/indoor_parser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function assignFloorToBuildings(
9191

9292
function parseBuilding(feature: VectorTileFeature): {id: string, center: [number, number]} {
9393
const id = feature.properties.id.toString();
94-
const center = feature.properties.center.toString().split(";").map(Number) as [number, number];
94+
const lon = feature.properties.center_lon as number || 0;
95+
const lat = feature.properties.center_lat as number || 0;
96+
const center: [number, number] = [lon, lat];
9597
return {id, center};
9698
}
9799

@@ -106,8 +108,8 @@ function parseFloor(feature: VectorTileFeature, tileID: CanonicalTileID): {id: s
106108
const conflicts: Set<string> = feature.properties.conflicted_floor_ids ?
107109
new Set(feature.properties.conflicted_floor_ids.toString().split(";")) :
108110
new Set();
109-
const buildings: Set<string> = feature.properties.building_ids ?
110-
new Set(feature.properties.building_ids.toString().split(";")) :
111+
const buildings: Set<string> = feature.properties.structure_ids ?
112+
new Set(feature.properties.structure_ids.toString().split(";")) :
111113
new Set();
112114
const name = feature.properties.name.toString();
113115
const zIndex = feature.properties.z_index as number;
@@ -136,7 +138,7 @@ function hasRequiredProperties(feature: VectorTileFeature, requiredProps: string
136138

137139
function isValidBuildingFeature(feature: VectorTileFeature): boolean {
138140
return hasRequiredProperties(feature, ['type', 'id', 'name']) &&
139-
feature.properties.type === "building";
141+
feature.properties.type === "structure";
140142
}
141143

142144
function isValidFloorFeature(feature: VectorTileFeature): boolean {
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* eslint-disable camelcase, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument */
2+
import {describe, test, expect} from '../../util/vitest';
3+
import {parseActiveFloors} from '../../../src/render/indoor_parser';
4+
import {CanonicalTileID} from '../../../src/source/tile_id';
5+
import Actor from '../../../src/util/actor';
6+
7+
// Mock Actor
8+
const mockTarget = {
9+
addEventListener: () => {},
10+
removeEventListener: () => {},
11+
postMessage: () => {}
12+
};
13+
const actor = new Actor(mockTarget as any, {} as any, 0);
14+
actor.send = () => ({cancel: () => {}});
15+
16+
describe('IndoorParser', () => {
17+
test('parses buildings with center_lat and center_lon', () => {
18+
const feature = {
19+
properties: {
20+
type: 'structure',
21+
id: '123',
22+
name: 'Test Building',
23+
center_lat: 40.7128,
24+
center_lon: -74.0060
25+
},
26+
loadGeometry: () => []
27+
};
28+
29+
const data = {
30+
layers: {
31+
'indoor-layer': {
32+
length: 1,
33+
feature: () => feature
34+
}
35+
}
36+
};
37+
38+
const indoorTileOptions = {
39+
indoorState: {
40+
activeFloorsVisible: false,
41+
activeFloors: new Set(),
42+
selectedFloorId: ''
43+
},
44+
sourceLayers: new Set(['indoor-layer'])
45+
};
46+
47+
let parsedData: any;
48+
actor.send = (type, data) => {
49+
if (type === 'setIndoorData') {
50+
parsedData = data;
51+
}
52+
return {cancel: () => {}};
53+
};
54+
55+
parseActiveFloors(data as any, indoorTileOptions as any, actor, new CanonicalTileID(0, 0, 0));
56+
57+
expect(parsedData).toBeDefined();
58+
expect(parsedData.buildings['123']).toBeDefined();
59+
expect(parsedData.buildings['123'].center).toEqual([-74.0060, 40.7128]);
60+
});
61+
62+
test('parses floors with structure_ids', () => {
63+
const buildingFeature = {
64+
properties: {
65+
type: 'structure',
66+
id: '123',
67+
name: 'Test Building',
68+
center_lat: 40,
69+
center_lon: -74
70+
},
71+
loadGeometry: () => []
72+
};
73+
74+
const floorFeature = {
75+
properties: {
76+
type: 'floor',
77+
id: 'f1',
78+
name: 'Floor 1',
79+
z_index: 0,
80+
structure_ids: '123;456'
81+
},
82+
loadGeometry: () => [[[{x: 0, y: 0}, {x: 10, y: 0}, {x: 10, y: 10}, {x: 0, y: 10}, {x: 0, y: 0}]]]
83+
};
84+
85+
const data = {
86+
layers: {
87+
'indoor-layer': {
88+
length: 2,
89+
feature: (index: number) => (index === 0 ? buildingFeature : floorFeature)
90+
}
91+
}
92+
};
93+
94+
const indoorTileOptions = {
95+
indoorState: {
96+
activeFloorsVisible: false,
97+
activeFloors: new Set(),
98+
selectedFloorId: ''
99+
},
100+
sourceLayers: new Set(['indoor-layer'])
101+
};
102+
103+
let parsedData: any;
104+
actor.send = (type, data) => {
105+
if (type === 'setIndoorData') {
106+
parsedData = data;
107+
}
108+
return {cancel: () => {}};
109+
};
110+
111+
parseActiveFloors(data as any, indoorTileOptions as any, actor, new CanonicalTileID(0, 0, 0));
112+
113+
expect(parsedData).toBeDefined();
114+
expect(parsedData.buildings['123'].floors['f1']).toBeDefined();
115+
expect(parsedData.buildings['123'].floors['f1'].buildings.has('123')).toBe(true);
116+
expect(parsedData.buildings['123'].floors['f1'].buildings.has('456')).toBe(true);
117+
expect(parsedData.buildings['456']).toBeDefined();
118+
expect(parsedData.buildings['456'].floors['f1']).toBeDefined();
119+
});
120+
});

0 commit comments

Comments
 (0)