| | |
| | | // 开始绘制 |
| | | startDrawing() { |
| | | if (!this.whetherToDraw) { |
| | | console.log('当前不允许绘制'); |
| | | |
| | | return; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | } |
| | | // 清除不在范围内的点 |
| | | removeLastInvalidPoint() { |
| | | const posLen = this.curPolygon.positions.length |
| | | if (posLen === 0) return |
| | | |
| | | let targetPointId = '' |
| | | let removeCount = 0 |
| | | |
| | | if (posLen === 2) { |
| | | removeCount = 2 |
| | | targetPointId = `${DrawPolygon.ENTITY_NAMES.POINT_ID_PREFIX}0` |
| | | } else if (posLen > 2) { |
| | | removeCount = 1 |
| | | const pointIndex = posLen - 2 |
| | | targetPointId = `${DrawPolygon.ENTITY_NAMES.POINT_ID_PREFIX}${pointIndex}` |
| | | } |
| | | |
| | | this.curPolygon.positions.splice(posLen - removeCount, removeCount) |
| | | |
| | | const invalidPoint = this.editPolygonPointDataSource.entities.getById(targetPointId) |
| | | if (invalidPoint) { |
| | | this.editPolygonPointDataSource.entities.remove(invalidPoint) |
| | | } |
| | | |
| | | if (this.curPolygon.positions.length === 0 && this.polygonEntity) { |
| | | this.editPolygonDataSource.entities.remove(this.polygonEntity) |
| | | this.polygonEntity = null |
| | | } |
| | | } |
| | | // 添加一个点 |
| | | addPosition(position, isAdd = true) { |
| | | // 第一个点要重复压入一次,形成动态绘制效果 |
| | |
| | | const isPolygonPoint = pickedAllEntity.find(i => i.id.name === DrawPolygon.ENTITY_NAMES.POINT) |
| | | const isPolygon = pickedAllEntity.find(i => i.id.name === DrawPolygon.ENTITY_NAMES.POLYGON) |
| | | if (this.drawingMode && !this.whetherToDraw) { |
| | | console.log('当前不允许绘制'); |
| | | |
| | | return; // 阻断后续绘制逻辑 |
| | | } |
| | | // 如果不是绘制模式 |
| | |
| | | this.notify('getPolygonPositions', []) |
| | | this.startDrawing() |
| | | } |
| | | // 删除图斑 |
| | | delSpot() { |
| | | this.removeEntities() |
| | | this.isPreviewMode = true |
| | | this.startDrawing() |
| | | } |
| | | |
| | | // 删除端点 |
| | | delPoint() { |
| | | if (this.curPolygon.positions.length <= 3) { |
| | |
| | | } else { |
| | | // 新增:不允许绘制时,确保绘制模式为 false,避免误触发 |
| | | this.drawingMode = false; |
| | | console.log('当前不允许绘制'); |
| | | |
| | | } |
| | | |
| | | let newPosition = positions.map(item => { |