mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
router now properly handles poly changes
This commit is contained in:
parent
e477f50283
commit
245b559e2d
3 changed files with 40 additions and 4 deletions
|
@ -12,9 +12,9 @@ export class Editor {
|
||||||
}) {
|
}) {
|
||||||
this.map = new Map({ container });
|
this.map = new Map({ container });
|
||||||
|
|
||||||
const { lockMapClicks, map: { map } } = this;
|
const { lockMapClicks, routerMoveStart, map: { map } } = this;
|
||||||
|
|
||||||
this.poly = new Poly({ map: this.map.map });
|
this.poly = new Poly({ map, routerMoveStart });
|
||||||
this.stickers = new Stickers({ map, lockMapClicks });
|
this.stickers = new Stickers({ map, lockMapClicks });
|
||||||
this.router = new Router({ map, lockMapClicks });
|
this.router = new Router({ map, lockMapClicks });
|
||||||
|
|
||||||
|
@ -88,4 +88,10 @@ export class Editor {
|
||||||
|
|
||||||
this.router.startFrom(latlngs.pop());
|
this.router.startFrom(latlngs.pop());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
routerMoveStart = () => {
|
||||||
|
const { _latlngs } = this.poly.poly;
|
||||||
|
|
||||||
|
if (_latlngs) this.router.moveStart(_latlngs[_latlngs.length-1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,24 +3,28 @@ import L from "leaflet";
|
||||||
const polyStyle = { color: '#ff3333', weight: '5' };
|
const polyStyle = { color: '#ff3333', weight: '5' };
|
||||||
|
|
||||||
export class Poly {
|
export class Poly {
|
||||||
constructor({ map }) {
|
constructor({ map, routerMoveStart }) {
|
||||||
this.poly = L.polyline([], polyStyle);
|
this.poly = L.polyline([], polyStyle);
|
||||||
this.latlngs = [];
|
this.latlngs = [];
|
||||||
this.poly.addTo(map);
|
this.poly.addTo(map);
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
|
||||||
|
this.routerMoveStart = routerMoveStart;
|
||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMarks = () => {
|
updateMarks = () => {
|
||||||
const coords = this.poly.toGeoJSON().geometry.coordinates;
|
const coords = this.poly.toGeoJSON().geometry.coordinates;
|
||||||
this.latlngs = (coords && coords.length && coords.map(([lng, lat]) => ({ lng, lat }))) || [];
|
this.latlngs = (coords && coords.length && coords.map(([lng, lat]) => ({ lng, lat }))) || [];
|
||||||
|
|
||||||
|
this.routerMoveStart();
|
||||||
};
|
};
|
||||||
|
|
||||||
bindEvents = () => {
|
bindEvents = () => {
|
||||||
// Если на карте что-то меняется, пересчитать километражи
|
// Если на карте что-то меняется, пересчитать километражи
|
||||||
this.map.editTools.addEventListener('editable:drawing:mouseup', this.updateMarks);
|
this.map.editTools.addEventListener('editable:drawing:mouseup', this.updateMarks);
|
||||||
this.map.editTools.addEventListener('editable:vertex:dragend', this.updateMarks);
|
this.map.editTools.addEventListener('editable:vertex:dragend', this.updateMarks);
|
||||||
|
this.map.editTools.addEventListener('editable:vertex:mouseup', this.updateMarks);
|
||||||
this.map.editTools.addEventListener('editable:vertex:deleted', this.updateMarks);
|
this.map.editTools.addEventListener('editable:vertex:deleted', this.updateMarks);
|
||||||
this.map.editTools.addEventListener('editable:vertex:new', this.updateMarks);
|
this.map.editTools.addEventListener('editable:vertex:new', this.updateMarks);
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,32 @@ export class Router {
|
||||||
};
|
};
|
||||||
|
|
||||||
startFrom = latlngs => {
|
startFrom = latlngs => {
|
||||||
this.router.setWaypoints([{ ...latlngs }]);
|
const waypoints = this.router.getWaypoints();
|
||||||
|
|
||||||
|
if (waypoints && waypoints.length) {
|
||||||
|
waypoints[0] = { ...latlngs };
|
||||||
|
this.router.setWaypoints(waypoints);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.router.setWaypoints([{ ...latlngs }]);
|
||||||
|
};
|
||||||
|
|
||||||
|
moveStart = latlng => {
|
||||||
|
const waypoints = this.router.getWaypoints();
|
||||||
|
const { latLng } = (waypoints[0] || {});
|
||||||
|
|
||||||
|
if (!latLng || !latlng) return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
latlng.lat.toFixed(5) === latLng.lat.toFixed(5) &&
|
||||||
|
latlng.lng.toFixed(5) === latLng.lng.toFixed(5)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
waypoints[0] = { ...latlng };
|
||||||
|
|
||||||
|
this.router.setWaypoints(waypoints);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue