refactor(googlemaps): throw warnings plugin_not_installed (#655)

* refactor(googlemaps): adjust imports to warnings console and delete @author comments

* refactor(googlemaps): throw warnings plugin_not_installed

* refactor(googlemaps): delete warnings of the methods added Promise.reject case plugin_not_instalet
This commit is contained in:
Ramon Henrique Ornelas 2016-10-08 21:29:53 -03:00 committed by Ibrahim Hadeed
parent b40b0fff98
commit 7d1686ef93

View File

@ -1,11 +1,6 @@
import {Cordova, CordovaInstance, Plugin, InstanceProperty} from './plugin';
import { Cordova, CordovaInstance, Plugin, InstanceProperty, getPlugin, pluginWarn } from './plugin';
import { Observable } from 'rxjs/Observable';
/**
* @private
* Created by Ibrahim on 3/29/2016.
*/
declare var plugin: any;
/**
@ -88,12 +83,13 @@ export const GoogleMapsAnimation = {
* });
* ```
*/
@Plugin({
let pluginMap = {
pluginRef: 'plugin.google.maps.Map',
plugin: 'cordova-plugin-googlemaps',
repo: 'https://github.com/mapsplugin/cordova-plugin-googlemaps',
install: 'ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"'
})
};
@Plugin(pluginMap)
export class GoogleMap {
_objectInstance: any;
@ -106,8 +102,14 @@ export class GoogleMap {
static isAvailable(): Promise<boolean> { return; }
constructor(element: string|HTMLElement, options?: any) {
if (typeof element === 'string') element = document.getElementById(<string>element);
this._objectInstance = plugin.google.maps.Map.getMap(element, options);
if (!!getPlugin('plugin.google.maps.Map')) {
if (typeof element === 'string') {
element = document.getElementById(<string>element);
}
this._objectInstance = plugin.google.maps.Map.getMap(element, options);
} else {
pluginWarn(pluginMap);
}
}
/**
@ -116,6 +118,12 @@ export class GoogleMap {
* @return {Observable<any>}
*/
on(event: any): Observable<any> {
if (!this._objectInstance) {
return new Observable((observer) => {
observer.error({ error: 'plugin_not_installed' });
});
}
return new Observable(
(observer) => {
this._objectInstance.on(event, observer.next.bind(observer));
@ -130,6 +138,9 @@ export class GoogleMap {
* @return {Promise<any>}
*/
one(event: any): Promise<any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<any>(
resolve => this._objectInstance.one(event, resolve)
);
@ -207,7 +218,10 @@ export class GoogleMap {
@CordovaInstance({ sync: true })
setAllGesturesEnabled(enabled: boolean): void { }
addMarker(options: GoogleMapsMarkerOptions): Promise<GoogleMapsMarker> {
addMarker(options: GoogleMapsMarkerOptions): Promise<GoogleMapsMarker | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsMarker>(
(resolve, reject) => {
this._objectInstance.addMarker(options, (marker: any) => {
@ -221,7 +235,10 @@ export class GoogleMap {
);
}
addCircle(options: GoogleMapsCircleOptions): Promise<GoogleMapsCircle> {
addCircle(options: GoogleMapsCircleOptions): Promise<GoogleMapsCircle | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsCircle>(
(resolve, reject) => {
this._objectInstance.addCircle(options, (circle: any) => {
@ -235,7 +252,10 @@ export class GoogleMap {
);
}
addPolygon(options: GoogleMapsPolygonOptions): Promise<GoogleMapsPolygon> {
addPolygon(options: GoogleMapsPolygonOptions): Promise<GoogleMapsPolygon | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsPolygon>(
(resolve, reject) => {
this._objectInstance.addPolygon(options, (polygon: any) => {
@ -249,7 +269,10 @@ export class GoogleMap {
);
}
addPolyline(options: GoogleMapsPolylineOptions): Promise<GoogleMapsPolyline> {
addPolyline(options: GoogleMapsPolylineOptions): Promise<GoogleMapsPolyline | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsPolyline>(
(resolve, reject) => {
this._objectInstance.addPolyline(options, (polyline: any) => {
@ -263,7 +286,10 @@ export class GoogleMap {
);
}
addTileOverlay(options: GoogleMapsTileOverlayOptions): Promise<GoogleMapsTileOverlay> {
addTileOverlay(options: GoogleMapsTileOverlayOptions): Promise<GoogleMapsTileOverlay | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsTileOverlay>(
(resolve, reject) => {
this._objectInstance.addTileOverlay(options, (tileOverlay: any) => {
@ -277,7 +303,10 @@ export class GoogleMap {
);
}
addGroundOverlay(options: GoogleMapsGroundOverlayOptions): Promise<GoogleMapsGroundOverlay> {
addGroundOverlay(options: GoogleMapsGroundOverlayOptions): Promise<GoogleMapsGroundOverlay | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsGroundOverlay>(
(resolve, reject) => {
this._objectInstance.addGroundOverlay(options, (groundOverlay: any) => {
@ -291,7 +320,10 @@ export class GoogleMap {
);
}
addKmlOverlay(options: GoogleMapsKmlOverlayOptions): Promise<GoogleMapsKmlOverlay> {
addKmlOverlay(options: GoogleMapsKmlOverlayOptions): Promise<GoogleMapsKmlOverlay | any> {
if (!this._objectInstance) {
return Promise.reject({ error: 'plugin_not_installed' });
}
return new Promise<GoogleMapsKmlOverlay>(
(resolve, reject) => {
this._objectInstance.addKmlOverlay(options, (kmlOverlay: any) => {
@ -942,9 +974,10 @@ export class Geocoder {
* @param {GeocoderRequest} request Request object with either an address or a position
* @returns {Promise<GeocoderResult[]>}
*/
static geocode(request: GeocoderRequest): Promise<GeocoderResult[]> {
static geocode(request: GeocoderRequest): Promise<GeocoderResult[] | any> {
return new Promise<GeocoderResult[]>((resolve, reject) => {
if (!plugin || !plugin.google || !plugin.google.maps || !plugin.google.maps.Geocoder) {
pluginWarn(pluginMap);
reject({ error: 'plugin_not_installed' });
} else {
plugin.google.maps.Geocoder.geocode(request, resolve);