import { GET_SETTING, UPDATE_SETTING } from "./constant"; import defaultCover from "@/assets/cover.png"; import { params } from "@/env"; import axios from "./instance"; import { fetchMapTiles } from "./map-tile"; type ServeSetting = { settingsId?: string; pose?: string; cover?: string; mapType?: 'satellite' | 'standard', back?: string | null; mapId?: number | null }; export type Setting = { id?: string; title?: string initGPS?: string pose?: { position: SceneLocalPos; target: SceneLocalPos; panoInfo?: { panoId: any; modelId: string; posInModel: SceneLocalPos; rotInModel: SceneLocalPos; }; }; mapType: 'satellite' | 'standard', cover: string; back?: string | null; fov?: number; openCompass?: boolean; mapId?: number | null }; const toLocal = (serviceSetting: ServeSetting): Setting => ({ id: serviceSetting.settingsId, pose: serviceSetting.pose && JSON.parse(serviceSetting.pose), cover: serviceSetting.cover || defaultCover, back: serviceSetting.back || undefined, mapType: serviceSetting.mapType || 'satellite', mapId: serviceSetting.mapId || undefined, }); const toService = (setting: Setting): ServeSetting => ({ settingsId: setting.id, mapId: setting.mapId || null, pose: setting.pose && JSON.stringify(setting.pose), cover: setting.cover, back: setting.back || null, mapType: setting.mapType, }); export const fetchSetting = async () => { let data = await axios.get(GET_SETTING, { params: { fusionId: params.caseId }, }); const tData = toLocal(data[0] || {}) if (!tData.back && !tData.mapId) { const tiles = await fetchMapTiles() tData.mapId = tiles[0].id } return tData }; export const updateSetting = async (setting: Setting) => { await axios.post(UPDATE_SETTING, { fusionId: params.caseId, ...toService(setting), }); };