explooosion / Agm-Direction

This is the directive for @agm/core (not official)
https://robby570.tw/Agm-Direction-Docs/
MIT License
75 stars 26 forks source link

Adding directions_changed listener for dragable routes #18

Closed P1X3 closed 6 years ago

P1X3 commented 6 years ago

Would love to get some input and help with adding directions_changed listener. However, I can't comprehend how to connect it all. I have added the code pasted below right after directionsDisplay is initialized, but the problem is that neither onChange or directionsDisplay are defined inside listener function. Obviously...

        this.directionsDisplay.addListener('directions_changed', function() {
          this.onChange.emit(this.directionsDisplay.getDirections());
        });

So my temporary workaround was to create additional EventEmitter outside of AgmDirection class, then subscribe to it in ngOnInit, and finally from there just emit onChange with directionsDisplay.getDirections(). Kind of a tacky but it works. If dragable is set to true then after dragging route will fire onChange with modified route.

Would love to know what would be the proper way to do this and perhaps it can be added to project.

P1X3 commented 6 years ago

Okay, so going to answer my own question.

  1. Comment out this.onChange.emit(response);
  2. Add following code right after initializing this.directionsDisplay and calling setMap method on it.
    this.directionsDisplay.addListener('directions_changed', () => {
    this.onChange.emit(this.directionsDisplay.getDirections());
    });

    So now onChange is fired when directions are changed in the Renderer, and that includes dragable routes.

explooosion commented 6 years ago

Hi @P1X3 . Thanks for your suggestion, I will add this feature 😃.

explooosion commented 6 years ago

Version 0.5.4 Now Available.