From 30197c7f150ab6875320183bad0894fe3842ec68 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 20 Jan 2020 12:44:12 +0700 Subject: [PATCH] current location button --- src/components/UserLocation.tsx | 103 +++++++++--------------------- src/map/CurrentLocation/index.tsx | 2 +- src/styles/panel.less | 4 ++ 3 files changed, 34 insertions(+), 75 deletions(-) diff --git a/src/components/UserLocation.tsx b/src/components/UserLocation.tsx index ecb501c..cc4a3af 100644 --- a/src/components/UserLocation.tsx +++ b/src/components/UserLocation.tsx @@ -1,81 +1,36 @@ -import React from 'react'; -// import { marker } from 'leaflet'; -// import { DomMarker } from '~/utils/DomMarker'; -// import { Icon } from '~/components/panels/Icon'; -// import { editor } from '~/modules/Editor'; +import React, { FC, useCallback } from 'react'; +import { IState } from '~/redux/store'; +import { selectUserLocation } from '~/redux/user/selectors'; +import { connect } from 'react-redux'; +import { Tooltip } from './panels/Tooltip'; +import { MainMap } from '~/constants/map'; -interface Props { +const mapStateToProps = (state: IState) => ({ + location: selectUserLocation(state), +}); -} +type Props = ReturnType & {}; -export class UserLocation extends React.Component { - render() { - return null - } - // constructor(props) { - // super(props); +const UserLocationUnconnected: FC = ({ location }) => { + const onClick = useCallback(() => { + if (!location) return; - // const element = document.createElement('div'); - // this.icon = new DomMarker({ element, className: 'location-marker' }); + MainMap.setView(location, 17); + }, [MainMap, location]); - // // this.map = editor.map.map; - // this.location = []; - // } + return ( +
+ Где я? - // icon; - // mark = null; - // map; - // location; + + + + + + + +
+ ); +}; - // componentDidMount() { - // this.getUserLocation(this.updateLocationMark); - // } - - // getUserLocation = callback => { - // // todo: TO SAGAS - // if (!window.navigator || !window.navigator.geolocation) return; - - // window.navigator.geolocation.getCurrentPosition(position => { - // if (!position || !position.coords || !position.coords.latitude || !position.coords.longitude) return; - - // const { latitude, longitude } = position.coords; - - // callback(latitude, longitude); - // }); - // }; - - // centerMapOnLocation = () => { - // if (this.location && this.location.length === 2) { - // this.panMapTo(this.location[0], this.location[1]); - // } else { - // this.getUserLocation(this.panMapTo); - // } - - // this.getUserLocation(this.updateLocationMark); - // }; - - // panMapTo = (latitude, longitude) => { - // if (!latitude || !longitude) return; - - // this.map.panTo([latitude, longitude]); - // }; - - // updateLocationMark = (latitude, longitude) => { - // if (!latitude || !longitude) return; - - // if (this.mark) this.map.removeLayer(this.mark); - - // this.location = [latitude, longitude]; - // this.mark = marker(this.location, { icon: this.icon }).addTo(this.map); - // }; - - // render() { - // return ( - //
- //
- // - //
- //
- // ); - // } -} +export const UserLocation = connect(mapStateToProps)(UserLocationUnconnected); diff --git a/src/map/CurrentLocation/index.tsx b/src/map/CurrentLocation/index.tsx index 663110b..745a8aa 100644 --- a/src/map/CurrentLocation/index.tsx +++ b/src/map/CurrentLocation/index.tsx @@ -22,7 +22,7 @@ const CurrentLocation: FC = ({ location }) => { - + `, }), diff --git a/src/styles/panel.less b/src/styles/panel.less index a2d6d9c..c787e50 100644 --- a/src/styles/panel.less +++ b/src/styles/panel.less @@ -720,3 +720,7 @@ } } } + +.location-bar { + width: 32px; +} \ No newline at end of file