Support Promise
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.3.0-beta-201800509-1906" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.3.0-beta-201800510-1719" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
www/Circle.js
www/Circle.js
@@ -111,6 +111,11 @@ Circle.prototype.setRadius = function (radius) {
Circle.prototype.remove = function (callback) {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
+ return;
+ } else {
+ return Promise.resolve();
+ }
return;
}
Object.defineProperty(self, "_isRemoved", {
@@ -118,16 +123,27 @@ Circle.prototype.remove = function (callback) {
writable: false
});
self.trigger(self.id + "_remove");
- self.exec.call(self, function () {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
self.destroy();
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()], {
remove: true
});
};
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+
+};
+
Circle.prototype.getBounds = function () {
var d2r = Math.PI / 180; // degrees to radians
var r2d = 180 / Math.PI; // radians to degrees

MODIFY
www/Common.js
www/Common.js
var BaseArrayClass = require('./BaseArrayClass');
var utils = require("cordova/utils");
-var resolvedPromise = typeof Promise == 'undefined' ? null : Promise.resolve();
-var nextTick = resolvedPromise ? function(fn) { resolvedPromise.then(fn); } : function(fn) { setTimeout(fn); };
+var nextTick = Promise.then;
//---------------------------
// Convert HTML color to RGB
@@ -24,21 +23,6 @@ function isHTMLColorString(inputValue) {
return inputValue in HTML_COLORS;
}
-function deleteFromObject(object, type) {
- if (object === null) return object;
- if (typeof object !== "object") {
- return object;
- }
- for(var index in Object.keys(object)) {
- var key = Object.keys(object)[index];
- if (typeof object[key] === 'object') {
- object[key] = deleteFromObject(object[key], type);
- } else if (typeof object[key] === type) {
- delete object[key];
- }
- }
- return object;
-}
function HTMLColor2RGBA(colorValue, defaultOpacity) {
defaultOpacity = !defaultOpacity ? 1.0 : defaultOpacity;
if (colorValue instanceof Array) {
@@ -712,25 +696,11 @@ function hashCode(text) {
return hash;
}
-function assign() {
- var args = [].slice.call(arguments),
- target = args.shift();
-
- return args.reduce(function(base, obj) {
- Object.keys(obj).forEach(function(prop) {
- if (obj.hasOwnProperty(prop)) {
- base[prop] = obj[prop];
- }
- });
- return base;
- }, target);
-}
module.exports = {
_clearInternalCache: _clearInternalCache,
_removeCacheById: _removeCacheById,
getZIndex: getZIndex,
- deleteFromObject: deleteFromObject,
getDivRect: getDivRect,
getDomInfo: getDomInfo,
isDom: isDom,
@@ -748,8 +718,7 @@ module.exports = {
quickfilter: quickfilter,
nextTick: nextTick,
getPluginDomId: getPluginDomId,
- hashCode: hashCode,
- assign: assign
+ hashCode: hashCode
};
if (cordova && cordova.platformId === "browser") {

MODIFY
www/Geocoder.js
www/Geocoder.js
@@ -10,12 +10,41 @@ var Geocoder = function(exec) {
return {
geocode: function(geocoderRequest, callback) {
- var mvcResults = null;
- var requestCnt = 0;
- if (typeof callback !== "function") {
- return;
+
+ geocoderRequest = geocoderRequest || {};
+ var requestProperty = null;
+ if ("position" in geocoderRequest && !("address" in geocoderRequest)) {
+ requestProperty = "position";
+ } else if ("address" in geocoderRequest && !("position" in geocoderRequest)) {
+ requestProperty = "address";
+ }
+ if (!requestProperty) {
+ var error = new Error("Invalid request");
+ if (typeof callback === "function") {
+ callback([], error);
+ } else {
+ return Promise.reject(error);
+ }
+ }
+
+
+ if (geocoderRequest[requestProperty] instanceof Array || Array.isArray(geocoderRequest[requestProperty])) {
+ //-------------------------
+ // Geocoder.geocode({
+ // address: [
+ // "Kyoto, Japan",
+ // "Tokyo, Japan"
+ // ]
+ // })
+ //-------------------------
+
+ var mvcResults = common.createMvcArray();
+ for (i = 0; i < requestCnt; i++) {
+ mvcResults.push(-1, true);
}
+ // Execute geocoder.geocode() when a new request is instearted.
+ var requestCnt = geocoderRequest[requestProperty].length;
var requests = common.createMvcArray();
requests.on('insert_at', function(idx) {
var request = requests.getAt(idx);
@@ -23,9 +52,7 @@ var Geocoder = function(exec) {
exec.call({
_isReady: true
}, function(result) {
- if (!mvcResults) {
- callback(result.results);
- } else {
+
mvcResults.insertAt(result.idx, result.results);
if (mvcResults.getLength() === requestCnt) {
var tmp = mvcResults.getArray();
@@ -33,48 +60,20 @@ var Geocoder = function(exec) {
return ele === -1;
});
if (tmp2.length === 0) {
+ // Notifies `finish` event when all results are received.
mvcResults.trigger("finish");
}
}
- }
+
}, function(error) {
- if (!mvcResults) {
- callback([], error);
- } else {
mvcResults.trigger("error", error);
- }
}, "Geocoder", 'geocode', [request]);
});
- geocoderRequest = geocoderRequest || {};
- var requestProperty = null;
- if ("position" in geocoderRequest && !("address" in geocoderRequest)) {
- requestProperty = "position";
- } else if ("address" in geocoderRequest && !("position" in geocoderRequest)) {
- requestProperty = "address";
- }
- if (!requestProperty) {
- callback([], new Error("Invalid request"));
- return;
- }
- if (geocoderRequest[requestProperty] instanceof Array || Array.isArray(geocoderRequest[requestProperty])) {
- //-------------------------
- // Geocoder.geocode({
- // address: [
- // "Kyoto, Japan",
- // "Tokyo, Japan"
- // ]
- // })
- //-------------------------
- requestCnt = geocoderRequest[requestProperty].length;
- mvcResults = common.createMvcArray();
- for (i = 0; i < requestCnt; i++) {
- mvcResults.push(-1, true);
- }
+
var request;
var baseRequest = utils.clone(geocoderRequest);
delete baseRequest[requestProperty];
-
for (i = 0; i < requestCnt; i++) {
request = utils.clone(baseRequest);
request[requestProperty] = geocoderRequest[requestProperty][i];
@@ -85,7 +84,11 @@ var Geocoder = function(exec) {
}
requests.push(request);
}
+ if (typeof callback === "function") {
callback(mvcResults);
+ } else {
+ return Promise.resolve(mvcResults);
+ }
} else {
//-------------------------
// Geocoder.geocode({
@@ -97,7 +100,19 @@ var Geocoder = function(exec) {
geocoderRequest.position.lng = geocoderRequest.position.lng || 0.0;
}
geocoderRequest.idx = -1;
- requests.push(geocoderRequest);
+
+ var resolver1 = function(resolve, reject) {
+ exec.call({_isReady: true}, resolve, reject, "Geocoder", 'geocode', [geocoderRequest]);
+ };
+
+ if (typeof callback === "function") {
+ resolver(callback, function(error) {
+ callback([], error);
+ });
+ } else {
+ return new Promise(resolver);
+ }
+
}
}

MODIFY
www/GroundOverlay.js
www/GroundOverlay.js
@@ -115,21 +115,36 @@ GroundOverlay.prototype.getClickable = function () {
GroundOverlay.prototype.remove = function (callback) {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
Object.defineProperty(self, "_isRemoved", {
value: true,
writable: false
});
self.trigger(self.id + "_remove");
- self.exec.call(self, function () {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
self.destroy();
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()], {
remove: true
});
};
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+
+};
+
module.exports = GroundOverlay;

MODIFY
www/KmlOverlay.js
www/KmlOverlay.js
@@ -304,7 +304,11 @@ KmlOverlay.prototype.setVisible = function(visible) {
KmlOverlay.prototype.remove = function(callback) {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
Object.defineProperty(self, "_isRemoved", {
value: true,
@@ -327,12 +331,19 @@ KmlOverlay.prototype.remove = function(callback) {
}, cb);
};
+ var resolver = function(resolve, reject) {
removeChildren(self.kmlData, function() {
self.destroy();
+ resolve.call(self);
+ });
+ };
+
if (typeof callback === "function") {
- callback.call(self);
+ resolver.call(self, callback, null);
+ return;
+ } else {
+ return Promise.resolve();
}
- });
};

MODIFY
www/LocationService.js
www/LocationService.js
@@ -16,21 +16,33 @@ var LocationService = function(exec) {
success_callback = args[1];
error_callback = args[2];
- params.enableHighAccuracy = params.enableHighAccuracy === true;
- var successHandler = function(location) {
- if (typeof success_callback === "function") {
+
+ var resolver = function(resolve, reject) {
+ exec.call({
+ _isReady: true
+ },
+ function(location) {
location.latLng = new LatLng(location.latLng.lat, location.latLng.lng);
- success_callback.call(self, location);
- }
+ resolve.call(self, location);
+ },
+ reject.bind(self), 'LocationService', 'getMyLocation', [params], {sync: true});
};
+
+ params.enableHighAccuracy = params.enableHighAccuracy === true;
var errorHandler = function(result) {
if (typeof error_callback === "function") {
error_callback.call(self, result);
+ } else {
+ self.errorHandler.call(self, result);
}
};
- exec.call({
- _isReady: true
- }, successHandler, errorHandler, 'LocationService', 'getMyLocation', [params], {sync: true});
+
+ if (typeof callback === "function") {
+ resolver(callback, errorHandler);
+ return self;
+ } else {
+ return new Promise(resolver);
+ }
}
};
};

MODIFY
www/Map.js
www/Map.js
-var argscheck = require('cordova/argscheck'),
- utils = require('cordova/utils'),
+var utils = require('cordova/utils'),
cordova_exec = require('cordova/exec'),
common = require('./Common'),
Overlay = require('./Overlay'),
@@ -286,7 +285,7 @@ Map.prototype.setOptions = function(options) {
};
Map.prototype.getMyLocation = function(params, success_callback, error_callback) {
- plugin.google.maps.LocationService.getMyLocation.call(this, params, success_callback, error_callback);
+ return plugin.google.maps.LocationService.getMyLocation.call(this, params, success_callback, error_callback);
};
Map.prototype.setCameraTarget = function(latLng) {
@@ -318,7 +317,8 @@ Map.prototype.panBy = function(x, y) {
Map.prototype.clear = function(callback) {
var self = this;
if (self._isRemoved) {
- return;
+ // Simply ignore because this map is already removed.
+ return Promise.resolve();
}
// Close the active infoWindow
@@ -348,15 +348,23 @@ Map.prototype.clear = function(callback) {
clearObj(self.MARKERS);
self.trigger("map_clear");
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, this.id, 'clear', [], {
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ resolve.bind(self),
+ reject.bind(self),
+ self.id, 'clear', [], {
sync: true
});
};
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+
+};
+
/**
* @desc Change the map type
* @param {String} mapTypeId Specifies the one of the follow strings:
@@ -405,13 +413,7 @@ Map.prototype.moveCameraZoomIn = function(callback) {
cameraPosition.zoom++;
cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.id, 'moveCamera', [cameraPosition], {
- sync: true
- });
+ return self.moveCamera(cameraPosition, callback);
};
Map.prototype.moveCameraZoomOut = function(callback) {
@@ -420,14 +422,7 @@ Map.prototype.moveCameraZoomOut = function(callback) {
cameraPosition.zoom--;
cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.id, 'moveCamera', [cameraPosition], {
- sync: true
- });
-
+ return self.moveCamera(cameraPosition, callback);
};
Map.prototype.animateCameraZoomIn = function(callback) {
var self = this;
@@ -435,15 +430,7 @@ Map.prototype.animateCameraZoomIn = function(callback) {
cameraPosition.zoom++;
cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
cameraPosition.duration = 500;
-
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.id, 'animateCamera', [cameraPosition], {
- sync: true
- });
-
+ return self.animateCamera(cameraPosition, callback);
};
Map.prototype.animateCameraZoomOut = function(callback) {
var self = this;
@@ -451,15 +438,7 @@ Map.prototype.animateCameraZoomOut = function(callback) {
cameraPosition.zoom--;
cameraPosition.zoom = cameraPosition.zoom < 0 ? 0 : cameraPosition.zoom;
cameraPosition.duration = 500;
-
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.id, 'animateCamera', [cameraPosition], {
- sync: true
- });
-
+ return self.animateCamera(cameraPosition, callback);
};
/**
* @desc Move the map camera with animation
@@ -468,12 +447,13 @@ Map.prototype.animateCameraZoomOut = function(callback) {
*/
Map.prototype.animateCamera = function(cameraPosition, callback) {
var self = this;
+
var target = cameraPosition.target;
if (!target && "position" in cameraPosition) {
target = cameraPosition.position;
}
if (!target) {
- return;
+ return Promise.reject("No target field is specified.");
}
if (!("padding" in cameraPosition)) {
cameraPosition.padding = 20;
@@ -485,20 +465,29 @@ Map.prototype.animateCamera = function(cameraPosition, callback) {
// skip if no point is specified
if (typeof callback === "function") {
callback.call(self);
- }
return;
+ } else {
+ return Promise.reject("No point is specified.");
+ }
}
}
cameraPosition.target = target;
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.id, 'animateCamera', [cameraPosition], {
+ var resolver = function(resolve, reject) {
+
+ self.exec.call(self,
+ resolve.bind(self),
+ reject.bind(self),
+ self.id, 'animateCamera', [cameraPosition], {
sync: true
});
+ };
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
};
/**
* @desc Move the map camera without animation
@@ -512,7 +501,7 @@ Map.prototype.moveCamera = function(cameraPosition, callback) {
target = cameraPosition.position;
}
if (!target) {
- return;
+ return Promise.reject("No target field is specified.");
}
if (!("padding" in cameraPosition)) {
@@ -524,19 +513,29 @@ Map.prototype.moveCamera = function(cameraPosition, callback) {
// skip if no point is specified
if (typeof callback === "function") {
callback.call(self);
- }
return;
+ } else {
+ return Promise.reject("No point is specified.");
}
}
- cameraPosition.target = target;
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
}
- }, self.errorHandler, self.id, 'moveCamera', [cameraPosition], {
+ cameraPosition.target = target;
+
+ var resolver = function(resolve, reject) {
+
+ self.exec.call(self,
+ resolve.bind(self),
+ reject.bind(self),
+ self.id, 'moveCamera', [cameraPosition], {
sync: true
});
+ };
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
};
Map.prototype.setMyLocationButtonEnabled = function(enabled) {
@@ -582,7 +581,19 @@ Map.prototype.setCompassEnabled = function(enabled) {
return this;
};
Map.prototype.getFocusedBuilding = function(callback) {
- this.exec.call(this, callback, this.errorHandler, this.id, 'getFocusedBuilding', []);
+ var self = this;
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ resolve.bind(self),
+ reject.bind(self),
+ self.id, 'getFocusedBuilding', []);
+ };
+
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
};
Map.prototype.getVisible = function() {
return this.get("visible");
@@ -685,16 +696,25 @@ Map.prototype.remove = function(callback) {
clearObj(self.OVERLAYS);
clearObj(self.MARKERS);
- self.exec.call(this, function() {
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, 'CordovaGoogleMaps', 'removeMap', [self.id], {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(this,
+ resolve.bind(self),
+ reject.bind(self),
+ 'CordovaGoogleMaps', 'removeMap', [self.id],
+ {
sync: true,
remove: true
});
};
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+};
+
Map.prototype.toDataURL = function(params, callback) {
var args = [params || {}, callback];
@@ -707,11 +727,19 @@ Map.prototype.toDataURL = function(params, callback) {
params.uncompress = params.uncompress === true;
var self = this;
- self.exec.call(this, function(image) {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(this,
+ resolve.bind(self),
+ reject.bind(self),
+ self.id, 'toDataURL', [params]);
+ };
+
if (typeof callback === "function") {
- callback.call(self, image);
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
}
- }, self.errorHandler, self.id, 'toDataURL', [params]);
};
/**
@@ -824,15 +852,30 @@ Map.prototype.getVisibleRegion = function(callback) {
*/
Map.prototype.fromLatLngToPoint = function(latLng, callback) {
var self = this;
+
if ("lat" in latLng && "lng" in latLng) {
- self.exec.call(this, function(result) {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(this,
+ resolve.bind(self),
+ reject.bind(self),
+ self.id, 'fromLatLngToPoint', [latLng.lat, latLng.lng]);
+ };
+
if (typeof callback === "function") {
- callback.call(self, result);
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
}
- }, self.errorHandler, self.id, 'fromLatLngToPoint', [latLng.lat, latLng.lng]);
} else {
+ var rejector = function(resolve, reject) {
+ reject("The latLng is invalid");
+ };
+
if (typeof callback === "function") {
- callback.call(self, [undefined, undefined]);
+ rejector(callback, self.errorHandler);
+ } else {
+ return new Promise(rejector);
}
}
@@ -842,16 +885,35 @@ Map.prototype.fromLatLngToPoint = function(latLng, callback) {
*/
Map.prototype.fromPointToLatLng = function(pixel, callback) {
var self = this;
+ if (typeof pixel === "object" && "x" in pixel && "y" in pixel) {
+ pixel = [pixel.x, pixel.y];
+ }
if (pixel.length == 2 && utils.isArray(pixel)) {
- self.exec.call(this, function(result) {
- if (typeof callback === "function") {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(this,
+ function(result) {
var latLng = new LatLng(result[0] || 0, result[1] || 0);
- callback.call(self, latLng);
+ resolve.call(self, latLng);
+ },
+ reject.bind(self),
+ self.id, 'fromPointToLatLng', [pixel[0], pixel[1]]);
+ };
+
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
}
- }, self.errorHandler, self.id, 'fromPointToLatLng', [pixel[0], pixel[1]]);
} else {
+ var rejector = function(resolve, reject) {
+ reject("The pixel[] argument is invalid");
+ };
+
if (typeof callback === "function") {
- callback.call(self, undefined);
+ rejector(callback, self.errorHandler);
+ } else {
+ return new Promise(rejector);
}
}
@@ -925,6 +987,8 @@ Map.prototype.addKmlOverlay = function(kmlOverlayOptions, callback) {
}));
}
+ var resolver = function(resolve, reject) {
+
var loader = new KmlLoader(self, self.exec, kmlOverlayOptions);
loader.parseKmlFile(function(camera, kmlData) {
if (kmlData instanceof BaseClass) {
@@ -933,8 +997,16 @@ Map.prototype.addKmlOverlay = function(kmlOverlayOptions, callback) {
var kmlId = "kmloverlay_" + Math.floor(Math.random() * Date.now());
var kmlOverlay = new KmlOverlay(self, kmlId, camera, kmlData, kmlOverlayOptions);
self.OVERLAYS[kmlId] = kmlOverlay;
- callback(kmlOverlay);
+ resolve.call(self, kmlOverlay);
});
+
+ };
+
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
};

MODIFY
www/Marker.js
www/Marker.js
@@ -96,7 +96,11 @@ utils.extend(Marker, Overlay);
Marker.prototype.remove = function(callback) {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
Object.defineProperty(self, "_isRemoved", {
value: true,
@@ -104,14 +108,25 @@ Marker.prototype.remove = function(callback) {
});
self.trigger(event.INFO_CLOSE); // close open infowindow, otherwise it will stay
self.trigger(self.id + "_remove");
- self.exec.call(self, function() {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
self.destroy();
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()], {
remove: true
});
+ };
+
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+
};
@@ -146,15 +161,32 @@ Marker.prototype.setAnimation = function(animation, callback) {
animation = animation || null;
if (!animation) {
- return;
+ // just ignore
+ if (typeof callback === "function") {
+ return self;
+ } else {
+ return Promise.resolve();
+ }
}
self.set("animation", animation);
- self.exec.call(self, function() {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
+ self.destroy();
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'setAnimation', [self.getId(), animation]);
+ };
+
if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'setAnimation', [self.getId(), animation]);
+ resolver(callback, self.errorHandler);
return self;
+ } else {
+ return new Promise(resolver);
+ }
+
};
Marker.prototype.setDisableAutoPan = function(disableAutoPan) {

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
@@ -213,11 +213,15 @@ MarkerCluster.prototype._onCameraMoved = function() {
};
-MarkerCluster.prototype.remove = function() {
+MarkerCluster.prototype.remove = function(callback) {
var self = this;
self._stopRequest = self.hashCode;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
if (self.debug) {
clearInterval(self.debugTimer);
@@ -282,7 +286,22 @@ MarkerCluster.prototype.remove = function() {
cluster.remove();
});
}
- self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {sync: true, remove: true});
+
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ resolve.bind(self),
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()],
+ {sync: true, remove: true});
+ };
+
+ var answer;
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ result = new Promise(resolver);
+ }
keys = Object.keys(self._markerMap);
keys.forEach(function(markerId) {
@@ -293,6 +312,7 @@ MarkerCluster.prototype.remove = function() {
}
self.off();
+ return answer;
};
MarkerCluster.prototype.removeMarkerById = function(markerId) {
var self = this;

MODIFY
www/Polygon.js
www/Polygon.js
@@ -119,23 +119,38 @@ utils.extend(Polygon, Overlay);
Polygon.prototype.remove = function (callback) {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
Object.defineProperty(self, "_isRemoved", {
value: true,
writable: false
});
self.trigger(this.id + "_remove");
- self.exec.call(self, function () {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
self.destroy();
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()], {
remove: true
});
};
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+
+};
+
Polygon.prototype.setPoints = function (points) {
var self = this;
var mvcArray = self.points;

MODIFY
www/Polyline.js
www/Polyline.js
@@ -152,23 +152,41 @@ Polyline.prototype.getZIndex = function () {
Polyline.prototype.remove = function () {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
Object.defineProperty(self, "_isRemoved", {
value: true,
writable: false
});
- self.exec.call(self, function () {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
self.destroy();
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()], {
remove: true
});
+ };
+
+ var result;
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ result = new Promise(resolver);
+ }
+
if (self.points) {
self.points.empty();
}
self.trigger(self.id + "_remove");
+
+ return result;
};
module.exports = Polyline;

MODIFY
www/StreetViewPanorama.js
www/StreetViewPanorama.js
@@ -216,7 +216,16 @@ StreetViewPanorama.prototype.getPosition = function () {
StreetViewPanorama.prototype.setPosition = function(cameraPosition, callback) {
var self = this;
cameraPosition = cameraPosition || {};
+ if (typeof cameraPosition === "string") {
+ // case: panorama.setPosition(panoId);
+ cameraPosition = {
+ target : cameraPosition
+ };
+ }
if (typeof cameraPosition.target === "object") {
+ // case: panorama.setPosition({
+ // target: {lat: ..., lng: ...}
+ // });
self.set("position", cameraPosition.target);
}
self.exec.call(self, function() {
@@ -266,7 +275,7 @@ StreetViewPanorama.prototype.remove = function(callback) {
};
StreetViewPanorama.prototype._onPanoramaCameraChange = function(eventName, cameraPosition) {
var self = this;
- self.set('camera', common.assign(self.get("camera") || {}, cameraPosition));
+ self.set('camera', utils.clone(self.get("camera") || {}, cameraPosition));
self.set('camera_zoom', cameraPosition.zoom);
self.set('camera_bearing', cameraPosition.bearing);
self.set('camera_tilt', cameraPosition.viewAngle || cameraPosition.tilt);

MODIFY
www/TileOverlay.js
www/TileOverlay.js
@@ -85,21 +85,36 @@ TileOverlay.prototype.getVisible = function () {
TileOverlay.prototype.remove = function (callback) {
var self = this;
if (self._isRemoved) {
+ if (typeof callback === "function") {
return;
+ } else {
+ return Promise.resolve();
+ }
}
Object.defineProperty(self, "_isRemoved", {
value: true,
writable: false
});
self.trigger(self.id + "_remove");
- self.exec.call(self, function () {
+
+ var resolver = function(resolve, reject) {
+ self.exec.call(self,
+ function() {
self.destroy();
- if (typeof callback === "function") {
- callback.call(self);
- }
- }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {
+ resolve.call(self);
+ },
+ reject.bind(self),
+ self.getPluginName(), 'remove', [self.getId()], {
remove: true
});
};
+ if (typeof callback === "function") {
+ resolver(callback, self.errorHandler);
+ } else {
+ return new Promise(resolver);
+ }
+
+};
+
module.exports = TileOverlay;

Support Promise