{"version":3,"file":"ShowWeatherTipMessage.mjs","sources":["../../../../../../../packages/sdk/plugins/weather/util/ShowWeatherTipMessage.ts"],"sourcesContent":["import L from 'leaflet'\nimport { throttle } from 'lodash-unified'\nimport type { MyMap } from '@map-sdk/sdk'\n\nclass ShowWeatherTipMessage {\n  private _map: any\n  lyGroup: L.LayerGroup = L.layerGroup()\n  clickLatLng!: L.LatLng\n  type!: string\n  infoDom!: HTMLElement\n  constructor(map: MyMap, type: string) {\n    const msgType = [\n      'showSeaBreeze',\n      'showWind',\n      'showSeaBreezeArrow',\n      'showHaiLang',\n      'showHL',\n      'showYangliu',\n      'showAirTemperature',\n      'showWaterTemperature',\n      'showAtmosphericPressure',\n      'showRainfall',\n      'showVisibility',\n    ]\n    if (!msgType.includes(type)) {\n      console.log('未找到对应图层的注册事件')\n      return\n    }\n    this._map = map\n    this.type = type\n    this.registerEvent()\n  }\n  showWeatherLayer(latlng: L.LatLngExpression) {\n    this.offRegisterEvent(false)\n    //添加一个120px\n    const point = this._map.latLngToLayerPoint(latlng)\n    const start = L.point(point.x, point.y - 7)\n    const end = L.point(point.x, point.y - 120)\n    const startLatLng = this._map.layerPointToLatLng(start)\n    const endLatLng = this._map.layerPointToLatLng(end)\n    const polyline = L.polyline([startLatLng, endLatLng], {\n      color: '#1d374c',\n      weight: 2,\n    })\n    const marker = L.circleMarker(latlng, {\n      radius: 6,\n      color: '#fff',\n      weight: 2,\n      fillOpacity: 1,\n    }).addTo(this._map)\n    // TODO: 获取点的气象数据 此处目前模拟 接口请求\n    const d = {\n      winddir: 12,\n      windspeed: 12,\n      oceandir: 1,\n      oceanspeed: 1,\n      waveheight: 1,\n      temperature: 1,\n      pressure: 1,\n    }\n    // <i class=\"layui-icon layui-icon-close-fill weather-shuiwen-close\"></i>\n    let html = `<div class=\"weather-shuiwen-container\">`\n    const commHtml = `<div class=\"other\">\n                        <div class=\"field\">流：<label style=\"display: inline-block;width:45px;\">${\n                          d.oceandir || '--'\n                        }°</label>${d.oceanspeed || '--'}米/秒</div>\n                        <div class=\"field\">浪：<label style=\"display: inline-block;width:45px;\">${\n                          d.waveheight || '--'\n                        }米</label>温：${d.temperature || '--'}℃</div>\n                        <div class=\"field\">压：${d.pressure || '--'}(hPa)</div>\n                      </div>`\n    switch (this.type) {\n      // 海风、风场\n      case 'showSeaBreeze':\n      case 'showWind':\n      case 'showSeaBreezeArrow':\n        html += `<div class=\"field short\">风：<label style=\"display: inline-block;width:45px;\">${\n          d.winddir || '--'\n        }°</label>${\n          this.changeWind(d.windspeed) || '--'\n        }<i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n        break\n      // 海浪\n      case 'showHaiLang':\n        html += `<div class=\"field short\">浪：${\n          d.waveheight || '--'\n        }米<i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n        break\n      // 海流、洋流\n      case 'showHL':\n      case 'showYangliu':\n        html += `<div class=\"field short\">流：<label style=\"display: inline-block;width:45px;\">${\n          d.oceandir || '--'\n        }°</label>${\n          d.oceanspeed || '--'\n        }米/秒<i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n        break\n      // 气温、水温\n      case 'showAirTemperature':\n      case 'showWaterTemperature':\n        html += `<div class=\"field short\">温：${\n          d.temperature || '--'\n        }℃ <i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n\n        break\n      // 气压\n      case 'showAtmosphericPressure':\n        html += `<div class=\"field short\">压：${\n          d.pressure || '--'\n        }(hPa) <i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n        break\n      // 降雨量\n      case 'showRainfall':\n        html += `<div class=\"field short\">降雨量：${\n          d.pressure || '--'\n        }(hPa) <i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n        break\n      // 能见度\n      case 'showVisibility':\n        html += `<div class=\"field short\">能见度：${\n          d.pressure || '--'\n        }(hPa) <i class=\"layui-icon layui-icon-down\"></i></div>${commHtml}`\n        break\n    }\n\n    html += `</div>` // <i class=\"layui-icon layui-icon-up\"></i>\n\n    marker.bindTooltip(html, {\n      direction: 'right',\n      offset: [-7, -10],\n      opacity: 1,\n      className: 'weather-shuiwen-tooltip',\n      permanent: true,\n      interactive: true,\n    })\n\n    this.lyGroup.addLayer(polyline)\n    this.lyGroup.addLayer(marker)\n    this.lyGroup.addTo(this._map)\n    marker.addTo(this._map)\n  }\n\n  private _Event = {\n    zoomEnd: () => {\n      this.clickLatLng && this.showWeatherLayer(this.clickLatLng)\n    },\n    click: (e: { latlng: L.LatLng }) => {\n      this.clickLatLng = e.latlng\n      this.showWeatherLayer(e.latlng)\n    },\n    mouseMove: throttle(\n      (e: { latlng: L.LatLng }) => this._renderHtml(e.latlng),\n      1000\n    ),\n  }\n\n  private _renderHtml = (latlng: L.LatLng) => {\n    const { lat, lng } = latlng\n    const data = {\n      WindSpeed: lat,\n      WindDir: lng,\n      WaveHeght: 1,\n      OceanSpeed: 1,\n      OceanDir: 1,\n      WaveDir: 1,\n      Temprature: 1,\n      Pressure: 1,\n    }\n\n    if (!this.infoDom) {\n      this.infoDom = L.DomUtil.create(\n        'div',\n        'weather-info-mousemove',\n        this._map._container\n      )\n      L.DomEvent.disableClickPropagation(this.infoDom)\n      L.DomEvent.disableScrollPropagation(this.infoDom)\n      new L.Draggable(this.infoDom).enable()\n    }\n    const html = `<div class=\"weather-title\">气象信息</div><div class=\"seamete_info_box\">\n                      <ul >\n                        <li>风速：<label id=\"WindSpeed\">${\n                          data.WindSpeed || '--'\n                        }</label></li>\n                        <li>风向：<label id=\"WindDir\">${\n                          data.WindDir || '--'\n                        }</label>度</li>\n                        <li>浪高：<label id=\"WaveHeght\">${\n                          data.WaveHeght || '--'\n                        }</label>米</li>\n                        <li>流速：<label id=\"OceanSpeed\">${\n                          data.OceanSpeed || '--'\n                        }</label>米/秒</li>\n                        <li>流向：<label id=\"OceanDir\">${\n                          data.OceanDir || '--'\n                        }</label>度</li>\n                        <li>浪向：<label id=\"WaveDir\">${\n                          data.WaveDir || '--'\n                        }</label>度</li>\n                        <li>温度：<label id=\"Temprature\">${\n                          data.Temprature || '--'\n                        }</label>摄氏度</li>\n                        <li>气压：<label id=\"Pressure\">${\n                          data.Pressure || '--'\n                        }</label>hPa</li>\n                      </ul>\n                    </div>`\n    this.infoDom.innerHTML = html\n  }\n\n  registerEvent() {\n    this.offRegisterEvent()\n    this._map.on('zoomend', this._Event.zoomEnd)\n\n    //地图点击事件\n    this._map.on('click', this._Event.click)\n\n    this._map.on('mousemove', this._Event.mouseMove)\n    this._renderHtml(this._map.getCenter())\n  }\n  offRegisterEvent(isClearEvent = true) {\n    this.lyGroup && this.lyGroup.clearLayers()\n    if (isClearEvent && this._map) {\n      this._map.off('zoomend', this._Event.zoomEnd)\n      this._map.off('click', this._Event.click)\n      this._map.off('mousemove', this._Event.mouseMove)\n      this.infoDom && L.DomUtil.remove(this.infoDom)\n    }\n  }\n\n  /**\n   * 气象信息 角度\n   * @param wind\n   * @returns\n   */\n  winddir(wind: string | number) {\n    wind = Number.parseFloat(`${wind}`)\n    if (wind > 0 && wind <= 22.5) {\n      return 'NNE'\n    } else if (wind > 22.5 && wind <= 45) {\n      return 'NE'\n    } else if (wind > 45 && wind <= 67.5) {\n      return 'ENE'\n    } else if (wind > 67.5 && wind <= 90) {\n      return 'E'\n    } else if (wind > 90 && wind <= 112.5) {\n      return 'ESE'\n    } else if (wind > 112.5 && wind <= 135) {\n      return 'SE'\n    } else if (wind > 135 && wind <= 157.5) {\n      return 'SSE'\n    } else if (wind > 157.5 && wind <= 180) {\n      return 'S'\n    } else if (wind > 180 && wind <= 202.5) {\n      return 'SSW'\n    } else if (wind > 202.5 && wind <= 225) {\n      return 'SW'\n    } else if (wind > 225 && wind <= 247.5) {\n      return 'WSW'\n    } else if (wind > 247.5 && wind <= 270) {\n      return 'W'\n    } else if (wind > 270 && wind <= 292.5) {\n      return 'WNW'\n    } else if (wind > 292.5 && wind <= 315) {\n      return 'NW'\n    } else if (wind > 315 && wind <= 337.5) {\n      return 'NNW'\n    } else if (wind > 337.5 && wind <= 360) {\n      return 'N'\n    } else {\n      return '-'\n    }\n  }\n  /**\n   * 气象风级\n   * @param wind\n   * @returns\n   */\n  private changeWind(wind: number) {\n    let i\n    wind = wind ? Number(Number.parseFloat(`${wind}`).toFixed(1)) : 0\n    if (wind > 0 && wind <= 1.5) {\n      i = 1\n    } else if (wind >= 1.6 && wind <= 3.3) {\n      i = 2\n    } else if (wind >= 3.4 && wind <= 5.4) {\n      i = 3\n    } else if (wind >= 5.5 && wind <= 7.9) {\n      i = 4\n    } else if (wind >= 8 && wind <= 10.7) {\n      i = 5\n    } else if (wind >= 10.8 && wind <= 13.8) {\n      i = 6\n    } else if (wind >= 13.9 && wind <= 17.1) {\n      i = 7\n    } else if (wind >= 17.2 && wind <= 20.7) {\n      i = 8\n    } else if (wind >= 20.8 && wind <= 24.4) {\n      i = 9\n    } else if (wind >= 24.5 && wind <= 28.4) {\n      i = 10\n    } else if (wind >= 28.5 && wind <= 32.6) {\n      i = 11\n    } else if (wind > 32.6) {\n      i = 12\n    }\n    return wind === 0 ? '--' : `${wind}米/秒 (${i || '--'}级风)`\n  }\n}\n\nconst showWeatherTipMessage = (map: MyMap, type: string) =>\n  new ShowWeatherTipMessage(map, type)\n\nexport { showWeatherTipMessage }\n"],"names":["f","constructor","e","i","this","lyGroup","a","layerGroup","_Event","zoomEnd","clickLatLng","showWeatherLayer","click","latlng","mouseMove","u","_renderHtml","lat","lng","o","t","infoDom","DomUtil","create","_map","_container","DomEvent","disableClickPropagation","disableScrollPropagation","Draggable","enable","n","innerHTML","includes","type","registerEvent","offRegisterEvent","latLngToLayerPoint","point","x","y","layerPointToLatLng","p","m","polyline","color","weight","h","circleMarker","radius","fillOpacity","addTo","l","r","changeWind","bindTooltip","direction","offset","opacity","className","permanent","interactive","addLayer","on","getCenter","clearLayers","off","remove","winddir","Number","parseFloat","toFixed","d","c"],"mappings":"iEAAiE,MAAMA,EAAE,WAAAC,CAAYC,EAAEC,GAAGC,KAAKC,QAAQC,EAAEC,aAA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