@bitalltech-maplibre/core 1.0.0 → 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.
- package/README.md +183 -6
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +3021 -139
- package/dist/index.umd.js +1 -1
- package/dist/types/basemaps/index.d.ts +5 -1
- package/dist/types/basemaps/tianditu.d.ts +7 -4
- package/dist/types/effects/electronic-fence-common.d.ts +76 -0
- package/dist/types/effects/electronic-fence-types.d.ts +131 -0
- package/dist/types/effects/geometry.d.ts +2 -0
- package/dist/types/effects/index.d.ts +5 -2
- package/dist/types/effects/low-altitude/breach-alert.d.ts +61 -0
- package/dist/types/effects/low-altitude/breathing-circle.d.ts +5 -0
- package/dist/types/effects/low-altitude/coordinated-countermeasure.d.ts +5 -0
- package/dist/types/effects/low-altitude/countermeasure-beam.d.ts +5 -0
- package/dist/types/effects/low-altitude/defence-circle.d.ts +5 -0
- package/dist/types/effects/low-altitude/directional-pulse.d.ts +6 -0
- package/dist/types/effects/low-altitude/navigation-spoofing.d.ts +6 -0
- package/dist/types/effects/low-altitude/pulse-marker.d.ts +5 -0
- package/dist/types/effects/low-altitude/radar-sweep.d.ts +5 -0
- package/dist/types/effects/low-altitude/ring-pulse-marker.d.ts +5 -0
- package/dist/types/effects/low-altitude/sector-scan.d.ts +5 -0
- package/dist/types/effects/low-altitude/shared.d.ts +67 -0
- package/dist/types/effects/low-altitude/target-lock.d.ts +4 -0
- package/dist/types/effects/low-altitude/types.d.ts +333 -0
- package/dist/types/effects/low-altitude/visual.d.ts +15 -0
- package/dist/types/effects/low-altitude.d.ts +15 -126
- package/dist/types/effects/standard-electronic-fence.d.ts +7 -0
- package/dist/types/effects/webgl-electronic-fence.d.ts +7 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/map/create-map.d.ts +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# bitalltech-maplibre
|
|
1
|
+
# @bitalltech-maplibre/core
|
|
2
2
|
|
|
3
3
|
BitAllTech MapLibre 核心工具包,封装地图初始化、内置底图和低空可视化特效。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install bitalltech-maplibre
|
|
8
|
+
npm install @bitalltech-maplibre/core maplibre-gl
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## 基础使用
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
createMap,
|
|
16
16
|
maplibregl,
|
|
17
17
|
setMaplibreToolsConfig,
|
|
18
|
-
} from "bitalltech-maplibre
|
|
18
|
+
} from "@bitalltech-maplibre/core";
|
|
19
19
|
import "maplibre-gl/dist/maplibre-gl.css";
|
|
20
20
|
|
|
21
21
|
setMaplibreToolsConfig({
|
|
@@ -50,7 +50,7 @@ map.addControl(new maplibregl.NavigationControl(), "top-right");
|
|
|
50
50
|
## 底图
|
|
51
51
|
|
|
52
52
|
```ts
|
|
53
|
-
import { setBaseMap } from "bitalltech-maplibre
|
|
53
|
+
import { setBaseMap } from "@bitalltech-maplibre/core";
|
|
54
54
|
|
|
55
55
|
setBaseMap(map, "tdt-image-label", {
|
|
56
56
|
token: "你的天地图 token",
|
|
@@ -63,7 +63,13 @@ setBaseMap(map, "tdt-image-label", {
|
|
|
63
63
|
## 低空特效
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
addBreathingCircle,
|
|
68
|
+
addRadarSweep,
|
|
69
|
+
addPulseMarker,
|
|
70
|
+
addTargetLock,
|
|
71
|
+
addCountermeasureBeam,
|
|
72
|
+
} from "@bitalltech-maplibre/core";
|
|
67
73
|
|
|
68
74
|
const radar = addRadarSweep(map, {
|
|
69
75
|
id: "radar",
|
|
@@ -78,8 +84,33 @@ const pulse = addPulseMarker(map, {
|
|
|
78
84
|
color: "#ef4444",
|
|
79
85
|
});
|
|
80
86
|
|
|
87
|
+
const breathing = addBreathingCircle(map, {
|
|
88
|
+
id: "target-breathing",
|
|
89
|
+
center: [116.405, 39.915],
|
|
90
|
+
radius: 90,
|
|
91
|
+
color: "#1677ff",
|
|
92
|
+
duration: 1800,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const lock = addTargetLock(map, {
|
|
96
|
+
id: "target-lock",
|
|
97
|
+
center: [116.4, 39.918],
|
|
98
|
+
color: "#ff3b30",
|
|
99
|
+
size: 76,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const beam = addCountermeasureBeam(map, {
|
|
103
|
+
id: "countermeasure-beam",
|
|
104
|
+
center: [116.386, 39.906],
|
|
105
|
+
target: [116.399, 39.912],
|
|
106
|
+
mode: "expulsion",
|
|
107
|
+
color: "#a855f7",
|
|
108
|
+
});
|
|
109
|
+
|
|
81
110
|
radar.update({ radius: 5000 });
|
|
82
111
|
pulse.hide();
|
|
112
|
+
breathing.show();
|
|
113
|
+
lock.update({ center: [116.402, 39.919] });
|
|
83
114
|
radar.remove();
|
|
84
115
|
```
|
|
85
116
|
|
|
@@ -104,13 +135,159 @@ addSectorScan(map, {
|
|
|
104
135
|
|
|
105
136
|
当前提供:
|
|
106
137
|
|
|
138
|
+
- `addBreathingCircle`
|
|
107
139
|
- `addPulseMarker`
|
|
108
140
|
- `addRingPulseMarker`
|
|
109
141
|
- `addSectorScan`
|
|
110
142
|
- `addDirectionalPulse`
|
|
111
143
|
- `addRadarSweep`
|
|
144
|
+
- `addDefenceCircle`
|
|
145
|
+
- `addTargetLock`
|
|
146
|
+
- `addCountermeasureBeam`
|
|
147
|
+
- `addCoordinatedCountermeasure`
|
|
148
|
+
- `addNavigationSpoofing`
|
|
149
|
+
- `addBreachAlert`
|
|
150
|
+
|
|
151
|
+
这些方法都会返回控制器,支持 `update()`、`show()`、`hide()` 和 `remove()`。其中 `addBreachAlert` 额外提供 `trigger(point)`、`reset()` 和 `isActive()`:trigger 开始持续预警,reset 停止,开始与结束都由业务层决定。
|
|
152
|
+
|
|
153
|
+
### 电子围栏渲染
|
|
154
|
+
|
|
155
|
+
电子围栏提供两个互不依赖的渲染器,由业务在创建时明确选择:
|
|
156
|
+
|
|
157
|
+
- `addStandardElectronicFenceLayer`:使用一个 GeoJSON Source 和固定数量的 MapLibre 内置图层,适合几十到上百个围栏。
|
|
158
|
+
- `addWebGLElectronicFenceLayer`:使用一个原生 WebGL 3D CustomLayer 绘制透明围栏、白色流动虚线或实线,以及与围栏同色的多层柔和泛光,适合少量重点围栏;首版支持 Mercator 投影。
|
|
159
|
+
|
|
160
|
+
两者共用 `ElectronicFenceFeature` 和 `ElectronicFenceController`,均不依赖编辑插件。围栏必须是带稳定字符串 `id` 的 GeoJSON Polygon;矩形和圆形应先转换成 Polygon。`properties` 仅作为业务数据保存和回传,插件不会读取其中字段覆盖高度、样式或状态。
|
|
161
|
+
|
|
162
|
+
`defaults.thickness` 可省略,默认使用 `1` 米;显式传入时必须大于 `0`。
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import {
|
|
166
|
+
addStandardElectronicFenceLayer,
|
|
167
|
+
addWebGLElectronicFenceLayer,
|
|
168
|
+
type ElectronicFenceFeatureCollection,
|
|
169
|
+
} from "@bitalltech-maplibre/core";
|
|
170
|
+
|
|
171
|
+
const data: ElectronicFenceFeatureCollection = {
|
|
172
|
+
type: "FeatureCollection",
|
|
173
|
+
features: [
|
|
174
|
+
{
|
|
175
|
+
type: "Feature",
|
|
176
|
+
id: "fence-01",
|
|
177
|
+
geometry: {
|
|
178
|
+
type: "Polygon",
|
|
179
|
+
coordinates: [[
|
|
180
|
+
[116.386, 39.905],
|
|
181
|
+
[116.396, 39.905],
|
|
182
|
+
[116.396, 39.912],
|
|
183
|
+
[116.386, 39.912],
|
|
184
|
+
[116.386, 39.905],
|
|
185
|
+
]],
|
|
186
|
+
},
|
|
187
|
+
properties: {
|
|
188
|
+
name: "核心防区",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const standardFence = addStandardElectronicFenceLayer(map, {
|
|
195
|
+
id: "standard-fence",
|
|
196
|
+
defaults: {
|
|
197
|
+
baseHeight: 0,
|
|
198
|
+
height: 130,
|
|
199
|
+
thickness: 18,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
standardFence.setData(data);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
WebGL 版本使用相同数据和控制器 API:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
const webglFence = addWebGLElectronicFenceLayer(map, {
|
|
210
|
+
id: "webgl-fence",
|
|
211
|
+
defaults: {
|
|
212
|
+
baseHeight: 0,
|
|
213
|
+
height: 150,
|
|
214
|
+
thickness: 22,
|
|
215
|
+
},
|
|
216
|
+
styles: {
|
|
217
|
+
normal: {
|
|
218
|
+
color: "#c084fc",
|
|
219
|
+
opacity: 0.18,
|
|
220
|
+
glowStrength: 1,
|
|
221
|
+
flowColor: "#ffffff",
|
|
222
|
+
flowCount: 3,
|
|
223
|
+
flowLineStyle: "dashed",
|
|
224
|
+
flowWidth: 0.18,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
animation: {
|
|
228
|
+
enabled: true,
|
|
229
|
+
fps: 30,
|
|
230
|
+
speed: 0.35,
|
|
231
|
+
scope: "all",
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
webglFence.setData(data);
|
|
236
|
+
webglFence.setFeatureState("fence-01", "alarm");
|
|
237
|
+
webglFence.setFeatureActive("fence-01", true);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
公共控制器方法:
|
|
241
|
+
|
|
242
|
+
- `setData(data)`:全量替换,清除 renderer state、active 和 hidden 状态。
|
|
243
|
+
- `add(feature)`:严格新增,重复 id 抛错。
|
|
244
|
+
- `update(id, patch)`:严格更新业务 Feature,不读取 properties 控制渲染。
|
|
245
|
+
- `removeFeature(id)`:严格删除单围栏。
|
|
246
|
+
- `clear()`:清空数据但保留插件。
|
|
247
|
+
- `setFeatureState(id, state)`:显式设置 normal、warning、alarm 或 disabled 渲染状态。
|
|
248
|
+
- `setFeatureActive(id, active)`:设置临时高亮,不修改业务 Feature。
|
|
249
|
+
- `setFeatureVisible(id, visible)`:临时控制单围栏显隐。
|
|
250
|
+
- `show()`、`hide()`:控制整个插件显隐;WebGL 版隐藏时暂停动画。
|
|
251
|
+
- `destroy()`:释放 Source、Layer、事件和 WebGL 资源。
|
|
252
|
+
|
|
253
|
+
当 `interactive` 未设为 `false` 时,两种渲染器都会通过地图触发 `fence.click`、`fence.mouseenter` 和 `fence.mouseleave`,事件载荷包含 `instanceId`、`renderer`、`id`、`feature` 和 `originalEvent`。
|
|
254
|
+
|
|
255
|
+
### 围栏闯入预警
|
|
256
|
+
|
|
257
|
+
`addBreachAlert` 用于无人机闯入电子围栏时的复合预警,三段叠加且各自独立开关。trigger 后三段持续播放,直到业务层调用 reset() 才停止:
|
|
258
|
+
|
|
259
|
+
- 围栏高频闪烁:接触瞬间围栏由正常色(蓝/绿)切到高频闪烁警报红
|
|
260
|
+
- 接触点涟漪扩散:以接触点为中心持续向外扩散红色涟漪
|
|
261
|
+
- 战术框闪烁:全屏或局部 DOM 边框高频闪烁
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
import { addBreachAlert, createFenceCircle } from "@bitalltech-maplibre/core";
|
|
265
|
+
|
|
266
|
+
// fence 支持直接传入 edit 插件 getAll() 的 FeatureCollection,
|
|
267
|
+
// 或单个 Polygon / MultiPolygon / Feature;圆形用 createFenceCircle 构造。
|
|
268
|
+
const fence = createFenceCircle([116.39, 39.91], 1000);
|
|
269
|
+
|
|
270
|
+
const alert = addBreachAlert(map, {
|
|
271
|
+
id: "breach-zone",
|
|
272
|
+
center: [116.39, 39.91],
|
|
273
|
+
fence, // 围栏几何
|
|
274
|
+
fenceColor: "#1677ff", // 正常态蓝
|
|
275
|
+
fenceAlertColor: "#ff3b30", // 警报红
|
|
276
|
+
fenceFlash: true, // 围栏闪烁:开
|
|
277
|
+
ripple: true, // 涟漪:开
|
|
278
|
+
tacticalFlash: false, // 战术框:关
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// 业务层判定闯入后触发(几何判定与目标分类归业务层)
|
|
282
|
+
detector.on("breach", ({ point }) => {
|
|
283
|
+
alert.trigger(point);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
alert.reset(); // 业务层判定解警后停止
|
|
287
|
+
alert.remove(); // 销毁(连 DOM 一起清理)
|
|
288
|
+
```
|
|
112
289
|
|
|
113
|
-
|
|
290
|
+
> 插件只负责视觉表现,不判定「是否闯入」「目标是否黑飞/未知」,也不决定警报持续多久——这些都由业务层完成,插件只暴露 trigger 与 reset。
|
|
114
291
|
|
|
115
292
|
## 常用导出
|
|
116
293
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("maplibre-gl"),e={},a=()=>({...e}),r="https://tiles.openfreemap.org/styles",i=(t,e,a)=>({type:t,label:e,style:`${r}/${a}`}),n={"openfreemap-liberty":i("openfreemap-liberty","OpenFreeMap Liberty","liberty"),"openfreemap-bright":i("openfreemap-bright","OpenFreeMap Bright","bright"),"openfreemap-positron":i("openfreemap-positron","OpenFreeMap Positron","positron"),"openfreemap-dark":i("openfreemap-dark","OpenFreeMap Dark","dark"),"openfreemap-fiord":i("openfreemap-fiord","OpenFreeMap Fiord","fiord")},o=Object.keys(n),s=(t="openfreemap-liberty")=>n[t].style,l=["0","1","2","3","4","5","6","7"],c=(t,e)=>{const r=(t=>{const e=t||a().tdtToken;if(!e)throw new Error("Tianditu token is required. Pass token or call setMaplibreToolsConfig({ tdtToken }).");return e})(e);return l.map(e=>`https://t${e}.tianditu.gov.cn/DataServer?T=${t}&x={x}&y={y}&l={z}&tk=${r}`)},p=(t,e={})=>({type:"raster",tiles:c(t,e.token),tileSize:256,minzoom:0,maxzoom:18,attribution:"© 天地图"}),d=(t={})=>{const e=!1!==t.label,a={"tdt-image":p("img_w",t)},r=[{id:"tdt-image",type:"raster",source:"tdt-image"}];return e&&(a["tdt-image-label"]=p("cia_w",t),r.push({id:"tdt-image-label",type:"raster",source:"tdt-image-label"})),{version:8,sources:a,layers:r}},h=[...Object.keys(n),"tdt-image","tdt-image-label"],y=t=>h.includes(t),f=(t="openfreemap-liberty",e={})=>"tdt-image"===t?d({...e,label:!1}):"tdt-image-label"===t?d({...e,label:!0}):s(t),u=t=>t*Math.PI/180,m=t=>180*t/Math.PI,g=t=>(t%360+360)%360,M=(t,e,a)=>{const r=e/6378137,i=u(a),n=u(t[1]),o=u(t[0]),s=Math.asin(Math.sin(n)*Math.cos(r)+Math.cos(n)*Math.sin(r)*Math.cos(i)),l=o+Math.atan2(Math.sin(i)*Math.sin(r)*Math.cos(n),Math.cos(r)-Math.sin(n)*Math.sin(s));return[(c=m(l),c>180?c-360:c<-180?c+360:c),m(s)];var c},b=(t,e,a=64)=>{const r=((t,e)=>{const a=g(e)-g(t);return a<=0?a+360:a})(t,e),i=Math.max(12,Math.ceil(a*r/360));return Array.from({length:i+1},(e,a)=>g(t+r*a/i))},x=(t,e,a=64)=>(t=>{if(0===t.length)return t;const[e,a]=t[0],r=t[t.length-1];return r[0]===e&&r[1]===a?t:[...t,[e,a]]})(Array.from({length:a},(r,i)=>M(t,e,360*i/a))),k=(t,e,a=64)=>({type:"Polygon",coordinates:[x(t,e,a)]}),v=(t,e,a=64)=>({type:"LineString",coordinates:x(t,e,a)}),A=(t,e,a,r,i=64)=>{const n=b(a,r,i).map(a=>M(t,e,a));return{type:"Polygon",coordinates:[[t,...n,t]]}},$=(t,e,a,r,i=64)=>({type:"LineString",coordinates:b(a,r,i).map(a=>M(t,e,a))}),w=(t,e,a)=>({type:"LineString",coordinates:[t,M(t,e,a)]}),F=(t,e)=>({type:"Feature",geometry:t,properties:e}),O=t=>({type:"FeatureCollection",features:t}),q=(t,e,a)=>{const r=a?"visible":"none";e.forEach(e=>{t.getLayer(e)&&t.setLayoutProperty(e,"visibility",r)})},S=(t,e,a)=>{const r=e.id,i=`${r}-source`;let n,o={...e},s=[],l=[i],c=!1,p=!1;const d=()=>{null==n||n(),n=void 0,[...s].reverse().forEach(e=>{((t,e)=>{t.getLayer(e)&&t.removeLayer(e)})(t,e)}),[...l].reverse().forEach(e=>{((t,e)=>{t.getSource(e)&&t.removeSource(e)})(t,e)}),s=[],l=[i]},h=e=>{const a=t.getSource(i);a&&a.setData(e)},y=()=>{var e,r;if(c)return;d();const p=a(o);t.addSource(i,{type:"geojson",data:p.data}),null==(e=p.canvasSources)||e.forEach(e=>{t.addSource(e.id,e.source)}),l=[i,...(null==(r=p.canvasSources)?void 0:r.map(t=>t.id))||[]],s=p.layers.map(t=>t.id),p.layers.forEach(e=>{var a;const r="raster"===e.type&&(null==(a=p.canvasSources)?void 0:a[0])?p.canvasSources[0].id:i;t.addLayer({...e,source:r},o.beforeId)}),q(t,s,!1!==o.visible),p.startAnimation&&(n=p.startAnimation({getOptions:()=>o,setData:h})||void 0)},f=()=>{p&&!c&&t.isStyleLoaded()&&(p=!1,t.off("styledata",f),y())},u=()=>{c||(t.isStyleLoaded()?(p&&(p=!1,t.off("styledata",f)),y()):p||(p=!0,t.on("styledata",f)))};return u(),{id:r,update(t){c||(o={...o,...t,id:r},u())},show(){c||(o={...o,visible:!0},q(t,s,!0))},hide(){c||(o={...o,visible:!1},q(t,s,!1))},remove(){c||(c=!0,p&&(p=!1,t.off("styledata",f)),d())}}},D=(t,e=0)=>{const a=Math.max(10,t.radius??70),r=Math.max(a,t.maxRadius??2.3*a),i=Math.max(1,t.pulseCount??2),n=Math.max(1,t.lineWidth??2),o=t.pulseOpacity??.9,s=[F(k(t.center,a),{kind:"core"})];for(let l=0;l<i;l+=1){const c=(e+l/i)%1,p=a+(r-a)*c;s.push(F(v(t.center,p),{kind:"pulse",opacity:o*(1-c),width:n*(1-.35*c)}))}return O(s)},j=t=>{const e=t.color||"#ff3b30",a=t.fillColor||e;return{data:D(t),layers:[{id:`${t.id}-core`,type:"fill",filter:["==",["get","kind"],"core"],paint:{"fill-color":a,"fill-opacity":t.fillOpacity??.28}},{id:`${t.id}-pulse`,type:"line",filter:["==",["get","kind"],"pulse"],paint:{"line-color":e,"line-opacity":["coalesce",["get","opacity"],t.pulseOpacity??.9],"line-width":["coalesce",["get","width"],t.lineWidth??2]}}],startAnimation({getOptions:t,setData:e}){const a=Math.max(400,t().duration??1800);let r=0;const i=performance.now(),n=o=>{const s=t();e(D(s,(o-i)%a/a)),r=requestAnimationFrame(n)};return r=requestAnimationFrame(n),()=>{cancelAnimationFrame(r)}}}},L=(t,e=0)=>{var a,r;const i=Math.max(16,t.radius??110),n=Math.max(0,t.pulseScale??.16),o=(1-Math.cos(e*Math.PI*2))/2,s=i*(1+n*o),l=1.28*s,c=Math.max(1,t.ringCount??(null==(a=t.radii)?void 0:a.length)??3),p=Math.max(2.2*s,t.maxRadius??((null==(r=t.radii)?void 0:r.length)?Math.max(...t.radii):i*(2.5*c))),d=p/c,h=[F(k(t.center,l),{kind:"halo",opacity:(t.haloOpacity??.16)*(.75+.65*o)}),F(k(t.center,s),{kind:"core",opacity:(t.fillOpacity??.28)*(.88+.2*o)}),F(v(t.center,1.06*s),{kind:"core-ring",opacity:(t.lineOpacity??.95)*(.8+.2*o),width:Math.max(1,(t.lineWidth??3)*(.92+.12*o))})];for(let y=0;y<c;y+=1){const a=(y+e+1)*d%p||p,r=a/p;h.push(F(v(t.center,a),{kind:"ring",opacity:Math.max(.18,(t.lineOpacity??.95)*(1-.42*r)),width:Math.max(1,(t.lineWidth??3)*(1-.18*r))}))}return O(h)},z=t=>{const e=t.color||"#ef4444",a=t.fillColor||e;return{data:L(t),layers:[{id:`${t.id}-halo`,type:"fill",filter:["==",["get","kind"],"halo"],paint:{"fill-color":a,"fill-opacity":["coalesce",["get","opacity"],t.haloOpacity??.16]}},{id:`${t.id}-core`,type:"fill",filter:["==",["get","kind"],"core"],paint:{"fill-color":a,"fill-opacity":["coalesce",["get","opacity"],t.fillOpacity??.28]}},{id:`${t.id}-rings`,type:"line",filter:["any",["==",["get","kind"],"ring"]],paint:{"line-color":e,"line-opacity":["coalesce",["get","opacity"],t.lineOpacity??.95],"line-width":["coalesce",["get","width"],t.lineWidth??3]}}],startAnimation({getOptions:t,setData:e}){const a=Math.max(600,t().duration??2e3);let r=0;const i=performance.now(),n=o=>{const s=t();e(L(s,(o-i)%a/a)),r=requestAnimationFrame(n)};return r=requestAnimationFrame(n),()=>{cancelAnimationFrame(r)}}}},P=(t,e,a)=>Math.min(a,Math.max(e,t)),T=t=>(t%360+360)%360,I=(t,e)=>{const a=(t=>{const e=t.trim(),a=e.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(a){const t=a[1],e=3===t.length?t.split("").map(t=>t+t).join(""):t;return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const r=e.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);if(r)return[P(Number(r[1]),0,255),P(Number(r[2]),0,255),P(Number(r[3]),0,255)]})(t);return a?`rgba(${a[0]}, ${a[1]}, ${a[2]}, ${P(e,0,1)})`:t},N=(t,e)=>{const a=M(t,e,0)[1],r=M(t,e,90)[0],i=M(t,e,180)[1],n=M(t,e,270)[0];return[[n,a],[r,a],[r,i],[n,i]]},B=t=>{var e;const a=null==(e=t.gradient)?void 0:e.colors;return Array.isArray(a)&&a.length>=2?a:void 0},C=(t,e,a=0)=>{const r=t.getContext("2d"),i=B(e);if(!r||!e.gradient||!i)return;const n=t.width,o=n/2,s=o-2,l=e.startAngle+a,c=((t,e)=>{const a=T(e)-T(t);return a<=0?a+360:a})(l,e.endAngle+a),p=(l-90)*Math.PI/180;const d=p+c*Math.PI/180,h=e.gradient.opacity??e.opacity??.28,y=e.gradient.centerOpacity??e.gradient.tailOpacity??.25*h,f=e.gradient.edgeOpacity??e.gradient.headOpacity??h,u=r.createRadialGradient(o,o,0,o,o,s);i.forEach((t,e)=>{const a=e/Math.max(1,i.length-1),r=y+(f-y)*a;u.addColorStop(a,I(t,r))}),r.clearRect(0,0,n,n),r.save(),r.beginPath(),r.moveTo(o,o),r.arc(o,o,s,p,d,!1),r.closePath(),r.clip(),r.fillStyle=u,r.fillRect(0,0,n,n),r.restore()},_=t=>{if(!B(t))return;const e=(()=>{const t=document.createElement("canvas");return t.width=768,t.height=768,t})();return C(e,t),e},E=(t,e,a)=>B(t)?[]:[F(A(t.center,t.radius,e,a),{kind:"sector",color:t.color||"#ff453a",opacity:t.opacity??.28})],G=(t,e=0)=>{const a=t.startAngle+e,r=t.endAngle+e,i=[...E(t,a,r),F(w(t.center,t.radius,a),{kind:"frame"}),F(w(t.center,t.radius,r),{kind:"frame"})];return O(i)},H=t=>{const e=_(t),a=e?{id:`${t.id}-sector-fill`,type:"raster",paint:{"raster-opacity":1,"raster-fade-duration":0}}:{id:`${t.id}-sector-fill`,type:"fill",filter:["==",["get","kind"],"sector"],paint:{"fill-color":["coalesce",["get","color"],t.color||"#ff453a"],"fill-opacity":["coalesce",["get","opacity"],t.opacity??.28],"fill-antialias":!1}};return{data:G(t),canvasSources:e?[{id:`${t.id}-canvas-source`,source:{type:"canvas",canvas:e,coordinates:N(t.center,t.radius),animate:Boolean(t.rotationSpeed&&0!==t.rotationSpeed)}}]:void 0,layers:[a,{id:`${t.id}-sector-frame`,type:"line",filter:["==",["get","kind"],"frame"],paint:{"line-color":t.outlineColor||t.color||"#ff453a","line-opacity":t.outlineOpacity??.95,"line-width":t.outlineWidth??2}}],startAnimation:t.rotationSpeed&&0!==t.rotationSpeed?({getOptions:t,setData:a})=>{const r=performance.now();let i=0;const n=o=>{const s=t(),l=(o-r)/1e3*(s.rotationSpeed||0);e&&C(e,s,l),a(G(s,l)),i=requestAnimationFrame(n)};return i=requestAnimationFrame(n),()=>{cancelAnimationFrame(i)}}:void 0}},J=(t,e)=>{const a=Math.max(40,t.radius),r=t.direction??270,i=Math.min(180,Math.max(8,t.spread??72)),n=Math.max(1,t.lineCount??7),o=Math.max(20,t.lineSpacing??Math.max(80,a/9)),s=e??0,l=Math.max(0,Math.min(.35*a,t.innerRadius??Math.min(.4*o,120))),c=r-i/2,p=r+i/2,d=[];for(let h=0;h<n;h+=1){const e=l+s+h*o;if(e>a)continue;const r=e/a,i=1-h/Math.max(1,n);d.push(F($(t.center,e,c,p),{kind:"directional-pulse-line",opacity:Math.max(.08,(t.opacity??.92)*(.42+.58*i)*(1-.28*r)),width:Math.max(1,(t.lineWidth??2.8)*(.86+.24*i)*(1-.08*r))}))}return O(d)},K=t=>({data:J(t),layers:[{id:`${t.id}-directional-pulse`,type:"line",filter:["==",["get","kind"],"directional-pulse-line"],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t.color||"#ef4444","line-opacity":["coalesce",["get","opacity"],t.opacity??.92],"line-width":["coalesce",["get","width"],t.lineWidth??2.8]}}],startAnimation:t.speed&&t.speed>0?({getOptions:t,setData:e})=>{const a=performance.now();let r=0;const i=n=>{const o=t(),s=Math.max(40,o.radius),l=Math.max(20,o.lineSpacing??Math.max(80,s/9)),c=(n-a)/1e3*(o.speed??0)%l;e(J(o,c)),r=requestAnimationFrame(i)};return r=requestAnimationFrame(i),()=>{cancelAnimationFrame(r)}}:void 0}),Q=(t,e=0)=>{var a;const r=Math.max(0,t.ringCount??4),i=Math.max(1,t.trailCount??8),n=Math.max(12,t.sweepAngle??42),o=.22*n,s=t.tailOpacity??.04,l=t.headOpacity??Math.max(.24,t.opacity??.3),c=(t.sweepStartAngle??0)+e,p=!1!==t.showCrosshair,d=!1!==t.showDistanceLabels,h=Math.max(20,t.coreRadius??Math.min(160,.035*t.radius)),y=[];for(let f=r;f>=1;f-=1){const e=t.radius*f/r;if(y.push(F(v(t.center,e),{kind:"ring"})),d){const r=(null==(a=t.distanceLabelFormatter)?void 0:a.call(t,e,f))??`${Math.round(e)}`;[{bearing:0,textAnchor:"bottom"},{bearing:90,textAnchor:"left"},{bearing:180,textAnchor:"top"},{bearing:270,textAnchor:"right"}].forEach(a=>{y.push(F({type:"Point",coordinates:M(t.center,e,a.bearing)},{kind:"distance-label",text:r,textAnchor:a.textAnchor}))})}}p&&y.push(F({type:"LineString",coordinates:[M(t.center,t.radius,180),M(t.center,t.radius,0)]},{kind:"crosshair"}),F({type:"LineString",coordinates:[M(t.center,t.radius,270),M(t.center,t.radius,90)]},{kind:"crosshair"})),y.push(F(k(t.center,h),{kind:"core"}));for(let f=i-1;f>=0;f-=1){const e=c-o*f,a=e+n,r=(i-f)/i,p=s+(l-s)*r*r;y.push(F(A(t.center,t.radius,e,a),{kind:"sweep",opacity:p}))}return y.push(F(A(t.center,t.radius,c+.42*n,c+n),{kind:"head",opacity:Math.min(1,l+.08)})),O(y)},R=t=>({data:Q(t),layers:[{id:`${t.id}-radar-trail`,type:"fill",filter:["==",["get","kind"],"sweep"],paint:{"fill-color":t.color||"#22c55e","fill-opacity":["coalesce",["get","opacity"],t.opacity??.32]}},{id:`${t.id}-radar-rings`,type:"line",filter:["==",["get","kind"],"ring"],paint:{"line-color":t.ringColor||t.color||"#22c55e","line-opacity":t.ringOpacity??.95,"line-width":t.ringWidth??2}},{id:`${t.id}-radar-crosshair`,type:"line",filter:["==",["get","kind"],"crosshair"],paint:{"line-color":t.crosshairColor||t.ringColor||t.color||"#22c55e","line-opacity":t.crosshairOpacity??.5,"line-width":t.crosshairWidth??1.4}},{id:`${t.id}-radar-distance-labels`,type:"symbol",filter:["==",["get","kind"],"distance-label"],layout:{"text-field":["get","text"],"text-size":t.distanceLabelSize??12,"text-anchor":["get","textAnchor"],"text-allow-overlap":!0,"text-ignore-placement":!0},paint:{"text-color":t.distanceLabelColor||t.ringColor||t.color||"#22c55e","text-opacity":t.distanceLabelOpacity??.92,"text-halo-color":t.distanceLabelHaloColor||"rgba(15, 23, 42, 0.42)","text-halo-width":1}}],startAnimation({getOptions:t,setData:e}){const a=performance.now();let r=0;const i=n=>{const o=t(),s=(n-a)/1e3*(o.rotationSpeed??36);e(Q(o,s)),r=requestAnimationFrame(i)};return r=requestAnimationFrame(i),()=>{cancelAnimationFrame(r)}}}),U=(t,e)=>t?"string"==typeof t&&y(t)?f(t,{token:e}):t:f("openfreemap-liberty");exports.maplibregl=t,exports.BASE_MAP_TYPES=h,exports.OPENFREEMAP_STYLES=n,exports.OPENFREEMAP_STYLE_BASE_URL=r,exports.OPENFREEMAP_STYLE_TYPES=o,exports.TDT_STYLE_TYPES=["tdt-image","tdt-image-label"],exports.addDirectionalPulse=(t,e)=>S(t,e,K),exports.addPulseMarker=(t,e)=>S(t,e,j),exports.addRadarSweep=(t,e)=>S(t,e,R),exports.addRingPulseMarker=(t,e)=>S(t,e,z),exports.addSectorScan=(t,e)=>S(t,e,H),exports.createMap=e=>{const{style:a,tdtToken:r,...i}=e;return new t.Map({...i,style:U(a,r)})},exports.createTiandituImageStyle=d,exports.createTiandituRasterSource=p,exports.getBaseMapStyle=f,exports.getMaplibreToolsConfig=a,exports.getOpenFreeMapStyle=s,exports.isBaseMapType=y,exports.setBaseMap=(t,e,a={})=>{const{diff:r=!1,...i}=a;t.setStyle(f(e,i),{diff:r})},exports.setMaplibreToolsConfig=t=>{Object.assign(e,t)};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("maplibre-gl"),e={},o=()=>({...e}),n="https://tiles.openfreemap.org/styles",i=(t,e,o)=>({type:t,label:e,style:`${n}/${o}`}),r={"openfreemap-liberty":i("openfreemap-liberty","OpenFreeMap Liberty","liberty"),"openfreemap-bright":i("openfreemap-bright","OpenFreeMap Bright","bright"),"openfreemap-positron":i("openfreemap-positron","OpenFreeMap Positron","positron"),"openfreemap-dark":i("openfreemap-dark","OpenFreeMap Dark","dark"),"openfreemap-fiord":i("openfreemap-fiord","OpenFreeMap Fiord","fiord")},a=Object.keys(r),l=(t="openfreemap-liberty")=>r[t].style,s=["0","1","2","3","4","5","6","7"],c="© 天地图",d=(t,e)=>{const n=(t=>{const e=t||o().tdtToken;if(!e)throw new Error("Tianditu token is required. Pass token or call setMaplibreToolsConfig({ tdtToken }).");return e})(e);return s.map(e=>`https://t${e}.tianditu.gov.cn/DataServer?T=${t}&x={x}&y={y}&l={z}&tk=${n}`)},f=(t,e={})=>({type:"raster",tiles:d(t,e.token),tileSize:256,minzoom:0,maxzoom:18,attribution:c}),h=(t={})=>({type:"raster",tiles:d("vec_w",t.token),tileSize:256,minzoom:0,maxzoom:18,attribution:c}),p=(t={})=>{const e=!1!==t.label,o={"tdt-image":f("img_w",t)},n=[{id:"tdt-image",type:"raster",source:"tdt-image"}];return e&&(o["tdt-image-label"]=f("cia_w",t),n.push({id:"tdt-image-label",type:"raster",source:"tdt-image-label"})),{version:8,sources:o,layers:n}},u=(t={})=>{const e=!1!==t.label,o={"tdt-mvt":h(t)},n=[{id:"tdt-mvt",type:"raster",source:"tdt-mvt"}];return e&&(o["tdt-mvt-label"]=f("cva_w",t),n.push({id:"tdt-mvt-label",type:"raster",source:"tdt-mvt-label"})),{version:8,sources:o,layers:n}},g=[...Object.keys(r),"tdt-image","tdt-image-label","tdt-mvt","tdt-mvt-label"],y=t=>g.includes(t),m=(t="openfreemap-liberty",e={})=>"tdt-image"===t?p({...e,label:!1}):"tdt-image-label"===t?p({...e,label:!0}):"tdt-mvt"===t?u({...e,label:!1}):"tdt-mvt-label"===t?u({...e,label:!0}):l(t),_=6378137,w=t=>t*Math.PI/180,v=t=>180*t/Math.PI,b=t=>(t%360+360)%360,M=(t,e,o)=>{const n=e/_,i=w(o),r=w(t[1]),a=w(t[0]),l=Math.asin(Math.sin(r)*Math.cos(n)+Math.cos(r)*Math.sin(n)*Math.cos(i)),s=a+Math.atan2(Math.sin(i)*Math.sin(n)*Math.cos(r),Math.cos(n)-Math.sin(r)*Math.sin(l));return[(c=v(s),c>180?c-360:c<-180?c+360:c),v(l)];var c},$=(t,e)=>{const o=w(e[1]-t[1]),n=w(e[0]-t[0]),i=w(t[1]),r=w(e[1]),a=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(r)*Math.sin(n/2)*Math.sin(n/2);return 12756274*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))},k=(t,e)=>{const o=w(t[1]),n=w(e[1]),i=w(e[0]-t[0]),r=Math.sin(i)*Math.cos(n),a=Math.cos(o)*Math.sin(n)-Math.sin(o)*Math.cos(n)*Math.cos(i);return b(v(Math.atan2(r,a)))},x=(t,e,o=64)=>{const n=((t,e)=>{const o=b(e)-b(t);return o<=0?o+360:o})(t,e),i=Math.max(12,Math.ceil(o*n/360));return Array.from({length:i+1},(e,o)=>b(t+n*o/i))},A=(t,e,o=64)=>(t=>{if(0===t.length)return t;const[e,o]=t[0],n=t[t.length-1];return n[0]===e&&n[1]===o?t:[...t,[e,o]]})(Array.from({length:o},(n,i)=>M(t,e,360*i/o))),F=(t,e,o=64)=>({type:"Polygon",coordinates:[A(t,e,o)]}),C=(t,e,o=64)=>({type:"LineString",coordinates:A(t,e,o)}),P=(t,e,o,n,i=64)=>{const r=x(o,n,i).map(o=>M(t,e,o));return{type:"Polygon",coordinates:[[t,...r,t]]}},S=(t,e,o,n,i=64)=>({type:"LineString",coordinates:x(o,n,i).map(o=>M(t,e,o))}),O=(t,e,o)=>({type:"LineString",coordinates:[t,M(t,e,o)]}),L=(t,e)=>({type:"Feature",geometry:t,properties:e}),W=t=>({type:"FeatureCollection",features:t}),N=(t,e)=>{t.getLayer(e)&&t.removeLayer(e)},q=(t,e)=>{t.getSource(e)&&t.removeSource(e)},G=(t,e,o)=>{const n=o?"visible":"none";e.forEach(e=>{t.getLayer(e)&&t.setLayoutProperty(e,"visibility",n)})},E=t=>t instanceof Error&&"Style is not done loading."===t.message,I=(t,e,o)=>{const n=e.id,i=`${n}-source`;let r,a={...e},l=[],s=[i],c=!1,d=!1;const f=()=>{null==r||r(),r=void 0,[...l].reverse().forEach(e=>{N(t,e)}),[...s].reverse().forEach(e=>{q(t,e)}),l=[],s=[i]},h=e=>{const o=t.getSource(i);o&&o.setData(e)},p=()=>{try{(()=>{var e,n,d;if(c)return;f();const p=o(a);t.addSource(i,{type:"geojson",data:p.data}),null==(e=p.canvasSources)||e.forEach(e=>{t.addSource(e.id,e.source)}),s=[i,...(null==(n=p.canvasSources)?void 0:n.map(t=>t.id))||[]],l=p.layers.map(t=>t.id),p.layers.forEach(e=>{var o;const n="raster"===e.type&&(null==(o=p.canvasSources)?void 0:o[0])?p.canvasSources[0].id:i;t.addLayer({...e,source:n},a.beforeId)}),G(t,l,!1!==a.visible),null==(d=p.canvasSources)||d.forEach(e=>{var o;const n=t.style,i=null==(o=null==n?void 0:n.tileManagers)?void 0:o[e.id];if(!i||!i.t)return;const r=i.used;i.used=!0;const a=t;i.update(a.transform,a.terrain),i.used=r}),p.startAnimation&&(r=p.startAnimation({getOptions:()=>a,setData:h})||void 0)})(),d&&(d=!1,t.off("styledata",u))}catch(e){if(!E(e))throw e;d||(d=!0,t.on("styledata",u))}},u=()=>{d&&!c&&p()},g=()=>{c||p()};return g(),{id:n,update(t){c||(a={...a,...t,id:n},g())},show(){c||(a={...a,visible:!0},G(t,l,!0))},hide(){c||(a={...a,visible:!1},G(t,l,!1))},remove(){c||(c=!0,d&&(d=!1,t.off("styledata",u)),f())}}},R=(t,e=0)=>{const o=Math.max(10,t.radius??70),n=Math.max(o,t.maxRadius??2.3*o),i=Math.max(1,t.pulseCount??2),r=Math.max(1,t.lineWidth??2),a=t.pulseOpacity??.9,l=[L(F(t.center,o),{kind:"core"})];for(let s=0;s<i;s+=1){const c=(e+s/i)%1,d=o+(n-o)*c;l.push(L(C(t.center,d),{kind:"pulse",opacity:a*(1-c),width:r*(1-.35*c)}))}return W(l)},j=t=>{const e=t.color||"#ff3b30",o=t.fillColor||e;return{data:R(t),layers:[{id:`${t.id}-core`,type:"fill",filter:["==",["get","kind"],"core"],paint:{"fill-color":o,"fill-opacity":t.fillOpacity??.28}},{id:`${t.id}-pulse`,type:"line",filter:["==",["get","kind"],"pulse"],paint:{"line-color":e,"line-opacity":["coalesce",["get","opacity"],t.pulseOpacity??.9],"line-width":["coalesce",["get","width"],t.lineWidth??2]}}],startAnimation({getOptions:t,setData:e}){const o=Math.max(400,t().duration??1800);let n=0;const i=performance.now(),r=a=>{const l=t();e(R(l,(a-i)%o/o)),n=requestAnimationFrame(r)};return n=requestAnimationFrame(r),()=>{cancelAnimationFrame(n)}}}},D=(t,e=0)=>{const o=Math.max(1,t.radius??90),n=Math.max(1,t.minRadius??.78*o),i=Math.max(n,t.maxRadius??1.22*o),r=(1-Math.cos(e*Math.PI*2))/2,a=n+(i-n)*r,l=t.fillOpacity??.28,s=t.minFillOpacity??.46*l,c=t.strokeOpacity??.82,d=t.minStrokeOpacity??.38*c,f=1-r,h=[L(F(t.center,a),{kind:"breathing-fill",opacity:s+(l-s)*f})];return(t.strokeWidth??2)>0&&h.push(L(C(t.center,a),{kind:"breathing-stroke",opacity:d+(c-d)*f})),W(h)},T=t=>{const e=t.color||"#1677ff",o=t.fillColor||e,n=t.strokeColor||e,i=Math.max(0,t.strokeWidth??2);return{data:D(t),layers:[{id:`${t.id}-breathing-fill`,type:"fill",filter:["==",["get","kind"],"breathing-fill"],paint:{"fill-color":o,"fill-opacity":["coalesce",["get","opacity"],t.fillOpacity??.28]}},{id:`${t.id}-breathing-stroke`,type:"line",filter:["==",["get","kind"],"breathing-stroke"],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":n,"line-opacity":["coalesce",["get","opacity"],t.strokeOpacity??.82],"line-width":i}}],startAnimation({getOptions:t,setData:e}){const o=Math.max(400,t().duration??1800),n=performance.now();let i=0;const r=a=>{const l=t();e(D(l,(a-n)%o/o)),i=requestAnimationFrame(r)};return i=requestAnimationFrame(r),()=>{cancelAnimationFrame(i)}}}},V=(t,e=0)=>{const o=Math.max(16,t.radius??110),n=Math.max(0,t.pulseScale??.16),i=(1-Math.cos(e*Math.PI*2))/2,r=o*(1+n*i),a=Math.max(1,t.ringCount??3),l=Math.max(2.2*r,t.maxRadius??o*(2.5*a)),s=l/a,c=t.fillOpacity??.28,d=[L(F(t.center,r),{kind:"core",opacity:c*(.88+.2*i)}),L(C(t.center,1.06*r),{kind:"core-ring",opacity:(t.lineOpacity??.95)*(.8+.2*i),width:Math.max(1,(t.lineWidth??3)*(.92+.12*i))})];for(let f=0;f<a;f+=1){const o=(f+e+1)*s%l||l,n=o/l;d.push(L(C(t.center,o),{kind:"ring",opacity:Math.max(.18,(t.lineOpacity??.95)*(1-.42*n)),width:Math.max(1,(t.lineWidth??3)*(1-.18*n))}))}return W(d)},Y=t=>{const e=t.color||"#ef4444",o=t.fillColor||e;return{data:V(t),layers:[{id:`${t.id}-core`,type:"fill",filter:["==",["get","kind"],"core"],paint:{"fill-color":o,"fill-opacity":["coalesce",["get","opacity"],t.fillOpacity??.28]}},{id:`${t.id}-rings`,type:"line",filter:["any",["==",["get","kind"],"ring"]],paint:{"line-color":e,"line-opacity":["coalesce",["get","opacity"],t.lineOpacity??.95],"line-width":["coalesce",["get","width"],t.lineWidth??3]}}],startAnimation({getOptions:t,setData:e}){const o=Math.max(600,t().duration??2e3);let n=0;const i=performance.now(),r=a=>{const l=t();e(V(l,(a-i)%o/o)),n=requestAnimationFrame(r)};return n=requestAnimationFrame(r),()=>{cancelAnimationFrame(n)}}}},z=(t,e,o)=>Math.min(o,Math.max(e,t)),U=t=>{const e=t.trim(),o=e.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(o){const t=o[1],e=3===t.length?t.split("").map(t=>t+t).join(""):t;return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const n=e.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);if(n)return[z(Number(n[1]),0,255),z(Number(n[2]),0,255),z(Number(n[3]),0,255)]},B=t=>(t%360+360)%360,H=t=>(t-90)*Math.PI/180,J=(t,e)=>{const o=U(t);return o?`rgba(${o[0]}, ${o[1]}, ${o[2]}, ${z(e,0,1)})`:t},X=t=>t*(2-t),K=(t,e)=>{const o=t.length-1;if(e<=0)return t[0];if(e>=o)return t[o];const n=Math.floor(e),i=e-n,[r,a]=[U(t[n]),U(t[n+1])];if(!r||!a)return t[Math.round(e)];const[l,s,c]=((t,e,o)=>[Math.round(t[0]+(e[0]-t[0])*o),Math.round(t[1]+(e[1]-t[1])*o),Math.round(t[2]+(e[2]-t[2])*o)])(r,a,i);return`rgb(${l},${s},${c})`},Q=(t,e)=>{const o=M(t,e,0)[1],n=M(t,e,90)[0],i=M(t,e,180)[1],r=M(t,e,270)[0];return[[r,o],[n,o],[n,i],[r,i]]},Z=t=>{var e;const o=null==(e=t.gradient)?void 0:e.colors;return Array.isArray(o)&&o.length>=2?o:void 0},tt=(t,e,o=0)=>{const n=t.getContext("2d"),i=Z(e);if(!n||!e.gradient||!i)return;const r=t.width,a=r/2,l=a-2,s=e.startAngle+o,c=((t,e)=>{const o=B(e)-B(t);return o<=0?o+360:o})(s,e.endAngle+o),d=H(s),f=d+c*Math.PI/180,h=e.gradient.opacity??e.opacity??.28,p=e.gradient.centerOpacity??.25*h,u=e.gradient.edgeOpacity??h,g=n.createRadialGradient(a,a,0,a,a,l);i.forEach((t,e)=>{const o=e/Math.max(1,i.length-1),n=p+(u-p)*o;g.addColorStop(o,J(t,n))}),n.clearRect(0,0,r,r),n.save(),n.beginPath(),n.moveTo(a,a),n.arc(a,a,l,d,f,!1),n.closePath(),n.clip(),n.fillStyle=g,n.fillRect(0,0,r,r),n.restore()},et=t=>{if(!Z(t))return;const e=(()=>{const t=document.createElement("canvas");return t.width=768,t.height=768,t})();return tt(e,t),e},ot=(t,e,o)=>Z(t)?[]:[L(P(t.center,t.radius,e,o),{kind:"sector",color:t.color||"#ff453a",opacity:t.opacity??.28})],nt=(t,e=0)=>{const o=t.startAngle+e,n=t.endAngle+e,i=[...ot(t,o,n),L(O(t.center,t.radius,o),{kind:"frame"}),L(O(t.center,t.radius,n),{kind:"frame"})];return W(i)},it=t=>{const e=et(t),o=e?{id:`${t.id}-sector-fill`,type:"raster",paint:{"raster-opacity":1,"raster-fade-duration":0}}:{id:`${t.id}-sector-fill`,type:"fill",filter:["==",["get","kind"],"sector"],paint:{"fill-color":["coalesce",["get","color"],t.color||"#ff453a"],"fill-opacity":["coalesce",["get","opacity"],t.opacity??.28],"fill-antialias":!1}};return{data:nt(t),canvasSources:e?[{id:`${t.id}-canvas-source`,source:{type:"canvas",canvas:e,coordinates:Q(t.center,t.radius),animate:Boolean(t.rotationSpeed&&0!==t.rotationSpeed)}}]:void 0,layers:[o,{id:`${t.id}-sector-frame`,type:"line",filter:["==",["get","kind"],"frame"],paint:{"line-color":t.outlineColor||t.color||"#ff453a","line-opacity":t.outlineOpacity??.95,"line-width":t.outlineWidth??2}}],startAnimation:t.rotationSpeed&&0!==t.rotationSpeed?({getOptions:t,setData:o})=>{const n=performance.now();let i=0;const r=a=>{const l=t(),s=(a-n)/1e3*(l.rotationSpeed||0);e&&tt(e,l,s),o(nt(l,s)),i=requestAnimationFrame(r)};return i=requestAnimationFrame(r),()=>{cancelAnimationFrame(i)}}:void 0}},rt=(t,e)=>{const o=Math.max(40,t.radius),n=t.direction??270,i=Math.min(180,Math.max(8,t.spread??72)),r=Math.max(1,t.lineCount??7),a=Math.max(20,t.lineSpacing??Math.max(80,o/9)),l=e??0,s=Math.max(0,Math.min(.35*o,t.innerRadius??Math.min(.4*a,120))),c=n-i/2,d=n+i/2,f=[];for(let h=0;h<r;h+=1){const e=s+l+h*a;if(e>o)continue;const n=e/o,i=1-h/Math.max(1,r);f.push(L(S(t.center,e,c,d),{kind:"directional-pulse-line",opacity:Math.max(.08,(t.opacity??.92)*(.42+.58*i)*(1-.28*n)),width:Math.max(1,(t.lineWidth??2.8)*(.86+.24*i)*(1-.08*n))}))}return W(f)},at=t=>({data:rt(t),layers:[{id:`${t.id}-directional-pulse`,type:"line",filter:["==",["get","kind"],"directional-pulse-line"],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t.color||"#ef4444","line-opacity":["coalesce",["get","opacity"],t.opacity??.92],"line-width":["coalesce",["get","width"],t.lineWidth??2.8]}}],startAnimation:t.speed&&t.speed>0?({getOptions:t,setData:e})=>{const o=performance.now();let n=0;const i=r=>{const a=t(),l=Math.max(40,a.radius),s=Math.max(20,a.lineSpacing??Math.max(80,l/9)),c=(r-o)/1e3*(a.speed??0)%s;e(rt(a,c)),n=requestAnimationFrame(i)};return n=requestAnimationFrame(i),()=>{cancelAnimationFrame(n)}}:void 0}),lt=t=>{var e;const o=null==(e=t.gradient)?void 0:e.colors;return Array.isArray(o)&&o.length>=2},st=(t,e)=>{const o=M(t,e,0)[1],n=M(t,e,90)[0],i=M(t,e,180)[1],r=M(t,e,270)[0];return[[r,o],[n,o],[n,i],[r,i]]},ct=(t,e,o=0)=>{const n=t.getContext("2d"),i=e.gradient,r=null==i?void 0:i.colors;if(!n||!i||!r||r.length<2)return;const a=t.width,l=a/2,s=l-2,c=Math.max(12,e.sweepAngle??42),d=e.tailOpacity??.04,f=Math.max(.24,e.opacity??.3),h=(e.sweepStartAngle??0)+o,p=h,u=h+c,g=c;n.clearRect(0,0,a,a);const y=n.createConicGradient(H(p),l,l),m=g/360,_=Math.min(1,f+.08);for(let w=0;w<=128;w++){const t=w/128,e=d+(_-d)*X(t),o=t*(r.length-1),n=K(r,o);y.addColorStop(t*m,J(n,Math.max(0,e)))}n.save(),n.beginPath(),n.moveTo(l,l),n.arc(l,l,s,H(p),H(u),!1),n.closePath(),n.fillStyle=y,n.fill(),n.restore()},dt=(t,e=0)=>{var o;const n=Math.max(0,t.ringCount??4),i=Math.max(12,t.sweepAngle??42),r=t.headOpacity??Math.max(.24,t.opacity??.3),a=(t.sweepStartAngle??0)+e,l=!1!==t.showCrosshair,s=!1!==t.showDistanceLabels,c=Math.max(20,t.coreRadius??Math.min(160,.035*t.radius)),d=lt(t),f=[];for(let h=n;h>=1;h-=1){const e=t.radius*h/n;if(f.push(L(C(t.center,e),{kind:"ring"})),s){const n=(null==(o=t.distanceLabelFormatter)?void 0:o.call(t,e,h))??`${Math.round(e)}`;[{bearing:0,textAnchor:"bottom"},{bearing:90,textAnchor:"left"},{bearing:180,textAnchor:"top"},{bearing:270,textAnchor:"right"}].forEach(o=>{f.push(L({type:"Point",coordinates:M(t.center,e,o.bearing)},{kind:"distance-label",text:n,textAnchor:o.textAnchor}))})}}return l&&f.push(L({type:"LineString",coordinates:[M(t.center,t.radius,180),M(t.center,t.radius,0)]},{kind:"crosshair"}),L({type:"LineString",coordinates:[M(t.center,t.radius,270),M(t.center,t.radius,90)]},{kind:"crosshair"})),f.push(L(F(t.center,c),{kind:"core"})),d||f.push(L(P(t.center,t.radius,a,a+i),{kind:"sweep",opacity:r})),W(f)},ft=t=>{const e=lt(t)?(()=>{const t=document.createElement("canvas");return t.width=768,t.height=768,t})():void 0;e&&ct(e,t);const o=e?{id:`${t.id}-radar-trail`,type:"raster",paint:{"raster-opacity":1,"raster-fade-duration":0}}:{id:`${t.id}-radar-trail`,type:"fill",filter:["==",["get","kind"],"sweep"],paint:{"fill-color":t.color||"#22c55e","fill-opacity":["coalesce",["get","opacity"],t.opacity??.32]}};return{data:dt(t),canvasSources:e?[{id:`${t.id}-canvas-source`,source:{type:"canvas",canvas:e,coordinates:st(t.center,t.radius),animate:!0}}]:void 0,layers:[o,{id:`${t.id}-radar-rings`,type:"line",filter:["==",["get","kind"],"ring"],paint:{"line-color":t.ringColor||t.color||"#22c55e","line-opacity":t.ringOpacity??.95,"line-width":t.ringWidth??2}},{id:`${t.id}-radar-crosshair`,type:"line",filter:["==",["get","kind"],"crosshair"],paint:{"line-color":t.crosshairColor||t.ringColor||t.color||"#22c55e","line-opacity":t.crosshairOpacity??.5,"line-width":t.crosshairWidth??1.4}},{id:`${t.id}-radar-distance-labels`,type:"symbol",filter:["==",["get","kind"],"distance-label"],layout:{"text-field":["get","text"],"text-size":t.distanceLabelSize??12,"text-anchor":["get","textAnchor"],"text-allow-overlap":!0,"text-ignore-placement":!0},paint:{"text-color":t.distanceLabelColor||t.ringColor||t.color||"#22c55e","text-opacity":t.distanceLabelOpacity??.92,"text-halo-color":t.distanceLabelHaloColor||"rgba(15, 23, 42, 0.42)","text-halo-width":1}}],startAnimation({getOptions:t,setData:o}){const n=performance.now();let i=0;const r=a=>{const l=t(),s=(a-n)/1e3*(l.rotationSpeed??36);e&&ct(e,l,s),o(dt(l,s)),i=requestAnimationFrame(r)};return i=requestAnimationFrame(r),()=>{cancelAnimationFrame(i)}}}},ht=(t,e)=>{const o=M(t,e,0)[1],n=M(t,e,90)[0],i=M(t,e,180)[1],r=M(t,e,270)[0];return[[r,o],[n,o],[n,i],[r,i]]},pt=t=>{const e=(()=>{const t=document.createElement("canvas");return t.width=512,t.height=512,t})();((t,e)=>{const o=t.getContext("2d");if(!o)return;const n=t.width,i=n/2,r=i-1,a=e.color||"#06c536",l=e.fillColor||a,s=e.borderColor||a,c=e.fillOpacity??.06,d=e.borderOpacity??.92;o.clearRect(0,0,n,n),o.save(),o.beginPath(),o.arc(i,i,r,0,2*Math.PI),o.clip();const f=o.createRadialGradient(i,i,0,i,i,r),h=Math.min(.8,c+.85*(d-c));f.addColorStop(0,J(l,c)),f.addColorStop(.85,J(l,c)),f.addColorStop(.92,J(s,c+.3*(h-c))),f.addColorStop(.96,J(s,c+.7*(h-c))),f.addColorStop(1,J(s,h)),o.fillStyle=f,o.fillRect(0,0,n,n),o.restore()})(e,t);const o=t.borderColor||t.color||"#06c536";return{data:W([L(C(t.center,t.radius),{kind:"defence-border"})]),canvasSources:[{id:`${t.id}-canvas-source`,source:{type:"canvas",canvas:e,coordinates:ht(t.center,t.radius),animate:!0}}],layers:[{id:`${t.id}-defence-circle`,type:"raster",paint:{"raster-opacity":1,"raster-fade-duration":0}},{id:`${t.id}-defence-border`,type:"line",filter:["==",["get","kind"],"defence-border"],paint:{"line-color":o,"line-opacity":t.borderOpacity??.92,"line-width":t.borderWidth??2}}]}},ut=(t,e=0)=>{const o=Math.max(1,t.sourceWidth??220),n=Math.max(1,t.targetWidth??45),i=(t=>{const e=t.target||M(t.center,t.distance||0,t.bearing||0),o=void 0!==t.target?k(t.center,t.target):b(t.bearing||0),n=M(t.center,t.startWidth/2,o-90),i=M(t.center,t.startWidth/2,o+90);return{polygon:{type:"Polygon",coordinates:[[n,M(e,t.endWidth/2,o-90),M(e,t.endWidth/2,o+90),i,n]]},centerLine:{type:"LineString",coordinates:[t.center,e]}}})({center:t.center,target:t.target,startWidth:o,endWidth:n}),r=[L(i.polygon,{kind:"countermeasure-channel"}),L(i.centerLine,{kind:"countermeasure-line"})],a=$(t.center,t.target),l=k(t.center,t.target),s=Math.max(0,Math.floor(t.particleCount??18)),c=Math.max(300,t.particleDuration??1200),d=e%c/c,f=Math.max(1,t.particleRadius??2.8);if(a>0)for(let h=0;h<s;h+=1){const e=(d+h/s)%1;r.push(L({type:"Point",coordinates:M(t.center,a*e,l)},{kind:"countermeasure-particle",opacity:.25+.75*e,radius:f*(.7+.3*e)}))}if(!1!==t.targetRipple){const o=Math.max(1,Math.floor(t.targetRippleCount??2)),n=Math.max(10,t.targetRippleRadius??120),i=Math.max(300,t.targetRippleDuration??900),a=e%i/i;for(let e=0;e<o;e+=1){const i=(a+e/o)%1,l="forcedLanding"===t.mode?1-i:i;r.push(L(C(t.target,Math.max(2,n*l)),{kind:"countermeasure-target-ripple",opacity:.9*Math.sin(Math.PI*i)}))}}return W(r)},gt=t=>{const e=t.color??"#a855f7",o=t.lineColor??"#f0abfc",n=Math.max(1,t.lineWidth??2.5);return{data:ut(t),layers:[{id:`${t.id}-countermeasure-channel`,type:"fill",filter:["==",["get","kind"],"countermeasure-channel"],paint:{"fill-color":t.channelColor??e,"fill-opacity":t.channelOpacity??.16}},{id:`${t.id}-countermeasure-glow`,type:"line",filter:["==",["get","kind"],"countermeasure-line"],layout:{"line-cap":"round"},paint:{"line-color":o,"line-opacity":.28*(t.lineOpacity??.92),"line-width":4*n,"line-blur":1.4*n}},{id:`${t.id}-countermeasure-line`,type:"line",filter:["==",["get","kind"],"countermeasure-line"],layout:{"line-cap":"round"},paint:{"line-color":o,"line-opacity":t.lineOpacity??.92,"line-width":n}},{id:`${t.id}-countermeasure-target-ripple`,type:"line",filter:["==",["get","kind"],"countermeasure-target-ripple"],paint:{"line-color":e,"line-opacity":["coalesce",["get","opacity"],.9],"line-width":Math.max(1,t.targetRippleWidth??2.5)}},{id:`${t.id}-countermeasure-particle`,type:"circle",filter:["==",["get","kind"],"countermeasure-particle"],paint:{"circle-color":t.particleColor??o,"circle-opacity":["coalesce",["get","opacity"],1],"circle-radius":["coalesce",["get","radius"],2.8],"circle-blur":.18,"circle-stroke-color":"#ffffff","circle-stroke-opacity":.45,"circle-stroke-width":.5}}],startAnimation:({getOptions:t,setData:e})=>{let o=0;const n=performance.now(),i=r=>{e(ut(t(),r-n)),o=requestAnimationFrame(i)};return o=requestAnimationFrame(i),()=>cancelAnimationFrame(o)}}},yt=(t,e=0)=>{const o=[],n=new Set,i=Math.max(0,Math.floor(t.particleCount??5)),r=Math.max(300,t.particleDuration??1600),a=e%r/r,l=Math.max(1,t.particleRadius??2.5);if(t.links.forEach((e,r)=>{const s=e.color??("detection"===(c=e.type)?"#38bdf8":"command"===c?"#22d3ee":"#f97316");var c;const d=$(e.from,e.to),f=k(e.from,e.to);if(o.push(L({type:"LineString",coordinates:[e.from,e.to]},{kind:"coordination-link",linkType:e.type,color:s})),!1!==t.showNodes&&[e.from,e.to].forEach(t=>{const e=`${t[0]},${t[1]}`;n.has(e)||(n.add(e),o.push(L({type:"Point",coordinates:t},{kind:"coordination-node",color:s})))}),!(d<=0))for(let n=0;n<i;n+=1){const c=(a+n/i+r/t.links.length)%1;o.push(L({type:"Point",coordinates:M(e.from,d*c,f)},{kind:"coordination-particle",color:s,opacity:.35+.65*c,radius:l}))}}),!1!==t.targetRipple){const n=Math.max(300,t.targetRippleDuration??1200),i=e%n/n,r=Math.max(10,t.targetRippleRadius??100)*i;o.push(L(C(t.center,Math.max(2,r)),{kind:"coordination-target-ripple",opacity:.9*(1-i)}))}return W(o)},mt=t=>{const e=Math.max(1,t.lineWidth??2.2),o=t.lineOpacity??.9;return{data:yt(t),layers:[{id:`${t.id}-coordination-detection`,type:"line",filter:["==",["get","linkType"],"detection"],paint:{"line-color":["coalesce",["get","color"],"#38bdf8"],"line-opacity":o,"line-width":e,"line-dasharray":[2,2]}},{id:`${t.id}-coordination-command`,type:"line",filter:["==",["get","linkType"],"command"],paint:{"line-color":["coalesce",["get","color"],"#22d3ee"],"line-opacity":o,"line-width":e,"line-dasharray":[.5,1.8]}},{id:`${t.id}-coordination-countermeasure`,type:"line",filter:["==",["get","linkType"],"countermeasure"],paint:{"line-color":["coalesce",["get","color"],"#f97316"],"line-opacity":o,"line-width":e+.8}},{id:`${t.id}-coordination-target-ripple`,type:"line",filter:["==",["get","kind"],"coordination-target-ripple"],paint:{"line-color":"#ff3b30","line-opacity":["coalesce",["get","opacity"],.9],"line-width":2.5}},{id:`${t.id}-coordination-node`,type:"circle",filter:["==",["get","kind"],"coordination-node"],paint:{"circle-color":["coalesce",["get","color"],"#ffffff"],"circle-radius":Math.max(2,t.nodeRadius??5),"circle-stroke-color":"#ffffff","circle-stroke-width":1.5}},{id:`${t.id}-coordination-particle`,type:"circle",filter:["==",["get","kind"],"coordination-particle"],paint:{"circle-color":["coalesce",["get","color"],"#ffffff"],"circle-opacity":["coalesce",["get","opacity"],1],"circle-radius":["coalesce",["get","radius"],2.5],"circle-blur":.1}}],startAnimation:({getOptions:t,setData:e})=>{let o=0;const n=performance.now(),i=r=>{e(yt(t(),r-n)),o=requestAnimationFrame(i)};return o=requestAnimationFrame(i),()=>cancelAnimationFrame(o)}}},_t=(t,e=0)=>{const o=[L({type:"LineString",coordinates:[t.center,t.spoofedPosition]},{kind:"spoofing-offset"})],n=$(t.center,t.spoofedPosition),i=k(t.center,t.spoofedPosition),r=Math.max(0,Math.floor(t.particleCount??10)),a=Math.max(300,t.particleDuration??1800),l=e%a/a;if(!1!==t.showTruePosition&&o.push(L({type:"Point",coordinates:t.center},{kind:"spoofing-true-position"})),!1!==t.showSpoofedPosition&&o.push(L({type:"Point",coordinates:t.spoofedPosition},{kind:"spoofing-ghost"})),n>0)for(let s=0;s<r;s+=1){const e=(l+s/r)%1;o.push(L({type:"Point",coordinates:M(t.center,n*e,i)},{kind:"spoofing-particle",opacity:.25+.75*e}))}if(!1!==t.ripple){const n=Math.max(1,Math.floor(t.rippleCount??2)),i=Math.max(300,t.rippleDuration??1200),r=Math.max(10,t.rippleRadius??120),a=e%i/i;for(let e=0;e<n;e+=1){const i=(a+e/n)%1;o.push(L(C(t.spoofedPosition,Math.max(2,r*i)),{kind:"spoofing-ripple",opacity:.75*(1-i)}))}}return W(o)},wt=t=>{const e=t.color??"#8b5cf6";return{data:_t(t),layers:[{id:`${t.id}-spoofing-offset`,type:"line",filter:["==",["get","kind"],"spoofing-offset"],layout:{"line-cap":"round"},paint:{"line-color":t.lineColor??e,"line-opacity":t.lineOpacity??.82,"line-width":Math.max(1,t.lineWidth??2),"line-dasharray":[1.2,2]}},{id:`${t.id}-spoofing-ripple`,type:"line",filter:["==",["get","kind"],"spoofing-ripple"],paint:{"line-color":e,"line-opacity":["coalesce",["get","opacity"],.75],"line-width":2}},{id:`${t.id}-spoofing-true-position`,type:"circle",filter:["==",["get","kind"],"spoofing-true-position"],paint:{"circle-color":"#ffffff","circle-radius":5,"circle-stroke-color":e,"circle-stroke-width":2}},{id:`${t.id}-spoofing-ghost`,type:"circle",filter:["==",["get","kind"],"spoofing-ghost"],paint:{"circle-color":e,"circle-opacity":t.ghostOpacity??.42,"circle-radius":Math.max(2,t.ghostRadius??8),"circle-stroke-color":"#ffffff","circle-stroke-opacity":.8,"circle-stroke-width":1.5}},{id:`${t.id}-spoofing-particle`,type:"circle",filter:["==",["get","kind"],"spoofing-particle"],paint:{"circle-color":e,"circle-opacity":["coalesce",["get","opacity"],1],"circle-radius":Math.max(1,t.particleRadius??2.5),"circle-blur":.12}}],startAnimation:({getOptions:t,setData:e})=>{let o=0;const n=performance.now(),i=r=>{e(_t(t(),r-n)),o=requestAnimationFrame(i)};return o=requestAnimationFrame(i),()=>cancelAnimationFrame(o)}}},vt="__electronic_fence_id",bt=t=>JSON.parse(JSON.stringify(t)),Mt=t=>{const e=t.map(t=>{const e=Number(t[0]),o=Number(t[1]);if(!Number.isFinite(e)||!Number.isFinite(o))throw new Error("电子围栏坐标必须是有限数字。");return[e,o]});if(e.length<3)throw new Error("电子围栏的每个环至少需要 3 个不同坐标。");var o,n;if(o=e[0],n=e[e.length-1],(o[0]!==n[0]||o[1]!==n[1])&&e.push([...e[0]]),e.length<4)throw new Error("电子围栏 Polygon 环无效。");return e},$t=t=>{if("string"!=typeof t.id||!t.id.trim())throw new Error("电子围栏必须提供非空字符串 id。");if(!t.geometry||"Polygon"!==t.geometry.type)throw new Error(`电子围栏 ${t.id} 仅支持 Polygon geometry。`);const e=bt(t.properties||{});return{type:"Feature",id:t.id,geometry:{type:"Polygon",coordinates:t.geometry.coordinates.map(Mt)},properties:e}};class kt{constructor(){this.features=new Map,this.states=new Map,this.activeIds=new Set,this.hiddenIds=new Set}setData(t){const e=new Map;t.features.forEach(t=>{const o=$t(t);if(e.has(o.id))throw new Error(`电子围栏 id 重复:${o.id}`);e.set(o.id,o)}),this.features=e,this.states.clear(),this.activeIds.clear(),this.hiddenIds.clear()}add(t){const e=$t(t);if(this.features.has(e.id))throw new Error(`电子围栏 id 已存在:${e.id}`);return this.features.set(e.id,e),e.id}update(t,e){const o=this.requireFeature(t);this.features.set(t,((t,e)=>{const o=t.properties||{},n=e.properties||{},i=n.style?{...o.style||{},...n.style}:o.style;return $t({...bt(t),geometry:e.geometry?bt(e.geometry):bt(t.geometry),properties:{...bt(o),...bt(n),...i?{style:i}:{}}})})(o,e))}remove(t){this.requireFeature(t),this.features.delete(t),this.states.delete(t),this.activeIds.delete(t),this.hiddenIds.delete(t)}clear(){this.features.clear(),this.states.clear(),this.activeIds.clear(),this.hiddenIds.clear()}setActive(t,e){this.requireFeature(t),e?this.activeIds.add(t):this.activeIds.delete(t)}setState(t,e){if(this.requireFeature(t),"normal"!==e&&"warning"!==e&&"alarm"!==e&&"disabled"!==e)throw new Error(`电子围栏 ${t} 的渲染状态无效。`);"normal"===e?this.states.delete(t):this.states.set(t,e)}setVisible(t,e){this.requireFeature(t),e?this.hiddenIds.delete(t):this.hiddenIds.add(t)}isActive(t){return this.activeIds.has(t)}getState(t){return this.requireFeature(t),this.states.get(t)||"normal"}get(t){const e=this.features.get(t);return e?bt(e):void 0}values(){return Array.from(this.features.values())}visibleValues(){return this.values().filter(t=>!this.hiddenIds.has(t.id))}requireFeature(t){const e=this.features.get(t);if(!e)throw new Error(`电子围栏不存在:${t}`);return e}}const xt=(t,e,o,n=!1)=>{const i=void 0===t?e:Number(t);if(!Number.isFinite(i)||n&&i<=0)throw new Error(`${o} 必须是${n?"大于 0 的":"有限"}数字。`);return i},At=(t,e)=>{if(!t.trim())throw new Error("电子围栏插件 id 不能为空。");xt(e.baseHeight,0,"defaults.baseHeight"),xt(e.height,0,"defaults.height",!0),xt(e.thickness,1,"defaults.thickness",!0)},Ft=t=>({baseHeight:xt(t.baseHeight,0,"defaults.baseHeight"),height:xt(t.height,0,"defaults.height",!0),thickness:xt(t.thickness,1,"defaults.thickness",!0)}),Ct=(t,e)=>"normal"!==t?t:e?"active":"normal",Pt=t=>{var e,o;return{...{...t.defaults.normal,...(null==(e=t.overrides)?void 0:e.normal)||{}},..."normal"===t.state?{}:{...t.defaults[t.state],...(null==(o=t.overrides)?void 0:o[t.state])||{}}}},St=(t,e)=>{const o=e/2,n=[];return t.coordinates.forEach(t=>{const e=[];for(let o=0;o<t.length-1;o+=1){const n=[t[o][0],t[o][1]],i=[t[o+1][0],t[o+1][1]],r=$(n,i);r<.01||e.push({start:n,end:i,length:r,bearing:k(n,i)})}const i=e.reduce((t,e)=>t+e.length,0);let r=0;e.forEach(t=>{const e=M(t.start,o,t.bearing+180),a=M(t.end,o,t.bearing);n.push({startLeft:M(e,o,t.bearing-90),startRight:M(e,o,t.bearing+90),endLeft:M(a,o,t.bearing-90),endRight:M(a,o,t.bearing+90),startProgress:i?r/i:0,endProgress:i?(r+t.length)/i:1}),r+=t.length})}),n},Ot=t=>({type:"MultiPolygon",coordinates:t.map(t=>[[t.startLeft,t.endLeft,t.endRight,t.startRight,t.startLeft]])}),Lt=(t,e,o)=>Math.min(o,Math.max(e,t)),Wt=t=>{const e=t.trim().toLowerCase();if(e.startsWith("#")){const t=e.slice(1),o=3===t.length||4===t.length?t.split("").map(t=>t+t).join(""):t;if(6===o.length||8===o.length){const t=Number.parseInt(o,16);if(Number.isFinite(t))return[(t>>(8===o.length?24:16)&255)/255,(t>>(8===o.length?16:8)&255)/255,(t>>(8===o.length?8:0)&255)/255,8===o.length?(255&t)/255:1]}}const o=e.match(/^rgba?\(([^)]+)\)$/);if(o){const t=o[1].split(",").map(t=>Number(t.trim()));if(t.length>=3&&t.every(t=>Number.isFinite(t)))return[Lt(t[0]/255,0,1),Lt(t[1]/255,0,1),Lt(t[2]/255,0,1),Lt(t[3]??1,0,1)]}throw new Error(`暂不支持的围栏颜色格式:${t}`)},Nt=(t,e=1)=>{const[o,n,i,r]=Wt(t);return`rgba(${Math.round(255*o)}, ${Math.round(255*n)}, ${Math.round(255*i)}, ${Lt(r*e,0,1)})`},qt=Lt,Gt=t=>({type:"FeatureCollection",features:t.visibleValues().map(t=>({type:"Feature",id:`${t.id}:interaction`,geometry:bt(t.geometry),properties:{[vt]:t.id}}))}),Et=t=>{let e;const o=e=>{var o;if(!t.map.getLayer(t.layerId))return;const n=t.map.queryRenderedFeatures(e.point,{layers:[t.layerId]})[0],i=null==(o=null==n?void 0:n.properties)?void 0:o[vt];return"string"==typeof i?i:void 0},n=(e,o,n)=>{const i=t.store.get(o);i&&t.map.fire(`fence.${e}`,{instanceId:t.instanceId,renderer:t.renderer,id:o,feature:i,originalEvent:n})},i=t=>{const e=o(t);e&&n("click",e,t)},r=t=>{const i=o(t);i!==e&&(e&&n("mouseleave",e,t),e=i,e&&n("mouseenter",e,t))},a=t=>{e&&(n("mouseleave",e,t),e=void 0)};return t.map.on("click",i),t.map.on("mousemove",r),t.map.on("mouseout",a),()=>{t.map.off("click",i),t.map.off("mousemove",r),t.map.off("mouseout",a)}},It=t=>t instanceof Error&&"Style is not done loading."===t.message,Rt=(t,e,o)=>{e.forEach(e=>{t.getLayer(e)&&t.setLayoutProperty(e,"visibility",o?"visible":"none")})},jt=t=>{let e=!1;const o=()=>{if(e)throw new Error(`电子围栏插件 ${t.id} 已销毁。`)};return{id:t.id,renderer:t.renderer,setData(e){o(),t.store.setData(e),t.refresh()},add(e){o();const n=t.store.add(e);return t.refresh(),n},update(e,n){o(),t.store.update(e,n),t.refresh()},removeFeature(e){o(),t.store.remove(e),t.refresh()},clear(){o(),t.store.clear(),t.refresh()},setFeatureState(e,n){o(),t.store.setState(e,n),t.refresh()},setFeatureActive(e,n){o(),t.store.setActive(e,n),t.refresh()},setFeatureVisible(e,n){o(),t.store.setVisible(e,n),t.refresh()},show(){o(),t.setPluginVisible(!0)},hide(){o(),t.setPluginVisible(!1)},destroy(){e||(e=!0,t.destroy())}}},Dt="__electronic_fence_kind",Tt="__electronic_fence_color",Vt="__electronic_fence_outline_color",Yt="__electronic_fence_outline_width",zt="__electronic_fence_base",Ut="__electronic_fence_top",Bt={normal:{color:"#d8b4fe",opacity:.28,outlineColor:"#f5e9ff",outlineWidth:1.5},active:{color:"#c084fc",opacity:.42,outlineColor:"#ffffff",outlineWidth:2.5},warning:{color:"#f59e0b",opacity:.38,outlineColor:"#fde68a",outlineWidth:2},alarm:{color:"#ef4444",opacity:.48,outlineColor:"#ffffff",outlineWidth:2.5},disabled:{color:"#94a3b8",opacity:.16,outlineColor:"#cbd5e1",outlineWidth:1}},Ht=(t,e)=>{const o=[],n=Ft(e.defaults);return t.visibleValues().forEach(i=>{const r=Ct(t.getState(i.id),t.isActive(i.id)),a=Pt({defaults:Bt,overrides:e.styles,state:r}),l=St(i.geometry,n.thickness),s={[vt]:i.id,[Tt]:Nt(a.color,qt(a.opacity,0,1)),[Vt]:Nt(a.outlineColor),[Yt]:Math.max(0,a.outlineWidth),[zt]:n.baseHeight,[Ut]:n.baseHeight+n.height};l.length&&o.push({type:"Feature",id:`${i.id}:wall`,geometry:Ot(l),properties:{...s,[Dt]:"wall"}}),o.push({type:"Feature",id:`${i.id}:boundary`,geometry:i.geometry,properties:{...s,[Dt]:"boundary"}})}),{type:"FeatureCollection",features:o}},Jt=[{thicknessScale:.08,opacity:1},{thicknessScale:.22,opacity:.56},{thicknessScale:.45,opacity:.28},{thicknessScale:.8,opacity:.12},{thicknessScale:1.3,opacity:.045}],Xt={normal:{color:"#d8b4fe",opacity:.2,outlineColor:"#f5e9ff",outlineWidth:1.5,glowStrength:1,flowColor:"#ffffff",flowCount:3,flowLineStyle:"dashed",flowWidth:.18},active:{color:"#e9d5ff",opacity:.28,outlineColor:"#ffffff",outlineWidth:2.5,glowStrength:1.25,flowColor:"#ffffff",flowCount:3,flowLineStyle:"dashed",flowWidth:.2},warning:{color:"#f59e0b",opacity:.25,outlineColor:"#fde68a",outlineWidth:2,glowStrength:1.1,flowColor:"#ffffff",flowCount:4,flowLineStyle:"dashed",flowWidth:.18},alarm:{color:"#ef4444",opacity:.3,outlineColor:"#ffffff",outlineWidth:2.5,glowStrength:1.35,flowColor:"#ffffff",flowCount:4,flowLineStyle:"dashed",flowWidth:.2},disabled:{color:"#94a3b8",opacity:.12,outlineColor:"#cbd5e1",outlineWidth:1,glowStrength:0,flowColor:"#ffffff",flowCount:0,flowLineStyle:"dashed",flowWidth:0}},Kt=(e,o)=>{const n=t.MercatorCoordinate.fromLngLat(e,o);return[n.x,n.y,n.z]},Qt=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Zt=(t,e,o)=>{const n=Qt(e,t),i=Qt(o,t);return(t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]})([n[1]*i[2]-n[2]*i[1],n[2]*i[0]-n[0]*i[2],n[0]*i[1]-n[1]*i[0]])},te=(t,e,o,n,i)=>{const r=Zt(e[0],e[1],e[2]);[0,1,2,0,2,3].forEach(a=>{((t,e,o,n,i,r)=>{t.push(...e,...o,n,i,...r.color,r.flowColor[0],r.flowColor[1],r.flowColor[2],r.glowStrength,r.flowWidth,r.flowCount,r.flowLineStyle)})(t,e[a],r,o[a],n[a],i)})},ee=(t,e,o,n,i)=>{const r=o+n,a=Kt(e.startLeft,o),l=Kt(e.startRight,o),s=Kt(e.endLeft,o),c=Kt(e.endRight,o),d=Kt(e.startLeft,r),f=Kt(e.startRight,r),h=Kt(e.endLeft,r),p=Kt(e.endRight,r);te(t,[d,h,p,f],[1,1,1,1],[e.startProgress,e.endProgress,e.endProgress,e.startProgress],i),te(t,[a,s,h,d],[0,0,1,1],[e.startProgress,e.endProgress,e.endProgress,e.startProgress],i),te(t,[c,l,f,p],[0,0,1,1],[e.endProgress,e.startProgress,e.startProgress,e.endProgress],i)},oe=(t,e,o)=>{const n=Jt.map(()=>[]),i=[],r=Ft(e.defaults);let a=!1;t.visibleValues().forEach(l=>{const s=t.isActive(l.id),c=Ct(t.getState(l.id),s),d=Pt({defaults:Xt,overrides:e.styles,state:c}),f=o.enabled&&("all"===o.scope||(t=>"active"===t||"warning"===t||"alarm"===t)(c)),h=((t,e)=>{const o=Wt(t.color),n=Wt(t.flowColor),i=e&&t.flowCount>0?Math.round(qt(t.flowCount,1,8)):0;return{color:[o[0],o[1],o[2],qt(o[3]*t.opacity,0,1)],flowColor:n,glowStrength:qt(t.glowStrength,0,4),flowCount:i,flowLineStyle:"solid"===t.flowLineStyle?0:1,flowWidth:i>0?qt(t.flowWidth,.01,.49):0}})(d,f);St(l.geometry,r.thickness).forEach(t=>{ee(i,t,r.baseHeight,r.height,h)}),h.glowStrength>0&&Jt.forEach((t,e)=>{const o=r.thickness*(1+Math.min(h.glowStrength,2)*t.thicknessScale);St(l.geometry,o).forEach(t=>{ee(n[e],t,r.baseHeight,r.height,h)})}),a||(a=h.flowCount>0&&h.flowWidth>0)});const l=n.reduce((t,e)=>t+e.length,0),s=new Float32Array(l+i.length),c=[];let d=0;n.forEach((t,e)=>{const o=t.length/19;o>0&&c.push({first:d/19,count:o,opacity:Jt[e].opacity}),s.set(t,d),d+=t.length});const f=d/19;return s.set(i,d),{vertices:s,glowPasses:c,bodyFirst:f,bodyVertexCount:i.length/19,animated:a}},ne=(t,e,o)=>{const n=t.createShader(e);if(!n)throw new Error("无法创建电子围栏 WebGL shader。");if(t.shaderSource(n,o),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const e=t.getShaderInfoLog(n)||"未知 shader 编译错误";throw t.deleteShader(n),new Error(`电子围栏 WebGL shader 编译失败:${e}`)}return n},ie=(t,e,o)=>{const n=t.getUniformLocation(e,o);if(!n)throw new Error(`电子围栏 WebGL uniform 不存在:${o}`);return n};class re{constructor(t,e){this.type="custom",this.renderingMode="3d",this.geometry={vertices:new Float32Array,glowPasses:[],bodyFirst:0,bodyVertexCount:0,animated:!1},this.visible=!0,this.id=t,this.animation=e}setGeometry(t){var e;this.geometry=t,this.uploadGeometry(),null==(e=this.map)||e.triggerRepaint()}setVisible(t){var e;this.visible=t,null==(e=this.map)||e.triggerRepaint()}onAdd(t,e){if(this.map=t,this.gl=e,this.program=(t=>{const e="undefined"!=typeof WebGL2RenderingContext&&t instanceof WebGL2RenderingContext,o=e?"#version 300 es\n precision highp float;\n in vec3 a_position;\n in vec3 a_normal;\n in float a_height_ratio;\n in float a_path_progress;\n in vec4 a_color;\n in vec3 a_flow_color;\n in float a_glow_strength;\n in float a_flow_width;\n in float a_flow_count;\n in float a_flow_line_style;\n uniform mat4 u_matrix;\n out vec3 v_normal;\n out float v_height_ratio;\n out float v_path_progress;\n out vec4 v_color;\n out vec3 v_flow_color;\n out float v_glow_strength;\n out float v_flow_width;\n out float v_flow_count;\n out float v_flow_line_style;\n void main() {\n gl_Position = u_matrix * vec4(a_position, 1.0);\n v_normal = a_normal;\n v_height_ratio = a_height_ratio;\n v_path_progress = a_path_progress;\n v_color = a_color;\n v_flow_color = a_flow_color;\n v_glow_strength = a_glow_strength;\n v_flow_width = a_flow_width;\n v_flow_count = a_flow_count;\n v_flow_line_style = a_flow_line_style;\n }\n ":"\n precision highp float;\n attribute vec3 a_position;\n attribute vec3 a_normal;\n attribute float a_height_ratio;\n attribute float a_path_progress;\n attribute vec4 a_color;\n attribute vec3 a_flow_color;\n attribute float a_glow_strength;\n attribute float a_flow_width;\n attribute float a_flow_count;\n attribute float a_flow_line_style;\n uniform mat4 u_matrix;\n varying vec3 v_normal;\n varying float v_height_ratio;\n varying float v_path_progress;\n varying vec4 v_color;\n varying vec3 v_flow_color;\n varying float v_glow_strength;\n varying float v_flow_width;\n varying float v_flow_count;\n varying float v_flow_line_style;\n void main() {\n gl_Position = u_matrix * vec4(a_position, 1.0);\n v_normal = a_normal;\n v_height_ratio = a_height_ratio;\n v_path_progress = a_path_progress;\n v_color = a_color;\n v_flow_color = a_flow_color;\n v_glow_strength = a_glow_strength;\n v_flow_width = a_flow_width;\n v_flow_count = a_flow_count;\n v_flow_line_style = a_flow_line_style;\n }\n ",n="\n precision highp float;\n uniform float u_time;\n uniform float u_speed;\n uniform float u_animation_enabled;\n uniform float u_glow_pass;\n uniform float u_glow_opacity;\n VARYING vec3 v_normal;\n VARYING float v_height_ratio;\n VARYING float v_path_progress;\n VARYING vec4 v_color;\n VARYING vec3 v_flow_color;\n VARYING float v_glow_strength;\n VARYING float v_flow_width;\n VARYING float v_flow_count;\n VARYING float v_flow_line_style;\n void main() {\n float bandCore = 0.0;\n float bandGlow = 0.0;\n float verticalFace = 1.0 - smoothstep(\n 0.82,\n 0.98,\n abs(normalize(v_normal).z)\n );\n\n if (\n u_animation_enabled > 0.5 &&\n v_flow_count > 0.5 &&\n v_flow_width > 0.0001\n ) {\n float count = max(v_flow_count, 1.0);\n float phase = fract(\n v_height_ratio * count + u_time * u_speed * count\n );\n float bandDistance = abs(phase - 0.5);\n float dashPhase = fract(\n v_path_progress * 36.0 - u_time * u_speed * 2.4\n );\n float dash = smoothstep(0.02, 0.1, dashPhase) *\n (1.0 - smoothstep(0.62, 0.74, dashPhase));\n float linePattern = v_flow_line_style > 0.5 ? dash : 1.0;\n\n bandCore = 1.0 - smoothstep(\n max(v_flow_width * 0.08, 0.001),\n max(v_flow_width * 0.42, 0.003),\n bandDistance\n );\n float glowDistance = bandDistance / max(v_flow_width, 0.001);\n bandGlow = exp(\n -glowDistance * glowDistance * 2.6\n );\n bandCore *= linePattern * verticalFace;\n bandGlow *= verticalFace;\n }\n\n if (u_glow_pass > 0.5) {\n float glowAlpha = clamp(\n (v_color.a * 0.003 + bandGlow * 0.085) *\n v_glow_strength * u_glow_opacity,\n 0.0,\n 0.14\n );\n OUTPUT_COLOR = vec4(v_color.rgb, glowAlpha);\n return;\n }\n\n float faceLight = 0.88 + 0.12 * abs(normalize(v_normal).z);\n vec3 bodyColor = v_color.rgb * faceLight;\n vec3 color = mix(bodyColor, v_flow_color, bandCore);\n float alpha = clamp(\n v_color.a + bandCore * 0.68,\n 0.0,\n 1.0\n );\n OUTPUT_COLOR = vec4(color, alpha);\n }\n ",i=(t,e,o)=>t.split(e).join(o),r=e?`#version 300 es\n ${i(i(n,"VARYING","in"),"OUTPUT_COLOR","fragmentColor").replace("precision highp float;","precision highp float;\n out vec4 fragmentColor;")}\n `:i(i(n,"VARYING","varying"),"OUTPUT_COLOR","gl_FragColor"),a=ne(t,t.VERTEX_SHADER,o),l=ne(t,t.FRAGMENT_SHADER,r),s=t.createProgram();if(!s)throw t.deleteShader(a),t.deleteShader(l),new Error("无法创建电子围栏 WebGL program。");if(t.attachShader(s,a),t.attachShader(s,l),t.linkProgram(s),t.deleteShader(a),t.deleteShader(l),!t.getProgramParameter(s,t.LINK_STATUS)){const e=t.getProgramInfoLog(s)||"未知 program 链接错误";throw t.deleteProgram(s),new Error(`电子围栏 WebGL program 链接失败:${e}`)}return s})(e),this.locations=((t,e)=>({position:t.getAttribLocation(e,"a_position"),normal:t.getAttribLocation(e,"a_normal"),heightRatio:t.getAttribLocation(e,"a_height_ratio"),pathProgress:t.getAttribLocation(e,"a_path_progress"),color:t.getAttribLocation(e,"a_color"),flowColor:t.getAttribLocation(e,"a_flow_color"),glowStrength:t.getAttribLocation(e,"a_glow_strength"),flowWidth:t.getAttribLocation(e,"a_flow_width"),flowCount:t.getAttribLocation(e,"a_flow_count"),flowLineStyle:t.getAttribLocation(e,"a_flow_line_style"),matrix:ie(t,e,"u_matrix"),time:ie(t,e,"u_time"),speed:ie(t,e,"u_speed"),animationEnabled:ie(t,e,"u_animation_enabled"),glowPass:ie(t,e,"u_glow_pass"),glowOpacity:ie(t,e,"u_glow_opacity")}))(e,this.program),this.buffer=e.createBuffer()||void 0,!this.buffer)throw new Error("无法创建电子围栏 WebGL 顶点缓冲。");this.uploadGeometry(e)}render(t,e){if(!(this.visible&&this.program&&this.buffer&&this.locations&&(this.geometry.glowPasses.length||this.geometry.bodyVertexCount)))return;const o=19*Float32Array.BYTES_PER_ELEMENT,n=(e,n,i)=>{t.enableVertexAttribArray(e),t.vertexAttribPointer(e,n,t.FLOAT,!1,o,i*Float32Array.BYTES_PER_ELEMENT)};t.useProgram(this.program),t.bindBuffer(t.ARRAY_BUFFER,this.buffer),n(this.locations.position,3,0),n(this.locations.normal,3,3),n(this.locations.heightRatio,1,6),n(this.locations.pathProgress,1,7),n(this.locations.color,4,8),n(this.locations.flowColor,3,12),n(this.locations.glowStrength,1,15),n(this.locations.flowWidth,1,16),n(this.locations.flowCount,1,17),n(this.locations.flowLineStyle,1,18),t.uniformMatrix4fv(this.locations.matrix,!1,e.defaultProjectionData.mainMatrix),t.uniform1f(this.locations.time,performance.now()/1e3),t.uniform1f(this.locations.speed,this.animation.speed),t.uniform1f(this.locations.animationEnabled,this.animation.enabled?1:0),t.enable(t.BLEND),t.enable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.depthMask(!1),this.geometry.glowPasses.length&&(t.blendFunc(t.SRC_ALPHA,t.ONE),t.uniform1f(this.locations.glowPass,1),this.geometry.glowPasses.forEach(e=>{t.uniform1f(this.locations.glowOpacity,e.opacity),t.drawArrays(t.TRIANGLES,e.first,e.count)})),this.geometry.bodyVertexCount&&(t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA),t.uniform1f(this.locations.glowPass,0),t.uniform1f(this.locations.glowOpacity,0),t.drawArrays(t.TRIANGLES,this.geometry.bodyFirst,this.geometry.bodyVertexCount)),t.depthMask(!0),t.bindBuffer(t.ARRAY_BUFFER,null)}onRemove(t,e){this.buffer&&e.deleteBuffer(this.buffer),this.program&&e.deleteProgram(this.program),this.map=void 0,this.gl=void 0,this.buffer=void 0,this.program=void 0,this.locations=void 0}uploadGeometry(t){const e=t||this.gl;e&&this.buffer&&(e.bindBuffer(e.ARRAY_BUFFER,this.buffer),e.bufferData(e.ARRAY_BUFFER,this.geometry.vertices,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null))}}const ae=(t,e)=>t?"string"==typeof t&&y(t)?m(t,{token:e}):t:m("openfreemap-liberty");exports.maplibregl=t,exports.BASE_MAP_TYPES=g,exports.OPENFREEMAP_STYLES=r,exports.OPENFREEMAP_STYLE_BASE_URL=n,exports.OPENFREEMAP_STYLE_TYPES=a,exports.TDT_STYLE_TYPES=["tdt-image","tdt-image-label","tdt-mvt","tdt-mvt-label"],exports.addBreachAlert=(t,e)=>{const o=e.id,n=`${o}-fence-source`,i=`${o}-fence-fill`,r=`${o}-fence-line`,a=`${o}-ripple-source`,l=`${o}-ripple-line`;let s,c,d,f={...e},h=!1,p=!1,u=!1,g=!1,y=0;const m=()=>f.fenceColor??"#1677ff",_=()=>f.fenceFillColor??m(),w=()=>f.fenceFillOpacity??.1,v=()=>f.fenceBorderWidth??2,b=()=>f.fenceBorderOpacity??.9,M=()=>f.fenceAlertColor??"#ff3b30",$=()=>f.rippleColor??M(),k=e=>{const o=t.getSource(a);o&&o.setData(e)},x=t=>{const e=Math.max(20,f.rippleRadius??800),o=Math.max(1,f.rippleCount??3),n=Math.max(400,f.rippleDuration??1500),i=Math.max(1,f.rippleLineWidth??3),r=performance.now(),a=l=>{k(((t,e,o,n,i,r)=>{const a=[];for(let l=0;l<o;l+=1){const s=(r/n+l/o)%1,c=s*e;c<1||a.push(L(C(t,c),{kind:"ring",opacity:.95*(1-s),width:i*(1-.3*s)}))}return W(a)})(t,e,o,n,i,l-r)),y=requestAnimationFrame(a)};y=requestAnimationFrame(a)},A=()=>{if(!u)return;const e=m(),o=_();t.getLayer(i)&&(t.setPaintProperty(i,"fill-color",o),t.setPaintProperty(i,"fill-opacity",w())),t.getLayer(r)&&(t.setPaintProperty(r,"line-color",e),t.setPaintProperty(r,"line-width",v()),t.setPaintProperty(r,"line-opacity",b()))},F=()=>{const e=f.tacticalColor??M(),o=Math.max(1,f.tacticalBorderWidth??4),n="viewport"===f.tacticalScope?12:0,i=Math.max(60,f.fenceFlashInterval??200),r=t.getContainer(),a=document.createElement("div");a.style.position="absolute",a.style.inset=`${n}px`,a.style.border=`${o}px solid ${e}`,a.style.boxShadow=`inset 0 0 ${6*o}px ${e}`,a.style.pointerEvents="none",a.style.zIndex="5",a.style.opacity="1",r.appendChild(a),d=a;let l=!0;c=setInterval(()=>{l=!l,a.style.opacity=l?"1":"0.15"},i)},P=()=>{const e=(t=>{if(!t)return[];if(Array.isArray(t))return[{type:"Polygon",coordinates:t}];switch(t.type){case"Polygon":return[t];case"MultiPolygon":return t.coordinates.map(t=>({type:"Polygon",coordinates:t}));case"Feature":{const e=t.geometry;return"Polygon"===(null==e?void 0:e.type)?[e]:"MultiPolygon"===(null==e?void 0:e.type)?e.coordinates.map(t=>({type:"Polygon",coordinates:t})):[]}case"FeatureCollection":{const e=[];for(const o of t.features){const t=o.geometry;"Polygon"===(null==t?void 0:t.type)?e.push(t):"MultiPolygon"===(null==t?void 0:t.type)&&e.push(...t.coordinates.map(t=>({type:"Polygon",coordinates:t})))}return e}default:return[]}})(f.fence);if(0===e.length)return;const o=W(e.map(t=>L(t,{kind:"fence"})));if(u){const e=t.getSource(n);e&&e.setData(o),A()}else t.getSource(n)?t.getSource(n).setData(o):t.addSource(n,{type:"geojson",data:o}),t.getLayer(i)||t.addLayer({id:i,type:"fill",source:n,filter:["==",["get","kind"],"fence"],paint:{"fill-color":_(),"fill-opacity":w()}},f.beforeId),t.getLayer(r)||t.addLayer({id:r,type:"line",source:n,filter:["==",["get","kind"],"fence"],paint:{"line-color":m(),"line-width":v(),"line-opacity":b()}},f.beforeId),u=!0,G(t,[i,r],!1!==f.visible)},S=()=>{p&&!h&&O()},O=()=>{if(!h)try{P(),t.getSource(a)||t.addSource(a,{type:"geojson",data:W([])}),t.getLayer(l)?t.getLayer(l)&&t.setPaintProperty(l,"line-color",$()):(t.addLayer({id:l,type:"line",source:a,filter:["==",["get","kind"],"ring"],paint:{"line-color":$(),"line-opacity":["coalesce",["get","opacity"],.9],"line-width":["coalesce",["get","width"],3]}},f.beforeId),G(t,[l],!1!==f.visible)),p=!1,t.off("styledata",S)}catch(e){if(!E(e))throw e;p||(p=!0,t.on("styledata",S))}},I=()=>{s&&(clearInterval(s),s=void 0),y&&(cancelAnimationFrame(y),y=0),k(W([])),c&&(clearInterval(c),c=void 0),d&&(d.remove(),d=void 0),A()};return O(),{id:o,update(t){h||(f={...f,...t,id:o},O())},show(){h||(f={...f,visible:!0},G(t,[i,r,l],!0))},hide(){h||(f={...f,visible:!1},G(t,[i,r,l],!1))},remove(){h||(h=!0,p&&(p=!1,t.off("styledata",S)),I(),N(t,l),N(t,r),N(t,i),q(t,a),q(t,n),u=!1)},trigger(e){if(h)return;g&&I();const o=e??f.center;g=!0,!1!==f.fenceFlash&&(()=>{if(!u)return;const e=M(),o=Math.max(60,f.fenceFlashInterval??200);let n=!0;t.getLayer(i)&&(t.setPaintProperty(i,"fill-color",e),t.setPaintProperty(i,"fill-opacity",.42)),t.getLayer(r)&&(t.setPaintProperty(r,"line-color",e),t.setPaintProperty(r,"line-opacity",1)),s=setInterval(()=>{n=!n;const e=n?.42:.08,o=n?1:.4;t.getLayer(i)&&t.setPaintProperty(i,"fill-opacity",e),t.getLayer(r)&&t.setPaintProperty(r,"line-opacity",o)},o)})(),!1!==f.ripple&&x(o),f.tacticalFlash&&F()},reset(){h||(I(),g=!1)},isActive:()=>g}},exports.addBreathingCircle=(t,e)=>I(t,e,T),exports.addCoordinatedCountermeasure=(t,e)=>I(t,e,mt),exports.addCountermeasureBeam=(t,e)=>I(t,e,gt),exports.addDefenceCircle=(t,e)=>I(t,e,pt),exports.addDirectionalPulse=(t,e)=>I(t,e,at),exports.addNavigationSpoofing=(t,e)=>I(t,e,wt),exports.addPulseMarker=(t,e)=>I(t,e,j),exports.addRadarSweep=(t,e)=>I(t,e,ft),exports.addRingPulseMarker=(t,e)=>I(t,e,Y),exports.addSectorScan=(t,e)=>I(t,e,it),exports.addStandardElectronicFenceLayer=(t,e)=>{At(e.id,e.defaults);const o=new kt,n=`${e.id}-standard-source`,i=`${e.id}-standard-extrusion`,r=`${e.id}-standard-outline`,a=`${e.id}-standard-interaction`,l=[i,r,...!1===e.interactive?[]:[a]];let s=Ht(o,e),c=!1!==e.visible,d=!1;const f=()=>{if(!d)try{t.getSource(n)||t.addSource(n,{type:"geojson",data:s}),t.getLayer(i)||t.addLayer({id:i,type:"fill-extrusion",source:n,filter:["==",["get",Dt],"wall"],paint:{"fill-extrusion-color":["get",Tt],"fill-extrusion-opacity":1,"fill-extrusion-base":["get",zt],"fill-extrusion-height":["get",Ut],"fill-extrusion-vertical-gradient":!0}},e.beforeId),t.getLayer(r)||t.addLayer({id:r,type:"line",source:n,filter:["==",["get",Dt],"boundary"],paint:{"line-color":["get",Vt],"line-width":["get",Yt],"line-opacity":1}},e.beforeId),!1===e.interactive||t.getLayer(a)||t.addLayer({id:a,type:"fill",source:n,filter:["==",["get",Dt],"boundary"],paint:{"fill-color":"#000000","fill-opacity":0}},e.beforeId),Rt(t,l,c)}catch(o){if(!It(o))throw o}},h=()=>{f()};t.on("styledata",h),f();const p=!1===e.interactive?()=>{}:Et({map:t,instanceId:e.id,renderer:"standard",layerId:a,store:o});return jt({id:e.id,renderer:"standard",store:o,refresh:()=>{s=Ht(o,e);const i=t.getSource(n);i?i.setData(s):f()},setPluginVisible(e){c=e,f(),Rt(t,l,c)},destroy(){d=!0,t.off("styledata",h),p(),[...l].reverse().forEach(e=>{t.getLayer(e)&&t.removeLayer(e)}),t.getSource(n)&&t.removeSource(n)}})},exports.addTargetLock=(e,o)=>{const n=o.id;let i,r={...o},a=!1;const l=document.createElement("div"),s=document.createElement("div"),c=Array.from({length:4},()=>document.createElement("div")),d=Array.from({length:4},()=>document.createElement("div"));l.dataset.effectId=n,l.setAttribute("aria-hidden","true"),l.style.position="absolute",l.style.pointerEvents="none",s.style.position="absolute",s.style.inset="0",l.appendChild(s),c.forEach(t=>{t.style.position="absolute",t.style.boxSizing="border-box",s.appendChild(t)}),d.forEach(t=>{t.style.position="absolute",l.appendChild(t)});const f=new t.Marker({element:l,anchor:"center"}).setLngLat(r.center).addTo(e),h=()=>{const t=r.color??"#ff3b30",e=Math.max(24,r.size??72),o=Math.max(1,r.lineWidth??2),n=Math.min(e/2,Math.max(2*o,r.cornerLength??18)),a=Math.max(2,r.crosshairLength??10),h=Math.max(0,r.crosshairGap??5);f.setLngLat(r.center),l.style.width=`${e}px`,l.style.height=`${e}px`,l.style.display=!1===r.visible?"none":"block",l.style.opacity=`${Math.min(1,Math.max(0,r.opacity??1))}`,c.forEach(t=>{t.style.width=`${n}px`,t.style.height=`${n}px`,t.style.border="0"}),Object.assign(c[0].style,{left:"0",top:"0",borderLeft:`${o}px solid ${t}`,borderTop:`${o}px solid ${t}`}),Object.assign(c[1].style,{right:"0",top:"0",borderRight:`${o}px solid ${t}`,borderTop:`${o}px solid ${t}`}),Object.assign(c[2].style,{right:"0",bottom:"0",borderRight:`${o}px solid ${t}`,borderBottom:`${o}px solid ${t}`}),Object.assign(c[3].style,{left:"0",bottom:"0",borderLeft:`${o}px solid ${t}`,borderBottom:`${o}px solid ${t}`}),d.forEach(e=>{e.style.display=!1===r.showCrosshair?"none":"block",e.style.background=t}),Object.assign(d[0].style,{width:`${o}px`,height:`${a}px`,left:"50%",bottom:`calc(50% + ${h}px)`,transform:"translateX(-50%)"}),Object.assign(d[1].style,{width:`${o}px`,height:`${a}px`,left:"50%",top:`calc(50% + ${h}px)`,transform:"translateX(-50%)"}),Object.assign(d[2].style,{width:`${a}px`,height:`${o}px`,right:`calc(50% + ${h}px)`,top:"50%",transform:"translateY(-50%)"}),Object.assign(d[3].style,{width:`${a}px`,height:`${o}px`,left:`calc(50% + ${h}px)`,top:"50%",transform:"translateY(-50%)"}),null==i||i.cancel(),i=void 0,s.style.transform="rotate(0deg)",!1!==r.rotate&&(i=s.animate([{transform:"rotate(0deg)"},{transform:"rotate(360deg)"}],{duration:Math.max(300,r.rotationDuration??2400),iterations:1/0}))};return h(),{id:n,update(t){a||(r={...r,...t,id:n},h())},show(){a||(r={...r,visible:!0},l.style.display="block")},hide(){a||(r={...r,visible:!1},l.style.display="none")},remove(){a||(a=!0,null==i||i.cancel(),i=void 0,f.remove())}}},exports.addWebGLElectronicFenceLayer=(t,e)=>{At(e.id,e.defaults);const o=(t=>({enabled:(null==t?void 0:t.enabled)??!0,fps:Math.round(qt((null==t?void 0:t.fps)??30,1,60)),speed:Math.max(0,(null==t?void 0:t.speed)??.35),scope:(null==t?void 0:t.scope)??"all"}))(e.animation),n=new kt,i=`${e.id}-webgl`,r=`${e.id}-webgl-interaction-source`,a=`${e.id}-webgl-interaction`,l=new re(i,o);let s=Gt(n),c=oe(n,e,o),d=!1!==e.visible,f=!1,h=0,p=0;const u=()=>{h&&(cancelAnimationFrame(h),h=0)},g=e=>{!f&&d&&c.animated?(("undefined"==typeof document||!document.hidden)&&e-p>=1e3/o.fps&&(p=e,t.triggerRepaint()),h=requestAnimationFrame(g)):h=0},y=()=>{const e=o.enabled&&d&&c.animated&&!!t.getLayer(i);e&&!h?(p=0,h=requestAnimationFrame(g)):e||u()},m=()=>{if(!f)try{!1===e.interactive||t.getSource(r)||t.addSource(r,{type:"geojson",data:s}),t.getLayer(i)||t.addLayer(l,e.beforeId),!1===e.interactive||t.getLayer(a)||t.addLayer({id:a,type:"fill",source:r,paint:{"fill-color":"#000000","fill-opacity":0}},e.beforeId),l.setVisible(d),Rt(t,!1===e.interactive?[]:[a],d),y()}catch(o){if(!It(o))throw o}},_=()=>{m()};l.setGeometry(c),t.on("styledata",_),m();const w=!1===e.interactive?()=>{}:Et({map:t,instanceId:e.id,renderer:"webgl",layerId:a,store:n});return jt({id:e.id,renderer:"webgl",store:n,refresh:()=>{c=oe(n,e,o),s=Gt(n),l.setGeometry(c);const i=t.getSource(r);i&&i.setData(s),m(),y()},setPluginVisible(o){d=o,l.setVisible(d),m(),Rt(t,!1===e.interactive?[]:[a],d),y()},destroy(){f=!0,u(),t.off("styledata",_),w(),t.getLayer(a)&&t.removeLayer(a),t.getLayer(i)&&t.removeLayer(i),t.getSource(r)&&t.removeSource(r)}})},exports.createFenceCircle=(t,e,o)=>F(t,e,o),exports.createMap=e=>{const{style:o,tdtToken:n,projection:i,...r}=e,a=new t.Map({...r,style:ae(o,n)});return i&&a.on("style.load",()=>{a.setProjection({type:i})}),a},exports.createTiandituImageStyle=p,exports.createTiandituRasterSource=f,exports.getBaseMapStyle=m,exports.getMaplibreToolsConfig=o,exports.getOpenFreeMapStyle=l,exports.isBaseMapType=y,exports.setBaseMap=(t,e,o={})=>{const{diff:n=!1,...i}=o;t.setStyle(m(e,i),{diff:n})},exports.setMaplibreToolsConfig=t=>{Object.assign(e,t)};
|