diff --git a/src/plugins/googlemap.ts b/src/plugins/googlemap.ts index 678bb466e0..809c08f39d 100644 --- a/src/plugins/googlemap.ts +++ b/src/plugins/googlemap.ts @@ -119,7 +119,7 @@ export class GoogleMap { @Cordova() static isAvailable(): Promise { return; } - constructor(element: string|HTMLElement, options?: any) { + constructor(element: string | HTMLElement, options?: any) { if (!!getPlugin('plugin.google.maps.Map')) { if (typeof element === 'string') { element = document.getElementById(element); @@ -133,12 +133,55 @@ export class GoogleMap { } } + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { + return new Observable( + (observer) => { + this._objectInstance.addEventListener(event, observer.next.bind(observer)); + return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer)); + } + ); + } + + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + /** * Listen to a map event. * * @returns {Observable} */ - on(event: any): Observable { + on(eventName: string): Observable { if (!this._objectInstance) { return new Observable((observer) => { observer.error({ error: 'plugin_not_installed' }); @@ -147,7 +190,7 @@ export class GoogleMap { return new Observable( (observer) => { - this._objectInstance.on(event, observer.next.bind(observer)); + this._objectInstance.on(eventName, observer.next.bind(observer)); return () => this._objectInstance.off(event); } ); @@ -158,15 +201,21 @@ export class GoogleMap { * * @returns {Promise} */ - one(event: any): Promise { + one(eventName: string): Promise { if (!this._objectInstance) { return Promise.reject({ error: 'plugin_not_installed' }); } return new Promise( - resolve => this._objectInstance.one(event, resolve) + resolve => this._objectInstance.one(eventName, resolve) ); } + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) setDebuggable(isDebuggable: boolean): void { } @@ -576,7 +625,12 @@ export class GoogleMapsMarker { constructor(private _objectInstance: any) { } - addEventListener(event: any): Observable { + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { return new Observable( (observer) => { this._objectInstance.addEventListener(event, observer.next.bind(observer)); @@ -585,11 +639,25 @@ export class GoogleMapsMarker { ); } + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + /** * Gets a value * @param key */ - @CordovaInstance({sync: true}) + @CordovaInstance({ sync: true }) get(key: string): any { return; } /** @@ -597,9 +665,49 @@ export class GoogleMapsMarker { * @param key * @param value */ - @CordovaInstance({sync: true}) + @CordovaInstance({ sync: true }) set(key: string, value: any): void { } + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + /** * Return true if the marker is visible */ @@ -797,7 +905,12 @@ export class GoogleMapsCircle { constructor(private _objectInstance: any) { } - addEventListener(event: any): Observable { + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { return new Observable( (observer) => { this._objectInstance.addEventListener(event, observer.next.bind(observer)); @@ -806,6 +919,75 @@ export class GoogleMapsCircle { ); } + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) getCenter(): GoogleMapsLatLng { return; } @@ -867,7 +1049,12 @@ export interface GoogleMapsPolylineOptions { export class GoogleMapsPolyline { constructor(private _objectInstance: any) { } - addEventListener(event: any): Observable { + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { return new Observable( (observer) => { this._objectInstance.addEventListener(event, observer.next.bind(observer)); @@ -876,6 +1063,75 @@ export class GoogleMapsPolyline { ); } + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) getPoints(): Array { return; } @@ -938,7 +1194,12 @@ export class GoogleMapsPolygon { constructor(private _objectInstance: any) { } - addEventListener(event: any): Observable { + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { return new Observable( (observer) => { this._objectInstance.addEventListener(event, observer.next.bind(observer)); @@ -947,6 +1208,75 @@ export class GoogleMapsPolygon { ); } + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) getPoints(): Array { return; } @@ -1011,6 +1341,89 @@ export class GoogleMapsTileOverlay { constructor(private _objectInstance: any) { } + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { + return new Observable( + (observer) => { + this._objectInstance.addEventListener(event, observer.next.bind(observer)); + return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer)); + } + ); + } + + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) getVisible(): boolean { return; } @@ -1062,6 +1475,89 @@ export class GoogleMapsGroundOverlay { constructor(private _objectInstance: any) { } + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { + return new Observable( + (observer) => { + this._objectInstance.addEventListener(event, observer.next.bind(observer)); + return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer)); + } + ); + } + + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) setBearing(bearing: number): void { } @@ -1104,6 +1600,89 @@ export class GoogleMapsKmlOverlay { constructor(private _objectInstance: any) { } + /** + * Adds an event listener. + * + * @returns {Observable} + */ + addEventListener(eventName: string): Observable { + return new Observable( + (observer) => { + this._objectInstance.addEventListener(event, observer.next.bind(observer)); + return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer)); + } + ); + } + + /** + * Adds an event listener that works once. + * + * @returns {Promise} + */ + addListenerOnce(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.addListenerOnce(eventName, resolve) + ); + } + + /** + * Gets a value + * @param key + */ + @CordovaInstance({ sync: true }) + get(key: string): any { return; } + + /** + * Sets a value + * @param key + * @param value + */ + @CordovaInstance({ sync: true }) + set(key: string, value: any): void { } + + /** + * Listen to a map event. + * + * @returns {Observable} + */ + on(eventName: string): Observable { + if (!this._objectInstance) { + return new Observable((observer) => { + observer.error({ error: 'plugin_not_installed' }); + }); + } + + return new Observable( + (observer) => { + this._objectInstance.on(eventName, observer.next.bind(observer)); + return () => this._objectInstance.off(event); + } + ); + } + + /** + * Listen to a map event only once. + * + * @returns {Promise} + */ + one(eventName: string): Promise { + if (!this._objectInstance) { + return Promise.reject({ error: 'plugin_not_installed' }); + } + return new Promise( + resolve => this._objectInstance.one(eventName, resolve) + ); + } + + /** + * Clears all stored values + */ + @CordovaInstance({ sync: true }) + empty(): void { } + @CordovaInstance({ sync: true }) remove(): void { }