-
Notifications
You must be signed in to change notification settings - Fork 208
/
RealityDataPicker.tsx
757 lines (641 loc) · 26.6 KB
/
RealityDataPicker.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
/** @module Widget */
import * as React from "react";
import * as classnames from "classnames";
import * as _ from "lodash";
import { IModelConnection, findAvailableUnattachedRealityModels, IModelApp, Viewport, ContextRealityModelState, SpatialViewState, ScreenViewport, SpatialModelState } from "@bentley/imodeljs-frontend";
import { ContextRealityModelProps, BackgroundMapType, CartographicRange } from "@bentley/imodeljs-common";
import { IconSpecUtilities } from "@bentley/ui-abstract";
import { LoadingSpinner, SpinnerSize, SearchBox, ContextMenu, ContextMenuItem, ContextMenuDirection } from "@bentley/ui-core";
import { RealityDataEntry, AttachedRealityModel } from "./RealityData";
import { RealityDataItem } from "./RealityDataItem";
import { SettingsModalDialog } from "./SettingsModalDialog";
import "./RealityDataPicker.scss";
import "./RealityDataItem.scss";
import { RealityDataServicesClient, AuthorizedClientRequestContext } from "@bentley/imodeljs-clients";
import { ConfigurableCreateInfo } from "../../configurableui/ConfigurableUiControl";
import { ConfigurableUiManager } from "../../configurableui/ConfigurableUiManager";
import { ModalDialogManager } from "../../dialog/ModalDialogManager";
import { WidgetControl } from "../../widgets/WidgetControl";
import { UiFramework } from "../../UiFramework";
import widgetIconSvg from "@bentley/icons-generic/icons/network.svg";
/** Properties for the [[RealityDataPickerControl]] component */
interface RealityDataPickerProps {
iModelConnection: IModelConnection;
}
/** State for the [[RealityDataPickerControl]] component */
interface RealityDataPickerState {
items: RealityDataEntry[]; /** Items displayed in picker */
filter: string;
isMapEnabled: boolean;
isOptionsOpened: boolean;
showMapTypes: boolean;
bingMapType: BackgroundMapType;
showSearchBox: boolean;
initialized: boolean;
}
/**
* Model Selector [[RealityDataPickerControl]]
* @alpha
*/
// istanbul ignore next
export class RealityDataPickerControl extends WidgetControl {
public static get iconSpec() {
return IconSpecUtilities.createSvgIconSpec(widgetIconSvg);
}
public static get label() {
return UiFramework.translate("realityData.title");
}
/** Creates a ModelSelectorDemoWidget */
constructor(info: ConfigurableCreateInfo, options: any) {
super(info, options);
this.reactElement = (
<div style={{ padding: "2px 4px 0px 4px", width: "100%", height: "100%", boxSizing: "border-box" }}>
<RealityDataPicker iModelConnection={options.iModelConnection} />;
</div>
);
}
}
/**
* Reality Data React component
* @alpha
*/
// istanbul ignore next
export class RealityDataPicker extends React.Component<RealityDataPickerProps, RealityDataPickerState> {
private _availableModels: ContextRealityModelProps[] = [];
private _attachedModels: AttachedRealityModel[] = [];
private _searchBox: SearchBox | null = null;
private _removeListener: () => void;
private _vp: ScreenViewport | undefined;
private _bingMapTitle = UiFramework.i18n.translate("UiFramework:realityData.bingMap");
private _isMounted = false;
/** Creates a ModelSelectorWidget */
constructor(props: RealityDataPickerProps) {
super(props);
this._removeListener = () => { };
this.state = {
items: [],
filter: "",
isMapEnabled: false,
isOptionsOpened: false,
showMapTypes: false,
bingMapType: BackgroundMapType.Hybrid,
initialized: false,
showSearchBox: false,
};
}
public get attachedModels(): AttachedRealityModel[] {
return this._attachedModels;
}
/** Initialize listeners and category/model rulesets */
public async componentDidMount() {
this._isMounted = true;
// get selected viewport
const vp = IModelApp.viewManager.selectedView;
// if view exists bind update routine to onRender loop, otherwise do so once the onViewOpen event runs
if (vp) {
await this._onViewOpen(vp);
} else {
IModelApp.viewManager.onViewOpen.addListener(this._onViewOpen, this);
}
}
private async _onViewOpen(vp: Viewport) {
if (IModelApp.viewManager.onViewOpen.has(this._onViewOpen, this))
IModelApp.viewManager.onViewOpen.removeListener(this._onViewOpen, this);
this._vp = vp as ScreenViewport;
await this._initializeRealityModels();
this._removeListener = vp.onDisplayStyleChanged.addListener(this._refreshFromView, this);
const view = vp.view as SpatialViewState;
if (this._isMounted)
this.setState({
isMapEnabled: view.viewFlags.backgroundMap,
bingMapType: view.getDisplayStyle3d().backgroundMap.settings.mapType,
});
}
/** Get rid of listeners */
public componentWillUnmount() {
this._isMounted = false;
if (this._removeListener)
this._removeListener();
}
/** Initializes reality model data. */
private _initializeRealityModels = async () => {
this._availableModels = [];
if (!this.props.iModelConnection.iModelToken.contextId)
throw new Error("Invalid iModelToken/Context Id");
if (this.props.iModelConnection && this.props.iModelConnection.ecefLocation) {
// Should query online
const projectCartographicRange = new CartographicRange(this.props.iModelConnection.projectExtents, this.props.iModelConnection.ecefLocation!.getTransform());
this._availableModels = await findAvailableUnattachedRealityModels(this.props.iModelConnection.iModelToken.contextId, this.props.iModelConnection, projectCartographicRange);
} else if (this.props.iModelConnection.isGeoLocated) {
this._availableModels = await findAvailableUnattachedRealityModels(this.props.iModelConnection.iModelToken.contextId, this.props.iModelConnection);
}
const query = { from: SpatialModelState.classFullName, wantPrivate: false };
const props = await this.props.iModelConnection.models.queryProps(query);
for (const prop of props)
if (prop.jsonProperties !== undefined && prop.jsonProperties.tilesetUrl !== undefined && prop.id !== undefined && prop.name !== undefined) {
this._attachedModels.push(new AttachedRealityModel(prop.id!, prop.name, prop.jsonProperties.tilesetUrl));
}
this._setRealityDataEntries(); // tslint:disable-line:no-floating-promises
}
private _refreshFromView = async () => {
if (!this._isMounted)
return;
const items = await this._loadAvailableItems();
this.setState({
items,
isMapEnabled: this._vp!.view.viewFlags.backgroundMap,
initialized: true,
});
}
private _setRealityDataEntries = async () => {
if (!this._isMounted)
return;
const items = await this._loadAvailableItems();
this.setState({
items,
initialized: true,
});
}
private _loadAvailableItems = async () => {
const _items: RealityDataEntry[] = [];
const view = this._vp!.view as SpatialViewState;
const models: ContextRealityModelState[] = [];
view.displayStyle.forEachRealityModel((modelState: ContextRealityModelState) => models.push(modelState));
for (const modelState of models) {
let group = "";
let size = "";
const tilesetUrl = modelState.toJSON().tilesetUrl || modelState.url;
const realityData = await this._fetchRealityData(tilesetUrl);
if (realityData) {
group = realityData.group || "";
size = realityData.size || "";
}
_items.push({
model: modelState,
url: modelState.url,
name: modelState.name,
description: "",
enabled: true,
group,
size,
});
}
for (const props of this._availableModels) {
if (this._isUniqueUrl(props.tilesetUrl, _items)) {
let group = "";
let size = "";
const realityData = await this._fetchRealityData(props.tilesetUrl);
if (realityData) {
group = realityData.group || "";
size = realityData.size || "";
}
_items.push({
model: new ContextRealityModelState(props, this._vp!.iModel, this._vp!.displayStyle),
url: props.tilesetUrl,
name: props.name || "",
description: props.description || "",
enabled: false,
group,
size,
});
}
}
const modelSelector = (this._vp!.view as SpatialViewState).modelSelector;
for (const attachedModel of this._attachedModels) {
_items.push({
model: attachedModel,
url: attachedModel.url,
name: attachedModel.name + " " + IModelApp.i18n.translate("UiFramework:realityData.attached"),
description: "",
enabled: modelSelector.has(attachedModel.id),
group: "",
size: "",
});
}
_items.sort((a: RealityDataEntry, b: RealityDataEntry) => {
if (a.name.toLowerCase() < b.name.toLowerCase())
return -1;
if (a.name.toLowerCase() > b.name.toLowerCase())
return 1;
return 0;
});
return _items;
}
private _fetchRealityData = async (titlesetUrl: string) => {
const accessToken = await IModelApp.authorizationClient!.getAccessToken();
if (!accessToken)
return null;
const requestContext = new AuthorizedClientRequestContext(accessToken); // might want to pass in as prop
const client = new RealityDataServicesClient();
const realityDataId = client.getRealityDataIdFromUrl(titlesetUrl);
if (realityDataId) {
const realityData = await client.getRealityData(requestContext, this.props.iModelConnection.iModelToken.contextId!, this.props.iModelConnection.iModelToken.iModelId!);
return realityData;
}
return null;
}
private _isUniqueUrl = (url: string, items: RealityDataEntry[]) => {
for (const item of items) {
if (url === item.url)
return false;
}
const view = this._vp!.view as SpatialViewState;
const models: ContextRealityModelState[] = [];
view.displayStyle.forEachRealityModel((modelState: ContextRealityModelState) => models.push(modelState));
for (const model of models) {
if (url === model.url)
return false;
}
return true;
}
/**
* Toggles tree item and display of selected item.
* @param item RealityDataEntry selected in picker.
*/
private _onVisibilityChange(item: RealityDataEntry) {
item.enabled ? this._disableItem(item) : this._enableItem(item);
}
/**
* Enable tree item and display of selected item.
* @param item RealityDataEntry to enable.
*/
private _enableItem = (item: RealityDataEntry) => {
this._enableTreeItems([item]);
this._enableDisplayItems([item]);
}
/**
* Disable tree item and display of selected item.
* @param item RealityDataEntry to disable.
*/
private _disableItem = (item: RealityDataEntry) => {
this._disableTreeItems([item]);
this._disableDisplayItems([item]);
}
/**
* Enable item in tree.
* @param item RealityDataEntry to enable tree item for.
*/
private _enableTreeItems = (entries: RealityDataEntry[]) => {
if (!this._isMounted)
return;
const items = this.state.items;
entries.forEach((entry) => {
entry.enabled = true;
const index = items.indexOf(entry);
items.splice(index, 1, entry);
});
this.setState({ items });
}
/**
* Enable display item in viewport.
* @param item RealityDataEntry to enable display for.
*/
private _enableDisplayItems = (entries: RealityDataEntry[]) => {
const view = this._vp!.view as SpatialViewState;
for (const entry of entries) {
if (entry.model instanceof AttachedRealityModel) {
this._vp!.addViewedModels((entry.model as AttachedRealityModel).id); // tslint:disable-line:no-floating-promises
return;
}
const props = {
tilesetUrl: entry.model.url,
name: entry.model.name,
description: entry.description,
// classifiers: entry. SpatialClassificationProps.PropertiesProps[], // TODO?
};
const existingRealityModels: ContextRealityModelState[] = [];
view.displayStyle.forEachRealityModel((modelState: ContextRealityModelState) => existingRealityModels.push(modelState));
const found = existingRealityModels.find((model) => {
if (model.url === props.tilesetUrl)
return true;
return false;
});
if (!found)
view.displayStyle.attachRealityModel(props);
}
this._vp!.sync.invalidateScene();
}
/**
* Disable tree item and display of selected item.
* @param item RealityDataEntry to disable.
*/
private _disableTreeItems = (entries: RealityDataEntry[]) => {
if (!this._isMounted)
return;
const items = this.state.items;
for (const entry of entries) {
entry.enabled = false;
if (entry.model instanceof AttachedRealityModel) {
this._vp!.changeModelDisplay((entry.model as AttachedRealityModel).id, false);
return;
}
const index = items.indexOf(entry);
items.splice(index, 1, entry);
}
this.setState({ items });
}
/**
* Disable display item in viewport.
* @param item RealityDataEntry to disable display for.
*/
private _disableDisplayItems = (entries: RealityDataEntry[]) => {
if (!this._vp)
return;
const view = this._vp!.view as SpatialViewState;
const models: ContextRealityModelState[] = [];
view.displayStyle.forEachRealityModel((modelState: ContextRealityModelState) => models.push(modelState));
entries.forEach((entry) => {
if (entry.model) {
const index = models.findIndex((state: ContextRealityModelState) => {
return entry.model.url.includes(state.url);
});
if (-1 !== index)
view.displayStyle.detachRealityModelByIndex(index);
}
});
this._vp!.invalidateScene();
}
/**
* Enable all tree items and corresponding display items.
*/
private _showAllRealityData = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
event.preventDefault();
event.stopPropagation();
this._setEnableMap(true);
this._enableTreeItems(this.state.items);
this._enableDisplayItems(this.state.items);
if (this._isMounted)
this.setState({ isOptionsOpened: false });
}
/**
* Disable all tree items and corresponding display items.
*/
private _hideAllRealityData = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
event.preventDefault();
event.stopPropagation();
this._setEnableMap(false);
this._disableTreeItems(this.state.items);
this._disableAllDisplayItems();
if (this._isMounted)
this.setState({ isOptionsOpened: false });
}
/**
* Enable or disable map.
* @param isEnabled specifies wether to enable or disable map.
*/
private _setEnableMap = (isEnabled: boolean) => {
if (!this._isMounted)
return;
const view = this._vp!.view as SpatialViewState;
const newFlags = view.viewFlags.clone();
newFlags.backgroundMap = isEnabled;
this._vp!.viewFlags = newFlags;
if (isEnabled) {
(this._vp!.view as SpatialViewState).getDisplayStyle3d().setBackgroundMap({
groundBias: view.getDisplayStyle3d().settings.backgroundMap.groundBias,
providerName: "BingProvider",
providerData: {
mapType: this.state.bingMapType,
},
});
this._vp!.synchWithView(false);
}
this.setState({
isMapEnabled: isEnabled,
});
this._vp!.sync.invalidateScene();
}
/** Disable all display items. */
private _disableAllDisplayItems = () => {
if (!this._vp)
return;
const view = this._vp!.view as SpatialViewState;
const models: ContextRealityModelState[] = [];
view.displayStyle.forEachRealityModel((modelState: ContextRealityModelState) => models.push(modelState));
for (const model of models)
view.displayStyle.detachRealityModelByNameAndUrl(model.name, model.url);
}
/**
* Invert all tree items and corresponding display items.
*/
private _invertAllRealityData = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
event.preventDefault();
event.stopPropagation();
const items = this.state.items;
const enabledItems: RealityDataEntry[] = [];
const disabledItems: RealityDataEntry[] = [];
items.forEach((item) => {
item.enabled ? enabledItems.push(item) : disabledItems.push(item);
});
this._toggleBingMap();
this._enableTreeItems(disabledItems);
this._enableDisplayItems(disabledItems);
this._disableTreeItems(enabledItems);
this._disableDisplayItems(enabledItems);
if (this._isMounted)
this.setState({ isOptionsOpened: false });
}
/** @hidden */
public render() {
const headerClassName = classnames("reality-data-viewer", this.state.showSearchBox && "show-search");
return (
<div className="reality-data-widget">
{!this.state.initialized &&
<LoadingSpinner size={SpinnerSize.Medium} />
}
{(this.state.initialized && this.state.items.length === 0 && !this.props.iModelConnection.isGeoLocated) &&
<div className="reality-data-empty-msg">
{UiFramework.i18n.translate("UiFramework:realityData.noneAvailable")}
</div>
}
{(this.state.initialized && this.state.items.length === 0 && this.props.iModelConnection.isGeoLocated) &&
<div className={headerClassName}>
{this._getHeader()}
{this._getSearch()}
{this._getMapOnly()}
</div>
}
{(this.state.initialized && this.state.items.length !== 0) &&
<div className={headerClassName}>
{this._getHeader()}
{this._getSearch()}
{this._getContent()}
</div>
}
</div>
);
}
private _onShowOptions(event: any) {
event.stopPropagation();
if (this._isMounted)
this.setState((prevState) => ({ isOptionsOpened: !prevState.isOptionsOpened }));
}
private _onCloseContextMenu() {
if (this._isMounted)
this.setState({ isOptionsOpened: false });
}
private _onToggleSearchBox = () => {
if (this._isMounted)
this.setState(
(prevState) => ({ showSearchBox: !prevState.showSearchBox }),
() => { this._searchBox!.focus(); });
}
private _getMapOnly = () => {
return (
<div className="reality-data-content">
<ul className="reality-data-list">
{this._isMapVisible() ?
<li className="reality-data-item" key={"bingMap"} onClick={this._toggleBingMap}>
<span className={this.state.isMapEnabled ? "icon icon-visibility" : "icon icon-visibility-hide-2"} />
<a><span className="reality-data-name">{this._bingMapTitle}</span></a>
<span className="icon icon-more-2" onClick={this._onShowMapTypes} />
<ContextMenu opened={this.state.showMapTypes} onOutsideClick={this._onCloseMapTypesMenu.bind(this)} direction={ContextMenuDirection.BottomRight} >
<ContextMenuItem checked={this.state.bingMapType === BackgroundMapType.Hybrid} onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => this._onChanged.bind(this, BackgroundMapType.Hybrid, event)}>{IModelApp.i18n.translate("UiFramework:realityData.hybrid")}</ContextMenuItem>
<ContextMenuItem checked={this.state.bingMapType === BackgroundMapType.Aerial} onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => this._onChanged.bind(this, BackgroundMapType.Aerial, event)}>{IModelApp.i18n.translate("UiFramework:realityData.aerial")}</ContextMenuItem>
<ContextMenuItem checked={this.state.bingMapType === BackgroundMapType.Street} onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => this._onChanged.bind(this, BackgroundMapType.Street, event)}>{IModelApp.i18n.translate("UiFramework:realityData.street")} </ContextMenuItem>
<ContextMenuItem onClick={this._onSettingsOpened}>{IModelApp.i18n.translate("UiFramework:realityData.settings")}</ContextMenuItem>
</ContextMenu>
</li> :
undefined}
</ul>
</div>
);
}
private _getHeader = () => {
return (
<div className={"reality-data-header"}>
<span>{UiFramework.i18n.translate("UiFramework:realityData.title")}</span>
<span className="icon icon-search" onClick={this._onToggleSearchBox} />
<span className="options icon icon-more-2" title={IModelApp.i18n.translate("UiFramework:realityData.options")}
onClick={this._onShowOptions.bind(this)}></span>
<ContextMenu opened={this.state.isOptionsOpened} onOutsideClick={this._onCloseContextMenu.bind(this)} direction={ContextMenuDirection.BottomRight}>
<ContextMenuItem key={0} icon="icon-visibility" onClick={this._showAllRealityData}>{IModelApp.i18n.translate("UiFramework:realityData.showAll")}</ContextMenuItem>
<ContextMenuItem key={1} icon="icon-visibility-hide-2" onClick={this._hideAllRealityData}>{IModelApp.i18n.translate("UiFramework:realityData.hideAll")}</ContextMenuItem>
<ContextMenuItem key={2} icon="icon-visibility-invert" onClick={this._invertAllRealityData}>{IModelApp.i18n.translate("UiFramework:realityData.invertDisplay")}</ContextMenuItem>
</ContextMenu>
</div>
);
}
private _getSearch = () => {
return (
<SearchBox placeholder={UiFramework.i18n.translate("UiCore:general.search")} onValueChanged={this._handleSearchValueChanged} valueChangedDelay={250}
ref={(searchBox) => { this._searchBox = searchBox; }} />
);
}
private _handleSearchValueChanged = (value: string): void => {
if (this._isMounted)
this.setState({ filter: value });
}
private _onShowMapTypes = (event: any) => {
if (!this._isMounted)
return;
event.preventDefault();
event.stopPropagation();
const view = this._vp!.view as SpatialViewState;
const mapType = view.getDisplayStyle3d().backgroundMap.settings.mapType;
this.setState({ showMapTypes: true, bingMapType: mapType });
}
private _onChanged = (mapType: BackgroundMapType, event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
event.preventDefault();
event.stopPropagation();
if (!this._vp || !this._isMounted)
return;
this._vp!.changeBackgroundMapProps({ providerData: { mapType } });
this._vp!.synchWithView(false);
this._vp!.sync.invalidateScene();
this.setState({ showMapTypes: false, bingMapType: mapType });
}
private _onSettingsOpened = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
event.preventDefault();
event.stopPropagation();
if (!this._isMounted)
return;
ModalDialogManager.openDialog(this._getSettingsDialog());
this.setState({ showMapTypes: false });
}
private _getSettingsDialog = () => {
return (
<SettingsModalDialog
iModelConnection={this.props.iModelConnection}
opened={true}
/>
);
}
private _onCloseMapTypesMenu = () => {
if (this._isMounted)
this.setState({ showMapTypes: false });
}
private _getContent = () => {
const filteredRealityData = this._getFilteredRealityData();
return (
<div className="reality-data-content">
<ul className="reality-data-list">
{this._isMapVisible() ?
<li className="reality-data-item" key={"bingMap"} onClick={this._toggleBingMap}>
<span className={this.state.isMapEnabled ? "icon icon-visibility" : "icon icon-visibility-hide-2"} />
<a><span className="reality-data-name">{this._bingMapTitle}</span></a>
<span className="icon icon-more-2" onClick={this._onShowMapTypes} />
<ContextMenu opened={this.state.showMapTypes} onOutsideClick={this._onCloseMapTypesMenu.bind(this)} direction={ContextMenuDirection.BottomRight}>
<ContextMenuItem checked={this.state.bingMapType === BackgroundMapType.Hybrid} onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => this._onChanged.bind(this, BackgroundMapType.Hybrid, event)}>{IModelApp.i18n.translate("UiFramework:realityData.hybrid")}</ContextMenuItem>
<ContextMenuItem checked={this.state.bingMapType === BackgroundMapType.Aerial} onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => this._onChanged.bind(this, BackgroundMapType.Aerial, event)}>{IModelApp.i18n.translate("UiFramework:realityData.aerial")}</ContextMenuItem>
<ContextMenuItem checked={this.state.bingMapType === BackgroundMapType.Street} onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => this._onChanged.bind(this, BackgroundMapType.Street, event)}>{IModelApp.i18n.translate("UiFramework:realityData.street")}</ContextMenuItem>
<ContextMenuItem onClick={this._onSettingsOpened}>{IModelApp.i18n.translate("UiFramework:realityData.settings")}</ContextMenuItem>
</ContextMenu>
</li> :
null
}
{
filteredRealityData.map((_item: RealityDataEntry) =>
(
<RealityDataItem key={_item.url} item={_item} onVisibilityChange={this._onVisibilityChange.bind(this, _item)} />
))
}
</ul>
</div>
);
}
private _isMapVisible = () => {
return this._bingMapTitle.toLowerCase().includes(this.state.filter.toLowerCase());
}
private _toggleBingMap = () => {
if (!this._isMounted)
return;
const view = this._vp!.view as SpatialViewState;
const newFlags = view.viewFlags.clone();
newFlags.backgroundMap = !view.viewFlags.backgroundMap;
this._vp!.viewFlags = newFlags;
const isMapEnabled = this._vp!.viewFlags.backgroundMap;
if (isMapEnabled) {
(this._vp!.view as SpatialViewState).getDisplayStyle3d().setBackgroundMap({
groundBias: view.getDisplayStyle3d().settings.backgroundMap.groundBias,
providerName: "BingProvider",
providerData: {
mapType: this.state.bingMapType,
},
});
this._vp!.synchWithView(false);
}
this.setState({
isMapEnabled,
});
this._vp!.sync.invalidateScene();
}
private _getFilteredRealityData = (): RealityDataEntry[] => {
if (!this.state.filter || this.state.filter === "")
return this.state.items;
let filteredData: RealityDataEntry[] = [];
if (this.state.items) {
filteredData = this.state.items!.filter((item) => {
return item.name.toLowerCase().includes(this.state.filter.toLowerCase()) ||
item.description.toLowerCase().includes(this.state.filter.toLowerCase());
});
}
return filteredData;
}
}
export default RealityDataPicker;
ConfigurableUiManager.registerControl("RealityDataPicker", RealityDataPickerControl);