Prevent map events before the map_ready event
MODIFY
www/Circle.js
www/Circle.js
@@ -141,6 +141,7 @@ Circle.prototype.setRadius = function(radius) {
Circle.prototype.remove = function() {
this.trigger(this.id + "_remove");
exec(null, this.errorHandler, this.getPluginName(), 'remove', [this.getId()]);
+ this.destroy();
};
Circle.prototype.getBounds = function() {

MODIFY
www/Cluster.js
www/Cluster.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
Marker = require('./Marker'),
geomodel = require('./geomodel'),
@@ -111,7 +110,6 @@ Cluster.prototype.remove = function() {
this._markerOptsArray.forEach(function(markerOpts) {
markerOpts._cluster.isAdded = false;
});
-
};
Cluster.prototype.getItemLength = function() {
return this._markerOptsArray.length;

MODIFY
www/GroundOverlay.js
www/GroundOverlay.js
@@ -144,6 +144,7 @@ GroundOverlay.prototype.getClickable = function() {
GroundOverlay.prototype.remove = function() {
this.trigger(this.id + "_remove");
exec(null, this.errorHandler, this.getPluginName(), 'remove', [this.getId()]);
+ this.destroy();
};

MODIFY
www/Map.js
www/Map.js
@@ -42,6 +42,7 @@ var Map = function(id, _exec) {
value: id,
writable: false
});
+ this._isReady = false;
self.on("active_marker_id_changed", function(prevId, newId) {
if (prevId in self.MARKERS) {
@@ -173,6 +174,7 @@ Map.prototype.getMap = function(mapId, div, options) {
//------------------------------------------------------------------------
setTimeout(function() {
self.refreshLayout();
+ self._isReady = true;
self.trigger(event.MAP_READY, self);
}, 250);
}, self.errorHandler, 'CordovaGoogleMaps', 'getMap', args, {sync: true});
@@ -498,6 +500,7 @@ Map.prototype.getCameraPosition = function() {
*/
Map.prototype.remove = function(callback) {
var self = this;
+ self._isReady = false;
var div = this.get('div');
if (div) {
while (div) {
@@ -517,7 +520,7 @@ Map.prototype.remove = function(callback) {
self.set('div', undefined);
self.clear();
self.empty();
- self.off();
+ self.destroy();
exec(function() {
if (typeof callback === "function") {
callback.call(self);
@@ -1021,7 +1024,7 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
delete self.OVERLAYS[markerId];
});
*/
- markerCluster.off();
+ markerCluster.destroy();
});
self.OVERLAYS[result.id] = markerCluster;
@@ -1045,6 +1048,9 @@ Map.prototype._onSyncInfoWndPosition = function(eventName, points) {
};
Map.prototype._onMapEvent = function(eventName) {
+ if (!this._isReady) {
+ return;
+ }
var args = [eventName];
for (var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
@@ -1194,6 +1200,8 @@ Map.prototype._onCameraEvent = function(eventName, cameraPosition) {
this.set('camera_nearRight', cameraPosition.nearRight);
this.set('camera_farLeft', cameraPosition.farLeft);
this.set('camera_farRight', cameraPosition.farRight);
+ if (this._isReady) {
this.trigger(eventName, cameraPosition, this);
+ }
};
module.exports = Map;

MODIFY
www/Marker.js
www/Marker.js
@@ -128,6 +128,7 @@ Marker.prototype.remove = function(callback) {
self.trigger(event.INFO_CLOSE); // close open infowindow, otherwise it will stay
self.trigger(self.id + "_remove");
exec(function() {
+ self.destroy();
if (typeof callback === "function") {
callback.call(self);
}

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
@@ -140,7 +140,7 @@ var MarkerCluster = function(map, markerClusterId, markerClusterOptions, _exec)
self.on("cluster_click", self.onClusterClicked);
self.on("nextTask", function(){
- if (self.taskQueue.length === 0) {
+ if (self._isRemove || self.taskQueue.length === 0) {
return;
}
sel.redraw();
@@ -149,7 +149,7 @@ var MarkerCluster = function(map, markerClusterId, markerClusterOptions, _exec)
self._onCameraMoved(false);
if (self.debug) {
- setInterval(function() {
+ self.debugTimer = setInterval(function() {
console.log("self.taskQueue.push = " + self.taskQueue.length);
}, 5000);
}
@@ -173,6 +173,9 @@ MarkerCluster.prototype.getHashCode = function() {
};
MarkerCluster.prototype.onClusterClicked = function(cluster) {
+ if (this._isRemove) {
+ return null;
+ }
this.map.animateCamera({
target: cluster.getBounds(),
duration: 500
@@ -181,6 +184,9 @@ MarkerCluster.prototype.onClusterClicked = function(cluster) {
MarkerCluster.prototype._onCameraMoved = function(force) {
var self = this;
+ if (self._isRemove) {
+ return null;
+ }
var visibleRegion = self.map.getVisibleRegion();
self.map.fromLatLngToPoint(visibleRegion.southwest, function(swPosition) {
swPosition[0] = swPosition[0] + 40;
@@ -198,6 +204,10 @@ MarkerCluster.prototype.remove = function() {
if (self._isRemove) {
return;
}
+ if (self.debug) {
+ clearInterval(self.debugTimer);
+ self.self.debugTimer = undefined;
+ }
var resolution = self.get("resolution"),
activeMarkerId = self.map.get("active_marker_id"),
@@ -207,6 +217,21 @@ MarkerCluster.prototype.remove = function() {
self.taskQueue = [];
self._isRemove = true;
+ if (resolution === self.MAX_RESOLUTION) {
+ while (self._clusters[resolution].length > 0) {
+ markerOpts = self._clusters[resolution].shift();
+ deleteClusters.push(markerOpts.id);
+ if (markerOpts.id === activeMarkerId) {
+ var marker = markerOpts._cluster.marker;
+ if (!marker) {
+ marker = self._createMarker(markerOpts);
+ markerOpts._cluster.marker = marker;
+ }
+ marker.trigger(event.INFO_CLOSE);
+ marker.hideInfoWindow();
+ }
+ }
+ } else {
var keys = Object.keys(self._clusters[resolution]);
keys.forEach(function(geocell) {
var cluster = self._clusters[resolution][geocell];
@@ -230,13 +255,19 @@ MarkerCluster.prototype.remove = function() {
}
cluster.remove();
});
+ }
exec(null, self.errorHandler, self.getPluginName(), 'redrawClusters', [self.getId(), {
"resolution": resolution,
"delete": deleteClusters
}], {sync: true});
+ self.off();
+
};
MarkerCluster.prototype.removeMarkerById = function(markerId) {
+ if (self._isRemove) {
+ return null;
+ }
var self = this;
if (markerId.indexOf(self.id + "-") === -1) {
markerId = self.id + "-" + markerId;
@@ -276,6 +307,9 @@ MarkerCluster.prototype.removeMarkerById = function(markerId) {
};
MarkerCluster.prototype.getMarkerById = function(markerId) {
var self = this;
+ if (self._isRemove) {
+ return null;
+ }
if (markerId.indexOf(self.id + "-") === -1) {
markerId = self.id + "-" + markerId;
}
@@ -292,8 +326,12 @@ MarkerCluster.prototype.getMarkerById = function(markerId) {
};
MarkerCluster.prototype.getClusterByClusterId = function(clusterId) {
- var self = this,
- resolution = self.get("resolution");
+ var self = this;
+
+ if (self._isRemove) {
+ return null;
+ }
+ var resolution = self.get("resolution");
if (!self._clusters[resolution]) {
return null;
@@ -308,6 +346,9 @@ MarkerCluster.prototype.getClusterByClusterId = function(clusterId) {
MarkerCluster.prototype.redraw = function(clusterDistance, force) {
var self = this;
+ if (self._isRemove) {
+ return null;
+ }
self.taskQueue.push([clusterDistance, force]);
if (self.debug) {
@@ -320,14 +361,15 @@ MarkerCluster.prototype.redraw = function(clusterDistance, force) {
self._redraw.apply(self, taskParams);
};
MarkerCluster.prototype._redraw = function(clusterDistance, force) {
- var self = this,
- map = self.map,
- currentZoomLevel = Math.floor(self.map.getCameraZoom()),
- prevResolution = self.get("resolution");
+ var self = this;
if (self._isRemove) {
- return;
+ return null;
}
+ var map = self.map,
+ currentZoomLevel = Math.floor(self.map.getCameraZoom()),
+ prevResolution = self.get("resolution");
+
currentZoomLevel = currentZoomLevel < 0 ? 0 : currentZoomLevel;
self.set("zoom", currentZoomLevel);
@@ -732,6 +774,7 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
if (self._isRemove) {
return;
}
+
exec(function() {
self.trigger("nextTask");
}, self.errorHandler, self.getPluginName(), 'redrawClusters', [self.getId(), {

MODIFY
www/Polygon.js
www/Polygon.js
@@ -125,6 +125,7 @@ utils.extend(Polygon, BaseClass);
Polygon.prototype.remove = function() {
this.trigger(this.id + "_remove");
exec(null, this.errorHandler, this.getPluginName(), 'remove', [this.getId()]);
+ this.destroy();
};
Polygon.prototype.getPluginName = function() {
return this.map.getId() + "-polygon";

MODIFY
www/Polyline.js
www/Polyline.js
@@ -168,6 +168,6 @@ Polyline.prototype.remove = function() {
if (points) {
points.clear();
}
- this.off();
+ this.destroy();
};
module.exports = Polyline;

MODIFY
www/TileOverlay.js
www/TileOverlay.js
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
common = require('./Common'),
BaseClass = require('./BaseClass');
@@ -106,6 +105,7 @@ TileOverlay.prototype.getVisible = function() {
TileOverlay.prototype.remove = function() {
this.trigger(this.id + "_remove");
exec(null, this.errorHandler, this.getPluginName(), 'remove', [this.getId()]);
+ this.destroy();
};
module.exports = TileOverlay;

Prevent map events before the map_ready event