Do I have to import leaflet's CSS file?

2019-08-14 03:38发布

问题:

I'm using Node / React / Webpack with leaflet. I installed leaflet using npm and in my map component I import 'leaflet'; which works fine for the js.

However, the map does not look correct due to the css not working correctly, however images stored in the leaflet/dist/images seem to work fine. In order to get the css to work I have to also import 'leaflet/dist/leaflet.css' but it feels to me like I shouldn't have to and that it should be included with the first import statement?

回答1:

Yes you have to have, see this link might be useful:

leaflet-css webpack require

I omitted its css in an ionic project but coppied a few necessary lines to avoid broken map ui.