@bitalltech-maplibre/core 1.0.4 → 1.0.5
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/README.md +340 -297
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +268 -0
- package/dist/index.umd.js +1 -1
- package/dist/types/__tests__/radar-power-group.test.d.ts +1 -0
- package/dist/types/effects/index.d.ts +2 -0
- package/dist/types/effects/radar-power-group.d.ts +89 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,297 +1,340 @@
|
|
|
1
|
-
# @bitalltech-maplibre/core
|
|
2
|
-
|
|
3
|
-
BitAllTech MapLibre 核心工具包,封装地图初始化、内置底图和低空可视化特效。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @bitalltech-maplibre/core maplibre-gl
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## 基础使用
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import {
|
|
15
|
-
createMap,
|
|
16
|
-
maplibregl,
|
|
17
|
-
setMaplibreToolsConfig,
|
|
18
|
-
} from "@bitalltech-maplibre/core";
|
|
19
|
-
import "maplibre-gl/dist/maplibre-gl.css";
|
|
20
|
-
|
|
21
|
-
setMaplibreToolsConfig({
|
|
22
|
-
tdtToken: "你的天地图 token",
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const map = createMap({
|
|
26
|
-
container: "map",
|
|
27
|
-
center: [116.39, 39.91],
|
|
28
|
-
zoom: 10.5,
|
|
29
|
-
style: "openfreemap-liberty",
|
|
30
|
-
attributionControl: false,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
map.addControl(new maplibregl.NavigationControl(), "top-right");
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## 地图初始化
|
|
37
|
-
|
|
38
|
-
`createMap(options)` 是 `new maplibregl.Map()` 的轻量封装,额外支持内置底图类型:
|
|
39
|
-
|
|
40
|
-
- `openfreemap-liberty`
|
|
41
|
-
- `openfreemap-bright`
|
|
42
|
-
- `openfreemap-positron`
|
|
43
|
-
- `openfreemap-dark`
|
|
44
|
-
- `openfreemap-fiord`
|
|
45
|
-
- `tdt-image`
|
|
46
|
-
- `tdt-image-label`
|
|
47
|
-
|
|
48
|
-
如果 `style` 传入普通 URL 或完整 `StyleSpecification`,会原样交给 MapLibre。
|
|
49
|
-
|
|
50
|
-
## 底图
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { setBaseMap } from "@bitalltech-maplibre/core";
|
|
54
|
-
|
|
55
|
-
setBaseMap(map, "tdt-image-label", {
|
|
56
|
-
token: "你的天地图 token",
|
|
57
|
-
diff: false,
|
|
58
|
-
});
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
天地图 token 可以通过单次调用传入,也可以通过 `setMaplibreToolsConfig({ tdtToken })` 设置全局默认值。
|
|
62
|
-
|
|
63
|
-
## 低空特效
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import {
|
|
67
|
-
addBreathingCircle,
|
|
68
|
-
addRadarSweep,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
- `
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
1
|
+
# @bitalltech-maplibre/core
|
|
2
|
+
|
|
3
|
+
BitAllTech MapLibre 核心工具包,封装地图初始化、内置底图和低空可视化特效。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bitalltech-maplibre/core maplibre-gl
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 基础使用
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
createMap,
|
|
16
|
+
maplibregl,
|
|
17
|
+
setMaplibreToolsConfig,
|
|
18
|
+
} from "@bitalltech-maplibre/core";
|
|
19
|
+
import "maplibre-gl/dist/maplibre-gl.css";
|
|
20
|
+
|
|
21
|
+
setMaplibreToolsConfig({
|
|
22
|
+
tdtToken: "你的天地图 token",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const map = createMap({
|
|
26
|
+
container: "map",
|
|
27
|
+
center: [116.39, 39.91],
|
|
28
|
+
zoom: 10.5,
|
|
29
|
+
style: "openfreemap-liberty",
|
|
30
|
+
attributionControl: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
map.addControl(new maplibregl.NavigationControl(), "top-right");
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 地图初始化
|
|
37
|
+
|
|
38
|
+
`createMap(options)` 是 `new maplibregl.Map()` 的轻量封装,额外支持内置底图类型:
|
|
39
|
+
|
|
40
|
+
- `openfreemap-liberty`
|
|
41
|
+
- `openfreemap-bright`
|
|
42
|
+
- `openfreemap-positron`
|
|
43
|
+
- `openfreemap-dark`
|
|
44
|
+
- `openfreemap-fiord`
|
|
45
|
+
- `tdt-image`
|
|
46
|
+
- `tdt-image-label`
|
|
47
|
+
|
|
48
|
+
如果 `style` 传入普通 URL 或完整 `StyleSpecification`,会原样交给 MapLibre。
|
|
49
|
+
|
|
50
|
+
## 底图
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { setBaseMap } from "@bitalltech-maplibre/core";
|
|
54
|
+
|
|
55
|
+
setBaseMap(map, "tdt-image-label", {
|
|
56
|
+
token: "你的天地图 token",
|
|
57
|
+
diff: false,
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
天地图 token 可以通过单次调用传入,也可以通过 `setMaplibreToolsConfig({ tdtToken })` 设置全局默认值。
|
|
62
|
+
|
|
63
|
+
## 低空特效
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import {
|
|
67
|
+
addBreathingCircle,
|
|
68
|
+
addRadarSweep,
|
|
69
|
+
addRadarPowerGroup,
|
|
70
|
+
addPulseMarker,
|
|
71
|
+
addTargetLock,
|
|
72
|
+
addCountermeasureBeam,
|
|
73
|
+
} from "@bitalltech-maplibre/core";
|
|
74
|
+
|
|
75
|
+
const radar = addRadarSweep(map, {
|
|
76
|
+
id: "radar",
|
|
77
|
+
center: [116.39, 39.91],
|
|
78
|
+
radius: 3000,
|
|
79
|
+
color: "#22c55e",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const pulse = addPulseMarker(map, {
|
|
83
|
+
id: "event-pulse",
|
|
84
|
+
center: [116.41, 39.92],
|
|
85
|
+
color: "#ef4444",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const breathing = addBreathingCircle(map, {
|
|
89
|
+
id: "target-breathing",
|
|
90
|
+
center: [116.405, 39.915],
|
|
91
|
+
radius: 90,
|
|
92
|
+
color: "#1677ff",
|
|
93
|
+
duration: 1800,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const lock = addTargetLock(map, {
|
|
97
|
+
id: "target-lock",
|
|
98
|
+
center: [116.4, 39.918],
|
|
99
|
+
color: "#ff3b30",
|
|
100
|
+
size: 76,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const beam = addCountermeasureBeam(map, {
|
|
104
|
+
id: "countermeasure-beam",
|
|
105
|
+
center: [116.386, 39.906],
|
|
106
|
+
target: [116.399, 39.912],
|
|
107
|
+
mode: "expulsion",
|
|
108
|
+
color: "#a855f7",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
radar.update({ radius: 5000 });
|
|
112
|
+
pulse.hide();
|
|
113
|
+
breathing.show();
|
|
114
|
+
lock.update({ center: [116.402, 39.919] });
|
|
115
|
+
radar.remove();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 批量雷达威力图
|
|
119
|
+
|
|
120
|
+
多个雷达威力图可以共用一个 GeoJSON source 和一组固定图层。调用时会先创建空 source/layer;如果不传 `radars`,也可以在接口数据返回后再调用 `setData`。
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { addRadarPowerGroup } from "@bitalltech-maplibre/core";
|
|
124
|
+
|
|
125
|
+
map.on("load", () => {
|
|
126
|
+
const radarPower = addRadarPowerGroup(map, {
|
|
127
|
+
id: "radar-power",
|
|
128
|
+
// 可选:插入到指定图层之前;layerIds 会按 fill、core、ring、crosshair、labels 顺序创建。
|
|
129
|
+
beforeId: "target-layer",
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// 数据返回后只更新共享 source,不重新创建图层,因此图层顺序保持不变。
|
|
133
|
+
radarPower.setData([
|
|
134
|
+
{
|
|
135
|
+
id: "radar-west",
|
|
136
|
+
center: [116.382, 39.903],
|
|
137
|
+
radius: 4000,
|
|
138
|
+
color: "#22c55e",
|
|
139
|
+
ringCount: 4,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: "radar-east",
|
|
143
|
+
center: [116.42, 39.915],
|
|
144
|
+
radius: 3000,
|
|
145
|
+
color: "#38bdf8",
|
|
146
|
+
visible: true,
|
|
147
|
+
},
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
radarPower.setRadarVisible("radar-east", false);
|
|
151
|
+
radarPower.updateRadar("radar-west", { radius: 5000 });
|
|
152
|
+
|
|
153
|
+
// 不再使用时一次性清理整组 source/layer。
|
|
154
|
+
// radarPower.remove();
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`radarPower.sourceId` 是共享 GeoJSON source,`radarPower.layerIds` 是按绘制顺序排列的固定图层 id。插件只保证威力图组内部顺序;雷达组与目标、轨迹、测距等其他业务组之间的顺序,建议由业务侧统一图层管理器安排。
|
|
159
|
+
扇形扫描支持从圆心到外缘的径向渐变:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
addSectorScan(map, {
|
|
163
|
+
id: "sector",
|
|
164
|
+
center: [116.39, 39.91],
|
|
165
|
+
radius: 1600,
|
|
166
|
+
startAngle: 215,
|
|
167
|
+
endAngle: 282,
|
|
168
|
+
outlineColor: "#22c55e",
|
|
169
|
+
gradient: {
|
|
170
|
+
colors: ["#f97316", "#facc15", "#22c55e"],
|
|
171
|
+
steps: 64,
|
|
172
|
+
centerOpacity: 0.08,
|
|
173
|
+
edgeOpacity: 0.34,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
当前提供:
|
|
179
|
+
|
|
180
|
+
- `addBreathingCircle`
|
|
181
|
+
- `addPulseMarker`
|
|
182
|
+
- `addRingPulseMarker`
|
|
183
|
+
- `addSectorScan`
|
|
184
|
+
- `addDirectionalPulse`
|
|
185
|
+
- `addRadarSweep`
|
|
186
|
+
- `addRadarPowerGroup`
|
|
187
|
+
- `addDefenceCircle`
|
|
188
|
+
- `addTargetLock`
|
|
189
|
+
- `addCountermeasureBeam`
|
|
190
|
+
- `addCoordinatedCountermeasure`
|
|
191
|
+
- `addNavigationSpoofing`
|
|
192
|
+
- `addBreachAlert`
|
|
193
|
+
|
|
194
|
+
这些方法都会返回控制器,支持 `update()`、`show()`、`hide()` 和 `remove()`。其中 `addBreachAlert` 额外提供 `trigger(point)`、`reset()` 和 `isActive()`:trigger 开始持续预警,reset 停止,开始与结束都由业务层决定。
|
|
195
|
+
|
|
196
|
+
### 电子围栏渲染
|
|
197
|
+
|
|
198
|
+
电子围栏提供两个互不依赖的渲染器,由业务在创建时明确选择:
|
|
199
|
+
|
|
200
|
+
- `addStandardElectronicFenceLayer`:使用一个 GeoJSON Source 和固定数量的 MapLibre 内置图层,适合几十到上百个围栏。
|
|
201
|
+
- `addWebGLElectronicFenceLayer`:使用一个原生 WebGL 3D CustomLayer 绘制透明围栏、白色流动虚线或实线,以及与围栏同色的多层柔和泛光,适合少量重点围栏;首版支持 Mercator 投影。
|
|
202
|
+
|
|
203
|
+
两者共用 `ElectronicFenceFeature` 和 `ElectronicFenceController`,均不依赖编辑插件。围栏必须是带稳定字符串 `id` 的 GeoJSON Polygon;矩形和圆形应先转换成 Polygon。`properties` 仅作为业务数据保存和回传,插件不会读取其中字段覆盖高度、样式或状态。
|
|
204
|
+
|
|
205
|
+
`defaults.thickness` 可省略,默认使用 `1` 米;显式传入时必须大于 `0`。
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import {
|
|
209
|
+
addStandardElectronicFenceLayer,
|
|
210
|
+
addWebGLElectronicFenceLayer,
|
|
211
|
+
type ElectronicFenceFeatureCollection,
|
|
212
|
+
} from "@bitalltech-maplibre/core";
|
|
213
|
+
|
|
214
|
+
const data: ElectronicFenceFeatureCollection = {
|
|
215
|
+
type: "FeatureCollection",
|
|
216
|
+
features: [
|
|
217
|
+
{
|
|
218
|
+
type: "Feature",
|
|
219
|
+
id: "fence-01",
|
|
220
|
+
geometry: {
|
|
221
|
+
type: "Polygon",
|
|
222
|
+
coordinates: [[
|
|
223
|
+
[116.386, 39.905],
|
|
224
|
+
[116.396, 39.905],
|
|
225
|
+
[116.396, 39.912],
|
|
226
|
+
[116.386, 39.912],
|
|
227
|
+
[116.386, 39.905],
|
|
228
|
+
]],
|
|
229
|
+
},
|
|
230
|
+
properties: {
|
|
231
|
+
name: "核心防区",
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const standardFence = addStandardElectronicFenceLayer(map, {
|
|
238
|
+
id: "standard-fence",
|
|
239
|
+
defaults: {
|
|
240
|
+
baseHeight: 0,
|
|
241
|
+
height: 130,
|
|
242
|
+
thickness: 18,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
standardFence.setData(data);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
WebGL 版本使用相同数据和控制器 API:
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
const webglFence = addWebGLElectronicFenceLayer(map, {
|
|
253
|
+
id: "webgl-fence",
|
|
254
|
+
defaults: {
|
|
255
|
+
baseHeight: 0,
|
|
256
|
+
height: 150,
|
|
257
|
+
thickness: 22,
|
|
258
|
+
},
|
|
259
|
+
styles: {
|
|
260
|
+
normal: {
|
|
261
|
+
color: "#c084fc",
|
|
262
|
+
opacity: 0.18,
|
|
263
|
+
glowStrength: 1,
|
|
264
|
+
flowColor: "#ffffff",
|
|
265
|
+
flowCount: 3,
|
|
266
|
+
flowLineStyle: "dashed",
|
|
267
|
+
flowWidth: 0.18,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
animation: {
|
|
271
|
+
enabled: true,
|
|
272
|
+
fps: 30,
|
|
273
|
+
speed: 0.35,
|
|
274
|
+
scope: "all",
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
webglFence.setData(data);
|
|
279
|
+
webglFence.setFeatureState("fence-01", "alarm");
|
|
280
|
+
webglFence.setFeatureActive("fence-01", true);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
公共控制器方法:
|
|
284
|
+
|
|
285
|
+
- `setData(data)`:全量替换,清除 renderer state、active 和 hidden 状态。
|
|
286
|
+
- `add(feature)`:严格新增,重复 id 抛错。
|
|
287
|
+
- `update(id, patch)`:严格更新业务 Feature,不读取 properties 控制渲染。
|
|
288
|
+
- `removeFeature(id)`:严格删除单围栏。
|
|
289
|
+
- `clear()`:清空数据但保留插件。
|
|
290
|
+
- `setFeatureState(id, state)`:显式设置 normal、warning、alarm 或 disabled 渲染状态。
|
|
291
|
+
- `setFeatureActive(id, active)`:设置临时高亮,不修改业务 Feature。
|
|
292
|
+
- `setFeatureVisible(id, visible)`:临时控制单围栏显隐。
|
|
293
|
+
- `show()`、`hide()`:控制整个插件显隐;WebGL 版隐藏时暂停动画。
|
|
294
|
+
- `destroy()`:释放 Source、Layer、事件和 WebGL 资源。
|
|
295
|
+
|
|
296
|
+
当 `interactive` 未设为 `false` 时,两种渲染器都会通过地图触发 `fence.click`、`fence.mouseenter` 和 `fence.mouseleave`,事件载荷包含 `instanceId`、`renderer`、`id`、`feature` 和 `originalEvent`。
|
|
297
|
+
|
|
298
|
+
### 围栏闯入预警
|
|
299
|
+
|
|
300
|
+
`addBreachAlert` 用于无人机闯入电子围栏时的复合预警,三段叠加且各自独立开关。trigger 后三段持续播放,直到业务层调用 reset() 才停止:
|
|
301
|
+
|
|
302
|
+
- 围栏高频闪烁:接触瞬间围栏由正常色(蓝/绿)切到高频闪烁警报红
|
|
303
|
+
- 接触点涟漪扩散:以接触点为中心持续向外扩散红色涟漪
|
|
304
|
+
- 战术框闪烁:全屏或局部 DOM 边框高频闪烁
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
import { addBreachAlert, createFenceCircle } from "@bitalltech-maplibre/core";
|
|
308
|
+
|
|
309
|
+
// fence 支持直接传入 edit 插件 getAll() 的 FeatureCollection,
|
|
310
|
+
// 或单个 Polygon / MultiPolygon / Feature;圆形用 createFenceCircle 构造。
|
|
311
|
+
const fence = createFenceCircle([116.39, 39.91], 1000);
|
|
312
|
+
|
|
313
|
+
const alert = addBreachAlert(map, {
|
|
314
|
+
id: "breach-zone",
|
|
315
|
+
center: [116.39, 39.91],
|
|
316
|
+
fence, // 围栏几何
|
|
317
|
+
fenceColor: "#1677ff", // 正常态蓝
|
|
318
|
+
fenceAlertColor: "#ff3b30", // 警报红
|
|
319
|
+
fenceFlash: true, // 围栏闪烁:开
|
|
320
|
+
ripple: true, // 涟漪:开
|
|
321
|
+
tacticalFlash: false, // 战术框:关
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// 业务层判定闯入后触发(几何判定与目标分类归业务层)
|
|
325
|
+
detector.on("breach", ({ point }) => {
|
|
326
|
+
alert.trigger(point);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
alert.reset(); // 业务层判定解警后停止
|
|
330
|
+
alert.remove(); // 销毁(连 DOM 一起清理)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
> 插件只负责视觉表现,不判定「是否闯入」「目标是否黑飞/未知」,也不决定警报持续多久——这些都由业务层完成,插件只暴露 trigger 与 reset。
|
|
334
|
+
|
|
335
|
+
## 常用导出
|
|
336
|
+
|
|
337
|
+
- `createMap`、`maplibregl`
|
|
338
|
+
- `setMaplibreToolsConfig`、`getMaplibreToolsConfig`
|
|
339
|
+
- `getBaseMapStyle`、`setBaseMap`
|
|
340
|
+
- 低空特效方法和对应类型
|