{"version":3,"file":"BaselinesAtSeaSymbol.mjs","sources":["../../../../../../../packages/sdk/plugins/AreaView/layer/BaselinesAtSeaSymbol.ts"],"sourcesContent":["/*\n * @Author: Yolo\n * @Date: 2024-07-02 09:10:08\n * @Last Modified by: Yolo\n * @Last Modified time: 2024-07-02 09:12:01\n * @Desc 中国领海基线\n */\nimport * as 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 { AreaViewBase } from '@map-sdk/sdk/plugins/AreaView/AreaViewBase'\nimport { baseLine } from '@map-sdk/sdk/plugins/AreaView/layer/BaselinesAtSeaSymbolData'\nimport type { AreaViewBaseOptions } from '@map-sdk/sdk/plugins/AreaView/AreaViewBase'\nimport type { MyMap } from '@map-sdk/sdk/ShipxyAPISDK'\n\ninterface BaselineOptions extends L.PolylineOptions {\n  colors?: string[]\n  data?: {\n    name?: string\n    points: { lat: number; lng: number }[]\n    options?: {\n      minZoom?: number\n    }\n  }\n}\n\ninterface BaselinePopupOptions {\n  className: string\n  closeButton?: boolean\n  offset?: [number, number]\n}\n\nclass BaselinesAtSeaSymbol extends AreaViewBase {\n  constructor(map: MyMap, options?: Partial<AreaViewBaseOptions>) {\n    super(map, options)\n    this._data = baseLine\n  }\n  _show(): this {\n    const defaultOption: L.PolylineOptions = {\n      dashArray: [5, 5],\n      weight: 2,\n    }\n\n    if (!this._data) {\n      console.error('区域图形展示，请求无数据！')\n      return this\n    }\n\n    this.options.colors ||= ['#CF0072', '#FFFF33']\n    let colors: string = this.options.colors![0]\n    let boundary0: string = ShipxyOptions.COM_IMG_BASE64.boundary_0\n    let sty = 'baseline-popup cfff'\n\n    if ('MT_SATELLITE' === this._map!.mapType) {\n      colors = this.options.colors![1]\n      boundary0 = ShipxyOptions.COM_IMG_BASE64.boundary_f\n      sty = 'baseline-popup c000'\n    }\n\n    for (let i = 0; i < this._data!.length; i++) {\n      const points = this._data![i].points\n      const pointsList: L.LatLngExpression[] = []\n\n      for (let j = 0; j < points.length; j++) {\n        const point = points[j]\n        const latLng = CanvasShipUtils.GPSEncryptByMapToLatLng(\n          L.latLng(point.lat, point.lng),\n          this._map!\n        )\n        if (!CommUtils.isEmpty(point.name)) {\n          if (\n            !(\n              this._data[i].options &&\n              this._data[i].options.minZoom &&\n              this._map!.getZoom() < this._data[i].options.minZoom\n            )\n          ) {\n            let max = 0\n            if (j > 0) {\n              const latLngToLayerPoint = this._map!.latLngToLayerPoint(\n                pointsList[pointsList.length - 1]\n              )\n              const pointLayerPoint = this._map!.latLngToLayerPoint(latLng)\n              max = Math.max(\n                Math.abs(latLngToLayerPoint.x - pointLayerPoint.x),\n                Math.abs(latLngToLayerPoint.y - pointLayerPoint.y)\n              )\n            }\n            if (max >= 20 || j === 0 || j === points.length - 1) {\n              this._areaLayers.push(\n                this._addOneMarker(point.name, latLng, boundary0, sty)\n              )\n            }\n          }\n        }\n        pointsList.push(latLng)\n      }\n\n      if (pointsList.length > 0) {\n        if (\n          !(\n            this._data[i].options &&\n            this._data[i].options.minZoom &&\n            this._map!.getZoom() < this._data[i].options.minZoom\n          )\n        ) {\n          const options: BaselineOptions = {\n            ...defaultOption,\n            ...this._data[i].options,\n          }\n          CommUtils.isEmpty(options.color) && (options.color = colors)\n          options.data = this._data[i]\n\n          const polyline = L.polyline(pointsList, options)\n          polyline.addTo(this._map!)\n\n          if (CommUtils.isEmpty(this._data[i].name)) {\n            polyline.bindPopup(\n              () => {\n                const html = `\n                <div class=\"box\">\n                  <div class=\"title\">${this._data[i].name}</div>\n                </div>\n              `\n                return html\n              },\n              {\n                className: 'area-popup',\n                closeButton: false,\n              }\n            )\n\n            polyline.on('mousemove', (e) => {\n              e.target.openPopup(e.latlng)\n            })\n\n            polyline.on('mouseout', (e) => {\n              e.target.closePopup()\n            })\n          }\n\n          this._areaLayers.push(polyline)\n        }\n      }\n    }\n\n    return this\n  }\n\n  /**\n   * 添加单个标记\n   * @param text 显示文本\n   * @param latlng 经纬度\n   * @param iconUrl 图标URL\n   * @param className 自定义class\n   */\n  _addOneMarker(\n    text: string,\n    latlng: L.LatLngLiteral | L.LatLng,\n    iconUrl: string,\n    className: string\n  ): L.Marker {\n    const markerOption: L.MarkerOptions = {\n      icon: L.icon({\n        iconUrl,\n        iconSize: [8, 16],\n        iconAnchor: [4, 16],\n      }),\n    }\n\n    const marker = L.marker(latlng, markerOption)\n\n    const textLength = CommUtils.calcStrLength(this._map!, text)\n    const popupOffset: [number, number] = [\n      Math.max(50, textLength) / 2 + 10,\n      10,\n    ]\n    const popupOptions: BaselinePopupOptions = {\n      className,\n      closeButton: false,\n      offset: popupOffset,\n    }\n\n    marker.bindPopup(() => {\n      const html = `\n        <div class=\"box\">\n          <div class=\"title\">${text}</div>\n        </div>\n      `\n      return html\n    }, popupOptions)\n\n    marker.on('mousemove', (e) => {\n      // marker, marker.getLatLng()\n      e.target.openPopup()\n    })\n\n    marker.addTo(this._map!)\n\n    return marker\n  }\n}\n\nconst baselinesAtSeaSymbol = (\n  map: MyMap,\n  options: Partial<AreaViewBaseOptions>\n) => new BaselinesAtSeaSymbol(map, options)\n\nexport { BaselinesAtSeaSymbol, baselinesAtSeaSymbol }\n"],"names":["L","b","constructor","a","e","super","this","_data","M","_show","m","dashArray","weight","options","colors","r","g","COM_IMG_BASE64","boundary_0","l","_map","mapType","boundary_f","t","length","p","points","n","o","s","i","y","GPSEncryptByMapToLatLng","h","latLng","lat","lng","c","isEmpty","name","minZoom","getZoom","u","_","latLngToLayerPoint","f","Math","max","abs","x","_areaLayers","push","_addOneMarker","color","data","polyline","addTo","bindPopup","className","closeButton","on","target","openPopup","latlng","closePopup","icon","iconUrl","iconSize","iconAnchor","marker","calcStrLength","offset","O","d"],"mappings":"yTAA8W,MAAMA,UAAUC,EAAE,WAAAC,CAAYC,EAAEC,GAAGC,MAAMF,EAAEC,GAAGE,KAAKC,MAAMC,CAAC,CAA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