I'm using ReactJS with NextJS.
Currently my leaflet fails to fill the whole parent div on my page, in fact it doesn't appear at all. I assumed the map would fill the entire parent div, maybe someone have an idea to handle the situation.
Here my leaflet snippet:
const Wrapper= styled.div`
width:${props => props.width};
height:${props => props.height};
`;
const location= [34.0522, -118.2457]
export default class Map extends Component{
componentDidMount(){
// Map = require('react-leaflet').Map
// Marker = require('react-leaflet').Marker
// Popup = require('react-leaflet').Popup
// TileLayer = require('react-leaflet').TileLayer
// Tooltip = require('react-leaflet').Tooltip
// this.setState({ showMap: true })
this.map= L.map("map", {
center:location,
zoom:12,
zoomControl:true
})
L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
maxZoom: 20,
attribution: '© Openstreetmap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
})
.addTo(this.map)
var marker = L.marker(location ,{icon: placeholder}).addTo(this.map);
setTimeout( ()=> {
marker.bindPopup("Come see us, it would be awesome!", {maxWidth: "500"});
this.map.setView(location);
}
render(){
return (
<Fragment>
<Head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/images/marker-icon-2x.png"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/images/marker-icon.png"/>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"
integrity="yyyy"
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
integrity="yyyyy"
crossorigin=""></script>
</Head>
<Wrapper width="100%" height="100%" id="map"/>
</Fragment>
)
}
}
any hint would be great, thanks