Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Know when polyline path variable change

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

like image 285
cadetill Avatar asked Dec 04 '22 04:12

cadetill


2 Answers

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.

like image 89
Connie Avatar answered Dec 21 '22 23:12

Connie


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.

like image 25
Eric Bridger Avatar answered Dec 22 '22 00:12

Eric Bridger