vue-cesium
Version:
Vue 3.x components for CesiumJS.
1 lines • 12 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/primitive-collections/point-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 '@vue-cesium/utils/types'\nimport { usePrimitiveCollections } from '@vue-cesium/composables'\nimport { cloneDeep, differenceBy } from 'lodash-unified'\nimport { modelMatrix, debugShowBoundingVolume, blendOption, show, enableMouseEvent } from '@vue-cesium/utils/cesium-props'\nimport { addCustomProperty, kebabCase } from '@vue-cesium/utils/util'\nimport { hSlot } from '@vue-cesium/utils/private/render'\nimport { primitiveCollectionEmits } from '@vue-cesium/utils/emits'\nimport { VcPointProps } from '../point'\n\nexport const pointCollectionProps = {\n ...modelMatrix,\n ...debugShowBoundingVolume,\n ...blendOption,\n ...show,\n ...enableMouseEvent,\n points: {\n type: Array as PropType<Array<VcPointProps>>,\n default: () => []\n }\n}\nexport default defineComponent({\n name: 'VcCollectionPoint',\n props: pointCollectionProps,\n emits: primitiveCollectionEmits,\n setup(props, ctx) {\n // state\n const instance = getCurrentInstance() as VcComponentInternalInstance\n instance.cesiumClass = 'PointPrimitiveCollection'\n const primitiveCollectionsState = usePrimitiveCollections(props, ctx, instance)\n if (primitiveCollectionsState === void 0) {\n return\n }\n // watcher\n instance.alreadyListening.push('points')\n let unwatchFns: Array<WatchStopHandle> = []\n unwatchFns.push(\n watch(\n () => cloneDeep(props.points),\n (newVal, oldVal) => {\n if (!instance.mounted) {\n return\n }\n const pointCollection = instance.cesiumObject as Cesium.PointPrimitiveCollection\n if (newVal.length === oldVal.length) {\n // 视为修改操作\n // Treated as modified\n const modifies: Array<{\n newOptions: any\n oldOptions: any\n }> = []\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 modifyPoint = pointCollection._pointPrimitives.find(v => v && v.id === modify.oldOptions.id)\n modifyPoint &&\n Object.keys(modify.newOptions).forEach(prop => {\n if (modify.oldOptions[prop] !== modify.newOptions[prop]) {\n modifyPoint[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 deletePoints: Array<Cesium.PointPrimitive> = []\n for (let i = 0; i < deletes.length; i++) {\n const deletePoint = pointCollection._pointPrimitives.find(v => v.id === deletes[i].id)\n deletePoint && deletePoints.push(deletePoint)\n }\n\n deletePoints.forEach(v => {\n pointCollection.remove(v)\n })\n\n addPoints(pointCollection, addeds)\n }\n },\n {\n deep: true\n }\n )\n )\n // methods\n const addPoints = (pointCollection: Cesium.PointPrimitiveCollection, points) => {\n for (let i = 0; i < points.length; i++) {\n const pointOptions = points[i] as Cesium.PointPrimitive\n pointOptions.id = Cesium.defined(pointOptions.id) ? pointOptions.id : Cesium.createGuid()\n const pointOptionsTransform = primitiveCollectionsState.transformProps(pointOptions)\n const point = pointCollection.add(pointOptionsTransform)\n\n addCustomProperty(point, pointOptionsTransform)\n }\n }\n\n instance.createCesiumObject = async () => {\n const options = primitiveCollectionsState.transformProps(props)\n const pointCollection = new Cesium.PointPrimitiveCollection(options)\n addPoints(pointCollection, props.points)\n return pointCollection\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 VcCollectionPointProps = {\n /**\n * The point blending option. The default is used for rendering both opaque and translucent points. However, if either all of the points 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 primitives in the collection will be shown.\n * Default Value: true\n */\n show?: boolean\n /**\n * The 4x4 transformation matrix that transforms each point 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 points collections. The structure of the array object is the same as the attribute of the [vc-point](https://zouyaoji.top/vue-cesium/#/en-US/component/primitives/vc-collection-point#vcpoint-props) component.\n */\n points?: Array<VcPointProps>\n /**\n * Triggers before the VcCollectionPoint is loaded.\n */\n onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n /**\n * Triggers when the VcCollectionPoint 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 VcCollectionPoint 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 VcCollectionPointRef = VcComponentPublicInstance<VcCollectionPointProps>\n\nexport interface VcCollectionPointSlots {\n /**\n * Slot for vc-point.\n */\n default: () => VNode[]\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWO,MAAM,oBAAuB,GAAA;AAAA,EAClC,GAAG,WAAA;AAAA,EACH,GAAG,uBAAA;AAAA,EACH,GAAG,WAAA;AAAA,EACH,GAAG,IAAA;AAAA,EACH,GAAG,gBAAA;AAAA,EACH,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,KAAA;AAAA,IACN,OAAA,EAAS,MAAM,EAAC;AAAA,GAClB;AACF,EAAA;AACA,sBAAe,eAAgB,CAAA;AAAA,EAC7B,IAAM,EAAA,mBAAA;AAAA,EACN,KAAO,EAAA,oBAAA;AAAA,EACP,KAAO,EAAA,wBAAA;AAAA,EACP,KAAA,CAAM,OAAO,GAAK,EAAA;AAEhB,IAAA,MAAM,WAAW,kBAAmB,EAAA,CAAA;AACpC,IAAA,QAAA,CAAS,WAAc,GAAA,0BAAA,CAAA;AACvB,IAAA,MAAM,yBAA4B,GAAA,uBAAA,CAAwB,KAAO,EAAA,GAAA,EAAK,QAAQ,CAAA,CAAA;AAC9E,IAAA,IAAI,8BAA8B,KAAQ,CAAA,EAAA;AACxC,MAAA,OAAA;AAAA,KACF;AAEA,IAAS,QAAA,CAAA,gBAAA,CAAiB,KAAK,QAAQ,CAAA,CAAA;AACvC,IAAA,IAAI,aAAqC,EAAC,CAAA;AAC1C,IAAW,UAAA,CAAA,IAAA;AAAA,MACT,KAAA;AAAA,QACE,MAAM,SAAU,CAAA,KAAA,CAAM,MAAM,CAAA;AAAA,QAC5B,CAAC,QAAQ,MAAW,KAAA;AAClB,UAAI,IAAA,CAAC,SAAS,OAAS,EAAA;AACrB,YAAA,OAAA;AAAA,WACF;AACA,UAAA,MAAM,kBAAkB,QAAS,CAAA,YAAA,CAAA;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