diff --git a/.jsbeautifyrc b/.jsbeautifyrc new file mode 100644 index 000000000..aee5ec44b --- /dev/null +++ b/.jsbeautifyrc @@ -0,0 +1,11 @@ +{ + "js": { + "indent_size": 2, + "indent_char": " ", + "indent_level": 0, + "indent_with_tabs": false, + "preserve_newlines": true, + "max_preserve_newlines": 2, + "jslint_happy": true + } +} diff --git a/src/android/plugin/google/maps/PluginCircle.java b/src/android/plugin/google/maps/PluginCircle.java index f3b9758a7..ee6a4008a 100644 --- a/src/android/plugin/google/maps/PluginCircle.java +++ b/src/android/plugin/google/maps/PluginCircle.java @@ -64,6 +64,7 @@ public void create(final JSONArray args, final CallbackContext callbackContext) @Override public void run() { Circle circle = map.addCircle(circleOptions); + circle.setTag(hashCode); pluginMap.objects.put("circle_" + hashCode, circle); pluginMap.objects.put("circle_property_" + hashCode, properties); @@ -103,7 +104,7 @@ public void setCenter(final JSONArray args, final CallbackContext callbackContex @Override public void run() { // Recalculate the circle bounds - String propertyId = "circle_bounds_" + circle.getId(); + String propertyId = "circle_bounds_" + circle.getTag(); LatLngBounds bounds = PluginUtil.getBoundsFromCircle(circle.getCenter(), circle.getRadius()); pluginMap.objects.put(propertyId, bounds); @@ -169,7 +170,7 @@ public void setRadius(final JSONArray args, final CallbackContext callbackContex public void run() { // Recalculate the circle bounds - String propertyId = "circle_bounds_" + circle.getId(); + String propertyId = "circle_bounds_" + circle.getTag(); LatLngBounds bounds = PluginUtil.getBoundsFromCircle(circle.getCenter(), circle.getRadius()); pluginMap.objects.put(propertyId, bounds); @@ -213,7 +214,7 @@ public void run() { circle.setVisible(isVisible); } }); - String propertyId = "circle_property_" + circle.getId(); + String propertyId = "circle_property_" + circle.getTag(); JSONObject properties = (JSONObject)pluginMap.objects.get(propertyId); properties.put("isVisible", isVisible); pluginMap.objects.put(propertyId, properties); diff --git a/src/android/plugin/google/maps/PluginGroundOverlay.java b/src/android/plugin/google/maps/PluginGroundOverlay.java index eb74c8d8d..abe184762 100644 --- a/src/android/plugin/google/maps/PluginGroundOverlay.java +++ b/src/android/plugin/google/maps/PluginGroundOverlay.java @@ -40,9 +40,8 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV */ public void create(JSONArray args, CallbackContext callbackContext) throws JSONException { JSONObject opts = args.getJSONObject(1); - - final String idBase = "" + callbackContext.hashCode(); - _createGroundOverlay(idBase, opts, callbackContext); + String hashCode = args.getString(2); + _createGroundOverlay(hashCode, opts, callbackContext); } public void _createGroundOverlay(final String idBase, final JSONObject opts, final CallbackContext callbackContext) throws JSONException { @@ -113,7 +112,7 @@ public void onPostExecute(Object object) { JSONObject resultJSON = new JSONObject(); try { - resultJSON.put("hashCode", groundOverlay.hashCode()); + resultJSON.put("hashCode", idBase); resultJSON.put("id", "groundoverlay_" + idBase); } catch (Exception e) { e.printStackTrace(); diff --git a/src/android/plugin/google/maps/PluginMarkerCluster.java b/src/android/plugin/google/maps/PluginMarkerCluster.java index ed32d89b6..99a76e426 100644 --- a/src/android/plugin/google/maps/PluginMarkerCluster.java +++ b/src/android/plugin/google/maps/PluginMarkerCluster.java @@ -211,6 +211,7 @@ public void remove(final JSONArray args, final CallbackContext callbackContext) public void create(final JSONArray args, final CallbackContext callbackContext) throws JSONException { JSONObject params = args.getJSONObject(1); + String hashCode = args.getString(2); JSONArray positionList = params.getJSONArray("positionList"); JSONArray geocellList = new JSONArray(); JSONObject position; @@ -220,13 +221,13 @@ public void create(final JSONArray args, final CallbackContext callbackContext) geocellList.put(getGeocell(position.getDouble("lat"), position.getDouble("lng"), 12)); } - String id = "markercluster_" + callbackContext.hashCode(); + String id = "markercluster_" + hashCode; debugFlags.put(id, params.getBoolean("debug")); final JSONObject result = new JSONObject(); try { result.put("geocellList", geocellList); - result.put("hashCode", callbackContext.hashCode()); + result.put("hashCode", hashCode); result.put("id", id); } catch (JSONException e) { e.printStackTrace(); diff --git a/src/android/plugin/google/maps/PluginPolygon.java b/src/android/plugin/google/maps/PluginPolygon.java index df83466ab..248c1a151 100644 --- a/src/android/plugin/google/maps/PluginPolygon.java +++ b/src/android/plugin/google/maps/PluginPolygon.java @@ -39,6 +39,7 @@ public void create(final JSONArray args, final CallbackContext callbackContext) final ArrayList> holePaths = new ArrayList>(); JSONObject opts = args.getJSONObject(1); + final String hashCode = args.getString(2); if (opts.has("points")) { JSONArray points = opts.getJSONArray("points"); ArrayList path2 = PluginUtil.JSONArray2LatLngList(points); @@ -108,7 +109,8 @@ public void create(final JSONArray args, final CallbackContext callbackContext) @Override public void run() { Polygon polygon = map.addPolygon(polygonOptions); - String id = polygon.getId(); + String id = hashCode; + polygon.setTag(hashCode); pluginMap.objects.put("polygon_"+ id, polygon); pluginMap.objects.put("polygon_bounds_" + id, builder.build()); pluginMap.objects.put("polygon_path_" + id, path); @@ -117,7 +119,7 @@ public void run() { JSONObject result = new JSONObject(); try { - result.put("hashCode", polygon.hashCode()); + result.put("hashCode", hashCode); result.put("id", "polygon_"+ id); } catch (JSONException e) { e.printStackTrace(); @@ -232,7 +234,7 @@ public void remove(final JSONArray args, final CallbackContext callbackContext) } pluginMap.objects.remove(id); - id = polygon.getId(); + id = (String) polygon.getTag(); pluginMap.objects.remove("polygon_bounds_" + id); pluginMap.objects.remove("polygon_property_" + id); pluginMap.objects.remove("polygon_path_" + id); @@ -262,7 +264,7 @@ public void removePointAt(final JSONArray args, final CallbackContext callbackCo //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_path_" + polygon.getId(); + String propertyId = "polygon_path_" + polygon.getTag(); final ArrayList path = (ArrayList)pluginMap.objects.get(propertyId); if (path.size() > 0) { path.remove(index); @@ -272,7 +274,7 @@ public void removePointAt(final JSONArray args, final CallbackContext callbackCo //----------------------------------- // Recalculate the polygon bounds //----------------------------------- - propertyId = "polygon_bounds_" + polygon.getId(); + propertyId = "polygon_bounds_" + polygon.getTag(); if (path.size() > 0) { pluginMap.objects.put(propertyId, PluginUtil.getBoundsFromPath(path)); } else { @@ -314,7 +316,7 @@ public void setPoints(final JSONArray args, final CallbackContext callbackContex //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_path_" + polygon.getId(); + String propertyId = "polygon_path_" + polygon.getTag(); final ArrayList path = (ArrayList)pluginMap.objects.get(propertyId); path.clear(); JSONObject position; @@ -327,7 +329,7 @@ public void setPoints(final JSONArray args, final CallbackContext callbackContex //----------------------------------- // Recalculate the polygon bounds //----------------------------------- - propertyId = "polygon_bounds_" + polygon.getId(); + propertyId = "polygon_bounds_" + polygon.getTag(); pluginMap.objects.put(propertyId, PluginUtil.getBoundsFromPath(path)); cordova.getActivity().runOnUiThread(new Runnable() { @@ -363,10 +365,10 @@ public void insertPointAt(final JSONArray args, final CallbackContext callbackCo // Update the hole list //------------------------ boolean shouldBeVisible = false; - String propertyId = "polygon_path_" + polygon.getId(); + String propertyId = "polygon_path_" + polygon.getTag(); final ArrayList path = (ArrayList)pluginMap.objects.get(propertyId); if (path.size() == 0) { - JSONObject properties = (JSONObject)pluginMap.objects.get("polygon_property_" + polygon.getId()); + JSONObject properties = (JSONObject)pluginMap.objects.get("polygon_property_" + polygon.getTag()); if (properties.getBoolean("isVisible")) { shouldBeVisible = true; } @@ -377,7 +379,7 @@ public void insertPointAt(final JSONArray args, final CallbackContext callbackCo //----------------------------------- // Recalculate the polygon bounds //----------------------------------- - propertyId = "polygon_bounds_" + polygon.getId(); + propertyId = "polygon_bounds_" + polygon.getTag(); pluginMap.objects.put(propertyId, PluginUtil.getBoundsFromPath(path)); final boolean changeToVisible = shouldBeVisible; @@ -411,7 +413,7 @@ public void setPointAt(final JSONArray args, final CallbackContext callbackConte //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_path_" + polygon.getId(); + String propertyId = "polygon_path_" + polygon.getTag(); final ArrayList path = (ArrayList)pluginMap.objects.get(propertyId); path.set(index, latLng); pluginMap.objects.put(propertyId, path); @@ -419,7 +421,7 @@ public void setPointAt(final JSONArray args, final CallbackContext callbackConte //----------------------------------- // Recalculate the polygon bounds //----------------------------------- - propertyId = "polygon_bounds_" + polygon.getId(); + propertyId = "polygon_bounds_" + polygon.getTag(); pluginMap.objects.put(propertyId, PluginUtil.getBoundsFromPath(path)); cordova.getActivity().runOnUiThread(new Runnable() { @@ -446,7 +448,7 @@ public void setHoles(final JSONArray args, final CallbackContext callbackContext //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); for (int i = 0; i < holes.size(); i++) { holes.get(i).clear(); @@ -494,7 +496,7 @@ public void insertPointOfHoleAt(final JSONArray args, final CallbackContext call //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); ArrayList hole = null; if (holeIndex < holes.size()) { @@ -537,7 +539,7 @@ public void setPointOfHoleAt(final JSONArray args, final CallbackContext callbac //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); ArrayList hole = null; if (holeIndex < holes.size()) { @@ -581,7 +583,7 @@ public void removePointOfHoleAt(final JSONArray args, final CallbackContext call //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); ArrayList hole = null; if (holeIndex < holes.size()) { @@ -621,7 +623,7 @@ public void insertHoleAt(final JSONArray args, final CallbackContext callbackCon //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); holes.add(holeIndex, newHole); pluginMap.objects.put(propertyId, holes); @@ -659,7 +661,7 @@ public void setHoleAt(final JSONArray args, final CallbackContext callbackContex //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); holes.set(holeIndex, newHole); pluginMap.objects.put(propertyId, holes); @@ -690,7 +692,7 @@ public void removeHoleAt(final JSONArray args, final CallbackContext callbackCon //------------------------ // Update the hole list //------------------------ - String propertyId = "polygon_holePaths_" + polygon.getId(); + String propertyId = "polygon_holePaths_" + polygon.getTag(); final ArrayList> holes = (ArrayList>) pluginMap.objects.get(propertyId); holes.remove(holeIndex); pluginMap.objects.put(propertyId, holes); @@ -722,7 +724,7 @@ public void run() { polygon.setVisible(isVisible); } }); - String propertyId = "polygon_property_" + polygon.getId(); + String propertyId = "polygon_property_" + polygon.getTag(); JSONObject properties = (JSONObject)pluginMap.objects.get(propertyId); properties.put("isVisible", isVisible); pluginMap.objects.put(propertyId, properties); diff --git a/src/android/plugin/google/maps/PluginPolyline.java b/src/android/plugin/google/maps/PluginPolyline.java index 6ebc9f15d..e0bfd80e4 100644 --- a/src/android/plugin/google/maps/PluginPolyline.java +++ b/src/android/plugin/google/maps/PluginPolyline.java @@ -31,6 +31,7 @@ public void create(final JSONArray args, final CallbackContext callbackContext) final JSONObject properties = new JSONObject(); JSONObject opts = args.getJSONObject(1); + final String hashCode = args.getString(2); if (opts.has("points")) { JSONArray points = opts.getJSONArray("points"); List path = PluginUtil.JSONArray2LatLngList(points); @@ -72,18 +73,19 @@ public void create(final JSONArray args, final CallbackContext callbackContext) public void run() { Polyline polyline = map.addPolyline(polylineOptions); - String id = "polyline_" + polyline.getId(); + polyline.setTag(hashCode); + String id = "polyline_" + hashCode; pluginMap.objects.put(id, polyline); - String boundsId = "polyline_bounds_" + polyline.getId(); + String boundsId = "polyline_bounds_" + hashCode; pluginMap.objects.put(boundsId, builder.build()); - String propertyId = "polyline_property_" + polyline.getId(); + String propertyId = "polyline_property_" + hashCode; pluginMap.objects.put(propertyId, properties); try { JSONObject result = new JSONObject(); - result.put("hashCode", polyline.hashCode()); + result.put("hashCode", hashCode); result.put("id", id); callbackContext.success(result); } catch (JSONException e) { @@ -247,7 +249,7 @@ public void remove(final JSONArray args, final CallbackContext callbackContext) } pluginMap.objects.remove(id); - id = "polyline_bounds_" + polyline.getId(); + id = "polyline_bounds_" + polyline.getTag(); pluginMap.objects.remove(id); cordova.getActivity().runOnUiThread(new Runnable() { @@ -265,7 +267,7 @@ public void setPoints(final JSONArray args, final CallbackContext callbackContex final Polyline polyline = this.getPolyline(id); // Recalculate the polygon bounds - final String propertyId = "polyline_bounds_" + polyline.getId(); + final String propertyId = "polyline_bounds_" + polyline.getTag(); cordova.getActivity().runOnUiThread(new Runnable() { @Override @@ -295,7 +297,7 @@ public void removePointAt(final JSONArray args, CallbackContext callbackContext) final Polyline polyline = this.getPolyline(id); // Recalculate the polygon bounds - final String propertyId = "polyline_bounds_" + polyline.getId(); + final String propertyId = "polyline_bounds_" + polyline.getTag(); cordova.getActivity().runOnUiThread(new Runnable() { @Override @@ -326,7 +328,7 @@ public void insertPointAt(final JSONArray args, CallbackContext callbackContext) // Recalculate the polygon bounds - final String propertyId = "polyline_bounds_" + polyline.getId(); + final String propertyId = "polyline_bounds_" + polyline.getTag(); cordova.getActivity().runOnUiThread(new Runnable() { @Override @@ -359,7 +361,7 @@ public void run() { path.set(index, latLng); // Recalculate the polygon bounds - String propertyId = "polyline_bounds_" + polyline.getId(); + String propertyId = "polyline_bounds_" + polyline.getTag(); pluginMap.objects.put(propertyId, PluginUtil.getBoundsFromPath(path)); polyline.setPoints(path); @@ -399,7 +401,7 @@ public void run() { polyline.setVisible(isVisible); } }); - String propertyId = "polyline_property_" + polyline.getId(); + String propertyId = "polyline_property_" + polyline.getTag(); JSONObject properties = (JSONObject)pluginMap.objects.get(propertyId); properties.put("isVisible", isVisible); pluginMap.objects.put(propertyId, properties); diff --git a/src/android/plugin/google/maps/PluginTileOverlay.java b/src/android/plugin/google/maps/PluginTileOverlay.java index 722829dd1..d68924cf6 100644 --- a/src/android/plugin/google/maps/PluginTileOverlay.java +++ b/src/android/plugin/google/maps/PluginTileOverlay.java @@ -28,6 +28,7 @@ public void create(final JSONArray args, final JSONObject opts = args.getJSONObject(1); + final String id = args.getString(2); final int tileSize = opts.getInt("tileSize"); @@ -46,7 +47,6 @@ public void create(final JSONArray args, if (opts.has("debug")) { isDebug = opts.getBoolean("debug"); } - final String id = opts.getString("_id"); final boolean _isDebug = isDebug; cordova.getActivity().runOnUiThread(new Runnable() { @@ -108,7 +108,7 @@ public void onCacheClear(int hashCode) { try { JSONObject result = new JSONObject(); - result.put("hashCode", tileOverlay.hashCode()); + result.put("hashCode", id); result.put("id", "tileoverlay_" + id); callbackContext.success(result); } catch (JSONException e) { diff --git a/www/BaseClass.js b/www/BaseClass.js index dda55129c..4dac8b327 100644 --- a/www/BaseClass.js +++ b/www/BaseClass.js @@ -1,139 +1,138 @@ var VARS_FIELD = typeof Symbol === 'undefined' ? '__vars' + Date.now() : Symbol.for('vars'); var SUBSCRIPTIONS_FIELD = typeof Symbol === 'undefined' ? '__subs' + Date.now() : Symbol.for('subscriptions'); - function BaseClass() { - this[VARS_FIELD] = {}; - this[SUBSCRIPTIONS_FIELD] = {}; - this.errorHandler = this.errorHandler.bind(this); + this[VARS_FIELD] = {}; + this[SUBSCRIPTIONS_FIELD] = {}; + this.errorHandler = this.errorHandler.bind(this); - Object.defineProperty(this, 'hashCode', { - value: Math.floor(Date.now() * Math.random()) - }); + Object.defineProperty(this, 'hashCode', { + value: Math.floor(Date.now() * Math.random()) + }); } BaseClass.prototype = { - empty: function() { - var vars = this[VARS_FIELD]; - - Object.keys(vars).forEach(function(name) { - vars[name] = null; - delete vars[name]; - }); - }, - - get: function(key) { - return this[VARS_FIELD].hasOwnProperty(key) ? this[VARS_FIELD][key] : undefined; - }, - - set: function(key, value, noNotify) { - var prev = this.get(key); - - this[VARS_FIELD][key] = value; - - if (!noNotify && prev !== value) { - this.trigger(key + '_changed', prev, value, key); - } - - return this; - }, - - bindTo: function(key, target, targetKey, noNotify) { - targetKey = targetKey || key; - - // 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, target.get(targetKey), noNotify); - - this.on(key + '_changed', function(oldValue, value) { - target.set(targetKey, value); - }); - }, - - trigger: function(eventName) { - if (!eventName) { - return this; - } - - if (!this[SUBSCRIPTIONS_FIELD][eventName]) { - return this; - } - - var listeners = this[SUBSCRIPTIONS_FIELD][eventName]; - var i = listeners.length; - var args = Array.prototype.slice.call(arguments, 1); - - while (i--) { - listeners[i].apply(this, args); - } - - return this; - }, - - on: function(eventName, listener) { - if (!listener || typeof listener !== "function") { - throw Error('Listener for on()/addEventListener() method is not a function'); - } - var topic; - this[SUBSCRIPTIONS_FIELD][eventName] = this[SUBSCRIPTIONS_FIELD][eventName] || []; - topic = this[SUBSCRIPTIONS_FIELD][eventName]; - topic.push(listener); - return this; - }, - - off: function(eventName, listener) { - if (!eventName && !listener) { - this[SUBSCRIPTIONS_FIELD] = {}; - return this; - } - - if (eventName && !listener) { - this[SUBSCRIPTIONS_FIELD][eventName] = null; - } else if (this[SUBSCRIPTIONS_FIELD][eventName]) { - var index = this[SUBSCRIPTIONS_FIELD][eventName].indexOf(listener); - - if (index !== -1) { - this[SUBSCRIPTIONS_FIELD][eventName].splice(index, 1); - } - } - - return this; - }, - - one: function(eventName, listener) { - if (!listener || typeof listener !== "function") { - throw Error('Listener for one()/addEventListenerOnce() method is not a function'); - } - - var self = this; - - var callback = function() { - self.off(eventName, arguments.callee); - listener.apply(self, arguments); - }; - this.on(eventName, callback); - - return this; - }, - - destroy: function() { - this.off(); - this.empty(); - }, - - errorHandler: function(error) { - if (error) { - if (typeof console.error === "function") { - console.error(error); - } else { - console.log(error); - } - this.trigger('error', error instanceof Error ? error : createError(error)); - } - - return false; - } + empty: function () { + var vars = this[VARS_FIELD]; + + Object.keys(vars).forEach(function (name) { + vars[name] = null; + delete vars[name]; + }); + }, + + get: function (key) { + return this[VARS_FIELD].hasOwnProperty(key) ? this[VARS_FIELD][key] : undefined; + }, + + set: function (key, value, noNotify) { + var prev = this.get(key); + + this[VARS_FIELD][key] = value; + + if (!noNotify && prev !== value) { + this.trigger(key + '_changed', prev, value, key); + } + + return this; + }, + + bindTo: function (key, target, targetKey, noNotify) { + targetKey = targetKey || key; + + // 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, target.get(targetKey), noNotify); + + this.on(key + '_changed', function (oldValue, value) { + target.set(targetKey, value); + }); + }, + + trigger: function (eventName) { + if (!eventName) { + return this; + } + + if (!this[SUBSCRIPTIONS_FIELD][eventName]) { + return this; + } + + var listeners = this[SUBSCRIPTIONS_FIELD][eventName]; + var i = listeners.length; + var args = Array.prototype.slice.call(arguments, 1); + + while (i--) { + listeners[i].apply(this, args); + } + + return this; + }, + + on: function (eventName, listener) { + if (!listener || typeof listener !== "function") { + throw Error('Listener for on()/addEventListener() method is not a function'); + } + var topic; + this[SUBSCRIPTIONS_FIELD][eventName] = this[SUBSCRIPTIONS_FIELD][eventName] || []; + topic = this[SUBSCRIPTIONS_FIELD][eventName]; + topic.push(listener); + return this; + }, + + off: function (eventName, listener) { + if (!eventName && !listener) { + this[SUBSCRIPTIONS_FIELD] = {}; + return this; + } + + if (eventName && !listener) { + this[SUBSCRIPTIONS_FIELD][eventName] = null; + } else if (this[SUBSCRIPTIONS_FIELD][eventName]) { + var index = this[SUBSCRIPTIONS_FIELD][eventName].indexOf(listener); + + if (index !== -1) { + this[SUBSCRIPTIONS_FIELD][eventName].splice(index, 1); + } + } + + return this; + }, + + one: function (eventName, listener) { + if (!listener || typeof listener !== "function") { + throw Error('Listener for one()/addEventListenerOnce() method is not a function'); + } + + var self = this; + + var callback = function () { + self.off(eventName, arguments.callee); + listener.apply(self, arguments); + }; + this.on(eventName, callback); + + return this; + }, + + destroy: function () { + this.off(); + this.empty(); + }, + + errorHandler: function (error) { + if (error) { + if (typeof console.error === "function") { + console.error(error); + } else { + console.log(error); + } + this.trigger('error', error instanceof Error ? error : createError(error)); + } + + return false; + } }; BaseClass.prototype.addEventListener = BaseClass.prototype.on; @@ -141,21 +140,21 @@ BaseClass.prototype.addEventListenerOnce = BaseClass.prototype.one; BaseClass.prototype.removeEventListener = BaseClass.prototype.off; function createError(message, methodName, args) { - var error = new Error(methodName ? [ - 'Got error with message: "', message, '" ', - 'after calling "', methodName, '"' - ].join('') : message); - - Object.defineProperties(error, { - methodName: { - value: methodName - }, - args: { - value: args - } - }); - - return error; + var error = new Error(methodName ? [ + 'Got error with message: "', message, '" ', + 'after calling "', methodName, '"' + ].join('') : message); + + Object.defineProperties(error, { + methodName: { + value: methodName + }, + args: { + value: args + } + }); + + return error; } module.exports = BaseClass; diff --git a/www/Circle.js b/www/Circle.js index a41911868..fee4ef6af 100644 --- a/www/Circle.js +++ b/www/Circle.js @@ -7,8 +7,8 @@ var argscheck = require('cordova/argscheck'), /***************************************************************************** * Circle Class *****************************************************************************/ -var Circle = function(map, circleOptions, className, _exec) { - Overlay.call(this, map, circleOptions, className, _exec); +var Circle = function(map, circleOptions, _exec) { + Overlay.call(this, map, circleOptions, 'Circle', _exec); var self = this; diff --git a/www/GroundOverlay.js b/www/GroundOverlay.js index 55e1552de..ae98686ec 100644 --- a/www/GroundOverlay.js +++ b/www/GroundOverlay.js @@ -1,15 +1,13 @@ var argscheck = require('cordova/argscheck'), - utils = require('cordova/utils'), - common = require('./Common'), - BaseClass = require('./BaseClass'); + utils = require('cordova/utils'), + common = require('./Common'), + Overlay = require('./Overlay'); /***************************************************************************** -* GroundOverlay Class -*****************************************************************************/ -var exec; -var GroundOverlay = function(map, groundOverlayId, groundOverlayOptions, _exec) { - BaseClass.apply(this); - exec = _exec; + * GroundOverlay Class + *****************************************************************************/ +var GroundOverlay = function (map, groundOverlayOptions, _exec) { + Overlay.call(this, map, groundOverlayOptions, 'GroundOverlay', _exec); var self = this; groundOverlayOptions.visible = groundOverlayOptions.visible === undefined ? true : groundOverlayOptions.visible; @@ -18,157 +16,120 @@ var GroundOverlay = function(map, groundOverlayId, groundOverlayOptions, _exec) groundOverlayOptions.bounds = groundOverlayOptions.bounds || []; groundOverlayOptions.anchor = groundOverlayOptions.anchor || [0, 0]; groundOverlayOptions.bearing = groundOverlayOptions.bearing || 0; - Object.defineProperty(self, "_isReady", { - value: true, - writable: false - }); - Object.defineProperty(self, "id", { - value: groundOverlayId, - writable: false - }); - Object.defineProperty(self, "type", { - value: "GroundOverlay", - writable: false - }); - Object.defineProperty(self, "map", { - value: map, - writable: false - }); - var ignores = ["map", "id", "hashCode", "type"]; - for (var key in groundOverlayOptions) { - if (ignores.indexOf(key) === -1) { - self.set(key, groundOverlayOptions[key]); - } - } //----------------------------------------------- // Sets event listeners //----------------------------------------------- - self.on("visible_changed", function() { - var visible = self.get("visible"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); + self.on("visible_changed", function () { + var visible = self.get("visible"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); }); - self.on("image_changed", function() { - var image = self.get("image"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setImage', [self.getId(), image]); + self.on("image_changed", function () { + var image = self.get("image"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setImage', [self.getId(), image]); }); - self.on("bounds_changed", function() { - var bounds = self.get("bounds"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setBounds', [self.getId(), bounds]); + self.on("bounds_changed", function () { + var bounds = self.get("bounds"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setBounds', [self.getId(), bounds]); }); - self.on("opacity_changed", function() { - var opacity = self.get("opacity"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setOpacity', [self.getId(), opacity]); + self.on("opacity_changed", function () { + var opacity = self.get("opacity"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setOpacity', [self.getId(), opacity]); }); - self.on("clickable_changed", function() { - var clickable = self.get("clickable"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setClickable', [self.getId(), clickable]); + self.on("clickable_changed", function () { + var clickable = self.get("clickable"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setClickable', [self.getId(), clickable]); }); - self.on("bearing_changed", function() { - var bearing = self.get("bearing"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setBearing', [self.getId(), bearing]); + self.on("bearing_changed", function () { + var bearing = self.get("bearing"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setBearing', [self.getId(), bearing]); }); - self.on("zIndex_changed", function() { - var zIndex = self.get("zIndex"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); + self.on("zIndex_changed", function () { + var zIndex = self.get("zIndex"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); }); }; +utils.extend(GroundOverlay, Overlay); -utils.extend(GroundOverlay, BaseClass); - -GroundOverlay.prototype.getPluginName = function() { - return this.map.getId() + "-groundoverlay"; -}; - -GroundOverlay.prototype.getHashCode = function() { - return this.hashCode; -}; - -GroundOverlay.prototype.getMap = function() { - return this.map; -}; -GroundOverlay.prototype.getId = function() { - return this.id; -}; - -GroundOverlay.prototype.setVisible = function(visible) { - this.set('visible', visible); +GroundOverlay.prototype.setVisible = function (visible) { + this.set('visible', visible); }; -GroundOverlay.prototype.getVisible = function() { - return this.get('visible'); +GroundOverlay.prototype.getVisible = function () { + return this.get('visible'); }; -GroundOverlay.prototype.setImage = function(url) { - this.set('image', url); +GroundOverlay.prototype.setImage = function (url) { + this.set('image', url); }; -GroundOverlay.prototype.setBounds = function(points) { - var i, - bounds = []; - for (i = 0; i < points.length; i++) { - bounds.push({ - "lat": points[i].lat, - "lng": points[i].lng - }); - } - this.set('bounds', bounds); +GroundOverlay.prototype.setBounds = function (points) { + var i, + bounds = []; + for (i = 0; i < points.length; i++) { + bounds.push({ + "lat": points[i].lat, + "lng": points[i].lng + }); + } + this.set('bounds', bounds); }; -GroundOverlay.prototype.getOpacity = function() { - return this.get("opacity"); +GroundOverlay.prototype.getOpacity = function () { + return this.get("opacity"); }; -GroundOverlay.prototype.getBearing = function() { - return this.get("bearing"); +GroundOverlay.prototype.getBearing = function () { + return this.get("bearing"); }; -GroundOverlay.prototype.setOpacity = function(opacity) { - if (!opacity && opacity !== 0) { - console.log('opacity value must be int or double'); - return false; - } - this.set('opacity', opacity); +GroundOverlay.prototype.setOpacity = function (opacity) { + if (!opacity && opacity !== 0) { + console.log('opacity value must be int or double'); + return false; + } + this.set('opacity', opacity); }; -GroundOverlay.prototype.setBearing = function(bearing) { - this.set('bearing', bearing); +GroundOverlay.prototype.setBearing = function (bearing) { + this.set('bearing', bearing); }; -GroundOverlay.prototype.getZIndex = function() { - return this.get("zIndex"); +GroundOverlay.prototype.getZIndex = function () { + return this.get("zIndex"); }; -GroundOverlay.prototype.setZIndex = function(zIndex) { - this.set('zIndex', zIndex); +GroundOverlay.prototype.setZIndex = function (zIndex) { + this.set('zIndex', zIndex); }; -GroundOverlay.prototype.setClickable = function(clickable) { - clickable = common.parseBoolean(clickable); - this.set('clickable', clickable); - return this; +GroundOverlay.prototype.setClickable = function (clickable) { + clickable = common.parseBoolean(clickable); + this.set('clickable', clickable); + return this; }; -GroundOverlay.prototype.getClickable = function() { - return this.get('clickable'); +GroundOverlay.prototype.getClickable = function () { + return this.get('clickable'); }; -GroundOverlay.prototype.remove = function(callback) { - var self = this; - if (self._isRemoved) { - return; +GroundOverlay.prototype.remove = function (callback) { + var self = this; + if (self._isRemoved) { + return; + } + Object.defineProperty(self, "_isRemoved", { + value: true, + writable: false + }); + self.trigger(self.id + "_remove"); + self.exec.call(self, function () { + self.destroy(); + if (typeof callback === "function") { + callback.call(self); } - Object.defineProperty(self, "_isRemoved", { - value: true, - writable: false - }); - self.trigger(self.id + "_remove"); - exec.call(self, function() { - self.destroy(); - if (typeof callback === "function") { - callback.call(self); - } - }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {remove: true}); + }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], { + remove: true + }); }; - module.exports = GroundOverlay; diff --git a/www/Map.js b/www/Map.js index 3163d5329..03af98c81 100644 --- a/www/Map.js +++ b/www/Map.js @@ -1001,6 +1001,19 @@ Map.prototype.addTileOverlay = function(tilelayerOptions, callback) { tilelayerOptions.debug = tilelayerOptions.debug === true; tilelayerOptions.userAgent = tilelayerOptions.userAgent || navigator.userAgent; + + var tileOverlay = new TileOverlay(self, tilelayerOptions, exec); + var tileOverlayId = tileOverlay.getId(); + self.OVERLAYS[tileOverlayId] = tileOverlay; + var hashCode = tileOverlay.hashCode; + + tileOverlay.one(tileOverlayId + "_remove", function() { + document.removeEventListener(tileOverlayId + "-" + hashCode + "-tileoverlay", onNativeCallback); + tileOverlay.off(); + delete self.OVERLAYS[tileOverlayId]; + tileOverlay = undefined; + }); + var options = { visible: tilelayerOptions.visible, zIndex: tilelayerOptions.zIndex, @@ -1008,7 +1021,7 @@ Map.prototype.addTileOverlay = function(tilelayerOptions, callback) { opacity: tilelayerOptions.opacity, userAgent: tilelayerOptions.userAgent, debug: tilelayerOptions.debug, - _id: Math.floor(Math.random() * Date.now()) + _id: hashCode }; var onNativeCallback = function(params) { @@ -1016,23 +1029,20 @@ Map.prototype.addTileOverlay = function(tilelayerOptions, callback) { if (!url || url === "(null)" || url === "undefined" || url === "null") { url = "(null)"; } - cordova_exec(null, self.errorHandler, self.id + "-tileoverlay", 'onGetTileUrlFromJS', [options._id, params.key, url]); + cordova_exec(null, self.errorHandler, self.id + "-tileoverlay", 'onGetTileUrlFromJS', [hashCode, params.key, url]); }; - document.addEventListener(self.id + "-" + options._id + "-tileoverlay", onNativeCallback); + document.addEventListener(self.id + "-" + hashCode + "-tileoverlay", onNativeCallback); exec.call(this, function(result) { - var tileOverlay = new TileOverlay(self, result.id, tilelayerOptions, exec); - self.OVERLAYS[result.id] = tileOverlay; - tileOverlay.one(result.id + "_remove", function() { - document.removeEventListener(self.id + "-" + options._id + "-tileoverlay", onNativeCallback); - tileOverlay.off(); - delete self.OVERLAYS[result.id]; - tileOverlay = undefined; - }); + tileOverlay._privateInitialize(); + delete tileOverlay._privateInitialize; + if (typeof callback === "function") { callback.call(self, tileOverlay); } - }, self.errorHandler, self.id, 'loadPlugin', ['TileOverlay', options]); + }, self.errorHandler, self.id, 'loadPlugin', ['TileOverlay', options, hashCode]); + + return tileOverlay; }; //------------- @@ -1070,19 +1080,27 @@ Map.prototype.addPolygon = function(polygonOptions, callback) { polygonOptions.zIndex = polygonOptions.zIndex || 0; polygonOptions.geodesic = polygonOptions.geodesic === true; + var opts = JSON.parse(JSON.stringify(polygonOptions)); + polygonOptions.points = _orgs; + var polygon = new Polygon(self, polygonOptions, exec); + var polygonId = polygon.getId(); + self.OVERLAYS[polygonId] = polygon; + polygon.one(polygonId + "_remove", function() { + polygon.off(); + delete self.OVERLAYS[polygonId]; + polygon = undefined; + }); + exec.call(this, function(result) { - polygonOptions.points = _orgs; - var polygon = new Polygon(self, result.id, polygonOptions, exec); - self.OVERLAYS[result.id] = polygon; - polygon.one(result.id + "_remove", function() { - polygon.off(); - delete self.OVERLAYS[result.id]; - polygon = undefined; - }); + polygon._privateInitialize(); + delete polygon._privateInitialize; + if (typeof callback === "function") { callback.call(self, polygon); } - }, self.errorHandler, self.id, 'loadPlugin', ["Polygon", polygonOptions]); + }, self.errorHandler, self.id, 'loadPlugin', ["Polygon", opts, polygon.hashCode]); + + return polygon; }; //------------- @@ -1099,19 +1117,29 @@ Map.prototype.addPolyline = function(polylineOptions, callback) { polylineOptions.clickable = polylineOptions.clickable === true; polylineOptions.zIndex = polylineOptions.zIndex || 0; polylineOptions.geodesic = polylineOptions.geodesic === true; + + var opts = JSON.parse(JSON.stringify(polylineOptions)); + polylineOptions.points = _orgs; + var polyline = new Polyline(self, polylineOptions, exec); + var polylineId = polyline.getId(); + self.OVERLAYS[polylineId] = polyline; + + polyline.one(polylineId + "_remove", function() { + polyline.off(); + delete self.OVERLAYS[polylineId]; + polyline = undefined; + }); + exec.call(this, function(result) { - polylineOptions.points = _orgs; - var polyline = new Polyline(self, result.id, polylineOptions, exec); - self.OVERLAYS[result.id] = polyline; - polyline.one(result.id + "_remove", function() { - polyline.off(); - delete self.OVERLAYS[result.id]; - polyline = undefined; - }); + polyline._privateInitialize(); + delete polyline._privateInitialize; + if (typeof callback === "function") { callback.call(self, polyline); } - }, self.errorHandler, self.id, 'loadPlugin', ['Polyline', polylineOptions]); + }, self.errorHandler, self.id, 'loadPlugin', ['Polyline', opts, polyline.hashCode]); + + return polyline; }; //------------- @@ -1129,7 +1157,7 @@ Map.prototype.addCircle = function(circleOptions, callback) { circleOptions.zIndex = circleOptions.zIndex || 0; circleOptions.radius = "radius" in circleOptions ? circleOptions.radius : 1; - var circle = new Circle(self, circleOptions, "Circle", exec); + var circle = new Circle(self, circleOptions, exec); var circleId = circle.getId(); self.OVERLAYS[circleId] = circle; circle.one(circleId + "_remove", function() { @@ -1169,7 +1197,7 @@ Map.prototype.addMarker = function(markerOptions, callback) { }; } - var marker = new Marker(self, markerOptions, "Marker", exec); + var marker = new Marker(self, markerOptions, exec); var markerId = marker.getId(); self.MARKERS[markerId] = marker; @@ -1217,6 +1245,22 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) { return marker.position; }); + + var markerCluster = new MarkerCluster(self, { + "icons": markerClusterOptions.icons, + "maxZoomLevel": Math.min(markerClusterOptions.maxZoomLevel || 15, 18), + "debug": markerClusterOptions.debug === true, + "boundsDraw": common.defaultTrueOption(markerClusterOptions.boundsDraw) + }, exec); + var markerClusterId = markerCluster.getId(); + self.OVERLAYS[markerClusterId] = markerCluster; + + markerCluster.one("remove", function() { + delete self.OVERLAYS[markerClusterId]; + markerCluster.destroy(); + }); + + exec.call(this, function(result) { var markerMap = {}; @@ -1233,46 +1277,16 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) { geocell: geocell, _marker: null }; - /* - 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); - marker.getId = function() { - return result.id + "-" + markerId; - }; - */ markerMap[markerId] = markerOptions; - - //self.MARKERS[marker.getId()] = marker; - //self.OVERLAYS[marker.getId()] = marker; }); - var markerCluster = new MarkerCluster(self, result.id, { - "icons": markerClusterOptions.icons, - "markerMap": markerMap, - "maxZoomLevel": Math.min(markerClusterOptions.maxZoomLevel || 15, 18), - "debug": markerClusterOptions.debug === true, - "boundsDraw": common.defaultTrueOption(markerClusterOptions.boundsDraw) - }, exec); - markerCluster.one("remove", function() { - delete self.OVERLAYS[result.id]; - /* - result.geocellList.forEach(function(geocell, idx) { - var markerOptions = markerClusterOptions.markers[idx]; - var markerId = result.id + "-" + (markerOptions.id || "marker_" + idx); - var marker = self.MARKERS[markerId]; - if (marker) { - marker.off(); - } - //delete self.MARKERS[markerId]; - delete self.OVERLAYS[markerId]; - }); - */ - markerCluster.destroy(); + marker._privateInitialize(); + delete marker._privateInitialize; + Object.defineProperty(marker, "_markerMap", { + value: markerMap, + writable: false }); - self.OVERLAYS[result.id] = markerCluster; if (typeof callback === "function") { callback.call(self, markerCluster); @@ -1280,8 +1294,9 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) { }, self.errorHandler, self.id, 'loadPlugin', ['MarkerCluster', { "positionList": positionList, "debug": markerClusterOptions.debug === true - }]); + }, markerCluster.hashCode]); + return markerCluster; }; /***************************************************************************** diff --git a/www/Marker.js b/www/Marker.js index e1cedf356..1b5b5940a 100644 --- a/www/Marker.js +++ b/www/Marker.js @@ -8,8 +8,9 @@ var argscheck = require('cordova/argscheck'), /***************************************************************************** * Marker Class *****************************************************************************/ -var Marker = function(map, id, markerOptions, className, _exec) { - Overlay.call(this, map, id, className, _exec); +var Marker = function(map, markerOptions, _exec, extras) { + extras = extras || {}; + Overlay.call(this, map, extras.className, 'Marker', _exec, extras); var self = this; @@ -17,16 +18,6 @@ var Marker = function(map, id, markerOptions, className, _exec) { self.set('position', markerOptions.position); } - //----------------------------------------------- - // Sets the initialize option to each property - //----------------------------------------------- - var ignores = ["map", "id", "hashCode", "type"]; - for (var key in markerOptions) { - if (ignores.indexOf(key) === -1) { - self.set(key, markerOptions[key]); - } - } - //----------------------------------------------- // Sets event listeners //----------------------------------------------- @@ -102,27 +93,6 @@ var Marker = function(map, id, markerOptions, className, _exec) { utils.extend(Marker, Overlay); -Marker.prototype._privateInitialize = function(markerOptions) { - var self = this; - //----------------------------------------------- - // Sets the initialize option to each property - //----------------------------------------------- - var ignores = ["map", "id", "hashCode", "type"]; - for (var key in markerOptions) { - if (ignores.indexOf(key) === -1) { - self.set(key, markerOptions[key], true); - } - } - - //----------------------------------------------- - // Trigger internal command queue - //----------------------------------------------- - Object.defineProperty(self, "_isReady", { - value: true, - writable: false - }); - self.exec("nop"); -}; Marker.prototype.remove = function(callback) { var self = this; if (self._isRemoved) { @@ -170,15 +140,6 @@ Marker.prototype.getPosition = function() { } return position; }; -Marker.prototype.getId = function() { - return this.id; -}; -Marker.prototype.getMap = function() { - return this.map; -}; -Marker.prototype.getHashCode = function() { - return this.hashCode; -}; Marker.prototype.setAnimation = function(animation, callback) { var self = this; diff --git a/www/MarkerCluster.js b/www/MarkerCluster.js index 5f02aea39..798a7e1e7 100644 --- a/www/MarkerCluster.js +++ b/www/MarkerCluster.js @@ -8,24 +8,18 @@ var argscheck = require('cordova/argscheck'), Marker = require('./Marker'), Cluster = require('./Cluster'), spherical = require('./spherical'), - BaseClass = require('./BaseClass'), + Overlay = require('./Overlay'), BaseArrayClass = require('./BaseArrayClass'); /***************************************************************************** * MarkerCluster Class *****************************************************************************/ -var exec; -var MarkerCluster = function(map, markerClusterId, markerClusterOptions, _exec) { - exec = _exec; - BaseClass.call(this); +var MarkerCluster = function(map, markerClusterOptions, _exec) { + Overlay.call(this, map, 'MarkerCluster', _exec); var idxCount = Object.keys(markerClusterOptions.markerMap).length + 1; var self = this; - Object.defineProperty(self, "_isReady", { - value: true, - writable: false - }); Object.defineProperty(self, "maxZoomLevel", { value: markerClusterOptions.maxZoomLevel, writable: false @@ -42,26 +36,11 @@ var MarkerCluster = function(map, markerClusterId, markerClusterOptions, _exec) value: {}, writable: false }); - Object.defineProperty(self, "_markerMap", { - value: markerClusterOptions.markerMap, - writable: false - }); + Object.defineProperty(self, "debug", { value: markerClusterOptions.debug === true, writable: false }); - Object.defineProperty(self, "map", { - value: map, - writable: false - }); - Object.defineProperty(self, "type", { - value: "MarkerCluster", - writable: false - }); - Object.defineProperty(self, "id", { - value: markerClusterId, - writable: false - }); Object.defineProperty(self, "MAX_RESOLUTION", { value: 11, writable: false @@ -209,20 +188,7 @@ var MarkerCluster = function(map, markerClusterId, markerClusterOptions, _exec) return self; }; -utils.extend(MarkerCluster, BaseClass); - -MarkerCluster.prototype.getPluginName = function() { - return this.map.getId() + "-markercluster"; -}; -MarkerCluster.prototype.getId = function() { - return this.id; -}; -MarkerCluster.prototype.getMap = function() { - return this.map; -}; -MarkerCluster.prototype.getHashCode = function() { - return this.hashCode; -}; +utils.extend(MarkerCluster, Overlay); MarkerCluster.prototype.onClusterClicked = function(cluster) { if (this._isRemoved) { @@ -333,7 +299,7 @@ MarkerCluster.prototype.remove = function() { cluster.remove(); }); } - exec.call(self, null, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {sync: true, remove: true}); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {sync: true, remove: true}); keys = Object.keys(self._markerMap); keys.forEach(function(markerId) { @@ -382,7 +348,7 @@ MarkerCluster.prototype.removeMarkerById = function(markerId) { markerOpts._cluster.marker = undefined; //delete self._markerMap[markerId]; if (isAdded) { - exec.call(self, null, null, self.getPluginName(), 'redrawClusters', [self.getId(), { + self.exec.call(self, null, null, self.getPluginName(), 'redrawClusters', [self.getId(), { "delete": [markerId] }], {sync: true}); } @@ -1052,7 +1018,7 @@ MarkerCluster.prototype._redraw = function(params) { return; } - exec.call(self, function() { + self.exec.call(self, function() { self.trigger("nextTask"); }, self.errorHandler, self.getPluginName(), 'redrawClusters', [self.getId(), { "resolution": resolution, @@ -1098,7 +1064,11 @@ MarkerCluster.prototype.getClusterIcon = function(cluster) { MarkerCluster.prototype._createMarker = function(markerOpts) { var markerId = markerOpts.__pgmId; var self = this; - var marker = new Marker(self.getMap(), self.id + "-" + markerId, markerOpts, "MarkerCluster", exec); + var marker = new Marker(self.getMap(), markerOpts, self.exec, { + class: 'MarkerCluster', + id: self.id + "-" + markerId, + }); + function updateProperty(prevValue, newValue, key) { self._markerMap[markerId][key] = newValue; } diff --git a/www/Overlay.js b/www/Overlay.js index 5661a1b1a..79773e27c 100644 --- a/www/Overlay.js +++ b/www/Overlay.js @@ -6,7 +6,8 @@ var BaseClass = require('./BaseClass'), /***************************************************************************** * Overlay Class *****************************************************************************/ -var Overlay = function(map, options, className, _exec) { +var Overlay = function(map, options, className, _exec, extras) { + extras = extras || {}; BaseClass.apply(this); var self = this; @@ -57,7 +58,7 @@ var Overlay = function(map, options, className, _exec) { writable: false }); Object.defineProperty(self, "id", { - value: className + "_" + this.hashCode, + value: extras.id || className + "_" + this.hashCode, writable: false }); Object.defineProperty(self, "type", { diff --git a/www/Polygon.js b/www/Polygon.js index 77b954b99..f8ec4cd81 100644 --- a/www/Polygon.js +++ b/www/Polygon.js @@ -1,264 +1,235 @@ var argscheck = require('cordova/argscheck'), - utils = require('cordova/utils'), - common = require('./Common'), - BaseClass = require('./BaseClass'), - BaseArrayClass = require('./BaseArrayClass'); + utils = require('cordova/utils'), + common = require('./Common'), + Overlay = require('./Overlay'), + BaseArrayClass = require('./BaseArrayClass'); /***************************************************************************** * Polygon Class *****************************************************************************/ -var exec; -var Polygon = function(map, polygonId, polygonOptions, _exec) { - exec = _exec; - BaseClass.apply(this); - - var self = this; - Object.defineProperty(self, "_isReady", { - value: true, - writable: false - }); - Object.defineProperty(self, "map", { - value: map, - writable: false - }); - Object.defineProperty(self, "id", { - value: polygonId, - writable: false - }); - Object.defineProperty(self, "type", { - value: "Polygon", - writable: false - }); - - //-------------------------- - // points property - //-------------------------- - var pointsProperty = common.createMvcArray(polygonOptions.points); - pointsProperty.on('set_at', function(index) { - var value = common.getLatLng(pointsProperty.getAt(index)); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPointAt', [polygonId, index, value]); - }); - pointsProperty.on('insert_at', function(index) { - var value = common.getLatLng(pointsProperty.getAt(index)); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertPointAt', [polygonId, index, value]); - }); - pointsProperty.on('remove_at', function(index) { - exec.call(self, null, self.errorHandler, self.getPluginName(), 'removePointAt', [polygonId, index]); - }); - - Object.defineProperty(self, "points", { - value: pointsProperty, - writable: false - }); - //-------------------------- - // holes property - //-------------------------- - var holesProperty = common.createMvcArray(polygonOptions.holes); - var _holes = common.createMvcArray(holesProperty.getArray()); - - holesProperty.on('set_at', function(index) { - var value = common.getLatLng(holesProperty.getAt(index)); - _holes.setAt(index,value); - }); - holesProperty.on('remove_at', function(index) { - _holes.removeAt(index); - }); - holesProperty.on('insert_at', function(index) { - var array = holesProperty.getAt(index); - if (array && (array instanceof Array || Array.isArray(array))) { - array = common.createMvcArray(array); - } - array.on('insert_at', function(idx) { - var value = common.getLatLng(array.getAt(idx)); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertPointOfHoleAt', [polygonId, index, idx, value]); - }); - array.on('set_at', function(idx) { - var value = common.getLatLng(array.getAt(idx)); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPointOfHoleAt', [polygonId, index, idx, value]); - }); - array.on('remove_at', function(idx) { - exec.call(self, null, self.errorHandler, self.getPluginName(), 'removePointOfHoleAt', [polygonId, index, idx]); - }); - - exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertHoleAt', [polygonId, index, array.getArray()]); - }); - - Object.defineProperty(self, "holes", { - value: holesProperty, - writable: false - }); - - //-------------------------- - // other properties - //--------------------------. - var ignores = ["map", "id", "hashCode", "type", "points", "holes"]; - for (var key in polygonOptions) { - if (ignores.indexOf(key) === -1) { - self.set(key, polygonOptions[key]); - } +var Polygon = function (map, polygonOptions, _exec) { + Overlay.call(this, map, polygonOptions, 'Polygon', _exec); + + var self = this; + + //-------------------------- + // points property + //-------------------------- + var pointsProperty = common.createMvcArray(polygonOptions.points); + pointsProperty.on('set_at', function (index) { + var value = common.getLatLng(pointsProperty.getAt(index)); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPointAt', [polygonId, index, value]); + }); + pointsProperty.on('insert_at', function (index) { + var value = common.getLatLng(pointsProperty.getAt(index)); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertPointAt', [polygonId, index, value]); + }); + pointsProperty.on('remove_at', function (index) { + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'removePointAt', [polygonId, index]); + }); + + Object.defineProperty(self, "points", { + value: pointsProperty, + writable: false + }); + //-------------------------- + // holes property + //-------------------------- + var holesProperty = common.createMvcArray(polygonOptions.holes); + var _holes = common.createMvcArray(holesProperty.getArray()); + + holesProperty.on('set_at', function (index) { + var value = common.getLatLng(holesProperty.getAt(index)); + _holes.setAt(index, value); + }); + holesProperty.on('remove_at', function (index) { + _holes.removeAt(index); + }); + holesProperty.on('insert_at', function (index) { + var array = holesProperty.getAt(index); + if (array && (array instanceof Array || Array.isArray(array))) { + array = common.createMvcArray(array); } - //----------------------------------------------- - // Sets event listeners - //----------------------------------------------- - self.on("clickable_changed", function() { - var clickable = self.get("clickable"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setClickable', [self.getId(), clickable]); - }); - self.on("geodesic_changed", function() { - var geodesic = self.get("geodesic"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setGeodesic', [self.getId(), geodesic]); - }); - self.on("zIndex_changed", function() { - var zIndex = self.get("zIndex"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); - }); - self.on("visible_changed", function() { - var visible = self.get("visible"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); - }); - self.on("strokeWidth_changed", function() { - var width = self.get("strokeWidth"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeWidth', [self.getId(), width]); - }); - self.on("strokeColor_changed", function() { - var color = self.get("strokeColor"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeColor', [self.getId(), common.HTMLColor2RGBA(color, 0.75)]); - }); - self.on("fillColor_changed", function() { - var color = self.get("fillColor"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setFillColor', [self.getId(), common.HTMLColor2RGBA(color, 0.75)]); - }); - -}; - -utils.extend(Polygon, BaseClass); - -Polygon.prototype.remove = function(callback) { - var self = this; - if (self._isRemoved) { - return; + array.on('insert_at', function (idx) { + var value = common.getLatLng(array.getAt(idx)); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertPointOfHoleAt', [polygonId, index, idx, value]); + }); + array.on('set_at', function (idx) { + var value = common.getLatLng(array.getAt(idx)); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPointOfHoleAt', [polygonId, index, idx, value]); + }); + array.on('remove_at', function (idx) { + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'removePointOfHoleAt', [polygonId, index, idx]); + }); + + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertHoleAt', [polygonId, index, array.getArray()]); + }); + + Object.defineProperty(self, "holes", { + value: holesProperty, + writable: false + }); + + //-------------------------- + // other properties + //--------------------------. + // var ignores = ["map", "id", "hashCode", "type", "points", "holes"]; + // for (var key in polygonOptions) { + // if (ignores.indexOf(key) === -1) { + // self.set(key, polygonOptions[key]); + // } + // } + //----------------------------------------------- + // Sets event listeners + //----------------------------------------------- + self.on("clickable_changed", function () { + var clickable = self.get("clickable"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setClickable', [self.getId(), clickable]); + }); + self.on("geodesic_changed", function () { + var geodesic = self.get("geodesic"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setGeodesic', [self.getId(), geodesic]); + }); + self.on("zIndex_changed", function () { + var zIndex = self.get("zIndex"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); + }); + self.on("visible_changed", function () { + var visible = self.get("visible"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); + }); + self.on("strokeWidth_changed", function () { + var width = self.get("strokeWidth"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeWidth', [self.getId(), width]); + }); + self.on("strokeColor_changed", function () { + var color = self.get("strokeColor"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeColor', [self.getId(), common.HTMLColor2RGBA(color, 0.75)]); + }); + self.on("fillColor_changed", function () { + var color = self.get("fillColor"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setFillColor', [self.getId(), common.HTMLColor2RGBA(color, 0.75)]); + }); + +}; + +utils.extend(Polygon, Overlay); + +Polygon.prototype.remove = function (callback) { + var self = this; + if (self._isRemoved) { + return; + } + Object.defineProperty(self, "_isRemoved", { + value: true, + writable: false + }); + self.trigger(this.id + "_remove"); + self.exec.call(self, function () { + self.destroy(); + if (typeof callback === "function") { + callback.call(self); } - Object.defineProperty(self, "_isRemoved", { - value: true, - writable: false - }); - self.trigger(this.id + "_remove"); - exec.call(self, function() { - self.destroy(); - if (typeof callback === "function") { - callback.call(self); - } - }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {remove: true}); -}; -Polygon.prototype.getPluginName = function() { - return this.map.getId() + "-polygon"; -}; - -Polygon.prototype.getHashCode = function() { - return this.hashCode; -}; -Polygon.prototype.getMap = function() { - return this.map; -}; -Polygon.prototype.getId = function() { - return this.id; -}; - -Polygon.prototype.setPoints = function(points) { - var self = this; - var mvcArray = self.points; - mvcArray.empty(true); - - var i, - path = []; - - for (i = 0; i < points.length; i++) { - mvcArray.push(common.getLatLng(points[i]), true); - } - exec.call(this, null, self.errorHandler, self.getPluginName(), 'setPoints', [self.id, mvcArray.getArray()]); - return self; -}; -Polygon.prototype.getPoints = function() { - return this.points; -}; -Polygon.prototype.setHoles = function(holes) { - var self = this; - var mvcArray = this.holes; - mvcArray.empty(true); - - holes = holes || []; - if (holes.length > 0 && !utils.isArray(holes[0])) { - holes = [holes]; + }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], { + remove: true + }); +}; + +Polygon.prototype.setPoints = function (points) { + var self = this; + var mvcArray = self.points; + mvcArray.empty(true); + + var i, + path = []; + + for (i = 0; i < points.length; i++) { + mvcArray.push(common.getLatLng(points[i]), true); + } + self.exec.call(this, null, self.errorHandler, self.getPluginName(), 'setPoints', [self.id, mvcArray.getArray()]); + return self; +}; +Polygon.prototype.getPoints = function () { + return this.points; +}; +Polygon.prototype.setHoles = function (holes) { + var self = this; + var mvcArray = this.holes; + mvcArray.empty(true); + + holes = holes || []; + if (holes.length > 0 && !utils.isArray(holes[0])) { + holes = [holes]; + } + holes.forEach(function (hole) { + if (!utils.isArray(hole)) { + hole = [hole]; + mvcArray.push(hole, true); + } else { + var newHole = []; + for (var i = 0; i < hole.length; i++) { + newHole.push(common.getLatLng(hole[i])); + } + mvcArray.push(newHole, true); } - holes.forEach(function(hole) { - if (!utils.isArray(hole)) { - hole = [hole]; - mvcArray.push(hole, true); - } else { - var newHole = []; - for (var i = 0; i < hole.length; i++) { - newHole.push(common.getLatLng(hole[i])); - } - mvcArray.push(newHole, true); - } - }); - exec.call(this, null, self.errorHandler, self.getPluginName(), 'setHoles', [self.id, mvcArray.getArray()]); - return this; + }); + self.exec.call(this, null, self.errorHandler, self.getPluginName(), 'setHoles', [self.id, mvcArray.getArray()]); + return this; }; -Polygon.prototype.getHoles = function() { - return this.holes; +Polygon.prototype.getHoles = function () { + return this.holes; }; -Polygon.prototype.setFillColor = function(color) { - this.set('fillColor', color); - return this; +Polygon.prototype.setFillColor = function (color) { + this.set('fillColor', color); + return this; }; -Polygon.prototype.getFillColor = function() { - return this.get('fillColor'); +Polygon.prototype.getFillColor = function () { + return this.get('fillColor'); }; -Polygon.prototype.setStrokeColor = function(color) { - this.set('strokeColor', color); - return this; +Polygon.prototype.setStrokeColor = function (color) { + this.set('strokeColor', color); + return this; }; -Polygon.prototype.getStrokeColor = function() { - return this.get('strokeColor'); +Polygon.prototype.getStrokeColor = function () { + return this.get('strokeColor'); }; -Polygon.prototype.setStrokeWidth = function(width) { - this.set('strokeWidth', width); - return this; +Polygon.prototype.setStrokeWidth = function (width) { + this.set('strokeWidth', width); + return this; }; -Polygon.prototype.getStrokeWidth = function() { - return this.get('strokeWidth'); +Polygon.prototype.getStrokeWidth = function () { + return this.get('strokeWidth'); }; -Polygon.prototype.setVisible = function(visible) { - visible = common.parseBoolean(visible); - this.set('visible', visible); - return this; +Polygon.prototype.setVisible = function (visible) { + visible = common.parseBoolean(visible); + this.set('visible', visible); + return this; }; -Polygon.prototype.getVisible = function() { - return this.get('visible'); +Polygon.prototype.getVisible = function () { + return this.get('visible'); }; -Polygon.prototype.setClickable = function(clickable) { - clickable = common.parseBoolean(clickable); - this.set('clickable', clickable); - return this; +Polygon.prototype.setClickable = function (clickable) { + clickable = common.parseBoolean(clickable); + this.set('clickable', clickable); + return this; }; -Polygon.prototype.getClickable = function() { - return this.get('clickable'); +Polygon.prototype.getClickable = function () { + return this.get('clickable'); }; -Polygon.prototype.setGeodesic = function(geodesic) { - geodesic = common.parseBoolean(geodesic); - this.set('geodesic', geodesic); - return this; +Polygon.prototype.setGeodesic = function (geodesic) { + geodesic = common.parseBoolean(geodesic); + this.set('geodesic', geodesic); + return this; }; -Polygon.prototype.getGeodesic = function() { - return this.get('geodesic'); +Polygon.prototype.getGeodesic = function () { + return this.get('geodesic'); }; -Polygon.prototype.setZIndex = function(zIndex) { - this.set('zIndex', zIndex); - return this; +Polygon.prototype.setZIndex = function (zIndex) { + this.set('zIndex', zIndex); + return this; }; -Polygon.prototype.getZIndex = function() { - return this.get('zIndex'); +Polygon.prototype.getZIndex = function () { + return this.get('zIndex'); }; module.exports = Polygon; diff --git a/www/Polyline.js b/www/Polyline.js index f3cb2834d..219a63b36 100644 --- a/www/Polyline.js +++ b/www/Polyline.js @@ -1,195 +1,163 @@ var argscheck = require('cordova/argscheck'), - utils = require('cordova/utils'), - common = require('./Common'), - BaseClass = require('./BaseClass'), - BaseArrayClass = require('./BaseArrayClass'); + utils = require('cordova/utils'), + common = require('./Common'), + Overlay = require('./Overlay'), + BaseArrayClass = require('./BaseArrayClass'); /***************************************************************************** * Polyline Class *****************************************************************************/ -var exec; -var Polyline = function(map, polylineId, polylineOptions, _exec) { - exec = _exec; - BaseClass.apply(this); +var Polyline = function (map, polylineOptions, _exec) { + Overlay.call(this, map, polylineOptions, 'GroundOverlay', _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: polylineId, - writable: false - }); - Object.defineProperty(self, "type", { - value: "Polyline", - writable: false - }); + var self = this; - var pointsProperty = common.createMvcArray(polylineOptions.points); - pointsProperty.on('set_at', function(index) { - var value = common.getLatLng(pointsProperty.getAt(index)); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPointAt', [polylineId, index, value]); - }); - pointsProperty.on('insert_at', function(index) { - var value = common.getLatLng(pointsProperty.getAt(index)); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertPointAt', [polylineId, index, value]); - }); - pointsProperty.on('remove_at', function(index) { - exec.call(self, null, self.errorHandler, self.getPluginName(), 'removePointAt', [polylineId, index]); - }); + var pointsProperty = common.createMvcArray(polylineOptions.points); + pointsProperty.on('set_at', function (index) { + var value = common.getLatLng(pointsProperty.getAt(index)); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPointAt', [polylineId, index, value]); + }); + pointsProperty.on('insert_at', function (index) { + var value = common.getLatLng(pointsProperty.getAt(index)); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'insertPointAt', [polylineId, index, value]); + }); + pointsProperty.on('remove_at', function (index) { + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'removePointAt', [polylineId, index]); + }); - Object.defineProperty(self, "points", { - value: pointsProperty, - writable: false - }); - //----------------------------------------------- - // Sets the initialize option to each property - //----------------------------------------------- - var ignores = ["map", "id", "hashCode", "type", "points"]; - for (var key in polylineOptions) { - if (ignores.indexOf(key) === -1) { - self.set(key, polylineOptions[key]); - } - } + Object.defineProperty(self, "points", { + value: pointsProperty, + writable: false + }); + //----------------------------------------------- + // Sets the initialize option to each property + //----------------------------------------------- + // var ignores = ["map", "id", "hashCode", "type", "points"]; + // for (var key in polylineOptions) { + // if (ignores.indexOf(key) === -1) { + // self.set(key, polylineOptions[key]); + // } + // } - //----------------------------------------------- - // Sets event listeners - //----------------------------------------------- - self.on("geodesic_changed", function() { - var geodesic = self.get("geodesic"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setGeodesic', [self.getId(), geodesic]); - }); - self.on("zIndex_changed", function() { - var zIndex = self.get("zIndex"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); - }); - self.on("clickable_changed", function() { - var clickable = self.get("clickable"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setClickable', [self.getId(), clickable]); - }); - self.on("visible_changed", function() { - var visible = self.get("visible"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); - }); - self.on("strokeWidth_changed", function() { - var strokeWidth = self.get("strokeWidth"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeWidth', [self.getId(), strokeWidth]); - }); - self.on("strokeColor_changed", function() { - var color = self.get("strokeColor"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeColor', [self.getId(), common.HTMLColor2RGBA(color, 0.75)]); - }); + //----------------------------------------------- + // Sets event listeners + //----------------------------------------------- + self.on("geodesic_changed", function () { + var geodesic = self.get("geodesic"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setGeodesic', [self.getId(), geodesic]); + }); + self.on("zIndex_changed", function () { + var zIndex = self.get("zIndex"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); + }); + self.on("clickable_changed", function () { + var clickable = self.get("clickable"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setClickable', [self.getId(), clickable]); + }); + self.on("visible_changed", function () { + var visible = self.get("visible"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); + }); + self.on("strokeWidth_changed", function () { + var strokeWidth = self.get("strokeWidth"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeWidth', [self.getId(), strokeWidth]); + }); + self.on("strokeColor_changed", function () { + var color = self.get("strokeColor"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setStrokeColor', [self.getId(), common.HTMLColor2RGBA(color, 0.75)]); + }); }; -utils.extend(Polyline, BaseClass); +utils.extend(Polyline, Overlay); -Polyline.prototype.getId = function() { - return this.id; -}; +Polyline.prototype.setPoints = function (points) { + var self = this; + var mvcArray = self.points; + mvcArray.empty(true); -Polyline.prototype.getPluginName = function() { - return this.map.getId() + "-polyline"; -}; + var i, + path = []; -Polyline.prototype.getHashCode = function() { - return this.hashCode; + for (i = 0; i < points.length; i++) { + mvcArray.push({ + "lat": points[i].lat, + "lng": points[i].lng + }, true); + } + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPoints', [self.id, mvcArray.getArray()]); + return self; }; - -Polyline.prototype.setPoints = function(points) { - var self = this; - var mvcArray = self.points; - mvcArray.empty(true); - - var i, - path = []; - - for (i = 0; i < points.length; i++) { - mvcArray.push({ - "lat": points[i].lat, - "lng": points[i].lng - }, true); - } - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setPoints', [self.id, mvcArray.getArray()]); - return self; -}; -Polyline.prototype.getPoints = function() { - return this.points; +Polyline.prototype.getPoints = function () { + return this.points; }; -Polyline.prototype.setStrokeColor = function(color) { - this.set('strokeColor', color); - return this; +Polyline.prototype.setStrokeColor = function (color) { + this.set('strokeColor', color); + return this; }; -Polyline.prototype.getStrokeColor = function() { - return this.get('strokeColor'); +Polyline.prototype.getStrokeColor = function () { + return this.get('strokeColor'); }; -Polyline.prototype.setStrokeWidth = function(width) { - this.set('strokeWidth', width); - return this; +Polyline.prototype.setStrokeWidth = function (width) { + this.set('strokeWidth', width); + return this; }; -Polyline.prototype.getStrokeWidth = function() { - return this.get('strokeWidth'); +Polyline.prototype.getStrokeWidth = function () { + return this.get('strokeWidth'); }; -Polyline.prototype.setVisible = function(visible) { - visible = common.parseBoolean(visible); - this.set('visible', visible); - return this; +Polyline.prototype.setVisible = function (visible) { + visible = common.parseBoolean(visible); + this.set('visible', visible); + return this; }; -Polyline.prototype.getVisible = function() { - return this.get('visible'); +Polyline.prototype.getVisible = function () { + return this.get('visible'); }; -Polyline.prototype.setClickable = function(clickable) { - clickable = common.parseBoolean(clickable); - this.set('clickable', clickable); - return this; +Polyline.prototype.setClickable = function (clickable) { + clickable = common.parseBoolean(clickable); + this.set('clickable', clickable); + return this; }; -Polyline.prototype.getClickable = function() { - return this.get('clickable'); +Polyline.prototype.getClickable = function () { + return this.get('clickable'); }; -Polyline.prototype.setGeodesic = function(geodesic) { - geodesic = common.parseBoolean(geodesic); - this.set('geodesic', geodesic); - return this; +Polyline.prototype.setGeodesic = function (geodesic) { + geodesic = common.parseBoolean(geodesic); + this.set('geodesic', geodesic); + return this; }; -Polyline.prototype.getGeodesic = function() { - return this.get('geodesic'); +Polyline.prototype.getGeodesic = function () { + return this.get('geodesic'); }; -Polyline.prototype.setZIndex = function(zIndex) { - this.set('zIndex', zIndex); - return this; +Polyline.prototype.setZIndex = function (zIndex) { + this.set('zIndex', zIndex); + return this; }; -Polyline.prototype.getZIndex = function() { - return this.get('zIndex'); +Polyline.prototype.getZIndex = function () { + return this.get('zIndex'); }; -Polyline.prototype.getMap = function() { - return this.map; -}; - -Polyline.prototype.remove = function() { - var self = this; - if (self._isRemoved) { - return; - } - Object.defineProperty(self, "_isRemoved", { - value: true, - writable: false - }); - exec.call(self, function() { - self.destroy(); - if (typeof callback === "function") { - callback.call(self); - } - }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {remove: true}); - self.trigger(self.id + "_remove"); - var points = self.get("points"); - if (points) { - points.clear(); +Polyline.prototype.remove = function () { + var self = this; + if (self._isRemoved) { + return; + } + Object.defineProperty(self, "_isRemoved", { + value: true, + writable: false + }); + self.exec.call(self, function () { + self.destroy(); + if (typeof callback === "function") { + callback.call(self); } + }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], { + remove: true + }); + self.trigger(self.id + "_remove"); + var points = self.get("points"); + if (points) { + points.clear(); + } }; module.exports = Polyline; diff --git a/www/TileOverlay.js b/www/TileOverlay.js index ac4f32a75..55b39de25 100644 --- a/www/TileOverlay.js +++ b/www/TileOverlay.js @@ -1,131 +1,105 @@ var argscheck = require('cordova/argscheck'), - utils = require('cordova/utils'), - common = require('./Common'), - BaseClass = require('./BaseClass'); + utils = require('cordova/utils'), + common = require('./Common'), + Overlay = require('./Overlay'); /***************************************************************************** * TileOverlay Class *****************************************************************************/ -var exec; -var TileOverlay = function(map, tileOverlayId, tileOverlayOptions, _exec) { - exec = _exec; - BaseClass.apply(this); +var TileOverlay = function (map, tileOverlayOptions, _exec) { + Overlay.call(this, map, tileOverlayOptions, 'TileOverlay', _exec); - var self = this; - Object.defineProperty(self, "id", { - value: tileOverlayId, - writable: false - }); - Object.defineProperty(self, "type", { - value: "TileOverlay", - writable: false - }); - Object.defineProperty(self, "map", { - value: map, - writable: false - }); - Object.defineProperty(self, "_isReady", { - value: true, - writable: false - }); - //----------------------------------------------- - // Sets the initialize option to each property - //----------------------------------------------- - var ignores = ["map", "id", "hashCode", "type"]; - for (var key in tileOverlayOptions) { - if (ignores.indexOf(key) === -1) { - self.set(key, tileOverlayOptions[key]); - } - } + var self = this; - //----------------------------------------------- - // Sets event listeners - //----------------------------------------------- - self.on("fadeIn_changed", function() { - var fadeIn = self.get("fadeIn"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setFadeIn', [self.getId(), fadeIn]); - }); - self.on("opacity_changed", function() { - var opacity = self.get("opacity"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setOpacity', [self.getId(), opacity]); - }); - self.on("zIndex_changed", function() { - var zIndex = self.get("zIndex"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); - }); - self.on("visible_changed", function() { - var visible = self.get("visible"); - exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); - }); + //----------------------------------------------- + // Sets event listeners + //----------------------------------------------- + self.on("fadeIn_changed", function () { + var fadeIn = self.get("fadeIn"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setFadeIn', [self.getId(), fadeIn]); + }); + self.on("opacity_changed", function () { + var opacity = self.get("opacity"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setOpacity', [self.getId(), opacity]); + }); + self.on("zIndex_changed", function () { + var zIndex = self.get("zIndex"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setZIndex', [self.getId(), zIndex]); + }); + self.on("visible_changed", function () { + var visible = self.get("visible"); + self.exec.call(self, null, self.errorHandler, self.getPluginName(), 'setVisible', [self.getId(), visible]); + }); }; - utils.extend(TileOverlay, BaseClass); -TileOverlay.prototype.getPluginName = function() { - return this.map.getId() + "-tileoverlay"; +TileOverlay.prototype.getPluginName = function () { + return this.map.getId() + "-tileoverlay"; }; -TileOverlay.prototype.getHashCode = function() { - return this.hashCode; +TileOverlay.prototype.getHashCode = function () { + return this.hashCode; }; -TileOverlay.prototype.getMap = function() { - return this.map; +TileOverlay.prototype.getMap = function () { + return this.map; }; -TileOverlay.prototype.getId = function() { - return this.id; +TileOverlay.prototype.getId = function () { + return this.id; }; -TileOverlay.prototype.getTileSize = function() { - return this.get("tileSize"); +TileOverlay.prototype.getTileSize = function () { + return this.get("tileSize"); }; -TileOverlay.prototype.getZIndex = function() { - return this.get("zIndex"); +TileOverlay.prototype.getZIndex = function () { + return this.get("zIndex"); }; -TileOverlay.prototype.setZIndex = function(zIndex) { - this.set('zIndex', zIndex); +TileOverlay.prototype.setZIndex = function (zIndex) { + this.set('zIndex', zIndex); }; -TileOverlay.prototype.setFadeIn = function(fadeIn) { - fadeIn = common.parseBoolean(fadeIn); - this.set('fadeIn', fadeIn); +TileOverlay.prototype.setFadeIn = function (fadeIn) { + fadeIn = common.parseBoolean(fadeIn); + this.set('fadeIn', fadeIn); }; -TileOverlay.prototype.getFadeIn = function() { - return this.get('fadeIn'); +TileOverlay.prototype.getFadeIn = function () { + return this.get('fadeIn'); }; -TileOverlay.prototype.setVisible = function(visible) { - visible = common.parseBoolean(visible); - this.set('visible', visible); +TileOverlay.prototype.setVisible = function (visible) { + visible = common.parseBoolean(visible); + this.set('visible', visible); }; -TileOverlay.prototype.getOpacity = function() { - return this.get('opacity'); +TileOverlay.prototype.getOpacity = function () { + return this.get('opacity'); }; -TileOverlay.prototype.setOpacity = function(opacity) { - if (!opacity && opacity !== 0) { - console.log('opacity value must be int or double'); - return false; - } - this.set('opacity', opacity); +TileOverlay.prototype.setOpacity = function (opacity) { + if (!opacity && opacity !== 0) { + console.log('opacity value must be int or double'); + return false; + } + this.set('opacity', opacity); }; -TileOverlay.prototype.getVisible = function() { - return this.get('visible'); +TileOverlay.prototype.getVisible = function () { + return this.get('visible'); }; -TileOverlay.prototype.remove = function(callback) { - var self = this; - if (self._isRemoved) { - return; +TileOverlay.prototype.remove = function (callback) { + var self = this; + if (self._isRemoved) { + return; + } + Object.defineProperty(self, "_isRemoved", { + value: true, + writable: false + }); + self.trigger(self.id + "_remove"); + self.exec.call(self, function () { + self.destroy(); + if (typeof callback === "function") { + callback.call(self); } - Object.defineProperty(self, "_isRemoved", { - value: true, - writable: false - }); - self.trigger(self.id + "_remove"); - exec.call(self, function() { - self.destroy(); - if (typeof callback === "function") { - callback.call(self); - } - }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {remove: true}); + }, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], { + remove: true + }); }; module.exports = TileOverlay;