vue-cesium-jyt
Version:
Vue 3.x components for CesiumJS.
1 lines • 11.3 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/primitive-collections/polygon/index.ts"],"sourcesContent":["/*\n * @Author: zouyaoji@https://github.com/zouyaoji\n * @Date: 2021-11-19 22:09:27\n * @LastEditTime: 2022-01-25 11:13:43\n * @LastEditors: zouyaoji\n * @Description:\n * @FilePath: \\vue-cesium@next\\packages\\components\\primitive-collections\\polygon\\index.ts\n */\nimport type { ExtractPropTypes, WatchStopHandle } from 'vue'\nimport { createCommentVNode, defineComponent, getCurrentInstance, onUnmounted, watch } from 'vue'\nimport type {\n VcPickEvent,\n VcAppearance,\n VcCartesian3Array,\n VcComponentInternalInstance,\n VcPolygonHierarchy,\n VcReadyObject\n} from '@vue-cesium/utils/types'\nimport { usePrimitiveCollectionItems } from '@vue-cesium/composables'\nimport {\n id,\n show,\n enableMouseEvent,\n positions,\n classificationType,\n polygonHierarchy,\n clampToGround,\n appearance,\n depthFailAppearance,\n ellipsoid,\n allowPicking,\n asynchronous\n} from '@vue-cesium/utils/cesium-props'\nimport { kebabCase } from '@vue-cesium/utils/util'\nimport { PolygonPrimitive } from '@vue-cesium/shared'\nimport { makeAppearance, makeCartesian3Array, makePolygonHierarchy } from '@vue-cesium/utils/cesium-helpers'\nimport { primitiveCollectionEmits } from '@vue-cesium/utils/emits'\n\nexport const polygonProps = {\n ...positions,\n ...polygonHierarchy,\n ...appearance,\n ...depthFailAppearance,\n ...show,\n ...id,\n ...classificationType,\n ...clampToGround,\n ...ellipsoid,\n ...allowPicking,\n ...asynchronous,\n ...enableMouseEvent\n}\nexport default defineComponent({\n name: 'VcPolygon',\n props: polygonProps,\n emits: primitiveCollectionEmits,\n setup(props, ctx) {\n // state\n const instance = getCurrentInstance() as VcComponentInternalInstance\n instance.cesiumClass = 'PolygonPrimitive'\n const primitiveCollectionItemsState = usePrimitiveCollectionItems(props, ctx, instance)\n\n if (primitiveCollectionItemsState === void 0) {\n return\n }\n\n // watcch\n let unwatchFns: Array<WatchStopHandle> = []\n unwatchFns.push(\n watch(\n () => props.clampToGround,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.clampToGround = val as boolean)\n }\n )\n )\n unwatchFns.push(\n watch(\n () => props.positions,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.positions = makeCartesian3Array(val!) as Array<Cesium.Cartesian3>)\n }\n )\n )\n\n unwatchFns.push(\n watch(\n () => props.polygonHierarchy,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.polygonHierarchy = makePolygonHierarchy(val!) as Cesium.PolygonHierarchy)\n }\n )\n )\n\n unwatchFns.push(\n watch(\n () => props.appearance,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.appearance = makeAppearance.call(instance, val!) as Cesium.Appearance)\n }\n )\n )\n\n unwatchFns.push(\n watch(\n () => props.depthFailAppearance,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.depthFailAppearance = makeAppearance.call(instance, val!) as Cesium.Appearance)\n }\n )\n )\n\n unwatchFns.push(\n watch(\n () => props.show,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.show = val)\n }\n )\n )\n\n unwatchFns.push(\n watch(\n () => props.classificationType,\n val => {\n const polygonPrimitive = instance.cesiumObject as PolygonPrimitive\n polygonPrimitive && (polygonPrimitive.classificationType = val as number)\n }\n )\n )\n\n // methods\n instance.createCesiumObject = async () => {\n const options = primitiveCollectionItemsState.transformProps(props)\n return new PolygonPrimitive(options)\n }\n\n instance.mount = async () => {\n const primitives = primitiveCollectionItemsState.$services.primitives\n const collectionItem = instance.cesiumObject\n ;(collectionItem as any)._vcParent = primitives\n return primitives && primitives.add(collectionItem)\n }\n\n instance.unmount = async () => {\n const primitives = primitiveCollectionItemsState.$services.primitives\n const collectionItem = instance.cesiumObject\n return primitives && !primitives.isDestroyed() && primitives.remove(collectionItem)\n }\n\n // life cycle\n onUnmounted(() => {\n unwatchFns.forEach(item => item())\n unwatchFns = []\n })\n\n return () => createCommentVNode(kebabCase(instance.proxy?.$options.name || ''))\n }\n})\n\n// export type VcPolygonProps = ExtractPropTypes<typeof polygonProps>\nexport type VcPolygonProps = {\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 * Determines if this primitive will be shown.\n * Default value: true\n */\n show?: boolean\n positions?: VcCartesian3Array\n classificationType?: number\n /**\n * \tA polygon hierarchy that can include holes.\n */\n polygonHierarchy?: VcPolygonHierarchy\n /**\n * Specify whether the drawing result object is attached to the ground or 3dtiles. Only polyline and polygon objects work.\n */\n clampToGround?: boolean\n /**\n * The appearance used to render the primitive.\n */\n appearance?: VcAppearance\n /***\n * The appearance used to shade this primitive when it fails the depth test.\n */\n depthFailAppearance?: VcAppearance\n /**\n * The ellipsoid to be used as a reference.\n */\n ellipsoid?: Cesium.Ellipsoid\n /**\n * When true, each geometry instance will only be pickable with Scene#pick. When false, GPU memory is saved.\n */\n allowPicking?: boolean\n /**\n * Determines if the primitive will be created asynchronously or block until ready.\n */\n asynchronous?: boolean\n /**\n * Specifies whether to respond to mouse pick events.\n * Default Value: true\n */\n enableMouseEvent?: boolean\n /**\n * Triggers before the VcPoint is loaded.\n */\n onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n /**\n * Triggers when the VcPoint is successfully loaded.\n */\n onReady?: (readyObject: VcReadyObject) => void\n /**\n * Triggers when the VcPoint is destroyed.\n */\n onDestroyed?: (instance: VcComponentInternalInstance) => void\n /**\n * Triggers when the mouse is pressed on this polygon.\n */\n mousedown?: (evt: VcPickEvent) => void\n /**\n * Triggers when the mouse bounces up on this polygon.\n */\n mouseup?: (evt: VcPickEvent) => void\n /**\n * Triggers when the mouse clicks on this polygon.\n */\n click?: (evt: VcPickEvent) => void\n /**\n * Triggers when the mouse clicks outside this polygon.\n */\n clickout?: (evt: VcPickEvent) => void\n /**\n * Triggers when the left mouse button double-clicks this polygon.\n */\n dblclick?: (evt: VcPickEvent) => void\n /**\n * Triggers when the mouse moves on this polygon.\n */\n mousemove?: (evt: VcPickEvent) => void\n /**\n * Triggers when the mouse moves over to this polygon.\n */\n mouseover?: (evt: VcPickEvent) => void\n /**\n * \tTriggers when the mouse moves out of this polygon.\n */\n mouseout?: (evt: VcPickEvent) => void\n}\n"],"names":[],"mappings":";;;;;;;;;;AAoBY,MAAC,YAAY,GAAG;AAC5B,EAAE,GAAG,SAAS;AACd,EAAE,GAAG,gBAAgB;AACrB,EAAE,GAAG,UAAU;AACf,EAAE,GAAG,mBAAmB;AACxB,EAAE,GAAG,IAAI;AACT,EAAE,GAAG,EAAE;AACP,EAAE,GAAG,kBAAkB;AACvB,EAAE,GAAG,aAAa;AAClB,EAAE,GAAG,SAAS;AACd,EAAE,GAAG,YAAY;AACjB,EAAE,GAAG,YAAY;AACjB,EAAE,GAAG,gBAAgB;AACrB,EAAE;AACF,cAAe,eAAe,CAAC;AAC/B,EAAE,IAAI,EAAE,WAAW;AACnB,EAAE,KAAK,EAAE,YAAY;AACrB,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,kBAAkB,CAAC;AAC9C,IAAI,MAAM,6BAA6B,GAAG,2BAA2B,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC5F,IAAI,IAAI,6BAA6B,KAAK,KAAK,CAAC,EAAE;AAClD,MAAM,OAAO;AACb,KAAK;AACL,IAAI,IAAI,UAAU,GAAG,EAAE,CAAC;AAC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