in src/viewer/Observer.ts [191:421]
public startEmit(): void {
if (this._started) { return; }
this._started = true;
const subs = this._emitSubscriptions;
subs.push(this._navigator.stateService.currentImageExternal$
.subscribe((image: Image): void => {
const type: ViewerEventType = "image";
const event: ViewerImageEvent = {
image,
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._navigator.stateService.currentImageExternal$.pipe(
switchMap(
(image: Image): Observable<NavigationEdgeStatus> => {
return image.sequenceEdges$;
}))
.subscribe(
(status: NavigationEdgeStatus): void => {
const type: ViewerEventType = "sequenceedges";
const event: ViewerNavigationEdgeEvent = {
status,
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._navigator.stateService.currentImageExternal$.pipe(
switchMap(
(image: Image): Observable<NavigationEdgeStatus> => {
return image.spatialEdges$;
}))
.subscribe(
(status: NavigationEdgeStatus): void => {
const type: ViewerEventType = "spatialedges";
const event: ViewerNavigationEdgeEvent = {
status,
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._navigator.stateService.reference$
.subscribe((reference: LngLatAlt): void => {
const type: ViewerEventType = "reference";
const event: ViewerReferenceEvent = {
reference,
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(observableCombineLatest(
this._navigator.stateService.inMotion$,
this._container.mouseService.active$,
this._container.touchService.active$).pipe(
map(
(values: boolean[]): boolean => {
return values[0] || values[1] || values[2];
}),
distinctUntilChanged())
.subscribe(
(started: boolean) => {
const type: ViewerEventType = started ? "movestart" : "moveend";
const event: ViewerStateEvent = {
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._container.renderService.bearing$.pipe(
auditTime(100),
distinctUntilChanged(
(b1: number, b2: number): boolean => {
return Math.abs(b2 - b1) < 1;
}))
.subscribe(
(bearing): void => {
const type: ViewerEventType = "bearing";
const event: ViewerBearingEvent = {
bearing,
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
const mouseMove$ = this._container.mouseService.active$.pipe(
switchMap(
(active: boolean): Observable<MouseEvent> => {
return active ?
observableEmpty() :
this._container.mouseService.mouseMove$;
}));
subs.push(observableMerge(
this._mapMouseEvent$(
"click",
this._container.mouseService.staticClick$),
this._mapMouseEvent$(
"contextmenu",
this._container.mouseService.contextMenu$),
this._mapMouseEvent$(
"dblclick",
this._container.mouseService.dblClick$),
this._mapMouseEvent$(
"mousedown",
this._container.mouseService.mouseDown$),
this._mapMouseEvent$(
"mousemove",
mouseMove$),
this._mapMouseEvent$(
"mouseout",
this._container.mouseService.mouseOut$),
this._mapMouseEvent$(
"mouseover",
this._container.mouseService.mouseOver$),
this._mapMouseEvent$(
"mouseup",
this._container.mouseService.mouseUp$))
.pipe(
withLatestFrom(
this._container.renderService.renderCamera$,
this._navigator.stateService.reference$,
this._navigator.stateService.currentTransform$,
this._navigator.stateService.state$),
map(
([[type, event], render, reference, transform, state]
: UnprojectionParams)
: ViewerMouseEvent => {
const unprojection: Unprojection =
this._projection.eventToUnprojection(
event,
this._container.container,
render,
reference,
transform);
const basicPoint = state === State.Traversing ?
unprojection.basicPoint : null;
return {
basicPoint,
lngLat: unprojection.lngLat,
originalEvent: event,
pixelPoint: unprojection.pixelPoint,
target: this._viewer,
type: type,
};
}))
.subscribe(
(event: ViewerMouseEvent): void => {
this._viewer.fire(event.type, event);
}));
subs.push(this._container.renderService.renderCamera$.pipe(
distinctUntilChanged(
([x1, y1], [x2, y2]): boolean => {
return this._closeTo(x1, x2, 1e-2) &&
this._closeTo(y1, y2, 1e-2);
},
(rc: RenderCamera): number[] => {
return rc.camera.position.toArray();
}))
.subscribe(
(): void => {
const type: ViewerEventType = "position";
const event: ViewerStateEvent = {
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._navigator.stateService.reference$
.subscribe(
(): void => {
const type: ViewerEventType = "position";
const event: ViewerStateEvent = {
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._container.renderService.renderCamera$.pipe(
distinctUntilChanged(
([phi1, theta1], [phi2, theta2]): boolean => {
return this._closeTo(phi1, phi2, 1e-3) &&
this._closeTo(theta1, theta2, 1e-3);
},
(rc: RenderCamera): [number, number] => {
return [rc.rotation.phi, rc.rotation.theta];
}))
.subscribe(
(): void => {
const type: ViewerEventType = "pov";
const event: ViewerStateEvent = {
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
subs.push(this._container.renderService.renderCamera$.pipe(
distinctUntilChanged(
(fov1, fov2): boolean => {
return this._closeTo(fov1, fov2, 1e-2);
},
(rc: RenderCamera): number => {
return rc.perspective.fov;
}))
.subscribe(
(): void => {
const type: ViewerEventType = "fov";
const event: ViewerStateEvent = {
target: this._viewer,
type,
};
this._viewer.fire(type, event);
}));
}