{"version":3,"file":"AttributionElane.mjs","sources":["../../../../../packages/sdk/plugins/AttributionElane.ts"],"sourcesContent":["/*\n * @Author: Yolo\n * @Date: 2024-03-26 11:45:29\n * @Last Modified by: Yolo\n * @Last Modified time: 2024-06-07 17:23:00\n * @describe 属性展示\n */\nimport L from 'leaflet'\nimport { type MyMap, ShipxyAPI } from '@map-sdk/sdk/ShipxyAPISDK'\n\ninterface AttributionElaneOptions extends L.Control.AttributionOptions {\n  emptyString?: string\n}\nclass AttributionElane extends L.Control.Attribution {\n  private _options: AttributionElaneOptions\n  private _container!: HTMLElement\n  constructor(options?: AttributionElaneOptions) {\n    super(options)\n    this._options = {\n      position: 'bottomright',\n      emptyString: 'shipxy ',\n      prefix: '',\n      ...options,\n    }\n    L.Util.setOptions(this, this._options)\n  }\n\n  private _onLayerChange(event: L.LayerEvent): void {\n    const layer = event.layer\n    if ((layer as any).getAttribution) {\n      if (event.type === 'layeradd') {\n        this.addAttribution((layer as any).getAttribution())\n      } else if (event.type === 'layerremove') {\n        this.removeAttribution((layer as any).getAttribution())\n      }\n    }\n  }\n\n  override onAdd(map: MyMap): HTMLElement {\n    const vMaj = Number.parseInt(L.version.split('.')[0])\n    if (vMaj >= 1) {\n      // Leaflet 1\n      map.attributionControl = this\n    }\n\n    if (this._options.emptyString && this._options.emptyString.length > 0)\n      this.options.prefix = this._options.emptyString\n\n    this._container = L.DomUtil.create('div', 'leaflet-control-attribution')\n    if (L.DomEvent) {\n      L.DomEvent.disableClickPropagation(this._container)\n    }\n\n    if (vMaj < 1) {\n      // Leaflet sub 1\n      map\n        .on('layeradd', this._onLayerChange, this)\n        .on('layerremove', this._onLayerChange, this)\n    }\n    map.eachLayer((layer) => {\n      if (layer.getAttribution) {\n        this.addAttribution((layer as any).getAttribution())\n      }\n    })\n    ;(this as any)._update()\n    L.DomUtil.addClass(this._container, 'leaflet-condensed-attribution')\n    return this._container\n  }\n}\n\nconst attributionElane = (options?: AttributionElaneOptions) => {\n  ShipxyAPI.Map.mergeOptions({\n    attributionControl: false,\n  })\n  return new AttributionElane(options)\n}\n\nexport default attributionElane\n"],"names":["a","i","Control","Attribution","constructor","t","super","this","_options","position","emptyString","prefix","Util","setOptions","_onLayerChange","n","layer","getAttribution","type","addAttribution","removeAttribution","onAdd","Number","parseInt","version","split","attributionControl","length","options","_container","DomUtil","create","DomEvent","disableClickPropagation","on","eachLayer","e","_update","addClass","o","r","Map","mergeOptions"],"mappings":"uEAA6E,MAAMA,UAAUC,EAAEC,QAAQC,YAAY,WAAAC,CAAYC,GAAGC,MAAMD,GAAGE,KAAKC,SAAS,CAACC,SAAS,cAAcC,YAAY,UAAUC,OAAO,MAAMN,GAAGJ,EAAEW,KAAKC,WAAWN,KAAKA,KAAKC,SAAS,CAAC,cAAAM,CAAeT,GAAG,MAAMU,EAAEV,EAAEW,MAAMD,EAAEE,iBAA0B,aAATZ,EAAEa,KAAkBX,KAAKY,eAAeJ,EAAEE,kBAA2B,gBAATZ,EAAEa,MAAsBX,KAAKa,kBAAkBL,EAAEE,kBAAkB,CAAC,KAAAI,CAAMhB,GAAG,MAAMU,EAAEO,OAAOC,SAAStB,EAAEuB,QAAQC,MAAM,KAAK,IAAI,OAAOV,GAAG,IAAIV,EAAEqB,mBAAmBnB,MAAMA,KAAKC,SAASE,aAAaH,KAAKC,SAASE,YAAYiB,OAAO,IAAIpB,KAAKqB,QAAQjB,OAAOJ,KAAKC,SAASE,aAAaH,KAAKsB,WAAW5B,EAAE6B,QAAQC,OAAO,MAAM,+BAA+B9B,EAAE+B,UAAU/B,EAAE+B,SAASC,wBAAwB1B,KAAKsB,YAAYd,EAAE,GAAGV,EAAE6B,GAAG,WAAW3B,KAAKO,eAAeP,MAAM2B,GAAG,cAAc3B,KAAKO,eAAeP,MAAMF,EAAE8B,WAAUC,IAAIA,EAAEnB,gBAAgBV,KAAKY,eAAeiB,EAAEnB,qBAAoBV,KAAK8B,UAAUpC,EAAE6B,QAAQQ,SAAS/B,KAAKsB,WAAW,iCAAiCtB,KAAKsB,UAAU,EAAoE,MAA1DU,IAAIC,EAAEC,IAAIC,aAAa,CAAChB,oBAAmB,IAAK,IAAI1B,EAAEuC"}