ss-dp/src/models/runtime/index.ts

114 lines
2.5 KiB
TypeScript

import { createModel } from '@rematch/core'
import { RootModel } from '..'
import {
FeaturePopInfo,
FeatureTipInfo,
RecordId,
RuntimeState,
InfoDlg,
MarkerInfo,
} from '../_'
import { config } from '../../config'
export const runtime = createModel<RootModel>()({
state: {
cameraTarget: undefined,
mapCenter: null,
markers: {},
viewTick: 1, //用来刷新页面更新Marker位置
showPanels: true, //是否展开面板
homeCheckedObj: {}, //首页展开面板对象
featurePops: [], // [{ id, type, data, lgtd, lttd, elev }]
layerSetting: {},
layerSettingLoop: {},
} as RuntimeState,
reducers: {
setMapCenter(state, o) {
return { ...state, mapCenter: o }
},
setFeaturePop(state, popups: any): RuntimeState {
popups = popups || []
if (!Array.isArray(popups)) {
popups = [popups]
}
const val = popups.filter(
(o: any) => (o.id && o.lgtd && o.lttd && o.type) || o.data
)
console.log(val)
return {
...state,
featurePops: val,
}
},
closeFeaturePop(state, id: RecordId): RuntimeState {
const val = state.featurePops?.filter((o) => o.id !== id)
return {
...state,
featurePops: val,
}
},
closeFeaturePopAll(state): RuntimeState {
const val: any = []
return {
...state,
featurePops: val,
}
},
setMarkers( state, markers: { [layername: string]: MarkerInfo[] }): RuntimeState {
const s = { ...state }
s.markers = {
...s.markers,
...markers,
}
return s
},
tickViewChanged(state) {
return {
...state,
// @ts-ignore
viewTick: state.viewTick + 1,
}
},
setShowPanels(state, val) {
return {
...state,
showPanels: val,
}
},
setHomeCheckedObj(state, val) {
return {
...state,
homeCheckedObj: val,
}
},
// 地图飞行定位, center [lgtd, lttd] | bound [[x1, y1], [x2, y2]]
setCameraTarget(state, o) {
return { ...state, cameraTarget: o }
},
setHome(state, o) {
return {
...state,
cameraTarget: {
center:config.mapCenter,
zoom: 15,
pitch: config.pitch3d,
},
mapCenter: {
center:config.mapCenter,
zoom: 15,
pitch: config.pitch3d,
}
}
},
},
effects: (dispatch) => ({
}),
})