{"version":3,"file":"TyphoonLegendImpl.mjs","sources":["../../../../../../../packages/sdk/plugins/weather/Typhoon/TyphoonLegendImpl.ts"],"sourcesContent":["/*\n * @Author: Yolo\n * @Date: 2024-03-28 13:54:58\n * @Last Modified by: Yolo\n * @Last Modified time: 2024-06-06 10:23:31\n * @Desc 绘制台风图例\n */\nimport L from 'leaflet'\n\ntype TyphoonLegendOptions = L.ControlOptions\n\nclass TyphoonLegendControl extends L.Control {\n  private _container!: HTMLElement\n  private _legend!: HTMLElement\n  private _part1!: HTMLElement\n  private _canvas!: HTMLCanvasElement\n  private _strong!: HTMLElement\n  private _btn_expand!: any\n\n  constructor(options?: TyphoonLegendOptions) {\n    super(options)\n    this.options.position = 'topright'\n  }\n\n  override onAdd() {\n    this._container = L.DomUtil.create('div')\n    L.DomEvent.disableClickPropagation(this._container)\n\n    this._legend = L.DomUtil.create(\n      'div',\n      'weather-typh-legend',\n      this._container\n    )\n    this._legend.id = 'weather-typh-legend'\n\n    this._part1 = L.DomUtil.create('div', 'typh-title', this._legend)\n    this._canvas = L.DomUtil.create('canvas', '', this._legend)\n    this._canvas.id = 'lineCanvas_1'\n    this._canvas.width = 180\n    this._canvas.height = 370\n\n    this._strong = L.DomUtil.create('div', 'title-txt', this._part1)\n    this._strong.textContent = '台风图例'\n\n    this._btn_expand = L.DomUtil.create(\n      'div',\n      'title-btn btn-right',\n      this._part1\n    ) as any\n    this._btn_expand.id = 'weather-typh-legend-button2'\n    this._btn_expand.name = 'a'\n    this._btn_expand.textContent = ''\n\n    return this._container\n  }\n\n  show(isShow = true) {\n    const weatherTyphLegendDom = document.querySelector(\n      '#weather-typh-legend'\n    ) as HTMLElement\n    if (weatherTyphLegendDom) {\n      L.DomUtil.removeClass(weatherTyphLegendDom, 'weather-typh-legend-hid')\n      L.DomUtil.removeClass(weatherTyphLegendDom, 'weather-typh-legend-block')\n      isShow\n        ? L.DomUtil.addClass(weatherTyphLegendDom, 'weather-typh-legend-block')\n        : L.DomUtil.addClass(weatherTyphLegendDom, 'weather-typh-legend-hid')\n    }\n  }\n\n  override addTo(datas: any) {\n    super.addTo(datas)\n    L.DomUtil.addClass(this._container, 'leaflet-control-left')\n\n    const drawCanvasWind = (styleType: 'a' | 'b') => {\n      const lineCanvas1 = document.querySelector(\n        '#lineCanvas_1'\n      ) as HTMLCanvasElement\n      const canvas1 = lineCanvas1.getContext('2d') as CanvasRenderingContext2D\n\n      const windSpeed = [\n        '10.8~17.1',\n        '17.2~24.4',\n        '24.5~32.6',\n        '32.7~41.4',\n        '41.5~50.9',\n        '≥51',\n      ]\n      const windForce = ['6~7', '8~9', '10~11', '12~13', '14~15', '≥16']\n      const colors = [\n        '#076DEB',\n        '#FEF301',\n        '#FC8F2B',\n        '#FE0405',\n        '#FE3BA3',\n        '#AD00D8',\n      ]\n      const windNames = [\n        '热带低压',\n        '热带风暴',\n        '强热带风暴',\n        '台风',\n        '强台风',\n        '超强台风',\n        '七级风圈',\n        '十级风圈',\n        '实际路径',\n        '预测路径',\n        '24小时警戒线',\n        '48小时警戒线',\n      ]\n\n      let height = 10\n      let additionalOffset = 0\n\n      if (styleType === 'b') {\n        lineCanvas1.width = 310\n        lineCanvas1.height = 440\n        canvas1.strokeStyle = '#000'\n        canvas1.lineWidth = 0.5\n        canvas1.strokeRect(4, 0, lineCanvas1.width - 8, 204)\n        additionalOffset = 5\n      } else {\n        lineCanvas1.width = 180\n        lineCanvas1.height = 400\n        additionalOffset = 0\n      }\n\n      //绘制台风强度图例\n      for (const [i, windName] of windNames.entries()) {\n        canvas1.save()\n        if (i < 6) {\n          if ('b' == styleType) {\n            canvas1.beginPath()\n            if (0 == i) {\n              canvas1.fillStyle = '#000000'\n              canvas1.font = '12px Arial'\n              canvas1.fillText('级', 20 + additionalOffset, height + 5 + 0)\n              canvas1.fillText(\n                '风速' + '(' + '米' + '/' + '秒' + ')',\n                150 + additionalOffset,\n                height + 5 + 0\n              )\n              canvas1.fillText(\n                '风力' + '(' + '级' + '',\n                246 + additionalOffset,\n                height + 5 + 0\n              )\n              height += 30\n            }\n            canvas1.font = '12px Arial'\n            canvas1.fillText(windName, 28 + additionalOffset, height + 5 + 0)\n            canvas1.fillText(\n              windSpeed[i],\n              160 + additionalOffset,\n              height + 5 + 0\n            )\n            canvas1.fillText(\n              windForce[i],\n              240 + additionalOffset,\n              height + 5 + 0\n            )\n            canvas1.closePath()\n            canvas1.restore()\n          }\n          canvas1.save()\n          canvas1.lineWidth = 2\n          canvas1.strokeStyle = colors[i]\n          canvas1.fillStyle = colors[i]\n          canvas1.beginPath()\n          canvas1.arc(\n            15 + additionalOffset,\n            height + 0,\n            4.5,\n            0,\n            2 * Math.PI,\n            true\n          )\n          canvas1.stroke()\n          canvas1.fill()\n          canvas1.closePath()\n          canvas1.restore()\n        }\n        ;(6 != i && 7 != i) ||\n          (canvas1.beginPath(),\n          (canvas1.lineWidth = 2),\n          (canvas1.strokeStyle = 6 == i ? '#D8D243' : '#E59851'),\n          canvas1.arc(\n            15 + additionalOffset,\n            height + 0,\n            4.5,\n            0,\n            2 * Math.PI,\n            true\n          ),\n          canvas1.stroke(),\n          canvas1.closePath(),\n          canvas1.restore())\n        ;(8 != i && 9 != i) ||\n          (canvas1.beginPath(),\n          (canvas1.fillStyle = '#FE3BA3'),\n          (canvas1.strokeStyle = '#FE3BA3'),\n          (canvas1.lineWidth = 1.5),\n          canvas1.arc(\n            13 + additionalOffset,\n            height + 0,\n            3.5,\n            0,\n            2 * Math.PI,\n            true\n          ),\n          canvas1.fill(),\n          canvas1.stroke(),\n          canvas1.closePath(),\n          canvas1.beginPath(),\n          canvas1.moveTo(17 + additionalOffset, height + 0),\n          (canvas1.lineWidth = 3.5),\n          (canvas1.strokeStyle = '#FE3BA3'),\n          8 == i ||\n            (canvas1.lineTo(24.5 + additionalOffset, height + 0),\n            canvas1.moveTo(27.5 + additionalOffset, height + 0)),\n          canvas1.lineTo(0x24 + additionalOffset, height + 0),\n          canvas1.stroke(),\n          (canvas1.strokeStyle = '#FE3BA3'),\n          (canvas1.lineWidth = 1.5),\n          canvas1.closePath(),\n          canvas1.beginPath(),\n          canvas1.arc(\n            39.5 + additionalOffset,\n            height + 0,\n            3.5,\n            0,\n            2 * Math.PI,\n            true\n          ),\n          canvas1.fill(),\n          canvas1.stroke(),\n          canvas1.closePath(),\n          canvas1.restore())\n        ;(10 != i && 11 != i) ||\n          (canvas1.beginPath(),\n          (canvas1.strokeStyle = '#BE621F'),\n          (canvas1.lineWidth = 2),\n          (canvas1.lineCap = 'round'),\n          10 == i\n            ? (canvas1.moveTo(10 + additionalOffset, height + 0),\n              canvas1.lineTo(42 + additionalOffset, height + 0))\n            : (canvas1.setLineDash([5, 5]),\n              canvas1.moveTo(10 + additionalOffset, height + 0),\n              canvas1.lineTo(42 + additionalOffset, height + 0)),\n          canvas1.stroke(),\n          canvas1.closePath(),\n          canvas1.restore())\n        if ('a' == styleType || i > 5) {\n          canvas1.fillStyle = '#000000'\n          canvas1.font = '12px Arial'\n          canvas1.beginPath()\n          canvas1.fillText(\n            windName,\n            i <= 7 ? 28 + additionalOffset : 50 + additionalOffset,\n            height + 5 + 0\n          )\n          canvas1.stroke()\n          canvas1.closePath()\n          canvas1.restore()\n        }\n        height += 30\n      }\n    }\n\n    drawCanvasWind('a')\n\n    this._btn_expand.addEventListener('click', () => {\n      const weatherTyphLegendButton2 = document.querySelector(\n        '#weather-typh-legend-button2'\n      ) as any\n      const weatherTyphLegend = document.querySelector(\n        '#weather-typh-legend'\n      ) as HTMLDivElement\n\n      L.DomUtil.removeClass(weatherTyphLegendButton2, 'btn-left')\n      L.DomUtil.removeClass(weatherTyphLegendButton2, 'btn-right')\n\n      if (weatherTyphLegendButton2.name === 'a') {\n        weatherTyphLegendButton2.name = 'b'\n        L.DomUtil.addClass(weatherTyphLegendButton2, 'btn-left')\n        weatherTyphLegend.style.width = '310px'\n        weatherTyphLegend.style.height = '440px'\n        drawCanvasWind('b')\n      } else {\n        weatherTyphLegendButton2.name = 'a'\n        L.DomUtil.addClass(weatherTyphLegendButton2, 'btn-right')\n        weatherTyphLegend.style.width = '180px'\n        weatherTyphLegend.style.height = '400px'\n        drawCanvasWind('a')\n      }\n    })\n\n    return this\n  }\n}\n\nconst typhoonLegendImpl = (options?: TyphoonLegendOptions | undefined) =>\n  new TyphoonLegendControl(options)\nexport { TyphoonLegendControl, typhoonLegendImpl }\n"],"names":["p","o","Control","constructor","r","super","this","options","position","onAdd","_container","DomUtil","create","DomEvent","disableClickPropagation","_legend","id","_part1","_canvas","width","height","_strong","textContent","_btn_expand","name","show","s","document","querySelector","removeClass","addClass","addTo","a","l","e","getContext","g","m","d","v","n","t","strokeStyle","lineWidth","strokeRect","i","c","entries","save","beginPath","fillStyle","font","fillText","closePath","restore","arc","Math","PI","stroke","fill","moveTo","lineTo","lineCap","setLineDash","addEventListener","style","y","h"],"mappings":"uBAAuB,MAAMA,UAAUC,EAAEC,QAAQ,WAAAC,CAAYC,GAAGC,MAAMD,GAAGE,KAAKC,QAAQC,SAAS,UAAU,CAAC,KAAAC,GAAQ,OAAOH,KAAKI,WAAWT,EAAEU,QAAQC,OAAO,OAAOX,EAAEY,SAASC,wBAAwBR,KAAKI,YAAYJ,KAAKS,QAAQd,EAAEU,QAAQC,OAAO,MAAM,sBAAsBN,KAAKI,YAAYJ,KAAKS,QAAQC,GAAG,sBAAsBV,KAAKW,OAAOhB,EAAEU,QAAQC,OAAO,MAAM,aAAaN,KAAKS,SAAST,KAAKY,QAAQjB,EAAEU,QAAQC,OAAO,SAAS,GAAGN,KAAKS,SAAST,KAAKY,QAAQF,GAAG,eAAeV,KAAKY,QAAQC,MAAM,IAAIb,KAAKY,QAAQE,OAAO,IAAId,KAAKe,QAAQpB,EAAEU,QAAQC,OAAO,MAAM,YAAYN,KAAKW,QAAQX,KAAKe,QAAQC,YAAY,OAA2BhB,KAAKiB,YAAYtB,EAAEU,QAAQC,OAAO,MAAM,sBAAsBN,KAAKW,QAAQX,KAAKiB,YAAYP,GAAG,8BAA8BV,KAAKiB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