public start()

in src/viewer/CacheService.ts [61:154]


    public start(): void {
        if (this._started) { return; }

        const subs = this._subscriptions;

        subs.push(this._stateService.currentState$
            .pipe(
                distinctUntilChanged(
                    undefined,
                    (frame: AnimationFrame): string => {
                        return frame.state.currentImage.id;
                    }),
                map(
                    (frame: AnimationFrame): [string[], LngLat, string] => {
                        const state = frame.state;
                        const trajectory = state.trajectory;
                        const trajectoryKeys = trajectory
                            .map(
                                (n: Image): string => {
                                    return n.id;
                                });

                        const sequenceKey =
                            trajectory[trajectory.length - 1].sequenceId;

                        return [
                            trajectoryKeys,
                            state.currentImage.originalLngLat,
                            sequenceKey,
                        ];
                    }),
                bufferCount(1, 5),
                withLatestFrom(this._graphService.graphMode$),
                switchMap(
                    ([keepBuffer, graphMode]: [[string[], LngLat, string][], GraphMode]): Observable<void> => {
                        const keepKeys = keepBuffer[0][0];
                        const lngLat = keepBuffer[0][1];
                        const geometry = this._api.data.geometry;
                        const cellId = geometry.lngLatToCellId(lngLat)
                        const keepCellIds = connectedComponent(
                            cellId, this._cellDepth, geometry);
                        const keepSequenceKey =
                            graphMode === GraphMode.Sequence ?
                                keepBuffer[0][2] :
                                undefined;

                        return this._graphService
                            .uncache$(keepKeys, keepCellIds, keepSequenceKey);
                    }))
            .subscribe(() => { /*noop*/ }));

        subs.push(this._graphService.graphMode$
            .pipe(
                skip(1),
                withLatestFrom(this._stateService.currentState$),
                switchMap(
                    ([mode, frame]: [GraphMode, AnimationFrame]): Observable<NavigationEdgeStatus> => {
                        return mode === GraphMode.Sequence ?
                            this._keyToEdges(
                                frame.state.currentImage.id,
                                (image: Image)
                                    : Observable<NavigationEdgeStatus> => {
                                    return image.sequenceEdges$;
                                }) :
                            observableFrom(frame.state.trajectory
                                .map(
                                    (image: Image): string => {
                                        return image.id;
                                    })
                                .slice(frame.state.currentIndex)).pipe(
                                    mergeMap(
                                        (key: string): Observable<NavigationEdgeStatus> => {
                                            return this._keyToEdges(
                                                key,
                                                (image: Image): Observable<NavigationEdgeStatus> => {
                                                    return image.spatialEdges$;
                                                });
                                        },
                                        6));
                    }))
            .subscribe(() => { /*noop*/ }));

        subs.push(
            this._graphService.dataAdded$
                .pipe(
                    withLatestFrom(this._stateService.currentId$),
                    switchMap(
                        ([_, imageId]: [string, string]): Observable<Image> => {
                            return this._graphService.cacheImage$(imageId)
                        }))
                .subscribe(() => { /*noop*/ }))

        this._started = true;
    }