{"version":3,"file":"ShowFullScreenTitleLayer.mjs","sources":["../../../../../../../packages/sdk/plugins/weather/util/ShowFullScreenTitleLayer.ts"],"sourcesContent":["import { toRaw, unref } from 'vue'\nimport L from 'leaflet'\nimport { ShipxyOptions } from '@map-sdk/sdk/config'\nimport { CanvasShipUtils } from '@map-sdk/sdk/utils/CanvasShipUtils'\nimport { CommUtils } from '@map-sdk/sdk/utils/CommUtils'\nimport { tileLayerFunctional } from '@map-sdk/sdk/plugins/weather/util/TileLayerFunctional'\nimport { showWeatherTipMessage } from './ShowWeatherTipMessage'\nimport type { MyMap } from '@map-sdk/sdk/ShipxyAPISDK'\nimport type { TileLayerFunctional } from '@map-sdk/sdk/plugins/weather/util/TileLayerFunctional'\n\nexport interface LTileLayerFunctionalOptions {\n  minZoom?: number\n  maxZoom?: number\n  subdomains?: string\n}\n\nclass ShowFullScreenTitleLayer {\n  options: LTileLayerFunctionalOptions\n  _map: MyMap\n  _weatherTileLayer: Record<string, TileLayerFunctional> = {}\n  weatherTitleLayerUrl: Record<string, Record<string, string>> = {\n    '0': {\n      url: ShipxyOptions.weather.waterTemperatureTitleUrl,\n      msgCode: 'showWaterTemperature',\n    },\n    '1': {\n      url: ShipxyOptions.weather.iceConditionTitleUrl,\n      msgCode: 'showIceCondition',\n    },\n    '2': { url: ShipxyOptions.weather.seaIceTitleUrl, msgCode: 'showSeaIce' },\n    '3': {\n      url: ShipxyOptions.weather.seaBreezeTitleUrl,\n      msgCode: 'showSeaBreezeArrow',\n    },\n    '4': {\n      url: ShipxyOptions.weather.seaBreezeArrowTitleUrl,\n      msgCode: 'showSeaBreezeArrow',\n    },\n    '5': {\n      url: ShipxyOptions.weather.rainfallTitleUrl,\n      msgCode: 'showRainfall',\n    },\n    '6': {\n      url: ShipxyOptions.weather.atmosphericPressureTitleUrl,\n      msgCode: 'showAtmosphericPressure',\n    },\n    '7': {\n      url: ShipxyOptions.weather.visibilityTitleUrl,\n      msgCode: 'showVisibility',\n    },\n    '8': {\n      url: ShipxyOptions.weather.airTemperatureTitleUrl,\n      msgCode: 'showAirTemperature',\n    },\n    '9': { url: ShipxyOptions.weather.seaWaveTitleUrl, msgCode: 'showHaiLang' },\n    '10': {\n      url: ShipxyOptions.weather.waveArrowTitleUrl,\n      msgCode: 'showHaiLang',\n    },\n  }\n  weatherEvent: Record<string, any> = {}\n  constructor(map: MyMap, options?: LTileLayerFunctionalOptions) {\n    this.options = L.Util.extend({}, options)\n    this._map = toRaw(unref(map))\n  }\n\n  showFullScreenTileLayer(\n    type: string,\n    timeStamps: any,\n    customTimes?: { [type: string]: { time: string } }\n  ) {\n    const layerNamesArray = type.split(',')\n    layerNamesArray.forEach((item) => {\n      this.hideFullScreenTileLayer(item)\n      if (timeStamps && timeStamps.length) {\n        const formattedTimes: string[] = []\n        const typeName = `type_${item}`\n        if (customTimes && customTimes[typeName]) {\n          formattedTimes.push(customTimes[typeName].time)\n        } else {\n          // 否则使用默认时间\n          formattedTimes.push(\n            `${CanvasShipUtils.dataFormat(new Date(), 'YYYY-MM-DD')} 20:00:00`\n          )\n        }\n        this._weatherTileLayer[`${item}`] = this._getFullScreenLayer(\n          item,\n          formattedTimes as any,\n          timeStamps\n        )\n        if (this._weatherTileLayer[`${item}`]) {\n          this._weatherTileLayer[`${item}`].addTo(this._map)\n          this._weatherTileLayer[`${item}`].bringToFront()\n        } else {\n          console.log('气象栅格图层，无数据！')\n        }\n      } else {\n        console.error('气象栅格图层，参数非法！')\n      }\n    })\n    this.weatherEvent[`${type}`] = showWeatherTipMessage(\n      this._map,\n      this.weatherTitleLayerUrl[layerNamesArray[0]].msgCode\n    )\n  }\n\n  hideFullScreenTileLayer(type?: string) {\n    if (type) {\n      const types = type.split(',')\n      this.weatherEvent[type] && this.weatherEvent[type].offRegisterEvent()\n      types.forEach((item) => {\n        console.log(this._weatherTileLayer, this._weatherTileLayer[item], item)\n        if (this._weatherTileLayer[item]) {\n          this._weatherTileLayer[item].remove()\n          delete this._weatherTileLayer[item]\n        }\n      })\n\n      return\n    }\n\n    Object.keys(this._weatherTileLayer).forEach((key) => {\n      this._weatherTileLayer[key].remove()\n      delete this._weatherTileLayer[key]\n    })\n    Object.keys(this.weatherEvent).forEach((key) => {\n      this.weatherEvent[key] && this.weatherEvent[key].offRegisterEvent()\n    })\n  }\n\n  _getFullScreenLayer(\n    type: string,\n    time: string,\n    data: any,\n    minZoom?: number,\n    maxZoom?: number\n  ): TileLayerFunctional {\n    const weatherTileUrl = this.weatherTitleLayerUrl[type].url\n      .replace('{k}', (this as any)._map.options.ak)\n      .replace('{type}', type)\n      .replace('{time}', time)\n      .replace('{year}', CommUtils.dataFormat(new Date(), 'YYYY'))\n      .replace('{forecasttime}', data)\n    minZoom = minZoom || 2\n    maxZoom = maxZoom || 7\n    return tileLayerFunctional(\n      (val) => {\n        return weatherTileUrl\n          .replace('{z}', val.zoom.toString())\n          .replace('{x}', val.tile.column.toString())\n          .replace('{y}', val.tile.row.toString())\n          .replace('{zl}', val.zoom.toString())\n      },\n      {\n        minZoom,\n        maxZoom,\n        subdomains: 'weatherTile',\n      }\n    )\n  }\n}\n\nconst showFullScreenTitleLayer = (\n  map: MyMap,\n  options?: LTileLayerFunctionalOptions\n) => new ShowFullScreenTitleLayer(map, options)\n\nexport { ShowFullScreenTitleLayer, showFullScreenTitleLayer }\n"],"names":["h","constructor","r","e","this","_weatherTileLayer","weatherTitleLayerUrl","url","i","weather","waterTemperatureTitleUrl","msgCode","iceConditionTitleUrl","seaIceTitleUrl","seaBreezeTitleUrl","seaBreezeArrowTitleUrl","rainfallTitleUrl","atmosphericPressureTitleUrl","visibilityTitleUrl","airTemperatureTitleUrl","seaWaveTitleUrl","waveArrowTitleUrl","weatherEvent","options","p","Util","extend","_map","w","c","showFullScreenTileLayer","t","s","split","forEach","a","hideFullScreenTileLayer","length","o","l","push","time","y","dataFormat","Date","_getFullScreenLayer","addTo","bringToFront","m","offRegisterEvent","remove","Object","keys","replace","ak","u","T","zoom","toString","tile","column","row","minZoom","maxZo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