{"version":3,"file":"index.mjs","sources":["../../../../../../packages/components/analyses/flood/index.ts"],"sourcesContent":["/*\n * @Author: zouyaoji@https://github.com/zouyaoji\n * @Date: 2021-12-31 10:30:21\n * @LastEditTime: 2022-08-22 20:31:30\n * @LastEditors: zouyaoji\n * @Description:\n * @FilePath: \\vue-cesium@next\\packages\\components\\analyses\\flood\\index.ts\n */\nimport { defineComponent, getCurrentInstance, PropType, ref, h, createCommentVNode, WatchStopHandle, onUnmounted, watch } from 'vue'\nimport { polygonHierarchy } from 'casc-cesium-utils/cesium-props'\nimport { VcColor, VcComponentInternalInstance, VcComponentPublicInstance, VcPolygonHierarchy, VcReadyObject } from 'casc-cesium-utils/types'\nimport { makeColor } from 'casc-cesium-utils/cesium-helpers'\nimport { VcPrimitiveClassification } from 'casc-cesium-components/primitives'\nimport { VcGeometryInstance } from 'casc-cesium-components/geometry-instance'\nimport { VcGeometryPolygon } from 'casc-cesium-components/geometries'\nimport { getInstanceListener, getVcParentInstance } from 'casc-cesium-utils/private/vm'\nimport { useCommon } from 'casc-cesium-composables'\nimport { commonEmits } from 'casc-cesium-utils/emits'\n\nconst emits = {\n  ...commonEmits,\n  stop: (evt: Cesium.ClassificationPrimitive) => true\n}\nexport default defineComponent({\n  name: 'VcAnalysisFlood',\n  props: {\n    minHeight: {\n      type: Number,\n      default: -1\n    },\n    maxHeight: {\n      type: Number,\n      default: 8888\n    },\n    speed: {\n      type: Number,\n      default: 10\n    },\n    loop: {\n      type: Boolean,\n      default: false\n    },\n    color: {\n      type: [Object, Array, String] as PropType<VcColor>,\n      default: 'rgba(40,150,200,0.6)'\n    },\n    ...polygonHierarchy\n  },\n  emits: emits,\n  setup(props: VcAnalysisFloodProps, ctx) {\n    const instance = getCurrentInstance() as VcComponentInternalInstance\n    instance.cesiumClass = 'VcAnalysisFlood'\n    instance.cesiumEvents = []\n\n    const commonState = useCommon(props, ctx, instance)\n    if (commonState === void 0) {\n      return\n    }\n\n    const { emit } = ctx\n\n    const canRender = ref(false)\n\n    const vcParent = getVcParentInstance(instance)\n    ;(vcParent.proxy as VcComponentPublicInstance).creatingPromise?.then(() => {\n      canRender.value = true\n    })\n\n    const flooding = ref(false)\n    const attributes = ref<any>(null)\n    const extrudedHeight = ref(-1)\n    const childRef = ref<Cesium.ClassificationPrimitive>(null)\n    let stoped = false\n\n    // watcch\n    let unwatchFns: Array<WatchStopHandle> = []\n    unwatchFns.push(\n      watch(\n        () => props.minHeight,\n        val => {\n          extrudedHeight.value = val\n        }\n      )\n    )\n\n    // methods\n    instance.createCesiumObject = async () => {\n      const { ColorGeometryInstanceAttribute } = Cesium\n\n      attributes.value = {\n        color: ColorGeometryInstanceAttribute.fromColor(makeColor(props.color) as Cesium.Color)\n      }\n\n      return childRef.value\n    }\n\n    instance.mount = async () => {\n      const { viewer } = commonState.$services\n      viewer.clock.onTick.addEventListener(onClockTick)\n      return true\n    }\n\n    instance.unmount = async () => {\n      const { viewer } = commonState.$services\n      viewer.clock.onTick.removeEventListener(onClockTick)\n      extrudedHeight.value = -1\n      flooding.value = false\n      return true\n    }\n\n    const onClockTick = () => {\n      if (flooding.value) {\n        if (extrudedHeight.value <= props.maxHeight) {\n          extrudedHeight.value += props.speed\n          stoped = false\n        } else {\n          const listener = getInstanceListener(instance, 'stop')\n          listener && emit('stop', childRef.value)\n          stoped = true\n          if (props.loop) {\n            extrudedHeight.value = props.minHeight\n          } else {\n            flooding.value = false\n          }\n        }\n      }\n    }\n\n    const start = (height?: number) => {\n      extrudedHeight.value = Cesium.defined(height) ? height : props.minHeight\n      flooding.value = true\n    }\n\n    const pause = () => {\n      flooding.value = !flooding.value\n      if (stoped) {\n        extrudedHeight.value = props.minHeight\n      }\n    }\n\n    const stop = () => {\n      extrudedHeight.value = -1\n      flooding.value = false\n    }\n\n    // life cycle\n    onUnmounted(() => {\n      unwatchFns.forEach(item => item())\n      unwatchFns = []\n    })\n\n    // expose public methods\n    Object.assign(instance.proxy, {\n      start,\n      pause,\n      stop,\n      getCurrentHeight: () => extrudedHeight.value\n    })\n\n    return () => {\n      if (canRender.value) {\n        const { createGuid } = Cesium\n\n        return h(\n          VcPrimitiveClassification,\n          {\n            asynchronous: false,\n            ref: childRef\n          },\n          () =>\n            h(\n              VcGeometryInstance,\n              {\n                id: createGuid(),\n                attributes: attributes.value\n              },\n              () =>\n                h(VcGeometryPolygon, {\n                  extrudedHeight: extrudedHeight.value,\n                  polygonHierarchy: props.polygonHierarchy\n                })\n            )\n        )\n      } else {\n        return createCommentVNode('v-if')\n      }\n    }\n  }\n})\n\nexport interface VcAnalysisFloodProps {\n  /**\n   * Specify the minimum elevation.\n   * Default value: -1\n   */\n  minHeight?: number\n  /**\n   * Specify the maximum elevation.\n   * Default value: 8888\n   */\n  maxHeight?: number\n  /**\n   * Specify the height to increase each frame.\n   * Default value: 10\n   */\n  speed?: number\n  /**\n   * Specify whether to restart after reaching the maximum height.\n   * Default value: false\n   */\n  loop?: boolean\n  /**\n   * Specify the VcColor of water.\n   * Default value: rgba(40,150,200,0.6)\n   */\n  color?: VcColor\n  /**\n   * Specify ths VcPolygonHierarchy of polygon.\n   */\n  polygonHierarchy: VcPolygonHierarchy\n  /**\n   * Triggers before the VcAnalysisFlood is loaded.\n   */\n  onBeforeLoad?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the VcAnalysisFlood 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 VcAnalysisFlood is destroyed.\n   */\n  onDestroyed?: (instance: VcComponentInternalInstance) => void\n  /**\n   * Triggers when the maxHeight is reached.\n   */\n  onStop?: (evt: Cesium.ClassificationPrimitive) => void\n}\n\nexport interface VcAnalysisFloodRef extends VcComponentPublicInstance<VcAnalysisFloodProps> {\n  /**\n   * Start flood analysis\n   */\n  start: (height?: number) => void\n  /**\n   * Pause flood analysis\n   */\n  pause: () => void\n  /**\n   * Stop flood analysis\n   */\n  stop: (remove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