Moving the underlying map out of the slippy component and handling window resize events.
This commit is contained in:
1 parent
2207ae1652
commit
75b4bb2e2b
9 files changed
+184
-113
No files matched your search
@@ -0,0 +1,109 @@
|
||||
import react, { useMemo, useEffect } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import _ from 'lodash';
|
||||
import { MapState, mapActions } from '../../store/map';
|
||||
|
||||
const Map: react.FC<{}> = (props: {}) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const mapState = useSelector((state: { map: MapState }) => state.map);
|
||||
|
||||
console.log(`mapState: ${JSON.stringify(mapState)}`);
|
||||
|
||||
const resizeHandler = () => {
|
||||
dispatch(mapActions.resize());
|
||||
};
|
||||
const debouncedResizeHandler = useMemo(
|
||||
() => _.debounce(resizeHandler, 500),
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('resize', debouncedResizeHandler);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ height: '256px' }}>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11720/10052.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11721/10052.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11722/10052.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11723/10052.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ height: '256px' }}>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11720/10053.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11721/10053.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11722/10053.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11723/10053.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ height: '256px' }}>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11720/10054.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11721/10054.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11722/10054.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
<img
|
||||
alt=''
|
||||
role='presentation'
|
||||
src='https://tile.openstreetmap.org/14/11723/10054.png'
|
||||
style={{ width: '256px', height: '256px', opacity: 1 }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Map;
|
||||
Reference in new issue
Block a user