Skip to content

Commit

Permalink
feat: add option to use computed positions in graph
Browse files Browse the repository at this point in the history
Make it possible to have consistency if data provider
return core images based on computed lng lat.
  • Loading branch information
oscarlorentzon committed Nov 15, 2023
1 parent 5dfc6b3 commit 7fe4052
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 93 deletions.
22 changes: 15 additions & 7 deletions declarations/mapillary.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,14 @@ export interface ViewerOptions {
*/
component?: ComponentOptions;

/**
* Base the graph on computed positions instead of original.
* @description Experimental property.
* @default false
* @ignore
*/
computedGraph?: boolean;

/**
* The HTML element in which MapillaryJS will render the
* viewer, or the element's string `id`. The
Expand Down Expand Up @@ -5683,7 +5691,7 @@ declare class HandlerBase<TConfiguration: ComponentConfiguration> {
* @ignore
*/
constructor(
component: Component<TConfiguration>,
component_: Component<TConfiguration>,
container: Container,
navigator: Navigator
): this;
Expand Down Expand Up @@ -5762,7 +5770,7 @@ declare class KeySpatialNavigationHandler
* @ignore
*/
constructor(
component: Component<KeyboardConfiguration>,
component_: Component<KeyboardConfiguration>,
container: Container,
navigator: Navigator,
spatial: Spatial
Expand Down Expand Up @@ -5791,7 +5799,7 @@ declare class KeyZoomHandler extends HandlerBase<KeyboardConfiguration> {
* @ignore
*/
constructor(
component: Component<KeyboardConfiguration>,
component_: Component<KeyboardConfiguration>,
container: Container,
navigator: Navigator,
viewportCoords: ViewportCoords
Expand Down Expand Up @@ -6138,7 +6146,7 @@ declare class DragPanHandler extends HandlerBase<PointerConfiguration> {
* @ignore
*/
constructor(
component: Component<PointerConfiguration>,
component_: Component<PointerConfiguration>,
container: Container,
navigator: Navigator,
viewportCoords: ViewportCoords,
Expand All @@ -6153,7 +6161,7 @@ declare class EarthControlHandler extends HandlerBase<PointerConfiguration> {
* @ignore
*/
constructor(
component: Component<PointerConfiguration>,
component_: Component<PointerConfiguration>,
container: Container,
navigator: Navigator,
viewportCoords: ViewportCoords,
Expand All @@ -6179,7 +6187,7 @@ declare class ScrollZoomHandler extends HandlerBase<PointerConfiguration> {
* @ignore
*/
constructor(
component: Component<PointerConfiguration>,
component_: Component<PointerConfiguration>,
container: Container,
navigator: Navigator,
viewportCoords: ViewportCoords
Expand All @@ -6204,7 +6212,7 @@ declare class TouchZoomHandler extends HandlerBase<PointerConfiguration> {
* @ignore
*/
constructor(
component: Component<PointerConfiguration>,
component_: Component<PointerConfiguration>,
container: Container,
navigator: Navigator,
viewportCoords: ViewportCoords
Expand Down
25 changes: 22 additions & 3 deletions src/graph/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export type NodeIndexItem = {
node: Image;
};

export type GraphOptions = {
computedGraph?: boolean;
}

/**
* @class Graph
*
Expand All @@ -86,6 +90,8 @@ export type NodeIndexItem = {
export class Graph {
private static _spatialIndex: new (...args: any[]) => any;

private _computedGraph: boolean;

private _api: APIWrapper;

/**
Expand Down Expand Up @@ -226,13 +232,15 @@ export class Graph {
*/
constructor(
api: APIWrapper,
options?: GraphOptions,
nodeIndex?: any,
graphCalculator?: GraphCalculator,
edgeCalculator?: EdgeCalculator,
filterCreator?: FilterCreator,
configuration?: GraphConfiguration) {

this._api = api;
this._computedGraph = options?.computedGraph ?? false;

this._cachedNodes = {};
this._cachedNodeTiles = {};
Expand Down Expand Up @@ -596,8 +604,9 @@ export class Graph {
}
this._makeFull(node, item.node);

const lngLat = this._getNodeLngLat(node);
const cellId = this._api.data.geometry
.lngLatToCellId(node.originalLngLat);
.lngLatToCellId(lngLat);
this._preStore(cellId, node);
this._setNode(node);

Expand Down Expand Up @@ -756,8 +765,9 @@ export class Graph {

this._makeFull(node, item.node);

const lngLat = this._getNodeLngLat(node);
const cellId = this._api.data.geometry
.lngLatToCellId(node.originalLngLat);
.lngLatToCellId(lngLat);
this._preStore(cellId, node);
this._setNode(node);
}
Expand Down Expand Up @@ -1479,7 +1489,8 @@ export class Graph {
if (!this.hasNode(id)) { continue; }

const node = this._nodes[id];
const nodeCellId = geometry.lngLatToCellId(node.lngLat);
const lngLat = this._getNodeLngLat(node);
const nodeCellId = geometry.lngLatToCellId(lngLat);
if (!keepCells.has(nodeCellId)) {
if (id in this._cachedNodeTiles) {
delete this._cachedNodeTiles[id];
Expand Down Expand Up @@ -1948,6 +1959,14 @@ export class Graph {
node.dispose();
}

private _getNodeLngLat(node: Image): LngLat {
if (!this._computedGraph) {
return node.originalLngLat;
}

return node.lngLat;
}

private _preStore(h: string, node: Image): void {
if (!(h in this._preStored)) {
this._preStored[h] = {};
Expand Down
2 changes: 1 addition & 1 deletion src/viewer/Navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Navigator {
this._projectionService = new ProjectionService();

this._graphService = graphService ??
new GraphService(new Graph(this.api), this._projectionService);
new GraphService(new Graph(this.api, options), this._projectionService);

this._loadingName = "navigator";
this._loadingService = loadingService ??
Expand Down
11 changes: 11 additions & 0 deletions src/viewer/options/ViewerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ export interface ViewerOptions {
*/
component?: ComponentOptions;

/**
* Base the graph on computed positions instead of original.
*
* @description Experimental property.
*
* @default false
*
* @ignore
*/
computedGraph?: boolean;

/**
* The HTML element in which MapillaryJS will render the
* viewer, or the element's string `id`. The
Expand Down
Loading

0 comments on commit 7fe4052

Please sign in to comment.