Please make sure to check the following boxes before submitting an issue. Thanks!
Modifying the height and width props on the element correctly updates the size of the map and the appropriate tiles get loaded in. For example, when programmatically setting the map to be larger, new tiles should be fetched to fill in the newly visible area.
Modifying the height and width props on the element correctly updates the size of the map, but new tiles are not being loaded until the browser window is physically resized. The missing tiles are simply grey. After searching around, it looks like map.invalidateSize() must be called anytime the height and width are modified. I searched the react-leaflet code and it looks like invalidateSize() is never being called.
This is out of the scope of this library, it's up to your application to handle this.
@PaulLeCam I feel that since react-leaflet is trying to wrap leaflet in a react way, it should update (and do what needs to be done internally) on props change, including dimensions. We should probably not have to touch the leaflet internals for this.
This is out of the scope of this library, it's up to your application to handle this.
:-1: 1
I need to express my discontent with this. I second @borisrorsvort opinion that this is indeed a responsibility of this library. Maybe not the whole React community shares these design principles, but I'm 100% sure I'm not alone in thinking that using refs is an anti-pattern. React components should try as much as possible to maintain the declarative philosophy of React.
after dragging for while height and width of map automatically changing.why so?
I just found this and implemented a solution here: https://github.com/PaulLeCam/react-leaflet/pull/147#issuecomment-527939233
The important bit beeing the usage of ref and 'react-resize-detector':
import { withResizeDetector } from 'react-resize-detector'
...
const MyMap = (...) => {
// NOTE: this is using the internal leaflet element to update the size
const mapRef = useRef()
useEffect(() => {
mapRef.current.leafletElement.invalidateSize()
}, [width, height])
return (
<Map
ref={mapRef}
height={height}
width={width}
...
>
)
}
export default withResizeDetector(MyMap)
Most helpful comment
@PaulLeCam I feel that since react-leaflet is trying to wrap leaflet in a react way, it should update (and do what needs to be done internally) on props change, including dimensions. We should probably not have to touch the leaflet internals for this.