Skip to content

Commit e66dca7

Browse files
committed
refactor: default type for tile and terrain
1 parent 08ffa2b commit e66dca7

5 files changed

Lines changed: 79 additions & 13 deletions

File tree

web/src/classic/components/molecules/Visualizer/compatibility/BACKWARD_COMPATIBILITY.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const overriddenSceneProperty = useMemo(
5454

5555
| Old Type | New Type | Asset ID | Notes |
5656
|-------------------|------------------|----------|--------------------------------|
57+
| `undefined` / `null` | `google_satellite` | - | Default when no type specified |
5758
| `default` | `cesium_ion` | 2 | Cesium World Imagery |
5859
| `default_label` | `cesium_ion` | 3 | Cesium World Imagery + Labels |
5960
| `default_road` | `cesium_ion` | 4 | Cesium World Imagery + Roads |
@@ -80,21 +81,31 @@ const overriddenSceneProperty = useMemo(
8081
"tiles": [
8182
{ "id": "tile-1", "tile_type": "cesium_ion", "cesium_ion_asset_id": 2 },
8283
{ "id": "tile-2", "tile_type": "open_street_map" },
83-
{ "id": "tile-3", "tile_url": "https://..." }
84+
{ "id": "tile-3", "tile_url": "https://...", "tile_type": "google_satellite" }
8485
]
8586
}
8687
```
8788

88-
Note: Tiles without a `tile_type` field are left unchanged.
89+
Note: Tiles without a `tile_type` field are automatically assigned `"google_satellite"` as the default.
8990

9091
## Terrain Type Migrations
9192

9293
### Rules
9394

94-
1. **ArcGIS migration:** If `terrainType` is `"arcgis"`, change to `"reearth_terrain"`
95+
1. **Default:** If `terrainType` is `undefined`, `null`, or empty AND terrain is enabled (`terrain: true`), set to `"reearth_terrain"`
96+
2. **ArcGIS migration:** If `terrainType` is `"arcgis"`, change to `"reearth_terrain"`
9597

9698
### Examples
9799

100+
**Default terrain type:**
101+
```json
102+
// Before
103+
{ "terrain": true }
104+
105+
// After
106+
{ "terrain": true, "terrainType": "reearth_terrain" }
107+
```
108+
98109
**ArcGIS migration:**
99110
```json
100111
// Before

web/src/classic/components/molecules/Visualizer/compatibility/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ This directory contains a comprehensive system for handling backward compatibili
6969
### Backward Compatibility Rules
7070

7171
**Tiles:**
72+
- `undefined` / `null` / empty → `"google_satellite"` (default)
7273
- `"default"``cesium_ion` (asset_id: 2)
7374
- `"default_label"``cesium_ion` (asset_id: 3)
7475
- `"default_road"``cesium_ion` (asset_id: 4)
@@ -77,6 +78,7 @@ This directory contains a comprehensive system for handling backward compatibili
7778
- `"esri_world_topo"``open_street_map`
7879

7980
**Terrain:**
81+
- `undefined` / `null` / empty → `"reearth_terrain"` (default, only when terrain is enabled)
8082
- `"arcgis"``"reearth_terrain"`
8183

8284
### Fallback Rules (Only When No Cesium Ion Token)

web/src/classic/components/molecules/Visualizer/compatibility/backwardCompatibility.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe("migrateTileType", () => {
121121
expect(result).toEqual(tile);
122122
});
123123

124-
it("should not modify tile without tile_type", () => {
124+
it("should default to google_satellite when tile_type is undefined", () => {
125125
const tile = {
126126
id: "test-tile",
127127
tile_url: "https://example.com",
@@ -132,6 +132,7 @@ describe("migrateTileType", () => {
132132
expect(result).toEqual({
133133
id: "test-tile",
134134
tile_url: "https://example.com",
135+
tile_type: "google_satellite",
135136
});
136137
});
137138
});
@@ -190,6 +191,34 @@ describe("migrateTerrainType", () => {
190191
depthTestAgainstTerrain: true,
191192
});
192193
});
194+
195+
it("should default to reearth_terrain when terrainType is undefined", () => {
196+
const terrain = {
197+
terrain: true,
198+
};
199+
200+
const result = migrateTerrainType(terrain);
201+
202+
expect(result).toEqual({
203+
terrain: true,
204+
terrainType: "reearth_terrain",
205+
});
206+
});
207+
208+
it("should default to reearth_terrain when terrainType is undefined with other properties", () => {
209+
const terrain = {
210+
terrain: true,
211+
terrainExaggeration: 1.5,
212+
};
213+
214+
const result = migrateTerrainType(terrain);
215+
216+
expect(result).toEqual({
217+
terrain: true,
218+
terrainType: "reearth_terrain",
219+
terrainExaggeration: 1.5,
220+
});
221+
});
193222
});
194223

195224
describe("applyBackwardCompatibility", () => {

web/src/classic/components/molecules/Visualizer/compatibility/backwardCompatibility.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function applyBackwardCompatibility(
2929
/**
3030
* Migrate tile type from old format to new format
3131
* Backward compatibility rules:
32+
* - undefined/null/empty → "google_satellite" (default)
3233
* - "default" → "cesium_ion" with cesiumIonAssetId: 2
3334
* - "default_label" → "cesium_ion" with cesiumIonAssetId: 3
3435
* - "default_road" → "cesium_ion" with cesiumIonAssetId: 4
@@ -41,6 +42,17 @@ export function migrateTileType(
4142
): NonNullable<SceneProperty["tiles"]>[number] {
4243
const tileType = tile.tile_type;
4344

45+
// Default to google_satellite if no type specified
46+
if (!tileType) {
47+
console.warn(
48+
`[Re:Earth] Tile type migrated: undefined → "google_satellite" - Backward compatibility (tile ID: ${tile.id})`,
49+
);
50+
return {
51+
...tile,
52+
tile_type: "google_satellite",
53+
};
54+
}
55+
4456
// Backward compatibility: migrate old tile types to new ones
4557
switch (tileType) {
4658
case "default": {
@@ -117,11 +129,23 @@ export function migrateTileType(
117129
/**
118130
* Migrate terrain type from old format to new format
119131
* Backward compatibility rules:
132+
* - undefined/null/empty → "reearth_terrain" (default, only when terrain is enabled)
120133
* - If terrainType is "arcgis" (legacy) → change to "reearth_terrain"
121134
*/
122135
export function migrateTerrainType(terrain: TerrainProperty): TerrainProperty {
123136
const { terrainType } = terrain;
124137

138+
// Default to reearth_terrain if no type specified and terrain is enabled
139+
if (!terrainType && terrain.terrain) {
140+
console.warn(
141+
`[Re:Earth] Terrain type migrated: undefined → "reearth_terrain" - Backward compatibility (default)`,
142+
);
143+
return {
144+
...terrain,
145+
terrainType: "reearth_terrain",
146+
};
147+
}
148+
125149
// Migrate "arcgis" to "reearth_terrain" (handles legacy string type)
126150
if ((terrainType as string) === "arcgis") {
127151
console.warn(

web/src/classic/components/molecules/Visualizer/compatibility/compatibility.integration.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("Backward Compatibility + Fallbacks Integration", () => {
3030
]);
3131
expect(afterBackwardCompat?.terrain).toEqual({
3232
terrain: true,
33-
// terrainType is NOT added when missing
33+
terrainType: "reearth_terrain", // Default added when missing
3434
});
3535

3636
// Step 2: Apply fallbacks (no token, so fallbacks apply)
@@ -43,7 +43,7 @@ describe("Backward Compatibility + Fallbacks Integration", () => {
4343
]);
4444
expect(final?.terrain).toEqual({
4545
terrain: true,
46-
// terrainType remains undefined (no fallback when missing)
46+
terrainType: "reearth_terrain", // Default was added in backward compat step
4747
});
4848
});
4949

@@ -71,7 +71,7 @@ describe("Backward Compatibility + Fallbacks Integration", () => {
7171
]);
7272
expect(afterBackwardCompat?.terrain).toEqual({
7373
terrain: true,
74-
// terrainType is NOT added when missing
74+
terrainType: "reearth_terrain", // Default added when missing
7575
});
7676

7777
// Step 2: Apply fallbacks (has token, so NO fallbacks)
@@ -84,31 +84,31 @@ describe("Backward Compatibility + Fallbacks Integration", () => {
8484
]);
8585
expect(final?.terrain).toEqual({
8686
terrain: true,
87-
// terrainType remains undefined (token doesn't affect missing terrainType)
87+
terrainType: "reearth_terrain", // Default was added in backward compat step
8888
});
8989
});
9090

91-
it("should handle tile without tile_type (no migration)", () => {
91+
it("should handle tile without tile_type (adds google_satellite default)", () => {
9292
const input: SceneProperty = {
9393
tiles: [{ id: "tile-1", tile_url: "https://example.com" }],
9494
};
9595

96-
// Step 1: Backward compatibility (does NOT add tile_type when missing)
96+
// Step 1: Backward compatibility (adds google_satellite default)
9797
const afterBackwardCompat = applyBackwardCompatibility(input);
9898

9999
expect(afterBackwardCompat?.tiles?.[0]).toEqual({
100100
id: "tile-1",
101101
tile_url: "https://example.com",
102-
// tile_type and cesium_ion_asset_id are NOT added
102+
tile_type: "google_satellite", // Default added
103103
});
104104

105-
// Step 2: Apply fallbacks (no tile_type, so no fallback applies)
105+
// Step 2: Apply fallbacks (google_satellite doesn't need fallback)
106106
const final = applyFallbacks(afterBackwardCompat);
107107

108108
expect(final?.tiles?.[0]).toEqual({
109109
id: "tile-1",
110110
tile_url: "https://example.com",
111-
// Remains unchanged
111+
tile_type: "google_satellite", // Remains google_satellite
112112
});
113113
});
114114

0 commit comments

Comments
 (0)