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

Make "Missing Mapbox GL JS CSS" a console warning #5786

Closed
jfirebaugh opened this issue Dec 1, 2017 · 3 comments
Closed

Make "Missing Mapbox GL JS CSS" a console warning #5786

jfirebaugh opened this issue Dec 1, 2017 · 3 comments
Labels

Comments

@jfirebaugh
Copy link
Contributor

Putting "Missing Mapbox GL JS CSS" in the DOM has confused at least one user (#5785) and causes other issues (#5359 (comment)).

Instead, it should be a console warning that's logged when a map is created and there's no CSS rule targeting .mapboxgl-map present. This can be checked using CSSOM APIs.

@rtwalz
Copy link

rtwalz commented Mar 6, 2018

For now the workaround I'm using is adding display: none to the class mapboxgl-missing-css

@stevage
Copy link
Contributor

stevage commented May 14, 2018

Just encountered another confused user. (He told me that "the CSS isn't loading", on the strength of that DOM element.) Another possible solution would be deleting the DOM element once the CSS has indeed loaded.

@jczaplew
Copy link
Contributor

FWIW, the CSSOM APIs only function as expected with cross-loaded CSS resources when the attribute crossorigin="anonymous" is added to the <link>.

If you load the CSS as most people do, with <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.css' rel='stylesheet' />, the rules of the stylesheet are not available via document.styleSheets. I'm uncertain as to whether this is a chromium bug or feature, but you could hack around this by making an additional request for all stylesheets that do not contain a rules or cssRules attribute, but that seems like a heavy-handed solution for a fairly small problem.

In the absence of a better solution, simply checking the computed style of .mapboxgl-map might suffice. Something like

let mapboxglMap = document.querySelector('.mapboxgl-map')
if (!mapboxglMap || window.getComputedStyle(mapboxglMap).overflow != 'hidden') {
    // CSS error
}

The nasty bit is that it depends on a hardcoded CSS value that could change in the future. Thoughts as to whether this might be an appropriate method of checking if the CSS has loaded?

@lbud lbud closed this as completed in #6261 Jun 8, 2018
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

5 participants