{"version":3,"file":"SeaAreaForecastService.mjs","sources":["../../../../../../../packages/sdk/plugins/weather/Sea/SeaAreaForecastService.ts"],"sourcesContent":["import { merge } from 'lodash-unified'\nimport 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 type { MyMap } from '@map-sdk/sdk/ShipxyAPISDK'\n\nexport interface Weatherdetail {\n  forecastaging: string\n  meteorological: string\n  winddirection: string\n  windpower: string\n  waveheight: null\n  visibility: string\n  meteorological_icon?: string\n  imageUrl?: string\n  publishtime?: string\n}\n\nexport interface SeaForecastInterFaca {\n  seaarea: string\n  publishtime: string\n  centerlatitude: string | number\n  centerlongititude: string\n  weatherdetail: Array<Weatherdetail>\n  opacity: number\n  offset: number[]\n  direction: string\n  publishdate: Date | null\n  forecastaging_str: any\n  meteorological: string\n}\n\n/**\n * 海洋预报\n */\nclass SeaForecast implements SeaForecastInterFaca {\n  seaarea = ''\n  publishtime = ''\n  centerlatitude = ''\n  centerlongititude = ''\n  meteorological = ''\n  opacity = 0.9\n  offset = [0, 104]\n  direction = 'right'\n  weatherdetail: Array<Weatherdetail> = []\n  publishdate: Date | null = null\n  forecastaging_str: any\n}\n\nclass SeaAreaForecastService {\n  public static ajaxs: XMLHttpRequest[] = []\n  private _layerGroup: L.FeatureGroup\n  private _map: MyMap\n  private _seaForecasts_yanan: SeaForecastInterFaca[] = []\n  private _seaForecasts_jinhai: SeaForecastInterFaca[] = []\n  private _seaForecasts_yuanhai: SeaForecastInterFaca[] = []\n  private _seaForecasts: SeaForecastInterFaca[] = []\n  private callbackListener?: (params: any) => void\n\n  constructor(map: MyMap) {\n    this._map = map\n    this._layerGroup = L.featureGroup().addTo(map)\n  }\n\n  /**\n   * 添加气象图标显示\n   * @param type 1-沿岸天气，2-近海，3-远海 其他图层\n   * @param data\n   */\n  addSeaForecasts(type: number, data: SeaForecast[]) {\n    switch (type) {\n      //  沿岸天气\n      case 1:\n        this._seaForecasts_yanan = this._seaForecasts_yanan.concat(data)\n        break\n      //  近海\n      case 2:\n        this._seaForecasts_jinhai = this._seaForecasts_jinhai.concat(data)\n        break\n      //  远海\n      case 3:\n        this._seaForecasts_yuanhai = this._seaForecasts_yuanhai.concat(data)\n        break\n      default:\n        this._seaForecasts = this._seaForecasts.concat(data)\n    }\n    this._drawSeaForecasts()\n  }\n\n  _drawSeaForecast(data: SeaForecastInterFaca) {\n    if (data && data.weatherdetail && data.weatherdetail.length) {\n      const imageUrl = this._judgeImage(data.meteorological)\n      const iconUrl = `${ShipxyOptions.weather.icon_base_url}/${imageUrl.icon}`\n      let icon = L.icon({\n        iconUrl,\n        iconSize: [25, 25],\n      })\n      const marker = L.marker(\n        L.latLng(Number(data.centerlatitude), Number(data.centerlongititude)),\n        {}\n      )\n      marker.setIcon(icon)\n      marker.on('mouseover', () => {\n        icon = L.icon({\n          iconUrl,\n          iconSize: [40, 40],\n        })\n        marker.setIcon(icon)\n        this.callbackListener && this.callbackListener(mobisCbRes)\n      })\n      marker.on('mouseout', () => {\n        icon = L.icon({\n          iconUrl,\n          iconSize: [25, 25],\n        })\n        marker.setIcon(icon)\n      })\n      let width = '250px'\n      data\n      let url = `${ShipxyOptions.weather.icon_base_url}/${imageUrl.bg24}`\n      data.weatherdetail.length > 1 &&\n        ((url = `${ShipxyOptions.weather.icon_base_url}/${imageUrl.bg48}`),\n        (width = '308px')),\n        data.weatherdetail.length > 2 &&\n          ((url = `${ShipxyOptions.weather.icon_base_url}/${imageUrl.bg72}`),\n          (width = '474px'))\n\n      let html = `<div class=\"weather-tooltip\" style=\"background: url(${url}) no-repeat !important; width: ${width};\">\n                    <div class=\"area_info\">\n                      ${\n                        !CanvasShipUtils.isEmpty(data.seaarea) &&\n                        `<div class=\"title\">${data.seaarea}</div>`\n                      }\n                      ${\n                        !CanvasShipUtils.isEmpty(data.publishtime) &&\n                        `<div class=\"field yubaotime\">预报时间: ${data.publishtime}</div>`\n                      }\n                      <div class=\"field ml0\">${data.forecastaging_str}</div>\n                    </div>`\n\n      for (let i = 0; i < data.weatherdetail.length; i++) {\n        const weatherdetail = data.weatherdetail[i]\n        html += '<div class=\"day_info\">'\n        if (!CanvasShipUtils.isEmpty(weatherdetail.meteorological)) {\n          const imageUrl = this._judgeImage(\n            weatherdetail.meteorological_icon || ''\n          )\n          html += `<div class=\"field icon ml0\"><img src=\"${ShipxyOptions.weather.icon_base_url}/${imageUrl.icon_info}\"></div>`\n          data.weatherdetail[i].imageUrl = imageUrl\n        }\n        html += `<div class=\"field date ml0\">${weatherdetail.publishtime}</div>`\n        let className = ''\n        0 == i && (className = 'ml0')\n        if (!CanvasShipUtils.isEmpty(weatherdetail.meteorological))\n          html += `<div class=\"field ${className}\">天气：${weatherdetail.meteorological}</div>`\n        if (!CanvasShipUtils.isEmpty(weatherdetail.windpower))\n          html += `<div class=\"field ${className}\">风力：${weatherdetail.windpower}(级)</div>`\n        if (!CanvasShipUtils.isEmpty(weatherdetail.winddirection)) {\n          html += `<div class=\"field ${className}\">风向：${weatherdetail.winddirection}</div>`\n        }\n        if (!CanvasShipUtils.isEmpty(weatherdetail.visibility)) {\n          html += `<div class=\"field ${className}\">能见度：${weatherdetail.visibility}(千米)</div>`\n        }\n        if (!CanvasShipUtils.isEmpty(weatherdetail.waveheight))\n          html += `<div class=\"field ${className}\">浪高：${weatherdetail.waveheight}(米)</div>`\n        html += '</div>'\n      }\n      html += '</div>'\n      const mobisCbRes = merge(data, { background: url })\n      if (!isMobile.value) {\n        marker.bindTooltip(html, {\n          permanent: false,\n          opacity: 1,\n          offset: [20, -10], // Tooltip 相对于 Marker 的偏移量（像素），[水平偏移, 垂直偏移]\n          className: 'weather-bindTooltip',\n        })\n        const tooltip = marker.getTooltip() as any\n        if (tooltip) {\n          tooltip._initLayout()\n          tooltip._container.style.padding = 0\n          tooltip._container.style.border = 'none'\n          tooltip._container.style.background = 'transparent'\n          tooltip._container.style.boxShadow = 'none'\n        }\n      }\n      this._layerGroup.addLayer(marker)\n    }\n  }\n\n  _judgeImage(url: string) {\n    const key = url.split(' ')[0]\n    return key in ShipxyOptions.weather.icon_types\n      ? (ShipxyOptions.weather.icon_types as any)[key]\n      : ShipxyOptions.weather.icon_types.多云\n  }\n\n  _drawSeaForecasts() {\n    this._layerGroup.remove()\n    this._layerGroup = L.featureGroup().addTo(this._map)\n    const zoom = this._map.getZoom()\n    if (zoom >= 6) {\n      for (let i = 0; i < this._seaForecasts_yanan.length; i++)\n        this._drawSeaForecast(this._seaForecasts_yanan[i])\n    }\n    if (zoom >= 4) {\n      for (let i = 0; i < this._seaForecasts_jinhai.length; i++)\n        this._drawSeaForecast(this._seaForecasts_jinhai[i])\n    }\n    if (zoom >= 1) {\n      for (let i = 0; i < this._seaForecasts_yuanhai.length; i++)\n        this._drawSeaForecast(this._seaForecasts_yuanhai[i])\n    }\n    for (let i = 0; i < this._seaForecasts.length; i++)\n      this._drawSeaForecast(this._seaForecasts[i])\n  }\n\n  close() {\n    if (this._layerGroup) {\n      this._layerGroup.remove()\n      this._seaForecasts = []\n    }\n    this.removeEventCallbackListener()\n  }\n  addEventCallbackListener(listener: (params: any) => void) {\n    this.callbackListener = listener\n  }\n  removeEventCallbackListener() {\n    this.callbackListener = undefined\n  }\n}\n\n// 导出 SeaAreaForecastService 类，以便在其他模块中使用\nexport { SeaAreaForecastService, SeaForecast }\n"],"names":["b","constructor","this","seaarea","publishtime","centerlatitude","centerlongititude","meteorological","opacity","offset","direction","weatherdetail","publishdate","g","e","_seaForecasts_yanan","_seaForecasts_jinhai","_seaForecasts_yuanhai","_seaForecasts","_map","_layerGroup","c","featureGroup","addTo","addSeaForecasts","i","concat","_drawSeaForecasts","_drawSeaForecast","length","_judgeImage","_","o","weather","icon_base_url","icon","h","iconUrl","iconSize","r","marker","latLng","Number","setIcon","on","callbackListener","y","p","d","bg24","bg48","bg72","s","n","isEmpty","forecastaging_str","a","t","m","meteorological_icon","icon_info","imageUrl","l","windpower","winddirection","visibility","waveheight","f","background","v","value","bindTooltip","permanent","className","getTooltip","_initLayout","_container","style","padding","border","boxShadow","addLayer","split","icon_types","remove","getZoom","close","removeEventCallbackListener","addEventCallbackListener","ajaxs"],"mappings":"8OAAiO,MAAMA,EAAE,WAAAC,GAAcC,KAAKC,QAAQ,GAAGD,KAAKE,YAAY,GAAGF,KAAKG,eAAe,GAAGH,KAAKI,kBAAkB,GAAGJ,KAAKK,eAAe,GAAGL,KAAKM,QAAQ,GAAGN,KAAKO,OAAO,CAAC,EAAE,KAAKP,KAAKQ,UAAU,QAAQR,KAAKS,cAAc,GAAGT,KAAKU,YAAY,IAAI,EAAE,MAAMC,EAAE,WAAAZ,CAAYa,GAAGZ,KAAKa,oBAAoB,GAAGb,KAAKc,qBAAqB,GAAGd,KAAKe,sBAAsB,GAAGf,KAAKgB,cAAc,GAAGhB,KAAKiB,KAAKL,EAAEZ,KAAKkB,YAAYC,EAAEC,eAAeC,MAAMT,EAAE,CAAC,eAAAU,CAAgBV,EAAEW,GAAG,OAAOX,GAAG,KAAK,EAAEZ,KAAKa,oBAAoBb,KAAKa,oBAAoBW,OAAOD,GAAG,MAAM,KAAK,EAAEvB,KAAKc,qBAAqBd,KAAKc,qBAAqBU,OAAOD,GAAG,MAAM,KAAK,EAAEvB,KAAKe,sBAAsBf,KAAKe,sBAAsBS,OAAOD,GAAG,MAAM,QAAQvB,KAAKgB,cAAchB,KAAKgB,cAAcQ,OAAOD,GAAGvB,KAAKyB,mBAAmB,CAAC,gBAAAC,CAAiBd,GAAG,GAAGA,GAAGA,EAAEH,eAAeG,EAAEH,cAAckB,OAAO,CAAC,MAAMJ,EAAEvB,KAAK4B,YAAYhB,EAAEP,gBAAgBwB,EAAE,GAAGC,EAAEC,QAAQC,iBAAiBT,EAAEU,OAAO,IAAIC,EAAEf,EAAEc,KAAK,CAACE,QAAQN,EAAEO,SAAS,CAAC,GAAG,MAAM,MAAMC,EAAElB,EAAEmB,OAAOnB,E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