Skip to content

Commit

Permalink
- Implementing new way
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Mar 31, 2018
1 parent 9c2430a commit e921087
Show file tree
Hide file tree
Showing 17 changed files with 800 additions and 964 deletions.
11 changes: 11 additions & 0 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 4 additions & 3 deletions src/android/plugin/google/maps/PluginCircle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/android/plugin/google/maps/PluginGroundOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/android/plugin/google/maps/PluginMarkerCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
42 changes: 22 additions & 20 deletions src/android/plugin/google/maps/PluginPolygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
final ArrayList<ArrayList<LatLng>> holePaths = new ArrayList<ArrayList<LatLng>>();

JSONObject opts = args.getJSONObject(1);
final String hashCode = args.getString(2);
if (opts.has("points")) {
JSONArray points = opts.getJSONArray("points");
ArrayList<LatLng> path2 = PluginUtil.JSONArray2LatLngList(points);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<LatLng> path = (ArrayList<LatLng>)pluginMap.objects.get(propertyId);
if (path.size() > 0) {
path.remove(index);
Expand All @@ -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 {
Expand Down Expand Up @@ -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<LatLng> path = (ArrayList<LatLng>)pluginMap.objects.get(propertyId);
path.clear();
JSONObject position;
Expand All @@ -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() {
Expand Down Expand Up @@ -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<LatLng> path = (ArrayList<LatLng>)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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -411,15 +413,15 @@ 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<LatLng> path = (ArrayList<LatLng>)pluginMap.objects.get(propertyId);
path.set(index, latLng);
pluginMap.objects.put(propertyId, path);

//-----------------------------------
// 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() {
Expand All @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
for (int i = 0; i < holes.size(); i++) {
holes.get(i).clear();
Expand Down Expand Up @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
ArrayList<LatLng> hole = null;
if (holeIndex < holes.size()) {
Expand Down Expand Up @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
ArrayList<LatLng> hole = null;
if (holeIndex < holes.size()) {
Expand Down Expand Up @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
ArrayList<LatLng> hole = null;
if (holeIndex < holes.size()) {
Expand Down Expand Up @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
holes.add(holeIndex, newHole);
pluginMap.objects.put(propertyId, holes);
Expand Down Expand Up @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
holes.set(holeIndex, newHole);
pluginMap.objects.put(propertyId, holes);
Expand Down Expand Up @@ -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<ArrayList<LatLng>> holes = (ArrayList<ArrayList<LatLng>>) pluginMap.objects.get(propertyId);
holes.remove(holeIndex);
pluginMap.objects.put(propertyId, holes);
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 12 additions & 10 deletions src/android/plugin/google/maps/PluginPolyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<LatLng> path = PluginUtil.JSONArray2LatLngList(points);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/android/plugin/google/maps/PluginTileOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");


Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit e921087

Please sign in to comment.