public cacheBoundingBox$()

in src/graph/Graph.ts [313:398]


    public cacheBoundingBox$(sw: LngLat, ne: LngLat): Observable<Image[]> {
        const cacheTiles$ = this._api.data.geometry.bboxToCellIds(sw, ne)
            .filter(
                (h: string): boolean => {
                    return !(h in this._cachedTiles);
                })
            .map(
                (h: string): Observable<Graph> => {
                    return h in this._cachingTiles$ ?
                        this._cachingTiles$[h] :
                        this._cacheTile$(h);
                });

        if (cacheTiles$.length === 0) {
            cacheTiles$.push(observableOf(this));
        }

        return observableFrom(cacheTiles$).pipe(
            mergeAll(),
            last(),
            mergeMap(
                (): Observable<Image[]> => {
                    const nodes = <Image[]>this._nodeIndex
                        .search({
                            maxX: ne.lng,
                            maxY: ne.lat,
                            minX: sw.lng,
                            minY: sw.lat,
                        })
                        .map(
                            (item: NodeIndexItem): Image => {
                                return item.node;
                            });

                    const fullNodes: Image[] = [];
                    const coreNodes: string[] = [];

                    for (const node of nodes) {
                        if (node.complete) {
                            fullNodes.push(node);
                        } else {
                            coreNodes.push(node.id);
                        }
                    }

                    const coreNodeBatches: string[][] = [];
                    const batchSize = 200;
                    while (coreNodes.length > 0) {
                        coreNodeBatches.push(coreNodes.splice(0, batchSize));
                    }

                    const fullNodes$ = observableOf(fullNodes);
                    const fillNodes$ = coreNodeBatches
                        .map((batch: string[]): Observable<Image[]> => {
                            return this._api
                                .getSpatialImages$(batch)
                                .pipe(
                                    map((items: SpatialImagesContract)
                                        : Image[] => {
                                        const result: Image[] = [];
                                        for (const item of items) {
                                            const exists = this
                                                .hasNode(item.node_id);
                                            if (!exists) { continue; }

                                            const node = this
                                                .getNode(item.node_id);
                                            if (!node.complete) {
                                                this._makeFull(node, item.node);
                                            }
                                            result.push(node);
                                        }
                                        return result;
                                    }));
                        });

                    return observableMerge(
                        fullNodes$,
                        observableFrom(fillNodes$).pipe(
                            mergeAll()));
                }),
            reduce(
                (acc: Image[], value: Image[]): Image[] => {
                    return acc.concat(value);
                }));
    }