visgl/react-map-gl

[Bug] Library rendering error react-map-gl

daviAlves16 opened this issue · 1 comments

Description

In react, I defined a default size for the map, but when it renders, the component is the right size, the zoom buttons are all right, but the map image itself starts with a default size of 300 by 400px, and not with what I defined. only after I enlarged the screen a bit, the image goes to the defined size. how to solve this? it does not define the size of the parent div.

import Map, {FullscreenControl, GeolocateControl, Marker, Source, Layer, NavigationControl} from "react-map-gl"
import 'mapbox-gl/dist/mapbox-gl.css'

const [viewport, setViewport] = useState({
        latitude: -6.771433,
        longitude: -43.024926,
        zoom: 4,
 });
 <div className='mb-5 mb-xl-8' style={{width: "100%", height: "45rem"}}>
  <Map
        {...viewport}
        ref={mapRef}
        mapLib={import('mapbox-gl')}
        onMove={evt => setViewport(evt.viewState)}
        mapboxAccessToken={TOKEN}
        mapStyle={myStyle}
        style={{width: "100%", height: "45rem"}}
  >    
        <NavigationControl />
        <GeolocateControl />
        <FullscreenControl />    
  </Map>
</div>

Captura de tela de 2023-09-08 12-25-14

Expected Behavior

Captura de tela de 2023-09-08 12-25-30

Steps to Reproduce

import Map, {FullscreenControl, GeolocateControl, Marker, Source, Layer, NavigationControl} from "react-map-gl"
import 'mapbox-gl/dist/mapbox-gl.css'

const [viewport, setViewport] = useState({
        latitude: -6.771433,
        longitude: -43.024926,
        zoom: 4,
 });
return (
 <div className='mb-5 mb-xl-8' style={{width: "100%", height: "45rem"}}>
  <Map
        {...viewport}
        ref={mapRef}
        mapLib={import('mapbox-gl')}
        onMove={evt => setViewport(evt.viewState)}
        mapboxAccessToken={TOKEN}
        mapStyle={myStyle}
        style={{width: "100%", height: "45rem"}}
  >    
        <NavigationControl />
        <GeolocateControl />
        <FullscreenControl />    
  </Map>
</div>);

Environment

  • Framework version: 7.1.4 até a ultima lançada
  • Map library: react-map-gl
  • Browser: Google Chrome
  • OS: Linux Mint

Logs

No response

Please provide the version numbers and create a CodeSandbox.