mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-05-09 18:06:40 +07:00
Arrows layer
This commit is contained in:
parent
69d1d749cf
commit
de2b747a20
11 changed files with 57 additions and 58 deletions
35
src/map/Arrows/index.tsx
Normal file
35
src/map/Arrows/index.tsx
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { FC, memo, useState, useEffect } from 'react';
|
||||
import { MainMap } from '~/constants/map';
|
||||
import { connect } from 'react-redux';
|
||||
import { IState } from '~/redux/store';
|
||||
import { selectMapRoute } from '~/redux/map/selectors';
|
||||
import { ArrowsLayer } from '~/utils/map/ArrowsLayer';
|
||||
|
||||
const mapStateToProps = (state: IState) => ({
|
||||
route: selectMapRoute(state),
|
||||
});
|
||||
|
||||
const mapDispatchToProps = {};
|
||||
|
||||
type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||
|
||||
const ArrowsUnconnected: FC<Props> = memo(({ route }) => {
|
||||
const [layer, setLayer] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const item = new ArrowsLayer({}).addTo(MainMap);
|
||||
setLayer(item);
|
||||
return () => MainMap.removeLayer(item);
|
||||
}, [MainMap]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!layer) return
|
||||
|
||||
layer.setLatLngs(route);
|
||||
}, [layer, route])
|
||||
return null;
|
||||
});
|
||||
|
||||
const Arrows = connect(mapStateToProps, mapDispatchToProps)(ArrowsUnconnected);
|
||||
|
||||
export { Arrows };
|
Loading…
Add table
Add a link
Reference in a new issue