fixed setting distance

This commit is contained in:
Fedor Katurov 2020-01-09 14:03:13 +07:00
parent c166eee586
commit 42dbfb0681
3 changed files with 16 additions and 12 deletions

View file

@ -2,7 +2,7 @@ import React, { FC, useEffect, memo, useState, useCallback } from 'react';
import { IMapRoute } from '../../../redux/map/types'; import { IMapRoute } from '../../../redux/map/types';
import { InteractivePoly } from '~/modules/InteractivePoly'; import { InteractivePoly } from '~/modules/InteractivePoly';
import { isMobile } from '~/utils/window'; import { isMobile } from '~/utils/window';
import { LatLng, Map } from 'leaflet'; import { LatLng, Map, LeafletEvent } from 'leaflet';
import { selectEditor } from '~/redux/editor/selectors'; import { selectEditor } from '~/redux/editor/selectors';
import pick from 'ramda/es/pick'; import pick from 'ramda/es/pick';
import * as MAP_ACTIONS from '~/redux/map/actions'; import * as MAP_ACTIONS from '~/redux/map/actions';
@ -10,6 +10,7 @@ import { connect } from 'react-redux';
import { selectMap } from '~/redux/map/selectors'; import { selectMap } from '~/redux/map/selectors';
import { MainMap } from '~/constants/map'; import { MainMap } from '~/constants/map';
import { MODES } from '~/constants/modes'; import { MODES } from '~/constants/modes';
import * as EDITOR_ACTIONS from '~/redux/editor/actions';
const mapStateToProps = state => ({ const mapStateToProps = state => ({
editor: pick(['mode', 'editing'], selectEditor(state)), editor: pick(['mode', 'editing'], selectEditor(state)),
@ -18,16 +19,20 @@ const mapStateToProps = state => ({
const mapDispatchToProps = { const mapDispatchToProps = {
mapSetRoute: MAP_ACTIONS.mapSetRoute, mapSetRoute: MAP_ACTIONS.mapSetRoute,
editorSetDistance: EDITOR_ACTIONS.editorSetDistance,
}; };
type Props = ReturnType<typeof mapStateToProps> & type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
typeof mapDispatchToProps & {
};
const RouteUnconnected: FC<Props> = memo( const RouteUnconnected: FC<Props> = memo(
({ map: { route }, editor: { editing, mode }, mapSetRoute }) => { ({ map: { route }, editor: { editing, mode }, mapSetRoute, editorSetDistance }) => {
const [layer, setLayer] = useState<InteractivePoly>(null); const [layer, setLayer] = useState<InteractivePoly>(null);
const onDistanceChange = useCallback(
({ distance }) => editorSetDistance(distance),
[editorSetDistance]
);
useEffect(() => { useEffect(() => {
if (!MainMap) return; if (!MainMap) return;
@ -37,12 +42,13 @@ const RouteUnconnected: FC<Props> = memo(
weight: 6, weight: 6,
maxMarkers: isMobile() ? 20 : 100, maxMarkers: isMobile() ? 20 : 100,
smoothFactor: 3, smoothFactor: 3,
}).addTo(MainMap) })
// .on("distancechange", console.log) .addTo(MainMap)
.on('distancechange', onDistanceChange)
// .on("allvertexhide", console.log) // .on("allvertexhide", console.log)
// .on("allvertexshow", console.log) // .on("allvertexshow", console.log)
); );
}, [MainMap]); }, [MainMap, onDistanceChange]);
const onRouteChanged = useCallback( const onRouteChanged = useCallback(
({ latlngs }) => { ({ latlngs }) => {

View file

@ -184,8 +184,6 @@ export class InteractivePoly extends Polyline {
this.startDrawing(); this.startDrawing();
}, },
stop: () => { stop: () => {
this.stopDragHinting();
this.is_drawing = false;
this.stopDrawing(); this.stopDrawing();
} }
}; };

View file

@ -30,7 +30,7 @@ const setDistance = (
{ distance }: ReturnType<typeof ACTIONS.editorSetDistance> { distance }: ReturnType<typeof ACTIONS.editorSetDistance>
): IEditorState => ({ ): IEditorState => ({
...state, ...state,
distance, distance: parseFloat(distance.toFixed(1)),
estimated: getEstimated(distance, state.speed), estimated: getEstimated(distance, state.speed),
}); });