Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding directions_changed listener for dragable routes #18

Closed
P1X3 opened this issue May 4, 2018 · 3 comments
Closed

Adding directions_changed listener for dragable routes #18

P1X3 opened this issue May 4, 2018 · 3 comments
Labels
received Indicates the problem has been received

Comments

@P1X3
Copy link

P1X3 commented May 4, 2018

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 P1X3 changed the title Adding Adding directions_changed listener for dragable routes May 5, 2018
@P1X3
Copy link
Author

P1X3 commented May 5, 2018

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 explooosion added the received Indicates the problem has been received label May 6, 2018
explooosion added a commit that referenced this issue May 6, 2018
@explooosion
Copy link
Owner

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

@explooosion
Copy link
Owner

Version 0.5.4 Now Available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
received Indicates the problem has been received
Projects
None yet
Development

No branches or pull requests

2 participants