mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.06k stars 2.21k forks source link

Don't require external CSS to show attribution #9353

Open sansumbrella opened 4 years ago

sansumbrella commented 4 years ago

Motivation

Correctly attributing Mapbox on a map should be the easy default when using the gl-js library.

Currently, application developers must add a line of code in order to add attribution to their maps. This is easily forgotten in an HTML page, and a bit tricky to figure out how to do when using a bundler like Webpack. This makes it harder to correctly attribute Mapbox than it is to leave off attribution.

Design Alternatives

Require application code to remove attribution.

Current state

With external CSS loaded (attribution appears correctly): pink map of the US with yellow heatmap and attribution across the bottom

Without external CSS loaded (no attribution): pink map of the US with yellow heatmap

HTML pages must source the correct (matching) version of CSS to add attribution, e.g.: <link href="https://api.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.css" rel="stylesheet" />

Bundled applications can source the CSS from their node_modules folder and importing it close to where they use Mapbox, e.g.: import 'mapbox-gl/dist/mapbox-gl.css';

mourner commented 4 years ago

Note that adding mapbox-gl.css alongside mapbox-gl.js is required for correct operation of the map in general — otherwise many features won't work, not just attribution: all the controls (buttons, compass, scale control, search etc.), cursors, interactions like shift-drag-zoom, HTML markers and popups, etc.

Currently, if you don't include CSS, there will be a warning about it in the developer console. We don't want to support CSS-less GL JS usage at all, so moving attribution support to JS is not a good option. Would you rather suggest disabling the map completely in this case?

andrewharvey commented 4 years ago

I agree with @mourner here, the css is required, and don't think we should try and support a CSS-less GL JS. I think the current console warning is enough.