Пример #1
0
 onVertexMarkerClick: function (e) {
     L.Editable.makeCancellable(e);
     this.fireAndForward('editable:vertex:click', e);
     if (e._cancelled) return;
     if (this.tools.drawing() && this.tools._drawingEditor !== this) return;
     var index = e.vertex.getIndex(), commit;
     if (e.originalEvent.ctrlKey) {
         this.onVertexMarkerCtrlClick(e);
     } else if (e.originalEvent.altKey) {
         this.onVertexMarkerAltClick(e);
     } else if (e.originalEvent.shiftKey) {
         this.onVertexMarkerShiftClick(e);
     } else if (e.originalEvent.metaKey) {
         this.onVertexMarkerMetaKeyClick(e);
     } else if (index === e.vertex.getLastIndex() && this._drawing === L.Editable.FORWARD) {
         if (index >= this.MIN_VERTEX - 1) commit = true;
     } else if (index === 0 && this._drawing === L.Editable.BACKWARD && this._drawnLatLngs.length >= this.MIN_VERTEX) {
         commit = true;
     } else if (index === 0 && this._drawing === L.Editable.FORWARD && this._drawnLatLngs.length >= this.MIN_VERTEX && this.CLOSED) {
         commit = true;  // Allow to close on first point also for polygons
     } else {
         this.onVertexRawMarkerClick(e);
     }
     this.fireAndForward('editable:vertex:clicked', e);
     if (commit) this.commitDrawing(e);
 },
Пример #2
0
 onMouseDown: function (e) {
     var iconPos = L.DomUtil.getPosition(this._icon),
         latlng = this.editor.map.layerPointToLatLng(iconPos);
     e = {
         originalEvent: e,
         latlng: latlng
     };
     if (this.options.opacity === 0) return;
     L.Editable.makeCancellable(e);
     this.editor.onMiddleMarkerMouseDown(e);
     if (e._cancelled) return;
     this.latlngs.splice(this.index(), 0, e.latlng);
     this.editor.refresh();
     var icon = this._icon;
     var marker = this.editor.addVertexMarker(e.latlng, this.latlngs);
     /* Hack to workaround browser not firing touchend when element is no more on DOM */
     var parent = marker._icon.parentNode;
     parent.removeChild(marker._icon);
     marker._icon = icon;
     parent.appendChild(marker._icon);
     marker._initIcon();
     marker._initInteraction();
     marker.setOpacity(1);
     /* End hack */
     // Transfer ongoing dragging to real marker
     L.Draggable._dragging = false;
     marker.dragging._draggable._onDown(e.originalEvent);
     this.delete();
 },
Пример #3
0
 onDrawingClick: function (e) {
     if (!this.drawing) return;
     L.Editable.makeCancellable(e);
     this.fireAndForward('editable:drawing:click', e);
     if (e._cancelled) return;
     this.processDrawingClick(e);
 },
Пример #4
0
 doDelete = function (callback, shape) {
     e = {shape: shape};
     L.Editable.makeCancellable(e);
     self.fireAndForward('editable:shape:delete', e);
     if (e._cancelled) return;
     shape = callback(latlngs, shape);
     if (self.ensureNotFlat) self.ensureNotFlat();  // Polygon
     self.refresh();
     self.reset();
     self.fireAndForward('editable:shape:deleted', {shape: shape});
     return shape;
 };
Пример #5
0
    split: function () {
        if (!this.editor.splitShape) return;  // Only for PolylineEditor
        this.editor.splitShape(this.latlngs, this.getIndex());
    },

    continue: function () {
        if (!this.editor.continueBackward) return;  // Only for PolylineEditor
        var index = this.getIndex();
        if (index === 0) this.editor.continueBackward(this.latlngs);
        else if (index === this.getLastIndex()) this.editor.continueForward(this.latlngs);
    }

});

L.Editable.mergeOptions({
    vertexMarkerClass: L.Editable.VertexMarker
});

L.Editable.MiddleMarker = L.Marker.extend({

    options: {
        opacity: 0.5,
        className: 'leaflet-div-icon leaflet-middle-icon',
        draggable: true
    },

    initialize: function (left, right, latlngs, editor, options) {
        this.left = left;
        this.right = right;
        this.editor = editor;
        this.latlngs = latlngs;