{"version":3,"file":"WeatherWind.mjs","sources":["../../../../../../../packages/sdk/plugins/weather/Weather/WeatherWind.ts"],"sourcesContent":["import * as L from 'leaflet'\n\nclass WeatherWind extends L.Path {\n  private _latlng: L.LatLng\n  private _size: number\n  private _direction: number\n  private _windSymbol: any // ([number, number])[] | ([number, number, number, number])[] | ([number, number, number, number, number, number])[] ;\n\n  constructor(latlng: L.LatLng, options?: WeatherWindOptions) {\n    super()\n    L.setOptions(this, options)\n    this._latlng = L.latLng(latlng)\n    this._size = options?.size || 16\n    this._direction = ((options?.direction || 0) * Math.PI) / 180\n    this._windSymbol = [\n      [0.5, 0, -0.5, 0],\n      [-0.3, 0.2, -0.5, 0, -0.3, -0.2],\n      [0.5, 0, 0.5, -0.2 * 2],\n    ]\n\n    options?.speed ||\n      (4 > 4 && this._windSymbol.push([0.25, 0, 0.25, -0.2 * 2]))\n    options?.speed || (4 > 8 && this._windSymbol.push([0, 0, 0, -0.2 * 1]))\n\n    this.setStroke(options?.stroke || !0)\n    this.setColor(options?.color || '#ff0000')\n    this.setWeight(options?.weight || 1)\n  }\n\n  setColor(color: string): this {\n    this.setStyle({ color })\n    return this.redraw()\n  }\n\n  setFillOpacity(fillOpacity: number): this {\n    this.setStyle({ fillOpacity })\n    return this.redraw()\n  }\n\n  setOpacity(opacity: number): this {\n    this.setStyle({ opacity })\n    return this.redraw()\n  }\n\n  setWeight(weight: number): this {\n    this.setStyle({ weight })\n    return this.redraw()\n  }\n\n  setFill(fill: boolean): this {\n    this.setStyle({ fill })\n    return this.redraw()\n  }\n\n  setStroke(stroke: boolean): this {\n    this.setStyle({ stroke })\n    return this.redraw()\n  }\n\n  setLatLng(latLng: L.LatLng): this {\n    const oldLatLng = this._latlng\n    this._latlng = latLng\n    this.fire('move', { oldLatLng, latlng: this._latlng })\n    return this.redraw()\n  }\n\n  setDirection(direction: number): this {\n    this._direction = direction\n    return this.redraw()\n  }\n  _project() {\n    console.log('object')\n  }\n  _update() {\n    this._setPath()\n  }\n  _setPath() {\n    ;(this as any)._path.setAttribute('d', this.getPathString())\n  }\n  _getLatSize() {\n    return this._getLatSizeOf(this._size)\n  }\n  _getLngSize() {\n    return this._getLngSizeOf(this._size)\n  }\n  _getLatSizeOf(size: number) {\n    return (size / 40075017) * 360\n  }\n  _getLngSizeOf(size: number) {\n    return (\n      ((size / 40075017) * 360) / Math.cos((Math.PI / 180) * this._latlng.lat)\n    )\n  }\n  getLatLng() {\n    return this._latlng\n  }\n  // 旋转单个数据点\n  private rotate(point: [number, number], viewAngle: number): [number, number] {\n    const [itemX, itemY] = point\n    const sinViewAngle = Math.sin(viewAngle)\n    const cosViewAngle = Math.cos(viewAngle)\n    return [\n      itemX * cosViewAngle - itemY * sinViewAngle,\n      itemX * sinViewAngle + itemY * cosViewAngle,\n    ]\n  }\n  // 旋转一组数据点\n  private _rotateAllPoints(\n    points: [number, number][],\n    viewAngle: number\n  ): number[] {\n    const rotatedPoints: number[] = []\n    for (let i = 0; i < points.length; i += 2) {\n      // const [itemX, itemY] = points[i]\n      const item = (points as any)[i + 0] * this._size\n      const nextItem = (points as any)[i + 1] * this._size\n      const rotatedPoint = this.rotate([item, nextItem], viewAngle)\n      rotatedPoints.push(rotatedPoint[0], rotatedPoint[1])\n    }\n    return rotatedPoints\n  }\n  // 将所有点转换到视图坐标系\n  private _transformAllPointsToView(points: number[]): number[] {\n    const latLngPoint = this._map.latLngToLayerPoint(this._latlng)\n    const transformedPoints: number[] = []\n    for (let i = 0; i < points.length; i += 2) {\n      const x = points[i] + latLngPoint.x\n      const y = -points[i + 1] + latLngPoint.y\n      transformedPoints.push(x, y)\n    }\n    return transformedPoints\n  }\n  // 从点创建路径字符串\n  private _createPathFromPoints(points: number[]): string {\n    let pathString: string | undefined = `M${points[0]} ${points[1]}`\n    for (let i = 2; i < points.length; i += 2) {\n      pathString += ` L${points[i]} ${points[i + 1]}`\n    }\n    return pathString\n  }\n  // 从模型方向获取视图角度\n  private _getViewAngleFromModel(direction: number): number {\n    return Math.PI / 2 - direction\n  }\n  // 调整并移动点大小\n  private _resizeAndMovePoint(\n    point: [number, number],\n    resizeFactor: [number, number],\n    offset: [number, number]\n  ): [number, number] {\n    return [\n      point[0] * resizeFactor[0] + offset[0],\n      point[1] * resizeFactor[1] + offset[1],\n    ]\n  }\n  private _createWindPathString(): string {\n    let pathString = ''\n    const viewAngle = this._getViewAngleFromModel(this._direction)\n    for (let i = 0; i < this._windSymbol.length; ++i) {\n      const rotates = this._transformAllPointsToView(\n        this._rotateAllPoints(this._windSymbol[i], viewAngle)\n      )\n      0 == i\n        ? (pathString = this._createPathFromPoints(rotates))\n        : (pathString += ` ${this._createPathFromPoints(rotates)}`)\n    }\n    return pathString\n  }\n  getPathString(): string {\n    return this._createWindPathString()\n  }\n}\n\n// 定义 WeatherWindOptions 接口\nexport interface WeatherWindOptions extends L.PathOptions {\n  size?: number\n  direction?: number\n  speed: number\n  stroke?: boolean\n  color?: string\n  weight?: number\n  fillColor?: string\n}\n\n// 定义 L.weatherWind 工厂函数\nfunction weatherWind(\n  latlng: L.LatLng,\n  options?: WeatherWindOptions\n): WeatherWind {\n  return new WeatherWind(latlng, options)\n}\nexport default weatherWind\n"],"names":["g","a","Path","constructor","t","e","super","setOptions","this","_latlng","latLng","_size","size","_direction","direction","Math","PI","_windSymbol","speed","setStroke","stroke","setColor","color","setWeight","weight","setStyle","redraw","setFillOpacity","fillOpacity","setOpacity","opacity","setFill","fill","setLatLng","fire","oldLatLng","latlng","setDirection","_project","_update","_setPath","_path","setAttribute","getPathString","_getLatSize","_getLatSizeOf","_getLngSize","_getLngSizeOf","cos","lat","getLatLng","rotate","r","n","i","sin","s","_rotateAllPoints","length","u","push","_transformAllPointsToView","_map","latLngToLayerPoint","x","y","_createPathFromPoints","_getViewAngleFromModel","_resizeAndMovePoint","_createWindPathString","m","h","l"],"mappings":"0BAA0B,MAAMA,UAAUC,EAAEC,KAAK,WAAAC,CAAYC,EAAEC,GAAGC,QAAQL,EAAEM,WAAWC,KAAKH,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