in src/graph/Graph.ts [927:1002]
public cacheTiles$(key: string): Observable<Graph>[] {
if (key in this._cachedNodeTiles) {
throw new GraphMapillaryError(`Tiles already cached (${key}).`);
}
if (key in this._cachedSpatialEdges) {
throw new GraphMapillaryError(`Spatial edges already cached so tiles considered cached (${key}).`);
}
if (!(key in this._requiredNodeTiles)) {
throw new GraphMapillaryError(`Tiles have not been determined (${key}).`);
}
let nodeTiles: NodeTiles = this._requiredNodeTiles[key];
if (nodeTiles.cache.length === 0 &&
nodeTiles.caching.length === 0) {
throw new GraphMapillaryError(`Tiles already cached (${key}).`);
}
if (!this.hasNode(key)) {
throw new GraphMapillaryError(`Cannot cache tiles of node that does not exist in graph (${key}).`);
}
let hs: string[] = nodeTiles.cache.slice();
nodeTiles.caching = this._requiredNodeTiles[key].caching.concat(hs);
nodeTiles.cache = [];
let cacheTiles$: Observable<Graph>[] = [];
for (let h of nodeTiles.caching) {
const cacheTile$: Observable<Graph> = h in this._cachingTiles$ ?
this._cachingTiles$[h] :
this._cacheTile$(h);
cacheTiles$.push(
cacheTile$.pipe(
tap(
(graph: Graph): void => {
let index: number = nodeTiles.caching.indexOf(h);
if (index > -1) {
nodeTiles.caching.splice(index, 1);
}
if (nodeTiles.caching.length === 0 &&
nodeTiles.cache.length === 0) {
delete this._requiredNodeTiles[key];
this._cachedNodeTiles[key] = true;
}
}),
catchError(
(error: Error): Observable<Graph> => {
let index: number = nodeTiles.caching.indexOf(h);
if (index > -1) {
nodeTiles.caching.splice(index, 1);
}
if (nodeTiles.caching.length === 0 &&
nodeTiles.cache.length === 0) {
delete this._requiredNodeTiles[key];
this._cachedNodeTiles[key] = true;
}
throw error;
}),
finalize(
(): void => {
this._changed$.next(this);
}),
publish(),
refCount()));
}
return cacheTiles$;
}