From 42dbfb06810648385b8b4e7c196edd51f6b5c987 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Thu, 9 Jan 2020 14:03:13 +0700 Subject: [PATCH] fixed setting distance --- src/containers/map/Route/index.tsx | 24 +++++++++++++++--------- src/modules/InteractivePoly.ts | 2 -- src/redux/editor/handlers.ts | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/containers/map/Route/index.tsx b/src/containers/map/Route/index.tsx index 6214680..383a37e 100644 --- a/src/containers/map/Route/index.tsx +++ b/src/containers/map/Route/index.tsx @@ -2,7 +2,7 @@ import React, { FC, useEffect, memo, useState, useCallback } from 'react'; import { IMapRoute } from '../../../redux/map/types'; import { InteractivePoly } from '~/modules/InteractivePoly'; import { isMobile } from '~/utils/window'; -import { LatLng, Map } from 'leaflet'; +import { LatLng, Map, LeafletEvent } from 'leaflet'; import { selectEditor } from '~/redux/editor/selectors'; import pick from 'ramda/es/pick'; import * as MAP_ACTIONS from '~/redux/map/actions'; @@ -10,6 +10,7 @@ import { connect } from 'react-redux'; import { selectMap } from '~/redux/map/selectors'; import { MainMap } from '~/constants/map'; import { MODES } from '~/constants/modes'; +import * as EDITOR_ACTIONS from '~/redux/editor/actions'; const mapStateToProps = state => ({ editor: pick(['mode', 'editing'], selectEditor(state)), @@ -18,16 +19,20 @@ const mapStateToProps = state => ({ const mapDispatchToProps = { mapSetRoute: MAP_ACTIONS.mapSetRoute, + editorSetDistance: EDITOR_ACTIONS.editorSetDistance, }; -type Props = ReturnType & - typeof mapDispatchToProps & { - }; +type Props = ReturnType & typeof mapDispatchToProps & {}; const RouteUnconnected: FC = memo( - ({ map: { route }, editor: { editing, mode }, mapSetRoute }) => { + ({ map: { route }, editor: { editing, mode }, mapSetRoute, editorSetDistance }) => { const [layer, setLayer] = useState(null); + const onDistanceChange = useCallback( + ({ distance }) => editorSetDistance(distance), + [editorSetDistance] + ); + useEffect(() => { if (!MainMap) return; @@ -37,12 +42,13 @@ const RouteUnconnected: FC = memo( weight: 6, maxMarkers: isMobile() ? 20 : 100, smoothFactor: 3, - }).addTo(MainMap) - // .on("distancechange", console.log) + }) + .addTo(MainMap) + .on('distancechange', onDistanceChange) // .on("allvertexhide", console.log) // .on("allvertexshow", console.log) ); - }, [MainMap]); + }, [MainMap, onDistanceChange]); const onRouteChanged = useCallback( ({ latlngs }) => { @@ -80,7 +86,7 @@ const RouteUnconnected: FC = memo( useEffect(() => { if (!layer) return; - + if (mode === MODES.POLY && !layer.is_drawing) { layer.editor.continue(); } diff --git a/src/modules/InteractivePoly.ts b/src/modules/InteractivePoly.ts index 03cb8e0..0c6e064 100644 --- a/src/modules/InteractivePoly.ts +++ b/src/modules/InteractivePoly.ts @@ -184,8 +184,6 @@ export class InteractivePoly extends Polyline { this.startDrawing(); }, stop: () => { - this.stopDragHinting(); - this.is_drawing = false; this.stopDrawing(); } }; diff --git a/src/redux/editor/handlers.ts b/src/redux/editor/handlers.ts index 17257a1..78c22a8 100644 --- a/src/redux/editor/handlers.ts +++ b/src/redux/editor/handlers.ts @@ -30,7 +30,7 @@ const setDistance = ( { distance }: ReturnType ): IEditorState => ({ ...state, - distance, + distance: parseFloat(distance.toFixed(1)), estimated: getEstimated(distance, state.speed), });