{"version":3,"file":"TyphonInfoList.mjs","sources":["../../../../../../../packages/sdk/plugins/weather/Typhoon/TyphonInfoList.ts"],"sourcesContent":["import L from 'leaflet'\nimport { isMobile } from '@map-sdk/hooks'\nimport { ShipxyOptions } from '@map-sdk/sdk/config'\nimport { CanvasShipUtils } from '@map-sdk/sdk/utils/CanvasShipUtils'\nimport { GetAllTyphoon } from '@map-sdk/sdk/plugins/weather/Typhoon/data'\nimport { typhoonLegendImpl } from '@map-sdk/sdk/plugins/weather/Typhoon/TyphoonLegendImpl'\nimport type { MyMap } from '@map-sdk/sdk/ShipxyAPISDK'\nimport type { TyphoonLegendControl } from '@map-sdk/sdk/plugins/weather/Typhoon/TyphoonLegendImpl'\n\ninterface TyphonInfoListOptions {\n  weatherService?: any\n  closeCallback?: () => void\n  noIngCallback?: () => void\n  cbLoadData?: (item: any, done: any) => void\n  showWarningLine?: boolean\n  showWinList: boolean\n  showLegendList?: boolean\n  showNameLess?: boolean\n  autoLocation?: boolean\n  weather?: {\n    typhoonListUrl: string\n    ak: string\n  }\n}\n// 更精确的类型取决于layer的真实内容\nconst layerTyPhon: Record<string, any> = {}\n/**\n * 台风信息列表\n */\nclass TyphonInfoList {\n  private options: TyphonInfoListOptions\n  private noteCheck: Record<string, any>\n  private isShow: boolean\n  private _map: MyMap\n  private warningLineLayer?: L.LayerGroup\n  private _legend!: TyphoonLegendControl\n  constructor(map: MyMap, options?: TyphonInfoListOptions) {\n    this.options = {\n      showWarningLine: true,\n      showWinList: true,\n      showLegendList: false,\n      showNameLess: true,\n      autoLocation: true,\n    }\n    L.Util.extend(this.options, options ?? {})\n    this.noteCheck = {}\n    this.isShow = true\n    this._map = map\n    this.setListWin1Show(this.options.showWinList)\n  }\n  private _init() {\n    this._drawWarningLine()\n    // const typhoonListUrl = ShipxyOptions.weather.typhoonListUrl.replace(\n    //   '{k}',\n    //   (this._map.options as any).ak\n    // )\n\n    // console.log('TODO: _init 未实现 获取全部台风', typhoonListUrl)\n    // const loadPromise = $.getJSON(typhoonListUrl).then((GetAllTyphoon) => {\n    if (GetAllTyphoon && GetAllTyphoon.status === 0 && GetAllTyphoon.data) {\n      const sortCallback = (keyCode: string, isString = false) =>\n        isString\n          ? (a: any, b: any) =>\n              Number(a[keyCode]) > Number(b[keyCode]) ? -1 : 1\n          : (a: any, b: any) => (a[keyCode] > b[keyCode] ? -1 : 1)\n\n      const resultObj: { [key: string]: any[] } = {}\n\n      GetAllTyphoon.data.forEach(\n        (item: { currentyear: any; enname: string }) => {\n          const currentyear = `year_${item.currentyear}`\n          resultObj[currentyear] = resultObj[currentyear] || []\n          this.noteCheck[currentyear] = []\n          if (this.options.showNameLess || item.enname !== 'NAMELESS') {\n            resultObj[currentyear].push(item)\n          }\n        }\n      )\n\n      for (const key in resultObj) {\n        const list = resultObj[key]\n        if (list && list.length > 0) {\n          resultObj[key] = list.sort(sortCallback('chncode', true))\n          resultObj[key] = list.sort(sortCallback('datamark'))\n        }\n      }\n      // this._defaultTest(resultObj)\n    } else {\n      console.error(GetAllTyphoon)\n    }\n  }\n\n  setListWin1Show(lineList: boolean) {\n    const typhoonListWin1Element = document.querySelector(\n      '#typhoonListWin1'\n    ) as HTMLDivElement\n    if (typhoonListWin1Element) {\n      if (lineList) {\n        typhoonListWin1Element.style.display = 'block' // 显示\n      } else {\n        typhoonListWin1Element.style.display = 'none' // 隐藏\n      }\n    }\n  }\n\n  /**\n   * 绘制警戒线\n   */\n  private _drawWarningLine() {\n    if (this.options.showWarningLine) {\n      this.warningLineLayer = L.layerGroup()\n      const layerGroup = L.layerGroup()\n\n      const polyline1 = [\n        L.latLng(0, 105),\n        L.latLng(4.5, 113),\n        L.latLng(11, 119),\n        L.latLng(18, 119),\n        L.latLng(22, 127),\n        L.latLng(34, 127),\n      ]\n      const polyline2 = [\n        L.latLng(0, 105),\n        L.latLng(0, 120),\n        L.latLng(15, 132),\n        L.latLng(34, 132),\n      ]\n\n      layerGroup.addLayer(\n        L.polyline(polyline1, {\n          color: '#BE621F',\n          weight: 2,\n        })\n      )\n      layerGroup.addLayer(\n        L.polyline(polyline2, {\n          color: '#BE621F',\n          weight: 2,\n          dashArray: [5, 5],\n        })\n      )\n\n      layerGroup.addLayer(\n        L.marker(L.latLng(28, 127), {\n          icon: L.icon({\n            iconUrl: ShipxyOptions.weather.hour24,\n            iconSize: [15, 89],\n            iconAnchor: [22, 94],\n            popupAnchor: [-3, -76],\n            shadowSize: [68, 95],\n            shadowAnchor: [22, 94],\n          }),\n        })\n      )\n\n      layerGroup.addLayer(\n        L.marker(L.latLng(25, 132), {\n          icon: L.icon({\n            iconUrl: ShipxyOptions.weather.hour48,\n            iconSize: [15, 89],\n            iconAnchor: [22, 94],\n            popupAnchor: [-3, -76],\n            shadowSize: [68, 95],\n            shadowAnchor: [22, 94],\n          }),\n        })\n      )\n\n      this.warningLineLayer.addLayer(layerGroup)\n      this._map.addLayer(this.warningLineLayer)\n\n      // 绘制台风图例\n      if (!isMobile) {\n        if (!this._legend) {\n          this._legend = typhoonLegendImpl()\n          this._legend.addTo(this._map)\n        }\n        this._legend.show(this.options.showLegendList)\n      }\n    }\n  }\n\n  public selectItem(item: any, isChecked = false) {\n    if (isChecked) {\n      CanvasShipUtils.openLoadingPopup(50, () => {\n        this._getTyphoonInfoByKey(item, (GetAllTyphoon, item, isParse) => {\n          if (isParse) {\n            GetAllTyphoon = this.options.weatherService._parseRawTyphoon(\n              GetAllTyphoon,\n              this.options\n            )\n          }\n          layerTyPhon[`layer_${item.id}`] =\n            this.options.weatherService.showTyphoon(\n              GetAllTyphoon,\n              item,\n              this.options\n            )\n          CanvasShipUtils.closeLoadingPopup()\n        })\n      })\n    } else {\n      this.options.weatherService.hideTyphoon(layerTyPhon[`layer_${item.id}`])\n    }\n  }\n\n  private _getTyphoonInfoByKey(\n    item: any,\n    cb: (GetAllTyphoon: any, item: any, isParse: boolean) => void\n  ) {\n    // const typhoonInfoUrl = ShipxyOptions.weather.typhoonInfoUrl\n\n    if (!this.options.cbLoadData) {\n      console.error('请配置 cbLoadData 回调方法')\n      return\n    }\n    this.options.cbLoadData(item, (data: any) => {\n      console.log(data, 'data')\n      cb(data, item, false)\n    })\n  }\n\n  show() {\n    this.isShow = true\n    this._show()\n  }\n\n  private _show() {\n    this._remove()\n    if (this.isShow) {\n      this._init()\n    }\n  }\n\n  remove() {\n    this.isShow = false\n    this._remove()\n  }\n  private mousewheelHandler(event: Event) {\n    event.stopPropagation()\n  }\n  private _remove() {\n    const typhoonListWin1 = document.querySelector('#typhoonListWin1')\n    if (typhoonListWin1) {\n      const typhoonListElement = document.querySelector('#typhoonList')\n      if (typhoonListElement) {\n        typhoonListElement.removeEventListener(\n          'mousewheel',\n          this.mousewheelHandler\n        )\n        typhoonListElement.removeEventListener(\n          'DOMMouseScroll',\n          this.mousewheelHandler\n        )\n      }\n      this.options.weatherService.hideTyphoon('all')\n      typhoonListWin1.remove()\n    }\n\n    if (this.warningLineLayer) {\n      this.warningLineLayer.clearLayers()\n    }\n    if (this._legend) {\n      this._legend.show(false)\n    }\n  }\n}\n\nconst typhoonInfoList = (\n  map: MyMap,\n  option: TyphonInfoListOptions | undefined\n) => new TyphonInfoList(map, option)\n\nexport { TyphonInfoList, typhoonInfoList }\n"],"names":["y","L","constructor","o","e","this","options","showWarningLine","showWinList","showLegendList","showNameLess","autoLocation","t","Util","extend","noteCheck","isShow","_map","setListWin1Show","_init","_drawWarningLine","a","status","data","n","i","s","r","Number","forEach","currentyear","enname","push","length","sort","document","querySelector","style","display","warningLineLayer","layerGroup","latLng","addLayer","polyline","color","weight","dashArray","marker","icon","iconUrl","p","weather","hour24","iconSize","iconAnchor","popupAnchor","shadowSize","shadowAnchor","hour48","c","_legend","d","addTo","show","selectItem","l","openLoadingPopup","_getTyphoonInfoByKey","weatherService","_parseRawTyphoon","id","showTyphoon","closeLoadingPopup","hideTyphoon","cbLoadData","_show","_remove","remove","mousewheelHandler","stopPropagation","removeEventListener","clearLayers","g","h"],"mappings":"8SAA+V,MAAMA,EAAE,CAA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