| | |
| | | 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) |
| | |
| | | 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() |
| | |
| | | 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) |
| | | } |
| | | |
| | | }) |
| | |
| | | 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 () { |
| | |
| | | // 🍂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) |
| | | }, |
| | |
| | | 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 () { |
| | |
| | | // 🍂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) { |
| | |
| | | }, |
| | | |
| | | 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) |
| | |
| | | // 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) { |
| | |
| | | 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) |
| | | }, |
| | | |
| | |
| | | } |
| | | 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) |
| | | } |
| | | }, |
| | | |
| | |
| | | |
| | | 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 () { |
| | |
| | | }, |
| | | |
| | | 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) |
| | |
| | | // [[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 |
| | | } |
| | | } |
| | | |
| | | }) |
| | |
| | | }, |
| | | |
| | | 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) |
| | | }, |
| | | |
| | |
| | | // 🍂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 () { |
| | |
| | | // - 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 |
| | | }, |
| | | |
| | |
| | | // - 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 |
| | | }, |
| | | |
| | |
| | | l2 = latlngs[k] |
| | | |
| | | if (((l1.lat > l.lat) !== (l2.lat > l.lat)) && |
| | | (l.lng < (l2.lng - l1.lng) * (l.lat - l1.lat) / (l2.lat - l1.lat) + l1.lng)) { |
| | | (l.lng < (l2.lng - l1.lng) * (l.lat - l1.lat) / (l2.lat - l1.lat) + l1.lng)) { |
| | | inside = !inside |
| | | } |
| | | } |