@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/dist/vue.js CHANGED
@@ -1,6 +1,243 @@
1
- import { createEarth, SmartEarthError, describeCause } from './chunk-O7CP7PJG.js';
2
- import { defineComponent, ref, shallowRef, onMounted, onBeforeUnmount, h } from 'vue';
1
+ import { createEarth } from './chunk-JGNKH4TR.js';
2
+ import { createPresetLibrary } from './chunk-6U32ENXU.js';
3
+ import { SmartEarthError, describeCause } from './chunk-XJRW7VZC.js';
4
+ import { defineComponent, h, ref, shallowRef, onMounted, onBeforeUnmount, computed } from 'vue';
3
5
 
6
+ // src/vue/presetLibraryStyle.ts
7
+ var STYLE_ID = "smartearth-preset-library-style";
8
+ var CSS = `
9
+ .se-pl{display:flex;flex-direction:column;gap:8px;width:100%;max-height:100%;overflow-y:auto;box-sizing:border-box;padding:10px 14px;border-radius:8px;background:var(--se-pl-bg,#0b1020);color:var(--se-pl-fg,#e5e7eb);font:13px/1.5 system-ui,'Microsoft YaHei',sans-serif}
10
+ .se-pl h2,.se-pl h3{margin:0;font-size:13px;font-weight:600}
11
+ .se-pl-head{display:flex;justify-content:space-between;align-items:center}
12
+ .se-pl-row,.se-pl-chips{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
13
+ .se-pl-cities{display:flex;flex-wrap:wrap;gap:4px;max-height:120px;overflow-y:auto}
14
+ .se-pl-cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
15
+ .se-pl-card{display:flex;flex-direction:column;gap:4px;padding:6px;border:1px solid #334155;border-radius:6px;background:var(--se-pl-card-bg,#0f172a)}
16
+ .se-pl-card[data-active="true"]{border-color:var(--se-pl-accent,#2563eb)}
17
+ .se-pl .se-pl-thumb{height:80px;padding:4px;border:0;border-radius:4px;background:linear-gradient(135deg,#1e3a8a,#0f766e) center/cover;text-align:left;cursor:pointer}
18
+ .se-pl-thumb span{font-size:11px;padding:1px 4px;border-radius:3px;background:rgb(0 0 0 / 50%);color:#fff}
19
+ .se-pl small,.se-pl-hint{color:#94a3b8}
20
+ .se-pl-banner{display:flex;flex-wrap:wrap;gap:6px;align-items:center;padding:6px;border-radius:6px;background:rgb(37 99 235 / 25%)}
21
+ .se-pl-save{display:flex;flex-direction:column;gap:4px;padding-top:8px;border-top:1px solid #334155}
22
+ .se-pl input{flex:1;min-width:0;padding:3px 6px;border:1px solid #475569;border-radius:6px;background:transparent;color:inherit;font:inherit}
23
+ .se-pl button{padding:3px 8px;border:1px solid #475569;border-radius:6px;background:transparent;color:inherit;font:inherit;cursor:pointer}
24
+ .se-pl button[aria-pressed="true"]{background:var(--se-pl-accent,#2563eb);border-color:var(--se-pl-accent,#2563eb)}
25
+ .se-pl button:disabled{opacity:.4;cursor:not-allowed}
26
+ .se-pl-message{margin:0;color:#fcd34d}
27
+ `;
28
+ function injectPresetLibraryStyle() {
29
+ if (typeof document === "undefined" || document.getElementById(STYLE_ID)) return;
30
+ const style = document.createElement("style");
31
+ style.id = STYLE_ID;
32
+ style.textContent = CSS;
33
+ document.head.appendChild(style);
34
+ }
35
+
36
+ // src/vue/PresetLibrary.ts
37
+ function download(filename, content, type) {
38
+ const isDataUrl = content.startsWith("data:");
39
+ const link = document.createElement("a");
40
+ link.href = isDataUrl ? content : URL.createObjectURL(new Blob([content], { type }));
41
+ link.download = filename;
42
+ link.click();
43
+ if (!isDataUrl) setTimeout(() => URL.revokeObjectURL(link.href), 1e3);
44
+ }
45
+ function useLibraryState(library, initialAdcode) {
46
+ const state = {
47
+ cities: ref([]),
48
+ region: ref("all"),
49
+ query: ref(""),
50
+ hits: ref(null),
51
+ city: ref(null),
52
+ cards: ref([]),
53
+ loading: ref(false),
54
+ previewing: ref(null),
55
+ note: ref(null),
56
+ message: ref(""),
57
+ name: ref(""),
58
+ desc: ref("")
59
+ };
60
+ const guard = async (action) => {
61
+ try {
62
+ await action();
63
+ state.message.value = "";
64
+ return true;
65
+ } catch (error) {
66
+ state.message.value = error.message;
67
+ return false;
68
+ }
69
+ };
70
+ const refreshCards = async () => {
71
+ if (state.city.value) state.cards.value = await library.list(state.city.value.adcode);
72
+ };
73
+ const selectCity = async (next) => {
74
+ state.city.value = next;
75
+ state.loading.value = true;
76
+ await guard(refreshCards);
77
+ state.loading.value = false;
78
+ };
79
+ onMounted(
80
+ () => guard(async () => {
81
+ state.cities.value = await library.listCities();
82
+ const initial = state.cities.value.find((item) => item.adcode === initialAdcode);
83
+ if (initial) await selectCity(initial);
84
+ })
85
+ );
86
+ const visibleCities = computed(
87
+ () => state.cities.value.filter(
88
+ (item) => (state.region.value === "all" || item.regionId === state.region.value) && (state.hits.value === null || state.hits.value.has(item.adcode))
89
+ )
90
+ );
91
+ return { library, state, guard, refreshCards, selectCity, visibleCities };
92
+ }
93
+ var SmartEarthPresetLibrary = defineComponent({
94
+ name: "SmartEarthPresetLibrary",
95
+ props: {
96
+ earth: { type: Object, required: true },
97
+ /** 现成的预设库;不传就按 store 建一个。只在挂载时读一次。 */
98
+ library: { type: Object, default: void 0 },
99
+ /** 存预设的地方,上层建好传进来(如 httpPresetStore({ baseUrl, getToken, clusterId }));不传就只能浏览、不能存。只在挂载时读一次。 */
100
+ store: { type: Object, default: void 0 },
101
+ /** 打开时默认选中的城市(6 位 adcode)。 */
102
+ adcode: { type: String, default: void 0 },
103
+ /** 显示右上角关闭按钮(点了发 close 事件)。 */
104
+ closable: { type: Boolean, default: true }
105
+ },
106
+ emits: {
107
+ applied: (entry) => Boolean(entry),
108
+ saved: (entry) => Boolean(entry),
109
+ close: () => true
110
+ },
111
+ setup(props, { emit }) {
112
+ injectPresetLibraryStyle();
113
+ const library = props.library ?? createPresetLibrary(props.earth, props.store ? { store: props.store } : {});
114
+ const sourceLabel = (card2) => library.sources.find((item) => item.id === card2.source)?.label ?? card2.source;
115
+ const { state, guard, refreshCards, selectCity, visibleCities } = useLibraryState(library, props.adcode);
116
+ const search = () => guard(async () => {
117
+ const text = state.query.value.trim();
118
+ state.hits.value = text ? new Set((await library.searchCities(text)).map((item) => item.adcode)) : null;
119
+ });
120
+ const preview = (entry) => guard(async () => {
121
+ await library.preview(entry);
122
+ state.previewing.value = entry;
123
+ state.note.value = library.compatibility(entry);
124
+ });
125
+ const confirm = () => {
126
+ const entry = state.previewing.value;
127
+ library.confirmPreview();
128
+ state.previewing.value = null;
129
+ state.note.value = null;
130
+ if (entry) emit("applied", entry);
131
+ };
132
+ const cancel = () => guard(async () => {
133
+ await library.cancelPreview();
134
+ state.previewing.value = null;
135
+ state.note.value = null;
136
+ });
137
+ const downloadCard = (entry) => guard(async () => {
138
+ const document2 = await library.getDocument(entry);
139
+ download(`${entry.name}.json`, JSON.stringify(document2, null, 2), "application/json");
140
+ });
141
+ const removeEntry = (entry) => guard(async () => {
142
+ await library.remove(entry);
143
+ await refreshCards();
144
+ });
145
+ const save = () => guard(async () => {
146
+ if (!state.city.value) throw new Error("\u5148\u9009\u4E00\u4E2A\u57CE\u5E02\uFF0C\u9884\u8BBE\u6309\u57CE\u5E02\u4FDD\u5B58");
147
+ const entry = await library.save({
148
+ name: state.name.value,
149
+ desc: state.desc.value,
150
+ ...state.city.value ? { adcode: state.city.value.adcode } : {}
151
+ });
152
+ state.name.value = "";
153
+ state.desc.value = "";
154
+ await refreshCards();
155
+ emit("saved", entry);
156
+ });
157
+ const makeCityPackage = async () => {
158
+ let uploadDir = "";
159
+ await guard(async () => {
160
+ if (!state.city.value) throw new Error("\u5148\u9009\u4E00\u4E2A\u57CE\u5E02");
161
+ const pack = await library.bucketUploadPackage(state.city.value.adcode, { name: state.name.value, desc: state.desc.value });
162
+ download(pack.filename, JSON.stringify(pack.config, null, 2), "application/json");
163
+ if (pack.thumb) download(pack.thumb.filename, pack.thumb.dataUrl, "image/jpeg");
164
+ download("index.json", JSON.stringify(pack.index, null, 2), "application/json");
165
+ uploadDir = pack.uploadDir;
166
+ });
167
+ if (uploadDir) state.message.value = `\u5DF2\u4E0B\u8F7D\u914D\u7F6E\u3001\u622A\u56FE\u4E0E index.json\uFF0C\u4EA4\u7ED9\u6709 CDN \u5199\u6743\u9650\u7684\u4EBA\u4E0A\u4F20\u5230 ${uploadDir}`;
168
+ };
169
+ const button = (label, onClick, extra = {}) => h("button", { type: "button", onClick, ...extra }, label);
170
+ const input = (model, placeholder, onEnter) => h("input", {
171
+ value: model.value,
172
+ placeholder,
173
+ onInput: (event) => model.value = event.target.value,
174
+ ...onEnter ? { onKeydown: (event) => event.key === "Enter" && onEnter() } : {}
175
+ });
176
+ const card = (entry) => h("article", { class: "se-pl-card", "data-active": String(state.previewing.value?.id === entry.id), key: entry.id }, [
177
+ h(
178
+ "button",
179
+ {
180
+ type: "button",
181
+ class: "se-pl-thumb",
182
+ style: entry.thumb ? { backgroundImage: `url(${entry.thumb})` } : {},
183
+ title: "\u9884\u89C8",
184
+ onClick: () => preview(entry)
185
+ },
186
+ [h("span", sourceLabel(entry))]
187
+ ),
188
+ h("strong", entry.name),
189
+ entry.desc ? h("small", entry.desc) : null,
190
+ h("div", { class: "se-pl-chips" }, [
191
+ button("\u4E0B\u8F7D", () => downloadCard(entry)),
192
+ entry.writable ? button("\u5220\u9664", () => removeEntry(entry)) : null
193
+ ])
194
+ ]);
195
+ return () => {
196
+ const city = state.city.value;
197
+ return h("section", { class: "se-pl", "aria-label": "\u9884\u8BBE\u5E93" }, [
198
+ h("div", { class: "se-pl-head" }, [
199
+ h("h2", "\u9884\u8BBE\u5E93"),
200
+ props.closable ? button("\xD7", () => emit("close"), { "aria-label": "\u5173\u95ED" }) : null
201
+ ]),
202
+ h("div", { class: "se-pl-row" }, [input(state.query, "\u641C\u57CE\u5E02 / \u7701\u4EFD / \u5927\u533A / \u9884\u8BBE\u540D", search), button("\u641C\u7D22", search)]),
203
+ h("div", { class: "se-pl-chips" }, [
204
+ button("\u5168\u90E8", () => state.region.value = "all", { "aria-pressed": state.region.value === "all" }),
205
+ ...library.regions.map(
206
+ (item) => button(item.name, () => state.region.value = item.id, { key: item.id, "aria-pressed": state.region.value === item.id })
207
+ )
208
+ ]),
209
+ h(
210
+ "div",
211
+ { class: "se-pl-cities" },
212
+ visibleCities.value.map(
213
+ (item) => button(item.name, () => selectCity(item), { key: item.adcode, "aria-pressed": city?.adcode === item.adcode })
214
+ )
215
+ ),
216
+ city ? h("h3", `${city.name} \xB7 ${city.adcode}`) : null,
217
+ city && state.loading.value ? h("p", { class: "se-pl-hint" }, "\u8BFB\u53D6\u4E2D\u2026") : null,
218
+ city && !state.loading.value && state.cards.value.length === 0 ? h("p", { class: "se-pl-hint" }, "\u8FD9\u4E2A\u57CE\u5E02\u8FD8\u6CA1\u6709\u9884\u8BBE\uFF0C\u53EF\u4EE5\u5728\u4E0B\u9762\u4FDD\u5B58\u4E00\u4E2A\u3002") : null,
219
+ city ? h("div", { class: "se-pl-cards" }, state.cards.value.map(card)) : null,
220
+ state.previewing.value ? h("div", { class: "se-pl-banner" }, [
221
+ `\u6B63\u5728\u9884\u89C8\u300C${state.previewing.value.name}\u300D`,
222
+ button("\u786E\u8BA4", confirm),
223
+ button("\u53D6\u6D88\uFF08\u6062\u590D\u539F\u6837\uFF09", cancel),
224
+ state.note.value ? h("small", state.note.value) : null
225
+ ]) : null,
226
+ h("div", { class: "se-pl-save" }, [
227
+ input(state.name, "\u540D\u79F0"),
228
+ input(state.desc, "\u63CF\u8FF0\uFF08\u53EF\u9009\uFF09"),
229
+ h("div", { class: "se-pl-chips" }, [
230
+ button(library.canSave ? "\u4FDD\u5B58\u4E3A\u9884\u8BBE" : "\u4FDD\u5B58\uFF08\u672A\u914D\u7F6E\u9884\u8BBE\u5B58\u50A8\uFF09", save, { disabled: !library.canSave || !city }),
231
+ library.sources.some((item) => item.id === "bucket") ? button("\u751F\u6210\u6837\u677F\u95F4\u4E0A\u4F20\u5305", makeCityPackage, { disabled: !city }) : null
232
+ ])
233
+ ]),
234
+ state.message.value ? h("p", { class: "se-pl-message" }, state.message.value) : null
235
+ ]);
236
+ };
237
+ }
238
+ });
239
+
240
+ // src/vue/index.ts
4
241
  var SmartEarthView = defineComponent({
5
242
  name: "SmartEarthView",
6
243
  props: {
@@ -51,4 +288,4 @@ var SmartEarthView = defineComponent({
51
288
  });
52
289
  var vue_default = SmartEarthView;
53
290
 
54
- export { SmartEarthView, vue_default as default };
291
+ export { SmartEarthPresetLibrary, SmartEarthView, vue_default as default };
package/package.json CHANGED
@@ -1,70 +1,75 @@
1
- {
2
- "name": "@metagl/smartearth-base",
3
- "version": "0.2.0",
4
- "description": "集群业务地图底层包:基于 @metagl/sdk-render 的三维地球(替代已废弃的 @agent-earth/smart-earth)",
5
- "license": "Apache-2.0",
6
- "type": "module",
7
- "engines": {
8
- "node": ">=20.0.0"
9
- },
10
- "sideEffects": false,
11
- "files": [
12
- "dist",
13
- "README.md",
14
- "CHANGELOG.md"
15
- ],
16
- "main": "./dist/index.js",
17
- "module": "./dist/index.js",
18
- "types": "./dist/index.d.ts",
19
- "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "import": "./dist/index.js"
23
- },
24
- "./vite": {
25
- "types": "./dist/vite.d.ts",
26
- "import": "./dist/vite.js"
27
- },
28
- "./vue": {
29
- "types": "./dist/vue.d.ts",
30
- "import": "./dist/vue.js"
31
- },
32
- "./package.json": "./package.json"
33
- },
34
- "peerDependencies": {
35
- "@metagl/sdk-render": "^3.0.0 || ^4.0.1",
36
- "cesium": ">=1.132.0 <1.137.0",
37
- "vite": ">=5.0.0",
38
- "vue": "^3.5.0"
39
- },
40
- "peerDependenciesMeta": {
41
- "vite": {
42
- "optional": true
43
- },
44
- "vue": {
45
- "optional": true
46
- }
47
- },
48
- "devDependencies": {
49
- "@metagl/sdk-render": "4.0.2",
50
- "@types/node": "^22.0.0",
51
- "cesium": "1.136.0",
52
- "jsdom": "^26.0.0",
53
- "tsup": "^8.5.0",
54
- "typescript": "^5.8.0",
55
- "vite": "^6.0.0",
56
- "vitest": "^3.2.0",
57
- "vue": "^3.5.0"
58
- },
59
- "publishConfig": {
60
- "registry": "https://registry.npmjs.org/",
61
- "access": "public"
62
- },
63
- "scripts": {
64
- "build": "tsup",
65
- "typecheck": "tsc --noEmit -p tsconfig.json",
66
- "test": "vitest run",
67
- "check": "pnpm typecheck && pnpm test && pnpm build",
68
- "example:dev": "pnpm build && pnpm --filter smartearth-base-example-vue dev"
69
- }
70
- }
1
+ {
2
+ "name": "@metagl/smartearth-base",
3
+ "version": "0.3.1",
4
+ "description": "集群业务地图底层包:基于 @metagl/sdk-render 的三维地球(替代已废弃的 @agent-earth/smart-earth)",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "packageManager": "pnpm@10.26.0",
8
+ "engines": {
9
+ "node": ">=20.0.0"
10
+ },
11
+ "sideEffects": false,
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "CHANGELOG.md"
16
+ ],
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./vite": {
26
+ "types": "./dist/vite.d.ts",
27
+ "import": "./dist/vite.js"
28
+ },
29
+ "./presets": {
30
+ "types": "./dist/presets.d.ts",
31
+ "import": "./dist/presets.js"
32
+ },
33
+ "./vue": {
34
+ "types": "./dist/vue.d.ts",
35
+ "import": "./dist/vue.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "typecheck": "tsc --noEmit -p tsconfig.json",
42
+ "test": "vitest run",
43
+ "check": "pnpm typecheck && pnpm test && pnpm build",
44
+ "example:dev": "pnpm build && pnpm --filter smartearth-base-example-vue dev"
45
+ },
46
+ "peerDependencies": {
47
+ "@metagl/sdk-render": "^3.0.0 || ^4.0.1",
48
+ "cesium": ">=1.132.0 <1.137.0",
49
+ "vite": ">=5.0.0",
50
+ "vue": "^3.5.0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "vite": {
54
+ "optional": true
55
+ },
56
+ "vue": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "devDependencies": {
61
+ "@metagl/sdk-render": "4.0.3",
62
+ "@types/node": "^22.0.0",
63
+ "cesium": "1.136.0",
64
+ "jsdom": "^26.0.0",
65
+ "tsup": "^8.5.0",
66
+ "typescript": "^5.8.0",
67
+ "vite": "^6.0.0",
68
+ "vitest": "^3.2.0",
69
+ "vue": "^3.5.0"
70
+ },
71
+ "publishConfig": {
72
+ "registry": "https://registry.npmjs.org/",
73
+ "access": "public"
74
+ }
75
+ }
@@ -1,267 +0,0 @@
1
- import * as CesiumNS from 'cesium';
2
- import { Cartesian3, Viewer, Entity } from 'cesium';
3
- import { Render } from '@metagl/sdk-render';
4
-
5
- /**
6
- * sdk-render 4.x 的模型材质(PBR)参数。字段与范围以 SDK 为准(SDK 会钳制越界值、丢弃未知字段):
7
- * diffuseStrength 0~4 · emissiveStrength 0~8 · specularStrength 0~4 · roughnessOffset -1~1 ·
8
- * aoStrength 0~4 · iblDiffuse / iblSpecular / luminance 0~1 · iblNightFactor 0~1 · emissiveNightGate ·
9
- * proceduralWindows。与 @metagl/sdk-render 4.0.0 的 TilesetMaterialParams 对齐。
10
- */
11
- interface PbrMaterialParams {
12
- readonly diffuseStrength?: number;
13
- readonly emissiveStrength?: number;
14
- readonly specularStrength?: number;
15
- readonly roughnessOffset?: number;
16
- readonly aoStrength?: number;
17
- readonly iblDiffuse?: number;
18
- readonly iblSpecular?: number;
19
- readonly luminance?: number;
20
- /** 夜间环境光(IBL)倍率 0~1:满夜时 IBL × 该值,白天不变(4.0.0 全局默认 0.25)。 */
21
- readonly iblNightFactor?: number;
22
- /** true = 自发光白天灭、入夜亮(城市窗灯),默认 true。 */
23
- readonly emissiveNightGate?: boolean;
24
- /**
25
- * 程序化夜间窗灯:只作用于没有自发光材质的 3DTiles(如城市白模),入夜按窗格错峰点亮;
26
- * 有自发光贴图的模型与 GLB 不受影响。默认 false,按需开启。
27
- */
28
- readonly proceduralWindows?: boolean;
29
- }
30
- /** 全局 PBR 参数(作用于 GLB 模型与纳管的 3DTiles),比单个 tileset 多一个 anisotropy。 */
31
- interface PbrGlobalParams extends PbrMaterialParams {
32
- /** 各向异性过滤 1~16。 */
33
- readonly anisotropy?: number;
34
- }
35
- /** 'material' 系统配置,导入导出同形;tileset 以去掉查询串的 URL 为键,不含令牌。 */
36
- interface PbrConfig {
37
- readonly pbr?: PbrGlobalParams;
38
- /** 是否自动给场景里没有 customShader 的 3DTiles 挂共享 PBR(4.0.0 默认 true)。 */
39
- readonly autoManageTilesets?: boolean;
40
- readonly tilesets?: Readonly<Record<string, PbrMaterialParams>>;
41
- }
42
- /** tileset 实例,或其 URL(尚未加载的会在加载后自动应用)。 */
43
- type PbrTarget = object | string;
44
- interface EarthPbr {
45
- /** 给一个 3DTiles 设单独材质;返回该 tileset 的键(URL 去查询串)。 */
46
- setTilesetMaterial(target: PbrTarget, params: PbrMaterialParams): string | null;
47
- getTilesetMaterial(target: PbrTarget): PbrMaterialParams | null;
48
- /** 清除单独材质,还原 tileset 原有 shader。 */
49
- clearTilesetMaterial(target: PbrTarget): void;
50
- /** 读全局 PBR 参数。 */
51
- getGlobal(): PbrGlobalParams;
52
- /** 改全局 PBR 参数(只改给出的字段)。 */
53
- setGlobal(params: PbrGlobalParams): void;
54
- /** 导出 'material' 配置(可 JSON 序列化)。 */
55
- exportConfig(): PbrConfig;
56
- /** 导入 'material' 配置。 */
57
- importConfig(config: PbrConfig): void;
58
- }
59
- /** 本包用到的 4.x Render 材质能力子集。 */
60
- interface MaterialCapableRender {
61
- setTilesetMaterial(target: unknown, params: PbrMaterialParams): string | null;
62
- getTilesetMaterial(target: unknown): PbrMaterialParams | null;
63
- clearTilesetMaterial(target: unknown): void;
64
- updateSystemConfig(systemName: string, config: unknown): void;
65
- getSystemConfig(systemName: string): unknown;
66
- }
67
- declare function supportsPbr(render: unknown): render is MaterialCapableRender;
68
- /**
69
- * sdk-render 有材质接口(4.x)时返回 PBR 适配层,否则 undefined。
70
- * 只做透传与参数形状校验,数值钳制交给 SDK。
71
- */
72
- declare function createEarthPbr(render: unknown): EarthPbr | undefined;
73
-
74
- /** 运行时 Cesium 命名空间(可写副本)。类型沿用 cesium 包的导出。 */
75
- type CesiumRuntime = typeof CesiumNS;
76
- declare const CESIUM_MIN_VERSION = "1.132.0";
77
- /** 不含:sdk-render 3.x 只验证到 1.136.x。 */
78
- declare const CESIUM_MAX_VERSION_EXCLUSIVE = "1.137.0";
79
- /**
80
- * ESM 命名空间对象是只读冻结的;sdk-render 需要在 window.Cesium 上做运行时增强,
81
- * 所以先解冻成可写副本(sdk-render 接口文档 §1 的 makeExtensible)。
82
- */
83
- declare function makeExtensible<T extends object>(obj: T): T;
84
-
85
- /** 所有图层描述的公共字段;具体种类在此基础上扩展。 */
86
- interface LayerSpec {
87
- readonly kind: string;
88
- readonly id: string;
89
- readonly visible?: boolean;
90
- readonly [key: string]: unknown;
91
- }
92
- interface GeoPosition {
93
- /** 度。 */
94
- readonly lon: number;
95
- /** 度。 */
96
- readonly lat: number;
97
- /** 米。 */
98
- readonly height: number;
99
- }
100
- interface PickedFeature {
101
- readonly layerId: string;
102
- readonly featureId: string;
103
- readonly properties: Readonly<Record<string, unknown>>;
104
- }
105
- /** 场景里的一次左键点击:点到图层要素时带 feature,点到地表时带位置。 */
106
- interface ClickEvent {
107
- readonly feature?: PickedFeature;
108
- readonly position?: GeoPosition;
109
- /** 世界坐标:点到实体时取实体位置,否则取地表交点。 */
110
- readonly worldPosition?: Cartesian3;
111
- /** 画布像素坐标。 */
112
- readonly screen: {
113
- readonly x: number;
114
- readonly y: number;
115
- };
116
- }
117
- /** 把 scene.pick 的结果(实体以外,如 3D Tiles 要素)解释成图层要素;认不出返回 undefined。 */
118
- type PickResolver = (picked: unknown) => PickedFeature | undefined;
119
- interface LayerContext {
120
- readonly viewer: Viewer;
121
- readonly Cesium: CesiumRuntime;
122
- readonly render: Render;
123
- /** sdk-render 4.x 的 PBR 接口;3.0 下为 undefined。 */
124
- readonly pbr: EarthPbr | undefined;
125
- /** 已加载的 sdk-render 版本号(getVersionInfo().version);读不到为 undefined。 */
126
- readonly sdkRenderVersion: string | undefined;
127
- /** 图层把可拾取的实体登记到这里,pick 事件据此回报图层与要素。 */
128
- readonly registerPickable: (entity: Entity, feature: PickedFeature) => void;
129
- readonly unregisterPickable: (entity: Entity) => void;
130
- /** 实体以外的可拾取对象(如 3D Tiles 要素);返回取消登记的函数。 */
131
- readonly registerPickResolver: (resolver: PickResolver) => () => void;
132
- /** 监听场景左键点击;返回取消监听的函数。 */
133
- readonly onClick: (listener: (event: ClickEvent) => void) => () => void;
134
- }
135
- /** 图层工厂返回的句柄。 */
136
- interface LayerHandle {
137
- setVisible(visible: boolean): void;
138
- /** 可选:供 flyTo(layerId) 使用。 */
139
- flyTarget?(): unknown;
140
- /** 可选:图层自己的操作接口,经 earth.layers.get(id) 取到(如航线的 play/pause)。 */
141
- readonly api?: unknown;
142
- destroy(): void;
143
- }
144
- type LayerFactory<S extends LayerSpec = LayerSpec> = (context: LayerContext, spec: S) => LayerHandle | Promise<LayerHandle>;
145
- interface LayerInfo {
146
- readonly id: string;
147
- readonly kind: string;
148
- readonly visible: boolean;
149
- }
150
-
151
- type Quality = 'high' | 'medium' | 'low';
152
- /** SmartEarth SDK 授权:在线/离线 token,或 licence + RSA 公钥(需本地 sdk-licence 服务)二选一。 */
153
- type SdkAuth = {
154
- readonly sdkToken: string;
155
- } | {
156
- readonly licence: {
157
- readonly lic: string;
158
- readonly rsaPubKey: string;
159
- };
160
- };
161
- interface CustomBasemap {
162
- /** 影像瓦片 URL 模板({z}/{x}/{y},可含 {s})。 */
163
- readonly imageryUrl: string;
164
- /** 注记瓦片 URL 模板,可省略。 */
165
- readonly annotationUrl?: string;
166
- readonly subdomains?: readonly string[];
167
- readonly maximumLevel?: number;
168
- }
169
- interface InitialView {
170
- readonly lon: number;
171
- readonly lat: number;
172
- /** 相机高度(米)。 */
173
- readonly height: number;
174
- /** 度,默认 0。 */
175
- readonly heading?: number;
176
- /** 度,默认 -90(正俯视)。 */
177
- readonly pitch?: number;
178
- }
179
- interface CreateEarthOptions {
180
- readonly auth: SdkAuth;
181
- /** 星图地图令牌;用星图底图或星图地形时必填。到 https://datacloud.geovisearth.com/ 申请。 */
182
- readonly geovisToken?: string;
183
- /** 'geovis' = 星图影像 + 注记;也可传自定义瓦片。默认 'geovis'。 */
184
- readonly basemap?: 'geovis' | CustomBasemap;
185
- /** 是否加载星图地形,默认 true。 */
186
- readonly terrain?: boolean;
187
- /** 初始画质,默认 'high'。 */
188
- readonly quality?: Quality;
189
- /** smartEarthAssets() 拷出来的资源根路径(sdk-render assets/resources 所在处),默认 '/'。 */
190
- readonly assetsBasePath?: string;
191
- /** 初始视角,默认中国全景。 */
192
- readonly initialView?: InitialView;
193
- /** 初始化前探测静态资源是否就位,默认 true。 */
194
- readonly checkAssets?: boolean;
195
- }
196
-
197
- interface PickEvent extends PickedFeature {
198
- /** 拾取点经纬度(度)与高度(米);拾不到地表时为 undefined。 */
199
- readonly position?: {
200
- readonly lon: number;
201
- readonly lat: number;
202
- readonly height: number;
203
- };
204
- }
205
- interface EarthEvents extends Record<string, unknown> {
206
- pick: PickEvent;
207
- }
208
- interface FlyToTarget {
209
- readonly lon: number;
210
- readonly lat: number;
211
- readonly height: number;
212
- readonly heading?: number;
213
- readonly pitch?: number;
214
- /** 秒,默认 1.5。 */
215
- readonly duration?: number;
216
- }
217
- interface EarthLayers {
218
- register<S extends LayerSpec>(kind: string, factory: LayerFactory<S>): void;
219
- add(spec: LayerSpec): Promise<LayerInfo>;
220
- remove(id: string): boolean;
221
- setVisible(id: string, visible: boolean): void;
222
- list(): LayerInfo[];
223
- /** 取图层的操作接口,如 route 的 play/pause、annotation 的 exportJSON;见各图层的 *Api 类型。 */
224
- get<T = unknown>(id: string): T | undefined;
225
- }
226
- interface Earth {
227
- readonly viewer: Viewer;
228
- readonly render: Render;
229
- /** 当前画质。 */
230
- readonly quality: Quality;
231
- /** 当前 sdk-render 能切到的画质(3.0 为 ['high','low'],4.x 为三档)。 */
232
- readonly supportedQualities: readonly Quality[];
233
- setQuality(quality: Quality): Promise<void>;
234
- readonly layers: EarthLayers;
235
- /** sdk-render 4.x 的模型材质(PBR)接口;3.0 下为 undefined。 */
236
- readonly pbr: EarthPbr | undefined;
237
- /** 飞到经纬度,或飞到某个图层(传图层 id)。 */
238
- flyTo(target: FlyToTarget | string): Promise<void>;
239
- on<K extends keyof EarthEvents>(event: K, listener: (payload: EarthEvents[K]) => void): () => void;
240
- destroy(): void;
241
- }
242
- /**
243
- * 不建地球就能知道已安装的 sdk-render 支持哪些画质(看 Render 原型上有没有 setQuality),
244
- * 用来在 createEarth 之前决定初始画质。
245
- */
246
- declare function getSupportedQualities(): readonly Quality[];
247
- /**
248
- * 建一个 SmartEarth 三维地球。任何一步失败都抛 SmartEarthError,并清理已创建的 Viewer;
249
- * 不会退化成没有 SmartEarth 渲染的普通 Cesium。
250
- */
251
- declare function createEarth(container: HTMLElement, rawOptions: CreateEarthOptions): Promise<Earth>;
252
-
253
- /**
254
- * SmartEarth 统一错误。所有初始化与运行期失败都抛这个类型,code 供程序判断,message 给人看(中文)。
255
- *
256
- * 绝不静默降级成普通 Cesium:授权、版本、资源、渲染任何一步失败都直接抛出。
257
- */
258
- type SmartEarthErrorCode = 'INVALID_OPTIONS' | 'AUTH_MISSING_SDK' | 'AUTH_MISSING_MAP' | 'AUTH_FAILED' | 'CESIUM_VERSION' | 'ASSETS_MISSING' | 'RENDER_INIT_FAILED' | 'QUALITY_UNSUPPORTED' | 'LAYER_KIND_UNKNOWN' | 'LAYER_DUPLICATE' | 'LAYER_NOT_FOUND' | 'LAYER_LOAD_FAILED' | 'PBR_UNSUPPORTED' | 'DESTROYED';
259
- declare const MAP_TOKEN_APPLY_URL = "https://datacloud.geovisearth.com/";
260
- declare class SmartEarthError extends Error {
261
- readonly code: SmartEarthErrorCode;
262
- readonly cause?: unknown;
263
- constructor(code: SmartEarthErrorCode, message: string, cause?: unknown);
264
- }
265
- declare function isSmartEarthError(value: unknown): value is SmartEarthError;
266
-
267
- export { CESIUM_MAX_VERSION_EXCLUSIVE as C, type Earth as E, type FlyToTarget as F, type GeoPosition as G, type InitialView as I, type LayerSpec as L, MAP_TOKEN_APPLY_URL as M, type PbrMaterialParams as P, type Quality as Q, type SdkAuth as S, type PickedFeature as a, CESIUM_MIN_VERSION as b, type ClickEvent as c, type CreateEarthOptions as d, type CustomBasemap as e, type EarthEvents as f, type EarthLayers as g, type EarthPbr as h, type LayerContext as i, type LayerFactory as j, type LayerHandle as k, type LayerInfo as l, type PbrConfig as m, type PbrGlobalParams as n, type PbrTarget as o, type PickEvent as p, type PickResolver as q, SmartEarthError as r, type SmartEarthErrorCode as s, createEarth as t, createEarthPbr as u, getSupportedQualities as v, isSmartEarthError as w, makeExtensible as x, supportsPbr as y };