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

some of Popup methods don't work because of this._container being undefined #9429

Closed
miszekb opened this issue Mar 17, 2020 · 4 comments · Fixed by #9433
Closed

some of Popup methods don't work because of this._container being undefined #9429

miszekb opened this issue Mar 17, 2020 · 4 comments · Fixed by #9433
Assignees

Comments

@miszekb
Copy link

miszekb commented Mar 17, 2020

Some of Popup class methods doesn't work as expected:

  • addClassName
  • removeClassName
  • toggleClassName
  • getMaxWidth
  • getElement

That's how I'm initializing popup:
let popup = new mapboxgl.Popup().setText("Hello World");

And this is a code that fails:
popup.addClassName('my-class');

but it works when in the first place I add a popup to map using 'addTo()' and set coordinates using 'setLngLat()' method. In any other case methods mentioned in the list above throw this error:

TypeError: this._container is undefined popup.js:359:8
addClassName popup.js:359
test.html:30

mapbox GL JS version: https://api.mapbox.com/mapbox-gl-js/v1.8.1/mapbox-gl.js

It happens on every browser.

@ryanhamley
Copy link
Contributor

This was caused by those methods trying to access the popup's container element before it's created. I added checks so that the errors won't throw if the container is undefined, but these methods won't do anything if they're called before addTo or setLngLat.

@miszekb
Copy link
Author

miszekb commented Mar 18, 2020

Thank you for quick response :)

@ryanhamley
Copy link
Contributor

No problem! This will be in release 1.9.0 which will be published today or tomorrow

@EduardoMarques-TomTom
Copy link

Would it be possible to have the container created in the constructor so that these methods do something before addTo or setLngLat?
Maybe there's a reason that I'm not aware, but I think it will be confusing for developers using a method that does nothing.

If my suggestion is not possible, perhaps instead of throwing error you could use a warning message.

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

Successfully merging a pull request may close this issue.

4 participants