派生自 wuyushui/SewerAndRainNetwork

chenzeping
2021-03-09 3ecb480a576bb684f029ec655cd29af621d3c155
src/components/plugin/Editable.js
@@ -348,6 +348,26 @@
        circle.enableEdit(this.map).startDrawing()
        return circle
      },
      // 文字标注
      startText: function (latlng, options) {
        latlng = latlng || this.map.getCenter().clone()
        const markerBuilding = this.createMarker(latlng, options).bindTooltip('问题标注内容', {
          offset: [0, 0],
          permanent: true,
          direction: 'top',
          className: 'anim-tooltip'
        })
        markerBuilding.enableEdit(this.map).startDrawing()
        return markerBuilding
      },
      // 图标标注
      startIcon: function (latlng, options) {
        latlng = latlng || this.map.getCenter().clone()
        const icon = this.createMarker(latlng, options)
        icon.enableEdit(this.map).startDrawing()
        return icon
      },
      startHole: function (editor, latlng) {
        editor.newHole(latlng)
@@ -565,7 +585,10 @@
        const next = this.getNext() // Compute before changing latlng
        this.latlngs.splice(this.getIndex(), 1)
        this.editor.editLayer.removeLayer(this)
        this.editor.onVertexDeleted({ latlng: this.latlng, vertex: this })
        this.editor.onVertexDeleted({
          latlng: this.latlng,
          vertex: this
        })
        if (!this.latlngs.length) this.editor.deleteShape(this.latlngs)
        if (next) next.resetMiddleMarker()
        this.editor.refresh()
@@ -636,8 +659,9 @@
      continue: function () {
        if (!this.editor.continueBackward) return // Only for PolylineEditor
        const index = this.getIndex()
        if (index === 0) this.editor.continueBackward(this.latlngs)
        else if (index === this.getLastIndex()) this.editor.continueForward(this.latlngs)
        if (index === 0) {
          this.editor.continueBackward(this.latlngs)
        } else if (index === this.getLastIndex()) this.editor.continueForward(this.latlngs)
      }
    })
@@ -675,8 +699,11 @@
        const leftPoint = this._map.latLngToContainerPoint(this.left.latlng)
        const rightPoint = this._map.latLngToContainerPoint(this.right.latlng)
        const size = L.point(this.options.icon.options.iconSize)
        if (leftPoint.distanceTo(rightPoint) < size.x * 3) this.hide()
        else this.show()
        if (leftPoint.distanceTo(rightPoint) < size.x * 3) {
          this.hide()
        } else {
          this.show()
        }
      },
      show: function () {
@@ -780,8 +807,11 @@
      // 🍂method enable(): this
      // Set up the drawing tools for the feature to be editable.
      addHooks: function () {
        if (this.isConnected()) this.onFeatureAdd()
        else this.feature.once('add', this.onFeatureAdd, this)
        if (this.isConnected()) {
          this.onFeatureAdd()
        } else {
          this.feature.once('add', this.onFeatureAdd, this)
        }
        this.onEnable()
        this.feature.on(this._getEvents(), this)
      },
@@ -1030,8 +1060,11 @@
      initVertexMarkers: function (latlngs) {
        if (!this.enabled()) return
        latlngs = latlngs || this.getLatLngs()
        if (isFlat(latlngs)) this.addVertexMarkers(latlngs)
        else for (let i = 0; i < latlngs.length; i++) this.initVertexMarkers(latlngs[i])
        if (isFlat(latlngs)) {
          this.addVertexMarkers(latlngs)
        } else {
          for (let i = 0; i < latlngs.length; i++) this.initVertexMarkers(latlngs[i])
        }
      },
      getLatLngs: function () {
@@ -1054,7 +1087,10 @@
        // 🍂section Vertex events
        // 🍂event editable:vertex:new: VertexEvent
        // Fired when a new vertex is created.
        this.fireAndForward('editable:vertex:new', { latlng: vertex.latlng, vertex: vertex })
        this.fireAndForward('editable:vertex:new', {
          latlng: vertex.latlng,
          vertex: vertex
        })
      },
      addVertexMarkers: function (latlngs) {
@@ -1253,8 +1289,11 @@
      },
      addLatLng: function (latlng) {
        if (this._drawing === L.Editable.FORWARD) this._drawnLatLngs.push(latlng)
        else this._drawnLatLngs.unshift(latlng)
        if (this._drawing === L.Editable.FORWARD) {
          this._drawnLatLngs.push(latlng)
        } else {
          this._drawnLatLngs.unshift(latlng)
        }
        this.feature._bounds.extend(latlng)
        const vertex = this.addVertexMarker(latlng, this._drawnLatLngs)
        this.onNewVertex(vertex)
@@ -1277,8 +1316,11 @@
      // Programmatically add a point while drawing.
      push: function (latlng) {
        if (!latlng) return console.error('L.Editable.PathEditor.push expect a valid latlng as parameter')
        if (this._drawing === L.Editable.FORWARD) this.newPointForward(latlng)
        else this.newPointBackward(latlng)
        if (this._drawing === L.Editable.FORWARD) {
          this.newPointForward(latlng)
        } else {
          this.newPointBackward(latlng)
        }
      },
      removeLatLng: function (latlng) {
@@ -1291,18 +1333,27 @@
      pop: function () {
        if (this._drawnLatLngs.length <= 1) return
        let latlng
        if (this._drawing === L.Editable.FORWARD) latlng = this._drawnLatLngs[this._drawnLatLngs.length - 1]
        else latlng = this._drawnLatLngs[0]
        if (this._drawing === L.Editable.FORWARD) {
          latlng = this._drawnLatLngs[this._drawnLatLngs.length - 1]
        } else {
          latlng = this._drawnLatLngs[0]
        }
        this.removeLatLng(latlng)
        if (this._drawing === L.Editable.FORWARD) this.tools.anchorForwardLineGuide(this._drawnLatLngs[this._drawnLatLngs.length - 1])
        else this.tools.anchorForwardLineGuide(this._drawnLatLngs[0])
        if (this._drawing === L.Editable.FORWARD) {
          this.tools.anchorForwardLineGuide(this._drawnLatLngs[this._drawnLatLngs.length - 1])
        } else {
          this.tools.anchorForwardLineGuide(this._drawnLatLngs[0])
        }
        return latlng
      },
      processDrawingClick: function (e) {
        if (e.vertex && e.vertex.editor === this) return
        if (this._drawing === L.Editable.FORWARD) this.newPointForward(e.latlng)
        else this.newPointBackward(e.latlng)
        if (this._drawing === L.Editable.FORWARD) {
          this.newPointForward(e.latlng)
        } else {
          this.newPointBackward(e.latlng)
        }
        this.fireAndForward('editable:drawing:clicked', e)
      },
@@ -1375,8 +1426,9 @@
        }
        if (latlngs === shape) return inplaceDelete(latlngs, shape)
        for (let i = 0; i < latlngs.length; i++) {
          if (latlngs[i] === shape) return spliceDelete(latlngs, shape)
          else if (latlngs[i].indexOf(shape) !== -1) return spliceDelete(latlngs[i], shape)
          if (latlngs[i] === shape) {
            return spliceDelete(latlngs, shape)
          } else if (latlngs[i].indexOf(shape) !== -1) return spliceDelete(latlngs[i], shape)
        }
      },
@@ -1464,8 +1516,11 @@
      getDefaultLatLngs: function (latlngs) {
        latlngs = latlngs || this.feature._latlngs
        if (!latlngs.length || latlngs[0] instanceof L.LatLng) return latlngs
        else return this.getDefaultLatLngs(latlngs[0])
        if (!latlngs.length || latlngs[0] instanceof L.LatLng) {
          return latlngs
        } else {
          return this.getDefaultLatLngs(latlngs[0])
        }
      },
      ensureMulti: function () {
@@ -1485,8 +1540,9 @@
      },
      formatShape: function (shape) {
        if (isFlat(shape)) return shape
        else if (shape[0]) return this.formatShape(shape[0])
        if (isFlat(shape)) {
          return shape
        } else if (shape[0]) return this.formatShape(shape[0])
      },
      // 🍂method splitShape(latlngs?: Array, index: int)
@@ -1575,8 +1631,11 @@
        // [[1, 2], [3, 4]] => must be nested
        // [] => must be nested
        // [[]] => is already nested
        if (isFlat(shape) && (!shape[0] || shape[0].length !== 0)) return [shape]
        else return shape
        if (isFlat(shape) && (!shape[0] || shape[0].length !== 0)) {
          return [shape]
        } else {
          return shape
        }
      }
    })
@@ -1711,8 +1770,11 @@
      },
      onVertexMarkerDrag: function (e) {
        if (e.vertex.getIndex() === 1) this.resize(e)
        else this.updateResizeLatLng(e)
        if (e.vertex.getIndex() === 1) {
          this.resize(e)
        } else {
          this.updateResizeLatLng(e)
        }
        L.Editable.PathEditor.prototype.onVertexMarkerDrag.call(this, e)
      },
@@ -1792,8 +1854,11 @@
      // 🍂method toggleEdit()
      // Enable or disable editing, according to current status.
      toggleEdit: function () {
        if (this.editEnabled()) this.disableEdit()
        else this.enableEdit()
        if (this.editEnabled()) {
          this.disableEdit()
        } else {
          this.enableEdit()
        }
      },
      _onEditableAdd: function () {
@@ -1814,9 +1879,13 @@
        // - latlngs is an array of arrays of latlngs, loop over
        let shape = null
        latlngs = latlngs || this._latlngs
        if (!latlngs.length) return shape
        else if (isFlat(latlngs) && this.isInLatLngs(latlng, latlngs)) shape = latlngs
        else for (let i = 0; i < latlngs.length; i++) if (this.isInLatLngs(latlng, latlngs[i])) return latlngs[i]
        if (!latlngs.length) {
          return shape
        } else if (isFlat(latlngs) && this.isInLatLngs(latlng, latlngs)) {
          shape = latlngs
        } else {
          for (let i = 0; i < latlngs.length; i++) if (this.isInLatLngs(latlng, latlngs[i])) return latlngs[i]
        }
        return shape
      },
@@ -1855,10 +1924,15 @@
        // - latlngs is an array of arrays of arrays, this is a multi, loop over
        let shape = null
        latlngs = latlngs || this._latlngs
        if (!latlngs.length) return shape
        else if (isFlat(latlngs) && this.isInLatLngs(latlng, latlngs)) shape = latlngs
        else if (isFlat(latlngs[0]) && this.isInLatLngs(latlng, latlngs[0])) shape = latlngs
        else for (let i = 0; i < latlngs.length; i++) if (this.isInLatLngs(latlng, latlngs[i][0])) return latlngs[i]
        if (!latlngs.length) {
          return shape
        } else if (isFlat(latlngs) && this.isInLatLngs(latlng, latlngs)) {
          shape = latlngs
        } else if (isFlat(latlngs[0]) && this.isInLatLngs(latlng, latlngs[0])) {
          shape = latlngs
        } else {
          for (let i = 0; i < latlngs.length; i++) if (this.isInLatLngs(latlng, latlngs[i][0])) return latlngs[i]
        }
        return shape
      },