Skip to content

Commit

Permalink
feat: handle spatial edges for graph resets
Browse files Browse the repository at this point in the history
Ensure that the latest graph area request is prioritized.
Cancel prior requests.
  • Loading branch information
oscarlorentzon committed Mar 8, 2024
1 parent e62378b commit ac5b99a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/src/js/utils/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function generateCluster(options, intervals) {
let {idCounter} = options;
const {alt, lat, lng} = options.reference;

const distance = 5;
const distance = options.distance ?? 5;

const images = [];
const thumbUrl = `${cameraType}`;
Expand Down
6 changes: 5 additions & 1 deletion examples/debug/chunk.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
dataProvider,
cameraControls: CameraControls.Earth,
component: {
cache: false,
cover: false,
image: false,
spatial: {
Expand All @@ -73,6 +74,7 @@
imageTiling: false,
};
viewer = new Viewer(options);
viewer.setFilter(['!=', 'cameraType', 'invalid'])
chunks = [];

listen();
Expand All @@ -81,13 +83,15 @@
function generateChunk() {
const cameraType = CAMERA_TYPE_SPHERICAL;
const aspect = cameraTypeToAspect(cameraType);
const distance = 1;
const height = 100;
const counter = chunks.length;
const shift = counter * 10;
const shift = counter * 1;
const mod = 3;
const config = {
cameraType,
color: [1, (counter % mod) / (mod - 1), 0],
distance,
east: shift,
height,
id: counter.toString(),
Expand Down
25 changes: 17 additions & 8 deletions src/graph/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { SpatialImagesContract } from "../api/contracts/SpatialImagesContract";
import { ImagesContract } from "../api/contracts/ImagesContract";
import { SequenceContract } from "../api/contracts/SequenceContract";
import { CoreImagesContract } from "../api/contracts/CoreImagesContract";
import { CancelMapillaryError } from "../error/CancelMapillaryError";

type NodeTiles = {
cache: string[];
Expand Down Expand Up @@ -832,14 +833,20 @@ export class Graph {
}

let batchesToCache: number = batches.length;
let spatialNodes$: Observable<Graph>[] = [];
let spatialArea$: Observable<Graph>[] = [];

for (let batch of batches) {
let spatialNodeBatch$: Observable<Graph> = this._api.getSpatialImages$(batch).pipe(
tap(
(items: SpatialImagesContract): void => {
if (!(key in this._cachingSpatialArea$)) {
return;
const currentSpatialArea = this._requiredSpatialArea[key];
if (currentSpatialArea == null || spatialArea !== currentSpatialArea) {
throw new CancelMapillaryError('Required spatial area changed.');
}

const currentCaching = this._cachingSpatialArea$[key];
if (currentCaching == null || spatialArea$ !== currentCaching) {
throw new CancelMapillaryError('Spatial area caching changed.');
}

for (const item of items) {
Expand Down Expand Up @@ -876,7 +883,8 @@ export class Graph {
}
}

if (--batchesToCache === 0) {
const currentCaching = this._cachingSpatialArea$[key];
if (spatialArea$ === currentCaching) {
delete this._cachingSpatialArea$[key];
}

Expand All @@ -887,16 +895,17 @@ export class Graph {
if (Object.keys(spatialArea.cacheNodes).length === 0) {
this._changed$.next(this);
}

}),
publish(),
refCount());

spatialNodes$.push(spatialNodeBatch$);
spatialArea$.push(spatialNodeBatch$);
}

this._cachingSpatialArea$[key] = spatialNodes$;
this._cachingSpatialArea$[key] = spatialArea$;

return spatialNodes$;
return spatialArea$;
}

/**
Expand Down Expand Up @@ -935,7 +944,7 @@ export class Graph {

let spatialNode: Image = allSpatialNodes[spatialNodeKey];

if (filter(spatialNode)) {
if (spatialNode.complete && filter(spatialNode)) {
potentialNodes.push(spatialNode);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/graph/GraphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { GraphMapillaryError } from "../error/GraphMapillaryError";
import { ProjectionService } from "../viewer/ProjectionService";
import { ICameraFactory } from "../geometry/interfaces/ICameraFactory";
import { ProviderClusterEvent } from "../api/events/ProviderClusterEvent";
import { CancelMapillaryError } from "../error/CancelMapillaryError";

/**
* @class GraphService
Expand Down Expand Up @@ -386,7 +387,12 @@ export class GraphService {
return graph$.pipe(
catchError(
(error: Error): Observable<Graph> => {
console.error(`Failed to cache spatial images (${id}).`, error);
if (error instanceof CancelMapillaryError) {
// tslint:disable-next-line:no-console
console.debug(`Failed to cache spatial area (${id}).`, error);
} else {
console.error(`Failed to cache spatial area (${id}).`, error);
}

return observableEmpty();
}));
Expand Down

0 comments on commit ac5b99a

Please sign in to comment.