From 807bea9ec2ebc49921a8d45c6873497c2825d173 Mon Sep 17 00:00:00 2001 From: muerwre Date: Thu, 7 Feb 2019 10:48:25 +0700 Subject: [PATCH] fixed drawing polyline --- src/index.js | 2 ++ src/modules/NewPoly.js | 58 +++-------------------------------- src/utils/EditablePolyline.js | 11 +++++-- 3 files changed, 15 insertions(+), 56 deletions(-) diff --git a/src/index.js b/src/index.js index 5af3f3f..fae4755 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,11 @@ ## BUGS + todo fix arrows (can't reproduce now :-( ) todo clear routing on editing cancellation todo cancelling editing someone's else map return back to it's original address /razminochnyj/ todo selecting logo on crop + todo delete sticker icon ## FEATURES diff --git a/src/modules/NewPoly.js b/src/modules/NewPoly.js index d2928aa..caa2b1f 100644 --- a/src/modules/NewPoly.js +++ b/src/modules/NewPoly.js @@ -57,7 +57,7 @@ export class NewPoly { if (!latlngs || latlngs.length <= 1) return; - latlngs.map((latlng, i) => { + latlngs.forEach((latlng, i) => { if (i === 0) return; const mid = middleCoord(latlngs[i], latlngs[i - 1]); @@ -70,14 +70,14 @@ export class NewPoly { latlngs[i - 1], [mid.lat, mid.lng] ], - { color: 'none', weight: CLIENT.STROKE_WIDTH } + { color: 'blue', weight: CLIENT.STROKE_WIDTH } ).addTo(this.arrows); slide._path.setAttribute('marker-end', 'url(#long-arrow)'); }); }; - updateMarks = (e, callee) => { + updateMarks = () => { // return; const coords = this.poly.toGeoJSON().geometry.coordinates; @@ -103,52 +103,8 @@ export class NewPoly { if (mode === MODES.NONE) this.editor.setMode(MODES.POLY); }; - 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); - // this.map.editTools.addEventListener('editable:vertex:click', this.preventMissClicks); - - // this.map.editTools.addEventListener('editable:vertex:dragstart', this.lockMap); - // this.map.editTools.addEventListener('editable:vertex:dragstart', this.clearArrows); - - // После удаления точки - продолжить рисование - // this.map.editTools.addEventListener('editable:vertex:deleted', this.continueForward); - // - // map.editTools.addEventListener('editable:vertex:dragend', e => writeReduxData({ e, updatePolyCoords })); - // map.editTools.addEventListener('editable:vertex:new', e => writeReduxData({ e, updatePolyCoords })); - // map.editTools.addEventListener('editable:vertex:deleted', e => writeReduxData({ e, updatePolyCoords })); - - // Продолжить рисование после удаления точки - // map.editTools.addEventListener('editable:vertex:deleted', e => { - // poly.editor.continueForward(); - // updateMarks(); - // }); - - // Добавлять точек в полилинию по щелчку - // map.editTools.addEventListener('editable:drawing:click', e => insertVertex({ e, updatePolyCoords })); - // map.editTools.addEventListener('editable:drawing:clicked', () => updateMarks({ updatePolyCoords })); - - // Это для точек. При перетаскивании конца указателя тащим точку - // map.editTools.addEventListener('editable:vertex:drag', on_vertex_drag); - - // при перетаскивании ручек убирать все отметки километров - // map.editTools.addEventListener('editable:vertex:dragstart', clearKmMarks); - }; - continue = () => { this.poly.editor.continueForward(); - // if (this.latlngs && this.latlngs.length) { - // // this.poly.enableEdit().continueForward(); - // // this.poly.editor.reset(); - // this.poly.continueForward(); - // } else { - // // this.poly = this.map.editTools.startPolyline(); - // // this.poly.setStyle(polyStyle); - // } }; stop = () => { @@ -166,8 +122,6 @@ export class NewPoly { setPoints = latlngs => { if (!latlngs || latlngs.length <= 1) return; this.poly.setPoints(latlngs); - // this.poly._reloadPolyline(); - // this.updateMarks(); }; pushPoints = latlngs => { @@ -186,9 +140,8 @@ export class NewPoly { clearAll = () => { this.poly.setLatLngs([]); - // this.poly.disableEdit(); - - // this.updateMarks(); + this.poly.editor.reset(); + this.updateMarks(); }; clearArrows = () => this.arrows.clearLayers(); @@ -199,7 +152,6 @@ export class NewPoly { return ( this.poly && this.poly.getLatLngs().length && this.poly.getLatLngs().map(el => ({ ...el }))) || []; - } get isEmpty() { diff --git a/src/utils/EditablePolyline.js b/src/utils/EditablePolyline.js index 5c78a55..4d48ca5 100644 --- a/src/utils/EditablePolyline.js +++ b/src/utils/EditablePolyline.js @@ -453,14 +453,18 @@ L.Polyline.polylineEditor = L.Polyline.extend({ // User-defined custom event listeners: if (that._options.customPointListeners) { - for (let eventName in that._options.customPointListeners) { marker.on(eventName, that._options.customPointListeners[eventName]); } + for (let eventName in that._options.customPointListeners) { + marker.on(eventName, that._options.customPointListeners[eventName]); + } } if (that._options.customNewPointListeners) { - for (let eventName in that._options.customNewPointListeners) { newPointMarker.on(eventName, that._options.customNewPointListeners[eventName]); } + for (let eventName in that._options.customNewPointListeners) { + newPointMarker.on(eventName, that._options.customNewPointListeners[eventName]); + } } // exit if its first marker - if (!this._markers || this._markers.length <= 0) { + if (!this._markers || this._markers.length === 0 || points.length === 0) { this._markers.push(marker); return marker; } @@ -556,6 +560,7 @@ L.Polyline.polylineEditor = L.Polyline.extend({ this._addFirstPoint = event => { this._addMarkers(0, event.latlng, true); + this._map.setEditablePolylinesEnabled(true); this._reloadPolyline(); this._map.off('click', this._addFirstPoint);