Implement safe_mode
MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -99,6 +99,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
private Projection projection = null;
public Marker activeMarker = null;
private boolean isDragging = false;
+ private final Object dummyObj = new Object();
private enum TEXT_STYLE_ALIGNMENTS {
@@ -356,10 +357,8 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
});
} else {
mapView.setVisibility(View.VISIBLE);
+ PluginMap.this.onCameraEvent("camera_end");
callbackContext.success();
- //if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
- PluginMap.this.onMapLoaded();
- //}
}
}
});
@@ -377,6 +376,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
});
} else {
mapView.setVisibility(View.VISIBLE);
+ PluginMap.this.onCameraEvent("camera_end");
callbackContext.success();
//if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
PluginMap.this.onMapLoaded();
@@ -434,11 +434,11 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
}
map.moveCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
mapView.setVisibility(View.VISIBLE);
-
mCallback.success();
- if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
+
+ //if (map.getMapType() == GoogleMap.MAP_TYPE_NONE) {
PluginMap.this.onMapLoaded();
- }
+ //}
//fitBounds(initCameraBounds, CAMERA_PADDING);
}
@@ -577,7 +577,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (args.length() == 0) {
PluginMap.this.mapDivId = null;
mapCtrl.mPluginLayout.removePluginMap(mapId);
- this.sendNoResult(callbackContext);
+ callbackContext.success();
return;
}
PluginMap.this.mapDivId = args.getString(0);
@@ -595,7 +595,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
boolean clickable = args.getBoolean(0);
this.isClickable = clickable;
//mapCtrl.mPluginLayout.setClickable(mapId, clickable);
- this.sendNoResult(callbackContext);
+ callbackContext.success();
}
/**
@@ -615,7 +615,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
} else {
mapView.setVisibility(View.INVISIBLE);
}
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -710,7 +710,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
System.gc();
Runtime.getRuntime().gc();
if (callbackContext != null) {
- sendNoResult(callbackContext);
+ callbackContext.success();
}
PluginMap.this.onDestroy();
}
@@ -1183,10 +1183,10 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
args.put(isEnabled);
PluginMap.this.setMyLocationEnabled(args, callbackContext);
} else {
- sendNoResult(callbackContext);
+ callbackContext.success();
}
} else {
- sendNoResult(callbackContext);
+ callbackContext.success();
}
} catch (JSONException e) {
@@ -1645,7 +1645,6 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@SuppressWarnings("unused")
public void clear(JSONArray args, final CallbackContext callbackContext) throws JSONException {
-
cordova.getThreadPool().submit(new Runnable() {
@Override
public void run() {
@@ -1697,7 +1696,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void run() {
map.setIndoorEnabled(isEnabled);
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -1714,7 +1713,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void run() {
map.setTrafficEnabled(isEnabled);
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -1732,7 +1731,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
public void run() {
UiSettings uiSettings = map.getUiSettings();
uiSettings.setCompassEnabled(isEnabled);
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -1763,7 +1762,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void run() {
map.setMapType(myMapTypeId);
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -1949,7 +1948,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
public void run() {
UiSettings uiSettings = map.getUiSettings();
uiSettings.setAllGesturesEnabled(isEnabled);
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -1970,7 +1969,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void run() {
map.setPadding(left, top, right, bottom);
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -1991,7 +1990,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (marker != null) {
activeMarker = marker;
}
- sendNoResult(callbackContext);
+ callbackContext.success();
}
});
}
@@ -2102,7 +2101,6 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void onMapLoaded() {
this.onCameraEvent("camera_end");
- this.onMapEvent("map_loaded");
}

MODIFY
www/Circle.js
www/Circle.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
LatLngBounds = require('./LatLngBounds'),
BaseClass = require('./BaseClass');
@@ -8,7 +7,9 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* Circle Class
*****************************************************************************/
-var Circle = function(map, circleId, circleOptions) {
+var exec;
+var Circle = function(map, circleId, circleOptions, _exec) {
+ exec = _exec;
BaseClass.apply(this);
var self = this;

MODIFY
www/GroundOverlay.js
www/GroundOverlay.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
BaseClass = require('./BaseClass');
/*****************************************************************************
* GroundOverlay Class
*****************************************************************************/
-var GroundOverlay = function(map, groundOverlayId, groundOverlayOptions) {
+var exec;
+var GroundOverlay = function(map, groundOverlayId, groundOverlayOptions, _exec) {
BaseClass.apply(this);
+ exec = _exec;
var self = this;
groundOverlayOptions.visible = groundOverlayOptions.visible === undefined ? true : groundOverlayOptions.visible;

MODIFY
www/KmlOverlay.js
www/KmlOverlay.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
BaseClass = require('./BaseClass');
/*****************************************************************************
* KmlOverlay Class
*****************************************************************************/
-var KmlOverlay = function(map, kmlOverlayId, kmlOverlayOptions) {
+var exec;
+var KmlOverlay = function(map, kmlOverlayId, kmlOverlayOptions, _exec) {
BaseClass.apply(this);
var self = this;

MODIFY
www/Map.js
www/Map.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
+ cordova_exec = require('cordova/exec'),
common = require('./Common'),
BaseClass = require('./BaseClass'),
BaseArrayClass = require('./BaseArrayClass'),
@@ -23,9 +23,11 @@ var MarkerCluster = require('./MarkerCluster');
/**
* Google Maps model.
*/
-var Map = function(id) {
+var exec;
+var Map = function(id, _exec) {
var self = this;
BaseClass.apply(self);
+ exec = _exec;
self.MARKERS = {};
self.KML_LAYERS = {};
@@ -165,10 +167,8 @@ Map.prototype.getMap = function(mapId, div, options) {
cordova.fireDocumentEvent('plugin_touch', {});
exec(function() {
- self.one(event.MAP_LOADED, function() {
self.refreshLayout();
self.trigger(event.MAP_READY, self);
- });
}, self.errorHandler, 'CordovaGoogleMaps', 'getMap', args);
};
@@ -715,7 +715,7 @@ Map.prototype.addKmlOverlay = function(kmlOverlayOptions, callback) {
var kmlId = "kml" + (Math.random() * 9999999).toFixed(0);
kmlOverlayOptions.kmlId = kmlId;
- var kmlOverlay = new KmlOverlay(self, kmlId, kmlOverlayOptions);
+ var kmlOverlay = new KmlOverlay(self, kmlId, kmlOverlayOptions, exec);
self.OVERLAYS[kmlId] = kmlOverlay;
self.KML_LAYERS[kmlId] = kmlOverlay;
@@ -746,7 +746,7 @@ Map.prototype.addGroundOverlay = function(groundOverlayOptions, callback) {
groundOverlayOptions.bounds = common.convertToPositionArray(groundOverlayOptions.bounds);
exec(function(result) {
- var groundOverlay = new GroundOverlay(self, result.id, groundOverlayOptions);
+ var groundOverlay = new GroundOverlay(self, result.id, groundOverlayOptions, exec);
self.OVERLAYS[result.id] = groundOverlay;
groundOverlay.one(result.id + "_remove", function() {
groundOverlay.off();
@@ -804,7 +804,7 @@ Map.prototype.addTileOverlay = function(tilelayerOptions, callback) {
});
exec(function(result) {
- var tileOverlay = new TileOverlay(self, result.id, tilelayerOptions);
+ var tileOverlay = new TileOverlay(self, result.id, tilelayerOptions, exec);
self.OVERLAYS[result.id] = tileOverlay;
tileOverlay.one(result.id + "_remove", function() {
tileOverlay.off();
@@ -849,7 +849,7 @@ Map.prototype.addPolygon = function(polygonOptions, callback) {
exec(function(result) {
polygonOptions.points = _orgs;
- var polygon = new Polygon(self, result.id, polygonOptions);
+ var polygon = new Polygon(self, result.id, polygonOptions, exec);
self.OVERLAYS[result.id] = polygon;
polygon.one(result.id + "_remove", function() {
polygon.off();
@@ -878,7 +878,7 @@ Map.prototype.addPolyline = function(polylineOptions, callback) {
polylineOptions.geodesic = polylineOptions.geodesic === true;
exec(function(result) {
polylineOptions.points = _orgs;
- var polyline = new Polyline(self, result.id, polylineOptions);
+ var polyline = new Polyline(self, result.id, polylineOptions, exec);
self.OVERLAYS[result.id] = polyline;
polyline.one(result.id + "_remove", function() {
polyline.off();
@@ -907,7 +907,7 @@ Map.prototype.addCircle = function(circleOptions, callback) {
circleOptions.radius = circleOptions.radius || 1;
exec(function(result) {
- var circle = new Circle(self, result.id, circleOptions);
+ var circle = new Circle(self, result.id, circleOptions, exec);
self.OVERLAYS[result.id] = circle;
circle.one(result.id + "_remove", function() {
@@ -929,7 +929,7 @@ Map.prototype.addMarker = function(markerOptions, callback) {
var self = this;
markerOptions = common.markerOptionsFilter(markerOptions);
exec(function(result) {
- var marker = new Marker(self, result.id, markerOptions, "Marker");
+ var marker = new Marker(self, result.id, markerOptions, "Marker", exec);
self.MARKERS[result.id] = marker;
self.OVERLAYS[result.id] = marker;
@@ -969,7 +969,7 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
markerOptions = common.markerOptionsFilter(markerOptions);
var markerId = markerOptions.id || "marker_" + idx;
- var marker = new Marker(self, markerId, markerOptions, "MarkerCluster");
+ var marker = new Marker(self, markerId, markerOptions, "MarkerCluster", exec);
marker.set("isAdded", false, true);
marker.set("geocell", geocell, true);
marker.set("position", markerOptions.position, true);
@@ -986,7 +986,8 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
"icons": markerClusterOptions.icons,
"markerMap": markerMap,
"maxZoomLevel": Math.max(markerClusterOptions.maxZoomLevel, 18) || 15,
- "debug": markerClusterOptions.debug === true
+ "debug": markerClusterOptions.debug === true,
+ "exec": exec
});
markerCluster.one("remove", function() {
delete self.OVERLAYS[result.id];

MODIFY
www/Marker.js
www/Marker.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
LatLng = require('./LatLng'),
event = require('./event'),
@@ -9,7 +8,9 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* Marker Class
*****************************************************************************/
-var Marker = function(map, id, markerOptions, className) {
+var exec;
+var Marker = function(map, id, markerOptions, className, _exec) {
+ exec = _exec;
BaseClass.apply(this);
var self = this;

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
event = require('./event'),
geomodel = require('./geomodel'),
@@ -15,7 +14,9 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* MarkerCluster Class
*****************************************************************************/
-var MarkerCluster = function(map, id, markerClusterOptions) {
+var exec;
+var MarkerCluster = function(map, id, markerClusterOptions, _exec) {
+ exec = _exec;
BaseClass.call(this);
var idxCount = Object.keys(markerClusterOptions.markerMap) + 1;

MODIFY
www/Polygon.js
www/Polygon.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
BaseClass = require('./BaseClass'),
BaseArrayClass = require('./BaseArrayClass');
@@ -8,7 +7,9 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* Polygon Class
*****************************************************************************/
-var Polygon = function(map, polygonId, polygonOptions) {
+var exec;
+var Polygon = function(map, polygonId, polygonOptions, _exec) {
+ exec = _exec;
BaseClass.apply(this);
var self = this;

MODIFY
www/Polyline.js
www/Polyline.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
BaseClass = require('./BaseClass'),
BaseArrayClass = require('./BaseArrayClass');
@@ -8,7 +7,9 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* Polyline Class
*****************************************************************************/
-var Polyline = function(map, polylineId, polylineOptions) {
+var exec;
+var Polyline = function(map, polylineId, polylineOptions, _exec) {
+ exec = _exec;
BaseClass.apply(this);
var self = this;

MODIFY
www/TileOverlay.js
www/TileOverlay.js
@@ -7,7 +7,9 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* TileOverlay Class
*****************************************************************************/
-var TileOverlay = function(map, tileOverlayId, tileOverlayOptions) {
+var exec;
+var TileOverlay = function(map, tileOverlayId, tileOverlayOptions, _exec) {
+ exec = _exec;
BaseClass.apply(this);
var self = this;

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
@@ -7,6 +7,7 @@ if (!cordova) {
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
exec = require('cordova/exec'),
+ cordova_exec = require('cordova/exec'),
event = require('./event'),
common = require('./Common'),
BaseClass = require('./BaseClass'),
@@ -379,6 +380,57 @@ function nativeCallback(params) {
this[params.callback].apply(this, args);
}
+var taskQueue = [];
+var _isRemove = false;
+var _isWaitMethod = null;
+var _isExecuting = false;
+function exec_serial(success, error, pluginName, methodName, args) {
+ var self = this;
+ taskQueue.push([function() {
+ if (success) {
+ var results = [];
+ for (var i = 0; i < arguments.length; i++) {
+ results.push(arguments[i]);
+ }
+ success.apply(self, results);
+ }
+ if (methodName === _isWaitMethod) {
+ _isWaitMethod = null;
+ }
+ _exec();
+ }, function() {
+ if (error) {
+ var results = [];
+ for (var i = 0; i < arguments.length; i++) {
+ results.push(arguments[i]);
+ }
+ error.apply(self, results);
+ }
+
+ if (methodName === _isWaitMethod) {
+ _isWaitMethod = null;
+ }
+ _exec();
+ }, pluginName, methodName, args]);
+
+ if (_isRemove || _isExecuting || taskQueue.length > 1) {
+ return;
+ }
+ _exec();
+}
+function _exec() {
+ if (_isRemove || _isExecuting || _isWaitMethod || taskQueue.length === 0) {
+ return;
+ }
+ _isExecuting = true;
+ var taskParams = taskQueue.shift();
+ if (taskParams[3] === "clear") {
+ _isWaitMethod = taskParams[3];
+ }
+ cordova_exec.apply(this, taskParams);
+ _isExecuting = false;
+}
+
/*****************************************************************************
* Name space
*****************************************************************************/
@@ -392,7 +444,7 @@ module.exports = {
BaseClass: BaseClass,
BaseArrayClass: BaseArrayClass,
Map: {
- getMap: function(div) {
+ getMap: function(div, mapOptions) {
var mapId;
if (common.isDom(div)) {
mapId = div.getAttribute("__pluginMapId");
@@ -412,7 +464,8 @@ module.exports = {
div.setAttribute("__pluginMapId", mapId);
}
- var map = new Map(mapId);
+ var exec = mapOptions && mapOptions.execMode === "async" ? cordova_exec : exec_serial;
+ var map = new Map(mapId, exec);
// Catch all events for this map instance, then pass to the instance.
document.addEventListener(mapId, nativeCallback.bind(map));

Implement safe_mode