{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/primitive-collections/billboard-collection/index.ts"],"sourcesContent":["import type { PropType, VNode, WatchStopHandle } from 'vue'\nimport { createCommentVNode, defineComponent, getCurrentInstance, h, onUnmounted, watch } from 'vue'\nimport { VcComponentInternalInstance, VcComponentPublicInstance, VcPickEvent, VcReadyObject } from 'casc-cesium-utils/types'\nimport { usePrimitiveCollections } from 'casc-cesium-composables'\nimport { cloneDeep, differenceBy } from 'lodash-unified'\nimport { scene, blendOption, show, enableMouseEvent, debugShowBoundingVolume, modelMatrix } from 'casc-cesium-utils/cesium-props'\nimport { addCustomProperty, kebabCase } from 'casc-cesium-utils/util'\nimport { hSlot } from 'casc-cesium-utils/private/render'\nimport { primitiveCollectionEmits } from 'casc-cesium-utils/emits'\nimport { VcBillboardProps } from '../billboard'\n\nexport const billboardCollectionProps = {\n  ...scene,\n  ...blendOption,\n  ...show,\n  ...enableMouseEvent,\n  ...modelMatrix,\n  ...debugShowBoundingVolume,\n  billboards: {\n    type: Array as PropType<Array<VcBillboardProps>>,\n    default: () => []\n  }\n}\nexport default defineComponent({\n  name: 'VcCollectionBillboard',\n  props: billboardCollectionProps,\n  emits: primitiveCollectionEmits,\n  setup(props, ctx) {\n    // state\n    const instance = getCurrentInstance() as VcComponentInternalInstance\n    instance.cesiumClass = 'BillboardCollection'\n    const primitiveCollectionsState = usePrimitiveCollections(props, ctx, instance)\n\n    // watcher\n    let unwatchFns: Array<WatchStopHandle> = []\n    unwatchFns.push(\n      watch(\n        () => cloneDeep(props.billboards),\n        (newVal, oldVal) => {\n          if (!instance.mounted) {\n            return\n          }\n          const billboardCollection = instance.cesiumObject as Cesium.BillboardCollection\n          if (newVal.length === oldVal.length) {\n            // 视为修改操作\n            // Treated as modified\n            const modifies: Array<any> = []\n            for (let i = 0; i < newVal.length; i++) {\n              const options = newVal[i]\n              const oldOptions = oldVal[i]\n\n              if (JSON.stringify(options) !== JSON.stringify(oldOptions)) {\n                modifies.push({\n                  newOptions: options,\n                  oldOptions: oldOptions\n                })\n              }\n            }\n\n            modifies.forEach(modify => {\n              const modifyBillboard = billboardCollection._billboards.find(v => v.id === modify.oldOptions.id)\n              modifyBillboard &&\n                Object.keys(modify.newOptions).forEach(prop => {\n                  if (modify.oldOptions[prop] !== modify.newOptions[prop]) {\n                    modifyBillboard[prop] = primitiveCollectionsState?.transformProp(prop, modify.newOptions[prop])\n                  }\n                })\n            })\n          } else {\n            const addeds: any = differenceBy(newVal, oldVal, 'id')\n            const deletes: any = differenceBy(oldVal, newVal, 'id')\n            const deleteBillboards: Array<Cesium.Billboard> = []\n            for (let i = 0; i < deletes.length; i++) {\n              const deleteBillboard = billboardCollection._billboards.find(v => v.id === deletes[i].id)\n              deleteBillboard && deleteBillboards.push(deleteBillboard)\n            }\n\n            deleteBillboards.forEach(v => {\n              billboardCollection.remove(v)\n            })\n            addBillboards(billboardCollection, addeds)\n          }\n        },\n        {\n          deep: true\n        }\n      )\n    )\n    instance.alreadyListening.push('billboards')\n    // methods\n    const addBillboards = (billboardCollection: Cesium.BillboardCollection, billboards) => {\n      for (let i = 0; i < billboards.length; i++) {\n        const billboardOptions = billboards[i] as Cesium.Billboard\n        billboardOptions.id = Cesium.defined(billboardOptions.id) ? billboardOptions.id : Cesium.createGuid()\n        const billboardOptionsTransform = primitiveCollectionsState?.transformProps(billboardOptions)\n        const billboard = billboardCollection.add(billboardOptionsTransform)\n        addCustomProperty(billboard, billboardOptionsTransform)\n      }\n    }\n    instance.createCesiumObject = async () => {\n      const options = primitiveCollectionsState?.transformProps(props)\n      const billboardCollection = new Cesium.BillboardCollection(options)\n      addBillboards(billboardCollection, props.billboards)\n      return billboardCollection\n    }\n\n    // life cycle\n    onUnmounted(() => {\n      unwatchFns.forEach(item => item())\n      unwatchFns = []\n    })\n\n    return () =>\n      ctx.slots.default\n        ? h(\n            'i',\n            {\n              class: kebabCase(instance.proxy?.$options.name || ''),\n              style: { display: 'none !important' }\n            },\n            hSlot(ctx.slots.default)\n          )\n        : createCommentVNode(kebabCase(instance.proxy?.$options.name || ''))\n  }\n})\n\nexport type VcCollectionBillboardProps = {\n  /**\n   * Must be passed in for billboards that use the height reference property or will be depth tested against the globe.\n   */\n  scene?: Cesium.Scene\n  /**\n   * The billboard blending option. The default is used for rendering both opaque and translucent billboards. However, if either all of the billboards are completely opaque or all are completely translucent, setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.\n   */\n  blendOption?: number | Cesium.BlendOption\n  /**\n   * Determines if the billboards in the collection will be shown.\n   * Default Value: true\n   */\n  show?: boolean\n  /**\n   * The 4x4 transformation matrix that transforms each billboard from model to world coordinates.\n   */\n  modelMatrix?: Cesium.Matrix4\n  /**\n   * For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n   * Default Value: false\n   */\n  debugShowBoundingVolume?: boolean\n  /**\n   * Specifies whether to respond to mouse pick events.\n   * Default Value: true\n   */\n  enableMouseEvent?: boolean\n  /**\n   * Specify an array of billboard collections. The structure of the array object is the same as the attribute of the [vc-billboard](https://zouyaoji.top/vue-cesium/#/en-US/component/primitives/vc-collection-billboard#vcbillboard-props) component.\n   */\n  billboards?: Array<VcBillboardProps>\n  /**\n   * Triggers before the VcCollectionBillboard is loaded.\n   */\n  onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the VcCollectionBillboard is successfully loaded.\n   */\n  onReady?: (readyObject: VcReadyObject) => void\n  /**\n   * Triggers when the component load failed.\n   */\n  onUnready?: (e: any) => void\n  /**\n   * Triggers when the VcCollectionBillboard is destroyed.\n   */\n  onDestroyed?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the mouse is pressed on this collection.\n   */\n  onMousedown?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse bounces up on this collection.\n   */\n  onMouseup?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse clicks on this collection.\n   */\n  onClick?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse clicks outside this collection.\n   */\n  onClickout?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the left mouse button double-clicks this collection.\n   */\n  onDblclick?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse moves on this collection.\n   */\n  onMousemove?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse moves over to this collection.\n   */\n  onMouseover?: (evt: VcPickEvent) => void\n  /**\n   *  Triggers when the mouse moves out of this collection.\n   */\n  onMouseout?: (evt: VcPickEvent) => void\n}\n\nexport type VcCollectionBillboardRef = VcComponentPublicInstance<VcCollectionBillboardProps>\n\nexport interface VcCollectionBillboardSlots {\n  /**\n   * Slot for vc-billboard.\n   */\n  default: () => VNode[]\n}\n"],"names":[],"mappings":";;;;;;;;;AAOY,MAAC,wBAAwB,GAAG;AACxC,EAAE,GAAG,KAAK;AACV,EAAE,GAAG,WAAW;AAChB,EAAE,GAAG,IAAI;AACT,EAAE,GAAG,gBAAgB;AACrB,EAAE,GAAG,WAAW;AAChB,EAAE,GAAG,uBAAuB;AAC5B,EAAE,UAAU,EAAE;AACd,IAAI,IAAI,EAAE,KAAK;AACf,IAAI,OAAO,EAAE,MAAM,EAAE;AACrB,GAAG;AACH,EAAE;AACF,0BAAe,eAAe,CAAC;AAC/B,EAAE,IAAI,EAAE,uBAAuB;AAC/B,EAAE,KAAK,EAAE,wBAAwB;AACjC,EAAE,KAAK,EAAE,wBAAwB;AACjC,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE;AACpB,IAAI,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;AAC1C,IAAI,QAAQ,CAAC,WAAW,GAAG,qBAAqB,CAAC;AACjD,IAAI,MAAM,yBAAyB,GAAG,uBAAuB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;AACpF,IAAI,IAAI,UAAU,GAAG,EAAE,CAAC;AACxB,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,KAAK,C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