Skip to content

Commit

Permalink
refactor: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyaoji committed Mar 11, 2022
1 parent b4c23bc commit b64b8eb
Show file tree
Hide file tree
Showing 20 changed files with 405 additions and 263 deletions.
8 changes: 4 additions & 4 deletions packages/components/analyses/flood/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
/**
Expand Down
112 changes: 106 additions & 6 deletions packages/components/analyses/src/defaultProps.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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, {
Expand Down Expand Up @@ -152,7 +159,6 @@ const analysesProps = {
default: () => viewshedAnalysisDefault
}
}
export type VcAnalysesProps = ExtractPropTypes<typeof analysesProps>
const defaultOptions = getDefaultOptionByProps<VcAnalysesProps>(analysesProps)

export {
Expand All @@ -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
}
11 changes: 10 additions & 1 deletion packages/components/entity/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -122,3 +122,12 @@ export default defineComponent({

export type VcEntityProps = ExtractPropTypes<typeof entityProps>
export type VcEntityEmits = typeof emits

export interface VcEntityRef extends VcComponentPublicInstance<VcEntityProps> {
/**
* private method, update graphic.
* @param graphics
* @param type
*/
__updateGraphics: (graphics: VcGraphics | undefined, type: EntityEmitType) => boolean
}
51 changes: 44 additions & 7 deletions packages/components/geometry-instance/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -113,7 +112,6 @@ export default defineComponent({
}
})

// export type VcGeometryInstanceProps = ExtractPropTypes<typeof geometryInstanceProps>
export type VcGeometryInstanceEmits = typeof emits
export type VcGeometryInstanceProps = {
/**
Expand All @@ -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<VcGeometryInstanceProps> {
/**
* 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<number>
}
24 changes: 19 additions & 5 deletions packages/components/imagery-layer/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -88,7 +95,6 @@ export default defineComponent({
}
})

// export type VcLayerImageryProps = ExtractPropTypes<typeof imageryLayerProps>
export type VcLayerImageryEmits = typeof emits
export type VcLayerImageryProps = {
/**
Expand Down Expand Up @@ -202,3 +208,11 @@ export type VcLayerImageryProps = {
*/
'onUpdate:imageryProvider'?: (payload: VcImageryProvider) => void
}

export interface VcLayerImageryRef extends VcComponentPublicInstance<VcLayerImageryProps> {
/**
* private but needed by VcProviderXXX
* @param provider
*/
__updateProvider?(provider: VcImageryProvider | undefined): boolean
}
Loading

0 comments on commit b64b8eb

Please sign in to comment.