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:
parent
b40b0fff98
commit
7d1686ef93
@ -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';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* Created by Ibrahim on 3/29/2016.
|
|
||||||
*/
|
|
||||||
declare var plugin: any;
|
declare var plugin: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,12 +83,13 @@ export const GoogleMapsAnimation = {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@Plugin({
|
let pluginMap = {
|
||||||
pluginRef: 'plugin.google.maps.Map',
|
pluginRef: 'plugin.google.maps.Map',
|
||||||
plugin: 'cordova-plugin-googlemaps',
|
plugin: 'cordova-plugin-googlemaps',
|
||||||
repo: 'https://github.com/mapsplugin/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"'
|
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 {
|
export class GoogleMap {
|
||||||
_objectInstance: any;
|
_objectInstance: any;
|
||||||
|
|
||||||
@ -106,8 +102,14 @@ export class GoogleMap {
|
|||||||
static isAvailable(): Promise<boolean> { return; }
|
static isAvailable(): Promise<boolean> { return; }
|
||||||
|
|
||||||
constructor(element: string|HTMLElement, options?: any) {
|
constructor(element: string|HTMLElement, options?: any) {
|
||||||
if (typeof element === 'string') element = document.getElementById(<string>element);
|
if (!!getPlugin('plugin.google.maps.Map')) {
|
||||||
this._objectInstance = plugin.google.maps.Map.getMap(element, options);
|
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>}
|
* @return {Observable<any>}
|
||||||
*/
|
*/
|
||||||
on(event: any): Observable<any> {
|
on(event: any): Observable<any> {
|
||||||
|
if (!this._objectInstance) {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.error({ error: 'plugin_not_installed' });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return new Observable(
|
return new Observable(
|
||||||
(observer) => {
|
(observer) => {
|
||||||
this._objectInstance.on(event, observer.next.bind(observer));
|
this._objectInstance.on(event, observer.next.bind(observer));
|
||||||
@ -130,6 +138,9 @@ export class GoogleMap {
|
|||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
one(event: any): Promise<any> {
|
one(event: any): Promise<any> {
|
||||||
|
if (!this._objectInstance) {
|
||||||
|
return Promise.reject({ error: 'plugin_not_installed' });
|
||||||
|
}
|
||||||
return new Promise<any>(
|
return new Promise<any>(
|
||||||
resolve => this._objectInstance.one(event, resolve)
|
resolve => this._objectInstance.one(event, resolve)
|
||||||
);
|
);
|
||||||
@ -207,7 +218,10 @@ export class GoogleMap {
|
|||||||
@CordovaInstance({ sync: true })
|
@CordovaInstance({ sync: true })
|
||||||
setAllGesturesEnabled(enabled: boolean): void { }
|
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>(
|
return new Promise<GoogleMapsMarker>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addMarker(options, (marker: any) => {
|
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>(
|
return new Promise<GoogleMapsCircle>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addCircle(options, (circle: any) => {
|
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>(
|
return new Promise<GoogleMapsPolygon>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addPolygon(options, (polygon: any) => {
|
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>(
|
return new Promise<GoogleMapsPolyline>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addPolyline(options, (polyline: any) => {
|
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>(
|
return new Promise<GoogleMapsTileOverlay>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addTileOverlay(options, (tileOverlay: any) => {
|
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>(
|
return new Promise<GoogleMapsGroundOverlay>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addGroundOverlay(options, (groundOverlay: any) => {
|
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>(
|
return new Promise<GoogleMapsKmlOverlay>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
this._objectInstance.addKmlOverlay(options, (kmlOverlay: any) => {
|
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
|
* @param {GeocoderRequest} request Request object with either an address or a position
|
||||||
* @returns {Promise<GeocoderResult[]>}
|
* @returns {Promise<GeocoderResult[]>}
|
||||||
*/
|
*/
|
||||||
static geocode(request: GeocoderRequest): Promise<GeocoderResult[]> {
|
static geocode(request: GeocoderRequest): Promise<GeocoderResult[] | any> {
|
||||||
return new Promise<GeocoderResult[]>((resolve, reject) => {
|
return new Promise<GeocoderResult[]>((resolve, reject) => {
|
||||||
if (!plugin || !plugin.google || !plugin.google.maps || !plugin.google.maps.Geocoder) {
|
if (!plugin || !plugin.google || !plugin.google.maps || !plugin.google.maps.Geocoder) {
|
||||||
|
pluginWarn(pluginMap);
|
||||||
reject({ error: 'plugin_not_installed' });
|
reject({ error: 'plugin_not_installed' });
|
||||||
} else {
|
} else {
|
||||||
plugin.google.maps.Geocoder.geocode(request, resolve);
|
plugin.google.maps.Geocoder.geocode(request, resolve);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user