@metagl/smartearth-base 0.0.0-stage → 0.2.0
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 +35 -0
- package/README.md +196 -3
- package/dist/chunk-O7CP7PJG.js +1862 -0
- package/dist/errors-CtkYU3iT.d.ts +267 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +1 -0
- package/dist/vite.d.ts +20 -0
- package/dist/vite.js +89 -0
- package/dist/vue.d.ts +32 -0
- package/dist/vue.js +54 -0
- package/package.json +67 -3
|
@@ -0,0 +1,267 @@
|
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { L as LayerSpec, P as PbrMaterialParams, G as GeoPosition, a as PickedFeature } from './errors-CtkYU3iT.js';
|
|
2
|
+
export { C as CESIUM_MAX_VERSION_EXCLUSIVE, b as CESIUM_MIN_VERSION, c as ClickEvent, d as CreateEarthOptions, e as CustomBasemap, E as Earth, f as EarthEvents, g as EarthLayers, h as EarthPbr, F as FlyToTarget, I as InitialView, i as LayerContext, j as LayerFactory, k as LayerHandle, l as LayerInfo, M as MAP_TOKEN_APPLY_URL, m as PbrConfig, n as PbrGlobalParams, o as PbrTarget, p as PickEvent, q as PickResolver, Q as Quality, S as SdkAuth, r as SmartEarthError, s as SmartEarthErrorCode, t as createEarth, u as createEarthPbr, v as getSupportedQualities, w as isSmartEarthError, x as makeExtensible, y as supportsPbr } from './errors-CtkYU3iT.js';
|
|
3
|
+
import { Cesium3DTileset } from 'cesium';
|
|
4
|
+
import '@metagl/sdk-render';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* sdk-render 3.0 没有画质档位接口时,本包按 geovisearthsdk_web《渲染性能优化方案》(2026-08-18)
|
|
8
|
+
* 的 T0「low 档」在出厂 baseline 上叠一层配置。high 即 baseline 原样。
|
|
9
|
+
*
|
|
10
|
+
* | 项 | baseline | low |
|
|
11
|
+
* |---|---|---|
|
|
12
|
+
* | ssgi / ssrt / ssr | 开 | 关(保留 gBuffer + hbao) |
|
|
13
|
+
* | 云 nubis.maxSteps / noiseEnabled | 256 / true | 56 / false |
|
|
14
|
+
* | 高度雾 quality | cinematic | low |
|
|
15
|
+
* | msaaEnabled / hdrEnabled | true(8) / true | false / false(只留 fxaa) |
|
|
16
|
+
* | 阴影 size / numBlurSamples / softShadows | 4864 / 24 / true | 2048 / 8 / false |
|
|
17
|
+
*/
|
|
18
|
+
declare const LOW_QUALITY_OVERRIDES: {
|
|
19
|
+
readonly ssgi: {
|
|
20
|
+
readonly enabled: false;
|
|
21
|
+
};
|
|
22
|
+
readonly ssrt: {
|
|
23
|
+
readonly enabled: false;
|
|
24
|
+
};
|
|
25
|
+
readonly ssr: {
|
|
26
|
+
readonly enabled: false;
|
|
27
|
+
};
|
|
28
|
+
readonly volumetricClouds: {
|
|
29
|
+
readonly nubis: {
|
|
30
|
+
readonly maxSteps: 56;
|
|
31
|
+
readonly noiseEnabled: false;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly heightFog: {
|
|
35
|
+
readonly quality: "low";
|
|
36
|
+
};
|
|
37
|
+
readonly postProcessing: {
|
|
38
|
+
readonly msaaEnabled: false;
|
|
39
|
+
readonly hdrEnabled: false;
|
|
40
|
+
readonly fxaaEnabled: true;
|
|
41
|
+
};
|
|
42
|
+
readonly shadow: {
|
|
43
|
+
readonly size: 2048;
|
|
44
|
+
readonly numBlurSamples: 8;
|
|
45
|
+
readonly softShadows: false;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** 按字段取色:`field` 的值查 `colors`,查不到用 `fallback`。 */
|
|
50
|
+
interface FieldColors {
|
|
51
|
+
readonly field: string;
|
|
52
|
+
/** 字段值 → CSS 颜色。 */
|
|
53
|
+
readonly colors: Readonly<Record<string, string>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface PointDatum {
|
|
57
|
+
/** 要素 id,缺省用序号。 */
|
|
58
|
+
readonly id?: string | number;
|
|
59
|
+
readonly lon: number;
|
|
60
|
+
readonly lat: number;
|
|
61
|
+
/** 米;缺省贴地。 */
|
|
62
|
+
readonly height?: number;
|
|
63
|
+
readonly [field: string]: unknown;
|
|
64
|
+
}
|
|
65
|
+
interface PointsLayerSpec extends LayerSpec {
|
|
66
|
+
readonly kind: 'points';
|
|
67
|
+
readonly data: readonly PointDatum[];
|
|
68
|
+
/** 按这个字段的值分色。 */
|
|
69
|
+
readonly colorBy?: string;
|
|
70
|
+
/** 字段值 → CSS 颜色。 */
|
|
71
|
+
readonly colors?: Readonly<Record<string, string>>;
|
|
72
|
+
/** 没匹配上时的颜色,默认白色。 */
|
|
73
|
+
readonly defaultColor?: string;
|
|
74
|
+
readonly pixelSize?: number;
|
|
75
|
+
/** 用作文字标注的字段;不传不显示标注。 */
|
|
76
|
+
readonly labelField?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface GeojsonStyle {
|
|
80
|
+
/** 面填充色,默认 #3b82f6。 */
|
|
81
|
+
readonly fill?: string;
|
|
82
|
+
/** 面填充不透明度 0~1,默认 0.35。 */
|
|
83
|
+
readonly fillOpacity?: number;
|
|
84
|
+
/** 线与面边框颜色,默认 #1d4ed8。 */
|
|
85
|
+
readonly stroke?: string;
|
|
86
|
+
/** 线宽(像素),默认 2。 */
|
|
87
|
+
readonly strokeWidth?: number;
|
|
88
|
+
/** 点颜色,默认 #ffffff。 */
|
|
89
|
+
readonly pointColor?: string;
|
|
90
|
+
/** 点大小(像素),默认 10。 */
|
|
91
|
+
readonly pointSize?: number;
|
|
92
|
+
}
|
|
93
|
+
interface GeojsonLayerSpec extends LayerSpec {
|
|
94
|
+
readonly kind: 'geojson';
|
|
95
|
+
/** GeoJSON 对象(FeatureCollection / Feature / Geometry)或其 URL。 */
|
|
96
|
+
readonly data: unknown;
|
|
97
|
+
readonly style?: GeojsonStyle;
|
|
98
|
+
/** 按字段着色:面填充、线、点都按这个字段取色。 */
|
|
99
|
+
readonly colorBy?: FieldColors;
|
|
100
|
+
/** 贴地,默认 true。 */
|
|
101
|
+
readonly clampToGround?: boolean;
|
|
102
|
+
/** 用作文字标注的字段。 */
|
|
103
|
+
readonly labelField?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface Tileset3dLayerSpec extends LayerSpec {
|
|
107
|
+
readonly kind: 'tileset3d';
|
|
108
|
+
/** tileset.json 地址。 */
|
|
109
|
+
readonly url: string;
|
|
110
|
+
/**
|
|
111
|
+
* 该 tileset 的单独 PBR 材质(亮度、金属/镜面、粗糙度、自发光、IBL 等),经 earth.pbr.setTilesetMaterial 设置。
|
|
112
|
+
* 不传就不动:sdk-render 4.x 默认会给 3D Tiles 挂共享 PBR。需要 sdk-render 4.x,3.0 下传了抛 PBR_UNSUPPORTED。
|
|
113
|
+
*/
|
|
114
|
+
readonly pbr?: PbrMaterialParams;
|
|
115
|
+
/** 屏幕空间误差阈值,越大越省,默认沿用 Cesium(16)。 */
|
|
116
|
+
readonly maximumScreenSpaceError?: number;
|
|
117
|
+
}
|
|
118
|
+
interface Tileset3dApi {
|
|
119
|
+
readonly tileset: Cesium3DTileset;
|
|
120
|
+
/** 改这个 tileset 的单独材质(需要 sdk-render 4.x)。 */
|
|
121
|
+
setMaterial(params: PbrMaterialParams): void;
|
|
122
|
+
/** 清除单独材质,回到共享 PBR。 */
|
|
123
|
+
clearMaterial(): void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 航线顶点:经度、纬度(度),高度(米,可省略=贴地)。 */
|
|
127
|
+
interface RoutePoint {
|
|
128
|
+
readonly lon: number;
|
|
129
|
+
readonly lat: number;
|
|
130
|
+
readonly height?: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 航线来源:
|
|
134
|
+
* - 坐标数组:`[[lon, lat, height?], ...]` 或 `[{ lon, lat, height? }, ...]`
|
|
135
|
+
* - GeoJSON:LineString,或含 LineString 的 Feature / FeatureCollection(取第一条)
|
|
136
|
+
* - KML 文本:取第一个 `<LineString><coordinates>`
|
|
137
|
+
*/
|
|
138
|
+
type RouteSource = readonly (readonly number[])[] | readonly RoutePoint[] | Readonly<Record<string, unknown>> | string;
|
|
139
|
+
|
|
140
|
+
interface RouteLayerSpec extends LayerSpec {
|
|
141
|
+
readonly kind: 'route';
|
|
142
|
+
/**
|
|
143
|
+
* 坐标数组、GeoJSON LineString(或含它的 Feature/FeatureCollection)、KML 文本;
|
|
144
|
+
* 字符串以 http(s):// 或 / 开头且不含 `<` 时当作地址去取(内容可以是 KML 或 GeoJSON)。
|
|
145
|
+
*/
|
|
146
|
+
readonly path: RouteSource;
|
|
147
|
+
/** 1 倍速下走完全程的秒数,默认 60。 */
|
|
148
|
+
readonly durationSeconds?: number;
|
|
149
|
+
/** 循环播放,默认 false。 */
|
|
150
|
+
readonly loop?: boolean;
|
|
151
|
+
/** 加载后立即播放,默认 false。 */
|
|
152
|
+
readonly autoplay?: boolean;
|
|
153
|
+
/** 相机跟随,默认 false。 */
|
|
154
|
+
readonly follow?: boolean;
|
|
155
|
+
/** 跟随时相机在标记点后方的距离(米),默认 2000;高度取其 0.6 倍。 */
|
|
156
|
+
readonly followRange?: number;
|
|
157
|
+
/** 显示整条航线,默认 true。 */
|
|
158
|
+
readonly showPath?: boolean;
|
|
159
|
+
readonly pathColor?: string;
|
|
160
|
+
readonly pathWidth?: number;
|
|
161
|
+
readonly markerColor?: string;
|
|
162
|
+
readonly markerSize?: number;
|
|
163
|
+
}
|
|
164
|
+
interface RouteProgressEvent {
|
|
165
|
+
/** 0~1。 */
|
|
166
|
+
readonly progress: number;
|
|
167
|
+
readonly lon: number;
|
|
168
|
+
readonly lat: number;
|
|
169
|
+
readonly height: number;
|
|
170
|
+
}
|
|
171
|
+
interface RouteEvents extends Record<string, unknown> {
|
|
172
|
+
progress: RouteProgressEvent;
|
|
173
|
+
end: undefined;
|
|
174
|
+
}
|
|
175
|
+
interface RouteApi {
|
|
176
|
+
readonly progress: number;
|
|
177
|
+
readonly playing: boolean;
|
|
178
|
+
readonly speed: number;
|
|
179
|
+
play(): void;
|
|
180
|
+
pause(): void;
|
|
181
|
+
/** 跳到进度 0~1。 */
|
|
182
|
+
seek(progress: number): void;
|
|
183
|
+
/** 倍速,> 0。 */
|
|
184
|
+
setSpeed(multiplier: number): void;
|
|
185
|
+
setFollow(follow: boolean): void;
|
|
186
|
+
on<K extends keyof RouteEvents>(event: K, listener: (payload: RouteEvents[K]) => void): () => void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 弹窗内容:HTMLElement,或 HTML 字符串(由调用方保证可信;拼用户数据时先 escapeHtml)。返回 null 表示这次不弹。 */
|
|
190
|
+
type PopupContent = HTMLElement | string | null;
|
|
191
|
+
interface PopupLayerSpec extends LayerSpec {
|
|
192
|
+
readonly kind: 'popup';
|
|
193
|
+
/** 只对这些图层的要素弹出;不传 = 所有图层。 */
|
|
194
|
+
readonly layers?: readonly string[];
|
|
195
|
+
/** 点到要素时生成弹窗内容。 */
|
|
196
|
+
readonly render: (feature: PickedFeature, position: GeoPosition | undefined) => PopupContent;
|
|
197
|
+
/** 附加到弹窗根元素的 class,便于改样式。 */
|
|
198
|
+
readonly className?: string;
|
|
199
|
+
/** 相对锚点的像素偏移,默认 { x: 0, y: -14 }(显示在点上方)。 */
|
|
200
|
+
readonly offset?: {
|
|
201
|
+
readonly x: number;
|
|
202
|
+
readonly y: number;
|
|
203
|
+
};
|
|
204
|
+
/** 点击没有打开本弹窗时(空白处、别的图层、render 返回 null)关闭旧弹窗,默认 true。 */
|
|
205
|
+
readonly closeOnEmptyClick?: boolean;
|
|
206
|
+
}
|
|
207
|
+
interface PopupApi {
|
|
208
|
+
readonly isOpen: boolean;
|
|
209
|
+
/** 手动在某个位置打开弹窗。 */
|
|
210
|
+
open(position: GeoPosition, content: Exclude<PopupContent, null>): void;
|
|
211
|
+
close(): void;
|
|
212
|
+
}
|
|
213
|
+
/** 转义 HTML 特殊字符;把字段值拼进弹窗 HTML 前用它。 */
|
|
214
|
+
declare function escapeHtml(value: unknown): string;
|
|
215
|
+
|
|
216
|
+
interface AnnotationDraft {
|
|
217
|
+
readonly name: string;
|
|
218
|
+
/** 等级,按 levels 着色;默认「中」。 */
|
|
219
|
+
readonly level?: string;
|
|
220
|
+
readonly description?: string;
|
|
221
|
+
}
|
|
222
|
+
interface AnnotationItem extends AnnotationDraft {
|
|
223
|
+
readonly id: string;
|
|
224
|
+
readonly level: string;
|
|
225
|
+
readonly lon: number;
|
|
226
|
+
readonly lat: number;
|
|
227
|
+
readonly height?: number;
|
|
228
|
+
/** ISO 时间。 */
|
|
229
|
+
readonly createdAt: string;
|
|
230
|
+
}
|
|
231
|
+
interface AnnotationLayerSpec extends LayerSpec {
|
|
232
|
+
readonly kind: 'annotation';
|
|
233
|
+
/** 等级 → CSS 颜色,默认 高 红 / 中 橙 / 低 黄。 */
|
|
234
|
+
readonly levels?: Readonly<Record<string, string>>;
|
|
235
|
+
/** 初始标注(比如上层从后端读回的)。 */
|
|
236
|
+
readonly items?: readonly AnnotationItem[];
|
|
237
|
+
}
|
|
238
|
+
interface AnnotationEvents extends Record<string, unknown> {
|
|
239
|
+
change: readonly AnnotationItem[];
|
|
240
|
+
}
|
|
241
|
+
interface AnnotationApi {
|
|
242
|
+
/** 进入放置状态:下一次点到地表就按 draft 加一条标注。再次调用会替换待放置的 draft。 */
|
|
243
|
+
startPlacing(draft: AnnotationDraft): Promise<AnnotationItem | undefined>;
|
|
244
|
+
/** 退出放置状态;等待中的 startPlacing 以 undefined 结束。 */
|
|
245
|
+
cancelPlacing(): void;
|
|
246
|
+
readonly placing: boolean;
|
|
247
|
+
add(item: AnnotationDraft & {
|
|
248
|
+
readonly lon: number;
|
|
249
|
+
readonly lat: number;
|
|
250
|
+
readonly height?: number;
|
|
251
|
+
readonly id?: string;
|
|
252
|
+
}): AnnotationItem;
|
|
253
|
+
remove(id: string): boolean;
|
|
254
|
+
list(): AnnotationItem[];
|
|
255
|
+
clear(): void;
|
|
256
|
+
/** 导出 { version: 1, items };不做持久化,存哪里由上层决定。 */
|
|
257
|
+
exportJSON(): string;
|
|
258
|
+
/** 导入 exportJSON 的结果(字符串或对象);默认替换现有标注,返回导入条数。 */
|
|
259
|
+
importJSON(json: string | object, options?: {
|
|
260
|
+
readonly append?: boolean;
|
|
261
|
+
}): number;
|
|
262
|
+
on<K extends keyof AnnotationEvents>(event: K, listener: (payload: AnnotationEvents[K]) => void): () => void;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
interface RiverWaterLayerSpec extends LayerSpec {
|
|
266
|
+
readonly kind: 'riverWater';
|
|
267
|
+
/**
|
|
268
|
+
* 水系 GeoJSON(LineString = 河道,Polygon = 湖面)或其 URL。水面高度只取坐标的 Z(米):
|
|
269
|
+
* 坐标没有 Z 时必须给 `height`,否则报 INVALID_OPTIONS(不让水面悄悄落在 0 米)。
|
|
270
|
+
*/
|
|
271
|
+
readonly data: unknown;
|
|
272
|
+
/** 给缺 Z 的坐标补的水面高程(米,绝对高程)。 */
|
|
273
|
+
readonly height?: number;
|
|
274
|
+
/** 河道宽度(米),线要素用,默认 60。 */
|
|
275
|
+
readonly width?: number;
|
|
276
|
+
/**
|
|
277
|
+
* 线要素怎么交给 sdk-render:
|
|
278
|
+
* - 'auto'(默认):sdk-render ≥ 4.0.2 原样传线;更早的版本按 width 先转成飘带面(4.0.1 及以前传线会停止整个场景渲染)。
|
|
279
|
+
* - 'ribbon' / 'native':强制转面 / 强制传线。
|
|
280
|
+
*/
|
|
281
|
+
readonly lineMode?: 'auto' | 'ribbon' | 'native';
|
|
282
|
+
/** 水面相对高程偏移(米)。 */
|
|
283
|
+
readonly offsetHeight?: number;
|
|
284
|
+
/** 厚水体下沉米数,0 = 平面水面。 */
|
|
285
|
+
readonly thickness?: number;
|
|
286
|
+
/**
|
|
287
|
+
* 地形挖坑,把地形压低 depth 米(正数)。
|
|
288
|
+
* - sdk-render ≥ 4.0.2:湖、库与河道线都挖(河道线按 width 转成面交给挖坑,逐点顺坡下挖)。
|
|
289
|
+
* - 更早的版本:只挖 Polygon(旧版把区域压平到「平均高程 + 偏移」,沿坡的河道会被压成平台)。
|
|
290
|
+
* 地形调整在 sdk-render 里是全局的,一个地球同时只能有一个带 dig 的 riverWater 图层。
|
|
291
|
+
*/
|
|
292
|
+
readonly dig?: {
|
|
293
|
+
readonly depth: number;
|
|
294
|
+
};
|
|
295
|
+
/** 显示 sdk-render 挖坑的青色示意面和「区域 N」标签,默认 false。 */
|
|
296
|
+
readonly showDigViz?: boolean;
|
|
297
|
+
/** 河道水面外观参数,原样交给 sdk-render 的 RiverWaterSystem.update(颜色、波浪、反射等)。 */
|
|
298
|
+
readonly config?: Readonly<Record<string, unknown>>;
|
|
299
|
+
}
|
|
300
|
+
interface RiverWaterApi {
|
|
301
|
+
/** 本图层创建的水面图层 id。 */
|
|
302
|
+
readonly layerIds: readonly string[];
|
|
303
|
+
/** 实际用的线模式。 */
|
|
304
|
+
readonly lineMode: 'ribbon' | 'native';
|
|
305
|
+
/** 改水面外观参数(作用于整个河道水面系统)。 */
|
|
306
|
+
update(config: Readonly<Record<string, unknown>>): void;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export { type AnnotationApi, type AnnotationDraft, type AnnotationEvents, type AnnotationItem, type AnnotationLayerSpec, type FieldColors, GeoPosition, type GeojsonLayerSpec, type GeojsonStyle, LOW_QUALITY_OVERRIDES, LayerSpec, PbrMaterialParams, PickedFeature, type PointDatum, type PointsLayerSpec, type PopupApi, type PopupContent, type PopupLayerSpec, type RiverWaterApi, type RiverWaterLayerSpec, type RouteApi, type RouteEvents, type RouteLayerSpec, type RoutePoint, type RouteProgressEvent, type RouteSource, type Tileset3dApi, type Tileset3dLayerSpec, escapeHtml };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CESIUM_MAX_VERSION_EXCLUSIVE, CESIUM_MIN_VERSION, LOW_QUALITY_OVERRIDES, MAP_TOKEN_APPLY_URL, SmartEarthError, createEarth, createEarthPbr, escapeHtml, getSupportedQualities, isSmartEarthError, makeExtensible, supportsPbr } from './chunk-O7CP7PJG.js';
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface SmartEarthAssetsOptions {
|
|
4
|
+
/**
|
|
5
|
+
* 资源拷到哪个目录,默认 Vite 的 publicDir(通常是 <root>/public)。
|
|
6
|
+
* 拷出来的 cesium/、assets/、resources/ 应加进 .gitignore。
|
|
7
|
+
*/
|
|
8
|
+
readonly outDir?: string;
|
|
9
|
+
/** Cesium 资源在站点上的子路径,默认 'cesium'(即 `${base}cesium`)。 */
|
|
10
|
+
readonly cesiumPath?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* SmartEarth 运行所需的 Vite 配置:
|
|
14
|
+
* - 把 Cesium(Assets/ThirdParty/Widgets/Workers)与 sdk-render(assets/resources)资源拷到 publicDir;
|
|
15
|
+
* - define CESIUM_BASE_URL,并在页面里写 window.CESIUM_BASE_URL;
|
|
16
|
+
* - cesium 别名到源码入口、dedupe,sdk-render 不预构建。
|
|
17
|
+
*/
|
|
18
|
+
declare function smartEarthAssets(options?: SmartEarthAssetsOptions): Plugin;
|
|
19
|
+
|
|
20
|
+
export { type SmartEarthAssetsOptions, smartEarthAssets as default, smartEarthAssets };
|