-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackwardCompatibility.ts
More file actions
161 lines (142 loc) · 4.79 KB
/
Copy pathbackwardCompatibility.ts
File metadata and controls
161 lines (142 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { cloneDeep } from "lodash-es";
import type { SceneProperty, TerrainProperty } from "../Engine/ref";
/**
* Apply backward compatibility transformations to scene property
* This ensures old tile/terrain types are migrated to new provider names
*/
export function applyBackwardCompatibility(
sceneProperty: SceneProperty | undefined,
): SceneProperty | undefined {
if (!sceneProperty) return undefined;
const cloned = cloneDeep(sceneProperty);
// Apply tile type backward compatibility
if (cloned.tiles) {
cloned.tiles = cloned.tiles.map(tile => migrateTileType(tile));
}
// Apply terrain type backward compatibility
if (cloned.terrain) {
cloned.terrain = migrateTerrainType(cloned.terrain);
}
return cloned;
}
/**
* Migrate tile type from old format to new format
* Backward compatibility rules:
* - undefined/null/empty → "google_satellite" (default)
* - "default" → "cesium_ion" with cesiumIonAssetId: 2
* - "default_label" → "cesium_ion" with cesiumIonAssetId: 3
* - "default_road" → "cesium_ion" with cesiumIonAssetId: 4
* - "black_marble" → "cesium_ion" with cesiumIonAssetId: 3812
* - "stamen_toner" → "open_street_map"
* - "esri_world_topo" → "open_street_map"
*/
export function migrateTileType(
tile: NonNullable<SceneProperty["tiles"]>[number],
): NonNullable<SceneProperty["tiles"]>[number] {
const tileType = tile.tile_type;
// Default to google_satellite if no type specified
if (!tileType) {
console.warn(
`[Re:Earth] Tile type migrated: undefined → "google_satellite" - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "google_satellite",
};
}
// Backward compatibility: migrate old tile types to new ones
switch (tileType) {
case "default": {
const assetId = tile.cesium_ion_asset_id ?? 2;
console.warn(
`[Re:Earth] Tile type migrated: "default" → "cesium_ion" (asset_id: ${assetId}) - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "cesium_ion",
cesium_ion_asset_id: assetId,
};
}
case "default_label": {
const assetId = tile.cesium_ion_asset_id ?? 3;
console.warn(
`[Re:Earth] Tile type migrated: "default_label" → "cesium_ion" (asset_id: ${assetId}) - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "cesium_ion",
cesium_ion_asset_id: assetId,
};
}
case "default_road": {
const assetId = tile.cesium_ion_asset_id ?? 4;
console.warn(
`[Re:Earth] Tile type migrated: "default_road" → "cesium_ion" (asset_id: ${assetId}) - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "cesium_ion",
cesium_ion_asset_id: assetId,
};
}
case "black_marble": {
const assetId = tile.cesium_ion_asset_id ?? 3812;
console.warn(
`[Re:Earth] Tile type migrated: "black_marble" → "cesium_ion" (asset_id: ${assetId}) - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "cesium_ion",
cesium_ion_asset_id: assetId,
};
}
case "stamen_toner":
console.warn(
`[Re:Earth] Tile type migrated: "stamen_toner" → "open_street_map" - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "open_street_map",
};
case "esri_world_topo":
console.warn(
`[Re:Earth] Tile type migrated: "esri_world_topo" → "open_street_map" - Backward compatibility (tile ID: ${tile.id})`,
);
return {
...tile,
tile_type: "open_street_map",
};
default:
return tile;
}
}
/**
* Migrate terrain type from old format to new format
* Backward compatibility rules:
* - undefined/null/empty → "reearth_terrain" (default, only when terrain is enabled)
* - If terrainType is "arcgis" (legacy) → change to "reearth_terrain"
*/
export function migrateTerrainType(terrain: TerrainProperty): TerrainProperty {
const { terrainType } = terrain;
// Default to reearth_terrain if no type specified and terrain is enabled
if (!terrainType && terrain.terrain) {
console.warn(
`[Re:Earth] Terrain type migrated: undefined → "reearth_terrain" - Backward compatibility (default)`,
);
return {
...terrain,
terrainType: "reearth_terrain",
};
}
// Migrate "arcgis" to "reearth_terrain" (handles legacy string type)
if ((terrainType as string) === "arcgis") {
console.warn(
`[Re:Earth] Terrain type migrated: "arcgis" → "reearth_terrain" - Backward compatibility (legacy provider)`,
);
return {
...terrain,
terrainType: "reearth_terrain",
};
}
return terrain;
}