mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-28 12:36:41 +07:00
dist and time
finishing route
This commit is contained in:
parent
102328a1b2
commit
b8545105c8
15 changed files with 195 additions and 37 deletions
|
@ -2,9 +2,16 @@ import L from 'leaflet';
|
|||
import Routing from 'leaflet-routing-machine/src/index';
|
||||
import { CONFIG } from '$config';
|
||||
import { DomMarker } from '$utils/DomMarker';
|
||||
import { MODES } from '$constants/modes';
|
||||
|
||||
export class Router {
|
||||
constructor({ map, lockMapClicks, setRouterPoints }) {
|
||||
constructor({ map, lockMapClicks, setRouterPoints, changeMode, pushPolyPoints }) {
|
||||
this.waypoints = [];
|
||||
this.lockMapClicks = lockMapClicks;
|
||||
this.setRouterPoints = setRouterPoints;
|
||||
this.changeMode = changeMode;
|
||||
this.pushPolyPoints = pushPolyPoints;
|
||||
|
||||
const routeLine = r => Routing.line(r, {
|
||||
styles: [
|
||||
{ color: 'white', opacity: 0.8, weight: 6 },
|
||||
|
@ -36,9 +43,6 @@ export class Router {
|
|||
|
||||
this.router.addTo(map);
|
||||
|
||||
this.waypoints = [];
|
||||
this.lockMapClicks = lockMapClicks;
|
||||
this.setRouterPoints = setRouterPoints;
|
||||
// this.router._line.on('mousedown', console.log);
|
||||
}
|
||||
//
|
||||
|
@ -109,5 +113,20 @@ export class Router {
|
|||
updateWaypointsCount = () => {
|
||||
const waypoints = this.router.getWaypoints().filter(({ latLng }) => !!latLng);
|
||||
this.setRouterPoints(waypoints.length);
|
||||
}
|
||||
};
|
||||
|
||||
cancelDrawing = () => {
|
||||
this.router.setWaypoints([]);
|
||||
this.changeMode(MODES.NONE);
|
||||
};
|
||||
|
||||
submitDrawing = () => {
|
||||
const [route] = this.router._routes;
|
||||
if (!route) return;
|
||||
|
||||
const { coordinates, summary: { totalDistance } } = route;
|
||||
this.pushPolyPoints(coordinates);
|
||||
this.router.setWaypoints([]);
|
||||
this.changeMode(MODES.POLY);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue