I am trying to load a Mapbox map. However the map loads but not showing.
I have tried the exact same code in a blank pure html page and a blank react.js template and the map functions properly.
Component did mount:
Render:
<div id="map_test" style={{width: "100%", height: "100%"}}></div>
ComponentDidMount:
mapboxgl.accessToken = <MY-TOKEN>
var map = new mapboxgl.Map({
container: 'map_test',
style: 'mapbox://styles/mapbox/streets-v11'
})
index.html (in the head tag):
<script src='https://api.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.css' rel='stylesheet' />
And that’s the result of the map:
Note I have tried to load the map using CDN and either using npm package, both didn’t work.