{"version":3,"file":"AreaViewBase.mjs","sources":["../../../../../../packages/sdk/plugins/AreaView/AreaViewBase.ts"],"sourcesContent":["import * as L from 'leaflet'\nimport { CanvasShipUtils } from '@map-sdk/sdk/utils/CanvasShipUtils'\nimport { CommUtils } from '@map-sdk/sdk/utils/CommUtils'\nimport type { MyMap } from '@map-sdk/sdk/ShipxyAPISDK'\n\nexport interface AreaViewBaseOptions {\n  url: string\n  isShowName: boolean\n  minzoom: number\n  maxzoom: number\n  colors: string[]\n  viewZones: string\n  isZoomEnd: boolean\n  [key: string]: any\n}\n\nclass AreaViewBase {\n  public options: AreaViewBaseOptions\n  protected _isView = false\n  protected _map: MyMap\n  protected bounds: any[] = []\n  protected _areaLayers: L.Layer[] = []\n  protected _data: any | undefined // Record<string, SeaMapDataItem[]> | undefined\n\n  constructor(map: MyMap, options?: Partial<AreaViewBaseOptions>) {\n    this._isView = true\n    this._areaLayers = []\n    this._map = map\n    this.options = {\n      url: '',\n      isShowName: true,\n      minzoom: 3,\n      maxzoom: 9,\n      colors: ['#CF0072', '#FFFF33'],\n      viewZones: '',\n      isZoomEnd: true,\n    }\n\n    if (options?.value) {\n      this._data = options.value\n    }\n\n    L.Util.extend(this.options, options)\n\n    if (this.options.isZoomEnd) {\n      this._map.on('zoomend', () => this._showArea())\n      this._map.on('baselayerchange', () => this._showArea())\n    }\n  }\n\n  showArea(): this {\n    CanvasShipUtils.openLoadingPopup(50, () => {\n      this._isView = true\n      this._showArea()\n      CanvasShipUtils.closeLoadingPopup()\n    })\n\n    return this\n  }\n\n  protected _showArea(): this {\n    this._hideArea()\n    if (\n      this._map.getZoom() >= this.options.minzoom &&\n      this._map.getZoom() <= this.options.maxzoom &&\n      this._isView\n    ) {\n      if (\n        !this._data ||\n        (this._data.length === 0 && !CommUtils.isEmpty(this.options.url))\n      ) {\n        const url = this.options.url.replace(\n          '{k}',\n          this._map._options?.ak || ''\n        )\n        console.log('TODO: AreaViewBase', url)\n        fetch(url, {\n          method: 'GET',\n        })\n          .then((response) => {\n            if (!response.ok) {\n              throw new Error(\n                `Network response was not ok ${response.statusText}`\n              )\n            }\n            return response.json() // 解析 JSON 数据\n          })\n          .then((resData) => {\n            if (\n              resData &&\n              typeof resData.status === 'number' &&\n              resData.status === 0\n            ) {\n              this._data = resData.data\n            } else if (resData) {\n              this._data = resData\n            }\n            this._map.shipsService?.setZIndex()\n            ;(this as any)._show && (this as any)._show()\n          })\n      } else {\n        this._map.shipsService?.setZIndex()\n        this.bounds = []\n        ;(this as any)._show && (this as any)._show()\n      }\n      return this\n    }\n    return this\n  }\n\n  hideArea(): this {\n    this._isView = false\n    this._hideArea()\n    return this\n  }\n\n  protected _hideArea(): this {\n    if (!this._map.areaViewSymbol.hasView()) {\n      this._map.shipsService?.restoreZIndex()\n    }\n    if (this._areaLayers) {\n      for (let i = 0; i < this._areaLayers.length; i++) {\n        this._map.removeLayer(this._areaLayers[i])\n      }\n      this._areaLayers = []\n    }\n\n    ;(this as any)['_hide'] && (this as any)['_hide']()\n\n    return this\n  }\n\n  getViewState(): boolean {\n    return this._areaLayers && this._areaLayers.length > 0\n  }\n}\n\nexport { AreaViewBase }\n"],"names":["n","constructor","t","e","this","_isView","bounds","_areaLayers","_map","options","url","isShowName","minzoom","maxzoom","colors","viewZones","isZoomEnd","value","_data","r","Util","extend","on","_showArea","showArea","o","openLoadingPopup","closeLoadingPopup","_hideArea","getZoom","length","h","isEmpty","i","replace","_options","ak","fetch","method","then","s","ok","Error","statusText","json","a","status","data","shipsService","setZIndex","_show","hideArea","areaViewSymbol","hasView","restoreZIndex","removeLayer","_hide","getViewState"],"mappings":"kJAAwJ,MAAMA,EAAE,WAAAC,CAAYC,EAAEC,GAAGC,KAAKC,SAAQ,EAAGD,KAAKE,OAAO,GAAGF,KAAKG,YAAY,GAAGH,KAAKC,SAAQ,EAAGD,KAAKG,YAAY,GAAGH,KAAKI,KAAKN,EAAEE,KAAKK,QAAQ,CAACC,IAAI,GAAGC,YAAW,EAAGC,QAAQ,E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