{"version":3,"file":"AisManager.mjs","sources":["../../../../../../packages/sdk/plugins/Ais/AisManager.ts"],"sourcesContent":["/*\n * @Author: Yolo\n * @Date: 2024-07-09 15:48:52\n * @Last Modified by: Yolo\n * @Last Modified time: 2024-07-19 09:39:08\n * @Desc ais 图层工具类\n */\nimport { toRaw } from 'vue'\nimport L from 'leaflet'\nimport { merge } from 'lodash-unified'\nimport type { CanvasShip } from '@map-sdk/sdk/model/CanvasShip'\nimport type { MyMap } from '@map-sdk/sdk'\n\ninterface AisManageOptions {\n  aisLayerUrl: string\n  aisLayerOptions: L.TileLayerOptions\n  loadAisShipUrl: string\n  aisLayerMinZoom: number\n  aisLayerMaxZoom: number\n  showAisShipZoom: number\n  loadAisShip?: (params: L.LatLngBounds, done: (shipList: any) => void) => void\n}\n\nclass AisManager {\n  map: any\n  options: AisManageOptions = {\n    aisLayerUrl: 'https://api.xplusship.com/aismap/ac1/{x}/{y}/{z}.png',\n    aisLayerOptions: { minZoom: 0, maxZoom: 9, attribution: '' },\n    loadAisShipUrl: '',\n    aisLayerMinZoom: 3,\n    aisLayerMaxZoom: 18,\n    showAisShipZoom: 9,\n  }\n  aisLayer!: L.TileLayer\n  constructor(map: MyMap, options: Partial<AisManageOptions> = {}) {\n    this.map = toRaw<MyMap>(map)\n    this.options = merge(this.options, options)\n  }\n\n  private _done(shipList: CanvasShip[]) {\n    if (shipList.length) {\n      this.map.shipsService.addSpecialShips(toRaw(shipList))\n    }\n  }\n\n  private async _addAisLayer(zoom: number) {\n    if (\n      zoom > this.options.aisLayerMinZoom &&\n      zoom < this.options.aisLayerMaxZoom\n    ) {\n      if (zoom < this.options.showAisShipZoom) {\n        this.map.shipsService.deleteSpecialShips(true)\n        if (!this.aisLayer) {\n          this.aisLayer = L.tileLayer(\n            this.options.aisLayerUrl,\n            this.options.aisLayerOptions\n          )\n        }\n        this.map.addLayer(this.aisLayer)\n      } else {\n        this.map.removeLayer(this.aisLayer)\n        this.options.loadAisShip &&\n          this.options.loadAisShip(this.map.getBounds(), this._done)\n      }\n    } else {\n      this.hide(false)\n    }\n  }\n  private _Event = {\n    zoomend: (e: any) => this._addAisLayer(e.target._zoom),\n  }\n\n  show() {\n    if (!this.map) return\n    this._addAisLayer(this.map.getZoom())\n    this.map.on('zoomend', this._Event.zoomend)\n  }\n\n  hide(isRemoveOn = true) {\n    if (this.aisLayer) {\n      this.map.removeLayer(this.aisLayer)\n      if (isRemoveOn) {\n        this.map.off('zoomend', this._Event.zoomend)\n      }\n      this.map.shipsService.deleteSpecialShips(true)\n    }\n  }\n}\n\nexport { AisManager, type AisManageOptions }\n"],"names":["t","constructor","i","a","this","options","aisLayerUrl","aisLayerOptions","minZoom","maxZoom","attribution","loadAisShipUrl","aisLayerMinZoom","aisLayerMaxZoom","showAisShipZoom","_Event","zoomend","_addAisLayer","target","_zoom","map","s","o","_done","length","shipsService","addSpecialShips","deleteSpecialShips","aisLayer","e","tileLayer","addLayer","removeLayer","loadAisShip","getBounds","hide","show","getZoom","on","off"],"mappings":"0FAA0F,MAAMA,EAAE,WAAAC,CAAYC,EAAEC,EAAE,CAAE,GAAEC,KAAKC,QAAQ,CAACC,YAAY,uDAAuDC,gBAAgB,CAACC,QAAQ,EAAEC,QAAQ,EAAEC,YAAY,IAAIC,eAAe,GAAGC,gBAAgB,EAAEC,gBAAgB,GAAGC,gBAAgB,GAAGV,KAAKW,OAAO,CAACC,QAAQd,GAAGE,KAAKa,aAAaf,EAAEgB,OAAOC,QAAQf,KAAKgB,IAAIC,EAAEnB,GAAGE,KAAKC,QAAQiB,EAAElB,KAAKC,QAAQF,EAAE,CAAC,KAAAoB,CAAMrB,GAAGA,EAAEsB,QAAQpB,KAAKgB,IAAIK,aAAaC,gBAAgBL,EAAEnB,GAAG,CAAC,kBAAMe,CAAaf,GAAGA,EAAEE,KAAKC,QAAQO,iBAAiBV,EAAEE,KAAKC,QAAQQ,gBAAgBX,EAAEE,KAAKC,QAAQS,iBAAiBV,KAAKgB,IAAIK,aAAaE,oB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