Skip to content

Commit 500a0b1

Browse files
aleksprogergithub-actions[bot]
authored andcommitted
Improve indoor code structure (internal-8666)
GitOrigin-RevId: fddd003f56c9ef805bf2f2fe4800b4af9de4758f
1 parent 1e2f1d4 commit 500a0b1

File tree

11 files changed

+62
-42
lines changed

11 files changed

+62
-42
lines changed

debug/indoor.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
bearing: -15,
3838
pitch: 50,
3939
center: [24.941915, 60.171768],
40-
hash: true,
41-
style: style
40+
hash: true
4241
});
4342

4443
map.addControl(new mapboxgl.NavigationControl());
4544
map.addControl(new mapboxgl.AttributionControl());
45+
46+
map.setStyle(style);
4647
</script>
4748
</body>
4849

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
]
200200
},
201201
{
202-
"limit": "5.4 kb",
202+
"limit": "5.41 kb",
203203
"gzip": true,
204204
"path": "dist/mapbox-gl.css"
205205
}

src/css/mapbox-gl.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ a.mapboxgl-ctrl-logo.mapboxgl-compact {
845845
width: 50px;
846846
height: 50px;
847847
font-weight: bold;
848+
text-align: center;
849+
line-height: normal;
850+
padding: 0;
851+
display: flex;
852+
align-items: center;
853+
justify-content: center;
848854
}
849855

850856
.mapboxgl-ctrl button.mapboxgl-ctrl-level-button:first-child {

src/source/geojson_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class GeoJSONSource extends Evented<SourceEvents> implements ISource {
465465
scaleFactor: this.map.getScaleFactor(),
466466
partial,
467467
worldview: this.map.getWorldview(),
468-
indoor: this.map.indoor ? this.map.indoor.getIndoorTileOptions(this.id, this.scope) : null
468+
indoor: this.map.getIndoorTileOptions(this.id, this.scope)
469469
};
470470

471471
tile.request = this.actor.send(message, params, (err, data: WorkerSourceVectorTileResult) => {

src/source/vector_tile_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class VectorTileSource extends Evented<SourceEvents> implements ISource<'vector'
273273
tessellationStep: this.map._tessellationStep,
274274
scaleFactor: this.map.getScaleFactor(),
275275
worldview: this.map.getWorldview() || this.worldviewDefault,
276-
indoor: this.map.indoor ? this.map.indoor.getIndoorTileOptions(this.id, this.scope) : null
276+
indoor: this.map.getIndoorTileOptions(this.id, this.scope)
277277
};
278278

279279
// If we request a Mapbox URL, use the `worldview` param in the WorkerTile

src/style/indoor_data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type IndoorFloor = {
1616

1717
export type IndoorEvents = {
1818
'selector-update': IndoorControlModel;
19+
'buildings-appeared': Record<string, never>;
20+
'buildings-disappeared': Record<string, never>;
1921
};
2022

2123
export type IndoorControlFloor = {

src/style/indoor_manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default class IndoorManager extends Evented<IndoorEvents> {
9898
const closestBuilding = (closestBuildingId && buildings) ? buildings[closestBuildingId] : undefined;
9999

100100
if (!closestBuilding) {
101+
this.fire(new Event('buildings-disappeared', {}));
101102
this.fire(new Event('selector-update', {
102103
selectedFloorId: null,
103104
activeFloorsVisible: this._activeFloorsVisible,
@@ -106,6 +107,7 @@ export default class IndoorManager extends Evented<IndoorEvents> {
106107
return;
107108
}
108109

110+
this.fire(new Event('buildings-appeared', {}));
109111
let buildingActiveFloorId: string | null = null;
110112
for (const floorId of closestBuilding.floorIds) {
111113
if (this._activeFloors && this._activeFloors.has(floorId)) {

src/style/style.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {TargetFeature} from '../util/vectortile_to_geojson';
6767
import {loadIconset} from './load_iconset';
6868
import {ImageId} from '../style-spec/expression/types/image_id';
6969
import {ImageProvider} from '../render/image_provider';
70+
import IndoorManager from './indoor_manager';
7071

7172
import type {PropertyValidatorOptions} from '../style-spec/validate/validate_property';
7273
import type Tile from '../source/tile';
@@ -276,6 +277,7 @@ class Style extends Evented<MapEvents> {
276277
imageManager: ImageManager;
277278
glyphManager: GlyphManager;
278279
modelManager: ModelManager;
280+
indoorManager: IndoorManager;
279281
ambientLight: Lights<Ambient> | null | undefined;
280282
directionalLight: Lights<Directional> | null | undefined;
281283
light: Light;
@@ -414,6 +416,8 @@ class Style extends Evented<MapEvents> {
414416

415417
this._hasDataDrivenEmissive = false;
416418

419+
this.indoorManager = new IndoorManager(this);
420+
417421
if (options.dispatcher) {
418422
this.dispatcher = options.dispatcher;
419423
} else {
@@ -888,6 +892,7 @@ class Style extends Evented<MapEvents> {
888892
this._loadImports(json.imports, validate)
889893
.then(() => {
890894
this._reloadImports();
895+
this._setupIndoor();
891896
this.fire(new Event(isRootStyle ? 'style.load' : 'style.import.load'));
892897
})
893898
.catch((e) => {
@@ -897,6 +902,7 @@ class Style extends Evented<MapEvents> {
897902
});
898903
} else {
899904
this._reloadImports();
905+
this._setupIndoor();
900906
this.fire(new Event(isRootStyle ? 'style.load' : 'style.import.load'));
901907
}
902908
};
@@ -2466,7 +2472,7 @@ class Style extends Evented<MapEvents> {
24662472
}
24672473

24682474
setIndoorData(mapId: string, params: ActorMessages['setIndoorData']['params']) {
2469-
this.map.indoor.setIndoorData(params);
2475+
this.indoorManager.setIndoorData(params);
24702476
}
24712477

24722478
updateIndoorDependentLayers() {
@@ -3220,6 +3226,7 @@ class Style extends Evented<MapEvents> {
32203226
fog: this.stylesheet.fog,
32213227
snow: this.stylesheet.snow,
32223228
rain: this.stylesheet.rain,
3229+
indoor: this.stylesheet.indoor,
32233230
center: this.stylesheet.center,
32243231
'color-theme': this.stylesheet['color-theme'],
32253232
zoom: this.stylesheet.zoom,
@@ -4016,6 +4023,7 @@ class Style extends Evented<MapEvents> {
40164023
delete this.terrain;
40174024
delete this.ambientLight;
40184025
delete this.directionalLight;
4026+
this.indoorManager.destroy();
40194027

40204028
// Shared managers should be removed only on removing the root style
40214029
if (this.isRootStyle()) {
@@ -4615,6 +4623,25 @@ class Style extends Evented<MapEvents> {
46154623
this.dispatcher.broadcast('clearCaches');
46164624
}
46174625

4626+
_setupIndoor() {
4627+
this.indoorManager.on('buildings-appeared', () => {
4628+
this.map._addIndoorControl();
4629+
});
4630+
4631+
this.indoorManager.on('buildings-disappeared', () => {
4632+
this.map._removeIndoorControl();
4633+
});
4634+
4635+
const updateUI = () => {
4636+
this.indoorManager._updateUI(this.map.transform.zoom, this.map.transform.center, this.map.transform.getBounds());
4637+
};
4638+
4639+
this.map.on('move', updateUI);
4640+
this.map.on('idle', updateUI);
4641+
4642+
updateUI();
4643+
}
4644+
46184645
destroy() {
46194646
this._clearWorkerCaches();
46204647
this.fragments.forEach(fragment => {

src/ui/control/indoor_control.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class IndoorControl implements IControl {
2626
onAdd(map: Map): HTMLElement {
2727
this._map = map;
2828
this._container = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-group');
29-
this._map.indoor.on('selector-update', (controlModel: IndoorControlModel) => this._onIndoorUpdate(controlModel));
29+
if (this._map.style) {
30+
this._map.style.indoorManager.on('selector-update', (controlModel: IndoorControlModel) => this._onIndoorUpdate(controlModel));
31+
}
3032
return this._container;
3133
}
3234

@@ -52,8 +54,8 @@ class IndoorControl implements IControl {
5254
this._container.remove();
5355
}
5456

55-
if (this._map && this._map.indoor) {
56-
this._map.indoor.off('selector-update', this._onIndoorUpdate);
57+
if (this._map && this._map.style) {
58+
this._map.style.indoorManager.off('selector-update', this._onIndoorUpdate);
5759
this._map = null;
5860
}
5961
}

src/ui/map.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
postAddedAppearanceEvent
1919
} from '../util/mapbox';
2020
import Style from '../style/style';
21-
import IndoorManager from '../style/indoor_manager';
2221
import EvaluationParameters from '../style/evaluation_parameters';
2322
import Painter from '../render/painter';
2423
import Transform from '../geo/transform';
@@ -106,6 +105,7 @@ import type {SpriteFormat} from '../render/image_manager';
106105
import type {PitchRotateKey} from './handler_manager';
107106
import type {CustomSourceInterface} from '../source/custom_source';
108107
import type {RasterQueryParameters, RasterQueryResult} from '../source/raster_array_tile_source';
108+
import type {IndoorTileOptions} from '../style/indoor_data';
109109

110110
export type ControlPosition = 'top-left' | 'top' | 'top-right' | 'right' | 'bottom-right' | 'bottom' | 'bottom-left' | 'left';
111111

@@ -436,9 +436,7 @@ const defaultOptions = {
436436
*/
437437
export class Map extends Camera {
438438
style?: Style;
439-
indoor: IndoorManager;
440439
painter: Painter;
441-
442440
_container: HTMLElement;
443441
_missingCSSCanary: HTMLElement;
444442
_canvasContainer: HTMLElement;
@@ -788,7 +786,6 @@ export class Map extends Camera {
788786
}
789787
this._postStyleLoadEvent();
790788
this._postStyleWithAppearanceEvent();
791-
this._setupIndoor();
792789
});
793790

794791
this.on('data', (event) => {
@@ -4125,26 +4122,33 @@ export class Map extends Camera {
41254122
* map._selectIndoorFloor('floor-1');
41264123
*/
41274124
_selectIndoorFloor(floorId: string) {
4128-
this.indoor.selectFloor(floorId);
4125+
this.style.indoorManager.selectFloor(floorId);
41294126
}
41304127

41314128
_setIndoorActiveFloorsVisibility(activeFloorsVisible: boolean) {
4132-
this.indoor.setActiveFloorsVisibility(activeFloorsVisible);
4129+
this.style.indoorManager.setActiveFloorsVisibility(activeFloorsVisible);
41334130
}
41344131

41354132
_addIndoorControl() {
41364133
if (!this._indoorControl) {
41374134
this._indoorControl = new IndoorControl();
4135+
this.addControl(this._indoorControl, 'right');
41384136
}
4139-
4140-
this.addControl(this._indoorControl, 'right');
41414137
}
41424138

41434139
_removeIndoorControl() {
41444140
if (!this._indoorControl) {
41454141
return;
41464142
}
41474143
this.removeControl(this._indoorControl);
4144+
this._indoorControl = null;
4145+
}
4146+
4147+
getIndoorTileOptions(source: string, scope: string): IndoorTileOptions | null {
4148+
if (!this.style.isIndoorEnabled()) {
4149+
return null;
4150+
}
4151+
return this.style.indoorManager.getIndoorTileOptions(source, scope);
41484152
}
41494153

41504154
_updateContainerDimensions() {
@@ -4183,27 +4187,6 @@ export class Map extends Camera {
41834187
}
41844188
}
41854189

4186-
_setupIndoor() {
4187-
if (!this.style.isIndoorEnabled()) {
4188-
return;
4189-
}
4190-
4191-
this.indoor = new IndoorManager(this.style);
4192-
4193-
this.on('load', () => {
4194-
this._addIndoorControl();
4195-
this.indoor._updateUI(this.transform.zoom, this.transform.center, this.transform.getBounds());
4196-
4197-
this.on('move', () => {
4198-
this.indoor._updateUI(this.transform.zoom, this.transform.center, this.transform.getBounds());
4199-
});
4200-
4201-
this.on('idle', () => {
4202-
this.indoor._updateUI(this.transform.zoom, this.transform.center, this.transform.getBounds());
4203-
});
4204-
});
4205-
}
4206-
42074190
_setupContainer() {
42084191
const container = this._container;
42094192
container.classList.add('mapboxgl-map');
@@ -4901,9 +4884,6 @@ export class Map extends Camera {
49014884
if (this.style) {
49024885
this.style.destroy();
49034886
}
4904-
if (this.indoor) {
4905-
this.indoor.destroy();
4906-
}
49074887
this.painter.destroy();
49084888
if (this.handlers) this.handlers.destroy();
49094889
this.handlers = undefined;

0 commit comments

Comments
 (0)