Skip to content

Commit

Permalink
refactor(analyses): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyaoji committed Mar 9, 2022
1 parent e6720af commit df80823
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 134 deletions.
159 changes: 35 additions & 124 deletions packages/components/analyses/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -44,30 +27,22 @@ export default defineComponent({
name: 'VcAnalyses',
props: analysesProps,
emits: emits,
setup(props: ExtractPropTypes<typeof analysesProps>, ctx) {
setup(props: VcAnalysesProps, ctx) {
// state
const instance = getCurrentInstance() as VcComponentInternalInstance
instance.cesiumClass = 'VcAnalyses'
const { t } = useLocale()

const options: any = {}
// computed
const clearActionOpts = reactive<typeof clearActionDefault>(Object.assign({}, defaultOptions.clearActionOpts, props.clearActionOpts))
const mainFabOpts = reactive<typeof mainFabDefault>(Object.assign({}, defaultOptions.mainFabOpts, props.mainFabOpts))
const clearActionOpts = reactive<VcActionTooltipProps>(Object.assign({}, defaultOptions.clearActionOpts, props.clearActionOpts))
const mainFabOpts = reactive<VcActionTooltipProps & VcFabProps>(Object.assign({}, defaultOptions.mainFabOpts, props.mainFabOpts))

const sightlineActionOpts = reactive<typeof sightlineAnalysisActionDefault>(
Object.assign({}, defaultOptions.sightlineActionOpts, props.sightlineActionOpts)
)
const sightlineAnalysisOpts = reactive<typeof sightlineAnalysisDefault>(
Object.assign({}, defaultOptions.sightlineAnalysisOpts, props.sightlineAnalysisOpts)
)
const sightlineActionOpts = reactive<VcActionTooltipProps>(Object.assign({}, defaultOptions.sightlineActionOpts, props.sightlineActionOpts))
const sightlineAnalysisOpts = reactive<VcDrawingOpts>(Object.assign({}, defaultOptions.sightlineAnalysisOpts, props.sightlineAnalysisOpts))

const viewshedActionOpts = reactive<typeof viewshedAnalysisActionDefault>(
Object.assign({}, defaultOptions.viewshedActionOpts, props.viewshedActionOpts)
)
const viewshedAnalysisOpts = reactive<typeof sightlineAnalysisDefault>(
Object.assign({}, defaultOptions.viewshedAnalysisOpts, props.viewshedAnalysisOpts)
)
const viewshedActionOpts = reactive<VcActionTooltipProps>(Object.assign({}, defaultOptions.viewshedActionOpts, props.viewshedActionOpts))
const viewshedAnalysisOpts = reactive<VcViewshedAnalysisOpts>(Object.assign({}, defaultOptions.viewshedAnalysisOpts, props.viewshedAnalysisOpts))

options.sightlineActionOpts = sightlineActionOpts
options.sightlineAnalysisOpts = sightlineAnalysisOpts
Expand All @@ -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<VcFabActionRef>(null),
actionOpts: options[`${camelize(analysisName)}ActionOpts`] as VcActionTooltipProps,
cmp: getDrawingCmp(analysisName),
Expand All @@ -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<VcAnalysesProps> {
/**
* 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<VcDrawingActionInstance>
/**
* body slot content of the component
* Get the selected drawing action instance.
*/
body: () => VNode[]
getSelectedDrawingActionInstance: () => VcDrawingActionInstance
}
114 changes: 109 additions & 5 deletions packages/components/analyses/src/sightline/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -26,8 +37,7 @@ export default defineComponent({
sightlineType: {
type: String as PropType<'segment' | 'polyline' | 'circle'>,
default: 'polyline'
},
edge: Number
}
},
emits: drawingEmit,
setup(props, ctx) {
Expand All @@ -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<VcAnalysisSightlineProps> {
/**
* Get or set the renderDatas.
*/
renderDatas: Ref<Array<VcSegmentDrawing | VcPolylineDrawing>>
/**
* start a new draw.
*/
startNew: () => void
/**
* stop drawing.
*/
stop: () => void
/**
* clear and stop drawing.
*/
clear: () => void
}
Loading

0 comments on commit df80823

Please sign in to comment.