@metagl/smartearth-base 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +129 -5
- package/dist/chunk-6U32ENXU.js +736 -0
- package/dist/{chunk-O7CP7PJG.js → chunk-JGNKH4TR.js} +342 -88
- package/dist/chunk-XJRW7VZC.js +885 -0
- package/dist/createEarth-BY0dtgQQ.d.ts +647 -0
- package/dist/errors-cB7IQlHy.d.ts +15 -0
- package/dist/index.d.ts +44 -8
- package/dist/index.js +2 -1
- package/dist/presets.d.ts +311 -0
- package/dist/presets.js +2 -0
- package/dist/vue.d.ts +79 -3
- package/dist/vue.js +240 -3
- package/package.json +75 -70
- package/dist/errors-CtkYU3iT.d.ts +0 -267
|
@@ -1,38 +1,7 @@
|
|
|
1
|
+
import { SmartEarthError, Emitter, readSdkRenderVersion, createEarthEnvironment, describeCause, MAP_TOKEN_APPLY_URL, describeLayerCause, syncEnabledFlags, requirePresetDocument, ALL_EFFECTS } from './chunk-XJRW7VZC.js';
|
|
1
2
|
import * as CesiumNS from 'cesium';
|
|
2
3
|
import * as SdkRender from '@metagl/sdk-render';
|
|
3
4
|
|
|
4
|
-
// src/errors.ts
|
|
5
|
-
var MAP_TOKEN_APPLY_URL = "https://datacloud.geovisearth.com/";
|
|
6
|
-
var SmartEarthError = class extends Error {
|
|
7
|
-
code;
|
|
8
|
-
cause;
|
|
9
|
-
constructor(code, message, cause) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = "SmartEarthError";
|
|
12
|
-
this.code = code;
|
|
13
|
-
if (cause !== void 0) this.cause = cause;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
function isSmartEarthError(value) {
|
|
17
|
-
return value instanceof SmartEarthError;
|
|
18
|
-
}
|
|
19
|
-
var REDACTED = "***";
|
|
20
|
-
function redactUrlQueries(text) {
|
|
21
|
-
return text.replace(/(\b(?:https?|wss?):\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`);
|
|
22
|
-
}
|
|
23
|
-
function describeLayerCause(cause) {
|
|
24
|
-
return redactUrlQueries(describeCause(cause));
|
|
25
|
-
}
|
|
26
|
-
var MIN_SECRET_LENGTH = 8;
|
|
27
|
-
function describeCause(cause, secrets = []) {
|
|
28
|
-
let text = cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "\u672A\u77E5\u9519\u8BEF";
|
|
29
|
-
for (const secret of secrets) {
|
|
30
|
-
if (!secret || secret.length < MIN_SECRET_LENGTH) continue;
|
|
31
|
-
text = text.split(secret).join(REDACTED).split(encodeURIComponent(secret)).join(REDACTED);
|
|
32
|
-
}
|
|
33
|
-
return text;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
5
|
// src/quality/profiles.ts
|
|
37
6
|
var LOW_QUALITY_OVERRIDES = {
|
|
38
7
|
ssgi: { enabled: false },
|
|
@@ -287,6 +256,7 @@ function createEarthPbr(render) {
|
|
|
287
256
|
const ok = typeof target === "string" && target.length > 0 || typeof target === "object" && target !== null;
|
|
288
257
|
if (!ok) throw new SmartEarthError("INVALID_OPTIONS", "PBR \u76EE\u6807\u5FC5\u987B\u662F tileset \u5B9E\u4F8B\u6216\u975E\u7A7A URL\u3002");
|
|
289
258
|
};
|
|
259
|
+
const initialGlobal = { ...readConfig(render).pbr ?? {} };
|
|
290
260
|
return {
|
|
291
261
|
setTilesetMaterial(target, params) {
|
|
292
262
|
requireTarget(target);
|
|
@@ -314,6 +284,16 @@ function createEarthPbr(render) {
|
|
|
314
284
|
importConfig(config) {
|
|
315
285
|
requireParams(config);
|
|
316
286
|
call("\u5BFC\u5165\u914D\u7F6E", () => render.updateSystemConfig(MATERIAL_SYSTEM, structuredClone(config)));
|
|
287
|
+
},
|
|
288
|
+
setAutoManageTilesets(on) {
|
|
289
|
+
if (typeof on !== "boolean") throw new SmartEarthError("INVALID_OPTIONS", "\u81EA\u52A8\u7EB3\u7BA1\u5F00\u5173\u5FC5\u987B\u662F true / false\u3002");
|
|
290
|
+
call("\u8BBE\u7F6E\u81EA\u52A8\u7EB3\u7BA1", () => render.updateSystemConfig(MATERIAL_SYSTEM, { autoManageTilesets: on }));
|
|
291
|
+
},
|
|
292
|
+
getAutoManageTilesets() {
|
|
293
|
+
return readConfig(render).autoManageTilesets !== false;
|
|
294
|
+
},
|
|
295
|
+
resetGlobal() {
|
|
296
|
+
call("\u6062\u590D\u9ED8\u8BA4\u6750\u8D28", () => render.updateSystemConfig(MATERIAL_SYSTEM, { pbr: { ...initialGlobal } }));
|
|
317
297
|
}
|
|
318
298
|
};
|
|
319
299
|
}
|
|
@@ -712,35 +692,6 @@ var tileset3dLayerFactory = async (context, spec) => {
|
|
|
712
692
|
};
|
|
713
693
|
};
|
|
714
694
|
|
|
715
|
-
// src/core/events.ts
|
|
716
|
-
var Emitter = class {
|
|
717
|
-
constructor(onError = () => void 0) {
|
|
718
|
-
this.onError = onError;
|
|
719
|
-
}
|
|
720
|
-
onError;
|
|
721
|
-
listeners = /* @__PURE__ */ new Map();
|
|
722
|
-
on(event, listener) {
|
|
723
|
-
const set = this.listeners.get(event) ?? /* @__PURE__ */ new Set();
|
|
724
|
-
set.add(listener);
|
|
725
|
-
this.listeners.set(event, set);
|
|
726
|
-
return () => {
|
|
727
|
-
set.delete(listener);
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
emit(event, payload) {
|
|
731
|
-
for (const listener of this.listeners.get(event) ?? []) {
|
|
732
|
-
try {
|
|
733
|
-
listener(payload);
|
|
734
|
-
} catch (error) {
|
|
735
|
-
this.onError(error);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
clear() {
|
|
740
|
-
this.listeners.clear();
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
|
|
744
695
|
// src/layers/routePath.ts
|
|
745
696
|
function fail(layerId, message) {
|
|
746
697
|
throw new SmartEarthError("INVALID_OPTIONS", `\u822A\u7EBF\u56FE\u5C42 ${layerId}\uFF1A${message}`);
|
|
@@ -1246,6 +1197,7 @@ function fillMissingZ(geojson, height) {
|
|
|
1246
1197
|
// src/layers/riverWater.ts
|
|
1247
1198
|
var DEFAULT_RIVER_WIDTH = 60;
|
|
1248
1199
|
var RIVER_LINES_FIXED_IN = "4.0.2";
|
|
1200
|
+
var PIT_WATER_IN = "4.0.3";
|
|
1249
1201
|
var usage = /* @__PURE__ */ new WeakMap();
|
|
1250
1202
|
function systemsOf(render) {
|
|
1251
1203
|
const candidate = render;
|
|
@@ -1266,24 +1218,38 @@ function validate4(spec) {
|
|
|
1266
1218
|
requireLayerSpec(isRecord(spec.data) || typeof spec.data === "string", spec.id, "data \u9700\u8981\u6C34\u7CFB GeoJSON \u6216 URL\u3002");
|
|
1267
1219
|
if (spec.dig !== void 0) {
|
|
1268
1220
|
requireLayerSpec(isRecord(spec.dig) && typeof spec.dig.depth === "number" && spec.dig.depth > 0, spec.id, "dig.depth \u5FC5\u987B > 0\uFF08\u7C73\uFF09\u3002");
|
|
1221
|
+
const fill = spec.dig.fillWater;
|
|
1222
|
+
requireLayerSpec(fill === void 0 || typeof fill === "boolean" || isPitWaterOptions(fill), spec.id, "dig.fillWater \u53EA\u80FD\u662F\u5E03\u5C14\u503C\u6216 { freeboard?, minDepth?, spacingMeters? }\uFF08\u975E\u8D1F\u6570\u5B57\uFF09\u3002");
|
|
1269
1223
|
}
|
|
1224
|
+
requireLayerSpec(spec.lift === void 0 || typeof spec.lift === "number" && Number.isFinite(spec.lift), spec.id, "lift \u5FC5\u987B\u662F\u6570\u5B57\uFF08\u7C73\uFF09\u3002");
|
|
1270
1225
|
if (spec.config !== void 0) requireLayerSpec(isRecord(spec.config), spec.id, "config \u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
|
|
1271
1226
|
requireLayerSpec(spec.width === void 0 || typeof spec.width === "number" && spec.width > 0, spec.id, "width \u5FC5\u987B > 0\uFF08\u7C73\uFF09\u3002");
|
|
1272
1227
|
requireLayerSpec(spec.height === void 0 || typeof spec.height === "number" && Number.isFinite(spec.height), spec.id, "height \u5FC5\u987B\u662F\u6570\u5B57\uFF08\u7C73\uFF09\u3002");
|
|
1273
1228
|
requireLayerSpec(spec.lineMode === void 0 || LINE_MODES.has(spec.lineMode), spec.id, "lineMode \u53EA\u80FD\u662F 'auto'\u3001'ribbon' \u6216 'native'\u3002");
|
|
1274
1229
|
}
|
|
1230
|
+
function isPitWaterOptions(value) {
|
|
1231
|
+
if (!isRecord(value)) return false;
|
|
1232
|
+
return ["freeboard", "minDepth", "spacingMeters"].every((key) => {
|
|
1233
|
+
const field = value[key];
|
|
1234
|
+
return field === void 0 || typeof field === "number" && Number.isFinite(field) && field >= 0;
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
function pitWaterSupported(sdkRenderVersion) {
|
|
1238
|
+
return typeof sdkRenderVersion === "string" && compareVersions(sdkRenderVersion, PIT_WATER_IN) >= 0;
|
|
1239
|
+
}
|
|
1275
1240
|
function riverLinesFixed(sdkRenderVersion) {
|
|
1276
1241
|
return typeof sdkRenderVersion === "string" && compareVersions(sdkRenderVersion, RIVER_LINES_FIXED_IN) >= 0;
|
|
1277
1242
|
}
|
|
1278
|
-
function
|
|
1279
|
-
if (
|
|
1280
|
-
if (
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1243
|
+
function placeWater(raw, spec, canPlaceOnTerrain, sdkHasHeight) {
|
|
1244
|
+
if (spec.dig?.fillWater) return { data: raw, placement: "pit" };
|
|
1245
|
+
if (!hasMissingZ(raw)) return { data: raw, placement: "data" };
|
|
1246
|
+
if (spec.height === void 0 && sdkHasHeight?.(raw) === true) return { data: raw, placement: "data" };
|
|
1247
|
+
if (spec.height !== void 0) return { data: fillMissingZ(raw, spec.height), placement: "data" };
|
|
1248
|
+
if (canPlaceOnTerrain) return { data: raw, placement: "terrain" };
|
|
1249
|
+
throw new SmartEarthError(
|
|
1250
|
+
"INVALID_OPTIONS",
|
|
1251
|
+
`\u6CB3\u9053\u56FE\u5C42 ${spec.id}\uFF1A\u6C34\u7CFB\u5750\u6807\u6CA1\u6709\u9AD8\u7A0B\uFF08Z\uFF09\uFF0C\u6C34\u9762\u4F1A\u843D\u5728 0 \u7C73\u3002\u7ED9\u5750\u6807\u52A0\u4E0A Z\uFF0C\u6216\u8BBE\u7F6E height\uFF08\u6C34\u9762\u9AD8\u7A0B\uFF0C\u7C73\uFF09\uFF1Bsdk-render 4.0.3 \u8D77\u4F1A\u81EA\u52A8\u8D34\u5730\u5F62\u3002`
|
|
1252
|
+
);
|
|
1287
1253
|
}
|
|
1288
1254
|
async function digTerrain(water, geojson, depth, showViz, layerId) {
|
|
1289
1255
|
try {
|
|
@@ -1296,6 +1262,38 @@ async function digTerrain(water, geojson, depth, showViz, layerId) {
|
|
|
1296
1262
|
throw new SmartEarthError("LAYER_LOAD_FAILED", `\u6CB3\u9053\u56FE\u5C42 ${layerId} \u5730\u5F62\u6316\u5751\u5931\u8D25\uFF1A${describeLayerCause(error)}`);
|
|
1297
1263
|
}
|
|
1298
1264
|
}
|
|
1265
|
+
async function loadSurface(river, data, spec, width, placement) {
|
|
1266
|
+
if (placement === "terrain") {
|
|
1267
|
+
if (typeof river.loadFromGeoJsonOnTerrain !== "function") {
|
|
1268
|
+
throw new SmartEarthError("LAYER_LOAD_FAILED", `\u6CB3\u9053\u56FE\u5C42 ${spec.id}\uFF1A\u5F53\u524D sdk-render \u6CA1\u6709\u8D34\u5730\u653E\u6C34\u63A5\u53E3\u3002`);
|
|
1269
|
+
}
|
|
1270
|
+
return river.loadFromGeoJsonOnTerrain(data, { namePrefix: spec.id, width, ...spec.lift !== void 0 ? { lift: spec.lift } : {} });
|
|
1271
|
+
}
|
|
1272
|
+
return river.loadFromGeoJson(data, {
|
|
1273
|
+
namePrefix: spec.id,
|
|
1274
|
+
width,
|
|
1275
|
+
...spec.offsetHeight !== void 0 ? { offsetHeight: spec.offsetHeight } : {},
|
|
1276
|
+
...spec.thickness !== void 0 ? { thickness: spec.thickness } : {}
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
async function fillPits(river, terrain, spec) {
|
|
1280
|
+
const fill = spec.dig?.fillWater;
|
|
1281
|
+
const options = typeof fill === "object" ? fill : {};
|
|
1282
|
+
if (typeof river.loadWaterFromTerrainAdjust !== "function" || typeof terrain.getTerrainAdjustAreas !== "function" || typeof terrain.getOriginalTerrainProvider !== "function") {
|
|
1283
|
+
throw new SmartEarthError("LAYER_LOAD_FAILED", `\u6CB3\u9053\u56FE\u5C42 ${spec.id}\uFF1A\u5F53\u524D sdk-render \u6CA1\u6709\u6309\u5751\u52A0\u6C34\u63A5\u53E3\u3002`);
|
|
1284
|
+
}
|
|
1285
|
+
try {
|
|
1286
|
+
const layers = await river.loadWaterFromTerrainAdjust(terrain.getTerrainAdjustAreas(), {
|
|
1287
|
+
terrainProvider: terrain.getOriginalTerrainProvider(),
|
|
1288
|
+
namePrefix: spec.id,
|
|
1289
|
+
...options
|
|
1290
|
+
});
|
|
1291
|
+
if (layers.length === 0) throw new Error("\u6CA1\u6709\u751F\u6210\u6C34\u9762\uFF08\u5751\u7684\u504F\u79FB\u8981\u4E3A\u8D1F\u503C\uFF09");
|
|
1292
|
+
return layers;
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
throw new SmartEarthError("LAYER_LOAD_FAILED", `\u6CB3\u9053\u56FE\u5C42 ${spec.id} \u6309\u5751\u52A0\u6C34\u5931\u8D25\uFF1A${describeLayerCause(error)}`);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1299
1297
|
function prepareData(raw, spec, fixed) {
|
|
1300
1298
|
const width = spec.width ?? DEFAULT_RIVER_WIDTH;
|
|
1301
1299
|
const requested = spec.lineMode ?? "auto";
|
|
@@ -1308,9 +1306,14 @@ var riverWaterLayerFactory = async (context, spec) => {
|
|
|
1308
1306
|
validate4(spec);
|
|
1309
1307
|
const systems = systemsOf(context.render);
|
|
1310
1308
|
const river = requireSystem(systems, "riverWater", ["update", "loadFromGeoJson", "removeLayer", "setLayerVisible"]);
|
|
1311
|
-
const
|
|
1309
|
+
const pitSupported = pitWaterSupported(context.sdkRenderVersion);
|
|
1310
|
+
if (spec.dig?.fillWater && !pitSupported) {
|
|
1311
|
+
throw new SmartEarthError("INVALID_OPTIONS", `\u6CB3\u9053\u56FE\u5C42 ${spec.id}\uFF1A\u6309\u5751\u52A0\u6C34\uFF08dig.fillWater\uFF09\u9700\u8981 sdk-render ${PIT_WATER_IN} \u4EE5\u4E0A\u3002`);
|
|
1312
|
+
}
|
|
1313
|
+
const sdkHasHeight = pitSupported && typeof river.hasHeightInfo === "function" ? (geojson) => river.hasHeightInfo(geojson) : void 0;
|
|
1314
|
+
const placed = placeWater(await loadJson(spec.data, spec.id), spec, pitSupported, sdkHasHeight);
|
|
1312
1315
|
const fixed = riverLinesFixed(context.sdkRenderVersion);
|
|
1313
|
-
const { width, lineMode, water: waterData, dig: digData } = prepareData(
|
|
1316
|
+
const { width, lineMode, water: waterData, dig: digData } = prepareData(placed.data, spec, fixed);
|
|
1314
1317
|
if (spec.dig && digData.features.length === 0) {
|
|
1315
1318
|
const what = fixed ? "\u6570\u636E\u91CC\u6CA1\u6709\u6CB3\u9053\u7EBF\u6216\u9762\u8981\u7D20" : "\u5F53\u524D sdk-render \u53EA\u6316\u6E56\u3001\u5E93\u7B49\u9762\u8981\u7D20\uFF0C\u6570\u636E\u91CC\u6CA1\u6709 Polygon";
|
|
1316
1319
|
throw new SmartEarthError("INVALID_OPTIONS", `\u6CB3\u9053\u56FE\u5C42 ${spec.id}\uFF1Adig ${what}\u3002`);
|
|
@@ -1342,16 +1345,17 @@ var riverWaterLayerFactory = async (context, spec) => {
|
|
|
1342
1345
|
};
|
|
1343
1346
|
try {
|
|
1344
1347
|
if (spec.config) river.update(spec.config);
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
...spec.thickness !== void 0 ? { thickness: spec.thickness } : {}
|
|
1350
|
-
});
|
|
1351
|
-
layerIds = layers.map((layer) => layer.id);
|
|
1348
|
+
if (placed.placement !== "pit") {
|
|
1349
|
+
const layers = await loadSurface(river, waterData, spec, width, placed.placement);
|
|
1350
|
+
layerIds = layers.map((layer) => layer.id);
|
|
1351
|
+
}
|
|
1352
1352
|
if (spec.dig) {
|
|
1353
1353
|
terrain = requireSystem(systems, "water", ["loadTerrainAdjustFromGeoJSON", "applyTerrainAdjust", "clearAllTerrainAdjust"]);
|
|
1354
1354
|
await digTerrain(terrain, digData, spec.dig.depth, spec.showDigViz ?? false, spec.id);
|
|
1355
|
+
if (placed.placement === "pit") {
|
|
1356
|
+
const pit = await fillPits(river, terrain, spec);
|
|
1357
|
+
layerIds = pit.map((layer) => layer.id);
|
|
1358
|
+
}
|
|
1355
1359
|
}
|
|
1356
1360
|
} catch (error) {
|
|
1357
1361
|
release();
|
|
@@ -1363,6 +1367,7 @@ var riverWaterLayerFactory = async (context, spec) => {
|
|
|
1363
1367
|
return [...layerIds];
|
|
1364
1368
|
},
|
|
1365
1369
|
lineMode,
|
|
1370
|
+
placement: placed.placement,
|
|
1366
1371
|
update(config) {
|
|
1367
1372
|
if (!isRecord(config)) throw new SmartEarthError("INVALID_OPTIONS", "update \u9700\u8981\u914D\u7F6E\u5BF9\u8C61\u3002");
|
|
1368
1373
|
river.update(config);
|
|
@@ -1378,6 +1383,104 @@ var riverWaterLayerFactory = async (context, spec) => {
|
|
|
1378
1383
|
};
|
|
1379
1384
|
};
|
|
1380
1385
|
|
|
1386
|
+
// src/environment/panel.ts
|
|
1387
|
+
var PANEL_EDIT_DEBOUNCE_MS = 300;
|
|
1388
|
+
function panelElementOf(control) {
|
|
1389
|
+
const own = control.panelContainer;
|
|
1390
|
+
return own instanceof HTMLElement ? own : null;
|
|
1391
|
+
}
|
|
1392
|
+
function isShown(control, fallback) {
|
|
1393
|
+
const element = control ? panelElementOf(control) : null;
|
|
1394
|
+
if (!element || typeof getComputedStyle !== "function") return fallback;
|
|
1395
|
+
return element.isConnected && getComputedStyle(element).display !== "none";
|
|
1396
|
+
}
|
|
1397
|
+
function createPanelController(render, EnvironmentControl2, onEdit) {
|
|
1398
|
+
let control;
|
|
1399
|
+
let editTimer;
|
|
1400
|
+
const handleEdit = () => {
|
|
1401
|
+
if (!onEdit) return;
|
|
1402
|
+
clearTimeout(editTimer);
|
|
1403
|
+
editTimer = setTimeout(() => {
|
|
1404
|
+
editTimer = void 0;
|
|
1405
|
+
if (!destroyed) onEdit();
|
|
1406
|
+
}, PANEL_EDIT_DEBOUNCE_MS);
|
|
1407
|
+
};
|
|
1408
|
+
let pending;
|
|
1409
|
+
let requested = false;
|
|
1410
|
+
let destroyed = false;
|
|
1411
|
+
const ensure = async () => {
|
|
1412
|
+
if (control) return control;
|
|
1413
|
+
if (!EnvironmentControl2) {
|
|
1414
|
+
throw new SmartEarthError("ENVIRONMENT_UNSUPPORTED", "\u5F53\u524D @metagl/sdk-render \u6CA1\u6709\u73AF\u5883\u63A7\u5236\u9762\u677F\uFF08\u9700\u8981 4.x\uFF09\u3002");
|
|
1415
|
+
}
|
|
1416
|
+
pending ??= EnvironmentControl2.create({ render });
|
|
1417
|
+
let created;
|
|
1418
|
+
try {
|
|
1419
|
+
created = await pending;
|
|
1420
|
+
} catch (error) {
|
|
1421
|
+
pending = void 0;
|
|
1422
|
+
if (destroyed) throw new SmartEarthError("DESTROYED", "\u5730\u7403\u5DF2\u9500\u6BC1\u3002");
|
|
1423
|
+
throw new SmartEarthError("RENDER_INIT_FAILED", `\u73AF\u5883\u63A7\u5236\u9762\u677F\u521B\u5EFA\u5931\u8D25\uFF1A${describeCause(error)}`, error);
|
|
1424
|
+
}
|
|
1425
|
+
if (destroyed) {
|
|
1426
|
+
panelElementOf(created)?.remove();
|
|
1427
|
+
throw new SmartEarthError("DESTROYED", "\u5730\u7403\u5DF2\u9500\u6BC1\u3002");
|
|
1428
|
+
}
|
|
1429
|
+
control = created;
|
|
1430
|
+
const element = panelElementOf(created);
|
|
1431
|
+
element?.addEventListener("input", handleEdit);
|
|
1432
|
+
element?.addEventListener("change", handleEdit);
|
|
1433
|
+
return created;
|
|
1434
|
+
};
|
|
1435
|
+
return {
|
|
1436
|
+
async show(next) {
|
|
1437
|
+
requested = next;
|
|
1438
|
+
if (!next && !control && !pending) return;
|
|
1439
|
+
const panel = await ensure();
|
|
1440
|
+
panel.togglePanel(requested);
|
|
1441
|
+
},
|
|
1442
|
+
get visible() {
|
|
1443
|
+
return isShown(control, requested);
|
|
1444
|
+
},
|
|
1445
|
+
destroy() {
|
|
1446
|
+
destroyed = true;
|
|
1447
|
+
clearTimeout(editTimer);
|
|
1448
|
+
if (control) panelElementOf(control)?.remove();
|
|
1449
|
+
control = void 0;
|
|
1450
|
+
requested = false;
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
// src/core/capture.ts
|
|
1456
|
+
var DEFAULT_MAX_WIDTH = 480;
|
|
1457
|
+
var JPEG_QUALITY = 0.85;
|
|
1458
|
+
function captureImage(viewer, maxWidth = DEFAULT_MAX_WIDTH) {
|
|
1459
|
+
if (!Number.isFinite(maxWidth) || maxWidth <= 0) {
|
|
1460
|
+
return Promise.reject(new SmartEarthError("INVALID_OPTIONS", "maxWidth \u8981\u662F\u6B63\u6570\uFF08\u50CF\u7D20\uFF09\u3002"));
|
|
1461
|
+
}
|
|
1462
|
+
return new Promise((resolve, reject) => {
|
|
1463
|
+
const scene = viewer.scene;
|
|
1464
|
+
const remove = scene.postRender.addEventListener(() => {
|
|
1465
|
+
remove();
|
|
1466
|
+
try {
|
|
1467
|
+
const source = scene.canvas;
|
|
1468
|
+
const scale = Math.min(1, maxWidth / Math.max(1, source.width));
|
|
1469
|
+
const target = document.createElement("canvas");
|
|
1470
|
+
target.width = Math.max(1, Math.round(source.width * scale));
|
|
1471
|
+
target.height = Math.max(1, Math.round(source.height * scale));
|
|
1472
|
+
target.getContext("2d")?.drawImage(source, 0, 0, target.width, target.height);
|
|
1473
|
+
const dataUrl = target.toDataURL("image/jpeg", JPEG_QUALITY);
|
|
1474
|
+
if (!dataUrl.startsWith("data:image/jpeg")) throw new Error("\u753B\u5E03\u8F93\u51FA\u65E0\u6548");
|
|
1475
|
+
resolve(dataUrl);
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
reject(new SmartEarthError("RENDER_INIT_FAILED", `\u622A\u56FE\u5931\u8D25\uFF1A${describeCause(error)}`, error));
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
scene.requestRender();
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1381
1484
|
// src/core/assets.ts
|
|
1382
1485
|
var CESIUM_PROBE = "Assets/approximateTerrainHeights.json";
|
|
1383
1486
|
var SDK_RENDER_PROBE = "resources/readme.txt";
|
|
@@ -1522,6 +1625,31 @@ function resolveInitialView(view) {
|
|
|
1522
1625
|
pitch: typeof view.pitch === "number" ? view.pitch : DEFAULT_INITIAL_VIEW.pitch
|
|
1523
1626
|
};
|
|
1524
1627
|
}
|
|
1628
|
+
var BASELINES = ["environment", "cinematic"];
|
|
1629
|
+
function resolveEffects(effects) {
|
|
1630
|
+
if (effects === void 0) return {};
|
|
1631
|
+
const ok = isRecord3(effects) && !Array.isArray(effects) && Object.values(effects).every((v) => typeof v === "boolean");
|
|
1632
|
+
if (!ok) throw new SmartEarthError("INVALID_OPTIONS", "effects \u8981\u5199\u6210 { \u6548\u679C\u540D: true/false }\u3002");
|
|
1633
|
+
const unknown = Object.keys(effects).filter((name) => !ALL_EFFECTS.includes(name));
|
|
1634
|
+
if (unknown.length > 0) {
|
|
1635
|
+
throw new SmartEarthError("INVALID_OPTIONS", `effects \u91CC\u6CA1\u6709\u8FD9\u4E9B\u6548\u679C\uFF1A${unknown.join("\u3001")}\uFF1B\u53EF\u9009 ${ALL_EFFECTS.join("\u3001")}\u3002`);
|
|
1636
|
+
}
|
|
1637
|
+
return { ...effects };
|
|
1638
|
+
}
|
|
1639
|
+
function resolveEnvironmentOptions(options, assetsBasePath) {
|
|
1640
|
+
const baseline = options.baseline ?? "environment";
|
|
1641
|
+
if (!BASELINES.includes(baseline)) {
|
|
1642
|
+
throw new SmartEarthError("INVALID_OPTIONS", `baseline \u53EA\u80FD\u662F ${BASELINES.join(" / ")}\u3002`);
|
|
1643
|
+
}
|
|
1644
|
+
const showPanel = options.showPanel ?? false;
|
|
1645
|
+
if (typeof showPanel !== "boolean") throw new SmartEarthError("INVALID_OPTIONS", "showPanel \u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002");
|
|
1646
|
+
const preset = options.presetFile;
|
|
1647
|
+
if (preset !== void 0 && preset !== false && (typeof preset !== "string" || preset.trim() === "")) {
|
|
1648
|
+
throw new SmartEarthError("INVALID_OPTIONS", "presetFile \u8981\u662F false \u6216\u9884\u8BBE\u6587\u4EF6\u5730\u5740\u3002");
|
|
1649
|
+
}
|
|
1650
|
+
const presetFile = preset === false ? null : preset ?? `${assetsBasePath}environment/preset.json`;
|
|
1651
|
+
return { baseline, effects: resolveEffects(options.effects), showPanel, presetFile };
|
|
1652
|
+
}
|
|
1525
1653
|
function normalizeAssetsBasePath(path) {
|
|
1526
1654
|
return path.endsWith("/") ? path : `${path}/`;
|
|
1527
1655
|
}
|
|
@@ -1558,7 +1686,8 @@ function resolveOptions(options) {
|
|
|
1558
1686
|
quality,
|
|
1559
1687
|
assetsBasePath: normalizeAssetsBasePath(assetsBasePath),
|
|
1560
1688
|
initialView: resolveInitialView(options.initialView),
|
|
1561
|
-
checkAssets: options.checkAssets ?? true
|
|
1689
|
+
checkAssets: options.checkAssets ?? true,
|
|
1690
|
+
...resolveEnvironmentOptions(options, normalizeAssetsBasePath(assetsBasePath))
|
|
1562
1691
|
};
|
|
1563
1692
|
}
|
|
1564
1693
|
|
|
@@ -1583,14 +1712,88 @@ function getSupportedQualities() {
|
|
|
1583
1712
|
const prototype = SdkRender.Render?.prototype;
|
|
1584
1713
|
return qualitiesFor(prototype, SdkRender.DEMO_ENVIRONMENT_BASELINE);
|
|
1585
1714
|
}
|
|
1586
|
-
function
|
|
1715
|
+
async function resetToBaseline(render, quality) {
|
|
1716
|
+
const capable = render;
|
|
1717
|
+
if (typeof capable.loadConfig !== "function" || SdkRender.DEMO_ENVIRONMENT_BASELINE === void 0) {
|
|
1718
|
+
throw new SmartEarthError("ENVIRONMENT_UNSUPPORTED", "\u5F53\u524D @metagl/sdk-render \u4E0D\u652F\u6301\u91CD\u7F6E\u73AF\u5883\u914D\u7F6E\uFF08\u9700\u8981 4.x\uFF09\u3002");
|
|
1719
|
+
}
|
|
1587
1720
|
try {
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1721
|
+
const baseline = buildHighConfig(SdkRender.DEMO_ENVIRONMENT_BASELINE);
|
|
1722
|
+
await capable.loadConfig(baseline);
|
|
1723
|
+
syncEnabledFlags(render, baseline);
|
|
1724
|
+
if (typeof capable.setQuality === "function") {
|
|
1725
|
+
await capable.setQuality("high");
|
|
1726
|
+
if (quality !== "high") await capable.setQuality(quality);
|
|
1727
|
+
} else if (quality !== "high") {
|
|
1728
|
+
await applyQuality(capable, quality, SdkRender.DEMO_ENVIRONMENT_BASELINE);
|
|
1729
|
+
}
|
|
1730
|
+
} catch (error) {
|
|
1731
|
+
try {
|
|
1732
|
+
if (typeof capable.setQuality === "function") await capable.setQuality(quality);
|
|
1733
|
+
} catch {
|
|
1734
|
+
}
|
|
1735
|
+
throw new SmartEarthError("RENDER_INIT_FAILED", `\u91CD\u7F6E\u73AF\u5883\u914D\u7F6E\u5931\u8D25\uFF1A${describeCause(error)}`, error);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
async function withBaseQuality(render, quality, read) {
|
|
1739
|
+
if (quality === "high") return read();
|
|
1740
|
+
const capable = render;
|
|
1741
|
+
const toQuality = async (target) => {
|
|
1742
|
+
if (typeof capable.setQuality === "function") await capable.setQuality(target);
|
|
1743
|
+
else await applyQuality(capable, target, SdkRender.DEMO_ENVIRONMENT_BASELINE);
|
|
1744
|
+
};
|
|
1745
|
+
await toQuality("high");
|
|
1746
|
+
try {
|
|
1747
|
+
return await read();
|
|
1748
|
+
} finally {
|
|
1749
|
+
await toQuality(quality);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
function readLightingLink() {
|
|
1753
|
+
try {
|
|
1754
|
+
const derived = SdkRender.DEMO_ENVIRONMENT_BASELINE_DERIVED;
|
|
1755
|
+
return typeof derived?.ssgiIntensityFromLighting === "function" && typeof derived.ssrtShaftIntensityFromLighting === "function" ? derived : void 0;
|
|
1590
1756
|
} catch {
|
|
1591
1757
|
return void 0;
|
|
1592
1758
|
}
|
|
1593
1759
|
}
|
|
1760
|
+
function readEnvironmentControl() {
|
|
1761
|
+
try {
|
|
1762
|
+
const candidate = SdkRender.EnvironmentControl;
|
|
1763
|
+
return typeof candidate?.create === "function" ? candidate : void 0;
|
|
1764
|
+
} catch {
|
|
1765
|
+
return void 0;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
async function applyStartupEnvironment(earth, options) {
|
|
1769
|
+
for (const [effect, enabled] of Object.entries(options.effects)) {
|
|
1770
|
+
earth.environment.setEffect(effect, enabled === true);
|
|
1771
|
+
}
|
|
1772
|
+
if (options.presetFile) await loadProjectPreset(earth, options.presetFile);
|
|
1773
|
+
if (options.showPanel) await earth.showPanel(true);
|
|
1774
|
+
}
|
|
1775
|
+
var HTTP_NOT_FOUND = 404;
|
|
1776
|
+
async function loadProjectPreset(earth, url) {
|
|
1777
|
+
let response;
|
|
1778
|
+
try {
|
|
1779
|
+
response = await fetch(url, { cache: "no-cache" });
|
|
1780
|
+
} catch (error) {
|
|
1781
|
+
throw new SmartEarthError("ASSETS_MISSING", `\u8BFB\u53D6\u5DE5\u7A0B\u73AF\u5883\u9884\u8BBE ${url} \u5931\u8D25\uFF1A${describeCause(error)}`, error);
|
|
1782
|
+
}
|
|
1783
|
+
if (response.status === HTTP_NOT_FOUND) return;
|
|
1784
|
+
if (!response.ok) {
|
|
1785
|
+
throw new SmartEarthError("ASSETS_MISSING", `\u8BFB\u53D6\u5DE5\u7A0B\u73AF\u5883\u9884\u8BBE ${url} \u5931\u8D25\uFF1AHTTP ${response.status}`);
|
|
1786
|
+
}
|
|
1787
|
+
if (!(response.headers.get("content-type") ?? "").includes("json")) return;
|
|
1788
|
+
let body;
|
|
1789
|
+
try {
|
|
1790
|
+
body = await response.json();
|
|
1791
|
+
} catch (error) {
|
|
1792
|
+
throw new SmartEarthError("INVALID_OPTIONS", `\u5DE5\u7A0B\u73AF\u5883\u9884\u8BBE ${url} \u4E0D\u662F\u5408\u6CD5\u7684 JSON\u3002`, error);
|
|
1793
|
+
}
|
|
1794
|
+
const snapshot = requirePresetDocument(body, `\u5DE5\u7A0B\u73AF\u5883\u9884\u8BBE ${url}`);
|
|
1795
|
+
await earth.environment.restoreSnapshot(snapshot, { time: true, camera: false });
|
|
1796
|
+
}
|
|
1594
1797
|
function toRadians2(Cesium, degrees) {
|
|
1595
1798
|
return Cesium.Math.toRadians(degrees);
|
|
1596
1799
|
}
|
|
@@ -1645,7 +1848,7 @@ async function createRender(viewer, options) {
|
|
|
1645
1848
|
try {
|
|
1646
1849
|
return await SdkRender.Render.createWithDefaults({
|
|
1647
1850
|
viewer,
|
|
1648
|
-
baseline:
|
|
1851
|
+
baseline: options.baseline,
|
|
1649
1852
|
assetsBasePath: options.assetsBasePath,
|
|
1650
1853
|
...options.auth,
|
|
1651
1854
|
...nativeQualityOption(options.quality)
|
|
@@ -1713,7 +1916,14 @@ async function createEarth(container, rawOptions) {
|
|
|
1713
1916
|
if (options.quality !== "high" && !qualityApplied) {
|
|
1714
1917
|
await applyQuality(render, options.quality, SdkRender.DEMO_ENVIRONMENT_BASELINE);
|
|
1715
1918
|
}
|
|
1716
|
-
|
|
1919
|
+
const earth = assembleEarth(Cesium, viewer, render, options.quality);
|
|
1920
|
+
try {
|
|
1921
|
+
await applyStartupEnvironment(earth, options);
|
|
1922
|
+
} catch (error) {
|
|
1923
|
+
earth.destroy();
|
|
1924
|
+
throw error;
|
|
1925
|
+
}
|
|
1926
|
+
return earth;
|
|
1717
1927
|
} catch (error) {
|
|
1718
1928
|
const created = { viewer, render };
|
|
1719
1929
|
safely(() => created.render?.destroy());
|
|
@@ -1770,6 +1980,8 @@ function assembleEarth(Cesium, viewer, render, initialQuality) {
|
|
|
1770
1980
|
};
|
|
1771
1981
|
const emitter = new Emitter(reportListenerError);
|
|
1772
1982
|
const pbr = createEarthPbr(render);
|
|
1983
|
+
let notifyEnvironment;
|
|
1984
|
+
const panel = createPanelController(render, readEnvironmentControl(), () => notifyEnvironment?.("panel"));
|
|
1773
1985
|
const pipeline = createClickPipeline(Cesium, viewer, emitter, reportListenerError);
|
|
1774
1986
|
const clickHandler = pipeline.handler;
|
|
1775
1987
|
const registry = createLayerRegistry(
|
|
@@ -1793,6 +2005,17 @@ function assembleEarth(Cesium, viewer, render, initialQuality) {
|
|
|
1793
2005
|
const assertAlive = () => {
|
|
1794
2006
|
if (destroyed) throw new SmartEarthError("DESTROYED", "\u5730\u7403\u5DF2\u9500\u6BC1\u3002");
|
|
1795
2007
|
};
|
|
2008
|
+
const environment = createEarthEnvironment({
|
|
2009
|
+
viewer,
|
|
2010
|
+
Cesium,
|
|
2011
|
+
render,
|
|
2012
|
+
assertAlive,
|
|
2013
|
+
resetToBaseline: () => resetToBaseline(render, quality),
|
|
2014
|
+
lightingLink: readLightingLink(),
|
|
2015
|
+
getQuality: () => quality,
|
|
2016
|
+
withBaseQuality: (read) => withBaseQuality(render, quality, read)
|
|
2017
|
+
});
|
|
2018
|
+
notifyEnvironment = (source) => environment.notify(source);
|
|
1796
2019
|
return {
|
|
1797
2020
|
viewer,
|
|
1798
2021
|
render,
|
|
@@ -1805,8 +2028,24 @@ function assembleEarth(Cesium, viewer, render, initialQuality) {
|
|
|
1805
2028
|
),
|
|
1806
2029
|
async setQuality(next) {
|
|
1807
2030
|
assertAlive();
|
|
1808
|
-
|
|
1809
|
-
|
|
2031
|
+
const time = environment.getPreset() ? environment.getTime() : void 0;
|
|
2032
|
+
const preset = environment.suspendPreset();
|
|
2033
|
+
let reenterError;
|
|
2034
|
+
try {
|
|
2035
|
+
await applyQuality(render, next, SdkRender.DEMO_ENVIRONMENT_BASELINE);
|
|
2036
|
+
quality = next;
|
|
2037
|
+
} finally {
|
|
2038
|
+
if (preset) {
|
|
2039
|
+
try {
|
|
2040
|
+
environment.setPreset(preset, { deferAboveMeters: false });
|
|
2041
|
+
if (time) environment.setTime(time);
|
|
2042
|
+
} catch (error) {
|
|
2043
|
+
reenterError = error;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
if (reenterError !== void 0) throw reenterError;
|
|
2048
|
+
environment.notify("quality");
|
|
1810
2049
|
},
|
|
1811
2050
|
layers: {
|
|
1812
2051
|
register: (kind, factory) => registry.register(kind, factory),
|
|
@@ -1820,6 +2059,19 @@ function assembleEarth(Cesium, viewer, render, initialQuality) {
|
|
|
1820
2059
|
get: (id) => registry.get(id)
|
|
1821
2060
|
},
|
|
1822
2061
|
pbr,
|
|
2062
|
+
environment,
|
|
2063
|
+
captureImage(maxWidth) {
|
|
2064
|
+
assertAlive();
|
|
2065
|
+
return captureImage(viewer, maxWidth);
|
|
2066
|
+
},
|
|
2067
|
+
async showPanel(visible = true) {
|
|
2068
|
+
assertAlive();
|
|
2069
|
+
if (typeof visible !== "boolean") throw new SmartEarthError("INVALID_OPTIONS", "showPanel \u7684\u53C2\u6570\u5FC5\u987B\u662F true / false\u3002");
|
|
2070
|
+
await panel.show(visible);
|
|
2071
|
+
},
|
|
2072
|
+
get isPanelVisible() {
|
|
2073
|
+
return panel.visible;
|
|
2074
|
+
},
|
|
1823
2075
|
async flyTo(target) {
|
|
1824
2076
|
assertAlive();
|
|
1825
2077
|
if (typeof target === "string") {
|
|
@@ -1849,6 +2101,8 @@ function assembleEarth(Cesium, viewer, render, initialQuality) {
|
|
|
1849
2101
|
emitter.clear();
|
|
1850
2102
|
safely(() => clickHandler.destroy());
|
|
1851
2103
|
safely(() => registry.destroyAll());
|
|
2104
|
+
safely(() => panel.destroy());
|
|
2105
|
+
safely(() => environment.destroy());
|
|
1852
2106
|
pipeline.clicks.clear();
|
|
1853
2107
|
pipeline.resolvers.clear();
|
|
1854
2108
|
safely(() => render.destroy());
|
|
@@ -1859,4 +2113,4 @@ function assembleEarth(Cesium, viewer, render, initialQuality) {
|
|
|
1859
2113
|
};
|
|
1860
2114
|
}
|
|
1861
2115
|
|
|
1862
|
-
export { CESIUM_MAX_VERSION_EXCLUSIVE, CESIUM_MIN_VERSION, LOW_QUALITY_OVERRIDES,
|
|
2116
|
+
export { CESIUM_MAX_VERSION_EXCLUSIVE, CESIUM_MIN_VERSION, LOW_QUALITY_OVERRIDES, createEarth, createEarthPbr, escapeHtml, getSupportedQualities, makeExtensible, supportsPbr };
|