When a map has multiple polylines, and the code changes the points of a polyline (eg: polyline.setPoints() or directly modify the polyline points array).
The new points could become no clickable - depending on the whether the new points are within the original bounds
The last polyline added to the map becomes not clickable
Expected behavior:
All polylines should still register the click event
Screen capture or video record:
Related code, data or error log (please format your code or data):
Click on Yellow polyline (and any other polyline) to show a marker at point of click. See that all the polylines register click
Click Change points on green
Click on Yellow polyline. Notice that it no longer registers any click
NOTE:
Green line is still registering the click because the new points are within the original bounds
If you change the code as below, then green polyline will no longer register click event as well.
PluginPolyline.create is called for each polyline, with it's unique hashCode (polylineHashCode)
Only one instance of PluginPolyline is registered in PluginManager, with the same service id map-{{mapId}}-polyline
When a polyline function is called in javascript, it invokes the cordova plugin with id map-{{mapId}}-polyline.
If the program ever makes any changes to a polyline, the object cache in Java side of the program will become out of sync.
Because all of the functions in PluginPolyline make use of the instance's polylineHashCode to construct the cache property ids.
Since every polyline is created with the same instance of the plugin, the polylineHashCode is overwritten every time. So it will always be the hashCode of the last polyline.
Fix suggestions
There are many potential fixes for this issue. It will come down to the preferred solution architecture
Keep many instance of the Plugin
Register each instance of the plugin to PluginManager. Add the hashcode to the service id. ie: map-{{id}}-polyline-{{hashcode}}.
Change javascript to invoke the cordova plugin by adding the hashcode
Only one instance of Plugin
Create only one instance of each type of Plugin.
Does not need to change any of the javascript code
The caller already pass the id argument. Which is {{type}}_{{hashcode}}, eg: polyline_{{hashcode}}. So each function can extract the hashcode from theid` argument
Javascript pass the hashCode instead of the id
Instead of passing the id argument ({{type}}_{{hashcode}}), the caller should pass the hashCode
Then the id and other property keys can be constructed in the Plugin
NOTE
This bug has bigger impact than the described symptoms.
All map Plugins are implemented this way. Which means any change which requires "object cache syncing" will be impacted.
For example, I believe Polygons are also impacted.
Support this plugin activity
I appreicate if you give me a beer :beer: from here
I'm submitting a ... (check one with "x")
OS: (check one with "x")
cordova information: (run
$> cordova plugin list
)If you use
@ionic-native/google-maps
, please tell the package.json (only@ionic-native/core
and@ionic-native/google-maps
are fine mostly)Current behavior:
When a map has multiple polylines, and the code changes the points of a polyline (eg:
polyline.setPoints()
or directly modify the polyline points array).Expected behavior:
All polylines should still register the click event
Screen capture or video record:
Related code, data or error log (please format your code or data):
Project that demo this issue
https://github.com/ebhsgit/gmap-test/tree/bug-multi_polyline_incorrect_bounds
Steps
Create Polylines
Change points on green
NOTE: Green line is still registering the click because the new points are within the original bounds If you change the code as below, then green polyline will no longer register click event as well.
Cause:
PluginPolyline.create
is called for each polyline, with it's unique hashCode (polylineHashCode
) Only one instance ofPluginPolyline
is registered inPluginManager
, with the same service idmap-{{mapId}}-polyline
When a polyline function is called in javascript, it invokes the cordova plugin with idmap-{{mapId}}-polyline
.If the program ever makes any changes to a polyline, the
object cache
in Java side of the program will become out of sync. Because all of the functions inPluginPolyline
make use of the instance'spolylineHashCode
to construct the cache property ids. Since every polyline is created with the same instance of the plugin, thepolylineHashCode
is overwritten every time. So it will always be the hashCode of the last polyline.Fix suggestions
There are many potential fixes for this issue. It will come down to the preferred solution architecture
Register each instance of the plugin to
PluginManager
. Add the hashcode to the service id. ie:map-{{id}}-polyline-{{hashcode}}
. Change javascript to invoke the cordova plugin by adding the hashcodeCreate only one instance of each type of Plugin. Does not need to change any of the javascript code
The caller already pass the
id
argument. Which is{{type}}_{{hashcode}}
, eg:polyline_{{hashcode}}. So each function can extract the hashcode from the
id` argumenthashCode
instead of the idInstead of passing the
id
argument ({{type}}_{{hashcode}}
), the caller should pass the hashCode Then theid
and other property keys can be constructed in the PluginNOTE
This bug has bigger impact than the described symptoms. All map Plugins are implemented this way. Which means any change which requires "object cache syncing" will be impacted.
For example, I believe Polygons are also impacted.
Support this plugin activity
I appreicate if you give me a beer :beer: from here