    import { Feature, ViewEventType, SketchDataType, Projection } from '../../base'
    import { Point } from '../../base/geometry'
    import { defaultValue } from '../../util'
    import SketchStage from './SketchStage'
    import SketchBaseDrawTool from './SketchBaseDrawTool'
    import SketchStyle from './SketchStyle'
    /**
     * 点绘图工具类
     * @class SketchPointDrawTool
     * @moduleEX SketchEditorModule
     * @extends SketchBaseDrawTool
     * @param {Object} options 构造参数
     * @param {MapView}  [options.mapView]  地图视图对象
     * @param {GraphicsLayer}  [options.layer]  草图图层管对象
     * @param {SketchStyle}  [options.sketchStyle]  草图符号
     * @param {Function}  [options._hitTestEvent]  草图拾取事件
     */

    class SketchPointDrawTool extends SketchBaseDrawTool {
      constructor(options) {
        super(options)
        /**
         * 地图视图
         * @member {MapView|SecenView} SketchEditor.prototype._mapView
         */
        this._mapView = options.mapView
        /**
         * 草图图层
         * @member {GraphicsLayer} SketchEditor.prototype._layer
         */
        this._layer = defaultValue(options.layer, undefined)
        /**
         * 草图绘图形集合
         * @member {SketchStage} SketchEditor.prototype._sketchStage
         */
        this._sketchStage = new SketchStage()
        /**
         * 草图符号
         * @member {SketchStyle} SketchEditor.prototype._sketchStyle
         */
        this._sketchStyle = defaultValue(options.sketchStyle, new SketchStyle())
        /**
         * 草图编辑状态
         * 0:没有画图或编辑状态
         * 1:图形编辑
         * 2:节点编辑
         * 3:画图中
         * @member {MapView|SecenView} SketchEditor.prototype._editMode
         */
        this._editMode = 0
        /**
         * 草图捕获配置项
         * @member {Object} SketchEditor.prototype.snappingOption
         * @param {Object} [snappingOption.showSelectBox = {}] 捕捉时是否展示选中编辑框
         * @param {Object} [snappingOption.showSelectVertex = {}] 捕捉时是否展示顶点可编辑图形
         * @param {Object} [snappingOption._hitTestMode = {}] 捕捉拾取方式，0：click鼠标拾取。1：mouseDown鼠标按下拾取
         */
        const snappingOption = {
          showSelectBox: true, // 选中时，展示图形选中框
          showSelectVertex: false, // 选中时，展示顶点可选框
          canEditFeature: false,
          canEditVertex: false,
          _hitTestMode: 0
        }
        this.snappingOption = defaultValue(options.snappingOption, snappingOption)
        /**
         * 所属父级绘图工具
         * @member {GraphicsLayer} SketchEditor.prototype._layer
         */
        this._parent = defaultValue(options._parent, undefined)
        /**
         * 初始化事件
         */
        this._initEvent()
        this.undoRedoManager = defaultValue(options.undoRedoManager, undefined)
        this._drawTools = []
        this._otherDrawTools = []
      }

      /**
       * 初始化事件
       * @private
       */
      _initEvent() {
        this._processEvent = this._processEvent.bind(this)
        this.on('pan', this._processEvent)
      }

      getPanEvent(event, target, type) {
        const _event = {
          event,
          target,
          type
        }
        return _event
      }

      /**
       * @description 鼠标绘制图形
       */
      drawFeature() {
        const handler = (options) => {
          // 这个判断需要优化
          if (options.target && options.target.type === 'circle') {
            return
          }
          const position = options.pointer
            ? options.pointer
            : { x: options.x, y: options.y }
          const pixelCoord = { x: position.x, y: position.y }
          const geoCoord = this._mapView.toMap({ x: pixelCoord.x, y: pixelCoord.y })
          geoCoord._pixelCoords = pixelCoord
          const feature = this._getFeature(geoCoord)

          this._sketchStage.entityGraphic = feature
          this._addFeaturesToMap(feature)

          this._editMode = 3
          this.stop()
          this._editMode = 0
          // 注册hitTest拾取草图事件
          this._hitTestDrawToolStack.push(this)
          // 发送绘制完成事件
          this.fire('drawn', { geometry: feature.geometry }, self)
        }
        this._mouseEventHandlers = this._mouseEventHandlers
          ? this._mouseEventHandlers
          : []
        this._mouseEventHandlers.push(handler)
        this._mapView.on(ViewEventType.mouseDown, handler)
      }

      /**
       * 删除选中的顶点
       * @private
       */
      deleteSelectedVertex(feature) {}

      updateSelectedVertex() {}

      /**
       * @description 添加图形
       * @param {Point} point 生成图形的点数据
       * @param {SketchStyle} sketchStyle 线的符号样式
       * @param {Object} attributes feature图形的属性
       */
      addFeature(point, sketchStyle, attributes) {
        let vertexStyle = null
        if (!sketchStyle || !sketchStyle.vertexStyle) {
          vertexStyle = this._sketchStyle._vertexStyle
        } else {
          vertexStyle = sketchStyle.vertexStyle
        }

        const feature = this._getFeature(point, vertexStyle)
        if (attributes) {
          feature.attributes = attributes
        }
        this._sketchStage.entityGraphic = feature

        // 更新图层图形
        this._addFeaturesToMap(feature)
      }

      /**
       * @description 添加图形
       * @param {Geometry} geometry 生成图形的点数据
       * @param {SketchStyle} sketchStyle 线的符号样式
       * @param {Object} attributes feature图形的属性
       */
      addFeatureByGeometry(geometry, sketchStyle, attributes) {
        let symbol = null
        if (!sketchStyle || !sketchStyle.vertexStyle) {
          symbol = this._sketchStyle._vertexStyle
        } else {
          symbol = sketchStyle.vertexStyle
        }
        const feature = new Feature({
          geometry,
          symbol
        })
        if (attributes) {
          feature.attributes = attributes
        }
        this._sketchStage.entityGraphic = feature

        // 更新图层图形
        this._addFeaturesToMap(feature)
      }

      // 测试方法，用于其他草图中调用point草图，暂时在point中不上图更新
      addFeatureTemp(point, sketchStyle, attributes) {
        let vertexStyle = null
        if (!sketchStyle || !sketchStyle.vertexStyle) {
          vertexStyle = this._sketchStyle.vertexStyle
        } else {
          vertexStyle = sketchStyle.vertexStyle
        }

        const feature = this._getFeature(point, vertexStyle)
        feature.attributes = attributes
        this._sketchStage.entityGraphic = feature
        this._mapView.sketchFeatures.push(feature)
      }

      /**
       * @description 获取feature实例
       * @private
       * @param {Point} point 生成图形的点数据
       * @param {Symbol} symbol 点的符号样式
       */
      _getFeature(point, symbol) {
        if (!point) {
          point = Projection.project(
            new Point({
              coordinates: [0, 0, 0]
            }),
            this._spatialReference
          )
        }
        if (!symbol) {
          symbol = this._sketchStyle.vertexStyle
        }
        const pointGeometry = new Feature({
          geometry: point,
          symbol
        })

        return pointGeometry
      }

      /**
       * @description 捕获草图
       * @private
       * @param {Feature} feature 被选中feature对象
       */
      _hitTestFeature(feature, event) {
        if (this.snappingOption.showSelectBox) {
          // 高亮点元素,用新图形代替高亮，展示选中图形时的辅助图形
          this._editMode = 1
          this.selectFeature(feature)
        } else {
          // 如果父级草图是点，则是移动点草图。 如果父级草图是区、线，则是缩放区、线草图。
          // eslint-disable-next-line no-lonely-if
          if (this._parent._sketchDataType === SketchDataType.POINT) {
            // 平移事件
            this.startPanGraphics(feature, event)
          } else if (this._parent && this._parent._editMode === 1) {
            if (feature.attributes.type !== 'midVertex') {
              // 四个角顶点缩放事件
              this.startVertexScaleGraphics(feature, event)
            } else {
              // 边上中点缩放事件
              this.startMidVertexScaleGraphics(feature, event)
            }
          } else if (this._parent && this._parent._editMode === 2) {
            // 修改顶点事件
            this.startVertexMoveGraphics(feature, event)
          }
        }
      }

      /**
       * @description 选中feature
       * @private
       * @param {Feature} feature 被选中feature对象
       */
      selectFeature(feature) {
        if (!this.snappingOption.showSelectBox) return
        // 加载选时的辅助图形，高亮的点
        const pointDrawTool = new SketchPointDrawTool({
          mapView: this._mapView,
          layer: this._layer,
          sketchStyle: new SketchStyle({
            vertexStyle: this._sketchStyle._selectVertexStyle
          }),
          snappingOption: {
            showSelectBox: false,
            _hitTestMode: 1
          },
          _parent: this, // 或者只传父级相应pan的事件
          _hitTestEvent: this._hitTestEvent
        })
        const point = feature.geometry
        // 图形加到layer上
        pointDrawTool.addFeatureByGeometry(point)
        this._drawTools.push(pointDrawTool)
        // 注册hitTest事件移动图形
        this._hitTestDrawToolStack.push(pointDrawTool)
        this._sketchStage.selectBoxGraphics = [
          pointDrawTool._sketchStage.entityGraphic
        ]
        this._drawTools.push(pointDrawTool)
        this._otherDrawTools.push(pointDrawTool)

        // 添加到undoRedoManager中
        if (this.undoRedoManager) {
          this.undoRedoManager.addProcess('add', this._sketchStage)
        }

        // 点击到地图没有feature图形区域，退出编辑
        if (
          !this._mapClickEvent &&
          (!this._parent || (this._parent && !this._parent._mapClickEvent))
        ) {
          this._mapClickEvent = () => {
            const removedFeatures = this._sketchStage.selectBoxGraphics
            removedFeatures.forEach((feature) => {
              this._removeFeatureFromMap(feature)
            })
            this._mapView.off(ViewEventType.click, this._mapClickEvent)
            this._mapClickEvent = null
            // 发送草图没有被选中状态
            this.fire('selected', { isSelected: false }, self)
            this._sketchStage.selectBoxGraphics = []
          }
          setTimeout(() => {
            this._hitTestEventHandlers.push(this._mapClickEvent)
            this._mapView.on(ViewEventType.click, this._mapClickEvent)
          }, 0)
        }
      }

      setSketchStyle(sketchStyle) {
        this._sketchStyle = sketchStyle
      }

      /**
       * @description 平移图形
       * @private
       * @param {Feature} feature 被选中feature对象
       * @param {Object} event
       */
      startPanGraphics(feature, event) {
        const timer = null
        let moving = false
        this._startPan = true
        let startPoint = Projection.project(
          new Point({
            coordinates: [event.lon, event.lat]
          }),
          this._spatialReference
        )
        // 移除父级草图地图点击事件。点图形仍然会触发mapClick事件。
        if (this._parent && this._parent._mapClickEvent) {
          this._mapView.off(ViewEventType.click, this._mapClickEvent)
        }

        // 鼠标平移
        const handlerMove = (options) => {
          if (moving) {
            return
          }
          if (!this._startPan) {
            return
          }
          clearTimeout(timer)
          moving = true

          const movePosition = options.pointer
            ? options.pointer
            : { x: options.x, y: options.y }
          const pixelCoord = { x: movePosition.x, y: movePosition.y }
          const movePoint = this._mapView.toMap({
            x: pixelCoord.x,
            y: pixelCoord.y
          })
          const deltaX = movePoint.coordinates[0] - startPoint.coordinates[0]
          const deltaY = movePoint.coordinates[1] - startPoint.coordinates[1]
          if (deltaX === 0 && deltaY === 0) {
            moving = false
            return
          }
          startPoint = movePoint
          this._dispatchEvent(
            'pan',
            { deltaPosition: { x: deltaX, y: deltaY } },
            this
          )
          this.updateFeature(movePoint, feature)
          moving = false
        }
        // 鼠标平移完成事件,移除平移事件
        const handlerUp = () => {
          if (this._disableMapDrag) {
            this._disableMapDrag()
          }
          if (!this._startPan) {
            return
          }
          this._startPan = false
          this._mapView.off(ViewEventType.mouseUp, handlerUp)
          this._mapView.off(ViewEventType.mouseMove, handlerMove)
          if (this._enableMapDrag) {
            this._enableMapDrag()
          }

          // 添加到undoRedoManager中
          if (this._parent && this._parent.undoRedoManager) {
            this._parent.undoRedoManager.addProcess(
              'update',
              this._parent._sketchStage
            )
          }
          // 重新注册父级草图地图点击事件
          if (this._parent && this._parent._mapClickEvent) {
            setTimeout(() => {
              this._mapView.on(ViewEventType.click, this._parent._mapClickEvent)
            }, 0)
          }
        }
        // 点击到地图没有feature图形区域，退出编辑
        const mapClick = () => {
          this.removeFeature(feature)
          this._parent._editMode = 0
          this._mapView.off(ViewEventType.click, mapClick)
        }
        // 注册平移时的鼠标事件事件
        this._hitTestEventHandlers.push(handlerMove)
        this._hitTestEventHandlers.push(handlerUp)
        this._hitTestEventHandlers.push(mapClick)
        this._mapView.on(ViewEventType.mouseUp, handlerUp)
        this._mapView.on(ViewEventType.mouseMove, handlerMove)
        this._mapView.on(ViewEventType.click, mapClick)
      }

      /**
       * @description 顶点缩放
       * @private
       * @param {Feature} feature 被选中feature对象
       * @param {Object} event
       */
      startVertexScaleGraphics(feature, event) {
        const timer = null
        let moving = false
        this._startPan = true
        const startPoint = Projection.project(
          new Point({
            coordinates: [event.lon, event.lat]
          }),
          this._spatialReference
        )
        const startParentEntityGraphic = JSON.parse(
          JSON.stringify(
            this._parent._sketchStage.entityGraphic.geometry.coordinates
          )
        )
        const parentExtent = this._parent._sketchStage.entityGraphic.geometry.extent
        // 移除父级草图地图点击事件。点图形仍然会触发mapClick事件。
        if (this._parent && this._parent._mapClickEvent) {
          this._mapView.off(ViewEventType.click, this._mapClickEvent)
        }
        // 获取当前移动点的方位
        const getDirection = function (xy, extent) {
          let direction = null
          const centerXY = [
            (extent.xmax + extent.xmin) / 2,
            (extent.ymax + extent.ymin) / 2
          ]
          if (xy[0] >= centerXY[0] && xy[1] >= centerXY[1]) {
            direction = 'ne'
          } else if (xy[0] >= centerXY[0] && xy[1] < centerXY[1]) {
            direction = 'se'
          } else if (xy[0] < centerXY[0] && xy[1] < centerXY[1]) {
            direction = 'sw'
          } else if (xy[0] < centerXY[0] && xy[1] >= centerXY[1]) {
            direction = 'nw'
          }
          return direction
        }
        const direction = getDirection(feature.geometry.coordinates, parentExtent)

        // 鼠标平移
        const handlerMove = (options) => {
          if (moving || !this._startPan) {
            return
          }

          clearTimeout(timer)
          moving = true
          //
          const movePosition = options.pointer
            ? options.pointer
            : { x: options.x, y: options.y }
          const pixelCoord = { x: movePosition.x, y: movePosition.y }
          const movePoint = this._mapView.toMap({
            x: pixelCoord.x,
            y: pixelCoord.y
          })

          const deltaX = movePoint.coordinates[0] - startPoint.coordinates[0]
          const deltaY = movePoint.coordinates[1] - startPoint.coordinates[1]
          const scaleX = movePoint.coordinates[0] / startPoint.coordinates[0]
          const scaleY = movePoint.coordinates[1] / startPoint.coordinates[1]
          if (deltaX === 0 && deltaY === 0) {
            moving = false
            return
          }
          this._dispatchEvent(
            'vertexScale',
            {
              startPoint,
              movePoint,
              entityGraphic: startParentEntityGraphic,
              deltaPosition: { x: deltaX, y: deltaY },
              scale: { x: scaleX, y: scaleY },
              direction,
              extent: parentExtent,
              feature,
              action: 'scale'
            },
            this
          )
          // startPoint = movePoint
          this.updateFeature(movePoint, feature)
          moving = false
        }
        const handlerUp = () => {
          if (this._disableMapDrag) {
            this._disableMapDrag()
          }
          if (!this._startPan) {
            return
          }
          this._dispatchEvent(
            'vertexScale',
            {
              action: 'stop'
            },
            this
          )
          this._startPan = false
          this._mapView.off(ViewEventType.mouseUp, handlerUp)
          this._mapView.off(ViewEventType.mouseMove, handlerMove)
          // 添加到undoRedoManager中
          if (this._parent && this._parent.undoRedoManager) {
            this._parent.undoRedoManager.addProcess(
              'update',
              this._parent._sketchStage
            )
          }
          // 重新注册父级草图地图点击事件
          if (this._parent && this._parent._mapClickEvent) {
            setTimeout(() => {
              this._mapView.on(ViewEventType.click, this._parent._mapClickEvent)
            }, 0)
          }
        }
        // 注册平移时鼠标相关事件
        this._hitTestEventHandlers.push(handlerMove)
        this._hitTestEventHandlers.push(handlerUp)
        this._mapView.on(ViewEventType.mouseUp, handlerUp)
        this._mapView.on(ViewEventType.mouseMove, handlerMove)
      }

      startMidVertexScaleGraphics(feature, event) {
        const timer = null
        let moving = false
        this._startPan = true
        const startPoint = Projection.project(
          new Point({
            coordinates: [event.lon, event.lat]
          }),
          this._spatialReference
        )
        const startParentEntityGraphic = JSON.parse(
          JSON.stringify(
            this._parent._sketchStage.entityGraphic.geometry.coordinates
          )
        )
        const parentExtent = this._parent._sketchStage.entityGraphic.geometry.extent
        // 移除父级草图地图点击事件。点图形仍然会触发mapClick事件。
        if (this._parent && this._parent._mapClickEvent) {
          this._mapView.off(ViewEventType.click, this._mapClickEvent)
        }
        // 获取当前移动点的方位
        const getDirection = function (xy, extent) {
          let direction = null
          const centerXY = [
            (extent.xmax + extent.xmin) / 2,
            (extent.ymax + extent.ymin) / 2
          ]
          if (Math.abs(xy[0] - centerXY[0]) <= 1e-8 && xy[1] >= centerXY[1]) {
            // if (xy[0] === centerXY[0] && xy[1] >= centerXY[1]) {
            direction = 'n'
          } else if (
            xy[0] >= centerXY[0] &&
            Math.abs(xy[1] - centerXY[1]) <= 1e-8
          ) {
            direction = 'e'
          } else if (Math.abs(xy[0] - centerXY[0]) <= 1e-8 && xy[1] < centerXY[1]) {
            direction = 's'
          } else if (xy[0] < centerXY[0] && Math.abs(xy[1] - centerXY[1]) <= 1e-8) {
            direction = 'w'
          }
          return direction
        }
        const direction = getDirection(feature.geometry.coordinates, parentExtent)

        // 鼠标平移
        const handlerMove = (options) => {
          if (moving || !this._startPan) {
            return
          }

          clearTimeout(timer)
          moving = true
          //
          const movePosition = options.pointer
            ? options.pointer
            : { x: options.x, y: options.y }
          const pixelCoord = { x: movePosition.x, y: movePosition.y }
          const movePoint = this._mapView.toMap({
            x: pixelCoord.x,
            y: pixelCoord.y
          })

          const deltaX = movePoint.coordinates[0] - startPoint.coordinates[0]
          const deltaY = movePoint.coordinates[1] - startPoint.coordinates[1]
          const scaleX = movePoint.coordinates[0] / startPoint.coordinates[0]
          const scaleY = movePoint.coordinates[1] / startPoint.coordinates[1]
          if (deltaX === 0 && deltaY === 0) {
            moving = false
            return
          }
          this._dispatchEvent(
            'midVertexScale',
            {
              startPoint,
              movePoint,
              entityGraphic: startParentEntityGraphic,
              deltaPosition: { x: deltaX, y: deltaY },
              scale: { x: scaleX, y: scaleY },
              direction,
              extent: parentExtent,
              action: 'scale'
            },
            this
          )
          // startPoint = movePoint
          moving = false
        }
        const handlerUp = () => {
          if (this._disableMapDrag) {
            this._disableMapDrag()
          }
          if (!this._startPan) {
            return
          }
          this._dispatchEvent(
            'vertexScale',
            {
              action: 'stop'
            },
            this
          )
          this._startPan = false
          this._mapView.off(ViewEventType.mouseUp, handlerUp)
          this._mapView.off(ViewEventType.mouseMove, handlerMove)
          if (this._enableMapDrag) {
            this._enableMapDrag()
          }
          // 添加到undoRedoManager中
          if (this._parent && this._parent.undoRedoManager) {
            this._parent.undoRedoManager.addProcess(
              'update',
              this._parent._sketchStage
            )
          }
          // 重新注册父级草图地图点击事件
          if (this._parent && this._parent._mapClickEvent) {
            setTimeout(() => {
              this._mapView.on(ViewEventType.click, this._parent._mapClickEvent)
            }, 0)
          }
        }
        // 注册平移时鼠标相关事件
        this._hitTestEventHandlers.push(handlerMove)
        this._hitTestEventHandlers.push(handlerUp)
        this._mapView.on(ViewEventType.mouseUp, handlerUp)
        this._mapView.on(ViewEventType.mouseMove, handlerMove)
      }

      /**
       * @description 移动图形顶点
       * @private
       * @param {Feature} feature 被选中feature对象
       * @param {Object} event
       */
      startVertexMoveGraphics(feature, event) {
        const timer = null
        let moving = false
        this._startPan = true
        let startPoint = Projection.project(
          new Point({
            coordinates: [event.lon, event.lat]
          }),
          this._spatialReference
        )
        const index = feature.attributes ? feature.attributes.vertexIndex : -2
        // 如果是中点，这要增加一个顶点，并改变相应终点
        if (feature.attributes.type === 'midVertex') {
          this._dispatchEvent(
            'midVertexAdd',
            {
              point: startPoint,
              vertexIndex: feature.attributes ? index : undefined,
              action: 'changeFeature'
            },
            this
          )
          // setTimeout(() => {
          //   this._startPan = true
          // }, 500)
          this._startPan = true
        } else {
          this._startPan = true
        }
        // 移除父级草图地图点击事件。点图形仍然会触发mapClick事件。
        if (this._parent && this._parent._mapClickEvent) {
          this._mapView.off(ViewEventType.click, this._mapClickEvent)
        }

        // 鼠标移动，修改父级草图顶点
        const handlerMove = (options) => {
          if (moving || !this._startPan) {
            return
          }

          clearTimeout(timer)
          moving = true
          //
          const movePosition = options.pointer
            ? options.pointer
            : { x: options.x, y: options.y }
          const pixelCoord = { x: movePosition.x, y: movePosition.y }
          const movePoint = this._mapView.toMap({
            x: pixelCoord.x,
            y: pixelCoord.y
          })

          const deltaX = movePoint.coordinates[0] - startPoint.coordinates[0]
          const deltaY = movePoint.coordinates[1] - startPoint.coordinates[1]
          if (deltaX === 0 && deltaY === 0) {
            moving = false
            return
          }
          if (feature.attributes.type === 'midVertex') {
            this._dispatchEvent(
              'midVertexAdd',
              {
                startPoint,
                movePoint,
                vertexIndex: index,
                vertexType: feature.attributes
                  ? feature.attributes.type
                  : undefined,
                action: 'moveMidVertex'
              },
              this
            )
          } else {
            this._dispatchEvent(
              'vertexMove',
              {
                startPoint,
                movePoint,
                vertexIndex: index,
                vertexType: feature.attributes ? feature.attributes.type : undefined
              },
              this
            )
          }

          startPoint = movePoint
          this.updateFeature(movePoint, feature)
          moving = false
        }
        const handlerUp = (options) => {
          if (this._disableMapDrag) {
            this._disableMapDrag()
          }
          if (!this._startPan) {
            return
          }
          const movePosition = options.pointer
            ? options.pointer
            : { x: options.x, y: options.y }
          const pixelCoord = { x: movePosition.x, y: movePosition.y }
          const movePoint = this._mapView.toMap({
            x: pixelCoord.x,
            y: pixelCoord.y
          })
          this._startPan = false
          this._mapView.off(ViewEventType.mouseUp, handlerUp)
          this._mapView.off(ViewEventType.mouseMove, handlerMove)
          if (this._enableMapDrag) {
            this._enableMapDrag()
          }
          // 如果是中点，这要增加一个顶点，并改变相应终点
          if (feature.attributes.type === 'midVertex') {
            const index = feature.attributes.vertexIndex
            this._dispatchEvent(
              'midVertexAdd',
              {
                point: startPoint,
                vertexIndex: feature.attributes ? index : undefined,
                action: 'addVertex'
              },
              this
            )
          }

          moving = false
          // 添加到undoRedoManager中
          if (this._parent && this._parent.undoRedoManager) {
            this._parent.undoRedoManager.addProcess(
              'update',
              this._parent._sketchStage
            )
          }
          // 重新注册父级草图地图点击事件
          if (this._parent && this._parent._mapClickEvent) {
            setTimeout(() => {
              this._mapView.on(ViewEventType.click, this._parent._mapClickEvent)
            }, 0)
          }
        }
        // 注册平移时鼠标相关事件
        this._hitTestEventHandlers.push(handlerMove)
        this._hitTestEventHandlers.push(handlerUp)
        this._mapView.on(ViewEventType.mouseUp, handlerUp)
        this._mapView.on(ViewEventType.mouseMove, handlerMove)
      }

      startVertexAdd() {}

      /**
       * @description 响应图形平移事件
       * @private
       * @param {Feature} feature 被选中feature对象
       */
      _processEvent(event) {
        if (event.type === 'pan') {
          this._handlerPanEvent(event)
        } else if (event.type === 'vertexScale') {
          // 处理顶点缩放逻辑
          this._handlerVertexScaleEvent(event)
        } else if (event.type === 'midVertexScale') {
          // 处理顶点缩放逻辑
          this._handlerMidVertexScaleEvent(event)
        }
      }

      /**
       * @description 响应平移事件
       * @private
       * @param {Object} event 传入事件参数
       */
      _handlerPanEvent(event) {
        // 更新当前草图图形
        const newCoordinates = this.getPanCoordinates(
          this._sketchStage.entityGraphic.geometry.coordinates,
          event.deltaPosition.x,
          event.deltaPosition.y
        )
        const newGeometry = new Point({
          coordinates: newCoordinates,
          spatialReference: this._spatialReference
        })
        this._sketchStage.entityGraphic.geometry = newGeometry
      }

      /**
       * @description 响应外包盒四角顶点缩放事件
       * @private
       * @param {Object} event 传入事件参数
       */
      _handlerVertexScaleEvent(event) {
        if (event.action === 'scale') {
          // 更新当前草图的图形位置
          if (!this._sketchStage.entityGraphic.attributes.lastCoordinates) {
            const oriCoordinates = JSON.parse(
              JSON.stringify([this._sketchStage.entityGraphic.geometry.coordinates])
            )
            this._sketchStage.entityGraphic.attributes.lastCoordinates =
              oriCoordinates
          }
          this._sketchStage.entityGraphic.attributes = this._sketchStage
            .entityGraphic.attributes
            ? this._sketchStage.entityGraphic.attributes
            : {}
          const newCoordinates = this.getScaleCoordinates(
            [this._sketchStage.entityGraphic.geometry.coordinates],
            event.direction,
            event.extent,
            event.startPoint,
            event.movePoint,
            this._sketchStage.entityGraphic.attributes.lastCoordinates
          )
          const newGeometry = new Point({
            coordinates: newCoordinates[0],
            spatialReference: this._spatialReference
          })
          this._sketchStage.entityGraphic.geometry = newGeometry
        }
        if (event.action === 'stop') {
          if (this._sketchStage.entityGraphic.attributes.lastCoordinates) {
            this._sketchStage.entityGraphic.attributes.lastCoordinates = undefined
          }
        }
      }

      /**
       * @description 响应外包盒四边终点点缩放事件
       * @private
       * @param {Object} event 传入事件参数
       */
      _handlerMidVertexScaleEvent(event) {
        if (event.action === 'scale') {
          // 更新当前草图的图形位置
          let newGeometry = null
          if (!this._sketchStage.entityGraphic.attributes.lastCoordinates) {
            const oriCoordinates = JSON.parse(
              JSON.stringify([this._sketchStage.entityGraphic.geometry.coordinates])
            )
            this._sketchStage.entityGraphic.attributes.lastCoordinates =
              oriCoordinates
          }
          const newCoordinates = this.getMidScaleCoordinates(
            [this._sketchStage.entityGraphic.geometry.coordinates],
            event.direction,
            event.extent,
            event.startPoint,
            event.movePoint,
            this._sketchStage.entityGraphic.attributes.lastCoordinates
          )
          newGeometry = new Point({
            coordinates: newCoordinates[0],
            spatialReference: this._spatialReference
          })
          this._sketchStage.entityGraphic.geometry = newGeometry
          // 撤销后，在移动中点，有问题，parent的selectBoxVertexGraphics没有被更新。
          // 暂时强制更新
          if (this._parent) {
            this._parent._sketchStage.updateGraphic(this._sketchStage.entityGraphic)
          }
        }
        if (event.action === 'stop') {
          if (this._sketchStage.entityGraphic.attributes.lastCoordinates) {
            this._sketchStage.entityGraphic.attributes.lastCoordinates = undefined
          }
        }
      }

      /**
       * 点击到地图没有feature图形区域，退出编辑，临时方法
       * @private
       */
      removeFeature(feature) {
        if (this._sketchStage.entityGraphic.id !== feature.id) {
          this._sketchStage.entityGraphic = null
        }
        this._mapView.sketchFeatures = this._mapView.sketchFeatures.filter(
          (item) => item.id !== feature.id
        )
        this._addFeaturesToMap()
      }
    }
    export default SketchPointDrawTool