1 - import 'mapbox-gl/dist/mapbox-gl.css';
2 - override css class called .mapboxgl-canvas
.mapboxgl-canvas {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
}
Answer from Javier on Stack OverflowVideos
1 - import 'mapbox-gl/dist/mapbox-gl.css';
2 - override css class called .mapboxgl-canvas
.mapboxgl-canvas {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
}
The warning is also displayed when using an older version of the Mapbox stylesheet as described here:
Adding the stylesheet like this doesn't fix the warning:
<!-- index.html --> <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.42.0/mapbox-gl.css' rel='stylesheet' />And importing in the app.js like this doesn't work either:
// app.js import 'mapbox-gl/dist/mapbox-gl.css';The way I found that fix this problem with the current version of the module is add the updated stylesheet:
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />
I was having the same issue and this fixed it.
» npm install @urbica/react-map-gl
» npm install react-mapbox-gl
this worked for me:
viewport: {
width: "fit",
...
},
<ReactMapGL
onViewportChange={nextViewport =>
this.setState({ viewport: { ...nextViewport, width: "fit" } })
}
...
>
Using react-map-gl version 5.2.3, the map would not render when I used width: '100%', height: '100%'.
Instead of percentage units, I was able to get it to work using "vw"/"vh" units like this: width: '100vw', height: '100vh'. This is the style of syntax currently shown in the docs examples from the react-map-gl repo.
The repo example uses the width/height props directly, but in the viewPort object it would look like:
viewPort: {
width: '100vw',
height: '100vh',
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
Hope that helps someone.
» npm install react-map-gl