sean.zhou
2022-09-23 fa611ff2eeaac289931eb0e21a962743fb271ba7
src/hooks/use-mouse-tool.ts
@@ -6,13 +6,14 @@
export function useMouseTool () {
  const root = getRoot()
  const AMap = root.$aMapObj
  const state = reactive({
    pinNum: 0,
    polylineNum: 0,
    PolygonNum: 0,
    currentType: '',
  })
  function drawPin (type:MapDoodleType, getDrawCallback:Function) {
    root?.$mouseTool.marker({
      title: type + state.pinNum,
@@ -21,6 +22,7 @@
    state.pinNum++
    root?.$mouseTool.on('draw', getDrawCallback)
  }
  function drawPolyline (type:MapDoodleType, getDrawCallback:Function) {
    root?.$mouseTool.polyline({
      strokeColor: '#2d8cf0',
@@ -32,6 +34,7 @@
    })
    root?.$mouseTool.on('draw', getDrawCallback)
  }
  function drawPolygon (type:MapDoodleType, getDrawCallback:Function) {
    root?.$mouseTool.polygon({
      strokeColor: '#2d8cf0',
@@ -44,10 +47,12 @@
    })
    root?.$mouseTool.on('draw', getDrawCallback)
  }
  function drawOff (type:MapDoodleType) {
    root?.$mouseTool.close()
    root?.$mouseTool.off('draw')
  }
  function mouseTool (type: MapDoodleType, getDrawCallback: Function) {
    state.currentType = type
    switch (type) {
@@ -65,6 +70,7 @@
        break
    }
  }
  return {
    mouseTool
  }