I want a function which does some calculations to be called each time the route is edited.
The route_has_been_edited event is emitted only by an existing route (pitily).
I connect the event of deselecting routeEditor
control (which means the route has just been created) to a function call.
This nameless function creates a connection between routeupdate
event in the freshly made route
and the calculating function.
Here is my noob attempt to code it
routeEditor.events.add ('deselect', function (e) {
var route = e.get('target').getRoute();
alert ('Route length - ' + route.getLength());
// notice me, senpai
route.Editor.events.add ('routeupdate', recalc(polygon, route));
recalc (polygon, route);
alert("Watashi o mushi shinaide kudasaaai (>_<)");
});
I didn't check if I have done the second event connection right, but even despite that, why does the first alert work, and second does not?