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

Handling Events in Custom MapController #669

Closed
tomrussell opened this issue Dec 4, 2018 · 5 comments
Closed

Handling Events in Custom MapController #669

tomrussell opened this issue Dec 4, 2018 · 5 comments
Assignees
Labels

Comments

@tomrussell
Copy link

tomrussell commented Dec 4, 2018

I'm trying to work with the MapController component to construct a DrawControl as described in #450 (comment), but using the updated API in v4

My simple controller looks like this:

class DrawController extends MapController {
  constructor({ enabled }) {
    super();
    this.enabled = enabled;
    this.events = ['click'];
  }
  
  handleEvent = (event) => {
    if (this.enabled) {
      if (event.type === 'click') {
        console.log('Clicked');
      }
    }
    return super.handleEvent(event);
  }
}

HandleEvent is called but the final line returns an error when returning to the parent handleEvent function

Uncaught TypeError: Cannot read property 'call' of undefined
    at DrawController._this.handleEvent (DrawController.js:16)
    at EventRegistrar._emit (event-registrar.js:115)
    at EventRegistrar.handleEvent (event-registrar.js:87)
    at Manager.emit (hammer.js:2525)
    at TapRecognizer.emit (hammer.js:2130)
    at TapRecognizer.tryEmit (hammer.js:1572)
    at TapRecognizer.<anonymous> (hammer.js:2109)
    at boundFn (hammer.js:197)
@Pessimistress
Copy link
Collaborator

Pessimistress commented Dec 4, 2018

Can you make sure that MapController is imported directly from react-map-gl? https://uber.github.io/react-map-gl/#/Documentation/introduction/upgrade-guide

@guisers
Copy link

guisers commented Dec 4, 2018

I am having the same problem.

Seems that having an arrow function inside of a parent class does not allow children to use super when implementing the parent arrow function as an arrow function. On the other hand, implementing the parent arrow function as a function results in the child function not being called at all.

I think handleEvent must be changed to a function.

@tomrussell
Copy link
Author

@guisers I had tried implementing handleEvent in my controller as a function instead, in doing so it was never called

@guisers
Copy link

guisers commented Dec 5, 2018

Yes, what I mean is that the parent class MapController in react-map-gl needs this change. There doesn't appear to be anything we can do 😬

@Pessimistress
Copy link
Collaborator

Fix is published in 4.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants