I am currently working on a project using ReactJS and NextJS.
One issue I am facing is that my leaflet map is not filling the entire parent div on my page, and it is not showing up at all. I had expected the map to automatically adjust to the parent div size, but it seems that is not the case. Does anyone have any suggestions on how to resolve this issue?
Below is the snippet of my leaflet code:
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() {
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/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="254940444349405165140b110b15">[email protected]</a>/dist/leaflet.css"
integrity="yyyy"
crossorigin=""/>
<script src="https://unpkg.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d21282c2b2128390d7c6379637d">[email protected]</a>/dist/leaflet.js"
integrity="yyyyy"
crossorigin=""></script>
</Head>
<Wrapper width="100%" height="100%" id="map"/>
</Fragment>
)
}
}
Any help or hint would be greatly appreciated, Thank you