{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/primitive-collections/polyline-collection/index.ts"],"sourcesContent":["import type { ExtractPropTypes, PropType, VNode, WatchStopHandle } from 'vue'\nimport { createCommentVNode, defineComponent, getCurrentInstance, h, onUnmounted, watch } from 'vue'\nimport type { VcComponentInternalInstance, VcComponentPublicInstance, VcPickEvent, VcReadyObject } from 'casc-cesium-utils/types'\nimport { usePrimitiveCollections } from 'casc-cesium-composables'\nimport { cloneDeep, differenceBy } from 'lodash-unified'\nimport { modelMatrix, debugShowBoundingVolume, show, enableMouseEvent } 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 { VcPolylineProps } from '../polyline'\n\nconst polylineCollectionProps = {\n  ...modelMatrix,\n  ...debugShowBoundingVolume,\n  ...show,\n  ...enableMouseEvent,\n  polylines: {\n    type: Array as PropType<Array<VcPolylineProps>>,\n    default: () => []\n  }\n}\nexport default defineComponent({\n  name: 'VcCollectionPolyline',\n  props: polylineCollectionProps,\n  emits: primitiveCollectionEmits,\n  setup(props, ctx) {\n    // state\n    const instance = getCurrentInstance() as VcComponentInternalInstance\n    instance.cesiumClass = 'PolylineCollection'\n    const primitiveCollectionsState = usePrimitiveCollections(props, ctx, instance)\n\n    if (primitiveCollectionsState === void 0) {\n      return\n    }\n    // watcher\n    instance.alreadyListening.push('polylines')\n    let unwatchFns: Array<WatchStopHandle> = []\n    unwatchFns.push(\n      watch(\n        () => cloneDeep(props.polylines),\n        (newVal, oldVal) => {\n          if (!instance.mounted) {\n            return\n          }\n          const polylineCollection = instance.cesiumObject as Cesium.PolylineCollection\n\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 modifyPolyline = polylineCollection._polylines.find(v => v.id === modify.oldOptions.id)\n              modifyPolyline &&\n                Object.keys(modify.newOptions).forEach(prop => {\n                  if (modify.oldOptions[prop] !== modify.newOptions[prop]) {\n                    modifyPolyline[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 deletePolylines: Array<Cesium.Polyline> = []\n            for (let i = 0; i < deletes.length; i++) {\n              const deletePolyline = polylineCollection._polylines.find(v => v.id === deletes[i].id)\n              deletePolyline && deletePolylines.push(deletePolyline)\n            }\n\n            deletePolylines.forEach(v => {\n              polylineCollection.remove(v)\n            })\n\n            addPolylines(polylineCollection, addeds)\n          }\n        },\n        {\n          deep: true\n        }\n      )\n    )\n    // methods\n    const addPolylines = (polylineCollection: Cesium.PolylineCollection, polylines) => {\n      for (let i = 0; i < polylines.length; i++) {\n        const polylineOptions = polylines[i] as Cesium.Polyline\n        polylineOptions.id = Cesium.defined(polylineOptions.id) ? polylineOptions.id : Cesium.createGuid()\n        const polylineOptionsTransform = primitiveCollectionsState.transformProps(polylineOptions)\n        const polyline = polylineCollection.add(polylineOptionsTransform)\n        addCustomProperty(polyline, polylineOptionsTransform)\n      }\n    }\n    instance.createCesiumObject = async () => {\n      const options = primitiveCollectionsState.transformProps(props)\n      const polylineCollection = new Cesium.PolylineCollection(options)\n\n      addPolylines(polylineCollection, props.polylines)\n      return polylineCollection\n    }\n\n    // life cycle\n    onUnmounted(() => {\n      unwatchFns.forEach(item => item())\n      unwatchFns = []\n    })\n\n    const name = instance.proxy?.$options.name || ''\n    return () =>\n      ctx.slots.default\n        ? h(\n            'i',\n            {\n              class: kebabCase(name),\n              style: { display: 'none !important' }\n            },\n            hSlot(ctx.slots.default)\n          )\n        : createCommentVNode(kebabCase(name))\n  }\n})\n\nexport type VcCollectionPolylineProps = {\n  /**\n   * Determines if the polylines in the collection will be shown.\n   * Default Value: true\n   */\n  show?: boolean\n  /**\n   * The 4x4 transformation matrix that transforms each polyline 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 polylines collections. The structure of the array object is the same as the attribute of the [`vc-polyline`](https://zouyaoji.top/vue-cesium/#/en-US/component/primitives/vc-collection-polyline#vcpolyline-props) component.\n   */\n  polylines?: Array<VcPolylineProps>\n  /**\n   * Triggers before the VcCollectionPolyline is loaded.\n   */\n  onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the VcCollectionPolyline 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 VcCollectionPolyline 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 VcCollectionPolylineRef = VcComponentPublicInstance<VcCollectionPolylineProps>\n\nexport interface VcCollectionPolylineSlots {\n  /**\n   * Slot for vc-polyline.\n   */\n  default: () => VNode[]\n}\n"],"names":[],"mappings":";;;;;;;;;AAOA,MAAM,uBAAuB,GAAG;AAChC,EAAE,GAAG,WAAW;AAChB,EAAE,GAAG,uBAAuB;AAC5B,EAAE,GAAG,IAAI;AACT,EAAE,GAAG,gBAAgB;AACrB,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAE,KAAK;AACf,IAAI,OAAO,EAAE,MAAM,EAAE;AACrB,GAAG;AACH,CAAC,CAAC;AACF,yBAAe,eAAe,CAAC;AAC/B,EAAE,IAAI,EAAE,sBAAsB;AAC9B,EAAE,KAAK,EAAE,uBAAuB;AAChC,EAAE,KAAK,EAAE,wBAAwB;AACjC,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE;AACpB,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;AAC1C,IAAI,QAAQ,CAAC,WAAW,GAAG,oBAAoB,CAAC;AAChD,IAAI,MAAM,yBAAyB,GAAG,uBAAuB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;AACpF,IAAI,IAAI,yBAAyB,KAAK,KAAK,CAAC,EAAE;AAC9C,MAAM,OAAO;AACb,KAAK;AACL,IAAI,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAChD,IAAI,IAAI,UAAU,GAAG,EAAE,CAAC;AACxB,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK;AAChF,MAAM,IAAI,CAAC,QAAQ,CA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