{"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-08-25 21:31:00\n * @LastEditors: zouyaoji\n * @Description:\n * @FilePath: \\vue-cesium@next\\packages\\components\\primitive-collections\\polygon\\index.ts\n */\nimport type { 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  VcComponentPublicInstance\n} from '@vue-cesium/utils/types'\nimport { usePrimitiveCollectionItems } from '@vue-cesium/composables'\nimport {\n  id,\n  show,\n  enableMouseEvent,\n  positions,\n  arcType,\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  ...arcType,\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\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  /**\n   * Specify the positions.\n   */\n  positions?: VcCartesian3Array\n  /**\n   * \tA polygon hierarchy that can include holes.\n   */\n  polygonHierarchy?: VcPolygonHierarchy\n  /**\n   * The type of line the polygon edges must follow. Valid options are ArcType.GEODESIC and ArcType.RHUMB.\n   */\n  arcType?: number | Cesium.ArcType\n  /**\n   * An enum Property specifying whether this polygon will classify terrain, 3D Tiles, or both when on the ground.\n   */\n  classificationType?: number | Cesium.ClassificationType\n  /**\n   * Specify whether the polygon is attached to the ground or 3dtiles.\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   * Default value: true\n   */\n  allowPicking?: boolean\n  /**\n   * Determines if the primitive will be created asynchronously or block until ready.\n   * Default value: true\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 VcPolygon is loaded.\n   */\n  onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the VcPolygon 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 VcPolygon is destroyed.\n   */\n  onDestroyed?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the mouse is pressed on this polygon.\n   */\n  onMousedown?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse bounces up on this polygon.\n   */\n  onMouseup?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse clicks on this polygon.\n   */\n  onClick?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse clicks outside this polygon.\n   */\n  onClickout?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the left mouse button double-clicks this polygon.\n   */\n  onDblclick?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse moves on this polygon.\n   */\n  onMousemove?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse moves over to this polygon.\n   */\n  onMouseover?: (evt: VcPickEvent) => void\n  /**\n   * Triggers when the mouse moves out of this polygon.\n   */\n  onMouseout?: (evt: VcPickEvent) => void\n}\n\nexport type VcPolygonRef = VcComponentPublicInstance<VcPolygonProps>\n"],"names":[],"mappings":";;;;;;;;;;;AAwCO,MAAM,YAAe,GAAA;AAAA,EAC1B,GAAG,SAAA;AAAA,EACH,GAAG,gBAAA;AAAA,EACH,GAAG,UAAA;AAAA,EACH,GAAG,mBAAA;AAAA,EACH,GAAG,IAAA;AAAA,EACH,GAAG,EAAA;AAAA,EACH,GAAG,OAAA;AAAA,EACH,GAAG,kBAAA;AAAA,EACH,GAAG,aAAA;AAAA,EACH,GAAG,SAAA;AAAA,EACH,GAAG,YAAA;AAAA,EACH,GAAG,YAAA;AAAA,EACH,GAAG,gBAAA;AACL,EAA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