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

error when accessing style in a control's onRemove #7478

Closed
ansis opened this issue Oct 24, 2018 · 0 comments · Fixed by #7479
Closed

error when accessing style in a control's onRemove #7478

ansis opened this issue Oct 24, 2018 · 0 comments · Fixed by #7479
Labels

Comments

@ansis
Copy link
Contributor

ansis commented Oct 24, 2018

If a map control calls a method that accesses the style in onRemove then an error is thrown and the map removal fails.

This is heavily related to #7477. Fixing it would fix the error here but we might want to move removing the controls to before the setStyle(null) here so that the onRemove has access to the style:

mapbox-gl-js/src/ui/map.js

Lines 1672 to 1679 in 42d1a5a

this.setStyle(null);
if (typeof window !== 'undefined') {
window.removeEventListener('resize', this._onWindowResize, false);
window.removeEventListener('online', this._onWindowOnline, false);
}
for (const control of this._controls) control.onRemove(this);
this._controls = [];

mapbox-gl-js version: master

browser: all

Steps to Trigger Behavior

  1. create a control
  2. call a method that accesses the style in onRemove, for example map.getLayer("background")

Link to Demonstration

https://jsbin.com/tarecanedo/1/edit?html,output

Expected Behavior

Either:

  • gets called before the style is destroyed and it returns the actual layer
  • gets called after style is destroyed and it returns nothing
  • gets called after the style is destroyed and triggers error event but not exception

Actual Behavior

Uncaught TypeError: Cannot read property 'getLayer' of undefined and map fails to remove.

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

Successfully merging a pull request may close this issue.

1 participant