From bcd825bfc39d08f318fb93716a886d3b539016a2 Mon Sep 17 00:00:00 2001 From: Lawrence Owen Date: Tue, 19 Dec 2023 09:28:04 +1000 Subject: [PATCH] Fix: draw marker on first load --- lib/Models/LocationMarkerUtils.ts | 4 ++++ lib/ReactViewModels/ViewState.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/Models/LocationMarkerUtils.ts b/lib/Models/LocationMarkerUtils.ts index 12867814ad5..d6c93ba9df4 100644 --- a/lib/Models/LocationMarkerUtils.ts +++ b/lib/Models/LocationMarkerUtils.ts @@ -110,3 +110,7 @@ export function getMarkerLocation(terria: Terria): LatLonHeight | undefined { } return undefined; } + +export function getMarkerCatalogItem(terria: Terria) { + return terria.getModelById(CzmlCatalogItem, MARKER_UNIQUE_ID); +} diff --git a/lib/ReactViewModels/ViewState.ts b/lib/ReactViewModels/ViewState.ts index 0c7b80b4240..9a390424f1c 100644 --- a/lib/ReactViewModels/ViewState.ts +++ b/lib/ReactViewModels/ViewState.ts @@ -39,6 +39,8 @@ import { import DisclaimerHandler from "./DisclaimerHandler"; import SearchState from "./SearchState"; import CatalogSearchProviderMixin from "../ModelMixins/SearchProviders/CatalogSearchProviderMixin"; +import { getMarkerCatalogItem } from "../Models/LocationMarkerUtils"; +import CzmlCatalogItem from "../Models/Catalog/CatalogItems/CzmlCatalogItem"; export const DATA_CATALOG_NAME = "data-catalog"; export const USER_DATA_NAME = "my-data"; @@ -368,6 +370,7 @@ export default class ViewState { private _mobileMenuSubscription: IReactionDisposer; private _storyPromptSubscription: IReactionDisposer; private _previewedItemIdSubscription: IReactionDisposer; + private _locationMarkerSubscription: IReactionDisposer; private _workbenchHasTimeWMSSubscription: IReactionDisposer; private _storyBeforeUnloadSubscription: IReactionDisposer; private _disclaimerHandler: DisclaimerHandler; @@ -475,6 +478,17 @@ export default class ViewState { } ); + this._locationMarkerSubscription = reaction( + () => getMarkerCatalogItem(this.terria), + (item: CzmlCatalogItem | undefined) => { + if (item) { + terria.overlays.add(item); + /* dispose subscription after init */ + this._locationMarkerSubscription(); + } + } + ); + this._previewedItemIdSubscription = reaction( () => this.terria.previewedItemId, async (previewedItemId: string | undefined) => { @@ -525,6 +539,7 @@ export default class ViewState { this._storyPromptSubscription(); this._previewedItemIdSubscription(); this._workbenchHasTimeWMSSubscription(); + this._locationMarkerSubscription(); this._disclaimerHandler.dispose(); this.searchState.dispose(); }