mapillary-js
Version:
A WebGL interactive street imagery library
1,749 lines (1,698 loc) • 334 kB
TypeScript
import { Observable, Subject, Subscription, BehaviorSubject, Scheduler } from 'rxjs';
import * as THREE from 'three';
import * as vd from 'virtual-dom';
/**
* Convert coordinates from geodetic (WGS84) reference to local topocentric
* (ENU) reference.
*
* @param {number} lng Longitude in degrees.
* @param {number} lat Latitude in degrees.
* @param {number} alt Altitude in meters.
* @param {number} refLng Reference longitude in degrees.
* @param {number} refLat Reference latitude in degrees.
* @param {number} refAlt Reference altitude in meters.
* @returns {Array<number>} The x, y, z local topocentric ENU coordinates.
*/
declare function geodeticToEnu(lng: number, lat: number, alt: number, refLng: number, refLat: number, refAlt: number): number[];
/**
* Convert coordinates from local topocentric (ENU) reference to
* geodetic (WGS84) reference.
*
* @param {number} x Topocentric ENU coordinate in East direction.
* @param {number} y Topocentric ENU coordinate in North direction.
* @param {number} z Topocentric ENU coordinate in Up direction.
* @param {number} refLng Reference longitude in degrees.
* @param {number} refLat Reference latitude in degrees.
* @param {number} refAlt Reference altitude in meters.
* @returns {Array<number>} The longitude, latitude in degrees
* and altitude in meters.
*/
declare function enuToGeodetic(x: number, y: number, z: number, refLng: number, refLat: number, refAlt: number): number[];
/**
* Convert coordinates from Earth-Centered, Earth-Fixed (ECEF) reference
* to local topocentric (ENU) reference.
*
* @param {number} X ECEF X-value.
* @param {number} Y ECEF Y-value.
* @param {number} Z ECEF Z-value.
* @param {number} refLng Reference longitude in degrees.
* @param {number} refLat Reference latitude in degrees.
* @param {number} refAlt Reference altitude in meters.
* @returns {Array<number>} The x, y, z topocentric ENU coordinates in East, North
* and Up directions respectively.
*/
declare function ecefToEnu(X: number, Y: number, Z: number, refLng: number, refLat: number, refAlt: number): number[];
/**
* Convert coordinates from local topocentric (ENU) reference
* to Earth-Centered, Earth-Fixed (ECEF) reference.
*
* @param {number} x Topocentric ENU coordinate in East direction.
* @param {number} y Topocentric ENU coordinate in North direction.
* @param {number} z Topocentric ENU coordinate in Up direction.
* @param {number} refLng Reference longitude in degrees.
* @param {number} refLat Reference latitude in degrees.
* @param {number} refAlt Reference altitude in meters.
* @returns {Array<number>} The X, Y, Z ECEF coordinates.
*/
declare function enuToEcef(x: number, y: number, z: number, refLng: number, refLat: number, refAlt: number): number[];
/**
* Convert coordinates from geodetic reference (WGS84) to Earth-Centered,
* Earth-Fixed (ECEF) reference.
*
* @param {number} lng Longitude in degrees.
* @param {number} lat Latitude in degrees.
* @param {number} alt Altitude in meters.
* @returns {Array<number>} The X, Y, Z ECEF coordinates.
*/
declare function geodeticToEcef(lng: number, lat: number, alt: number): number[];
/**
* Convert coordinates from Earth-Centered, Earth-Fixed (ECEF) reference
* to geodetic reference (WGS84).
*
* @param {number} X ECEF X-value.
* @param {number} Y ECEF Y-value.
* @param {number} Z ECEF Z-value.
* @returns {Array<number>} The longitude, latitude in degrees
* and altitude in meters.
*/
declare function ecefToGeodetic(X: number, Y: number, Z: number): number[];
/**
* Contract describing triangulated meshes.
*/
interface MeshContract {
/**
* Flattened array of faces for the mesh. Each face consist
* three vertex indices.
*/
faces: number[];
/**
* Flattened array of vertices for the mesh. Each vertex
* consists of X, Y and Z coordinates in the camera
* reference frame.
*/
vertices: number[];
}
/**
* Decompress and parse an array buffer containing zipped
* json data and return as a json object.
*
* @description Handles array buffers continaing zipped json
* data.
*
* @param {ArrayBuffer} buffer - Array buffer to decompress.
* @returns {Object} Parsed object.
*/
declare function decompress<T>(buffer: ArrayBuffer): T;
/**
* Retrieves a resource as an array buffer and returns a promise
* to the buffer.
*
* @description Rejects the promise on request failure.
*
* @param {string} url - URL for resource to retrieve.
* @param {Promise} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<ArrayBuffer>} Promise to the array buffer
* resource.
*/
declare function fetchArrayBuffer(url: string, abort?: Promise<void>): Promise<ArrayBuffer>;
/**
* Read the fields of a protobuf array buffer into a mesh
* object.
*
* @param {ArrayBuffer} buffer - Protobuf array buffer
* to read from.
* @returns {MeshContract} Mesh object.
*/
declare function readMeshPbf(buffer: ArrayBuffer): MeshContract;
/**
* Interface describing event emitter members.
*/
interface IEventEmitter {
/**
* @ignore
*/
fire<T>(type: string, event: T): void;
/**
* Unsubscribe from an event by its name.
* @param {string} type - The name of the event
* to unsubscribe from.
* @param {(event: T) => void} handler - The
* handler to remove.
*/
off<T>(type: string, handler: (event: T) => void): void;
/**
* Subscribe to an event by its name.
* @param {string} type - The name of the event
* to subscribe to.
* @param {(event: T) => void} handler - The
* handler called when the event occurs.
*/
on<T>(type: string, handler: (event: T) => void): void;
}
declare class EventEmitter implements IEventEmitter {
private _events;
constructor();
/**
* @ignore
*/
fire<T>(type: string, event: T): void;
/**
* Unsubscribe from an event by its name.
* @param {string} type - The name of the event
* to unsubscribe from.
* @param {(event: T) => void} handler - The
* handler to remove.
*/
off<T>(type: string, handler: (event: T) => void): void;
/**
* Subscribe to an event by its name.
* @param {string} type - The name of the event
* to subscribe to.
* @param {(event: T) => void} handler - The
* handler called when the event occurs.
*/
on<T>(type: string, handler: (event: T) => void): void;
private _listens;
}
/**
* Interface that represents a longitude, latitude coordinate,
* measured in degrees. Coordinates are defined in the WGS84 datum.
*/
interface LngLat {
/**
* Latitude, measured in degrees.
*/
lat: number;
/**
* Longitude, measured in degrees.
*/
lng: number;
}
/**
* Interface that represents longitude-latitude-altitude
* coordinates. Longitude and latitude are measured in degrees
* and altitude in meters. Coordinates are defined in the WGS84 datum.
*
* @interface
*/
interface LngLatAlt extends LngLat {
/**
* Altitude, measured in meters.
*/
alt: number;
}
/**
* Contract describing a reconstruction point.
*/
interface PointContract {
/**
* RGB color vector of the point, normalized to floats
* on the interval [0, 1];
*/
color: number[];
/**
* Coordinates in metric scale in topocentric ENU
* reference frame with respect to a geo reference.
*/
coordinates: number[];
}
/**
* Contract describing cluster reconstruction data.
*/
interface ClusterContract {
/**
* The unique id of the cluster.
*/
id: string;
/**
* The points of the reconstruction.
*/
points: {
[pointId: string]: PointContract;
};
/**
* The reference longitude, latitude, altitude of
* the reconstruction. Determines the
* position of the reconstruction in world reference
* frame.
*/
reference: LngLatAlt;
}
/**
* Ent representing an entity with a unique ID.
*
* @interface IDEnt
*/
interface IDEnt {
/**
* Unique ID.
*/
id: string;
}
/**
* Ent representing core image properties.
*/
interface CoreImageEnt extends IDEnt {
/**
* SfM computed longitude, latitude in WGS84 datum, measured in degrees.
*
* @description Optional - no 3D interaction available
* if unset.
*/
computed_geometry?: LngLat;
/**
* Original EXIF longitude, latitude in WGS84 datum, measured in degrees.
*/
geometry: LngLat;
/**
* Sequence that the image is part of.
*/
sequence: IDEnt;
}
/**
* Contract describing core image results.
*/
interface CoreImagesContract {
/**
* Geometry cell ID.
*/
cell_id: string;
/**
* Array of core image ents.
*/
images: CoreImageEnt[];
}
/**
* Ent representing camera properties.
*/
interface CameraEnt {
/**
* Camera type dependent camera parameters.
*
* For perspective and fisheye camera types,
* the camera parameters array should be
* constructed according to
*
* `[focal, k1, k2]`
*
* where focal is the camera focal length,
* and k1, k2 are radial distortion parameters.
*
* For spherical camera type the camera
* parameters should be an emtpy array.
*/
camera_parameters: number[];
/**
* Projection type of the camera.
*
* @description Supported camera types are:
*
* ```js
* 'spherical'
* 'fisheye'
* 'perspective'
* ```
*
* Other camera types will be treated as
* perspective images.
*/
camera_type: string;
}
/**
* Ent representing URL properties.
*/
interface URLEnt extends IDEnt {
/**
* URL for fetching ent data.
*/
url: string;
}
/**
* Ent representing image creator properties.
*/
interface CreatorEnt extends IDEnt {
/**
* The username of the creator.
*/
username: string;
}
/**
* Ent representing spatial image properties.
*/
interface SpatialImageEnt extends CameraEnt, IDEnt {
/**
* Original EXIF altitude above sea level, in meters.
*/
altitude: number;
/**
* Scale of atomic reconstruction.
*
* @description Optional - no 3D interaction available
* if unset.
*/
atomic_scale?: number;
/**
* Timestamp representing the capture date and time.
*
* @description Unix epoch timestamp in milliseconds.
*/
captured_at: number;
/**
* Original EXIF compass angle, measured in degrees.
*/
compass_angle: number;
/**
* Computed altitude, in meters.
*
* @description Optional - no 3D interaction available
* if unset.
*/
computed_altitude?: number;
/**
* SfM computed compass angle, measured in degrees.
*
* @description Optional - no 3D interaction available
* if unset.
*/
computed_compass_angle?: number;
/**
* Rotation vector in angle axis representation.
*
* @description Optional - no 3D interaction available
* if unset.
*/
computed_rotation?: number[];
/**
* Cluster reconstruction to which the image belongs.
*/
cluster: URLEnt;
/**
* Image creator.
*/
creator: CreatorEnt;
/**
* EXIF orientation of original image.
*/
exif_orientation: number;
/**
* Height of original image, not adjusted for orientation.
*/
height: number;
/**
* SfM connected component id to which the image belongs.
*
* @description Optional - no 3D interaction available
* if unset.
*/
merge_id?: string;
/**
* 3D mesh resource.
*/
mesh: URLEnt;
/**
* Owner to which the image belongs.
*/
owner: IDEnt;
/**
* Value specifying if image is accessible to organization members only
* or to everyone.
*/
private?: boolean;
/**
* Image quality score on the interval [0, 1].
*/
quality_score?: number;
/**
* Image thumbnail resource.
*/
thumb: URLEnt;
/**
* Width of original image, not adjusted for orientation.
*/
width: number;
}
/**
* Contract describing ent results.
*/
interface EntContract<T> {
/**
* Ent node.
*/
node: T;
/**
* Ent node id.
*/
node_id: string;
}
/**
* Contract describing spatial image results.
*/
declare type SpatialImagesContract = EntContract<SpatialImageEnt>[];
/**
* Ent representing image properties.
*/
interface ImageEnt extends CoreImageEnt, SpatialImageEnt {
}
/**
* Contract describing image results.
*/
declare type ImagesContract = EntContract<ImageEnt>[];
/**
* Ent representing sequence properties.
*
* @interface SequenceEnt
*/
interface SequenceEnt extends IDEnt {
/**
* The image IDs of the sequence sorted in
* acsending order based on capture time.
*/
image_ids: string[];
}
/**
* Contract describing sequence results.
*/
declare type SequenceContract = SequenceEnt;
/**
* Ent representing image tile properties.
*/
interface ImageTileEnt {
/**
* URL for fetching image tile pixel data.
*/
url: string;
/**
* X tile coordinate.
*/
x: number;
/**
* Y tile coordinate.
*/
y: number;
/**
* Tile level.
*/
z: number;
}
/**
* Contract describing image tile results.
*/
declare type ImageTilesContract = EntContract<ImageTileEnt[]>;
/**
* Contract describing image tile requests.
*/
interface ImageTilesRequestContract {
/**
* ID of the tile's image.
*/
imageId: string;
/**
* Tile level.
*/
z: number;
}
/**
* @event
*/
declare type ProviderEventType = "datacreate";
/**
*
* Interface for data provider cell events.
*/
interface ProviderCellEvent extends ProviderEvent {
/**
* Cell ids for cells where data have been created.
*/
cellIds: string[];
/**
* Provider event type.
*/
type: "datacreate";
}
/**
* @interface IGeometryProvider
*
* Interface describing geometry provider members.
*
* This is a specification for implementers to model: it
* is not an exported method or class.
*/
interface IGeometryProvider {
/**
* Convert a geodetic bounding box to the the minimum set
* of cell ids containing the bounding box.
*
* @description The bounding box needs
* to be sufficiently small to be contained in an area with the size
* of maximally four tiles. Up to nine adjacent tiles may be returned.
*
* @param {LngLat} sw - South west corner of bounding box.
* @param {LngLat} ne - North east corner of bounding box.
*
* @returns {Array<string>} Array of cell ids.
*/
bboxToCellIds(sw: LngLat, ne: LngLat): string[];
/**
* Get the cell ids of all adjacent cells.
*
* @description In the case of approximately rectangular cells
* this is typically the eight orthogonally and diagonally adjacent
* cells.
*
* @param {string} cellId - Id of cell.
* @returns {Array<string>} Array of cell ids. No specific
* order is guaranteed.
*/
getAdjacent(cellId: string): string[];
/**
* Get the vertices of a cell.
*
* @description The vertices form an unclosed
* clockwise polygon in the 2D longitude, latitude
* space. No assumption on the position of the first
* vertex relative to the others can be made.
*
* @param {string} cellId - Id of cell.
* @returns {Array<LngLat>} Unclosed clockwise polygon.
*/
getVertices(cellId: string): LngLat[];
/**
* Convert geodetic coordinates to a cell id.
*
* @param {LngLat} lngLat - Longitude, latitude to convert.
* @returns {string} Cell id for the longitude, latitude.
*/
lngLatToCellId(lngLat: LngLat): string;
}
/**
* @interface IDataProvider
*
* Interface describing data provider members.
*
* This is a specification for implementers to model: it is
* not an exported method or class.
*
* @fires datacreate
*/
interface IDataProvider extends EventEmitter {
/**
* Get geometry property.
*
* @returns {IGeometryProvider} Geometry provider instance.
*/
geometry: IGeometryProvider;
/**
* Fire when data has been created in the data provider
* after initial load.
*
* @param type datacreate
* @param event Provider cell event
*
* @example
* ```js
* // Initialize the data provider
* class MyDataProvider extends DataProviderBase {
* // Class implementation
* }
* var provider = new MyDataProvider();
* // Create the event
* var cellIds = [ // Determine updated cells ];
* var target = provider;
* var type = "datacreate";
* var event = {
* cellIds,
* target,
* type,
* };
* // Fire the event
* provider.fire(type, event);
* ```
*/
fire(type: "datacreate", event: ProviderCellEvent): void;
/** @ignore */
fire(type: ProviderEventType, event: ProviderEvent): void;
fire<T>(type: ProviderEventType, event: T): void;
/**
* Get core images in a geometry cell.
*
* @param {string} cellId - The id of the geometry cell.
* @returns {Promise<CoreImagesContract>} Promise to
* the core images of the requested geometry cell id.
* @throws Rejects the promise on errors.
*/
getCoreImages(cellId: string): Promise<CoreImagesContract>;
/**
* Get a cluster reconstruction.
*
* @param {string} url - URL for the cluster reconstruction
* to retrieve.
* @param {Promise} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<ClusterContract>} Promise to the
* cluster reconstruction.
* @throws Rejects the promise on errors.
*/
getCluster(url: string, abort?: Promise<void>): Promise<ClusterContract>;
/**
* Get spatial images.
*
* @param {Array<string>} imageIds - The ids for the
* images to retrieve.
* @returns {Promise<SpatialImagesContract>} Promise to
* the spatial images of the requested image ids.
* @throws Rejects the promise on errors.
*/
getSpatialImages(imageIds: string[]): Promise<SpatialImagesContract>;
/**
* Get complete images.
*
* @param {Array<string>} imageIds - The ids for the
* images to retrieve.
* @returns {Promise<ImagesContract>} Promise to the images of the
* requested image ids.
* @throws Rejects the promise on errors.
*/
getImages(imageIds: string[]): Promise<ImagesContract>;
/**
* Get an image as an array buffer.
*
* @param {string} url - URL for image to retrieve.
* @param {Promise<void>} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<ArrayBuffer>} Promise to the array
* buffer containing the image.
* @throws Rejects the promise on errors.
*/
getImageBuffer(url: string, abort?: Promise<void>): Promise<ArrayBuffer>;
/**
* Get image tiles urls for a tile level.
*
* @param {ImageTilesRequestContract} tiles - Tiles to request
* @returns {Promise<ImageTilesContract>} Promise to the
* image tiles response contract
*
* @throws Rejects the promise on errors.
*
* @example
* ```js
* var tileRequest = { imageId: 'image-id', z: 12 };
* provider.getImageTiles(tileRequest)
* .then((response) => console.log(response));
* ```
*/
getImageTiles(tiles: ImageTilesRequestContract): Promise<ImageTilesContract>;
/**
* Get a mesh.
*
* @param {string} url - URL for mesh to retrieve.
* @param {Promise<void>} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<MeshContract>} Promise to the mesh.
* @throws Rejects the promise on errors.
*/
getMesh(url: string, abort?: Promise<void>): Promise<MeshContract>;
/**
* Get sequence.
*
* @param {Array<string>} sequenceId - The id for the
* sequence to retrieve.
* @returns {Promise} Promise to the sequences of the
* requested image ids.
* @throws Rejects the promise on errors.
*/
getSequence(sequenceId: string): Promise<SequenceContract>;
off(type: ProviderCellEvent["type"], handler: (event: ProviderCellEvent) => void): void;
/** @ignore */
off(type: ProviderEventType, handler: (event: ProviderEvent) => void): void;
/** @ignore */
off<T>(type: ProviderEventType, handler: (event: T) => void): void;
/**
* Fired when data has been created in the data provider
* after initial load.
*
* @event datacreate
* @example
* ```js
* // Initialize the data provider
* class MyDataProvider extends DataProviderBase {
* // implementation
* }
* var provider = new MyDataProvider();
* // Set an event listener
* provider.on("datacreate", function() {
* console.log("A datacreate event has occurred.");
* });
* ```
*/
on(type: "datacreate", handler: (event: ProviderCellEvent) => void): void;
/** @ignore */
on(type: ProviderEventType, handler: (event: ProviderEvent) => void): void;
/** @ignore */
on<T>(type: ProviderEventType, handler: (event: T) => void): void;
/**
* Set an access token for authenticated API requests of
* protected resources.
*
* @param {string} [accessToken] accessToken - User access
* token or client access token.
*/
setAccessToken(accessToken?: string): void;
}
/**
* Interface for general provider events.
*/
interface ProviderEvent {
/**
* Data provider target that emitted the event.
*/
target: IDataProvider;
/**
* Provider event type.
*/
type: ProviderEventType;
}
/**
* @class DataProviderBase
*
* @classdesc Base class to extend if implementing a data provider
* class.
*
* @fires datacreate
*
* @example
* ```js
* class MyDataProvider extends DataProviderBase {
* constructor() {
* super(new S2GeometryProvider());
* }
* ...
* }
* ```
*/
declare abstract class DataProviderBase extends EventEmitter implements IDataProvider {
protected _geometry: IGeometryProvider;
/**
* Create a new data provider base instance.
*
* @param {IGeometryProvider} geometry - Geometry
* provider instance.
*/
constructor(_geometry: IGeometryProvider);
/**
* Get geometry property.
*
* @returns {IGeometryProvider} Geometry provider instance.
*/
get geometry(): IGeometryProvider;
/**
* Fire when data has been created in the data provider
* after initial load.
*
* @param type datacreate
* @param event Provider cell event
*
* @example
* ```js
* // Initialize the data provider
* class MyDataProvider extends DataProviderBase {
* // Class implementation
* }
* var provider = new MyDataProvider();
* // Create the event
* var cellIds = [ // Determine updated cells ];
* var target = provider;
* var type = "datacreate";
* var event = {
* cellIds,
* target,
* type,
* };
* // Fire the event
* provider.fire(type, event);
* ```
*/
fire(type: "datacreate", event: ProviderCellEvent): void;
/** @ignore */
fire(type: ProviderEventType, event: ProviderEvent): void;
/**
* Get core images in a geometry cell.
*
* @param {string} cellId - The id of the geometry cell.
* @returns {Promise<CoreImagesContract>} Promise to
* the core images of the requested geometry cell id.
* @throws Rejects the promise on errors.
*/
getCoreImages(cellId: string): Promise<CoreImagesContract>;
/**
* Get a cluster reconstruction.
*
* @param {string} url - URL for the cluster reconstruction
* to retrieve.
* @param {Promise} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<ClusterContract>} Promise to the
* cluster reconstruction.
* @throws Rejects the promise on errors.
*/
getCluster(url: string, abort?: Promise<void>): Promise<ClusterContract>;
/**
* Get spatial images.
*
* @param {Array<string>} imageIds - The ids for the
* images to retrieve.
* @returns {Promise<SpatialImagesContract>} Promise to
* the spatial images of the requested image ids.
* @throws Rejects the promise on errors.
*/
getSpatialImages(imageIds: string[]): Promise<SpatialImagesContract>;
/**
* Get complete images.
*
* @param {Array<string>} imageIds - The ids for the
* images to retrieve.
* @returns {Promise<ImagesContract>} Promise to the images of the
* requested image ids.
* @throws Rejects the promise on errors.
*/
getImages(imageIds: string[]): Promise<ImagesContract>;
/**
* Get an image as an array buffer.
*
* @param {string} url - URL for image to retrieve.
* @param {Promise<void>} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<ArrayBuffer>} Promise to the array
* buffer containing the image.
* @throws Rejects the promise on errors.
*/
getImageBuffer(url: string, abort?: Promise<void>): Promise<ArrayBuffer>;
/**
* Get image tiles urls for a tile level.
*
* @param {ImageTilesRequestContract} tiles - Tiles to request
* @returns {Promise<ImageTilesContract>} Promise to the
* image tiles response contract
*
* @throws Rejects the promise on errors.
*
* @example
* ```js
* var tileRequest = { imageId: 'image-id', z: 12 };
* provider.getImageTiles(tileRequest)
* .then((response) => console.log(response));
* ```
*/
getImageTiles(tiles: ImageTilesRequestContract): Promise<ImageTilesContract>;
/**
* Get a mesh.
*
* @param {string} url - URL for mesh to retrieve.
* @param {Promise<void>} [abort] - Optional promise for aborting
* the request through rejection.
* @returns {Promise<MeshContract>} Promise to the mesh.
* @throws Rejects the promise on errors.
*/
getMesh(url: string, abort?: Promise<void>): Promise<MeshContract>;
/**
* Get sequence.
*
* @param {Array<string>} sequenceId - The id for the
* sequence to retrieve.
* @returns {Promise} Promise to the sequences of the
* requested image ids.
* @throws Rejects the promise on errors.
*/
getSequence(sequenceId: string): Promise<SequenceContract>;
off(type: ProviderCellEvent["type"], handler: (event: ProviderCellEvent) => void): void;
/** @ignore */
off(type: ProviderEventType, handler: (event: ProviderEvent) => void): void;
/**
* Fired when data has been created in the data provider
* after initial load.
*
* @event datacreate
* @example
* ```js
* // Initialize the data provider
* class MyDataProvider extends DataProviderBase {
* // implementation
* }
* var provider = new MyDataProvider();
* // Set an event listener
* provider.on("datacreate", function() {
* console.log("A datacreate event has occurred.");
* });
* ```
*/
on(type: "datacreate", handler: (event: ProviderCellEvent) => void): void;
/** @ignore */
on(type: ProviderEventType, handler: (event: ProviderEvent) => void): void;
/**
* Set an access token for authenticated API requests of
* protected resources.
*
* @param {string} [accessToken] accessToken - User access
* token or client access token.
*/
setAccessToken(accessToken?: string): void;
}
/**
* @class GeometryProviderBase
*
* @classdesc Base class to extend if implementing a geometry
* provider class.
*
* @example
* ```js
* class MyGeometryProvider extends GeometryProviderBase {
* ...
* }
* ```
*/
declare abstract class GeometryProviderBase implements IGeometryProvider {
/**
* Create a new geometry provider base instance.
*/
constructor();
/**
* Convert a geodetic bounding box to the the minimum set
* of cell ids containing the bounding box.
*
* @description The bounding box needs
* to be sufficiently small to be contained in an area with the size
* of maximally four tiles. Up to nine adjacent tiles may be returned.
*
* @param {LngLat} sw - South west corner of bounding box.
* @param {LngLat} ne - North east corner of bounding box.
*
* @returns {Array<string>} Array of cell ids.
*/
bboxToCellIds(sw: LngLat, ne: LngLat): string[];
/**
* Get the cell ids of all adjacent cells.
*
* @description In the case of approximately rectangular cells
* this is typically the eight orthogonally and diagonally adjacent
* cells.
*
* @param {string} cellId - Id of cell.
* @returns {Array<string>} Array of cell ids. No specific
* order is guaranteed.
*/
getAdjacent(cellId: string): string[];
/**
* Get the vertices of a cell.
*
* @description The vertices form an unclosed
* clockwise polygon in the 2D longitude, latitude
* space. No assumption on the position of the first
* vertex relative to the others can be made.
*
* @param {string} cellId - Id of cell.
* @returns {Array<LngLat>} Unclosed clockwise polygon.
*/
getVertices(cellId: string): LngLat[];
/**
* Convert geodetic coordinates to a cell id.
*
* @param {LngLat} lngLat - Longitude, latitude to convert.
* @returns {string} Cell id for the longitude, latitude.
*/
lngLatToCellId(lngLat: LngLat): string;
/** @ignore */
protected _approxBboxToCellIds(sw: LngLat, ne: LngLat): string[];
/** @ignore */
private _enuToGeodetic;
/** @ignore */
private _getLngLatBoundingBoxCorners;
/**
* Convert a geodetic square to cell ids.
*
* The square is specified as a longitude, latitude
* and a threshold from the position using Manhattan distance.
*
* @param {LngLat} lngLat - Longitude, latitude.
* @param {number} threshold - Threshold of the conversion in meters.
*
* @returns {Array<string>} Array of cell ids reachable within
* the threshold.
*
* @ignore
*/
private _lngLatToCellIds;
}
interface GraphCameraContract {
focal: number;
k1: number;
k2: number;
projection_type: string;
}
interface GraphCameraShotContract {
camera: string;
rotation: number[];
translation: number[];
}
interface GraphReferenceContract {
altitude: number;
latitude: number;
longitude: number;
}
interface GraphPointContract {
color: number[];
coordinates: number[];
}
interface GraphClusterContract {
cameras: {
[cameraId: string]: GraphCameraContract;
};
points: {
[pointId: string]: GraphPointContract;
};
reference_lla: GraphReferenceContract;
shots: {
[imageKey: string]: GraphCameraShotContract;
};
}
interface GraphGeometry {
coordinates: [number, number];
}
interface GraphCoreImageEnt extends IDEnt {
computed_geometry: GraphGeometry;
geometry: GraphGeometry;
sequence: string;
}
interface GraphSpatialImageEnt extends SpatialImageEnt {
merge_cc: number;
organization: IDEnt;
sfm_cluster: URLEnt;
thumb_1024_url: string;
thumb_2048_url: string;
}
declare class GraphConverter {
clusterReconstruction(source: GraphClusterContract): ClusterContract;
coreImage(source: GraphCoreImageEnt): CoreImageEnt;
spatialImage(source: GraphSpatialImageEnt): SpatialImageEnt;
private _geometry;
}
interface GraphDataProviderOptions {
endpoint?: string;
accessToken?: string;
}
declare class GraphQueryCreator {
readonly imagesPath: string;
readonly sequencePath: string;
readonly coreFields: string[];
readonly idFields: string[];
readonly spatialFields: string[];
readonly imageTileFields: string[];
private readonly _imageTilesPath;
constructor();
images(imageIds: string[], fields: string[]): string;
imagesS2(cellId: string, fields: string[]): string;
imageTiles(z: number, fields: string[]): string;
imageTilesPath(imageId: string): string;
sequence(sequenceId: string): string;
}
declare class GraphDataProvider extends DataProviderBase {
private readonly _method;
private readonly _endpoint;
private readonly _convert;
private readonly _query;
private _accessToken;
constructor(options?: GraphDataProviderOptions, geometry?: IGeometryProvider, converter?: GraphConverter, queryCreator?: GraphQueryCreator);
getCluster(url: string, abort?: Promise<void>): Promise<ClusterContract>;
getCoreImages(cellId: string): Promise<CoreImagesContract>;
getImageBuffer(url: string, abort?: Promise<void>): Promise<ArrayBuffer>;
getImages(imageIds: string[]): Promise<ImagesContract>;
getImageTiles(request: ImageTilesRequestContract): Promise<ImageTilesContract>;
getMesh(url: string, abort?: Promise<void>): Promise<MeshContract>;
getSequence(sequenceId: string): Promise<SequenceContract>;
getSpatialImages(imageIds: string[]): Promise<SpatialImagesContract>;
setAccessToken(accessToken: string): void;
private _createHeaders;
private _fetchGraphContract;
private _makeErrorMessage;
}
/**
* @class S2GeometryProvider
*
* @classdesc Geometry provider based on S2 cells.
*
* @example
* ```js
* class MyDataProvider extends DataProviderBase {
* ...
* }
*
* const geometryProvider = new S2GeometryProvider();
* const dataProvider = new MyDataProvider(geometryProvider);
* ```
*/
declare class S2GeometryProvider extends GeometryProviderBase {
private readonly _level;
/**
* Create a new S2 geometry provider instance.
*/
constructor(_level?: number);
/** @inheritdoc */
bboxToCellIds(sw: LngLat, ne: LngLat): string[];
/** @inheritdoc */
getAdjacent(cellId: string): string[];
/** @inheritdoc */
getVertices(cellId: string): LngLat[];
/** @inheritdoc */
lngLatToCellId(lngLat: LngLat): string;
private _getNeighbors;
private _lngLatToId;
}
interface ComponentConfiguration {
[key: string]: any;
}
/**
* Enumeration for render mode
* @enum {number}
* @readonly
* @description Modes for specifying how rendering is done
* in the viewer. All modes preserves the original aspect
* ratio of the images.
*/
declare enum RenderMode {
/**
* Displays all content within the viewer.
*
* @description Black bars shown on both
* sides of the content. Bars are shown
* either below and above or to the left
* and right of the content depending on
* the aspect ratio relation between the
* image and the viewer.
*/
Letterbox = 0,
/**
* Fills the viewer by cropping content.
*
* @description Cropping is done either
* in horizontal or vertical direction
* depending on the aspect ratio relation
* between the image and the viewer.
*/
Fill = 1
}
interface ViewportSize {
height: number;
width: number;
}
declare type CameraType = "spherical" | "fisheye" | "perspective";
/**
* @class Transform
*
* @classdesc Class used for calculating coordinate transformations
* and projections.
*/
declare class Transform {
private _width;
private _height;
private _focal;
private _orientation;
private _scale;
private _basicWidth;
private _basicHeight;
private _basicAspect;
private _worldToCamera;
private _worldToCameraInverse;
private _scaledWorldToCamera;
private _scaledWorldToCameraInverse;
private _basicWorldToCamera;
private _textureScale;
private _ck1;
private _ck2;
private _cameraType;
private _radialPeak;
/**
* Create a new transform instance.
* @param {number} orientation - Image orientation.
* @param {number} width - Image height.
* @param {number} height - Image width.
* @param {number} focal - Focal length.
* @param {number} scale - Atomic scale.
* @param {Array<number>} rotation - Rotation vector in three dimensions.
* @param {Array<number>} translation - Translation vector in three dimensions.
* @param {HTMLImageElement} image - Image for fallback size calculations.
*/
constructor(orientation: number, width: number, height: number, scale: number, rotation: number[], translation: number[], image: HTMLImageElement, textureScale?: number[], cameraParameters?: number[], cameraType?: CameraType);
get ck1(): number;
get ck2(): number;
get cameraType(): CameraType;
/**
* Get basic aspect.
* @returns {number} The orientation adjusted aspect ratio.
*/
get basicAspect(): number;
/**
* Get basic height.
*
* @description Does not fall back to image image height but
* uses original value from API so can be faulty.
*
* @returns {number} The height of the basic version image
* (adjusted for orientation).
*/
get basicHeight(): number;
get basicRt(): THREE.Matrix4;
/**
* Get basic width.
*
* @description Does not fall back to image image width but
* uses original value from API so can be faulty.
*
* @returns {number} The width of the basic version image
* (adjusted for orientation).
*/
get basicWidth(): number;
/**
* Get focal.
* @returns {number} The image focal length.
*/
get focal(): number;
/**
* Get height.
*
* @description Falls back to the image image height if
* the API data is faulty.
*
* @returns {number} The orientation adjusted image height.
*/
get height(): number;
/**
* Get orientation.
* @returns {number} The image orientation.
*/
get orientation(): number;
/**
* Get rt.
* @returns {THREE.Matrix4} The extrinsic camera matrix.
*/
get rt(): THREE.Matrix4;
/**
* Get srt.
* @returns {THREE.Matrix4} The scaled extrinsic camera matrix.
*/
get srt(): THREE.Matrix4;
/**
* Get srtInverse.
* @returns {THREE.Matrix4} The scaled extrinsic camera matrix.
*/
get srtInverse(): THREE.Matrix4;
/**
* Get scale.
* @returns {number} The image atomic reconstruction scale.
*/
get scale(): number;
/**
* Get has valid scale.
* @returns {boolean} Value indicating if the scale of the transform is valid.
*/
get hasValidScale(): boolean;
/**
* Get radial peak.
* @returns {number} Value indicating the radius where the radial
* undistortion function peaks.
*/
get radialPeak(): number;
/**
* Get width.
*
* @description Falls back to the image image width if
* the API data is faulty.
*
* @returns {number} The orientation adjusted image width.
*/
get width(): number;
/**
* Calculate the up vector for the image transform.
*
* @returns {THREE.Vector3} Normalized and orientation adjusted up vector.
*/
upVector(): THREE.Vector3;
/**
* Calculate projector matrix for projecting 3D points to texture map
* coordinates (u and v).
*
* @returns {THREE.Matrix4} Projection matrix for 3D point to texture
* map coordinate calculations.
*/
projectorMatrix(): THREE.Matrix4;
/**
* Project 3D world coordinates to basic coordinates.
*
* @param {Array<number>} point3d - 3D world coordinates.
* @return {Array<number>} 2D basic coordinates.
*/
projectBasic(point3d: number[]): number[];
/**
* Unproject basic coordinates to 3D world coordinates.
*
* @param {Array<number>} basic - 2D basic coordinates.
* @param {Array<number>} distance - Distance to unproject from camera center.
* @param {boolean} [depth] - Treat the distance value as depth from camera center.
* Only applicable for perspective images. Will be
* ignored for spherical.
* @returns {Array<number>} Unprojected 3D world coordinates.
*/
unprojectBasic(basic: number[], distance: number, depth?: boolean): number[];
/**
* Project 3D world coordinates to SfM coordinates.
*
* @param {Array<number>} point3d - 3D world coordinates.
* @return {Array<number>} 2D SfM coordinates.
*/
projectSfM(point3d: number[]): number[];
/**
* Unproject SfM coordinates to a 3D world coordinates.
*
* @param {Array<number>} sfm - 2D SfM coordinates.
* @param {Array<number>} distance - Distance to unproject
* from camera center.
* @param {boolean} [depth] - Treat the distance value as
* depth from camera center. Only applicable for perspective
* images. Will be ignored for spherical.
* @returns {Array<number>} Unprojected 3D world coordinates.
*/
unprojectSfM(sfm: number[], distance: number, depth?: boolean): number[];
/**
* Transform SfM coordinates to bearing vector (3D cartesian
* coordinates on the unit sphere).
*
* @param {Array<number>} sfm - 2D SfM coordinates.
* @returns {Array<number>} Bearing vector (3D cartesian coordinates
* on the unit sphere).
*/
private _sfmToBearing;
/** Compute distortion given the distorted radius.
*
* Solves for d in the equation
* y = d(x, k1, k2) * x
* given the distorted radius, y.
*/
private _distortionFromDistortedRadius;
/**
* Transform bearing vector (3D cartesian coordiantes on the unit sphere) to
* SfM coordinates.
*
* @param {Array<number>} bearing - Bearing vector (3D cartesian coordinates on the
* unit sphere).
* @returns {Array<number>} 2D SfM coordinates.
*/
private _bearingToSfm;
/**
* Convert basic coordinates to SfM coordinates.
*
* @param {Array<number>} basic - 2D basic coordinates.
* @returns {Array<number>} 2D SfM coordinates.
*/
private _basicToSfm;
/**
* Convert SfM coordinates to basic coordinates.
*
* @param {Array<number>} sfm - 2D SfM coordinates.
* @returns {Array<number>} 2D basic coordinates.
*/
private _sfmToBasic;
/**
* Checks a value and returns it if it exists and is larger than 0.
* Fallbacks if it is null.
*
* @param {number} value - Value to check.
* @param {number} fallback - Value to fall back to.
* @returns {number} The value or its fallback value if it is not defined or negative.
*/
private _getValue;
private _getCameraParameters;
/**
* Creates the extrinsic camera matrix [ R | t ].
*
* @param {Array<number>} rotation - Rotation vector in angle axis representation.
* @param {Array<number>} translation - Translation vector.
* @returns {THREE.Matrix4} Extrisic camera matrix.
*/
private createWorldToCamera;
/**
* Calculates the scaled extrinsic camera matrix scale * [ R | t ].
*
* @param {THREE.Matrix4} worldToCamera - Extrisic camera matrix.
* @param {number} scale - Scale factor.
* @returns {THREE.Matrix4} Scaled extrisic camera matrix.
*/
private _createScaledWorldToCamera;
private _createBasicWorldToCamera;
private _getRadialPeak;
/**
* Calculate a transformation matrix from normalized coordinates for
* texture map coordinates.
*
* @returns {THREE.Matrix4} Normalized coordinates to texture map
* coordinates transformation matrix.
*/
private _normalizedToTextureMatrix;
}
/**
* @class Camera
*
* @classdesc Holds information about a camera.
*/
declare class Camera {
private _position;
private _lookat;
private _up;
private _focal;
/**
* Create a new camera instance.
* @param {Transform} [transform] - Optional transform instance.
*/
constructor(transform?: Transform);
/**
* Get position.
* @returns {THREE.Vector3} The position vector.
*/
get position(): THREE.Vector3;
/**
* Get lookat.
* @returns {THREE.Vector3} The lookat vector.
*/
get lookat(): THREE.Vector3;
/**
* Get up.
* @returns {THREE.Vector3} The up vector.
*/
get up(): THREE.Vector3;
/**
* Get focal.
* @returns {number} The focal length.
*/
get focal(): number;
/**
* Set focal.
*/
set focal(value: number);
/**
* Update this camera to the linearly interpolated value of two other cameras.
*
* @param {Camera} a - First camera.
* @param {Camera} b - Second camera.
* @param {number} alpha - Interpolation value on the interval [0, 1].
*/
lerpCameras(a: Camera, b: Camera, alpha: number): void;
/**
* Copy the properties of another camera to this camera.
*
* @param {Camera} other - Another camera.
*/
copy(other: Camera): void;
/**
* Clone this camera.
*
* @returns {Camera} A camera with cloned properties equal to this camera.
*/
clone(): Camera;
/**
* Determine the distance between this camera and another camera.
*
* @param {Camera} other - Another camera.
* @returns {number} The distance between the cameras.
*/
diff(other: Camera): number;
/**
* Get the focal length based on the transform.
*
* @description Returns the focal length corresponding
* to a 90 degree field of view for spherical
* transforms.
*
* Returns the transform focal length for other
* projection types.
*
* @returns {number} Focal length.
*/
private _getFocal;
}
declare enum State {
Custom = 0,
Earth = 1,
Traversing = 2,
Waiting = 3,
WaitingInteractively = 4
}
/**
* Enumeration for edge directions
* @enum {number}
* @readonly
* @description Directions for edges in image graph describing
* sequence, spatial and image type relations between nodes.
*/
declare enum NavigationDirection {
/**
* Next image in the sequence.
*/
Next = 0,
/**
* Previous image in the sequence.
*/
Prev = 1,
/**
* Step to the left keeping viewing direction.
*/
StepLeft = 2,
/**
* Step to the right keeping viewing direction.
*/
StepRight = 3,
/**
* Step forward keeping viewing direction.
*/
StepForward = 4,
/**
* Step backward keeping viewing direction.
*/
StepBackward = 5,
/**
* Turn 90 degrees counter clockwise.
*/
TurnLeft = 6,
/**
* Turn 90 degrees clockwise.
*/
TurnRight = 7,
/**
* Turn 180 degrees.
*/
TurnU = 8,
/**
* Spherical in general direction.
*/
Spherical = 9,
/**
* Looking in roughly the same direction at rougly the same position.
*/
Similar = 10
}
/**
* Interface that describes additional properties of an edge.
*
* @interface NavigationEdgeData
*/
interface NavigationEdgeData {
/**
* The edge direction.
*/
direction: NavigationDirection;
/**
* The counter clockwise horizontal rotation angle from
* the X-axis in a spherical coordiante system of the
* motion from the source image to the destination node.
*/
worldMotionAzimuth: number;
}
/**
* Interface that describes the properties for a
* navigation edge from a source image to a
* target image.
*
* @interface NavigationEdge
*/
interface NavigationEdge {
/**
* The id of the source image.
*/
source: string;
/**
* The id of the target image.
*/
target: string;
/**
* Additional data describing properties of the edge.
*/
data: NavigationEdgeData;
}
/**
* Interface that indicates edge status.
*
* @interface NavigationEdgeStatus
*/
interface NavigationEdgeStatus {
/**
* Value indicating whether the edges have been cached.
*/
cached: boolean;
/**
* The edges.
*
* @description If the cached property is false the edges
* property will always be an empty array. If the cached
* property is true, there will exist edges in the the
* array if the image has edges.
*/
edges: NavigationEdge[];
}
/**
* @class ImageCache
*
* @classdesc Represents the cached properties of a image.
*/
declare class ImageCache {
private _disposed;
private _provider;
private _image;
private _mesh;
private _sequenceEdges;
private _spatialEdges;
private _imageAborter;
private _meshAborter;
private _imageChanged$;
private _image$;
private _sequenceEdgesChanged$;
private _sequenceEdges$;
private _spatialEdgesChanged$;
private _spatialEdges$;
private _cachingAssets$;
private _iamgeSubscription;
private _sequenceEdgesSubscription;
private _spatialEdgesSubscription;
/**
* Create a new image cache instance.
*/
constructor(provider: IDataProvider);
/**
* Get image.
*
* @description Will not be set when assets have not been cached
* or when the object has been disposed.
*
* @returns {HTMLImageElement} Cached image element of the image.
*/
get image(): HTMLImageElement;
/**
* Get image$.
*
* @returns {Observable<HTMLImageElement>} Observable emitting
* the cached image when it is updated