@caoguo/maplibre 0.0.6 → 0.0.7

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.
Files changed (64) hide show
  1. package/dist/chunk-DENQSIV2.js +81 -0
  2. package/dist/chunk-DENQSIV2.js.map +1 -0
  3. package/dist/chunk-G7VY42ZG.js +210 -0
  4. package/dist/chunk-G7VY42ZG.js.map +1 -0
  5. package/dist/chunk-MLLIAWVI.js +214 -0
  6. package/dist/chunk-MLLIAWVI.js.map +1 -0
  7. package/dist/chunk-OLS4DD3F.js +27 -0
  8. package/dist/chunk-OLS4DD3F.js.map +1 -0
  9. package/dist/chunk-OUEPE6JT.js +26 -0
  10. package/dist/chunk-OUEPE6JT.js.map +1 -0
  11. package/dist/chunk-SKXL3DKL.js +125 -0
  12. package/dist/chunk-SKXL3DKL.js.map +1 -0
  13. package/dist/chunk-Y3JNDOHU.js +56 -0
  14. package/dist/chunk-Y3JNDOHU.js.map +1 -0
  15. package/dist/controls/index.cjs +227 -0
  16. package/dist/controls/index.cjs.map +1 -0
  17. package/dist/controls/index.d.cts +171 -0
  18. package/dist/controls/index.d.ts +171 -0
  19. package/dist/controls/index.js +4 -0
  20. package/dist/controls/index.js.map +1 -0
  21. package/dist/crs/index.cjs +137 -0
  22. package/dist/crs/index.cjs.map +1 -0
  23. package/dist/crs/index.d.cts +80 -0
  24. package/dist/crs/index.d.ts +80 -0
  25. package/dist/crs/index.js +3 -0
  26. package/dist/crs/index.js.map +1 -0
  27. package/dist/index.cjs +48 -13
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +11 -499
  30. package/dist/index.d.ts +11 -499
  31. package/dist/index.js +14 -643
  32. package/dist/index.js.map +1 -1
  33. package/dist/lod/index.cjs +60 -0
  34. package/dist/lod/index.cjs.map +1 -0
  35. package/dist/lod/index.d.cts +62 -0
  36. package/dist/lod/index.d.ts +62 -0
  37. package/dist/lod/index.js +3 -0
  38. package/dist/lod/index.js.map +1 -0
  39. package/dist/shaders/index.cjs +215 -0
  40. package/dist/shaders/index.cjs.map +1 -0
  41. package/dist/shaders/index.d.cts +131 -0
  42. package/dist/shaders/index.d.ts +131 -0
  43. package/dist/shaders/index.js +3 -0
  44. package/dist/shaders/index.js.map +1 -0
  45. package/dist/sourceUtils.cjs +30 -0
  46. package/dist/sourceUtils.cjs.map +1 -0
  47. package/dist/sourceUtils.d.cts +60 -0
  48. package/dist/sourceUtils.d.ts +60 -0
  49. package/dist/sourceUtils.js +3 -0
  50. package/dist/sourceUtils.js.map +1 -0
  51. package/dist/styles.cjs +47 -12
  52. package/dist/styles.cjs.map +1 -1
  53. package/dist/styles.d.cts +13 -4
  54. package/dist/styles.d.ts +13 -4
  55. package/dist/styles.js +1 -1
  56. package/dist/terrain.cjs +31 -0
  57. package/dist/terrain.cjs.map +1 -0
  58. package/dist/terrain.d.cts +28 -0
  59. package/dist/terrain.d.ts +28 -0
  60. package/dist/terrain.js +3 -0
  61. package/dist/terrain.js.map +1 -0
  62. package/package.json +31 -1
  63. package/dist/chunk-DNEF4DHG.js +0 -48
  64. package/dist/chunk-DNEF4DHG.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,508 +1,20 @@
1
+ import { CRS, LngLat, Transformer } from './crs/index.js';
2
+ export { Bounds, GridShiftProvider, Point, cgcs2000ToWgs84, createTransformer, fromWgs84, gcj02ToWgs84, isInChina, setCgcs2000GridShift, toWgs84, transformBounds, transformPoint, wgs84ToCgcs2000, wgs84ToGcj02 } from './crs/index.js';
1
3
  import { StyleSpecification, Map as Map$1 } from 'maplibre-gl';
2
4
  export { default as maplibregl } from 'maplibre-gl';
3
- export { WUHAN_CENTER, WUHAN_ZOOM, osmRasterStyle } from './styles.js';
5
+ export { WUHAN_CENTER, WUHAN_ZOOM, geoqRasterStyle, localBasemapStyle, osmRasterStyle } from './styles.js';
4
6
  import { TiandituType, TiandituOptions } from './sources/index.js';
5
7
  export { AddTiandituOptions, MissingTokenError, TiandituLayer, TiandituSourceSpec, addTiandituBaseMap, buildTiandituSources, tiandituStyle, tiandituTileUrls } from './sources/index.js';
6
8
  import { TileStoreBackend, packGeoJSONToStore } from './offline/index.js';
7
9
  export { AirgapMessage, CACHEABLE_HOSTS, CACHE_NAME, IdbTileStore, MSG_AIRGAP, MemoryTileStore, OFFLINE_PROTOCOL, OfflineProtocolContext, PackGeoJSONOptions, ResolveResponseDeps, ResolvedResponse, SW_TEMPLATE_HINT, StoredTile, TileFormat, createDefaultStore, createFetchHandler, createOfflineLoader, installServiceWorker, offlineGeoJSONSource, offlineSourceTiles, offlineTileUrl, parseOfflineUrl, registerOfflineProtocol, registerOfflineServiceWorker, resolveCacheKey, resolveFromStore, resolveResponse, setAirgap, shouldCache, tileKey } from './offline/index.js';
10
+ import { ScaleControl, ThemeSwitcher, LegendControl, ExportControl } from './controls/index.js';
11
+ export { ExportOptions, LegendItem, LegendOptions, ScaleBar, ScaleControlOptions, ThemeSwitcherOptions, computeScaleBar, oppositeTheme, renderLegendHtml, themeFromStyle, triggerDownload } from './controls/index.js';
12
+ import { GlowLine } from './shaders/index.js';
13
+ export { CustomLayerInterface, CustomLineLayer, GlowGeometry, GlowLayerOptions, GlowPass, buildGlowGeometry, glowPasses, projectSimple } from './shaders/index.js';
14
+ import { LodLevel, LodChangeEvent, LodController } from './lod/index.js';
15
+ export { resolveLod, suggestDensity } from './lod/index.js';
8
16
  import { ThemeName } from '@caoguo/theme';
9
-
10
- /**
11
- * 坐标系类型与变换接口(F-1.1)。
12
- *
13
- * 草果地图内部统一以 WGS84(EPSG:4326)为渲染基准。
14
- * 业务数据可能为 GCJ-02(火星坐标)或 CGCS2000(国家2000),
15
- * 通过 `createTransformer` 以 WGS84 为枢纽做相互转换。
16
- */
17
- type CRS = 'WGS84' | 'GCJ02' | 'CGCS2000';
18
- type LngLat = [number, number];
19
- /** 一个坐标对(经/纬),与 MapLibre [lng, lat] 顺序一致 */
20
- type Point = LngLat;
21
- /** 地理范围 [west, south, east, north] */
22
- type Bounds = [number, number, number, number];
23
- interface Transformer {
24
- /** 正向变换:from -> to */
25
- forward(lng: number, lat: number): LngLat;
26
- /** 逆向变换:to -> from(数学逆) */
27
- inverse(lng: number, lat: number): LngLat;
28
- }
29
- /**
30
- * CGCS2000 高精度偏移提供方(可选)。
31
- * Phase 0 默认不接入官方格网,使用等价实现(误差 < 0.5m)。
32
- * 测绘级场景可注入区域 7 参数 / 格网平移表。
33
- */
34
- interface GridShiftProvider {
35
- /** 返回相对 WGS84 的 [dLng, dLat] 偏移(单位:度) */
36
- shift(lng: number, lat: number): LngLat;
37
- }
38
-
39
- /**
40
- * WGS84 <-> GCJ-02(火星坐标系)转换。
41
- *
42
- * 算法:公开的解析偏移模型(Krasovsky 椭球),与 coordtransform 一致。
43
- * 全国范围单点误差 < 50m(PRD 验收 F-1.1)。
44
- * 注意:GCJ-02 -> WGS84 采用 3 次迭代反算,进一步收敛残差。
45
- */
46
- /** WGS84 -> GCJ-02 */
47
- declare function wgs84ToGcj02(lng: number, lat: number): [number, number];
48
- /** GCJ-02 -> WGS84(3 次迭代反算) */
49
- declare function gcj02ToWgs84(lng: number, lat: number): [number, number];
50
- /** 是否在 GCJ-02 偏移覆盖区(中国境内外判定) */
51
- declare function isInChina(lng: number, lat: number): boolean;
52
-
53
- /**
54
- * WGS84 <-> CGCS2000 转换。
55
- *
56
- * 说明:CGCS2000 与 WGS84 采用近似相同的参考椭球(扁率/长半轴差异极小,
57
- * 历元差异仅导致 cm~dm 级点位偏移),在 Web Mercator 显示尺度下等价于一致。
58
- * 因此 Phase 0 默认实现为恒等变换(残差 < 0.5m,满足 PRD 验收 F-1.1)。
59
- *
60
- * 测绘级高精度需求:可注入 `GridShiftProvider`(区域 7 参数 / 格网平移),
61
- * 见 types.ts。本文件保留可扩展入口。
62
- */
63
-
64
- /** 注册 CGCS2000 偏移提供方(可选,测绘级) */
65
- declare function setCgcs2000GridShift(provider: GridShiftProvider | null): void;
66
- /** WGS84 -> CGCS2000 */
67
- declare function wgs84ToCgcs2000(lng: number, lat: number): LngLat;
68
- /** CGCS2000 -> WGS84 */
69
- declare function cgcs2000ToWgs84(lng: number, lat: number): LngLat;
70
-
71
- /**
72
- * 坐标系变换组合器(以 WGS84 为枢纽)。
73
- *
74
- * 用法:
75
- * const t = createTransformer('GCJ02', 'WGS84');
76
- * const [lng, lat] = t.forward(114.30, 30.59); // GCJ-02 业务数据 -> 渲染基准
77
- */
78
-
79
- /** 把任意 CRS 的坐标转换到 WGS84 */
80
- declare function toWgs84(crs: CRS, lng: number, lat: number): LngLat;
81
- /** 把 WGS84 坐标转换到目标 CRS */
82
- declare function fromWgs84(crs: CRS, lng: number, lat: number): LngLat;
83
- declare function createTransformer(from: CRS, to: CRS): Transformer;
84
- /** 单点快捷转换 */
85
- declare function transformPoint(lng: number, lat: number, from: CRS, to: CRS): LngLat;
86
- /** 范围 [w, s, e, n] 转换(取四个角点极值) */
87
- declare function transformBounds(b: Bounds, from: CRS, to: CRS): Bounds;
88
-
89
- interface ScaleBar {
90
- /** 比例尺条代表的真实距离(米) */
91
- meters: number;
92
- /** 比例尺条在屏幕上的像素宽度 */
93
- pixels: number;
94
- /** 展示文案,如 "500 m" / "2 km" */
95
- label: string;
96
- }
97
- /**
98
- * 计算比例尺。
99
- * @param latitude 当前视图中心纬度(度)
100
- * @param zoom MapLibre zoom(Web Mercator)
101
- * @param dpiScale 设备像素比(默认 1;Retina 设为 window.devicePixelRatio)
102
- * @param maxWidth 比例尺条最大像素宽度(默认 100)
103
- * @param tileSize 瓦片像素尺寸(默认 512,MapLibre v4 默认)
104
- */
105
- declare function computeScaleBar(latitude: number, zoom: number, opts?: {
106
- dpiScale?: number;
107
- maxWidth?: number;
108
- tileSize?: number;
109
- }): ScaleBar;
110
- interface ScaleControlOptions {
111
- /** 挂载容器(可选;不传则在地图容器内自动创建) */
112
- container?: HTMLElement;
113
- /** 是否显示实时坐标(默认 true) */
114
- showCoordinate?: boolean;
115
- /** 最大比例尺像素宽度 */
116
- maxWidth?: number;
117
- }
118
- /**
119
- * 比例尺控件。需传入 maplibre Map 实例(直接用 maplibre-gl 的 Map)。
120
- */
121
- declare class ScaleControl {
122
- private el;
123
- private barEl;
124
- private labelEl;
125
- private coordEl?;
126
- private map;
127
- private opts;
128
- private onMove;
129
- private onZoom;
130
- constructor(map: ScaleControl['map'], options?: ScaleControlOptions);
131
- /** 把控件挂到地图容器(无预设容器时调用) */
132
- addTo(container: HTMLElement): this;
133
- /** 计算并刷新显示 */
134
- update(): void;
135
- private handleMove;
136
- /** 移除控件与事件监听 */
137
- remove(): void;
138
- }
139
-
140
- /**
141
- * 主题切换控件(T8 / F-1.9)。
142
- *
143
- * 在暗色(caoguo-dark)与亮色(caoguo-light)官方矢量主题间切换,
144
- * 调用 `map.setStyle` 并保留当前视图(center/zoom)与现有 GeoJSON 源/图层。
145
- *
146
- * 设计为「纯函数 core + 薄 DOM 绑定」:
147
- * - `toggleTheme` / `themeFromStyle` 为纯逻辑,可独立单测;
148
- * - `ThemeSwitcher` 类负责渲染按钮并绑定点击事件。
149
- */
150
-
151
- interface ThemeSwitcherOptions {
152
- /** 挂载容器(可选) */
153
- container?: HTMLElement;
154
- /** 初始主题 */
155
- initial?: ThemeName;
156
- }
157
- declare function oppositeTheme(theme: ThemeName): ThemeName;
158
- /**
159
- * 从当前 style 对象推断主题名(依据其 JSON 标识)。
160
- * 非草果主题时回退到传入的 fallback。
161
- */
162
- declare function themeFromStyle(style: {
163
- name?: string;
164
- } | string | null | undefined, fallback?: ThemeName): ThemeName;
165
- declare class ThemeSwitcher {
166
- private el;
167
- private btn;
168
- private current;
169
- private map;
170
- constructor(map: ThemeSwitcher['map'], options?: ThemeSwitcherOptions);
171
- private applyLabel;
172
- /** 当前主题 */
173
- getTheme(): ThemeName;
174
- /** 切换到指定主题(保留视图,diff 模式避免闪烁) */
175
- setTheme(theme: ThemeName): void;
176
- /** 在明暗之间切换 */
177
- toggle(): void;
178
- /** 挂到容器 */
179
- addTo(container: HTMLElement): this;
180
- /** 移除 */
181
- remove(): void;
182
- }
183
-
184
- /**
185
- * 图例控件(通用)。
186
- *
187
- * 行业专题图(水深色阶 / 光缆利用率 / 闸站状态 / 故障告警等)渲染后,
188
- * 需要用户可读的图例说明。本控件接收数据驱动的图例项(label + color),
189
- * 以「色块 + 文案」形式渲染;支持运行时 setItems 随图层切换更新。
190
- *
191
- * 设计为「纯函数 renderLegendHtml + 薄 DOM 绑定」:renderLegendHtml 不依赖浏览器,可独立单测。
192
- */
193
- interface LegendItem {
194
- /** 文案,如「水深 > 3m」「利用率高」 */
195
- label: string;
196
- /** 色值(CSS color,可与渲染层 paint 配色保持一致) */
197
- color: string;
198
- /** 标记形状:color 色块(默认)/ line 线段 */
199
- shape?: 'color' | 'line';
200
- }
201
- interface LegendOptions {
202
- /** 图例标题(可选) */
203
- title?: string;
204
- /** 图例项 */
205
- items: LegendItem[];
206
- /** 挂载容器(可选;不传则自动创建) */
207
- container?: HTMLElement;
208
- }
209
- /** 纯函数:根据图例项生成 HTML 字符串(可单测) */
210
- declare function renderLegendHtml(items: LegendItem[], title?: string): string;
211
- /** 图例控件 */
212
- declare class LegendControl {
213
- private el;
214
- private bodyEl;
215
- private opts;
216
- constructor(options: LegendOptions);
217
- private render;
218
- /** 运行时更新图例项(随图层切换重新渲染) */
219
- setItems(items: LegendItem[], title?: string): void;
220
- /** 挂载到容器 */
221
- addTo(container: HTMLElement): this;
222
- remove(): void;
223
- }
224
-
225
- /**
226
- * 地图导出控件(通用)。
227
- *
228
- * 行业专题图渲染后,常需导出当前视图为成果图(PNG)。
229
- * 基于 maplibre-gl 画布 `toDataURL('image/png')` 生成截图并触发浏览器下载。
230
- *
231
- * 设计为「纯函数 triggerDownload + 薄 DOM 绑定」:triggerDownload 不依赖地图,可独立单测。
232
- */
233
- interface ExportOptions {
234
- /** 下载文件名(不含扩展名) */
235
- filename?: string;
236
- /** 挂载容器(可选;不传则自动创建) */
237
- container?: HTMLElement;
238
- /** 按钮文案 */
239
- buttonText?: string;
240
- }
241
- /** 纯函数:触发浏览器下载(data URL) */
242
- declare function triggerDownload(dataUrl: string, filename: string): void;
243
- /** 导出控件 */
244
- declare class ExportControl {
245
- private el;
246
- private map;
247
- private filename;
248
- private onClick;
249
- constructor(map: ExportControl['map'], options?: ExportOptions);
250
- /** 导出当前地图视图为 PNG 并下载 */
251
- export(): void;
252
- /** 挂载到容器 */
253
- addTo(container: HTMLElement): this;
254
- remove(): void;
255
- }
256
-
257
- /**
258
- * 辉光线几何构建(T6 / F-1.3 纯逻辑部分)。
259
- *
260
- * 把 GeoJSON LineString 集合转换为「多遍描边」所需的三角形带几何。
261
- * 渲染层(CustomLineLayer)据此在 WebGL 中以屏幕像素宽度的三角面叠加绘制,
262
- * 每遍一个宽度档 + 透明度档,加法混合形成管线/路网/水系的辉光效果。
263
- *
264
- * 设计:本模块**不依赖 WebGL / maplibre**,纯函数可在 Node 单测。
265
- * 坐标投影使用简化 Web Mercator(经度→x、纬度→y 的归一化世界坐标),
266
- * 真实渲染时由 CustomLayer 的 matrix 变换到屏幕;线宽在屏幕空间计算。
267
- */
268
- interface GlowLine {
269
- /** 线坐标 [lng, lat][] */
270
- coordinates: [number, number][];
271
- /** 该线所属分组(如 'pipe' | 'road' | 'water'),用于按组分色。缺省归入 'default'。 */
272
- group?: string;
273
- }
274
- interface GlowPass {
275
- /** 该遍屏幕像素宽度 */
276
- width: number;
277
- /** 该遍不透明度(核心线高、外晕低) */
278
- opacity: number;
279
- }
280
- interface GlowGeometry {
281
- /**
282
- * 扁平化顶点缓冲。每个顶点 6 个 float:
283
- * [worldX, worldY, dirX, dirY, side, groupIndex]
284
- * - worldX/worldY:该端点的归一化世界坐标
285
- * - dirX/dirY:所在线段的世界空间方向(用于屏幕空间法线)
286
- * - side:±1,左/右扩展符号
287
- * - groupIndex:该顶点所属分组在 `groups` 中的下标(用于按组分色)
288
- */
289
- vertices: Float32Array;
290
- /** 每遍在 vertices 中的顶点区间 [start, count](按顶点数,非 float 数) */
291
- passRanges: {
292
- start: number;
293
- count: number;
294
- }[];
295
- /** 每遍参数(从最外晕到核心,由宽到窄) */
296
- passes: GlowPass[];
297
- /** 顶点属性跨距(float 数) */
298
- stride: number;
299
- /** 参与渲染的去重分组名(与上层 colorMap 对应,下标即 groupIndex) */
300
- groups: string[];
301
- /** 逐遍、逐分组的连续顶点区间,供按组分色绘制 */
302
- renderGroups: {
303
- passIndex: number;
304
- group: string;
305
- start: number;
306
- count: number;
307
- }[];
308
- }
309
- /**
310
- * 生成辉光多遍档位。
311
- * @param passes 遍数(默认 4:3 层外晕 + 1 核心)
312
- * @param baseWidth 核心线像素宽度(默认 3)
313
- */
314
- declare function glowPasses(passes?: number, baseWidth?: number): GlowPass[];
315
- /**
316
- * 简化 Web Mercator 归一化(经度→x∈[-1,1],纬度→y 经墨卡托压缩)。
317
- * 仅用于几何构建与单测,真实投影在渲染层用 map 的 matrix。
318
- */
319
- declare function projectSimple(lng: number, lat: number): [number, number];
320
- /**
321
- * 构建辉光几何:对每条线、每遍、每段生成三角面(2 三角形 = 6 顶点)。
322
- */
323
- declare function buildGlowGeometry(lines: GlowLine[], opts?: {
324
- passes?: number;
325
- baseWidth?: number;
326
- }): GlowGeometry;
327
-
328
- /**
329
- * 辉光管线 Custom Layer(T6 / F-1.3 WebGL 渲染层)。
330
- *
331
- * 实现 MapLibre v4 `CustomLayerInterface`:在地图之上叠加绘制 GeoJSON 线,
332
- * 用多遍(glowPasses)三角面描边形成管线/路网/水系的辉光效果。
333
- *
334
- * 设计:几何构建(投影/三角带)在 `./glowGeometry` 纯函数中完成(可单测);
335
- * 本文件仅负责 WebGL 状态机与绘制,仅在浏览器执行。
336
- * 线宽在屏幕空间按像素计算(标准 Mapbox line shader 思路),因此可随缩放保持视觉宽度。
337
- * 通过 `Map.addGlowLayer` 注入,调用方无需感知 WebGL 细节。
338
- *
339
- * 依赖 MapLibre 注入的 `matrix`(map 的 projectionMatrix * modelViewMatrix)。
340
- */
341
-
342
- /** MapLibre v4 CustomLayerInterface 最小子集(避免强类型耦合) */
343
- interface CustomLayerInterface {
344
- id: string;
345
- type: 'custom';
346
- renderingMode?: '2d' | '3d';
347
- onAdd?(map: unknown, gl: WebGLRenderingContext): void;
348
- render(gl: WebGLRenderingContext, matrix: number[]): void;
349
- onRemove?(map: unknown, gl: WebGLRenderingContext): void;
350
- prerender?(gl: WebGLRenderingContext, matrix: number[]): void;
351
- }
352
- interface GlowLayerOptions {
353
- /** 图层 id */
354
- id?: string;
355
- /** 线分组颜色映射(group -> [r,g,b] 0..1) */
356
- colors?: Record<string, [number, number, number]>;
357
- /** 基础线宽(像素,核心线) */
358
- baseWidth?: number;
359
- /** 辉光遍数 */
360
- passes?: number;
361
- /** 线集合 */
362
- lines: GlowLine[];
363
- }
364
- declare class CustomLineLayer implements CustomLayerInterface {
365
- id: string;
366
- type: "custom";
367
- renderingMode: '2d';
368
- private lines;
369
- private colors;
370
- private baseWidth;
371
- private program?;
372
- private buffer?;
373
- private geometry;
374
- private map?;
375
- private gl?;
376
- constructor(opts: GlowLayerOptions);
377
- onAdd(map: unknown, gl: WebGLRenderingContext): void;
378
- render(gl: WebGLRenderingContext, matrix: number[]): void;
379
- /**
380
- * 动态更新线集合(高亮选中、切换数据等无需重建图层)。
381
- * 浏览器环境会刷新 GPU 缓冲;纯逻辑/测试环境仅更新几何与数据。
382
- */
383
- setLines(lines: GlowLine[]): void;
384
- onRemove(_map: unknown, gl: WebGLRenderingContext): void;
385
- }
386
-
387
- /**
388
- * LOD 控制器(T7 / F-1.7,纯逻辑)。
389
- *
390
- * 按地图 zoom 自动切换数据密度(Level of Detail):
391
- * - 低 zoom(全国/省)显示聚合/简化数据,避免要素过密;
392
- * - 高 zoom(市/区)显示全量/精细数据。
393
- *
394
- * 设计:本模块**不依赖 maplibre / WebGL / DOM**,纯函数可在 Node 单测。
395
- * 控制器 `LodController` 监听 zoom 变化并回调当前应激活的 LOD 等级,
396
- * 调用方据此 `setData` / 切换 source(具体渲染动作由调用方决定)。
397
- */
398
- interface LodLevel<T = unknown> {
399
- /** 该等级名称(如 'country' | 'province' | 'city' | 'detail') */
400
- id: string;
401
- /** 进入该等级的最小 zoom(含) */
402
- minZoom: number;
403
- /** 进入该等级的最大 zoom(含);省略表示 +∞ */
404
- maxZoom?: number;
405
- /** 该等级承载的数据/配置(任意类型,调用方解释) */
406
- payload?: T;
407
- }
408
- interface LodChangeEvent<T> {
409
- /** 当前激活等级 */
410
- level: LodLevel<T>;
411
- /** 是否相较上一次发生了等级切换 */
412
- changed: boolean;
413
- /** 当前 zoom */
414
- zoom: number;
415
- }
416
- /**
417
- * 根据 zoom 解析应激活的 LOD 等级。
418
- * 规则:取满足 minZoom<=zoom<=(maxZoom??∞) 的等级;
419
- * 若存在多个命中(区间重叠),取 minZoom 最大者(更精细优先)。
420
- * 无命中返回 null(调用方可保留上一等级)。
421
- */
422
- declare function resolveLod<T>(zoom: number, levels: LodLevel<T>[]): LodLevel<T> | null;
423
- /**
424
- * 给定可视范围的"要素密度"建议(用于调试/UI 提示)。
425
- * 返回每屏建议最大要素数(随 zoom 平方增长,模拟瓦片面积)。
426
- */
427
- declare function suggestDensity(zoom: number, basePerTile?: number, tileCountFactor?: number): number;
428
- /**
429
- * LOD 控制器(薄状态机)。监听 zoom,触发 onLod 回调。
430
- */
431
- declare class LodController<T = unknown> {
432
- private levels;
433
- private current;
434
- private onChange;
435
- private map;
436
- constructor(map: LodController['map'], levels: LodLevel<T>[], onChange: (e: LodChangeEvent<T>) => void);
437
- private handler;
438
- /** 立即评估当前 zoom 并(按需)触发回调 */
439
- evaluate(force?: boolean): LodLevel<T> | null;
440
- /** 当前等级 */
441
- getLevel(): LodLevel<T> | null;
442
- /** 更新分级配置(如权限/数据就绪后) */
443
- setLevels(levels: LodLevel<T>[]): void;
444
- /** 卸载监听 */
445
- remove(): void;
446
- }
447
-
448
- /**
449
- * 原生 MapLibre 地图 source 操作的幂等工具。
450
- *
451
- * 各业务 System(grid/water/pipeline/telecom/compute/transport)的 render()
452
- * 通过 `this.map.instance` 直接调用原生 MapLibre,而非经 CaoguoMap 包装类的
453
- * 幂等 addSource。为避免在每个 System 内重复书写 `if (!mlMap.getSource(id))`
454
- * 样板,并根治「层级切换重渲染崩溃」(Source already exists),统一在此提供
455
- * 幂等 upsert 与安全的 removeSource。
456
- *
457
- * 仅依赖原生 MapLibre 的 source 子集接口,便于各 System 直接传入 instance。
458
- */
459
- /**
460
- * 原生 MapLibre source 操作的子集接口。
461
- *
462
- * 仅 `getSource` 为必填——它是所有 helper 判断「source 是否存在」的统一探针。
463
- * 其余方法全部可选,因为各业务 System 对 `this.map.instance` 的局部类型断言
464
- * 只声明了实际用到的若干方法(如 topology 只取 getSource/removeSource,
465
- * traffic 只取 addSource/addLayer),强制统一必填字段会与这些子集冲突。
466
- * helper 内部对每个要调用的方法做存在性检查,缺失时安全跳过或回退,
467
- * 保证类型与运行时都安全(真实 MapLibre 实例始终具备全部方法)。
468
- */
469
- interface MlMapSourceApi {
470
- getSource: (id: string) => unknown;
471
- addSource?: (id: string, source: unknown) => void;
472
- addLayer?: (layer: unknown) => void;
473
- setData?: (id: string, data: unknown) => void;
474
- removeSource?: (id: string) => void;
475
- }
476
- /**
477
- * 幂等地确保一个 GeoJSON source 存在并持有给定数据。
478
- *
479
- * - 若 source 已存在且具备 setData:setData 更新(避免重复 addSource 抛错)。
480
- * - 若 source 已存在但无 setData:回退为 addSource(MapLibre 对重复 id 会忽略/覆盖,
481
- * 不抛错,仍可达成渲染目标)。
482
- * - 若 source 不存在且具备 addSource:addSource 创建。
483
- *
484
- * 注意:若传入对象既无 setData 又无 addSource,则无法创建/更新 source。
485
- * 各 System 传入的 `this.map.instance` 为真实 MapLibre 实例,始终具备这些方法。
486
- *
487
- * @param mlMap 原生 MapLibre 实例(或任意满足 MlMapSourceApi 的对象)
488
- * @param id source 唯一标识
489
- * @param data GeoJSON 数据(或 addSource 所需的 source spec)
490
- */
491
- declare function upsertSource(mlMap: MlMapSourceApi, id: string, data: unknown): void;
492
- /**
493
- * 安全地移除 source:仅当存在且具备 removeSource 时才移除,避免不存在时抛错。
494
- *
495
- * @param mlMap 原生 MapLibre 实例
496
- * @param id source 唯一标识
497
- */
498
- declare function removeSourceSafe(mlMap: MlMapSourceApi, id: string): void;
499
- /**
500
- * 安全地批量移除 source。
501
- *
502
- * @param mlMap 原生 MapLibre 实例
503
- * @param ids source 标识数组
504
- */
505
- declare function removeSourcesSafe(mlMap: MlMapSourceApi, ids: string[]): void;
17
+ export { MlMapSourceApi, removeSourceSafe, removeSourcesSafe, upsertSource } from './sourceUtils.js';
506
18
 
507
19
  type MapInstance = Map$1;
508
20
  /**
@@ -698,4 +210,4 @@ declare class Map {
698
210
  get instance(): Map$1;
699
211
  }
700
212
 
701
- export { type Bounds, type CRS, type CaoguoMapGlobalConfig, type CustomLayerInterface, CustomLineLayer, ExportControl, type ExportOptions, type GlowGeometry, type GlowLayerHandle, type GlowLayerOptions, type GlowLine, type GlowPass, type GridShiftProvider, LegendControl, type LegendItem, type LegendOptions, type LngLat, type LodChangeEvent, LodController, type LodLevel, Map, type MapInstance, type MapOptions, type MlMapSourceApi, type Point, type ScaleBar, ScaleControl, type ScaleControlOptions, ThemeSwitcher, type ThemeSwitcherOptions, TiandituOptions, TiandituType, TileStoreBackend, type Transformer, WebGLUnavailableError, buildGlowGeometry, cgcs2000ToWgs84, computeScaleBar, createTransformer, Map as default, fromWgs84, gcj02ToWgs84, getGlobalConfig, glowPasses, isInChina, isWebGLAvailable, oppositeTheme, packGeoJSONToStore, projectSimple, removeSourceSafe, removeSourcesSafe, renderLegendHtml, resolveLod, setCgcs2000GridShift, setGlobalConfig, suggestDensity, themeFromStyle, toWgs84, transformBounds, transformPoint, triggerDownload, upsertSource, wgs84ToCgcs2000, wgs84ToGcj02 };
213
+ export { CRS, type CaoguoMapGlobalConfig, ExportControl, type GlowLayerHandle, GlowLine, LegendControl, LngLat, LodChangeEvent, LodController, LodLevel, Map, type MapInstance, type MapOptions, ScaleControl, ThemeSwitcher, TiandituOptions, TiandituType, TileStoreBackend, Transformer, WebGLUnavailableError, Map as default, getGlobalConfig, isWebGLAvailable, packGeoJSONToStore, setGlobalConfig };