Skip to content

Commit

Permalink
FIX - Polyline not firing click event after changing points
Browse files Browse the repository at this point in the history
* Quick patch to fix object cache out of sync
* mapsplugin#2893
  • Loading branch information
ebhsgit committed Nov 17, 2021
1 parent 4292c19 commit 3762d17
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/android/plugin/google/maps/PluginPolyline.java
Expand Up @@ -21,6 +21,10 @@
public class PluginPolyline extends MyPlugin implements MyPluginInterface {
private String polylineHashCode;

private String getPolylineHashCode(String polylineId) {
return polylineId.replaceFirst("^polyline_", "");
}

/**
* Create polyline
* @param args
Expand Down Expand Up @@ -157,10 +161,12 @@ public void remove(final JSONArray args, final CallbackContext callbackContext)
}
pluginMap.objects.remove(id);

id = "polyline_bounds_" + polylineHashCode;
pluginMap.objects.remove(id);
String hashCode = this.getPolylineHashCode(id);

String boundPropertyKey = "polyline_bounds_" + hashCode;
pluginMap.objects.remove(boundPropertyKey);

String propertyKey = "polyline_property_" + polylineHashCode;
String propertyKey = "polyline_property_" + hashCode;
pluginMap.objects.remove(propertyKey);

cordova.getActivity().runOnUiThread(new Runnable() {
Expand All @@ -178,7 +184,8 @@ public void setPoints(final JSONArray args, final CallbackContext callbackContex

final Polyline polyline = this.getPolyline(id);
// Recalculate the polygon bounds
final String propertyId = "polyline_bounds_" + polylineHashCode;
String hashCode = this.getPolylineHashCode(id);
final String propertyId = "polyline_bounds_" + hashCode;

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
Expand Down Expand Up @@ -208,7 +215,8 @@ public void removePointAt(final JSONArray args, CallbackContext callbackContext)
final Polyline polyline = this.getPolyline(id);

// Recalculate the polygon bounds
final String propertyId = "polyline_bounds_" + polylineHashCode;
String hashCode = this.getPolylineHashCode(id);
final String propertyId = "polyline_bounds_" + hashCode;

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
Expand Down Expand Up @@ -239,7 +247,8 @@ public void insertPointAt(final JSONArray args, CallbackContext callbackContext)


// Recalculate the polygon bounds
final String propertyId = "polyline_bounds_" + polylineHashCode;
String hashCode = this.getPolylineHashCode(id);
final String propertyId = "polyline_bounds_" + hashCode;

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
Expand All @@ -264,15 +273,17 @@ public void setPointAt(final JSONArray args, CallbackContext callbackContext) th

final Polyline polyline = this.getPolyline(id);

// Recalculate the polygon bounds
String hashCode = this.getPolylineHashCode(id);
String propertyId = "polyline_bounds_" + hashCode;

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
List<LatLng> path = polyline.getPoints();
if (path.size() > index) {
path.set(index, latLng);

// Recalculate the polygon bounds
String propertyId = "polyline_bounds_" + polylineHashCode;
pluginMap.objects.put(propertyId, PluginUtil.getBoundsFromPath(path));

polyline.setPoints(path);
Expand Down Expand Up @@ -312,7 +323,9 @@ public void run() {
polyline.setVisible(isVisible);
}
});
String propertyId = "polyline_property_" + polylineHashCode;

String hashCode = this.getPolylineHashCode(id);
String propertyId = "polyline_property_" + hashCode;
JSONObject properties = (JSONObject)pluginMap.objects.get(propertyId);
properties.put("isVisible", isVisible);
pluginMap.objects.put(propertyId, properties);
Expand Down

0 comments on commit 3762d17

Please sign in to comment.