From 4eeb5b3525ea4dfb642e17421173e2b043706895 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Wed, 1 Jun 2016 06:20:25 -0400 Subject: [PATCH] fix marker + circle --- src/plugins/googlemaps.ts | 137 ++++++++++++++------------------------ 1 file changed, 51 insertions(+), 86 deletions(-) diff --git a/src/plugins/googlemaps.ts b/src/plugins/googlemaps.ts index 63414f417..e12026def 100644 --- a/src/plugins/googlemaps.ts +++ b/src/plugins/googlemaps.ts @@ -15,19 +15,40 @@ import {CordovaInstance} from './plugin'; * Created by Ibrahim on 3/29/2016. */ declare var plugin: any; + +/** + * You can listen to these events where appropriate + */ +export const GoogleMapsEvent = { + MAP_READY: plugin.google.maps.event.MAP_READY, + MAP_CLICK: plugin.google.maps.event.MAP_CLICK, + MAP_LONG_CLICK: plugin.google.maps.event.MAP_LONG_CLICK, + MY_LOCATION_BUTTON_CLICK: plugin.google.maps.event.MY_LOCATION_BUTTON_CLICK, + CAMERA_CHANGE: plugin.google.maps.event.CAMERA_CHANGE, + CAMERA_IDLE: plugin.google.maps.event.CAMERA_IDLE, + MAP_LOADED: plugin.google.maps.event.MAP_LOADED, + MAP_WILL_MOVE: plugin.google.maps.event.MAP_WILL_MOVE, + MAP_CLOSE: plugin.google.maps.event.MAP_CLOSE, + MARKER_CLICK: plugin.google.maps.event.MARKER_CLICK, + INFO_CLICK: plugin.google.maps.event.INFO_CLICK, + MARKER_DRAG: plugin.google.maps.event.MARKER_DRAG, + MARKER_DRAG_START: plugin.google.maps.event.MARKER_DRAG_START, + MARKER_DRAG_END: plugin.google.maps.event.MARKER_DRAG_END +}; + /** * @name Google Maps * @description This plugin uses the native Google Maps SDK * @usage * ``` - * import {GoogleMaps} from 'ionic-native'; + * import {GoogleMaps, GoogleMapsEvent} from 'ionic-native'; * * ... * * // somewhere in your component * let map = new GoogleMaps('elementID'); * - * map.onInit().subscribe(() => console.log("Map is ready!")); + * map.on(GoogleMapsEvent.MAP_READY).subscribe(() => console.log("Map is ready!")); * ``` */ @Plugin({ @@ -36,17 +57,6 @@ declare var plugin: any; repo: 'https://github.com/mapsplugin/cordova-plugin-googlemaps' }) export class GoogleMap { - static event: any = { - MAP_READY: plugin.google.maps.event.MAP_READY, - MAP_CLICK: plugin.google.maps.event.MAP_CLICK, - MAP_LONG_CLICK: plugin.google.maps.event.MAP_LONG_CLICK, - MY_LOCATION_BUTTON_CLICK: plugin.google.maps.event.MY_LOCATION_BUTTON_CLICK, - CAMERA_CHANGE: plugin.google.maps.event.CAMERA_CHANGE, - CAMERA_IDLE: plugin.google.maps.event.CAMERA_IDLE, - MAP_LOADED: plugin.google.maps.event.MAP_LOADED, - MAP_WILL_MOVE: plugin.google.maps.event.MAP_WILL_MOVE, - MAP_CLOSE: plugin.google.maps.event.MAP_CLOSE - }; _objectInstance: any; /** @@ -76,63 +86,6 @@ export class GoogleMap { } - /** - * Get notified via an Observable when the user changes the view. (Event: CAMERA_CHANGE) - */ - @Cordova({ - eventObservable: true, - event: 'plugin.google.maps.event.CAMERA_CHANGE' - }) - static onCameraChange (): Observable {return; } - - /** - * Get notified via an Observable when the view is on idle. (Event: CAMERA_IDLE) - */ - @Cordova({ - eventObservable: true, - event: 'plugin.google.maps.event.CAMERA_IDLE', - platforms: ['iOS'] - }) - static onCameraIdle (): Observable {return; } - - /** - * Get notified via an Observable when the map is ready. (Event: MAP_READY) - */ - @Cordova({ - eventObservable: true, - event: 'plugin.google.maps.event.MAP_READY' - }) - static onMapReady (): Observable {return; } - - /** - * Get notified via an Observable when the map is loaded. (Event: MAP_LOADED) - */ - @Cordova({ - eventObservable: true, - event: 'plugin.google.maps.event.MAP_LOADED', - platforms: ['Android'] - }) - static onMapLoaded (): Observable {return; } - - /** - * Get notified via an Observable when the map will move. (Event: MAP_WILL_MOVE) - */ - @Cordova({ - eventObservable: true, - event: 'plugin.google.maps.event.MAP_WILL_MOVE', - platforms: ['iOS'] - }) - static onMapWillMove (): Observable {return; } - - /** - * Get notified via an Observable when the user closes the map. (Event: MAP_CLOSE) - */ - @Cordova({ - eventObservable: true, - event: 'plugin.google.maps.event.MAP_CLOSE' - }) - static onMapClose (): Observable {return; } - @CordovaInstance({ sync: true }) @@ -240,29 +193,23 @@ export class GoogleMap { ); } - addCircle (options: GoogleMapsCircleOptions): GoogleMapsCircle { - let objectInstance: any = this._objectInstance.addCircle(options); - return new GoogleMapsCircle(objectInstance); + addCircle (options: GoogleMapsCircleOptions): Promise { + return new Promise( + (resolve, reject) => { + this._objectInstance.addCircle(options, (circle: any) => { + if(circle) resolve(new GoogleMapsCircle(circle)); + else reject(); + }); + } + ); } - @CordovaInstance({ - sync: true - }) addPolygon (options: any): void { } - @CordovaInstance({ - sync: true - }) addPolyline (options: any): void { } - @CordovaInstance({ - sync: true - }) addTileOverlay (options: any): void { } - @CordovaInstance({ - sync: true - }) addGroundOverlay (options: any): void { } @CordovaInstance({ @@ -376,6 +323,15 @@ export class GoogleMapsMarker { constructor (private _objectInstance: any) { } + addEventListener(event: any): Observable { + return new Observable( + (observer) => { + this._objectInstance.addEventListener(event, observer.next); + return () => this._objectInstance.removeEventListener(event, observer.next) + } + ); + } + @CordovaInstance({ sync: true }) @@ -512,7 +468,16 @@ export interface GoogleMapsCircleOptions { } export class GoogleMapsCircle { - constructor(private _objectInstnace: any) { } + constructor(private _objectInstance: any) { } + + addEventListener(event: any): Observable { + return new Observable( + (observer) => { + this._objectInstance.addEventListener(event, observer.next); + return () => this._objectInstance.removeEventListener(event, observer.next) + } + ); + } @CordovaInstance({ sync: true