Skip to content

Commit 2949112

Browse files
aleksprogergithub-actions[bot]
authored andcommitted
Indoor style and logic cleanup (internal-6361)
GitOrigin-RevId: 7de804b6299441d6805d4bc988a836deeba83241
1 parent 348c7d6 commit 2949112

File tree

6 files changed

+112
-112
lines changed

6 files changed

+112
-112
lines changed

debug/indoor/indoor_style.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function isSelectedFloor() {
22
// True if the current level is selected
3-
return ["in", ["get", "floor_id"], ["config", "mbx-indoor-level-selected"]]
3+
return ["in", ["get", "floor_id"], ["config", "activeFloors"]]
44
}
55

66
function isSelectedFloorBase() {
77
// True if the current level is selected
8-
return ["in", ["get", "id"], ["config", "mbx-indoor-level-selected"]]
8+
return ["in", ["get", "id"], ["config", "activeFloors"]]
99
}
1010

1111
const indoorLayers = [
@@ -17,7 +17,7 @@ const indoorLayers = [
1717
"minzoom": 16.0,
1818
"filter": [
1919
"all",
20-
[ ">", ["length", ["config", "mbx-indoor-level-selected"]], 0],
20+
[ ">", ["length", ["config", "activeFloors"]], 0],
2121
["==", ["get", "shape_type"], "building"],
2222
],
2323
"layout": {
@@ -33,7 +33,7 @@ const indoorLayers = [
3333
"slot": "middle",
3434
"filter": [
3535
"all",
36-
[ ">", ["length", ["config", "mbx-indoor-level-selected"]], 0],
36+
[ ">", ["length", ["config", "activeFloors"]], 0],
3737
["==", ["geometry-type"], "Polygon"],
3838
["in", ["get", "shape_type"], ["literal", ["building"]]],
3939
],
@@ -55,7 +55,7 @@ const indoorLayers = [
5555
// NOTE: In reality we mustn't rely on *_metadata layers, but in current example we need to use them due to internal implementation of indoor with QRF, this will be changed
5656
{
5757
"type": "fill",
58-
"id": "building-outline",
58+
"id": "building-metadata",
5959
"source": "indoor-source",
6060
"source-layer": "indoor_structure_metadata",
6161
"minzoom": 15.0,
@@ -75,7 +75,7 @@ const indoorLayers = [
7575
// NOTE: In reality we mustn't rely on *_metadata layers, but in current example we need to use them due to internal implementation of indoor with QRF, this will be changed
7676
{
7777
"type": "fill",
78-
"id": "floor-outline",
78+
"id": "floor-metadata",
7979
"source": "indoor-source",
8080
"source-layer": "indoor_floor_metadata",
8181
"minzoom": 15.0,
@@ -421,11 +421,17 @@ const style = {
421421
url: '',
422422
data: {
423423
version: 8,
424+
schema: {
425+
"activeFloors": {
426+
"default": "[]",
427+
}
428+
},
429+
// NOTE: In reality we mustn't rely on *_metadata layers, but in current example we need to use them due to internal implementation of indoor with QRF, this will be changed
424430
featuresets: {
425-
"building-outline": {
431+
"building-metadata": {
426432
"selectors": [
427433
{
428-
"layer": "building-outline",
434+
"layer": "building-metadata",
429435
"properties": {
430436
"id": ["get", "id"],
431437
"type": ["get", "type"],
@@ -434,10 +440,10 @@ const style = {
434440
}
435441
]
436442
},
437-
"floor-outline": {
443+
"floor-metadata": {
438444
"selectors": [
439445
{
440-
"layer": "floor-outline",
446+
"layer": "floor-metadata",
441447
"properties": {
442448
"id": ["get", "id"],
443449
"is_default": ["get", "is_default"],
@@ -459,9 +465,10 @@ const style = {
459465
"url": "mapbox://mapbox-geodata.indoor-v2-next"
460466
}
461467
},
468+
// Left it style but empty as indoor_manager depends on it to be present, will change it in future
462469
indoor: {
463-
floorplanFeaturesetId: "floorplan-detection",
464-
buildingFeaturesetId: "building-entry"
470+
floorplanFeaturesetId: "",
471+
buildingFeaturesetId: ""
465472
},
466473
layers: indoorLayers,
467474
glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf"

src/style/indoor_data_query.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,77 @@
11
import Point from '@mapbox/point-geometry';
22

3-
import type {TargetFeature} from "../util/vectortile_to_geojson";
4-
import type {QueryRenderedFeaturesetParams} from "./style";
3+
import type {GeoJSONFeature} from "../util/vectortile_to_geojson";
54
import type {Map} from "../ui/map";
65
import type {PointLike} from "../types/point-like";
76

87
export type IndoorData = {
9-
building: TargetFeature;
10-
floors: Array<TargetFeature>;
8+
building: IndoorDataBuilding;
9+
floors: Array<IndoorDataFloor>;
1110
};
1211

13-
export class IndoorDataQuery {
14-
_scope: string;
15-
_buildingQueryParams: QueryRenderedFeaturesetParams;
16-
_floorQueryParams: QueryRenderedFeaturesetParams;
17-
18-
// eslint-disable-next-line no-warning-comments
19-
// TODO: Don't use hardcoded featureset ids
20-
constructor(scope: string) {
21-
this._scope = scope;
22-
this._buildingQueryParams = {
23-
target: {
24-
featuresetId: "building-outline",
25-
importId: this._scope
26-
}
27-
};
28-
this._floorQueryParams = {
29-
target: {
30-
featuresetId: "floor-outline",
31-
importId: this._scope
32-
}
33-
};
34-
}
12+
export type IndoorDataBuilding = {
13+
id: string;
14+
name: string;
15+
};
16+
17+
export type IndoorDataFloor = {
18+
id: string;
19+
name: string;
20+
isDefault: boolean;
21+
zIndex: number;
22+
connectedFloorIds: string | null;
23+
conflictedFloorIds: string | null;
24+
buildingIds: string;
25+
};
3526

27+
export class IndoorDataQuery {
3628
execute(map: Map): IndoorData | null {
3729
const buildingsQueryArea = this._makeBuildingsQueryArea(map);
3830
const floorsQueryArea = this._makeFloorsQueryArea(map);
3931

40-
const buildingFeatures = map.queryRenderedFeatures(buildingsQueryArea, this._buildingQueryParams).reduce((unique, feature) => {
32+
const buildingFeatures = map.queryRenderedFeatures(buildingsQueryArea).reduce((unique, feature) => {
4133
const id = feature.properties.id as string;
4234
const shapeType = feature.properties.type as string;
4335
if (shapeType === "building" && !unique.some(existing => existing.properties.id === id)) {
4436
unique.push(feature);
4537
}
4638
return unique;
47-
}, [] as Array<TargetFeature>);
39+
}, [] as Array<GeoJSONFeature>);
4840

49-
const floorFeatures = map.queryRenderedFeatures(floorsQueryArea, this._floorQueryParams).reduce((unique, feature) => {
41+
const floorFeatures = map.queryRenderedFeatures(floorsQueryArea).reduce((unique, feature) => {
5042
const id = feature.properties.id as string;
5143
const shapeType = feature.properties.type as string;
5244
if (shapeType === "floor" && !unique.some(existing => existing.properties.id === id)) {
5345
unique.push(feature);
5446
}
5547
return unique;
56-
}, [] as Array<TargetFeature>);
48+
}, [] as Array<GeoJSONFeature>);
5749

5850
const centerPoint: [number, number] = [map.getCenter().lng, map.getCenter().lat];
5951
const closestBuilding = this._findBuildingAtCenter(centerPoint, buildingFeatures);
6052
const anyBuilding = buildingFeatures.length > 0 ? buildingFeatures[0] : null;
6153

54+
const floorData = floorFeatures.map(floor => ({
55+
id: floor.properties.id as string,
56+
name: floor.properties.name as string,
57+
isDefault: floor.properties.is_default as boolean,
58+
zIndex: floor.properties.z_index as number,
59+
connectedFloorIds: floor.properties.connected_floor_ids as string,
60+
conflictedFloorIds: floor.properties.conflicted_floor_ids as string,
61+
buildingIds: floor.properties.building_ids as string
62+
}));
63+
64+
const buildingData = closestBuilding ? {
65+
id: closestBuilding.properties.id as string,
66+
name: closestBuilding.properties.name as string
67+
} : {
68+
id: anyBuilding.properties.id as string,
69+
name: anyBuilding.properties.name as string
70+
};
71+
6272
return {
63-
floors: floorFeatures,
64-
building: closestBuilding ? closestBuilding : anyBuilding
73+
floors: floorData,
74+
building: buildingData
6575
};
6676
}
6777

@@ -87,7 +97,7 @@ export class IndoorDataQuery {
8797
return [new Point(0, 0), new Point(width, height)];
8898
}
8999

90-
_findBuildingAtCenter(centerPoint: [number, number], buildings: Array<TargetFeature>): TargetFeature | null {
100+
_findBuildingAtCenter(centerPoint: [number, number], buildings: Array<GeoJSONFeature>): GeoJSONFeature | null {
91101
for (const building of buildings) {
92102
if (building.geometry.type === 'Polygon') {
93103
const coordinates = building.geometry.coordinates[0];

src/style/indoor_features_storage.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type {TargetFeature} from "../util/vectortile_to_geojson";
2-
import type {IndoorData} from "./indoor_data_query";
1+
import type {IndoorData, IndoorDataBuilding, IndoorDataFloor} from "./indoor_data_query";
32

43
export default class IndoorFeaturesStorage {
5-
_floors: Map<string, TargetFeature>;
6-
_buildings: Map<string, TargetFeature>;
4+
_floors: Map<string, IndoorDataFloor>;
5+
_buildings: Map<string, IndoorDataBuilding>;
76

87
constructor() {
98
this._floors = new Map();
@@ -14,7 +13,7 @@ export default class IndoorFeaturesStorage {
1413
const building = indoorData.building;
1514
let hasChanges = false;
1615
if (building) {
17-
const buildingId = building.properties.id as string;
16+
const buildingId = building.id;
1817
if (buildingId) {
1918
this._buildings.set(buildingId, building);
2019
if (!hasChanges && !this._buildings.has(buildingId)) {
@@ -24,7 +23,7 @@ export default class IndoorFeaturesStorage {
2423
}
2524

2625
indoorData.floors.forEach(newFloor => {
27-
const floorId = newFloor.properties.id as string;
26+
const floorId = newFloor.id;
2827
if (!hasChanges && !this._floors.has(floorId)) {
2928
hasChanges = true;
3029
}
@@ -39,11 +38,11 @@ export default class IndoorFeaturesStorage {
3938
this._buildings.clear();
4039
}
4140

42-
getFloors(buildingId: string | null = null): Array<TargetFeature> {
41+
getFloors(buildingId: string | null = null): Array<IndoorDataFloor> {
4342
const floorFeatures = Array.from(this._floors.values());
4443
if (buildingId) {
4544
const floors = floorFeatures.filter(floor => {
46-
const buildingIds = floor.properties.building_ids as string;
45+
const buildingIds = floor.buildingIds;
4746
if (!buildingIds) {
4847
return false;
4948
}

0 commit comments

Comments
 (0)