From b64b8eb963e440308220c4f26ef69e3981159543 Mon Sep 17 00:00:00 2001 From: zouyaoji <370681295@qq.com> Date: Fri, 11 Mar 2022 11:42:16 +0800 Subject: [PATCH] refactor: improve types --- packages/components/analyses/flood/index.ts | 8 +- .../components/analyses/src/defaultProps.ts | 112 +++++++++++++++- packages/components/entity/src/index.ts | 11 +- .../components/geometry-instance/src/index.ts | 51 +++++++- .../components/imagery-layer/src/index.ts | 24 +++- .../primitive-collections/billboard/index.ts | 31 ++--- .../primitive-collections/cloud/index.ts | 53 ++------ .../primitive-collections/label/index.ts | 25 ++-- .../primitive-collections/point/index.ts | 25 ++-- .../primitive-collections/polygon/index.ts | 16 ++- packages/components/viewer/src/index.ts | 14 +- packages/components/viewer/src/useViewer.ts | 25 ++-- packages/composables/private/use-position.ts | 5 +- .../use-drawing/use-drawing-fab.ts | 24 ++-- packages/composables/use-geometries/index.ts | 7 +- packages/composables/use-graphics/index.ts | 9 +- packages/composables/use-providers/index.ts | 15 ++- packages/shared/src/DynamicOverlay.ts | 9 +- packages/utils/drawing-types.ts | 123 +++++------------- packages/utils/types.ts | 81 +++++++++--- 20 files changed, 405 insertions(+), 263 deletions(-) diff --git a/packages/components/analyses/flood/index.ts b/packages/components/analyses/flood/index.ts index 0172a8bc0..a8aea34b9 100644 --- a/packages/components/analyses/flood/index.ts +++ b/packages/components/analyses/flood/index.ts @@ -1,7 +1,7 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-12-31 10:30:21 - * @LastEditTime: 2022-03-05 15:38:26 + * @LastEditTime: 2022-03-09 22:55:14 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\analyses\flood\index.ts @@ -218,15 +218,15 @@ export interface VcAnalysisFloodProps { */ polygonHierarchy: VcPolygonHierarchy /** - * Triggers before the VcCompass is loaded. + * Triggers before the VcAnalysisFlood is loaded. */ onBeforeLoad?: (instance: VcComponentInternalInstance) => void /** - * Triggers when the VcCompass is successfully loaded. + * Triggers when the VcAnalysisFlood is successfully loaded. */ onReady?: (readyObject: VcReadyObject) => void /** - * Triggers when the VcCompass is destroyed. + * Triggers when the VcAnalysisFlood is destroyed. */ onDestroyed?: (instance: VcComponentInternalInstance) => void /** diff --git a/packages/components/analyses/src/defaultProps.ts b/packages/components/analyses/src/defaultProps.ts index be1ba5c37..c1ebea1b9 100644 --- a/packages/components/analyses/src/defaultProps.ts +++ b/packages/components/analyses/src/defaultProps.ts @@ -1,10 +1,10 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-10-18 10:40:15 - * @LastEditTime: 2022-02-17 16:52:10 + * @LastEditTime: 2022-03-11 09:49:41 * @LastEditors: zouyaoji * @Description: - * @FilePath: \vue-cesium-panda-parkd:\00_work\30_前端\Cesium\vue-cesium@next\packages\components\analyses\src\defaultProps.ts + * @FilePath: \vue-cesium@next\packages\components\analyses\src\defaultProps.ts */ import { @@ -17,10 +17,17 @@ import { polylinePrimitiveOptsDefault } from '@vue-cesium/composables/use-drawing/defaultOpts' import { useDrawingFabProps } from '@vue-cesium/composables/use-drawing/props' -import { VcDrawingOpts, VcViewshedAnalysisOpts } from '@vue-cesium/utils/drawing-types' -import type { VcActionTooltipProps } from '@vue-cesium/utils/types' +import { + VcDrawingActiveEvt, + VcDrawingDrawEvt, + VcDrawingEditorEvt, + VcDrawingMouseEvt, + VcDrawingOpts, + VcViewshedAnalysisOpts +} from '@vue-cesium/utils/drawing-types' +import type { VcActionTooltipProps, VcComponentInternalInstance, VcReadyObject } from '@vue-cesium/utils/types' import { getDefaultOptionByProps } from '@vue-cesium/utils/util' -import type { ExtractPropTypes, PropType } from 'vue' +import type { PropType } from 'vue' import type { VcFabProps } from '../../ui' const sightlineAnalysisActionDefault: VcActionTooltipProps = Object.assign({}, actionOptions, { @@ -152,7 +159,6 @@ const analysesProps = { default: () => viewshedAnalysisDefault } } -export type VcAnalysesProps = ExtractPropTypes const defaultOptions = getDefaultOptionByProps(analysesProps) export { @@ -164,3 +170,97 @@ export { viewshedAnalysisDefault, mainFabDefault } + +export type VcAnalysesProps = { + /** + * Specify the position of the VcAnalyses. + * Default value: bottom-left + */ + position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top' | 'right' | 'bottom' | 'left' + /** + * An array of two numbers to offset the VcAnalyses horizontally and vertically in pixels. + * Default value: [0, 0] + */ + offset?: [number, number] + /** + * Specify whether the analysis result is visible. + * Default value: true + */ + show?: boolean + /** + * Specify the interactive drawing mode, 0 means continuous drawing, and 1 means drawing ends once. + * Default value: 1 + */ + mode?: number + /** + * Specify which analysis instances to load. + * Default value: ['sightline', 'viewshed'] + */ + analyses?: Array<'sightline' | 'viewshed'> + /** + * Specify the color when the analysis instance is activated. + * Default value: positive + */ + activeColor?: string + /** + * Specify whether the analysis result can be edited. + * Default value: false + */ + editable?: boolean + /** + * Specify the style options of the floating action button of the VcAnalyses component. + */ + mainFabOpts?: VcActionTooltipProps & VcFabProps + /** + * Specify the style options of the sightline analysis action button. + */ + sightlineActionOpts?: VcActionTooltipProps + /** + * Specify sightline analysis options. + */ + sightlineAnalysisOpts?: VcDrawingOpts + /** + * Specify the style options of the viewshed analysis action button. + */ + viewshedActionOpts?: VcActionTooltipProps + /** + * Specify viewshed analysis options. + */ + viewshedAnalysisOpts?: VcViewshedAnalysisOpts + /** + * Specify the style options of the clear action button. + */ + clearActionOpts?: VcActionTooltipProps + /** + * Triggers before the VcAnalyses is loaded. + */ + onBeforeLoad?: (instance: VcComponentInternalInstance) => void + /** + * Triggers when the VcAnalyses is successfully loaded. + */ + onReady?: (readyObject: VcReadyObject) => void + /** + * Triggers when the VcAnalyses is destroyed. + */ + onDestroyed?: (instance: VcComponentInternalInstance) => void + /** + * Triggers when the analysis action is actived. + */ + onActiveEvt?: (evt: VcDrawingActiveEvt, viewer: Cesium.Viewer) => void + /** + * Triggers when drawing. + */ + onDrawEvt?: (evt: VcDrawingDrawEvt, viewer: Cesium.Viewer) => void + /** + * Triggers when the editor button is clicked. + */ + onEditorEvt?: (evt: VcDrawingEditorEvt, viewer: Cesium.Viewer) => void + /** + * Triggers when the mouse is over or out on the drawing point. + */ + onMouseEvt?: (evt: VcDrawingMouseEvt, viewer: Cesium.Viewer) => void + /** + * Triggers when the floating button is expanded or collapsed. + */ + onFabUpdated: (value: boolean) => void +} diff --git a/packages/components/entity/src/index.ts b/packages/components/entity/src/index.ts index fa92039b5..da12b321f 100644 --- a/packages/components/entity/src/index.ts +++ b/packages/components/entity/src/index.ts @@ -1,6 +1,6 @@ import type { ExtractPropTypes, PropType, ExtractDefaultPropTypes } from 'vue' import { createCommentVNode, defineComponent, getCurrentInstance, h } from 'vue' -import type { EntityEmitType, VcComponentInternalInstance } from '@vue-cesium/utils/types' +import type { EntityEmitType, VcComponentInternalInstance, VcComponentPublicInstance, VcGraphics } from '@vue-cesium/utils/types' import { useCommon } from '@vue-cesium/composables/index' import { position, plane, enableMouseEvent, show, viewFrom } from '@vue-cesium/utils/cesium-props' import { getInstanceListener } from '@vue-cesium/utils/private/vm' @@ -122,3 +122,12 @@ export default defineComponent({ export type VcEntityProps = ExtractPropTypes export type VcEntityEmits = typeof emits + +export interface VcEntityRef extends VcComponentPublicInstance { + /** + * private method, update graphic. + * @param graphics + * @param type + */ + __updateGraphics: (graphics: VcGraphics | undefined, type: EntityEmitType) => boolean +} diff --git a/packages/components/geometry-instance/src/index.ts b/packages/components/geometry-instance/src/index.ts index 3f55d1dc7..df9d86046 100644 --- a/packages/components/geometry-instance/src/index.ts +++ b/packages/components/geometry-instance/src/index.ts @@ -1,14 +1,13 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-09-16 09:28:13 - * @LastEditTime: 2022-02-15 09:14:41 + * @LastEditTime: 2022-03-11 10:02:30 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\geometry-instance\src\index.ts */ -import type { VcComponentInternalInstance, VcComponentPublicInstance, VcGeometry } from '@vue-cesium/utils/types' -import { defineComponent, getCurrentInstance, createCommentVNode, PropType, ref, h, provide } from 'vue' -import type { ExtractPropTypes } from 'vue' +import type { VcComponentInternalInstance, VcComponentPublicInstance, VcGeometry, VcReadyObject } from '@vue-cesium/utils/types' +import { defineComponent, getCurrentInstance, createCommentVNode, PropType, ref, h, provide, Ref } from 'vue' import { useCommon } from '@vue-cesium/composables' import { kebabCase } from '@vue-cesium/utils/util' import { modelMatrix, id } from '@vue-cesium/utils/cesium-props' @@ -52,7 +51,7 @@ export default defineComponent({ return new Cesium.GeometryInstance(options) } instance.mount = async () => { - const parentVM = getVcParentInstance(instance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(instance).proxy as VcGeometryInstanceRef if (parentVM.__childCount !== undefined) { vcIndex.value = parentVM.__childCount.value || 0 parentVM.__childCount.value += 1 @@ -64,7 +63,7 @@ export default defineComponent({ } instance.unmount = async () => { const geometryInstance = instance.cesiumObject as Cesium.GeometryInstance - const parentVM = getVcParentInstance(instance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(instance).proxy as VcGeometryInstanceRef parentVM.__removeGeometryInstances?.(geometryInstance) return true } @@ -113,7 +112,6 @@ export default defineComponent({ } }) -// export type VcGeometryInstanceProps = ExtractPropTypes export type VcGeometryInstanceEmits = typeof emits export type VcGeometryInstanceProps = { /** @@ -132,4 +130,43 @@ export type VcGeometryInstanceProps = { * Per-instance attributes like a show or color attribute shown in the example below. */ attributes: any + /** + * Triggers before the VcGeometryInstance is loaded. + */ + onBeforeLoad?: (instance: VcComponentInternalInstance) => void + /** + * Triggers when the VcGeometryInstance is successfully loaded. + */ + onReady?: (readyObject: VcReadyObject) => void + /** + * Triggers when the VcGeometryInstance is destroyed. + */ + onDestroyed?: (instance: VcComponentInternalInstance) => void + /** + * Triggers when the geometry mounted. + */ + 'onUpdate:geometry': (payload: VcGeometry) => void +} + +export interface VcGeometryInstanceRef extends VcComponentPublicInstance { + /** + * private but needed by VcGeometryInstance + * @param geometryInstance + * @param index + */ + __updateGeometryInstances?(geometryInstance: Cesium.GeometryInstance, index: number): boolean + /** + * private but needed by VcGeometryInstance + * @param geometryInstance + */ + __removeGeometryInstances?(geometryInstance: Cesium.GeometryInstance): boolean + /** + * private but needed by VcGeometryXXX. + * @param geometry + */ + __updateGeometry?(geometry: Cesium.Geometry): boolean + /** + * private but needed by VcGeometryInstance + */ + __childCount?: Ref } diff --git a/packages/components/imagery-layer/src/index.ts b/packages/components/imagery-layer/src/index.ts index 1c4de453a..f9bad3675 100644 --- a/packages/components/imagery-layer/src/index.ts +++ b/packages/components/imagery-layer/src/index.ts @@ -1,14 +1,21 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-09-16 09:28:13 - * @LastEditTime: 2022-02-18 11:28:17 + * @LastEditTime: 2022-03-11 11:36:34 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\imagery-layer\src\index.ts */ -import { createCommentVNode, defineComponent, getCurrentInstance, h, provide } from 'vue' -import type { ExtractPropTypes } from 'vue' -import type { AnyFunction, VcColor, VcComponentInternalInstance, VcImageryProvider, VcReadyObject, VcRectangle } from '@vue-cesium/utils/types' +import { createCommentVNode, defineComponent, getCurrentInstance, h } from 'vue' +import type { + AnyFunction, + VcColor, + VcComponentInternalInstance, + VcComponentPublicInstance, + VcImageryProvider, + VcReadyObject, + VcRectangle +} from '@vue-cesium/utils/types' import { hSlot } from '@vue-cesium/utils/private/render' import { useCommon } from '@vue-cesium/composables' import defaultProps from './defaultProps' @@ -88,7 +95,6 @@ export default defineComponent({ } }) -// export type VcLayerImageryProps = ExtractPropTypes export type VcLayerImageryEmits = typeof emits export type VcLayerImageryProps = { /** @@ -202,3 +208,11 @@ export type VcLayerImageryProps = { */ 'onUpdate:imageryProvider'?: (payload: VcImageryProvider) => void } + +export interface VcLayerImageryRef extends VcComponentPublicInstance { + /** + * private but needed by VcProviderXXX + * @param provider + */ + __updateProvider?(provider: VcImageryProvider | undefined): boolean +} diff --git a/packages/components/primitive-collections/billboard/index.ts b/packages/components/primitive-collections/billboard/index.ts index 6c34aee2f..9318bc3bb 100644 --- a/packages/components/primitive-collections/billboard/index.ts +++ b/packages/components/primitive-collections/billboard/index.ts @@ -1,12 +1,11 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-09-16 09:28:13 - * @LastEditTime: 2022-01-25 11:10:21 + * @LastEditTime: 2022-03-11 10:04:36 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\primitive-collections\billboard\index.ts */ -import type { ExtractPropTypes } from 'vue' import { createCommentVNode, defineComponent, getCurrentInstance } from 'vue' import type { VcPickEvent, @@ -16,7 +15,8 @@ import type { VcDistanceDisplayCondition, VcNearFarScalar, VcPosition, - VcReadyObject + VcReadyObject, + VcComponentPublicInstance } from '@vue-cesium/utils/types' import { usePrimitiveCollectionItems } from '@vue-cesium/composables' import { @@ -84,7 +84,6 @@ export default defineComponent({ } }) -// export type VcBillboardProps = ExtractPropTypes export type VcBillboardProps = { /** * Specify the aligned axis in world space. The aligned axis is the unit vector that the billboard up vector points towards. The default is the zero vector, which means the billboard is aligned to the screen up vector. @@ -179,47 +178,49 @@ export type VcBillboardProps = { */ enableMouseEvent?: boolean /** - * Triggers before the VcPoint is loaded. + * Triggers before the VcBillboard is loaded. */ onBeforeLoad?: (instance: VcComponentInternalInstance) => void /** - * Triggers when the VcPoint is successfully loaded. + * Triggers when the VcBillboard is successfully loaded. */ onReady?: (readyObject: VcReadyObject) => void /** - * Triggers when the VcPoint is destroyed. + * Triggers when the VcBillboard is destroyed. */ onDestroyed?: (instance: VcComponentInternalInstance) => void /** * Triggers when the mouse is pressed on this billboard. */ - mousedown?: (evt: VcPickEvent) => void + onMousedown?: (evt: VcPickEvent) => void /** * Triggers when the mouse bounces up on this billboard. */ - mouseup?: (evt: VcPickEvent) => void + onMouseup?: (evt: VcPickEvent) => void /** * Triggers when the mouse clicks on this billboard. */ - click?: (evt: VcPickEvent) => void + onClick?: (evt: VcPickEvent) => void /** * Triggers when the mouse clicks outside this billboard. */ - clickout?: (evt: VcPickEvent) => void + onClickout?: (evt: VcPickEvent) => void /** * Triggers when the left mouse button double-clicks this billboard. */ - dblclick?: (evt: VcPickEvent) => void + onDblclick?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves on this billboard. */ - mousemove?: (evt: VcPickEvent) => void + onMousemove?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves over to this billboard. */ - mouseover?: (evt: VcPickEvent) => void + onMouseover?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves out of this billboard. */ - mouseout?: (evt: VcPickEvent) => void + onMouseout?: (evt: VcPickEvent) => void } + +export type VcBillboardRef = VcComponentPublicInstance diff --git a/packages/components/primitive-collections/cloud/index.ts b/packages/components/primitive-collections/cloud/index.ts index 69be1c910..0d1857b7f 100644 --- a/packages/components/primitive-collections/cloud/index.ts +++ b/packages/components/primitive-collections/cloud/index.ts @@ -1,14 +1,21 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2022-01-28 11:13:56 - * @LastEditTime: 2022-01-29 10:15:27 + * @LastEditTime: 2022-03-11 10:46:42 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\primitive-collections\cloud\index.ts */ -import type { ExtractPropTypes, PropType } from 'vue' +import type { PropType } from 'vue' import { createCommentVNode, defineComponent, getCurrentInstance } from 'vue' -import type { VcPickEvent, VcCartesian2, VcColor, VcComponentInternalInstance, VcPosition, VcReadyObject } from '@vue-cesium/utils/types' +import type { + VcCartesian2, + VcColor, + VcComponentInternalInstance, + VcComponentPublicInstance, + VcPosition, + VcReadyObject +} from '@vue-cesium/utils/types' import { usePrimitiveCollectionItems } from '@vue-cesium/composables' import { color, position, show, enableMouseEvent } from '@vue-cesium/utils/cesium-props' import { kebabCase } from '@vue-cesium/utils/util' @@ -39,7 +46,6 @@ export const cumulusCloudProps = { type: Number, default: -1.0 } - // ...enableMouseEvent } export default defineComponent({ name: 'VcCumulusCloud', @@ -88,11 +94,6 @@ export type VcCumulusCloudProps = { * Default Value: -1.0 */ slice?: number - // /** - // * Specify whether to respond to mouse pick events. - // * Default Value: true - // */ - // enableMouseEvent?: boolean /** * Triggers before the VcCumulusCloud is loaded. */ @@ -105,36 +106,6 @@ export type VcCumulusCloudProps = { * Triggers when the VcCumulusCloud is destroyed. */ onDestroyed?: (instance: VcComponentInternalInstance) => void - // /** - // * Triggers when the mouse is pressed on this cumulusCloud. - // */ - // mousedown?: (evt: VcPickEvent) => void - // /** - // * Triggers when the mouse bounces up on this cumulusCloud. - // */ - // mouseup?: (evt: VcPickEvent) => void - // /** - // * Triggers when the mouse clicks on this cumulusCloud. - // */ - // click?: (evt: VcPickEvent) => void - // /** - // * Triggers when the mouse clicks outside this cumulusCloud. - // */ - // clickout?: (evt: VcPickEvent) => void - // /** - // * Triggers when the left mouse button double-clicks this cumulusCloud. - // */ - // dblclick?: (evt: VcPickEvent) => void - // /** - // * Triggers when the mouse moves on this cumulusCloud. - // */ - // mousemove?: (evt: VcPickEvent) => void - // /** - // * Triggers when the mouse moves over to this cumulusCloud. - // */ - // mouseover?: (evt: VcPickEvent) => void - // /** - // * Triggers when the mouse moves out of this cumulusCloud. - // */ - // mouseout?: (evt: VcPickEvent) => void } + +export type VcCumulusCloudRef = VcComponentPublicInstance diff --git a/packages/components/primitive-collections/label/index.ts b/packages/components/primitive-collections/label/index.ts index 8a6e5f0b3..dd24b1d58 100644 --- a/packages/components/primitive-collections/label/index.ts +++ b/packages/components/primitive-collections/label/index.ts @@ -1,12 +1,11 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-09-16 09:28:13 - * @LastEditTime: 2022-01-25 11:11:45 + * @LastEditTime: 2022-03-11 10:47:57 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\primitive-collections\label\index.ts */ -import type { ExtractPropTypes } from 'vue' import { createCommentVNode, defineComponent, getCurrentInstance } from 'vue' import { VcPickEvent, @@ -16,7 +15,8 @@ import { VcDistanceDisplayCondition, VcNearFarScalar, VcPosition, - VcReadyObject + VcReadyObject, + VcComponentPublicInstance } from '@vue-cesium/utils/types' import { usePrimitiveCollectionItems } from '@vue-cesium/composables' import { @@ -92,7 +92,6 @@ export default defineComponent({ } }) -// export type VcLabelProps = ExtractPropTypes export type VcLabelProps = { /** * Specify the background color of this label. @@ -214,33 +213,35 @@ export type VcLabelProps = { /** * Triggers when the mouse is pressed on this label. */ - mousedown?: (evt: VcPickEvent) => void + onMousedown?: (evt: VcPickEvent) => void /** * Triggers when the mouse bounces up on this label. */ - mouseup?: (evt: VcPickEvent) => void + onMouseup?: (evt: VcPickEvent) => void /** * Triggers when the mouse clicks on this label. */ - click?: (evt: VcPickEvent) => void + onClick?: (evt: VcPickEvent) => void /** * Triggers when the mouse clicks outside this label. */ - clickout?: (evt: VcPickEvent) => void + onClickout?: (evt: VcPickEvent) => void /** * Triggers when the left mouse button double-clicks this label. */ - dblclick?: (evt: VcPickEvent) => void + onDblclick?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves on this label. */ - mousemove?: (evt: VcPickEvent) => void + onMousemove?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves over to this label. */ - mouseover?: (evt: VcPickEvent) => void + onMouseover?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves out of this label. */ - mouseout?: (evt: VcPickEvent) => void + onMouseout?: (evt: VcPickEvent) => void } + +export type VcLabelRef = VcComponentPublicInstance diff --git a/packages/components/primitive-collections/point/index.ts b/packages/components/primitive-collections/point/index.ts index 9aa18d0c6..ae6d1c23c 100644 --- a/packages/components/primitive-collections/point/index.ts +++ b/packages/components/primitive-collections/point/index.ts @@ -1,12 +1,11 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-09-16 09:28:13 - * @LastEditTime: 2022-01-25 11:12:39 + * @LastEditTime: 2022-03-11 10:50:46 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\primitive-collections\point\index.ts */ -import type { ExtractPropTypes } from 'vue' import { createCommentVNode, defineComponent, getCurrentInstance } from 'vue' import type { VcPickEvent, @@ -15,7 +14,8 @@ import type { VcDistanceDisplayCondition, VcNearFarScalar, VcPosition, - VcReadyObject + VcReadyObject, + VcComponentPublicInstance } from '@vue-cesium/utils/types' import { usePrimitiveCollectionItems } from '@vue-cesium/composables' import { @@ -63,7 +63,6 @@ export default defineComponent({ } }) -// export type VcPointProps = ExtractPropTypes export type VcPointProps = { /** * Specify the inner color of the point. @@ -133,33 +132,35 @@ export type VcPointProps = { /** * Triggers when the mouse is pressed on this point. */ - mousedown?: (evt: VcPickEvent) => void + onMousedown?: (evt: VcPickEvent) => void /** * Triggers when the mouse bounces up on this point. */ - mouseup?: (evt: VcPickEvent) => void + onMouseup?: (evt: VcPickEvent) => void /** * Triggers when the mouse clicks on this point. */ - click?: (evt: VcPickEvent) => void + onClick?: (evt: VcPickEvent) => void /** * Triggers when the mouse clicks outside this point. */ - clickout?: (evt: VcPickEvent) => void + onClickout?: (evt: VcPickEvent) => void /** * Triggers when the left mouse button double-clicks this point. */ - dblclick?: (evt: VcPickEvent) => void + onDblclick?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves on this point. */ - mousemove?: (evt: VcPickEvent) => void + onMousemove?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves over to this point. */ - mouseover?: (evt: VcPickEvent) => void + onMouseover?: (evt: VcPickEvent) => void /** * Triggers when the mouse moves out of this point. */ - mouseout?: (evt: VcPickEvent) => void + onMouseout?: (evt: VcPickEvent) => void } + +export type VcPointRef = VcComponentPublicInstance diff --git a/packages/components/primitive-collections/polygon/index.ts b/packages/components/primitive-collections/polygon/index.ts index 062e8dbaa..045489fe4 100644 --- a/packages/components/primitive-collections/polygon/index.ts +++ b/packages/components/primitive-collections/polygon/index.ts @@ -1,12 +1,12 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-11-19 22:09:27 - * @LastEditTime: 2022-01-25 11:13:43 + * @LastEditTime: 2022-03-11 10:52:02 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\primitive-collections\polygon\index.ts */ -import type { ExtractPropTypes, WatchStopHandle } from 'vue' +import type { WatchStopHandle } from 'vue' import { createCommentVNode, defineComponent, getCurrentInstance, onUnmounted, watch } from 'vue' import type { VcPickEvent, @@ -14,7 +14,8 @@ import type { VcCartesian3Array, VcComponentInternalInstance, VcPolygonHierarchy, - VcReadyObject + VcReadyObject, + VcComponentPublicInstance } from '@vue-cesium/utils/types' import { usePrimitiveCollectionItems } from '@vue-cesium/composables' import { @@ -164,7 +165,6 @@ export default defineComponent({ } }) -// export type VcPolygonProps = ExtractPropTypes export type VcPolygonProps = { /** * A user-defined object to return when the instance is picked with Scene#pick or get/set per-instance attributes with Primitive#getGeometryInstanceAttributes. @@ -211,15 +211,15 @@ export type VcPolygonProps = { */ enableMouseEvent?: boolean /** - * Triggers before the VcPoint is loaded. + * Triggers before the VcPolygon is loaded. */ onBeforeLoad?: (instance: VcComponentInternalInstance) => void /** - * Triggers when the VcPoint is successfully loaded. + * Triggers when the VcPolygon is successfully loaded. */ onReady?: (readyObject: VcReadyObject) => void /** - * Triggers when the VcPoint is destroyed. + * Triggers when the VcPolygon is destroyed. */ onDestroyed?: (instance: VcComponentInternalInstance) => void /** @@ -255,3 +255,5 @@ export type VcPolygonProps = { */ mouseout?: (evt: VcPickEvent) => void } + +export type VcPolygonRef = VcComponentPublicInstance diff --git a/packages/components/viewer/src/index.ts b/packages/components/viewer/src/index.ts index f5f3a8eea..a0eb2da8d 100644 --- a/packages/components/viewer/src/index.ts +++ b/packages/components/viewer/src/index.ts @@ -1,7 +1,7 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-09-16 09:28:13 - * @LastEditTime: 2022-02-15 09:09:35 + * @LastEditTime: 2022-03-04 09:11:24 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\viewer\src\index.ts @@ -10,7 +10,13 @@ import { defineComponent, provide, getCurrentInstance, h, createCommentVNode } f import type { VNode } from 'vue' import useViewer, { viewerProps } from './useViewer' import type { VcViewerProps } from './useViewer' -import type { VcComponentInternalInstance, VcDatasource, VcTerrainProvider, ViewerWidgetResizedEvent } from '@vue-cesium/utils/types' +import type { + VcComponentInternalInstance, + VcDatasource, + VcTerrainProvider, + VcViewerProvider, + ViewerWidgetResizedEvent +} from '@vue-cesium/utils/types' import { vcKey } from '@vue-cesium/utils/config' import { viewerEvents } from './events' import { VcSkeleton } from '@vue-cesium/components/ui' @@ -91,11 +97,11 @@ export default defineComponent({ const viewerStates = useViewer(props, ctx, instance) // provide - provide(vcKey, viewerStates.getServices()) + provide(vcKey, viewerStates.getServices()) instance.appContext.config.globalProperties.$VueCesium = viewerStates.getServices() // expose public methods Object.assign(instance.proxy, { - createPromise: viewerStates.createPromise, + creatingPromise: viewerStates.creatingPromise, load: viewerStates.load, unload: viewerStates.unload, reload: viewerStates.reload, diff --git a/packages/components/viewer/src/useViewer.ts b/packages/components/viewer/src/useViewer.ts index dfd00aacf..f02e02b40 100644 --- a/packages/components/viewer/src/useViewer.ts +++ b/packages/components/viewer/src/useViewer.ts @@ -1,11 +1,11 @@ -import { ExtractPropTypes, watch, ref, onMounted, onUnmounted, nextTick, reactive, VNode } from 'vue' +import { watch, ref, onMounted, onUnmounted, nextTick, reactive, VNode } from 'vue' import mitt, { Emitter } from 'mitt' import { useLocale } from '@vue-cesium/composables' import defaultProps from './defaultProps' import { mergeDescriptors } from '@vue-cesium/utils/merge-descriptors' import { dirname, removeEmpty, isEmptyObj, hasOwn } from '@vue-cesium/utils/util' import { getInstanceListener, $ } from '@vue-cesium/utils/private/vm' -import { +import type { VcComponentInternalInstance, VcCamera, VcReadyObject, @@ -15,7 +15,8 @@ import { VcTerrainProvider, VcDatasource, ViewerWidgetResizedEvent, - VcContextOptions + VcContextOptions, + VcViewerProvider } from '@vue-cesium/utils/types' import { setViewerCamera } from '@vue-cesium/utils/cesium-helpers' import useLog from '@vue-cesium/composables/private/use-log' @@ -25,7 +26,6 @@ import { useGlobalConfig } from '@vue-cesium/composables/use-global-config' import { VcSkeletonProps } from '../../ui/skeleton' export const viewerProps = defaultProps -// export type VcViewerProps = ExtractPropTypes export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInternalInstance) { // state @@ -806,7 +806,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter const readyObj: VcReadyObject = { Cesium, viewer, - vm: vcInstance.proxy as VcComponentPublicInstance + vm: vcInstance.proxy as VcViewerRef } if (globalThis.XE) { Object.assign(readyObj, { @@ -1059,7 +1059,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter getComputedStyle(toolbarElement).visibility !== 'hidden' && getComputedStyle(toolbarElement).display !== 'none' ) { - ;(layout.toolbarContainerRC as any) = toolbarElement.getBoundingClientRect()! + layout.toolbarContainerRC = toolbarElement.getBoundingClientRect() } else { layout.toolbarContainerRC = undefined } @@ -1070,7 +1070,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter getComputedStyle(bottomContainer).visibility !== 'hidden' && getComputedStyle(bottomContainer).display !== 'none' ) { - ;(layout.bottomContainerRC as any) = bottomContainer.getBoundingClientRect() + layout.bottomContainerRC = bottomContainer.getBoundingClientRect() } else { layout.bottomContainerRC = undefined } @@ -1081,7 +1081,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter getComputedStyle(timelineContainer).visibility !== 'hidden' && getComputedStyle(timelineContainer).display !== 'none' ) { - ;(layout.timelineContainerRC as any) = timelineContainer.getBoundingClientRect() + layout.timelineContainerRC = timelineContainer.getBoundingClientRect() } else { layout.timelineContainerRC = undefined } @@ -1092,7 +1092,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter getComputedStyle(animationContainer).visibility !== 'hidden' && getComputedStyle(animationContainer).display !== 'none' ) { - ;(layout.animationContainerRC as any) = animationContainer.getBoundingClientRect() + layout.animationContainerRC = animationContainer.getBoundingClientRect() } else { layout.animationContainerRC = undefined } @@ -1263,7 +1263,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter } } - const getServices = function () { + const getServices = function (): VcViewerProvider { return mergeDescriptors( {}, { @@ -1340,8 +1340,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter } } -// export type VcViewerProps = ExtractPropTypes -export type VcViewerProps = { +export interface VcViewerProps { /** * If set to false, the Animation widget will not be created. * Default value: false @@ -1815,3 +1814,5 @@ export interface VcViewerSlots { */ default: () => VNode[] } + +export type VcViewerRef = VcComponentPublicInstance diff --git a/packages/composables/private/use-position.ts b/packages/composables/private/use-position.ts index 3276c3a7e..20ec52ee2 100644 --- a/packages/composables/private/use-position.ts +++ b/packages/composables/private/use-position.ts @@ -1,6 +1,5 @@ import { computed, CSSProperties, PropType, ref } from 'vue' -import { hasOwn, isArray, isPlainObject } from '@vue-cesium/utils/util' -import { VcViewerProvider, AnyObject } from '@vue-cesium/utils/types' +import { VcViewerProvider } from '@vue-cesium/utils/types' export const positionProps = { position: { @@ -9,7 +8,7 @@ export const positionProps = { validator: (v: string) => ['top-right', 'top-left', 'bottom-right', 'bottom-left', 'top', 'right', 'bottom', 'left'].includes(v) }, offset: { - type: Array as PropType, + type: Array as PropType as PropType<[number, number]>, validator: v => v.length === 2 } } diff --git a/packages/composables/use-drawing/use-drawing-fab.ts b/packages/composables/use-drawing/use-drawing-fab.ts index 38a2d60ab..7bab279a3 100644 --- a/packages/composables/use-drawing/use-drawing-fab.ts +++ b/packages/composables/use-drawing/use-drawing-fab.ts @@ -1,7 +1,7 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-10-13 09:45:59 - * @LastEditTime: 2022-03-09 10:16:06 + * @LastEditTime: 2022-03-11 09:41:37 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\composables\use-drawing\use-drawing-fab.ts @@ -13,7 +13,7 @@ import { useCommon, useHandler } from '@vue-cesium/composables' import { VisibilityState } from '@vue-cesium/shared' import { VcDrawingActionInstance } from '@vue-cesium/utils/drawing-types' import { VcActionTooltipProps, VcComponentInternalInstance, VcDrawingProvider, VcReadyObject } from '@vue-cesium/utils/types' -import { CSSProperties, provide, reactive, ref, VNode, h, createCommentVNode } from 'vue' +import { CSSProperties, provide, reactive, ref, VNode, h, createCommentVNode, ComputedRef } from 'vue' import usePosition from '../private/use-position' import { $ } from '@vue-cesium/utils/private/vm' import { isString } from '@vue-cesium/utils/util' @@ -26,7 +26,7 @@ export default function ( props, ctx, instance: VcComponentInternalInstance, - drawingActionInstances: Array, + drawingActionInstances: ComputedRef>, mainFabOpts: VcFabProps & VcActionTooltipProps, clearActionOpts: VcActionTooltipProps, cmpName: string @@ -65,7 +65,7 @@ export default function ( let drawingActionOpts const instanceVm = instance.proxy as VcDrawingsRef | VcMeasurementsRef | VcAnalysesRef if (instanceVm.editingActionName) { - drawingActionOpts = drawingActionInstances.find(v => v.name === instanceVm.editingActionName) + drawingActionOpts = getDrawingActionInstance(instanceVm.editingActionName) } if (drawingActionOpts && drawingActionOpts !== selectedDrawingActionInstance) { @@ -81,7 +81,7 @@ export default function ( let drawingActionOpts const instanceVm = instance.proxy as VcDrawingsRef | VcMeasurementsRef | VcAnalysesRef if (instanceVm.editingActionName) { - drawingActionOpts = drawingActionInstances.find(v => v.name === instanceVm.editingActionName) + drawingActionOpts = getDrawingActionInstance(instanceVm.editingActionName) } if (drawingActionOpts && drawingActionOpts !== selectedDrawingActionInstance) { @@ -97,7 +97,7 @@ export default function ( let drawingActionOpts const instanceVm = instance.proxy as VcDrawingsRef | VcMeasurementsRef | VcAnalysesRef if (instanceVm.editingActionName) { - drawingActionOpts = drawingActionInstances.find(v => v.name === instanceVm.editingActionName) + drawingActionOpts = getDrawingActionInstance(instanceVm.editingActionName) } if (drawingActionOpts && drawingActionOpts !== selectedDrawingActionInstance) { @@ -255,7 +255,7 @@ export default function ( } const getDrawingActionInstance = (drawingName: string) => { - return drawingActionInstances.find(v => v.name === drawingName) + return drawingActionInstances.value.find(v => v.name === drawingName) } const onUpdateFab = value => { @@ -272,7 +272,7 @@ export default function ( } const clearAll = () => { - drawingActionInstances.forEach(drawingActionOpts => { + drawingActionInstances.value.forEach(drawingActionOpts => { drawingActionOpts.cmpRef.value?.clear() }) @@ -313,7 +313,7 @@ export default function ( toggleAction, getFabRef: () => fabRef.value, getDrawingActionInstance, - getDrawingActionInstances: () => drawingActionInstances, + getDrawingActionInstances: () => drawingActionInstances.value, getSelectedDrawingActionInstance: () => selectedDrawingActionInstance }) @@ -321,7 +321,7 @@ export default function ( if (canRender.value) { const fabActionChildren: Array = [] const drawingChildren: Array = [] - drawingActionInstances.forEach(drawingActionInstance => { + drawingActionInstances.value.forEach(drawingActionInstance => { fabActionChildren.push( h( VcFabAction, @@ -366,7 +366,7 @@ export default function ( ) }) - drawingActionInstances.length && + drawingActionInstances.value.length && fabActionChildren.push( h( VcFabAction, @@ -401,7 +401,7 @@ export default function ( style: containerStyle }, ctx.slots.body !== void 0 - ? ctx.slots.body() + ? ctx.slots.body(drawingActionInstances.value) : h( VcFab, { diff --git a/packages/composables/use-geometries/index.ts b/packages/composables/use-geometries/index.ts index c87a36d89..fcc486b6e 100644 --- a/packages/composables/use-geometries/index.ts +++ b/packages/composables/use-geometries/index.ts @@ -1,14 +1,15 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-06-01 18:06:23 - * @LastEditTime: 2021-10-02 11:00:04 + * @LastEditTime: 2022-03-11 09:55:22 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\composables\use-geometries\index.ts */ -import { VcComponentInternalInstance, VcComponentPublicInstance } from '@vue-cesium/utils/types' +import { VcComponentInternalInstance } from '@vue-cesium/utils/types' import useCommon from '../use-common' import { getVcParentInstance } from '@vue-cesium/utils/private/vm' +import { VcGeometryInstanceRef } from '@vue-cesium/components' export default function (props, ctx, vcInstance: VcComponentInternalInstance) { // state @@ -23,7 +24,7 @@ export default function (props, ctx, vcInstance: VcComponentInternalInstance) { // methods vcInstance.mount = async () => { const geometry = vcInstance.cesiumObject as Cesium.Geometry - const parentVM = getVcParentInstance(vcInstance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(vcInstance).proxy as VcGeometryInstanceRef return parentVM.__updateGeometry?.(geometry) } diff --git a/packages/composables/use-graphics/index.ts b/packages/composables/use-graphics/index.ts index f24a7f7a1..adda359e2 100644 --- a/packages/composables/use-graphics/index.ts +++ b/packages/composables/use-graphics/index.ts @@ -1,15 +1,16 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-06-01 18:06:23 - * @LastEditTime: 2022-01-14 16:27:10 + * @LastEditTime: 2022-03-06 20:15:51 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\composables\use-graphics\index.ts */ -import type { EntityEmitType, VcComponentInternalInstance, VcComponentPublicInstance, VcGraphics } from '@vue-cesium/utils/types' +import type { EntityEmitType, VcComponentInternalInstance, VcGraphics } from '@vue-cesium/utils/types' import useCommon from '../use-common' import { kebabCase } from '@vue-cesium/utils/util' import { getVcParentInstance } from '@vue-cesium/utils/private/vm' +import type { VcEntityRef } from '@vue-cesium/components' export default function (props, ctx, vcInstance: VcComponentInternalInstance) { // state @@ -29,13 +30,13 @@ export default function (props, ctx, vcInstance: VcComponentInternalInstance) { const cmpNameArr = kebabCase(vcInstance.proxy?.$options.name || '').split('-') const emitType = (cmpNameArr.length === 3 ? `update:${cmpNameArr[2]}` : 'update:polylineVolume') as EntityEmitType - const parentVM = getVcParentInstance(vcInstance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(vcInstance).proxy as VcEntityRef return parentVM && parentVM.__updateGraphics?.(graphics, emitType) } vcInstance.unmount = async () => { const cmpNameArr = kebabCase(vcInstance.proxy?.$options.name || '').split('-') const emitType = (cmpNameArr.length === 3 ? `update:${cmpNameArr[2]}` : 'update:polylineVolume') as EntityEmitType - const parentVM = getVcParentInstance(vcInstance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(vcInstance).proxy as VcEntityRef return parentVM && parentVM.__updateGraphics?.(undefined, emitType) } } diff --git a/packages/composables/use-providers/index.ts b/packages/composables/use-providers/index.ts index 4626137b0..be0df2333 100644 --- a/packages/composables/use-providers/index.ts +++ b/packages/composables/use-providers/index.ts @@ -1,17 +1,18 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-06-01 18:06:23 - * @LastEditTime: 2022-01-15 23:58:19 + * @LastEditTime: 2022-03-11 11:36:37 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\composables\use-providers\index.ts */ import { getInstanceListener, getVcParentInstance } from '@vue-cesium/utils/private/vm' -import type { VcComponentInternalInstance, VcComponentPublicInstance } from '@vue-cesium/utils/types' +import type { VcComponentInternalInstance } from '@vue-cesium/utils/types' import * as coordtransform from '@vue-cesium/utils/coordtransform' import useCommon from '../use-common' import type { SetupContext } from 'vue' import type { ProviderEmits } from '@vue-cesium/utils/emits' +import { VcLayerImageryRef } from '@vue-cesium/components' export default function (props, ctx: SetupContext, vcInstance: VcComponentInternalInstance) { // state @@ -31,7 +32,7 @@ export default function (props, ctx: SetupContext, vcInstance: Vc const imageryProvider = vcInstance.cesiumObject as Cesium.ImageryProvider imageryProvider?.readyPromise?.then(() => { const listener = getInstanceListener(vcInstance, 'readyPromise') - listener && emit('readyPromise', imageryProvider, viewer, vcInstance.proxy as VcComponentPublicInstance) + listener && emit('readyPromise', imageryProvider, viewer, vcInstance.proxy as VcLayerImageryRef) }) if (props.projectionTransforms && props.projectionTransforms.from !== props.projectionTransforms.to) { @@ -70,13 +71,13 @@ export default function (props, ctx: SetupContext, vcInstance: Vc } } } - const parentVM = getVcParentInstance(vcInstance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(vcInstance).proxy as VcLayerImageryRef return parentVM && parentVM.__updateProvider?.(imageryProvider) } else { const terrainProvider = vcInstance.cesiumObject as Cesium.TerrainProvider terrainProvider.readyPromise.then(() => { const listener = getInstanceListener(vcInstance, 'readyPromise') - listener && emit('readyPromise', terrainProvider, viewer, vcInstance.proxy as VcComponentPublicInstance) + listener && emit('readyPromise', terrainProvider, viewer, vcInstance.proxy as VcLayerImageryRef) }) viewer.terrainProvider = terrainProvider return true @@ -85,13 +86,13 @@ export default function (props, ctx: SetupContext, vcInstance: Vc vcInstance.unmount = async () => { const { viewer } = commonState.$services if (vcInstance.cesiumClass.indexOf('ImageryProvider') !== -1) { - const parentVM = getVcParentInstance(vcInstance).proxy as VcComponentPublicInstance + const parentVM = getVcParentInstance(vcInstance).proxy as VcLayerImageryRef return parentVM && parentVM.__updateProvider?.(undefined) } else { const terrainProvider = new Cesium.EllipsoidTerrainProvider() terrainProvider.readyPromise.then(() => { const listener = getInstanceListener(vcInstance, 'readyPromise') - listener && emit('readyPromise', terrainProvider, viewer, vcInstance.proxy as VcComponentPublicInstance) + listener && emit('readyPromise', terrainProvider, viewer, vcInstance.proxy as VcLayerImageryRef) }) viewer.terrainProvider = terrainProvider return true diff --git a/packages/shared/src/DynamicOverlay.ts b/packages/shared/src/DynamicOverlay.ts index 297be702b..1db8ebd9c 100644 --- a/packages/shared/src/DynamicOverlay.ts +++ b/packages/shared/src/DynamicOverlay.ts @@ -1,7 +1,7 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-11-24 14:20:28 - * @LastEditTime: 2022-01-23 00:50:50 + * @LastEditTime: 2022-03-01 18:03:50 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\shared\src\DynamicOverlay.ts @@ -71,12 +71,13 @@ class DynamicOverlay { * @param interval * @returns */ - addPosition(position: VcPosition, timeOrInterval: string | number | Cesium.JulianDate) { + addPosition(position: VcPosition, timeOrInterval: string | number | Cesium.JulianDate | Date) { this._removePosition() - let time + let time: Cesium.JulianDate if (typeof timeOrInterval === 'number') { const now = Cesium.JulianDate.now() time = Cesium.JulianDate.addSeconds(now, timeOrInterval, new Cesium.JulianDate()) + Cesium.destroyObject(now) } else { time = makeJulianDate(timeOrInterval) } @@ -85,7 +86,7 @@ class DynamicOverlay { this._lastTime = time! this._cache.push(this._lastTime!) - return this + return time } } diff --git a/packages/utils/drawing-types.ts b/packages/utils/drawing-types.ts index ed4d48373..ec9c54c0b 100644 --- a/packages/utils/drawing-types.ts +++ b/packages/utils/drawing-types.ts @@ -1,7 +1,7 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-10-13 10:48:26 - * @LastEditTime: 2022-02-13 00:37:10 + * @LastEditTime: 2022-03-10 01:14:45 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\utils\drawing-types.ts @@ -16,7 +16,7 @@ import { VcDrawingRegular } from '@vue-cesium/components/drawings/src' import type { - VcFabAction, + VcFabActionRef, VcGeometryInstanceProps, VcGeometryPolylineProps, VcLabelProps, @@ -25,12 +25,6 @@ import type { VcPrimitiveProps } from '@vue-cesium/components' -import { - pointDrawingActionDefault, - polygonDrawingActionDefault, - polylineDrawingActionDefault, - rectangleDrawingActionDefault -} from '@vue-cesium/components/drawings/src/defaultProps' import { VcMeasurementArea, VcMeasurementDistance, @@ -44,47 +38,11 @@ import { } from '@vue-cesium/components/measurements/src' import { VcAnalysisSightline, VcAnalysisViewshed } from '@vue-cesium/components/analyses/src' - -import { - areaMeasurementActionDefault, - areaMeasurementDefault, - componentDistanceMeasurementActionDefault, - componentDistanceMeasurementDefault, - distanceMeasurementActionDefault, - distanceMeasurementDefault, - heightMeasurementActionDefault, - heightMeasurementDefault, - horizontalMeasurementActionDefault, - horizontalMeasurementDefault, - pointMeasurementActionDefault, - pointMeasurementDefault, - polylineMeasurementActionDefault, - polylineMeasurementDefault, - rectangleMeasurementActionDefault, - rectangleMeasurementDefault, - verticalMeasurementActionDefault, - verticalMeasurementDefault -} from '@vue-cesium/components/measurements/src/defaultProps' -import { - circleDrawingDefault, - clearActionDefault, - pointDrawingDefault, - polygonDrawingDefault, - polylineDrawingDefault, - rectangleDrawingDefault -} from '@vue-cesium/composables/use-drawing/defaultOpts' -import { sightlineAnalysisActionDefault, sightlineAnalysisDefault } from '@vue-cesium/components/analyses/src/defaultProps' - import type { CSSProperties, Ref } from 'vue' -import type { VcPickEvent, VcBtnTooltipProps, VcCartesian3Array, VcPosition, VcColor, AppearanceOption } from './types' +import type { VcPickEvent, VcBtnTooltipProps, VcCartesian3Array, VcPosition, VcColor, AppearanceOption, VcActionTooltipProps } from './types' import { MeasureUnits } from '@vue-cesium/shared' -export type DrawingActionOpts = - | typeof pointDrawingActionDefault - | typeof polylineDrawingActionDefault - | typeof polygonDrawingActionDefault - | typeof rectangleDrawingActionDefault - | typeof clearActionDefault +export type DrawingActionOpts = VcActionTooltipProps export type DrawgingActionCmp = | typeof VcDrawingPin @@ -97,24 +55,6 @@ export type DrawgingActionCmp = export type DrawingActionCmpRef = Ref< typeof VcDrawingPoint | typeof VcDrawingPolyline | typeof VcDrawingPolygon | typeof VcDrawingRegular | typeof VcDrawingRectangle > -export type DrawingActionCmpOpts = - | typeof pointDrawingDefault - | typeof polylineDrawingDefault - | typeof polygonDrawingDefault - | typeof rectangleDrawingDefault - | typeof circleDrawingDefault - -export type MeasurementActionOpts = - | typeof distanceMeasurementActionDefault - | typeof componentDistanceMeasurementActionDefault - | typeof polylineMeasurementActionDefault - | typeof horizontalMeasurementActionDefault - | typeof verticalMeasurementActionDefault - | typeof heightMeasurementActionDefault - | typeof areaMeasurementActionDefault - | typeof pointMeasurementActionDefault - | typeof rectangleMeasurementActionDefault - | typeof clearActionDefault export type MeasurementActionCmp = | typeof VcMeasurementArea @@ -139,32 +79,19 @@ export type MeasurementActionCmpRef = Ref< | typeof VcMeasurementRegular > -export type MeasurementActionCmpOpts = - | typeof distanceMeasurementDefault - | typeof componentDistanceMeasurementDefault - | typeof polylineMeasurementDefault - | typeof horizontalMeasurementDefault - | typeof verticalMeasurementDefault - | typeof heightMeasurementDefault - | typeof areaMeasurementDefault - | typeof pointMeasurementDefault - | typeof rectangleMeasurementDefault - -export type AnalysisActionOpts = typeof sightlineAnalysisActionDefault | typeof clearActionDefault export type AnalysisActionCmp = typeof VcAnalysisSightline | typeof VcAnalysisViewshed export type AnalysisActionCmpRef = Ref -export type AnalysisActionCmpOpts = typeof sightlineAnalysisDefault export interface VcDrawingActionInstance { name: string type: 'measurement' | 'drawing' | 'analysis' actionStyle: CSSProperties actionClass: string - actionRef: Ref - actionOpts: MeasurementActionOpts | DrawingActionOpts | AnalysisActionOpts + actionRef: Ref + actionOpts: VcActionTooltipProps cmp: MeasurementActionCmp | DrawgingActionCmp | AnalysisActionCmp cmpRef: MeasurementActionCmpRef | DrawingActionCmpRef | AnalysisActionCmpRef - cmpOpts: MeasurementActionCmpOpts | DrawingActionCmpOpts | AnalysisActionCmpOpts + cmpOpts: VcMeasurementOpts | VcDrawingOpts tip: string isActive: boolean } @@ -177,6 +104,8 @@ export interface VcPointDrawing { lat: number height: number slope: number + + positionDegrees?: [number, number, number] } export interface VcPolylineDrawing { @@ -199,6 +128,8 @@ export interface VcPolylineDrawing { height?: number firstMove?: boolean tempNextPos?: Cesium.Cartesian3 + + positionsDegreesArray?: Array<[number, number, number]> } export interface VcSegmentDrawing { @@ -231,6 +162,9 @@ export interface VcSegmentDrawing { viewshedShadowMap?: Cesium.ShadowMap spotLightCamera?: Cesium.Camera frustum?: Cesium.PerspectiveFrustum + + positionsDegreesArray?: Array<[number, number, number]> + polygonPositionsDegreesArray?: Array<[number, number, number]> } export interface VcDrawingPrimitive { @@ -297,7 +231,7 @@ export type AnalysisType = 'sightline' | 'viewshed' export interface VcDrawingDrawEvt { index?: number name: MeasurementType | DrawingType | AnalysisType - renderDatas: Array + renderDatas: Ref> finished: boolean position?: Cesium.Cartesian3 windowPoistion: Cesium.Cartesian2 @@ -312,7 +246,7 @@ export interface VcDrawingActiveEvt { export interface VcDrawingEditorEvt { type: 'move' | 'insert' | 'remove' | 'removeAll' - renderDatas: Array + renderDatas: Ref> name: MeasurementType | DrawingType | AnalysisType index: number } @@ -335,6 +269,7 @@ export interface VcMeasurementOpts extends VcDrawingOpts { slope?: number } locale?: string + autoUpdateLabelPosition?: boolean } export interface VcComponentDistanceMeasurementOpts extends VcMeasurementOpts { @@ -363,12 +298,24 @@ export interface VcRegularMeasurementOpts extends VcPolylineMeasurementOpts { } export interface VcViewshedAnalysisOpts extends VcDrawingOpts { - ellipsoidOpts?: { - show?: boolean - horizontalViewAngle?: number - verticalViewAngle?: number - color?: VcColor - } + ellipsoidOpts?: VcViewshedEllipsoidOpts +} + +export interface VcViewshedEllipsoidOpts { + show?: boolean + horizontalViewAngle?: number + verticalViewAngle?: number + color?: VcColor } export type VcDrawingPreRenderDatas = Array + +export type MeasurementDecimals = { + distance?: number + angle?: number + area?: number + lng?: number + lat?: number + height?: number + slope?: number +} diff --git a/packages/utils/types.ts b/packages/utils/types.ts index 92744d60e..3bc8ddb97 100644 --- a/packages/utils/types.ts +++ b/packages/utils/types.ts @@ -11,6 +11,8 @@ interface AnyObject { [propName: string]: any } +export type LooseDictionary = { [index in string]: any } + interface VcReadyObject { Cesium: typeof Cesium viewer: Cesium.Viewer @@ -160,6 +162,7 @@ interface SampledPosition { position: VcPosition time?: Cesium.JulianDate | string interval?: number + [key: string]: any } interface Cartesian2Option { @@ -262,18 +265,20 @@ interface VcViewerProvider { primitives: Cesium.PrimitiveCollection groundPrimitives: Cesium.PrimitiveCollection postProcessStages: Cesium.PostProcessStageCollection - // viewerMitt: Emitter layout?: { toolbarContainerRC: Partial timelineContainerRC: Partial animationContainerRC: Partial bottomContainerRC: Partial } + creatingPromise: Promise +} + +interface VcDrawingProvider extends VcViewerProvider { selectedDrawingActionInstance?: VcDrawingActionInstance drawingFabInstance?: VcComponentInternalInstance drawingHandlerActive: boolean getWorldPosition(scene: Cesium.Scene, windowPosition: Cesium.Cartesian2, result: Cesium.Cartesian3): Cesium.Cartesian3 - viewerCreatePromise: Promise } interface ViewerWidgetResizedEvent { @@ -325,20 +330,36 @@ export type StyleValue = string | CSSProperties | Array export type Mutable = { -readonly [P in keyof T]: T[P] } -export type VcComponentPublicInstance = ComponentPublicInstance<{ - load(): Promise - unload(): Promise - reload(): Promise - createPromise: Promise - cesiumObject: VcCesiumObject - getCesiumObject(): any - __updateGraphics?(graphics: VcGraphics | undefined, type: EntityEmitType): boolean - __updateProvider?(provider: VcImageryProvider | undefined): boolean - __updateGeometryInstances?(geometryInstance: Cesium.GeometryInstance, index: number): boolean - __removeGeometryInstances?(geometryInstance: Cesium.GeometryInstance): boolean - __updateGeometry?(geometry: Cesium.Geometry): boolean - __childCount?: Ref -}> +// eslint-disable-next-line @typescript-eslint/ban-types +export type VcComponentPublicInstance = ComponentPublicInstance< + T & { + /** + * Load components manually. + */ + load(): Promise + /** + * Destroy the loaded component manually. + */ + unload(): Promise + /** + * Reload components manually. + */ + reload(): Promise + /** + * Determine whether the component is created by this. + */ + creatingPromise: Promise + /** + * The cesiumobject created by component. + */ + cesiumObject: VcCesiumObject + /** + * Get the cesiumobject created by component. + */ + getCesiumObject(): VcCesiumObject + } +> + // 属性类型 export type VcCallbackPropertyFunction = (time?: Cesium.JulianDate, result?: T) => T @@ -446,6 +467,26 @@ export type VcDistanceDisplayCondition = export type CesiumNearFarScalar = Cesium.NearFarScalar | Cesium.CallbackProperty export type VcNearFarScalar = NearFarScalarOption | Array | VcCallbackPropertyFunction | CesiumNearFarScalar +export interface HeadingPitchRangeOpts { + heading?: number + pitch?: number + range?: number +} +export type VcHeadingPitchRange = HeadingPitchRangeOpts | Array | Cesium.HeadingPitchRange + +export interface HeadingPitchRollOpts { + heading?: number + pitch?: number + roll?: number +} +export type VcHeadingPitchRoll = HeadingPitchRollOpts | Array | Cesium.HeadingPitchRoll + +export type TrackViewOpts = { + mode: 'FP' | 'TP' | 'TRACKED' | 'FREE' | 'CUSTOM' + offset?: HeadingPitchRangeOpts + viewFrom?: [number, number, number] +} + // 对象类型 export type VcGraphics = | Cesium.BillboardGraphics @@ -626,12 +667,20 @@ export type VcContextOptions = { requestWebgl2?: boolean getWebGLStub?: (canvas: HTMLCanvasElement, webglOptions: WebGLContextAttributes) => Cesium.WebGLConstants } + +export type VcHeatMapData = { + x: number + y: number + value: number +} + export { AnyObject, VcCamera, VcReadyObject, VcComponentInternalInstance, VcViewerProvider, + VcDrawingProvider, CesiumMembersEvent, Cartesian2Option, Cartesian3Option,