Add example on how one way can be to set options to the viewer

This commit is contained in:
Johan Gyllenspetz 2015-11-07 16:07:11 -08:00
parent b434d6219d
commit 8a809ad9d3
6 changed files with 95 additions and 4 deletions

View File

@ -20,7 +20,6 @@ describe("Viewer.moveToKey", () => {
it("should move to a key", (done) => {
viewer.moveToKey("h_tzkTklF6DZfU5plCA9Cw", (data: any) => {
console.log(data);
done();
});
});

View File

@ -0,0 +1,8 @@
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
declare var Mapillary: any;
describe("OptionsParser", () => {
it("exists", () => {
});
});

View File

@ -2,8 +2,10 @@
import * as when from "when";
import Debug from "./utils/Debug";
import Graph from "./Graph";
import Prefetcher from "./viewer/Prefetcher";
import OptionsParser from "./viewer/OptionsParser";
/* Errors */
import ParameterMapillaryError from "./errors/ParameterMapillaryError";
@ -11,6 +13,7 @@ import ParameterMapillaryError from "./errors/ParameterMapillaryError";
/* Interfaces */
import IAPINavIm from "./interfaces/IAPINavIm";
import ILatLon from "./interfaces/ILatLon";
import IViewerOptions from "./interfaces/IViewerOptions";
export class Viewer {
/**
@ -37,16 +40,29 @@ export class Viewer {
*/
private prefetcher: Prefetcher;
/**
* Options to used to tweak the viewer. Optional if not
* provided Viewer will be set do default.
* @member Mapillary.Viewer#options
* @private
* @type {Prefetcher}
*/
private options: IViewerOptions;
/**
* Initializes a Mapillary viewer
* @class Mapillary.Viewer
* @classdesc A Viewer for viewing Mapillary Street Level Imagery
* @param {string} id of element to transform into viewer
* @param {string} clientId for Mapillary API
* @param {IViewerOptions} Options for the viewer
*/
constructor (id: string, clientId: string) {
constructor (id: string, clientId: string, options: IViewerOptions) {
this.loading = false;
let optionsParser: OptionsParser = new OptionsParser();
this.options = optionsParser.parseAndDefaultOptions(options);
this.graph = new Graph();
this.prefetcher = new Prefetcher(clientId);
}
@ -66,12 +82,12 @@ export class Viewer {
}
if (this.graph.keyIsWorthy(key)) {
console.log("MOVE ON");
Debug.log("MOVE ON");
} else {
let response: when.Promise<IAPINavIm> = this.prefetcher.loadFromKey(key);
response.then((data: IAPINavIm) => {
console.log(data);
if (cb != null) {
Debug.debug(data);
cb(data);
}
});

View File

@ -0,0 +1,19 @@
interface IViewerOptionsStepThr {
maxDistance?: number;
distancePerf?: number;
maxView?: number;
maxDrift?: number;
}
export interface IViewerOptions {
debugLevel?: string;
stepThr?: IViewerOptionsStepThr;
enablePanoNavigation?: boolean;
enablePanoPlaying?: boolean;
enablePanoArrowAlignment?: boolean;
gamingNavigation?: boolean;
}
export default IViewerOptions;

33
src/utils/Debug.ts Normal file
View File

@ -0,0 +1,33 @@
// fixme add more sophistication, this might be a module
enum LogLevel {debug, log, warning, error, off};
export class Debug {
public static logLevel: LogLevel = LogLevel.off;
public static debug(message: any): void {
if (this.logLevel <= LogLevel.debug) {
console.log(message);
}
}
public static log(message: any): void {
if (this.logLevel <= LogLevel.log) {
console.log(message);
}
}
public static warning(message: any): void {
if (this.logLevel <= LogLevel.warning) {
console.log(message);
}
}
public static error(message: any): void {
if (this.logLevel <= LogLevel.error) {
console.log(message);
}
}
}
export default Debug

View File

@ -0,0 +1,16 @@
/* Errors */
import ParameterMapillaryError from "../errors/ParameterMapillaryError";
/* Interfaces */
import IViewerOptions from "../interfaces/IViewerOptions";
export class OptionsParser {
public parseAndDefaultOptions(options: IViewerOptions): IViewerOptions {
if (false) {
throw new ParameterMapillaryError();
}
return options;
}
}
export default OptionsParser