router now properly handles poly changes

This commit is contained in:
Fedor Katurov 2018-08-16 15:39:54 +07:00
parent e477f50283
commit 245b559e2d
3 changed files with 40 additions and 4 deletions

View file

@ -3,24 +3,28 @@ import L from "leaflet";
const polyStyle = { color: '#ff3333', weight: '5' };
export class Poly {
constructor({ map }) {
constructor({ map, routerMoveStart }) {
this.poly = L.polyline([], polyStyle);
this.latlngs = [];
this.poly.addTo(map);
this.map = map;
this.routerMoveStart = routerMoveStart;
this.bindEvents();
}
updateMarks = () => {
const coords = this.poly.toGeoJSON().geometry.coordinates;
this.latlngs = (coords && coords.length && coords.map(([lng, lat]) => ({ lng, lat }))) || [];
this.routerMoveStart();
};
bindEvents = () => {
// Если на карте что-то меняется, пересчитать километражи
this.map.editTools.addEventListener('editable:drawing:mouseup', 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:new', this.updateMarks);