casc-cesium
Version:
Vue 3.x components for CesiumJS.
1 lines • 9.06 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/geometry-instance/src/index.ts"],"sourcesContent":["/*\n * @Author: zouyaoji@https://github.com/zouyaoji\n * @Date: 2021-09-16 09:28:13\n * @LastEditTime: 2022-08-12 11:48:54\n * @LastEditors: zouyaoji\n * @Description:\n * @FilePath: \\10_vue-cesium\\packages\\components\\geometry-instance\\src\\index.ts\n */\nimport type { VcComponentInternalInstance, VcComponentPublicInstance, VcGeometry, VcReadyObject } from 'casc-cesium-utils/types'\nimport { defineComponent, getCurrentInstance, createCommentVNode, PropType, ref, h, provide, VNode } from 'vue'\nimport { useCommon } from 'casc-cesium-composables'\nimport { kebabCase } from 'casc-cesium-utils/util'\nimport { modelMatrix, id } from 'casc-cesium-utils/cesium-props'\nimport { getInstanceListener, getVcParentInstance } from 'casc-cesium-utils/private/vm'\nimport { mergeDescriptors } from 'casc-cesium-utils/merge-descriptors'\nimport { hSlot } from 'casc-cesium-utils/private/render'\nimport { vcKey } from 'casc-cesium-utils/config'\nimport { commonEmits } from 'casc-cesium-utils/emits'\nimport { VcPrimitiveRef } from '../../primitives'\nexport const geometryInstanceProps = {\n geometry: Object as PropType<Cesium.Geometry | Cesium.GeometryFactory>,\n ...modelMatrix,\n ...id,\n attributes: Object\n}\nconst emits = {\n ...commonEmits,\n 'update:geometry': (payload: VcGeometry) => true\n}\nexport default defineComponent({\n name: 'VcGeometryInstance',\n props: geometryInstanceProps,\n emits: emits,\n setup(props, ctx) {\n // state\n const instance = getCurrentInstance() as VcComponentInternalInstance\n instance.renderByParent = true\n instance.cesiumClass = 'GeometryInstance'\n instance.cesiumEvents = []\n const commonState = useCommon(props, ctx, instance)\n if (commonState === void 0) {\n return\n }\n const { emit } = ctx\n const vcIndex = ref(0)\n // methods\n instance.createCesiumObject = async () => {\n const options = commonState.transformProps(props) as any\n if (!options.geometry) {\n options.geometry = new Cesium.Geometry({ attributes: new Cesium.GeometryAttributes() })\n }\n return new Cesium.GeometryInstance(options)\n }\n instance.mount = async () => {\n const parentVM = getVcParentInstance(instance).proxy as VcPrimitiveRef\n if (parentVM.__childCount !== undefined) {\n vcIndex.value = parentVM.__childCount.value || 0\n parentVM.__childCount.value += 1\n }\n\n const geometryInstance = instance.cesiumObject as Cesium.GeometryInstance\n parentVM.__updateGeometryInstances?.(geometryInstance, vcIndex.value)\n return true\n }\n instance.unmount = async () => {\n const geometryInstance = instance.cesiumObject as Cesium.GeometryInstance\n const parentVM = getVcParentInstance(instance).proxy as VcPrimitiveRef\n parentVM.__removeGeometryInstances?.(geometryInstance)\n return true\n }\n\n const updateGeometry = geometry => {\n const listener = getInstanceListener(instance, 'update:geometry')\n if (listener) {\n emit('update:geometry', geometry)\n } else {\n const geometryInstance = instance.cesiumObject as Cesium.GeometryInstance\n geometryInstance.geometry = geometry\n }\n\n return true\n }\n\n const getServices = () => {\n return mergeDescriptors(commonState.getServices(), {\n get geometryInstance() {\n return instance.cesiumObject as Cesium.GeometryInstance\n }\n })\n }\n\n // provide\n provide(vcKey, getServices())\n\n // expose public methods\n Object.assign(instance.proxy, {\n // private but needed by VcGeometryXXX\n __updateGeometry: updateGeometry\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 || 'v-if'))\n }\n})\n\nexport type VcGeometryInstanceEmits = typeof emits\nexport type VcGeometryInstanceProps = {\n /**\n * The geometry to instance.\n */\n geometry?: Cesium.Geometry | Cesium.GeometryFactory\n /**\n * The model matrix that transforms to transform the geometry from model to world coordinates.\n */\n modelMatrix?: Cesium.Matrix4\n /**\n * A user-defined object to return when the instance is picked with Scene#pick or get/set per-instance attributes with Primitive#getGeometryInstanceAttributes.\n */\n id?: any\n /**\n * Per-instance attributes like a show or color attribute shown in the example below.\n */\n attributes?: any\n /**\n * Triggers before the VcGeometryInstance is loaded.\n */\n onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n /**\n * Triggers when the VcGeometryInstance 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 VcGeometryInstance is destroyed.\n */\n onDestroyed?: (instance: VcComponentInternalInstance) => void\n /**\n * Triggers when the geometry mounted.\n */\n 'onUpdate:geometry'?: (payload: VcGeometry) => void\n}\n\nexport interface VcGeometryInstanceRef extends VcComponentPublicInstance<VcGeometryInstanceProps> {\n /**\n * private but needed by VcGeometryXXX.\n * @param geometry\n */\n __updateGeometry?(geometry: Cesium.Geometry): boolean\n}\n\nexport interface VcGeometryInstanceSlots {\n /**\n * Slot for vc-geometry-xxx.\n */\n default: () => VNode[]\n}\n"],"names":[],"mappings":";;;;;;;;;;;AASY,MAAC,qBAAqB,GAAG;AACrC,EAAE,QAAQ,EAAE,MAAM;AAClB,EAAE,GAAG,WAAW;AAChB,EAAE,GAAG,EAAE;AACP,EAAE,UAAU,EAAE,MAAM;AACpB,EAAE;AACF,MAAM,KAAK,GAAG;AACd,EAAE,GAAG,WAAW;AAChB,EAAE,iBAAiB,EAAE,CAAC,OAAO,KAAK,IAAI;AACtC,CAAC,CAAC;AACF,uBAAe,eAAe,CAAC;AAC/B,EAAE,IAAI,EAAE,oBAAoB;AAC5B,EAAE,KAAK,EAAE,qBAAqB;AAC9B,EAAE,KAAK;AACP,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE;AACpB,IAAI,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;AAC1C,IAAI,QAAQ,CAAC,cAAc,GAAG,IAAI,CAAC;AACnC,IAAI,QAAQ,CAAC,WAAW,GAAG,kBAAkB,CAAC;AAC9C,IAAI,QAAQ,CAAC,YAAY,GAAG,EAAE,CAAC;AAC/B,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,E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