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

Styling is automatically imported but documentation says otherwise #1581

Closed
iamdriz opened this issue Sep 21, 2021 · 1 comment
Closed

Styling is automatically imported but documentation says otherwise #1581

iamdriz opened this issue Sep 21, 2021 · 1 comment
Labels

Comments

@iamdriz
Copy link

iamdriz commented Sep 21, 2021

Description

According to the Documentation here: http://visgl.github.io/react-map-gl/docs/get-started/get-started#styling

The CSS should be included like so: import 'mapbox-gl/dist/mapbox-gl.css'; This would also allow you to easily opt-out of the standard CSS or overwrite it.

However what happens is that the CSS is included without having to do this... looking at the developer tools it's being imported from https://api.tiles.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.css.

Why is this happening, if the Documentation states it must be manually imported? And how can I stop this if I wanted to stop it from being imported (e.g. loading a custom localized one).

@iamdriz iamdriz added the bug label Sep 21, 2021
@Pessimistress
Copy link
Collaborator

It is recommended that you import the stylesheet yourself. When a map is rendered, we check if a stylesheet exists:

const testElement = document.createElement('div');
testElement.className = 'mapboxgl-map';
testElement.style.display = 'none';
document.body.appendChild(testElement);
const isCssLoaded = window.getComputedStyle(testElement).position !== 'static';

If not then a default one is attached automatically.

Why is this happening

There were too many complaints from users who failed to include the stylesheet in their apps and the components didn't work.

And how can I stop this if I wanted to stop it from being imported

Your custom stylesheet should contain an entry of .mapboxgl-map to pass the above test. If you are using maplibre see #1513.

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

2 participants