I have a editable polyline and I need to know when this polyline change their path variable. It is posible to add a new event ("path_change" or some like this) into my polyline?
Thanks
Regards cadetill
I was just facing this problem. I solved it by adding event listeners to the polyline path, which is implemented as an mvc array. I used the mvc array events documented here: https://developers.google.com/maps/documentation/javascript/reference#MVCArray
Once you have your polyline set up:
var path = poly.getPath();
google.maps.event.addListener(path, 'insert_at', function(){
alert("path insert_at event");
});
google.maps.event.addListener(path, 'remove_at', function(){
alert("path remove_at event");
});
google.maps.event.addListener(path, 'set_at', function(){
alert("path set_at event");
});
Hope that helps.
I don't think it's possible to add an event to the Polyline object. See the reference I'm also not sure what events are triggered during an edit, but I assume 'click', 'dblclick', etc are triggered. You'll need to run tests to see what events signal the end of the edit. Assuming you've saved the array returned by Polyline.getPath() before the edit, you'll need to check that against the new getPath() results to determine if they've changed. Since path is an array of LatLng objects you could use LatLng.equals(LatLng), along with basic array.length checks, etc. Could be that LatLngArray.join() could be used to compare the two arrays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With