Implementing new way for map.addCircle()
Bug fix: bindTo()
MODIFY
src/android/plugin/google/maps/PluginCircle.java
src/android/plugin/google/maps/PluginCircle.java
@@ -24,6 +24,7 @@ public class PluginCircle extends MyPlugin implements MyPluginInterface {
final JSONObject properties = new JSONObject();
JSONObject opts = args.getJSONObject(1);
+ final String hashCode = args.getString(2);
if (opts.has("center")) {
JSONObject center = opts.getJSONObject("center");
circleOptions.center(new LatLng(center.getDouble("lat"), center.getDouble("lng")));
@@ -63,19 +64,18 @@ public class PluginCircle extends MyPlugin implements MyPluginInterface {
@Override
public void run() {
Circle circle = map.addCircle(circleOptions);
- String id = circle.getId();
- pluginMap.objects.put("circle_" + id, circle);
+ pluginMap.objects.put("circle_" + hashCode, circle);
- pluginMap.objects.put("circle_property_" + id, properties);
+ pluginMap.objects.put("circle_property_" + hashCode, properties);
// Recalculate the circle bounds
LatLngBounds bounds = PluginUtil.getBoundsFromCircle(circleOptions.getCenter(), circleOptions.getRadius());
- pluginMap.objects.put("circle_bounds_" + id, bounds);
+ pluginMap.objects.put("circle_bounds_" + hashCode, bounds);
JSONObject result = new JSONObject();
try {
- result.put("hashCode", circle.hashCode());
- result.put("id", "circle_" + id);
+ result.put("hashCode", hashCode);
+ result.put("id", "circle_" + hashCode);
callbackContext.success(result);
} catch (JSONException e) {
e.printStackTrace();

MODIFY
src/android/plugin/google/maps/PluginMarker.java
src/android/plugin/google/maps/PluginMarker.java
@@ -197,7 +197,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
// Create an instance of Marker class
JSONObject opts = args.getJSONObject(1);
- final String markerId = args.getString(2);
+ final String markerId = "marker_" + args.getString(2);
final JSONObject result = new JSONObject();
result.put("id", markerId);

MODIFY
www/BaseClass.js
www/BaseClass.js
@@ -42,9 +42,10 @@ BaseClass.prototype = {
// If `noNotify` is true, prevent `(targetKey)_changed` event occurrs,
// when bind the value for the first time only.
// (Same behaviour as Google Maps JavaScript v3)
- target.set(targetKey, value, noNotify);
+ target.set(targetKey, target.get(targetKey), noNotify);
this.on(key + '_changed', function(oldValue, value) {
+console.log(key, value);
target.set(targetKey, value);
});
},

MODIFY
www/Circle.js
www/Circle.js
@@ -2,43 +2,17 @@ var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
common = require('./Common'),
LatLngBounds = require('./LatLngBounds'),
- BaseClass = require('./BaseClass');
+ Overlay = require('./Overlay');
/*****************************************************************************
* Circle Class
*****************************************************************************/
var exec;
-var Circle = function(map, circleId, circleOptions, _exec) {
+var Circle = function(map, circleOptions, _exec) {
exec = _exec;
- BaseClass.apply(this);
+ Overlay.call(this, map, circleOptions, _exec);
var self = this;
- Object.defineProperty(self, "_isReady", {
- value: true,
- writable: false
- });
- Object.defineProperty(self, "map", {
- value: map,
- writable: false
- });
- Object.defineProperty(self, "id", {
- value: circleId,
- writable: false
- });
- Object.defineProperty(self, "type", {
- value: "Circle",
- writable: false
- });
-
- //-----------------------------------------------
- // Sets the initialize option to each property
- //-----------------------------------------------
- var ignores = ["map", "id", "hashCode", "type"];
- for (var key in circleOptions) {
- if (ignores.indexOf(key) === -1) {
- self.set(key, circleOptions[key]);
- }
- }
//-----------------------------------------------
// Sets event listeners
@@ -78,22 +52,8 @@ var Circle = function(map, circleId, circleOptions, _exec) {
};
-utils.extend(Circle, BaseClass);
-
-Circle.prototype.getPluginName = function() {
- return this.map.getId() + "-circle";
-};
-
-Circle.prototype.getHashCode = function() {
- return this.hashCode;
-};
+utils.extend(Circle, Overlay);
-Circle.prototype.getMap = function() {
- return this.map;
-};
-Circle.prototype.getId = function() {
- return this.id;
-};
Circle.prototype.getCenter = function() {
return this.get('center');
};

MODIFY
www/Map.js
www/Map.js
@@ -1129,19 +1129,18 @@ Map.prototype.addCircle = function(circleOptions, callback) {
circleOptions.zIndex = circleOptions.zIndex || 0;
circleOptions.radius = "radius" in circleOptions ? circleOptions.radius : 1;
- exec.call(this, function(result) {
- var circle = new Circle(self, result.id, circleOptions, exec);
- self.OVERLAYS[result.id] = circle;
-
- circle.one(result.id + "_remove", function() {
+ var circle = new Circle(self, circleOptions, "Circle", exec);
+ var circleId = circle.getId();
+ self.OVERLAYS[circleId] = circle;
+ circle.one(circleId + "_remove", function() {
circle.off();
- delete self.OVERLAYS[result.id];
+ delete self.OVERLAYS[circleId];
circle = undefined;
});
- if (typeof callback === "function") {
- callback.call(self, circle);
- }
- }, self.errorHandler, self.id, 'loadPlugin', ['Circle', circleOptions]);
+
+ exec.call(this, callback, self.errorHandler, self.id, 'loadPlugin', ['Circle', circleOptions, circle.hashCode]);
+
+ return circle;
};
//-------------
@@ -1163,8 +1162,9 @@ Map.prototype.addMarker = function(markerOptions, callback) {
};
}
- var markerId = "marker_" + (Math.floor(Date.now() * Math.random()));
- var marker = new Marker(self, markerId, markerOptions, "Marker", exec);
+ var marker = new Marker(self, markerOptions, "Marker", exec);
+ var markerId = marker.getId();
+
self.MARKERS[markerId] = marker;
self.OVERLAYS[markerId] = marker;
marker.one(markerId + "_remove", function() {
@@ -1190,7 +1190,7 @@ Map.prototype.addMarker = function(markerOptions, callback) {
if (typeof callback === "function") {
callback.call(self, marker);
}
- }, self.errorHandler, self.id, 'loadPlugin', ['Marker', markerOptions, markerId]);
+ }, self.errorHandler, self.id, 'loadPlugin', ['Marker', markerOptions, marker.hashCode]);
return marker;
};

MODIFY
www/Overlay.js
www/Overlay.js
@@ -6,11 +6,21 @@ var BaseClass = require('./BaseClass'),
/*****************************************************************************
* Overlay Class
*****************************************************************************/
-var Overlay = function(map, id, className, _exec) {
+var Overlay = function(map, options, className, _exec) {
BaseClass.apply(this);
var self = this;
+ //-----------------------------------------------
+ // Sets the initialize option to each property
+ //-----------------------------------------------
+ var ignores = ["map", "id", "hashCode", "type"];
+ for (var key in options) {
+ if (ignores.indexOf(key) === -1) {
+ self.set(key, options[key]);
+ }
+ }
+
//-------------------------------------------------------------------------------
// If app code wants to execute some method before `_isReady = true`,
// just stack in to the internal queue.
@@ -37,6 +47,7 @@ var Overlay = function(map, id, className, _exec) {
writable: false
});
+ className = className.toLowerCase();
Object.defineProperty(self, "_isReady", {
value: false,
writable: true
@@ -46,7 +57,7 @@ var Overlay = function(map, id, className, _exec) {
writable: false
});
Object.defineProperty(self, "id", {
- value: id,
+ value: className + "_" + this.hashCode,
writable: false
});
Object.defineProperty(self, "type", {
@@ -54,7 +65,6 @@ var Overlay = function(map, id, className, _exec) {
writable: false
});
- className = className.toLowerCase();
Object.defineProperty(self, "getPluginName", {
writable: false,
value: function() {
@@ -65,6 +75,30 @@ var Overlay = function(map, id, className, _exec) {
utils.extend(Overlay, BaseClass);
+Overlay.prototype._privateInitialize = function(options) {
+ var self = this;
+ //-----------------------------------------------
+ // Sets the initialize option to each property
+ //-----------------------------------------------
+ if (options) {
+ var ignores = ["map", "id", "hashCode", "type"];
+ for (var key in options) {
+ if (ignores.indexOf(key) === -1) {
+ self.set(key, options[key], true);
+ }
+ }
+ }
+
+ //-----------------------------------------------
+ // Trigger internal command queue
+ //-----------------------------------------------
+ Object.defineProperty(self, "_isReady", {
+ value: true,
+ writable: false
+ });
+ self.exec("nop");
+};
+
Overlay.prototype.exec = function() {
this._cmdQueue.push.call(this._cmdQueue, {

- Implementing new way for map.addCircle()
- Bug fix: bindTo()