@caoguo/maplibre 0.0.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/chunk-DNEF4DHG.js +48 -0
- package/dist/chunk-DNEF4DHG.js.map +1 -0
- package/dist/chunk-EZOV5O2M.js +96 -0
- package/dist/chunk-EZOV5O2M.js.map +1 -0
- package/dist/chunk-MNUQZUQA.js +372 -0
- package/dist/chunk-MNUQZUQA.js.map +1 -0
- package/dist/index.cjs +1154 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +459 -0
- package/dist/index.d.ts +459 -0
- package/dist/index.js +587 -0
- package/dist/index.js.map +1 -0
- package/dist/offline/index.cjs +397 -0
- package/dist/offline/index.cjs.map +1 -0
- package/dist/offline/index.d.cts +300 -0
- package/dist/offline/index.d.ts +300 -0
- package/dist/offline/index.js +3 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/sources/index.cjs +102 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +83 -0
- package/dist/sources/index.d.ts +83 -0
- package/dist/sources/index.js +3 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/styles.cjs +53 -0
- package/dist/styles.cjs.map +1 -0
- package/dist/styles.d.cts +19 -0
- package/dist/styles.d.ts +19 -0
- package/dist/styles.js +3 -0
- package/dist/styles.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { StyleSpecification, Map as Map$1 } from 'maplibre-gl';
|
|
2
|
+
export { default as maplibregl } from 'maplibre-gl';
|
|
3
|
+
export { WUHAN_CENTER, WUHAN_ZOOM, osmRasterStyle } from './styles.js';
|
|
4
|
+
import { TiandituType, TiandituOptions } from './sources/index.js';
|
|
5
|
+
export { AddTiandituOptions, MissingTokenError, TiandituLayer, TiandituSourceSpec, addTiandituBaseMap, buildTiandituSources, tiandituStyle, tiandituTileUrls } from './sources/index.js';
|
|
6
|
+
import { TileStoreBackend, packGeoJSONToStore } from './offline/index.js';
|
|
7
|
+
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';
|
|
8
|
+
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
|
+
* 辉光线几何构建(T6 / F-1.3 纯逻辑部分)。
|
|
186
|
+
*
|
|
187
|
+
* 把 GeoJSON LineString 集合转换为「多遍辉光描边」所需的几何描述。
|
|
188
|
+
* 渲染层(CustomLineLayer)再据此在 WebGL 中绘制:每遍一个宽度档 + 透明度档,
|
|
189
|
+
* 叠加形成管线/路网/水系的辉光效果。
|
|
190
|
+
*
|
|
191
|
+
* 设计:本模块**不依赖 WebGL / maplibre**,纯函数可在 Node 单测。
|
|
192
|
+
* 坐标投影使用简化 Web Mercator(经度→x、纬度→y 的归一化世界坐标),
|
|
193
|
+
* 真实渲染时由 CustomLayer 的 matrix 变换到屏幕。
|
|
194
|
+
*/
|
|
195
|
+
interface GlowLine {
|
|
196
|
+
/** 线坐标 [lng, lat][] */
|
|
197
|
+
coordinates: [number, number][];
|
|
198
|
+
/** 该线所属分组(如 'pipe' | 'road' | 'water'),用于着色 */
|
|
199
|
+
group?: string;
|
|
200
|
+
}
|
|
201
|
+
interface GlowPass {
|
|
202
|
+
/** 相对基础宽度的倍数(核心线=1,外晕逐遍增大) */
|
|
203
|
+
widthScale: number;
|
|
204
|
+
/** 该遍不透明度(核心线高、外晕低) */
|
|
205
|
+
opacity: number;
|
|
206
|
+
}
|
|
207
|
+
interface GlowGeometry {
|
|
208
|
+
/** 所有线(含分组标记)的归一化坐标序列 */
|
|
209
|
+
lines: {
|
|
210
|
+
points: [number, number][];
|
|
211
|
+
group?: string;
|
|
212
|
+
}[];
|
|
213
|
+
/** 辉光多遍参数(从外晕到核心,或反之,由渲染层决定) */
|
|
214
|
+
passes: GlowPass[];
|
|
215
|
+
/** 总顶点数(用于缓冲分配) */
|
|
216
|
+
vertexCount: number;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* 生成辉光多遍档位。
|
|
220
|
+
* @param passes 遍数(默认 4:3 层外晕 + 1 核心)
|
|
221
|
+
* @param coreOpacity 核心线不透明度
|
|
222
|
+
*/
|
|
223
|
+
declare function glowPasses(passes?: number, coreOpacity?: number): GlowPass[];
|
|
224
|
+
/**
|
|
225
|
+
* 简化 Web Mercator 归一化(经度→x∈[-1,1],纬度→y∈[-1,1])。
|
|
226
|
+
* 仅用于几何构建与单测,真实投影在渲染层用 map 的 matrix。
|
|
227
|
+
*/
|
|
228
|
+
declare function projectSimple(lng: number, lat: number): [number, number];
|
|
229
|
+
/**
|
|
230
|
+
* 构建辉光几何:投影每条线并统计顶点。
|
|
231
|
+
* 顶点数 = 各线(点数-1)*2(线段两端),用于 Line 绘制。
|
|
232
|
+
*/
|
|
233
|
+
declare function buildGlowGeometry(lines: GlowLine[], opts?: {
|
|
234
|
+
passes?: number;
|
|
235
|
+
coreOpacity?: number;
|
|
236
|
+
}): GlowGeometry;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 辉光管线 Custom Layer(T6 / F-1.3 WebGL 渲染层)。
|
|
240
|
+
*
|
|
241
|
+
* 实现 MapLibre v4 `CustomLayerInterface`:在地图之上叠加绘制 GeoJSON 线,
|
|
242
|
+
* 用多遍(glowPasses)描边形成管线/路网/水系的辉光效果。
|
|
243
|
+
*
|
|
244
|
+
* 设计:几何构建(投影/档位)在 `./glowGeometry` 纯函数中完成(可单测);
|
|
245
|
+
* 本文件仅负责 WebGL 状态机与绘制,仅在浏览器执行。
|
|
246
|
+
* 通过 `Map.addGlowLayer` 注入,调用方无需感知 WebGL 细节。
|
|
247
|
+
*
|
|
248
|
+
* 依赖 MapLibre 注入的 `matrix`(map 的 projectionMatrix * modelViewMatrix),
|
|
249
|
+
* 与官方 CustomLayer 示例一致。
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
/** MapLibre v4 CustomLayerInterface 最小子集(避免强类型耦合) */
|
|
253
|
+
interface CustomLayerInterface {
|
|
254
|
+
id: string;
|
|
255
|
+
type: 'custom';
|
|
256
|
+
renderingMode?: '2d' | '3d';
|
|
257
|
+
onAdd?(map: unknown, gl: WebGLRenderingContext): void;
|
|
258
|
+
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
259
|
+
onRemove?(map: unknown, gl: WebGLRenderingContext): void;
|
|
260
|
+
prerender?(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
261
|
+
}
|
|
262
|
+
interface GlowLayerOptions {
|
|
263
|
+
/** 图层 id */
|
|
264
|
+
id?: string;
|
|
265
|
+
/** 线分组颜色映射(group -> [r,g,b] 0..1) */
|
|
266
|
+
colors?: Record<string, [number, number, number]>;
|
|
267
|
+
/** 基础线宽(像素,核心线) */
|
|
268
|
+
baseWidth?: number;
|
|
269
|
+
/** 辉光遍数 */
|
|
270
|
+
passes?: number;
|
|
271
|
+
/** 线集合 */
|
|
272
|
+
lines: GlowLine[];
|
|
273
|
+
}
|
|
274
|
+
declare class CustomLineLayer implements CustomLayerInterface {
|
|
275
|
+
id: string;
|
|
276
|
+
type: "custom";
|
|
277
|
+
renderingMode: '2d';
|
|
278
|
+
private lines;
|
|
279
|
+
private colors;
|
|
280
|
+
private baseWidth;
|
|
281
|
+
private passes;
|
|
282
|
+
private program?;
|
|
283
|
+
private buffer?;
|
|
284
|
+
private geometry;
|
|
285
|
+
private map?;
|
|
286
|
+
constructor(opts: GlowLayerOptions);
|
|
287
|
+
onAdd(map: unknown, gl: WebGLRenderingContext): void;
|
|
288
|
+
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
289
|
+
onRemove(_map: unknown, gl: WebGLRenderingContext): void;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* LOD 控制器(T7 / F-1.7,纯逻辑)。
|
|
294
|
+
*
|
|
295
|
+
* 按地图 zoom 自动切换数据密度(Level of Detail):
|
|
296
|
+
* - 低 zoom(全国/省)显示聚合/简化数据,避免要素过密;
|
|
297
|
+
* - 高 zoom(市/区)显示全量/精细数据。
|
|
298
|
+
*
|
|
299
|
+
* 设计:本模块**不依赖 maplibre / WebGL / DOM**,纯函数可在 Node 单测。
|
|
300
|
+
* 控制器 `LodController` 监听 zoom 变化并回调当前应激活的 LOD 等级,
|
|
301
|
+
* 调用方据此 `setData` / 切换 source(具体渲染动作由调用方决定)。
|
|
302
|
+
*/
|
|
303
|
+
interface LodLevel<T = unknown> {
|
|
304
|
+
/** 该等级名称(如 'country' | 'province' | 'city' | 'detail') */
|
|
305
|
+
id: string;
|
|
306
|
+
/** 进入该等级的最小 zoom(含) */
|
|
307
|
+
minZoom: number;
|
|
308
|
+
/** 进入该等级的最大 zoom(含);省略表示 +∞ */
|
|
309
|
+
maxZoom?: number;
|
|
310
|
+
/** 该等级承载的数据/配置(任意类型,调用方解释) */
|
|
311
|
+
payload?: T;
|
|
312
|
+
}
|
|
313
|
+
interface LodChangeEvent<T> {
|
|
314
|
+
/** 当前激活等级 */
|
|
315
|
+
level: LodLevel<T>;
|
|
316
|
+
/** 是否相较上一次发生了等级切换 */
|
|
317
|
+
changed: boolean;
|
|
318
|
+
/** 当前 zoom */
|
|
319
|
+
zoom: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* 根据 zoom 解析应激活的 LOD 等级。
|
|
323
|
+
* 规则:取满足 minZoom<=zoom<=(maxZoom??∞) 的等级;
|
|
324
|
+
* 若存在多个命中(区间重叠),取 minZoom 最大者(更精细优先)。
|
|
325
|
+
* 无命中返回 null(调用方可保留上一等级)。
|
|
326
|
+
*/
|
|
327
|
+
declare function resolveLod<T>(zoom: number, levels: LodLevel<T>[]): LodLevel<T> | null;
|
|
328
|
+
/**
|
|
329
|
+
* 给定可视范围的"要素密度"建议(用于调试/UI 提示)。
|
|
330
|
+
* 返回每屏建议最大要素数(随 zoom 平方增长,模拟瓦片面积)。
|
|
331
|
+
*/
|
|
332
|
+
declare function suggestDensity(zoom: number, basePerTile?: number, tileCountFactor?: number): number;
|
|
333
|
+
/**
|
|
334
|
+
* LOD 控制器(薄状态机)。监听 zoom,触发 onLod 回调。
|
|
335
|
+
*/
|
|
336
|
+
declare class LodController<T = unknown> {
|
|
337
|
+
private levels;
|
|
338
|
+
private current;
|
|
339
|
+
private onChange;
|
|
340
|
+
private map;
|
|
341
|
+
constructor(map: LodController['map'], levels: LodLevel<T>[], onChange: (e: LodChangeEvent<T>) => void);
|
|
342
|
+
private handler;
|
|
343
|
+
/** 立即评估当前 zoom 并(按需)触发回调 */
|
|
344
|
+
evaluate(force?: boolean): LodLevel<T> | null;
|
|
345
|
+
/** 当前等级 */
|
|
346
|
+
getLevel(): LodLevel<T> | null;
|
|
347
|
+
/** 更新分级配置(如权限/数据就绪后) */
|
|
348
|
+
setLevels(levels: LodLevel<T>[]): void;
|
|
349
|
+
/** 卸载监听 */
|
|
350
|
+
remove(): void;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
type MapInstance = Map$1;
|
|
354
|
+
|
|
355
|
+
interface MapOptions {
|
|
356
|
+
container: string | HTMLElement;
|
|
357
|
+
center?: [number, number];
|
|
358
|
+
zoom?: number;
|
|
359
|
+
style?: string | StyleSpecification;
|
|
360
|
+
pitch?: number;
|
|
361
|
+
bearing?: number;
|
|
362
|
+
/**
|
|
363
|
+
* 业务/叠加数据的坐标系(默认 WGS84)。
|
|
364
|
+
* 引擎内部以 WGS84 渲染;若数据为 GCJ-02 / CGCS2000,
|
|
365
|
+
* 设定后可通过 `transformToMap` 在入图前自动纠偏。
|
|
366
|
+
*/
|
|
367
|
+
dataCRS?: CRS;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* 草果地图引擎封装(展示层骨架)。
|
|
371
|
+
*
|
|
372
|
+
* 当前为轻量包装:直接复用 maplibre-gl 能力。
|
|
373
|
+
* 后续阶段将在此注入:GCJ-02/BD-09 坐标系插件、行业 Shader、离线瓦片加载,
|
|
374
|
+
* 业务调用方无需改动(通过本类统一入口)。
|
|
375
|
+
*/
|
|
376
|
+
declare class Map {
|
|
377
|
+
private _map;
|
|
378
|
+
private _dataCRS;
|
|
379
|
+
constructor(options: MapOptions);
|
|
380
|
+
/**
|
|
381
|
+
* 把业务坐标系坐标转换到地图渲染基准(WGS84)。
|
|
382
|
+
* 用于叠加 GCJ-02 / CGCS2000 数据前的纠偏。
|
|
383
|
+
*/
|
|
384
|
+
transformToMap(lng: number, lat: number): LngLat;
|
|
385
|
+
/** 设定叠加数据坐标系 */
|
|
386
|
+
setDataCRS(crs: CRS): void;
|
|
387
|
+
/** 读取叠加数据坐标系 */
|
|
388
|
+
getDataCRS(): CRS;
|
|
389
|
+
/** 生成当前 dataCRS -> WGS84 的变换器(供批量转换使用) */
|
|
390
|
+
getTransformer(): Transformer;
|
|
391
|
+
/**
|
|
392
|
+
* 切换为底图为天地图(国内权威底图,CGCS2000 / Web Mercator)。
|
|
393
|
+
* token 必须由调用方注入,缺失时抛出 MissingTokenError。
|
|
394
|
+
*/
|
|
395
|
+
useTianditu(type: TiandituType, opts: Omit<TiandituOptions, 'type'>): void;
|
|
396
|
+
/** 向当前地图注入天地图底图(叠加在现有 style 之上) */
|
|
397
|
+
addTianditu(opts: Omit<TiandituOptions, 'type'> & {
|
|
398
|
+
type?: TiandituType;
|
|
399
|
+
}): void;
|
|
400
|
+
/** 离线瓦片后端(默认浏览器 IndexedDB / Node 内存) */
|
|
401
|
+
private _store;
|
|
402
|
+
/** 注册离线协议并启用离线瓦片读取(F-1.4) */
|
|
403
|
+
enableOffline(store?: TileStoreBackend): void;
|
|
404
|
+
/** 当前离线存储实例 */
|
|
405
|
+
getOfflineStore(): TileStoreBackend;
|
|
406
|
+
/** 构造离线源 tiles(供 source.tiles 使用) */
|
|
407
|
+
offlineTiles(sourceId: string): string[];
|
|
408
|
+
/** 把 GeoJSON 打包进离线存储(分桶到瓦片网格) */
|
|
409
|
+
packGeoJSON(sourceId: string, geojson: Parameters<typeof packGeoJSONToStore>[1]['geojson'], opts?: {
|
|
410
|
+
maxZoom?: number;
|
|
411
|
+
expires?: number;
|
|
412
|
+
}): Promise<number>;
|
|
413
|
+
addLayer(layer: Record<string, unknown>): void;
|
|
414
|
+
removeLayer(id: string): void;
|
|
415
|
+
on(event: string, layerId?: string, cb?: (e: unknown) => void): void;
|
|
416
|
+
addSource(id: string, source: object): void;
|
|
417
|
+
getSource(id: string): unknown;
|
|
418
|
+
flyTo(opts: {
|
|
419
|
+
center?: [number, number];
|
|
420
|
+
zoom?: number;
|
|
421
|
+
pitch?: number;
|
|
422
|
+
bearing?: number;
|
|
423
|
+
}): void;
|
|
424
|
+
remove(): void;
|
|
425
|
+
/**
|
|
426
|
+
* 挂载比例尺 + 实时坐标控件(T8 / F-1.8)。
|
|
427
|
+
* 返回控件实例,可调用 .remove() 卸载。
|
|
428
|
+
*/
|
|
429
|
+
addScaleControl(options?: {
|
|
430
|
+
showCoordinate?: boolean;
|
|
431
|
+
maxWidth?: number;
|
|
432
|
+
}): ScaleControl;
|
|
433
|
+
/**
|
|
434
|
+
* 挂载主题切换控件(T8 / F-1.9),在 caoguo-dark / caoguo-light 间切换。
|
|
435
|
+
* 返回控件实例,可调用 .toggle() / .setTheme() / .remove()。
|
|
436
|
+
*/
|
|
437
|
+
addThemeSwitcher(initial?: ThemeName): ThemeSwitcher;
|
|
438
|
+
/**
|
|
439
|
+
* 挂载辉光管线 Custom Layer(T6 / F-1.3)。
|
|
440
|
+
* 传入 GeoJSON 线集合,叠加渲染管线/路网/水系辉光效果。
|
|
441
|
+
* @returns 图层 id(可用于 removeLayer)
|
|
442
|
+
*/
|
|
443
|
+
addGlowLayer(opts: {
|
|
444
|
+
id?: string;
|
|
445
|
+
lines: GlowLine[];
|
|
446
|
+
colors?: Record<string, [number, number, number]>;
|
|
447
|
+
baseWidth?: number;
|
|
448
|
+
passes?: number;
|
|
449
|
+
}): string;
|
|
450
|
+
/**
|
|
451
|
+
* 挂载 LOD 控制器(T7 / F-1.7)。
|
|
452
|
+
* 随 zoom 切换数据密度等级,并在等级变化时回调(调用方据此 setData / 切源)。
|
|
453
|
+
* @returns LodController 实例(可 .getLevel() / .remove())
|
|
454
|
+
*/
|
|
455
|
+
addLodController<T = unknown>(levels: LodLevel<T>[], onLod: (e: LodChangeEvent<T>) => void): LodController<T>;
|
|
456
|
+
get instance(): Map$1;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export { type Bounds, type CRS, type CustomLayerInterface, CustomLineLayer, type GlowGeometry, type GlowLayerOptions, type GlowLine, type GlowPass, type GridShiftProvider, type LngLat, type LodChangeEvent, LodController, type LodLevel, Map, type MapInstance, type MapOptions, type Point, type ScaleBar, ScaleControl, type ScaleControlOptions, ThemeSwitcher, type ThemeSwitcherOptions, TiandituOptions, TiandituType, TileStoreBackend, type Transformer, buildGlowGeometry, cgcs2000ToWgs84, computeScaleBar, createTransformer, Map as default, fromWgs84, gcj02ToWgs84, glowPasses, isInChina, oppositeTheme, packGeoJSONToStore, projectSimple, resolveLod, setCgcs2000GridShift, suggestDensity, themeFromStyle, toWgs84, transformBounds, transformPoint, wgs84ToCgcs2000, wgs84ToGcj02 };
|