@bitalltech-maplibre/core 1.0.2 → 1.0.3

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 (28) hide show
  1. package/README.md +102 -0
  2. package/dist/index.cjs.js +1 -1
  3. package/dist/index.esm.js +1566 -107
  4. package/dist/index.umd.js +1 -1
  5. package/dist/types/effects/electronic-fence-common.d.ts +76 -0
  6. package/dist/types/effects/electronic-fence-types.d.ts +131 -0
  7. package/dist/types/effects/index.d.ts +3 -0
  8. package/dist/types/effects/low-altitude/breach-alert.d.ts +61 -0
  9. package/dist/types/effects/low-altitude/breathing-circle.d.ts +5 -0
  10. package/dist/types/effects/low-altitude/coordinated-countermeasure.d.ts +5 -0
  11. package/dist/types/effects/low-altitude/countermeasure-beam.d.ts +5 -0
  12. package/dist/types/effects/low-altitude/defence-circle.d.ts +5 -0
  13. package/dist/types/effects/low-altitude/directional-pulse.d.ts +6 -0
  14. package/dist/types/effects/low-altitude/navigation-spoofing.d.ts +6 -0
  15. package/dist/types/effects/low-altitude/pulse-marker.d.ts +5 -0
  16. package/dist/types/effects/low-altitude/radar-sweep.d.ts +5 -0
  17. package/dist/types/effects/low-altitude/ring-pulse-marker.d.ts +5 -0
  18. package/dist/types/effects/low-altitude/sector-scan.d.ts +5 -0
  19. package/dist/types/effects/low-altitude/shared.d.ts +67 -0
  20. package/dist/types/effects/low-altitude/target-lock.d.ts +4 -0
  21. package/dist/types/effects/low-altitude/types.d.ts +333 -0
  22. package/dist/types/effects/low-altitude/visual.d.ts +15 -0
  23. package/dist/types/effects/low-altitude.d.ts +15 -441
  24. package/dist/types/effects/standard-electronic-fence.d.ts +7 -0
  25. package/dist/types/effects/webgl-electronic-fence.d.ts +7 -0
  26. package/dist/types/index.d.ts +2 -2
  27. package/dist/types/map/create-map.d.ts +2 -1
  28. package/package.json +1 -1
@@ -0,0 +1,67 @@
1
+ import { type Map, type CanvasSourceSpecification, type CircleLayerSpecification, type FillLayerSpecification, type LineLayerSpecification, type RasterLayerSpecification, type SymbolLayerSpecification } from "maplibre-gl";
2
+ import type { LngLatTuple } from "../geometry";
3
+ export type EffectFeatureCollection = GeoJSON.FeatureCollection<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>;
4
+ export type EffectLayerSpecification = (Omit<FillLayerSpecification, "id" | "source"> & {
5
+ id: string;
6
+ type: "fill";
7
+ }) | (Omit<LineLayerSpecification, "id" | "source"> & {
8
+ id: string;
9
+ type: "line";
10
+ }) | (Omit<CircleLayerSpecification, "id" | "source"> & {
11
+ id: string;
12
+ type: "circle";
13
+ }) | (Omit<SymbolLayerSpecification, "id" | "source"> & {
14
+ id: string;
15
+ type: "symbol";
16
+ }) | (Omit<RasterLayerSpecification, "id" | "source"> & {
17
+ id: string;
18
+ type: "raster";
19
+ });
20
+ /** Canvas 渐变这类非 GeoJSON 渲染需要额外挂载的 source。 */
21
+ export interface EffectCanvasSource {
22
+ id: string;
23
+ source: CanvasSourceSpecification;
24
+ }
25
+ export interface BaseEffectOptions {
26
+ /** 特效 id;会派生出 sourceId 和多个 layerId。 */
27
+ id: string;
28
+ /** 特效中心点,经纬度。 */
29
+ center: LngLatTuple;
30
+ /** 插入到指定图层之前。 */
31
+ beforeId?: string;
32
+ /** 初始是否可见,默认可见。 */
33
+ visible?: boolean;
34
+ }
35
+ /** 每种特效渲染函数的输出:GeoJSON 数据、图层配置和可选动画启动器。 */
36
+ export interface EffectRenderResult<Options> {
37
+ data: EffectFeatureCollection;
38
+ layers: EffectLayerSpecification[];
39
+ canvasSources?: EffectCanvasSource[];
40
+ startAnimation?: (context: EffectAnimationContext<Options>) => (() => void) | void;
41
+ }
42
+ export interface EffectAnimationContext<Options> {
43
+ /** 获取最新 options,动画过程中 update 后会立即读取到新配置。 */
44
+ getOptions: () => Options;
45
+ /** 写回 GeoJSON source 数据,动画每帧只需要替换特效数据。 */
46
+ setData: (data: EffectFeatureCollection) => void;
47
+ }
48
+ /** addXxxEffect 返回的控制器,用于更新、显隐和移除特效。 */
49
+ export interface MapEffectController<Options> {
50
+ /** 特效 id。 */
51
+ id: string;
52
+ /** 更新特效配置。内部会重建 source/layer 或刷新动画数据。 */
53
+ update: (options: Partial<Omit<Options, "id">>) => void;
54
+ /** 显示全部相关图层,不重新创建 source。 */
55
+ show: () => void;
56
+ /** 隐藏全部相关图层,source 数据仍保留。 */
57
+ hide: () => void;
58
+ /** 移除图层、source 和动画。调用后控制器不可再恢复。 */
59
+ remove: () => void;
60
+ }
61
+ export declare const createFeature: <Geometry extends GeoJSON.Geometry>(geometry: Geometry, properties: GeoJSON.GeoJsonProperties) => GeoJSON.Feature<Geometry>;
62
+ export declare const createFeatureCollection: (features: GeoJSON.Feature[]) => EffectFeatureCollection;
63
+ export declare const removeLayerIfExists: (map: Map, id: string) => void;
64
+ export declare const removeSourceIfExists: (map: Map, id: string) => void;
65
+ export declare const setLayersVisibility: (map: Map, layerIds: string[], visible: boolean) => void;
66
+ export declare const isStyleNotReadyError: (error: unknown) => boolean;
67
+ export declare const createManagedEffect: <Options extends BaseEffectOptions>(map: Map, initialOptions: Options, renderEffect: (options: Options) => EffectRenderResult<Options>) => MapEffectController<Options>;
@@ -0,0 +1,4 @@
1
+ import { type Map } from "maplibre-gl";
2
+ import type { MapEffectController } from "./shared";
3
+ import type { TargetLockOptions } from "./types";
4
+ export declare const addTargetLock: (map: Map, initialOptions: TargetLockOptions) => MapEffectController<TargetLockOptions>;
@@ -0,0 +1,333 @@
1
+ import type { LngLatTuple } from "../geometry";
2
+ import type { BaseEffectOptions } from "./shared";
3
+ /** 单点扩散脉冲:适合告警点、事件点、目标点高亮。 */
4
+ export interface PulseMarkerOptions extends BaseEffectOptions {
5
+ /** 中心实心区域半径,单位米。 */
6
+ radius?: number;
7
+ /** 脉冲最大扩散半径,单位米。 */
8
+ maxRadius?: number;
9
+ /** 主颜色。 */
10
+ color?: string;
11
+ /** 中心填充色,默认跟随 color。 */
12
+ fillColor?: string;
13
+ /** 中心填充透明度。 */
14
+ fillOpacity?: number;
15
+ /** 脉冲环透明度。 */
16
+ pulseOpacity?: number;
17
+ /** 脉冲环线宽。 */
18
+ lineWidth?: number;
19
+ /** 同时存在的脉冲环数量。 */
20
+ pulseCount?: number;
21
+ /** 一轮扩散动画时长,单位毫秒。 */
22
+ duration?: number;
23
+ }
24
+ /** 多环脉冲:比普通脉冲更强调中心和外扩环。 */
25
+ export interface RingPulseMarkerOptions extends BaseEffectOptions {
26
+ /** 核心半径,单位米。 */
27
+ radius?: number;
28
+ /** 外环最大半径,单位米。 */
29
+ maxRadius?: number;
30
+ /** 外扩环数量。 */
31
+ ringCount?: number;
32
+ /** 主颜色。 */
33
+ color?: string;
34
+ /** 核心填充色。 */
35
+ fillColor?: string;
36
+ /** 核心填充透明度。设为 0 可隐藏填充。 */
37
+ fillOpacity?: number;
38
+ /** 核心描边线及外扩同心环的线透明度。 */
39
+ lineOpacity?: number;
40
+ /** 环线宽度。 */
41
+ lineWidth?: number;
42
+ /** 一轮动画时长,单位毫秒。 */
43
+ duration?: number;
44
+ /** 核心呼吸缩放幅度。 */
45
+ pulseScale?: number;
46
+ }
47
+ /** 呼吸圆:适合叠在图标、设备点或目标点后面做柔和背景高亮。 */
48
+ export interface BreathingCircleOptions extends BaseEffectOptions {
49
+ /** 基础半径,单位米。 */
50
+ radius?: number;
51
+ /** 呼吸最小半径,单位米;不传时根据 radius 自动计算。 */
52
+ minRadius?: number;
53
+ /** 呼吸最大半径,单位米;不传时根据 radius 自动计算。 */
54
+ maxRadius?: number;
55
+ /** 主颜色。 */
56
+ color?: string;
57
+ /** 填充色,默认跟随 color。 */
58
+ fillColor?: string;
59
+ /** 最亮时填充透明度。 */
60
+ fillOpacity?: number;
61
+ /** 最暗时填充透明度。 */
62
+ minFillOpacity?: number;
63
+ /** 描边颜色,默认跟随 color。 */
64
+ strokeColor?: string;
65
+ /** 最亮时描边透明度。 */
66
+ strokeOpacity?: number;
67
+ /** 最暗时描边透明度。 */
68
+ minStrokeOpacity?: number;
69
+ /** 描边宽度,单位像素。设为 0 可隐藏描边。 */
70
+ strokeWidth?: number;
71
+ /** 一轮呼吸动画时长,单位毫秒。 */
72
+ duration?: number;
73
+ }
74
+ /** 扇形扫描渐变配置。colors 在扇形扫描效果中会从圆心沿半径方向过渡到外缘。在雷达扫描中,centerOpacity 会从圆心开始,edgeOpacity 会从外缘开始。 */
75
+ export interface SectorScanGradientOptions {
76
+ colors?: string[];
77
+ opacity?: number;
78
+ /** 圆心附近透明度;不传时使用基础透明度的 25%。 */
79
+ centerOpacity?: number;
80
+ /** 外缘透明度;不传时使用基础透明度。 */
81
+ edgeOpacity?: number;
82
+ }
83
+ /** 扇形扫描:给定起止角度,可选旋转速度和分段渐变。 */
84
+ export interface SectorScanOptions extends BaseEffectOptions {
85
+ /** 扇形半径,单位米。 */
86
+ radius: number;
87
+ /** 起始方位角,0 表示正北,顺时针增加。 */
88
+ startAngle: number;
89
+ /** 结束方位角,0 表示正北,顺时针增加。 */
90
+ endAngle: number;
91
+ /** 纯色填充颜色;未传 gradient.colors 时使用。 */
92
+ color?: string;
93
+ /** 纯色填充透明度,或渐变默认透明度。 */
94
+ opacity?: number;
95
+ /** 径向渐变配置;colors 至少两个颜色时启用 Canvas 渐变。 */
96
+ gradient?: SectorScanGradientOptions;
97
+ /** 扇形两条边线颜色。 */
98
+ outlineColor?: string;
99
+ /** 扇形边线透明度。 */
100
+ outlineOpacity?: number;
101
+ /** 扇形边线宽度。 */
102
+ outlineWidth?: number;
103
+ /** 旋转速度,单位度/秒;不传或为 0 时静止。 */
104
+ rotationSpeed?: number;
105
+ }
106
+ /** 定向脉冲:一组沿指定方向推进的弧线。 */
107
+ export interface DirectionalPulseOptions extends BaseEffectOptions {
108
+ /** 最大脉冲半径,单位米。 */
109
+ radius: number;
110
+ /** 中心方向角,0 表示正北。 */
111
+ direction?: number;
112
+ /** 扇形展开角度。 */
113
+ spread?: number;
114
+ /** 主颜色。 */
115
+ color?: string;
116
+ /** 线透明度。 */
117
+ opacity?: number;
118
+ /** 线宽。 */
119
+ lineWidth?: number;
120
+ /** 同屏弧线数量。 */
121
+ lineCount?: number;
122
+ /** 弧线间距,单位米。 */
123
+ lineSpacing?: number;
124
+ /** 推进速度,单位米/秒;不传时静止。 */
125
+ speed?: number;
126
+ /** 内侧起始半径,单位米。 */
127
+ innerRadius?: number;
128
+ }
129
+ /** 雷达扫描:距离环、十字线、距离文字和旋转扫描尾迹。 */
130
+ export interface RadarSweepOptions extends BaseEffectOptions {
131
+ /** 雷达半径,单位米。 */
132
+ radius: number;
133
+ /** 扫描主色。 */
134
+ color?: string;
135
+ /** 扫描面默认透明度。 */
136
+ opacity?: number;
137
+ /** 单个扫描扇形角度。 */
138
+ sweepAngle?: number;
139
+ /** 初始扫描起始角度。 */
140
+ sweepStartAngle?: number;
141
+ /** 旋转速度,单位度/秒。 */
142
+ rotationSpeed?: number;
143
+ /** 距离环数量。 */
144
+ ringCount?: number;
145
+ /** 距离环颜色。 */
146
+ ringColor?: string;
147
+ /** 距离环透明度。 */
148
+ ringOpacity?: number;
149
+ /** 距离环线宽。 */
150
+ ringWidth?: number;
151
+ /** 尾部透明度(渐变模式控制扫描起始边透明度)。 */
152
+ tailOpacity?: number;
153
+ /** 头部透明度(渐变模式控制扫描结束边透明度)。 */
154
+ headOpacity?: number;
155
+ /** 是否显示十字线。 */
156
+ showCrosshair?: boolean;
157
+ /** 十字线颜色。 */
158
+ crosshairColor?: string;
159
+ /** 十字线透明度。 */
160
+ crosshairOpacity?: number;
161
+ /** 十字线宽度。 */
162
+ crosshairWidth?: number;
163
+ /** 中心核心半径,单位米。 */
164
+ coreRadius?: number;
165
+ /** 中心核心颜色。 */
166
+ coreColor?: string;
167
+ /** 是否显示距离文字。 */
168
+ showDistanceLabels?: boolean;
169
+ /** 距离文字颜色。 */
170
+ distanceLabelColor?: string;
171
+ /** 距离文字 halo 颜色。 */
172
+ distanceLabelHaloColor?: string;
173
+ /** 距离文字透明度。 */
174
+ distanceLabelOpacity?: number;
175
+ /** 距离文字字号。 */
176
+ distanceLabelSize?: number;
177
+ /** 自定义距离文字格式化。 */
178
+ distanceLabelFormatter?: (distance: number, index: number) => string;
179
+ /** 径向渐变配置;colors 至少两个颜色时启用 Canvas 渐变渲染扫描区域。 */
180
+ gradient?: SectorScanGradientOptions;
181
+ }
182
+ /** 防御圆:静态地理圆,内部淡色填充经径向渐变过渡到边缘光晕,最外层叠加实心边框线,适合标识设备覆盖范围或防御区域。 */
183
+ export interface DefenceCircleOptions extends BaseEffectOptions {
184
+ /** 防御半径,单位米。 */
185
+ radius: number;
186
+ /** 主颜色。fillColor 和 borderColor 不传时默认跟随此值。 */
187
+ color?: string;
188
+ /** 内部填充色,不传时跟随 color。 */
189
+ fillColor?: string;
190
+ /** 内部填充透明度(渐变起始值)。 */
191
+ fillOpacity?: number;
192
+ /** 边框颜色,不传时跟随 color。 */
193
+ borderColor?: string;
194
+ /** 边框线宽,单位像素。 */
195
+ borderWidth?: number;
196
+ /** 边框线透明度(最外层实心边框)。 */
197
+ borderOpacity?: number;
198
+ }
199
+ /** 目标锁定:固定像素尺寸的四角锁定框和中心准星,适合跟随移动目标。 */
200
+ export interface TargetLockOptions extends BaseEffectOptions {
201
+ /** 锁定框颜色。 */
202
+ color?: string;
203
+ /** 锁定框尺寸,单位像素。 */
204
+ size?: number;
205
+ /** 线宽,单位像素。 */
206
+ lineWidth?: number;
207
+ /** 四角线段长度,单位像素。 */
208
+ cornerLength?: number;
209
+ /** 是否显示中心准星,默认 true。 */
210
+ showCrosshair?: boolean;
211
+ /** 中心准星单侧长度,单位像素。 */
212
+ crosshairLength?: number;
213
+ /** 准星与中心点之间的留白,单位像素。 */
214
+ crosshairGap?: number;
215
+ /** 是否旋转锁定框,默认 true。 */
216
+ rotate?: boolean;
217
+ /** 旋转一周时长,单位毫秒。 */
218
+ rotationDuration?: number;
219
+ /** 整体透明度。 */
220
+ opacity?: number;
221
+ }
222
+ /** 定向反制光束:由设备指向目标的收窄能量通道、粒子流和目标震荡环。 */
223
+ export interface CountermeasureBeamOptions extends BaseEffectOptions {
224
+ /** 反制目标经纬度。 */
225
+ target: LngLatTuple;
226
+ /** 反制模式。驱离时震荡环向外扩散,迫降时向目标收缩。 */
227
+ mode?: "expulsion" | "forcedLanding";
228
+ /** 主颜色。 */
229
+ color?: string;
230
+ /** 能量通道填充颜色,默认跟随 color。 */
231
+ channelColor?: string;
232
+ /** 能量通道透明度。 */
233
+ channelOpacity?: number;
234
+ /** 设备端通道宽度,单位米。 */
235
+ sourceWidth?: number;
236
+ /** 目标端通道宽度,单位米。 */
237
+ targetWidth?: number;
238
+ /** 中心束线颜色,默认使用偏亮的紫红色。 */
239
+ lineColor?: string;
240
+ /** 中心束线宽度,单位像素。 */
241
+ lineWidth?: number;
242
+ /** 中心束线透明度。 */
243
+ lineOpacity?: number;
244
+ /** 推进粒子颜色,默认跟随 lineColor。 */
245
+ particleColor?: string;
246
+ /** 同时显示的推进粒子数量;设为 0 可关闭。 */
247
+ particleCount?: number;
248
+ /** 粒子基础半径,单位像素。 */
249
+ particleRadius?: number;
250
+ /** 粒子从设备移动到目标所需时间,单位毫秒。 */
251
+ particleDuration?: number;
252
+ /** 是否显示目标端震荡环。 */
253
+ targetRipple?: boolean;
254
+ /** 目标端震荡环最大半径,单位米。 */
255
+ targetRippleRadius?: number;
256
+ /** 同时显示的震荡环数量。 */
257
+ targetRippleCount?: number;
258
+ /** 单轮震荡时长,单位毫秒。 */
259
+ targetRippleDuration?: number;
260
+ /** 震荡环线宽,单位像素。 */
261
+ targetRippleWidth?: number;
262
+ }
263
+ export type CoordinationLinkType = "detection" | "command" | "countermeasure";
264
+ export interface CoordinationLink {
265
+ /** 链路起点。 */
266
+ from: LngLatTuple;
267
+ /** 链路终点。 */
268
+ to: LngLatTuple;
269
+ /** 探测、指挥或反制链路。 */
270
+ type: CoordinationLinkType;
271
+ /** 覆盖该链路的默认颜色。 */
272
+ color?: string;
273
+ }
274
+ /** 多设备协同反制:展示探测、指挥和反制链路及其数据流向。 */
275
+ export interface CoordinatedCountermeasureOptions extends BaseEffectOptions {
276
+ /** 协同链路集合。center 表示当前处置目标位置。 */
277
+ links: CoordinationLink[];
278
+ /** 链路线宽,单位像素。 */
279
+ lineWidth?: number;
280
+ /** 链路透明度。 */
281
+ lineOpacity?: number;
282
+ /** 每条链路同时显示的流动粒子数量。 */
283
+ particleCount?: number;
284
+ /** 流动粒子半径,单位像素。 */
285
+ particleRadius?: number;
286
+ /** 粒子走完整条链路的时长,单位毫秒。 */
287
+ particleDuration?: number;
288
+ /** 是否显示链路端点。 */
289
+ showNodes?: boolean;
290
+ /** 链路端点半径,单位像素。 */
291
+ nodeRadius?: number;
292
+ /** 是否显示目标协同状态环。 */
293
+ targetRipple?: boolean;
294
+ /** 目标状态环最大半径,单位米。 */
295
+ targetRippleRadius?: number;
296
+ /** 目标状态环动画时长,单位毫秒。 */
297
+ targetRippleDuration?: number;
298
+ }
299
+ /** 导航诱骗:展示目标真实位置到诱导位置的偏移关系和诱导流向。 */
300
+ export interface NavigationSpoofingOptions extends BaseEffectOptions {
301
+ /** 后端或业务算法给出的诱导位置。center 表示目标真实位置。 */
302
+ spoofedPosition: LngLatTuple;
303
+ /** 主颜色。 */
304
+ color?: string;
305
+ /** 偏移虚线颜色,默认跟随 color。 */
306
+ lineColor?: string;
307
+ /** 偏移虚线宽度,单位像素。 */
308
+ lineWidth?: number;
309
+ /** 偏移虚线透明度。 */
310
+ lineOpacity?: number;
311
+ /** 诱导方向流动粒子数量。 */
312
+ particleCount?: number;
313
+ /** 粒子半径,单位像素。 */
314
+ particleRadius?: number;
315
+ /** 粒子从真实位置移动到诱导位置的时长,单位毫秒。 */
316
+ particleDuration?: number;
317
+ /** 是否显示真实位置点。 */
318
+ showTruePosition?: boolean;
319
+ /** 是否显示诱导位置虚影。 */
320
+ showSpoofedPosition?: boolean;
321
+ /** 诱导位置虚影半径,单位像素。 */
322
+ ghostRadius?: number;
323
+ /** 诱导位置虚影透明度。 */
324
+ ghostOpacity?: number;
325
+ /** 是否显示诱导位置脉冲环。 */
326
+ ripple?: boolean;
327
+ /** 诱导位置脉冲环最大半径,单位米。 */
328
+ rippleRadius?: number;
329
+ /** 同时显示的脉冲环数量。 */
330
+ rippleCount?: number;
331
+ /** 单轮脉冲动画时长,单位毫秒。 */
332
+ rippleDuration?: number;
333
+ }
@@ -0,0 +1,15 @@
1
+ export type RgbColor = [number, number, number];
2
+ export declare const clamp: (value: number, min: number, max: number) => number;
3
+ export declare const parseColor: (color: string) => RgbColor | undefined;
4
+ export declare const normalizeCanvasAngle: (angle: number) => number;
5
+ /** Canvas arc 使用数学角度,这里把方位角转换成顺时针扫过角度。 */
6
+ export declare const getClockwiseSweep: (startAngle: number, endAngle: number) => number;
7
+ export declare const getCanvasArcAngle: (bearing: number) => number;
8
+ /** 将 #hex/rgb 颜色和透明度合成 rgba;解析不了时原样返回。 */
9
+ export declare const toRgbaColor: (color: string, opacity: number) => string;
10
+ /** 二次缓出函数,让颜色过渡前快后慢更自然。 */
11
+ export declare const easeOutQuad: (t: number) => number;
12
+ /** 在两个 rgb 颜色之间线性插值。 */
13
+ export declare const lerpRgb: (a: RgbColor, b: RgbColor, t: number) => RgbColor;
14
+ /** 在颜色数组中按浮点索引做纯色插值,返回 "rgb(r,g,b)" 格式。 */
15
+ export declare const lerpColorArray: (colors: string[], t: number) => string;