feat: emit null image on reset

When viewer is reset, no current image is set anymore
so emit null for clarity.
This commit is contained in:
Oscar Lorentzon 2023-01-03 12:57:22 -08:00
parent 4b6cf8f488
commit b408b6db23
8 changed files with 44 additions and 15 deletions

View File

@ -1723,6 +1723,18 @@ declare class Image {
*/
id: string;
/**
* Get is disposed.
*
* @description If the image has been disposed no properties
* are acessible. Image are disposed when the {@link Viewer}
* is reset or a new data provider is set.
*
* @returns {boolean} Value indicating that this image
* has been disposed.
*/
isDisposed: boolean;
/**
* Get lngLat.
* @description If the SfM computed longitude, latitude exist
@ -3466,7 +3478,7 @@ export type ViewerImageEvent = {
/**
* The viewer's current image.
*/
image: Image,
image: Image | null,
type: "image",
...
} & ViewerEvent;
@ -3974,9 +3986,8 @@ declare class Viewer implements IEventEmitter, IViewer {
/**
* Reset the viewer's cache.
* @description All images in the viewer's cache at the moment when
* reset is called will eventually be removed if not navigated to
* again.
* @description All images in the viewer's cache at the moment of the
* reset will be disposed.
* @returns {Promise<void>} Promise that resolves when viewer's cache
* has been reset.
* @throws When viewer is not navigable.
@ -4029,7 +4040,7 @@ declare class Viewer implements IEventEmitter, IViewer {
/**
* Set a new data provider instance.
* @description [object Object],[object Object],[object Object]
* @description Resets the viewer's cache (see Viewer.reset).
* @returns {Promise<void>} Promise that resolves when viewer's data
* provider has been set.
* @throws When viewer is not navigable.

View File

@ -64,6 +64,9 @@
};
viewer = new Viewer(options);
viewer.on("reset", (event) => console.log(event.type));
viewer.on("image", (event) =>
console.log(event.image ? event.image.id : null)
);
viewer
.moveTo(dataProvider.images.keys().next().value)
.catch((error) => console.error(error));

View File

@ -317,6 +317,20 @@ export class Image {
return this._core.id;
}
/**
* Get is disposed.
*
* @description If the image has been disposed no properties
* are acessible. Image are disposed when the {@link Viewer}
* is reset or a new data provider is set.
*
* @returns {boolean} Value indicating that this image
* has been disposed.
*/
public get isDisposed(): boolean {
return !this._core;
}
/**
* Get lngLat.
*

View File

@ -33,7 +33,6 @@ import { Transform } from "../geo/Transform";
import { LngLatAlt } from "../api/interfaces/LngLatAlt";
import { SubscriptionHolder } from "../util/SubscriptionHolder";
import { Clock } from "three";
import { isNullImageId } from "../util/Common";
interface IContextOperation {
(context: IStateContext): IStateContext;
@ -193,10 +192,6 @@ export class StateService {
refCount());
this._currentImageExternal$ = imageChanged$.pipe(
filter(
(f: AnimationFrame): boolean => {
return !isNullImageId(f.state.currentImage.id);
}),
map(
(f: AnimationFrame): Image => {
return f.state.currentImage;

View File

@ -41,6 +41,7 @@ import { ViewerLoadEvent } from "./events/ViewerLoadEvent";
import { ViewerReferenceEvent } from "./events/ViewerReferenceEvent";
import { ViewerResetEvent } from "./events/ViewerResetEvent";
import { ViewerDragEndEvent } from "./events/ViewerDragEndEvent";
import { isNullImageId } from "../util/Common";
type UnprojectionParams = [
[
@ -200,7 +201,7 @@ export class Observer {
.subscribe((image: Image): void => {
const type: ViewerEventType = "image";
const event: ViewerImageEvent = {
image,
image: isNullImageId(image.id) ? null : image,
target: this._viewer,
type,
};

View File

@ -12,6 +12,7 @@ import {
import {
catchError,
distinctUntilChanged,
filter,
map,
publishReplay,
refCount,
@ -37,6 +38,7 @@ import { isSpherical } from "../geo/Geo";
import { geodeticToEnu } from "../geo/GeoCoords";
import { State } from "../state/State";
import { ICameraFactory } from "../geometry/interfaces/ICameraFactory";
import { isNullImageId } from "../util/Common";
enum PanMode {
Disabled,
@ -126,6 +128,7 @@ export class PanService {
}
const panImages$ = this._stateService.currentImage$.pipe(
filter((image: Image) => { return !isNullImageId(image.id); }),
switchMap(
(current: Image): Observable<[Image, Transform, number][]> => {
if (!current.merged || isSpherical(current.cameraType)) {

View File

@ -1431,9 +1431,8 @@ export class Viewer extends EventEmitter implements IViewer {
/**
* Reset the viewer's cache.
*
* @description All images in the viewer's cache at the moment when
* reset is called will eventually be removed if not navigated to
* again.
* @description All images in the viewer's cache at the moment of the
* reset will be disposed.
*
* @returns {Promise<void>} Promise that resolves when viewer's cache
* has been reset.

View File

@ -7,8 +7,11 @@ import { Image } from "../../graph/Image";
export interface ViewerImageEvent extends ViewerEvent {
/**
* The viewer's current image.
*
* @description If the viewer is reset, the emitted
* image will be null.
*/
image: Image;
image: Image | null;
type: "image";
}