diff --git a/src/graph/Graph.ts b/src/graph/Graph.ts index 19344c34..daed060b 100644 --- a/src/graph/Graph.ts +++ b/src/graph/Graph.ts @@ -35,7 +35,7 @@ type NodeTiles = { } type SpatialNodes = { - all: NewNode[]; + all: { [key: string]: NewNode }; cacheKeys: string[]; cacheNodes: { [key: string]: NewNode }; } @@ -490,13 +490,13 @@ export class NewGraph { }); let spatialNodes: SpatialNodes = { - all: [], + all: {}, cacheKeys: [], cacheNodes: {}, }; for (let spatialItem of spatialItems) { - spatialNodes.all.push(spatialItem.node); + spatialNodes.all[spatialItem.node.key] = spatialItem.node; if (!spatialItem.node.full) { spatialNodes.cacheKeys.push(spatialItem.node.key); @@ -557,6 +557,10 @@ export class NewGraph { .catch( (error: Error): Observable => { for (let batchKey of batch) { + if (batchKey in spatialNodes.all) { + delete spatialNodes.all[batchKey]; + } + if (batchKey in spatialNodes.cacheNodes) { delete spatialNodes.cacheNodes[batchKey]; } @@ -589,7 +593,17 @@ export class NewGraph { let nextKey: string = sequence.findNextKey(node.key); let prevKey: string = sequence.findPrevKey(node.key); - let potentialEdges: IPotentialEdge[] = this._edgeCalculator.getPotentialEdges(node, this._spatialNodes[key].all, fallbackKeys); + let allSpatialNodes: { [key: string]: NewNode } = this._spatialNodes[key].all; + let potentialNodes: NewNode[] = []; + for (let spatialNodeKey in allSpatialNodes) { + if (!allSpatialNodes.hasOwnProperty(spatialNodeKey)) { + continue; + } + + potentialNodes.push(allSpatialNodes[spatialNodeKey]); + } + + let potentialEdges: IPotentialEdge[] = this._edgeCalculator.getPotentialEdges(node, potentialNodes, fallbackKeys); let edges: IEdge[] = this._edgeCalculator.computeStepEdges( diff --git a/src/graph/edge/EdgeCalculator.ts b/src/graph/edge/EdgeCalculator.ts index e179b206..059fdb1d 100644 --- a/src/graph/edge/EdgeCalculator.ts +++ b/src/graph/edge/EdgeCalculator.ts @@ -61,7 +61,7 @@ export class EdgeCalculator { * be returned even if they do not meet * the criteria for a potential edge. */ - public getPotentialEdges(node: NewNode, nodes: NewNode[], fallbackKeys: string[]): IPotentialEdge[] { + public getPotentialEdges(node: NewNode, potentialNodes: NewNode[], fallbackKeys: string[]): IPotentialEdge[] { if (!node.full) { throw new ArgumentMapillaryError("Node has to be full."); } @@ -77,7 +77,7 @@ export class EdgeCalculator { let potentialEdges: IPotentialEdge[] = []; - for (let potential of nodes) { + for (let potential of potentialNodes) { if (!potential.merged || potential.key === node.key) { continue;