From df8082383b9544bef6f3353074fe61644f77c22a Mon Sep 17 00:00:00 2001 From: zouyaoji <370681295@qq.com> Date: Wed, 9 Mar 2022 10:29:43 +0800 Subject: [PATCH] refactor(analyses): improve types --- packages/components/analyses/src/index.ts | 159 ++++-------------- .../analyses/src/sightline/index.ts | 114 ++++++++++++- .../components/analyses/src/viewshed/index.ts | 113 ++++++++++++- 3 files changed, 252 insertions(+), 134 deletions(-) diff --git a/packages/components/analyses/src/index.ts b/packages/components/analyses/src/index.ts index a1ab0a3d4..aeed83792 100644 --- a/packages/components/analyses/src/index.ts +++ b/packages/components/analyses/src/index.ts @@ -1,36 +1,19 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2022-01-06 10:23:09 - * @LastEditTime: 2022-03-06 22:17:24 + * @LastEditTime: 2022-03-09 10:26:33 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\analyses\src\index.ts */ -import { VcActionTooltipProps, VcComponentInternalInstance, VcReadyObject } from '@vue-cesium/utils/types' -import { defineComponent, ExtractPropTypes, getCurrentInstance, reactive, ref, VNode } from 'vue' +import type { VcActionTooltipProps, VcComponentInternalInstance, VcComponentPublicInstance } from '@vue-cesium/utils/types' +import { defineComponent, getCurrentInstance, reactive, ref } from 'vue' import { useLocale } from '@vue-cesium/composables' -import { clearActionDefault } from '@vue-cesium/composables/use-drawing/defaultOpts' -import { - defaultOptions, - analysesProps, - mainFabDefault, - sightlineAnalysisActionDefault, - sightlineAnalysisDefault, - viewshedAnalysisActionDefault -} from './defaultProps' -import { - AnalysisActionCmpRef, - VcDrawingActionInstance, - VcDrawingActiveEvt, - VcDrawingDrawEvt, - VcDrawingEditorEvt, - VcDrawingMouseEvt, - VcDrawingOpts, - VcViewshedAnalysisOpts -} from '@vue-cesium/utils/drawing-types' +import { defaultOptions, analysesProps, VcAnalysesProps } from './defaultProps' +import type { AnalysisActionCmpRef, VcDrawingActionInstance, VcDrawingOpts, VcViewshedAnalysisOpts } from '@vue-cesium/utils/drawing-types' import { camelize } from '@vue-cesium/utils/util' -import { VcFabActionRef, VcFabProps } from '@vue-cesium/components/ui' +import type { VcFabActionRef, VcFabProps, VcFabRef } from '@vue-cesium/components/ui' import useDrawingFab from '@vue-cesium/composables/use-drawing/use-drawing-fab' import VcAnalysisSightline from './sightline' import VcAnalysisViewshed from './viewshed' @@ -44,7 +27,7 @@ export default defineComponent({ name: 'VcAnalyses', props: analysesProps, emits: emits, - setup(props: ExtractPropTypes, ctx) { + setup(props: VcAnalysesProps, ctx) { // state const instance = getCurrentInstance() as VcComponentInternalInstance instance.cesiumClass = 'VcAnalyses' @@ -52,22 +35,14 @@ export default defineComponent({ const options: any = {} // computed - const clearActionOpts = reactive(Object.assign({}, defaultOptions.clearActionOpts, props.clearActionOpts)) - const mainFabOpts = reactive(Object.assign({}, defaultOptions.mainFabOpts, props.mainFabOpts)) + const clearActionOpts = reactive(Object.assign({}, defaultOptions.clearActionOpts, props.clearActionOpts)) + const mainFabOpts = reactive(Object.assign({}, defaultOptions.mainFabOpts, props.mainFabOpts)) - const sightlineActionOpts = reactive( - Object.assign({}, defaultOptions.sightlineActionOpts, props.sightlineActionOpts) - ) - const sightlineAnalysisOpts = reactive( - Object.assign({}, defaultOptions.sightlineAnalysisOpts, props.sightlineAnalysisOpts) - ) + const sightlineActionOpts = reactive(Object.assign({}, defaultOptions.sightlineActionOpts, props.sightlineActionOpts)) + const sightlineAnalysisOpts = reactive(Object.assign({}, defaultOptions.sightlineAnalysisOpts, props.sightlineAnalysisOpts)) - const viewshedActionOpts = reactive( - Object.assign({}, defaultOptions.viewshedActionOpts, props.viewshedActionOpts) - ) - const viewshedAnalysisOpts = reactive( - Object.assign({}, defaultOptions.viewshedAnalysisOpts, props.viewshedAnalysisOpts) - ) + const viewshedActionOpts = reactive(Object.assign({}, defaultOptions.viewshedActionOpts, props.viewshedActionOpts)) + const viewshedAnalysisOpts = reactive(Object.assign({}, defaultOptions.viewshedAnalysisOpts, props.viewshedAnalysisOpts)) options.sightlineActionOpts = sightlineActionOpts options.sightlineAnalysisOpts = sightlineAnalysisOpts @@ -82,9 +57,7 @@ export default defineComponent({ background: options[`${camelize(analysisName)}ActionOpts`].color, color: options[`${camelize(analysisName)}ActionOpts`].textColor }, - actionClass: `vc-analysis-${analysisName} vc-analysis-button${ - analysisName === (instance.proxy as any).selectedDrawingActionInstance?.name ? ' active' : '' - }`, + actionClass: `vc-analysis-${analysisName} vc-analysis-button`, actionRef: ref(null), actionOpts: options[`${camelize(analysisName)}ActionOpts`] as VcActionTooltipProps, cmp: getDrawingCmp(analysisName), @@ -111,106 +84,44 @@ export default defineComponent({ export { VcAnalysisSightline, VcAnalysisViewshed, analysesProps } -// export type { VcAnalysesProps } from './defaultProps' +export type { VcAnalysesProps } from './defaultProps' export type VcAnalysesEmits = typeof emits - -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 +export interface VcAnalysesRef extends VcComponentPublicInstance { /** - * Specify the style options of the floating action button of the VcAnalyses component. + * Get or set the editingActionName. */ - mainFabOpts?: VcActionTooltipProps & VcFabProps + editingActionName?: string /** - * Specify the style options of the sightline analysis action button. + * Clear all drawing results. */ - sightlineActionOpts?: VcActionTooltipProps + clearAll: () => void /** - * Specify sightline analysis options. + * End listening for the ScreenSpaceEventHandler events. */ - sightlineAnalysisOpts?: VcDrawingOpts + deactivate: () => void /** - * Specify the style options of the viewshed analysis action button. + * Start listening for ScreenSpaceEventHandler events. */ - viewshedActionOpts?: VcActionTooltipProps + activate: () => void /** - * Specify viewshed analysis options. + * Toggle drawing instance. + * @param drawingOption drawing instance or drawing instance name. */ - viewshedAnalysisOpts?: VcViewshedAnalysisOpts + toggleAction: (drawingOption: VcDrawingActionInstance | string) => void /** - * Specify the style options of the clear action button. + * Get the float action button template reference. */ - clearActionOpts?: VcActionTooltipProps + getFabRef: () => VcFabRef /** - * Triggers before the VcCompass is loaded. + * Get the drawingActionInstance by action name. */ - onBeforeLoad?: (instance: VcComponentInternalInstance) => void + getDrawingActionInstance: (actionName: string) => VcDrawingActionInstance /** - * Triggers when the VcCompass is successfully loaded. + * Get the drawing action instances. */ - onReady?: (readyObject: VcReadyObject) => void - /** - * Triggers when the VcCompass 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 -} - -export type VcAnalysesSlots = { + getDrawingActionInstances: () => Array /** - * body slot content of the component + * Get the selected drawing action instance. */ - body: () => VNode[] + getSelectedDrawingActionInstance: () => VcDrawingActionInstance } diff --git a/packages/components/analyses/src/sightline/index.ts b/packages/components/analyses/src/sightline/index.ts index 575ef5455..bd7ea86ca 100644 --- a/packages/components/analyses/src/sightline/index.ts +++ b/packages/components/analyses/src/sightline/index.ts @@ -1,20 +1,31 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2022-01-04 21:42:14 - * @LastEditTime: 2022-02-08 16:21:48 + * @LastEditTime: 2022-03-08 22:48:54 * @LastEditors: zouyaoji * @Description: * @FilePath: \vue-cesium@next\packages\components\analyses\src\sightline\index.ts */ -import type { PropType } from 'vue' +import type { PropType, Ref } from 'vue' import { defineComponent } from 'vue' import { useDrawingActionProps } from '@vue-cesium/composables/use-drawing/props' import useDrawingPolyline from '@vue-cesium/composables/use-drawing/use-drawing-polyline' import type { VcPrimitiveGroundPolylineProps, VcPrimitiveProps } from '../../../primitives' import type { VcGeometryPolylineProps } from '../../../geometries' import useDrawingSegment from '@vue-cesium/composables/use-drawing/use-drawing-segment' -import { VcPolygonProps } from '../../../primitive-collections' +import { VcPointProps, VcPolygonProps } from '../../../primitive-collections' import { drawingEmit } from '@vue-cesium/utils/emits' +import { + VcDrawingDrawEvt, + VcDrawingEditorEvt, + VcDrawingMouseEvt, + VcDrawingPreRenderDatas, + VcDrawTipOpts, + VcEditorOpts, + VcPolylineDrawing, + VcSegmentDrawing +} from '@vue-cesium/utils/drawing-types' +import { VcComponentInternalInstance, VcComponentPublicInstance, VcReadyObject } from '@vue-cesium/utils/types' export default defineComponent({ name: 'VcAnalysisSightline', @@ -26,8 +37,7 @@ export default defineComponent({ sightlineType: { type: String as PropType<'segment' | 'polyline' | 'circle'>, default: 'polyline' - }, - edge: Number + } }, emits: drawingEmit, setup(props, ctx) { @@ -39,3 +49,97 @@ export default defineComponent({ } } }) + +export type VcAnalysisSightlineProps = { + /** + * Specify whether to respond to mouse pick events. + */ + enableMouseEvent?: boolean + /** + * Specify Whether the drawing object is visible. + */ + show?: boolean + /** + * Specify whether the drawing result can be edited. + */ + editable?: boolean + /** + * Specify drawing hints. + */ + drawtip?: VcDrawTipOpts + /** + * Specify parameters for drawing points. + */ + pointOpts?: VcPointProps + /** + * Specify editor options. + */ + editorOpts?: VcEditorOpts + /** + * Specify editor mode. + */ + mode?: number + /** + * Specify prerender datas. + */ + preRenderDatas?: VcDrawingPreRenderDatas + /** + * Specify parameters for drawing polylines. + */ + polylineOpts?: VcGeometryPolylineProps + /** + * Specify parameters for drawing polygons. + */ + polygonOpts?: VcPolygonProps + /** + * Specify parameters for drawing primitives. + */ + primitiveOpts?: VcPrimitiveProps & VcPrimitiveGroundPolylineProps + /** + * Specify the type of sightline. + */ + sightlineType?: 'segment' | 'polyline' + /** + * Triggers before the VcAnalysisSightline is loaded. + */ + onBeforeLoad?: (instance: VcComponentInternalInstance) => void + /** + * Triggers when the VcAnalysisSightline is successfully loaded. + */ + onReady?: (readyObject: VcReadyObject) => void + /** + * Triggers when the VcAnalysisSightline is destroyed. + */ + onDestroyed?: (instance: VcComponentInternalInstance) => 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 +} + +export interface VcAnalysisSightlineRef extends VcComponentPublicInstance { + /** + * Get or set the renderDatas. + */ + renderDatas: Ref> + /** + * start a new draw. + */ + startNew: () => void + /** + * stop drawing. + */ + stop: () => void + /** + * clear and stop drawing. + */ + clear: () => void +} diff --git a/packages/components/analyses/src/viewshed/index.ts b/packages/components/analyses/src/viewshed/index.ts index 038aec1c2..e859c7cde 100644 --- a/packages/components/analyses/src/viewshed/index.ts +++ b/packages/components/analyses/src/viewshed/index.ts @@ -1,25 +1,38 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2022-01-06 16:26:03 - * @LastEditTime: 2022-02-08 16:22:43 + * @LastEditTime: 2022-03-08 22:55:33 * @LastEditors: zouyaoji * @Description: refer to https://blog.csdn.net/fywindmoon/article/details/108415116 * @FilePath: \vue-cesium@next\packages\components\analyses\src\viewshed\index.ts */ -import { defineComponent, PropType } from 'vue' +import { defineComponent, PropType, Ref } from 'vue' import { useDrawingActionProps } from '@vue-cesium/composables/use-drawing/props' import useDrawingSegment from '@vue-cesium/composables/use-drawing/use-drawing-segment' import fragmentShader from './fragmentShader' import { VcGeometryPolylineProps } from '../../../geometries' -import { VcPrimitiveGroundPolylineProps, VcPrimitiveProps } from '../../../primitives' +import { VcPrimitiveProps } from '../../../primitives' import { drawingEmit } from '@vue-cesium/utils/emits' +import { + VcDrawingDrawEvt, + VcDrawingEditorEvt, + VcDrawingMouseEvt, + VcDrawingPreRenderDatas, + VcDrawTipOpts, + VcEditorOpts, + VcPolylineDrawing, + VcSegmentDrawing, + VcViewshedEllipsoidOpts +} from '@vue-cesium/utils/drawing-types' +import { VcPointProps } from '../../../primitive-collections' +import { VcComponentInternalInstance, VcComponentPublicInstance, VcReadyObject } from '@vue-cesium/utils/types' export default defineComponent({ name: 'VcAnalysisViewshed', props: { ...useDrawingActionProps, polylineOpts: Object as PropType, - primitiveOpts: Object as PropType, - ellipsoidOpts: Object + primitiveOpts: Object as PropType, + ellipsoidOpts: Object as PropType }, emits: drawingEmit, setup(props, ctx) { @@ -27,3 +40,93 @@ export default defineComponent({ return useDrawingSegment(props, ctx, 'VcAnalysisViewshed', fragmentShader) } }) + +export type VcAnalysisViewshedProps = { + /** + * Specify whether to respond to mouse pick events. + */ + enableMouseEvent?: boolean + /** + * Specify Whether the drawing object is visible. + */ + show?: boolean + /** + * Specify whether the drawing result can be edited. + */ + editable?: boolean + /** + * Specify drawing hints. + */ + drawtip?: VcDrawTipOpts + /** + * Specify parameters for drawing points. + */ + pointOpts?: VcPointProps + /** + * Specify editor options. + */ + editorOpts?: VcEditorOpts + /** + * Specify editor mode. + */ + mode?: number + /** + * Specify prerender datas. + */ + preRenderDatas?: VcDrawingPreRenderDatas + /** + * Specify parameters for drawing polylines. + */ + polylineOpts?: VcGeometryPolylineProps + /** + * Specify parameters for drawing primitives. + */ + primitiveOpts?: VcPrimitiveProps + /** + * Specify the ellipsoid options of viewshed. + */ + ellipsoidOpts?: VcViewshedEllipsoidOpts + /** + * Triggers before the VcAnalysisViewshed is loaded. + */ + onBeforeLoad?: (instance: VcComponentInternalInstance) => void + /** + * Triggers when the VcAnalysisViewshed is successfully loaded. + */ + onReady?: (readyObject: VcReadyObject) => void + /** + * Triggers when the VcAnalysisViewshed is destroyed. + */ + onDestroyed?: (instance: VcComponentInternalInstance) => 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 +} + +export interface VcAnalysisViewshedRef extends VcComponentPublicInstance { + /** + * Get or set the renderDatas. + */ + renderDatas: Ref> + /** + * start a new draw. + */ + startNew: () => void + /** + * stop drawing. + */ + stop: () => void + /** + * clear and stop drawing. + */ + clear: () => void +}