zhihao-ui 1.3.16 → 1.3.18

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.
@@ -1,2007 +0,0 @@
1
- import { defineComponent, openBlock, createElementBlock, createElementVNode, ref, computed, h, createVNode, render, reactive, onMounted, onUnmounted } from "vue";
2
- import { S as ScaleLine$1, M as Map$2, T as TileLayer, X as XYZ, p as fromLonLat, V as View, q as defaults, t as toLonLat, h as hooks, r as getLength, s as transformExtent, u as Text, F as Fill, v as Style, O as Overlay, P as Point, w as transform, x as debounce, L as LineString, y as buffer, z as Polyline, A as Feature, B as VectorLayer, C as VectorSource, D as Stroke, i as cloneDeep, G as CircleStyle, H as getVectorContext, I as Icon, J as VectorImageLayer, K as Circle, N as DoubleClickZoom, Q as Draw, R as unByKey, U as getUid, W as getArea, Y as getCenter, Z as MultiPoint } from "./vendor-D2mv9LHk.js";
3
- import { _ as _export_sfc } from "./Button-CGndQwez.js";
4
- import { w as withInstall } from "./utils-D2wHR1YB.js";
5
- const _hoisted_1$2 = { id: "scale-line-container" }, _sfc_main$2 = /* @__PURE__ */ defineComponent({
6
- __name: "scaleLine",
7
- setup(e, { expose: n }) {
8
- return n({
9
- setScaleLine: (s, a) => {
10
- a || (a = "metric");
11
- const o = new ScaleLine$1({
12
- units: a
13
- }), y = document.getElementById("scale-line-container");
14
- y && (o.setTarget(y), s.addControl(o));
15
- }
16
- }), (s, a) => (openBlock(), createElementBlock("div", _hoisted_1$2));
17
- }
18
- }), ScaleLine = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-2bc5dee8"]]), _hoisted_1$1 = { class: "zoom" }, _sfc_main$1 = /* @__PURE__ */ defineComponent({
19
- __name: "zoomControl",
20
- props: {
21
- mapInstance: {
22
- type: Object,
23
- default: () => null
24
- }
25
- },
26
- setup(e) {
27
- const n = e;
28
- console.log("props", n);
29
- const l = () => {
30
- console.log("props");
31
- const { setZoom: a, getZoom: o, getInstall: y } = n.mapInstance.methods;
32
- if (!y()) return;
33
- const t = o();
34
- t && a(t + 1);
35
- }, s = () => {
36
- const { setZoom: a, getZoom: o, getInstall: y } = n.mapInstance.methods;
37
- if (!y()) return;
38
- const t = o();
39
- t && a(t - 1);
40
- };
41
- return (a, o) => (openBlock(), createElementBlock("div", _hoisted_1$1, [
42
- createElementVNode("div", {
43
- class: "button big-button",
44
- onClick: l
45
- }, " + "),
46
- createElementVNode("div", {
47
- class: "button small-button",
48
- onClick: s
49
- }, " - ")
50
- ]));
51
- }
52
- }), ZoomControl = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-c39c3075"]]), TIAN_DI_TU_KEY = "a6e8f78974f2581f2ca00485b40c948f", MAP_ZOOM = {
53
- // 地图默认层级
54
- default: 13,
55
- // 地图缩放最小层级
56
- min: 3,
57
- // 地图缩放最大层级
58
- max: 18,
59
- // 船形图标最小渲染层级
60
- shipModelMin: 13,
61
- // 船形图标最小渲染层级
62
- shipTriggleMin: 16,
63
- // 船形图标最大渲染层级
64
- shipModelMax: 18,
65
- //根据原系统canvas图片转换svg长宽比例计算缩放值
66
- scaleNum: 0.555
67
- }, projection = {
68
- // 经纬度 源数据 地理坐标 WGS84
69
- data: "EPSG:4326",
70
- // 墨卡托投影坐标 渲染坐标
71
- mercator: "EPSG:3857"
72
- }, MAP_DEFAULT_CENTER = [114.84, 30.52], CDN_URL = "https://static.zhihaoscm.cn/", equatorialCircumference = 2003750834e-2;
73
- var BASE_MAP_LINK = ((e) => (e.vectorTile = `https://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&TILEMATRIXSET=w&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${TIAN_DI_TU_KEY}`, e.vectorTileMark = `https://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&TILEMATRIXSET=w&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${TIAN_DI_TU_KEY}`, e.satelliteImgTile = `https://t0.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&TILEMATRIXSET=w&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${TIAN_DI_TU_KEY}`, e.satelliteImgTileMark = `https://t0.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&TILEMATRIXSET=w&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${TIAN_DI_TU_KEY}`, e.greenTile = `${CDN_URL}/map/tile/{z}/{x}/{y}.png`, e))(BASE_MAP_LINK || {}), LENGTH_UNIT = /* @__PURE__ */ ((e) => (e[e.M = 1] = "M", e[e.KM = 2] = "KM", e[e.NM = 3] = "NM", e))(LENGTH_UNIT || {});
74
- function useMapInitializer() {
75
- const e = ref(), n = () => e.value, l = () => n().getView(), s = () => {
76
- var m;
77
- return (m = l()) == null ? void 0 : m.getZoom();
78
- }, a = (m) => {
79
- var N;
80
- (N = l()) == null || N.setZoom(m);
81
- }, o = (m, N) => {
82
- var D;
83
- (D = l()) == null || D.setCenter(fromLonLat([m, N]));
84
- }, y = () => {
85
- var N;
86
- const m = (N = l()) == null ? void 0 : N.getCenter();
87
- return toLonLat(m);
88
- }, T = () => {
89
- var m;
90
- return (m = n()) == null ? void 0 : m.getSize();
91
- }, t = new Map$2(), r = (m, N) => {
92
- g(N);
93
- const D = {
94
- zoom: N.zoom,
95
- center: fromLonLat(N.center),
96
- minZoom: MAP_ZOOM.min,
97
- maxZoom: MAP_ZOOM.max,
98
- constrainResolution: !0,
99
- enableRotation: !1,
100
- multiWorld: !0
101
- }, v = new Map$2({
102
- target: m,
103
- controls: defaults({
104
- zoom: !1
105
- }),
106
- layers: [
107
- t.get("vectorTile"),
108
- t.get("vectorTileMark"),
109
- t.get("satelliteImgTile"),
110
- t.get("satelliteImgTileMark")
111
- ],
112
- view: new View(D)
113
- });
114
- e.value = v;
115
- }, g = (m) => {
116
- t.set("vectorTile", new TileLayer({
117
- source: new XYZ({ url: BASE_MAP_LINK.vectorTile }),
118
- visible: m.layerType === "vector",
119
- zIndex: 0,
120
- preload: 1,
121
- className: "vector"
122
- })), t.set("vectorTileMark", new TileLayer({
123
- source: new XYZ({ url: BASE_MAP_LINK.vectorTileMark }),
124
- visible: m.layerType === "vector",
125
- zIndex: 1,
126
- preload: 1,
127
- className: "vector"
128
- })), t.set("satelliteImgTile", new TileLayer({
129
- source: new XYZ({ url: BASE_MAP_LINK.satelliteImgTile }),
130
- visible: m.layerType === "satellite",
131
- zIndex: 0,
132
- preload: 1,
133
- className: "satellite"
134
- })), t.set("satelliteImgTileMark", new TileLayer({
135
- source: new XYZ({ url: BASE_MAP_LINK.satelliteImgTileMark }),
136
- visible: m.layerType === "satellite",
137
- zIndex: 1,
138
- preload: 1,
139
- className: "satellite"
140
- })), t.set("greenMark", new TileLayer({
141
- source: new XYZ({ url: BASE_MAP_LINK.greenTile }),
142
- visible: m.showGreenLayer,
143
- zIndex: 2,
144
- className: "greenTile"
145
- }));
146
- };
147
- return {
148
- getInstall: n,
149
- getView: l,
150
- getZoom: s,
151
- setZoom: a,
152
- setCenter: o,
153
- getCenter: y,
154
- getSize: T,
155
- initMap: r,
156
- setBaseLayerMap: g
157
- };
158
- }
159
- const convertSixHundredThousandToLatLng = function(e, n) {
160
- const l = Number(n) / 6e5;
161
- return [Number(e) / 6e5, l];
162
- }, calculateCirclePoints = (e, n) => {
163
- const l = fromLonLat(e), s = n * 1e3, a = [
164
- l[0] - s,
165
- l[1] - s,
166
- l[0] + s,
167
- l[1] + s
168
- ], o = transformExtent(a, projection.mercator, projection.data);
169
- return {
170
- leftTopPoint: { lng: o[0], lat: o[3] },
171
- rightTopPoint: { lng: o[2], lat: o[3] },
172
- rightBottomPoint: { lng: o[2], lat: o[1] },
173
- leftBottomPoint: { lng: o[0], lat: o[1] }
174
- };
175
- }, formatLength = function(e, n) {
176
- const s = getLength(e);
177
- let a = "";
178
- switch (console.log(n, LENGTH_UNIT), n) {
179
- case LENGTH_UNIT.M:
180
- a = Math.round(s * 100) / 100 + " m";
181
- break;
182
- case LENGTH_UNIT.KM:
183
- a = Math.round(s / 1e3 * 100) / 100 + " km";
184
- break;
185
- case LENGTH_UNIT.NM:
186
- a = (Math.round(s / 1e3 * 100) / 100 / 1.852).toFixed(2) + " nm";
187
- break;
188
- }
189
- return a;
190
- };
191
- function lonLatToMercator(e) {
192
- const n = e[0] * equatorialCircumference / 180;
193
- let l = Math.log(Math.tan((90 + e[1]) * Math.PI / 360)) / (Math.PI / 180);
194
- return l = l * equatorialCircumference / 180, [n, l];
195
- }
196
- function getIconFont(unicode = "") {
197
- return unicode.indexOf("&") !== -1 && (unicode = unicode.replace("&", "&")), unicode.indexOf("&amp") !== -1 && (unicode = unicode.replace("&amp", "&")), eval('("' + unicode.replace("&#x", "\\u").replace(";", "") + '")');
198
- }
199
- const getIconStyle = (e) => {
200
- const n = new Text({
201
- font: "Normal 14px map-iconfont",
202
- text: getIconFont(e),
203
- fill: new Fill({ color: "#fff" }),
204
- offsetY: -14
205
- });
206
- return new Style({
207
- text: n,
208
- zIndex: 100
209
- });
210
- }, mercatorToLonLat = (e, n = "lonlat") => {
211
- const l = { lon: 0, lat: 0 }, s = e[0] / equatorialCircumference * 180;
212
- let a = e[1] / equatorialCircumference * 180;
213
- return a = 180 / Math.PI * (2 * Math.atan(Math.exp(a * Math.PI / 180)) - Math.PI / 2), l.lon = s, l.lat = a, n === "lonlat" ? l : [s, a];
214
- }, formatMinutesToDDHHMM = (e) => {
215
- const n = hooks.duration(e, "minutes"), l = Math.floor(n.asDays()), s = n.hours(), a = n.minutes();
216
- let o = `${String(a).padStart(2, "0")}分`;
217
- return s !== 0 && (o = `${String(s).padStart(2, "0")}时${o}`), l !== 0 && (o = `${String(l).padStart(2, "0")}天${o}`), o;
218
- }, useCarTrackManager = (e, n) => {
219
- let l = null;
220
- const s = async (g) => {
221
- if (!e || (console.log("vehicleInfo", g), !(g != null && g.lon && (g != null && g.lat)))) return;
222
- const m = Math.abs(Number(g.lon)) > 180 ? convertSixHundredThousandToLatLng(g.lon, g.lat) : [g.lon, g.lat];
223
- a(g, fromLonLat(m));
224
- const N = e == null ? void 0 : e.getView(), D = new Point(m);
225
- N.setCenter(transform(D.getCoordinates(), projection.data, projection.mercator));
226
- }, a = (g, m) => {
227
- const N = `${CDN_URL}map/car-icon.gif`;
228
- l || (l = new Overlay({
229
- element: document.createElement("div"),
230
- positioning: "center-center",
231
- stopEvent: !1
232
- // 允许交互事件穿透
233
- }), e.addOverlay(l));
234
- const D = l.getElement();
235
- D.style.backgroundImage = `url(${N})`, D.style.width = "80px", D.style.height = "80px";
236
- const v = (g == null ? void 0 : g.drc) || "";
237
- D.style.transform = `rotate(${v}deg)`, D.style.backgroundSize = "cover", l == null || l.setPosition(m);
238
- };
239
- return {
240
- location: s,
241
- remove: () => {
242
- const g = l == null ? void 0 : l.getElement();
243
- g && (g.innerHTML = "");
244
- },
245
- renderTrack: (g, m, N) => {
246
- n.render(g, m, N, "truck", 1e3);
247
- },
248
- setCenter: (g) => {
249
- n.setCenter(g);
250
- },
251
- closeTrack: () => {
252
- n.close();
253
- },
254
- playTrack: (g, m) => {
255
- n.play(g, m);
256
- }
257
- };
258
- };
259
- var SHIP_SAIL_STATUS = /* @__PURE__ */ ((e) => (e[e.发动机使用中 = 0] = "发动机使用中", e[e.锚泊 = 1] = "锚泊", e[e.未操作 = 2] = "未操作", e[e.操纵能力受限 = 3] = "操纵能力受限", e[e.吃水受限 = 4] = "吃水受限", e[e.系泊 = 5] = "系泊", e[e.搁浅 = 6] = "搁浅", e[e.从事捕捞 = 7] = "从事捕捞", e[e.航行中 = 8] = "航行中", e[e.留作将来修正导航状态 = 9] = "留作将来修正导航状态", e[e.高速船留用 = 10] = "高速船留用", e[e.机动船尾推作业 = 11] = "机动船尾推作业", e[e.机动船顶推或侧推作业 = 12] = "机动船顶推或侧推作业", e[e.飞翼船留用 = 13] = "飞翼船留用", e[e.现行的 = 14] = "现行的", e[e.未定义 = 15] = "未定义", e))(SHIP_SAIL_STATUS || {}), SHIP_DIRECT = /* @__PURE__ */ ((e) => (e.left = "left", e.right = "right", e.front = "front", e.up = "up", e.down = "down", e.back = "back", e))(SHIP_DIRECT || {});
260
- const useTrackManager = (e) => {
261
- const n = /* @__PURE__ */ new Map(), l = {};
262
- let s = null;
263
- const a = "--";
264
- let o = null;
265
- const y = document.createElement("div"), T = new Overlay({
266
- element: y,
267
- positioning: "top-left",
268
- stopEvent: !1,
269
- className: "track-label-popup"
270
- });
271
- let t, r, g, m, N, D = !1, v = Date.now(), f, P = 0, p = null, C = 20, Z = !1;
272
- const Y = 5, Q = [], H = (i) => {
273
- var c;
274
- for (Q.unshift(i); Q.length > Y; ) {
275
- const d = Q.pop(), w = n.get(d);
276
- w && ((c = w.getSource()) == null || c.clear(), e == null || e.removeLayer(w), n.delete(d), delete l[d]);
277
- }
278
- };
279
- let u = "";
280
- const L = ["#ff0000", "#00ff00", "#0079ff", "#ffa500", "#800080", "#008080", "#ffc0cb", "#800000", "#000080", "#808000"], E = debounce(() => {
281
- if (s && l[s] && n.get(s).getVisible() && Z) {
282
- console.log("reRenderTrackLine------------");
283
- const i = cloneDeep(S(s, l[s]));
284
- ce(s, i);
285
- }
286
- }, 300), S = (i, c) => {
287
- let d = [];
288
- const w = Math.max(1, Math.floor(c.length / C));
289
- return d = c.filter((b, _) => _ % w === 0).map((b, _) => {
290
- if (Number(b.lon) > 180 || Number(b.lat) > 180) {
291
- const [V, A] = convertSixHundredThousandToLatLng(b.lon, b.lat);
292
- b.lon = V, b.lat = A;
293
- }
294
- return b.center = [b.lon, b.lat], b.centerPoint = lonLatToMercator(b.center), b.time = hooks(b.createdAt).format("YYYY-MM-DD HH:mm:ss"), b.id = i, b.index = _, b;
295
- }), d;
296
- }, M = async (i, c, d, w = "ship", x = 200) => {
297
- if (!e || (c = c == null ? void 0 : c.reverse(), T && w === "ship" && (e != null && e.getOverlays().getArray().includes(T) || e.addOverlay(T)), (c == null ? void 0 : c.length) < 2))
298
- return;
299
- H(i), s = i, l[i] = c, C = x;
300
- const b = Object.keys(l).findIndex((_) => _ === i) || 0;
301
- u = d || L[b > 10 ? 10 : b], Z = !0, await z(), await ne(s);
302
- }, O = (i) => {
303
- const c = new VectorSource();
304
- return new VectorLayer({
305
- source: c,
306
- visible: !1,
307
- // 默认隐藏
308
- className: `track-layer-${i}`,
309
- renderBuffer: 1024
310
- // 增大渲染缓冲区
311
- });
312
- }, $ = (i) => {
313
- n.forEach((c, d) => {
314
- var x;
315
- const w = d === i;
316
- c.getVisible() !== w && (c.setVisible(w), e.getLayers().getArray().includes(c) || e.addLayer(c), w || (x = c.getSource()) == null || x.clear());
317
- }), s = i;
318
- }, z = async () => {
319
- const i = s;
320
- if (!n.has(i)) {
321
- const b = O(i);
322
- n.set(i, b);
323
- }
324
- await $(i);
325
- const c = u || "", d = l[i] || [];
326
- if (!(d && d.length > 1)) return [];
327
- let w = [];
328
- w = S(i, d);
329
- const x = w.map((b) => b.centerPoint);
330
- w.length >= 2 && await F(i, x, c);
331
- }, F = (i, c, d) => {
332
- const w = new LineString(c), x = n.get(i).getSource(), b = x.getFeatureById(i);
333
- if (b)
334
- b.setGeometry(w), b.setId(i), b.setStyle(R(d)), p = b;
335
- else {
336
- const _ = new Feature({ geometry: w });
337
- _.setId(i), _.set("type", "line"), _.setStyle(R(d)), x.addFeature(_), p = _;
338
- }
339
- return p;
340
- }, R = (i) => new Style({
341
- stroke: new Stroke({
342
- color: i,
343
- width: 2
344
- })
345
- }), j = (i, c, d) => {
346
- const w = i == null ? void 0 : i.get("trackId");
347
- if (i && w && c === "hover") {
348
- e.getTargetElement().style.cursor = w ? "pointer" : "";
349
- const x = i.get("data"), b = K(x), _ = d == null ? void 0 : d.coordinate;
350
- _ && (y.querySelector(".popup-content"), y.innerHTML = b, T == null || T.setPosition(_));
351
- } else
352
- T && T.setPosition(void 0);
353
- }, K = (i) => {
354
- if (!(i != null && i.time)) return;
355
- let c = "";
356
- return i != null && i.stayTime && (c = `
357
- <div class="item w-100">
358
- <div class="item-label">停泊时间约</div>
359
- <div class="item-item">${formatMinutesToDDHHMM(Number(i.stayTime))}</div>
360
- </div>
361
- `), `
362
- <div class="track-point-popup">
363
- <div class="item">
364
- <div class="item-label">状态</div>
365
- <div class="item-item">${i != null && i.sailStatus ? SHIP_SAIL_STATUS[i.sailStatus] : a}</div>
366
- </div>
367
- <div class="item">
368
- <div class="item-label">航速</div>
369
- <div class="item-item">${i.speed || a}</div>
370
- </div>
371
- <div class="item">
372
- <div class="item-label">艏向</div>
373
- <div class="item-item">${i.hdg || a}</div>
374
- </div>
375
- <div class="item">
376
- <div class="item-label">航向</div>
377
- <div class="item-item">${i.cog || a}</div>
378
- </div>
379
- <div class="item">
380
- <div class="item-label">经度</div>
381
- <div class="item-item">${i.lon || a}</div>
382
- </div>
383
- <div class="item">
384
- <div class="item-label">纬度</div>
385
- <div class="item-item">${i.lat || a}</div>
386
- </div>
387
- <div class="item w-100">
388
- <div class="item-label">时间</div>
389
- <div class="item-item">${i.time}</div>
390
- </div>
391
- ${c ?? c}
392
- </div>`;
393
- }, ie = (i) => {
394
- const d = i.map((V) => {
395
- const A = e.getPixelFromCoordinate(fromLonLat(V.center));
396
- return {
397
- ...V,
398
- original: V,
399
- pixel: A,
400
- distance: 0
401
- // 先初始化,后续计算
402
- };
403
- });
404
- let w = 0;
405
- d[0].distance = 0;
406
- for (let V = 1; V < d.length; V++) {
407
- const A = d[V - 1].pixel, B = d[V].pixel, W = B[0] - A[0], k = B[1] - A[1];
408
- w += Math.sqrt(W * W + k * k), d[V].distance = w;
409
- }
410
- const x = d.filter(
411
- (V, A) => A === 0 || A === d.length - 1
412
- ), b = [];
413
- for (let V = 0; V < x.length; V++) {
414
- const A = x[V];
415
- if (b.push(A), V < x.length - 1) {
416
- const B = x[V + 1], W = B.distance - A.distance, k = Math.floor(W / 100);
417
- for (let G = 1; G <= k; G++) {
418
- const q = A.distance + G * 100;
419
- if (q >= B.distance) break;
420
- const X = ae(
421
- d,
422
- q
423
- );
424
- X && b.push(X);
425
- }
426
- }
427
- }
428
- return Array.from(
429
- new Map(b.map((V) => [V.distance.toFixed(2), V])).values()
430
- ).map((V) => ({
431
- ...V.original,
432
- // 优先保留原始数据
433
- ...V,
434
- // 覆盖坐标等计算属性
435
- coord: V.coord,
436
- // 确保使用插值后的坐标
437
- pixel: V.pixel,
438
- distance: V.distance
439
- }));
440
- };
441
- function ae(i, c) {
442
- for (let d = 1; d < i.length; d++) {
443
- const w = i[d - 1], x = i[d];
444
- if (c >= w.distance && c <= x.distance) {
445
- const b = (c - w.distance) / (x.distance - w.distance), _ = w.pixel[0] + b * (x.pixel[0] - w.pixel[0]), V = w.pixel[1] + b * (x.pixel[1] - w.pixel[1]), A = e == null ? void 0 : e.getCoordinateFromPixel([_, V]);
446
- return {
447
- ...w,
448
- // 继承前一个点的属性(可调整)
449
- coord: A,
450
- pixel: [_, V],
451
- distance: c,
452
- original: void 0
453
- // 明确标记为插值生成点
454
- };
455
- }
456
- }
457
- return null;
458
- }
459
- const ce = async (i, c) => {
460
- await re(), await ge(i);
461
- const d = ie(c), w = d.map((b) => de(b));
462
- n.get(i).getSource().addFeatures(w), me(i, d, c, u), d.forEach((b) => {
463
- const _ = ue(i, u, b);
464
- e.addOverlay(_);
465
- });
466
- }, de = (i) => {
467
- const c = new Feature({
468
- geometry: new Point(i.centerPoint),
469
- data: i
470
- });
471
- c.set("type", "track_point"), c.set("trackId", i.id), c.set("data", i);
472
- let d = [
473
- ...fe(i, u)
474
- ];
475
- return (i.index === 0 || i.index === l[i.id].length - 1) && (d = [...he(i)], c.set("type", "track_begin")), i.state !== void 0 && i.state !== null && (d = [...ye(i)], c.set("type", "track_icon")), c.setStyle(d), c;
476
- }, ue = (i, c, d) => {
477
- const w = document.createElement("div");
478
- w.className = "track-overlay-label", w.style.position = "relative", w.style.backgroundColor = "rgba(255,255,255,0.8)", w.style.border = `1px solid ${c}`, w.style.fontSize = "12px", w.innerHTML = `
479
- <span>${d.time}</span>
480
- <svg
481
- style="position: absolute;left: -20px;top: 0;"
482
- viewBox="0 0 20 20"
483
- xmlns="http://www.w3.org/2000/svg"
484
- width="20"
485
- height="20">
486
- <line x1="0" y1="20"
487
- x2="20" y2="0"
488
- stroke="${c}"
489
- stroke-width="1" />
490
- `;
491
- const x = new Overlay({
492
- element: w,
493
- position: fromLonLat(d.center),
494
- positioning: "top-left",
495
- offset: [20, -20],
496
- stopEvent: !1,
497
- className: "track-label-time-overlay"
498
- });
499
- return x.set("class", "track-label-overlay"), x.set("trackId", i), x;
500
- }, re = () => {
501
- const i = e == null ? void 0 : e.getOverlays().getArray(), c = i == null ? void 0 : i.filter((d) => d.get("class") === "track-label-overlay");
502
- c && c.length > 0 && c.forEach((d) => {
503
- d.setPosition(void 0), d.dispose();
504
- });
505
- }, ge = (i) => {
506
- const c = n.get(i).getSource();
507
- c.forEachFeature((d) => {
508
- d.get("type") !== "line" && c.removeFeature(d);
509
- });
510
- }, fe = (i, c) => (`${i.time}`, [
511
- new Style({
512
- // 扩大交互热区
513
- image: new CircleStyle({
514
- stroke: new Stroke({ color: "rgba(0, 0, 0, 0.01)", width: 20 }),
515
- radius: 3
516
- })
517
- }),
518
- // 轨迹点样式
519
- new Style({
520
- image: new CircleStyle({
521
- fill: new Fill({ color: c }),
522
- stroke: new Stroke({ color: "#fff", width: 2 }),
523
- radius: 3
524
- })
525
- })
526
- // textStyle,
527
- ]), ye = (i) => {
528
- const c = "#E31818", d = "#1890FF", w = "&#xe6d2", x = new Style({
529
- text: new Text({
530
- font: "Normal 22px map-iconfont",
531
- text: getIconFont(w),
532
- offsetY: -10,
533
- fill: new Fill({
534
- color: Number(i.state) === 0 ? c : Number(i.state) === 1 ? d : ""
535
- })
536
- }),
537
- zIndex: 99
538
- }), _ = getIconStyle("&#xe6e2;"), A = getIconStyle("&#xe703;"), B = [];
539
- return Number(i.state) === 0 ? B.push(_) : Number(i.state) === 1 && B.push(A), B.push(x), B;
540
- }, me = (i, c, d, w) => {
541
- const x = c || [], b = c.length;
542
- b || (x.push(d[0]), x.push(d[d.length - 1]));
543
- const _ = [];
544
- for (let A = 0; A < b - 1; A++) {
545
- let B;
546
- const W = c[A], k = (c[A + 1].index + W.index) / 2;
547
- if (k % 2 === 0)
548
- B = d[k].centerPoint;
549
- else {
550
- const G = d[Math.floor(k)], q = d[Math.ceil(k)];
551
- if (G && q) {
552
- const [X, J] = G.centerPoint, [I, ee] = q.centerPoint;
553
- B = [(X + I) / 2, (J + ee) / 2];
554
- }
555
- }
556
- if (B) {
557
- const G = new Feature({
558
- geometry: new Point(B)
559
- });
560
- G.set("type", "track_arrow"), G.setStyle(
561
- new Style({
562
- text: new Text({
563
- font: "700 12px map-iconfont",
564
- text: getIconFont("&#xe6bc;"),
565
- fill: new Fill({ color: w }),
566
- // 设置箭头旋转 角度转为弧度
567
- rotation: le(
568
- c[A].center,
569
- c[A + 1].center
570
- ) * (Math.PI / 180)
571
- })
572
- })
573
- ), _.push(G);
574
- }
575
- }
576
- const V = n.get(i).getSource();
577
- V == null || V.addFeatures(_);
578
- }, ne = (i) => {
579
- var b, _;
580
- const c = e.getView(), d = (b = n == null ? void 0 : n.get(i)) == null ? void 0 : b.getSource(), w = p || (i ? d == null ? void 0 : d.getFeatureById(i) : null);
581
- if (!w) return;
582
- const x = (_ = w == null ? void 0 : w.getGeometry()) == null ? void 0 : _.getExtent();
583
- if (x != null && x.length)
584
- try {
585
- const V = buffer(x, Math.max(x[2] - x[0], x[3] - x[1]) * 0.02);
586
- c.fit(V);
587
- } catch (V) {
588
- console.log(V);
589
- }
590
- }, he = (i) => {
591
- const c = "&#xe69b;", x = i.index === 0 ? "#fcdc3f" : "#ff0000";
592
- return [new Style({
593
- text: new Text({
594
- font: "Normal 14px map-iconfont",
595
- text: getIconFont(c),
596
- fill: new Fill({ color: x })
597
- }),
598
- zIndex: 101
599
- })];
600
- }, ve = () => {
601
- console.log("清除所有的轨迹-----"), U(), n.forEach((c) => {
602
- var d;
603
- (d = c.getSource()) == null || d.clear(), e == null || e.removeLayer(c);
604
- }), Object.keys(l).forEach((c) => {
605
- n.delete(c), delete l[c];
606
- }), Z = !1, re();
607
- }, we = (i) => {
608
- const c = n.get(i || s);
609
- c == null || c.setVisible(!1);
610
- const d = e.getOverlays().getArray();
611
- for (let w = 0; w < d.length; ) {
612
- const x = d[w];
613
- x.get("class") === "track-label-overlay" ? (x.setPosition(void 0), e.removeOverlay(x)) : w++;
614
- }
615
- U();
616
- }, pe = (i, c = LENGTH_UNIT.NM) => {
617
- const d = {
618
- id: i,
619
- length: "--"
620
- }, x = (l[i] || []).map(
621
- (_) => transform([_.lon, _.lat], projection.data, projection.mercator)
622
- ), b = new LineString(x);
623
- return d.length = formatLength(b, c) || "--", d;
624
- }, Le = (i, c) => {
625
- xe(String(i), c);
626
- }, xe = (i, c) => {
627
- const d = l[String(i)], w = d == null ? void 0 : d.map((x) => [x.lon, x.lat]);
628
- w && ke(w, c);
629
- }, te = new Style({
630
- text: new Text({
631
- font: "700 20px map-iconfont",
632
- text: getIconFont("&#xe657;"),
633
- fill: new Fill({ color: "#ff0000" }),
634
- rotation: 0
635
- // 初始旋转角度
636
- })
637
- }), Me = (i, c) => {
638
- var k, G;
639
- const d = Number(50 * c), w = ((k = i.frameState) == null ? void 0 : k.time) ?? Date.now(), x = w - v;
640
- if (P = (P + d * x / 1e6) % 2, v = w, P >= 1) {
641
- U();
642
- return;
643
- }
644
- const b = r.getCoordinateAt(
645
- P > 1 ? 2 - P : P
646
- ), _ = r.getCoordinateAt(
647
- P > 1 ? P - 0.01 : P
648
- ), V = r.getCoordinateAt(
649
- P > 1 ? 2 - P : P + 0.01
650
- ), B = le(
651
- mercatorToLonLat(_, "array"),
652
- mercatorToLonLat(V, "array")
653
- ) * Math.PI / 180;
654
- (G = te.getText()) == null || G.setRotation(B), m.setCoordinates(b);
655
- const W = getVectorContext(i);
656
- W.setStyle(te), W.drawGeometry(m), e == null || e.render();
657
- }, be = () => {
658
- var i;
659
- D = !0, v = Date.now(), P = 0, m = ((i = g.getGeometry()) == null ? void 0 : i.clone()) || new Point([0, 0]), o && (f == null || f.on("postrender", o)), N == null || N.setGeometry(void 0);
660
- }, U = () => {
661
- D && (D = !1, N == null || N.setGeometry(void 0), o && f && f.un("postrender", o), f && (e == null || e.removeLayer(f)), f = null, N = null);
662
- }, ke = (i, c) => {
663
- D && U(), t = new Polyline({
664
- factor: 1e6
665
- }).writeGeometry(new LineString(i)), r = new Polyline({
666
- factor: 1e6
667
- }).readGeometry(t, {
668
- dataProjection: projection.data,
669
- featureProjection: projection.mercator
670
- }), g = new Feature({
671
- type: "icon",
672
- geometry: new Point(r.getFirstCoordinate())
673
- });
674
- const d = g.getGeometry();
675
- m = d ? d.clone() : new Point([0, 0]), N = new Feature({
676
- type: "geoMarker",
677
- style: te,
678
- geometry: m
679
- }), f = new VectorLayer({
680
- source: new VectorSource({
681
- features: [N]
682
- })
683
- }), e == null || e.addLayer(f), o = (w) => Me(w, c), be();
684
- }, le = (i, c, d) => {
685
- function w(k) {
686
- return 180 * (k % (2 * Math.PI)) / Math.PI;
687
- }
688
- function x(k) {
689
- return k % 360 * Math.PI / 180;
690
- }
691
- function b(k) {
692
- var G;
693
- if (!k) throw new Error("Coordinate is required");
694
- if (!Array.isArray(k)) {
695
- if ((k == null ? void 0 : k.type) === "Feature" && (k == null ? void 0 : k.geometry) !== null && ((G = k == null ? void 0 : k.geometry) == null ? void 0 : G.type) === "Point")
696
- return k == null ? void 0 : k.geometry.coordinates;
697
- if (k.type === "Point") return (k == null ? void 0 : k.coordinates) || [];
698
- }
699
- if (Array.isArray(k) && k.length >= 2 && !Array.isArray(k[0]) && !Array.isArray(k[1]))
700
- return k;
701
- throw new Error(
702
- "Coordinate must be GeoJSON Point or an Array of numbers"
703
- );
704
- }
705
- function _(k, G, q = {}) {
706
- if (q.final)
707
- return function(Te, Se) {
708
- return (_(Se, Te) + 180) % 360;
709
- }(k, G);
710
- const X = b(k), J = b(G), I = x(X[0]), ee = x(J[0]), se = x(X[1]), oe = x(J[1]), Ce = Math.sin(ee - I) * Math.cos(oe), Ee = Math.cos(se) * Math.sin(oe) - Math.sin(se) * Math.cos(oe) * Math.cos(ee - I);
711
- return w(Math.atan2(Ce, Ee));
712
- }
713
- function V(k) {
714
- return !isNaN(k) && k !== null && !Array.isArray(k);
715
- }
716
- function A(k, G = {}, q = {}) {
717
- return k || console.log("Coordinates are required"), Array.isArray(k) || console.log("Coordinates must be an Array"), k.length < 2 && console.log("Coordinates must be at least 2 numbers long"), (!V(k[0]) || !V(k[1])) && console.log("Coordinates must contain numbers"), B({ type: "Point", coordinates: k }, G, q);
718
- }
719
- function B(k, G = {}, q = {}) {
720
- const X = {
721
- type: "Feature",
722
- id: "",
723
- properties: {},
724
- bbox: {},
725
- geometry: {}
726
- };
727
- return q.id !== void 0 && (X.id = q.id), q.bbox && (X.bbox = q.bbox), X.properties = G, X.geometry = k, X;
728
- }
729
- const W = _(A(i), A(c), d);
730
- return W < 0 ? 360 + W : W;
731
- };
732
- return {
733
- render: M,
734
- remove: ve,
735
- play: Le,
736
- setCenter: ne,
737
- close: we,
738
- getLength: pe,
739
- handleTrackMapEvent: j,
740
- reRenderTrackLine: E
741
- };
742
- };
743
- function useShipOverlay(e) {
744
- const n = ref(null);
745
- ref(null);
746
- const l = computed(() => ({
747
- "--overlay-color": e.color || "#FFF",
748
- "--bg-color": e.selected ? e.color : "#ffffff",
749
- position: "relative",
750
- "pointer-events": "none"
751
- })), s = computed(() => ({
752
- position: "relative",
753
- "border-radius": "1px",
754
- "background-color": "var(--bg-color)",
755
- color: "#000",
756
- "padding-right": "5px",
757
- font: "500 Normal 12px",
758
- "font-size": "12px",
759
- "box-shadow": "0 2px 10px rgba(0, 0, 0, 0.2)",
760
- "white-space": "nowrap",
761
- border: "1px solid #FFF",
762
- "pointer-events": "auto",
763
- transition: "background-color 0.5s ease, border 0.5s ease",
764
- "z-index": "1",
765
- display: "flex",
766
- "align-items": "center",
767
- animation: e.selected ? "blink 1.5s ease-in-out infinite" : "none"
768
- // 动画开关
769
- })), a = computed(() => ({
770
- width: "14px",
771
- height: "14px",
772
- margin: "1px 5px 1px 1px",
773
- "background-color": "var(--bg-color)"
774
- })), o = computed(() => ({
775
- position: "absolute",
776
- top: "0px",
777
- color: "var(--overlay-color)",
778
- "pointer-events": "none",
779
- transform: "translateY(-1px)",
780
- "z-index": "0",
781
- width: "20px",
782
- height: "20px",
783
- overflow: "visible",
784
- left: "-20px"
785
- }));
786
- return () => h("div", {
787
- ref: n,
788
- class: "ship-overlay-container",
789
- style: l.value
790
- }, [
791
- h(
792
- "div",
793
- {
794
- class: "ship-overlay-content",
795
- style: s.value
796
- },
797
- [
798
- h("div", {
799
- style: e.selected ? a.value : {}
800
- }, ""),
801
- h("div", {
802
- class: "text"
803
- }, e.name || "未命名船舶"),
804
- h("div", {
805
- class: "icons",
806
- style: {
807
- color: "#3370ff"
808
- }
809
- }, [
810
- e.existDevice ? h("i", {
811
- class: "iconfont icon-Frame-19",
812
- style: {
813
- fontSize: "12px",
814
- marginRight: "2px",
815
- marginLeft: "2px"
816
- }
817
- }) : "",
818
- e.existMobile ? h("i", {
819
- class: "iconfont icon-Frame13",
820
- style: {
821
- fontSize: "12px",
822
- marginRight: "2px"
823
- }
824
- }) : "",
825
- e.existWaterGauge ? h("i", {
826
- class: "iconfont icon-a-Frame7",
827
- style: {
828
- fontSize: "12px"
829
- }
830
- }) : ""
831
- ])
832
- ]
833
- ),
834
- h("svg", {
835
- class: "ship-overlay-line",
836
- style: o.value,
837
- viewBox: "0 0 20 20",
838
- xmlns: "http://www.w3.org/2000/svg"
839
- }, [
840
- h("line", {
841
- x1: "0",
842
- y1: "20",
843
- x2: "20",
844
- y2: "4",
845
- stroke: "white",
846
- "stroke-width": "1"
847
- })
848
- ])
849
- ]);
850
- }
851
- ref([]);
852
- function addOverlay(e, n, l, s) {
853
- if (n) {
854
- const a = new Overlay({
855
- element: l,
856
- positioning: "top-left",
857
- id: "label-" + (s == null ? void 0 : s.id),
858
- offset: [20, -20],
859
- autoPan: !1,
860
- position: n,
861
- className: s.blinking ? "ship-label-overlay-blinking" : "ship-label-overlay"
862
- });
863
- a.set("class", "zh-map-ship-overlay"), e.addOverlay(a);
864
- }
865
- }
866
- const getShipDirectPath = (e) => {
867
- const { spd: n, hdg: l, cog: s } = e;
868
- return n ? l !== null && +l != 511 && s !== null ? s - +l >= 3 ? SHIP_DIRECT.right : s - +l <= -3 ? SHIP_DIRECT.left : SHIP_DIRECT.front : SHIP_DIRECT.front : "";
869
- }, createShipStyle = (e, n) => {
870
- const { shipData: l } = n.getProperties(), s = getShipType(e), a = getShipScale(e, l, s);
871
- return initShipStyle(n, a, s);
872
- }, getShipType = (e) => {
873
- const n = e == null ? void 0 : e.getView().getZoom();
874
- return n <= MAP_ZOOM.shipModelMax && n >= MAP_ZOOM.shipTriggleMin ? "ship" : "triangle";
875
- }, getShipScale = (e, n, l) => {
876
- if (l === "ship") {
877
- const { len: s, wid: a } = n, o = 97, y = 20, t = 1 / (e == null ? void 0 : e.getView().getResolution()), r = s * t / o, g = a * t / y;
878
- return Math.max(r, g);
879
- }
880
- return MAP_ZOOM.scaleNum;
881
- }, initShipStyle = (e, n, l) => {
882
- const { color: s, direct: a, isHighlight: o, shipData: y } = e.getProperties(), T = ((y == null ? void 0 : y.cog) - 90 + 360) % 360;
883
- return new Style({
884
- image: new Icon({
885
- src: t(),
886
- scale: n || MAP_ZOOM.scaleNum,
887
- anchor: [0.5, 0.5],
888
- rotation: T * Math.PI / 180,
889
- rotateWithView: !1
890
- })
891
- });
892
- function t() {
893
- return `data:image/svg+xml;utf8,${encodeURIComponent(r())}`;
894
- }
895
- function r() {
896
- switch (l) {
897
- case "triangle":
898
- return `<svg width="41" height="24" viewBox="0 0 41 24" fill="none" xmlns="http://www.w3.org/2000/svg">
899
- <path d="M30.8843 12.6777L2.21343 21.7067C1.75559 21.8509 1.28947 21.509 1.28947 21.029L1.28947 2.97103C1.28947 2.49102 1.75558 2.14913 2.21342 2.29331L30.8843 11.3223C31.5471 11.531 31.5471 12.469 30.8843 12.6777Z"
900
- fill="${s}" stroke="${o ? "#FF2424" : "black"}" stroke-width="${o ? "2" : "0.578947"}" />
901
- <!--path船航向左边或者向前-->
902
- ${a === SHIP_DIRECT.left && `<path d="M30 12L40 12L40 8" stroke="${o ? "#FF2424" : "black"}" stroke-width="2"/>`}
903
- <!--path船航向右边-->
904
- ${a === SHIP_DIRECT.right && `<path d="M30 12L40 12L40 16" stroke="${o ? "#FF2424" : "black"}" stroke-width="2"/>`}
905
- <!--path黑线无左右-->
906
- ${a === SHIP_DIRECT.front && `<path d="M30 12L40 12" stroke="${o ? "#FF2424" : "black"}" stroke-width="1.5"/>`}
907
- </svg>
908
- `;
909
- case "ship":
910
- return `<svg width="97" height="20" viewBox="0 0 97 20" fill="none" xmlns="http://www.w3.org/2000/svg">
911
- <path d="M0.289474 17.3433L0.289474 2.65655C0.289474 2.28572 0.574654 1.97725 0.944343 1.9482L22.0544 0.289473L67.5204 0.289473C67.6295 0.289473 67.7372 0.314613 67.835 0.362943L86.0565 9.3629C86.5844 9.6236 86.5844 10.3763 86.0565 10.637L67.835 19.6371C67.7372 19.6854 67.6295 19.7105 67.5203 19.7105L22.0544 19.7105L0.944343 18.0517C0.574653 18.0226 0.289474 17.7142 0.289474 17.3433Z"
912
- fill="${s}" stroke="${o ? "#FF2424" : "black"}" stroke-width="${o ? "4" : "0.578947"}"/>
913
- ${a === SHIP_DIRECT.left && `<path d="M86 10L96 10L96 6" stroke="${o ? "#FF2424" : "black"}" stroke-width="1.5"/>`}
914
- ${a === SHIP_DIRECT.right && `<path d="M86 10L96 10L96 14" stroke="${o ? "#FF2424" : "black"}" stroke-width="1.5"/>`}
915
- ${a === SHIP_DIRECT.front && `<path d="M86 10L96 10" stroke="${o ? "#FF2424" : "black"}" stroke-width="1.5"/>`}
916
- </svg>
917
- `;
918
- default:
919
- return "";
920
- }
921
- }
922
- }, selectedShipStyle = (e, n) => {
923
- const l = selectedShipElement(e, n), s = n.id, { lon: a, lat: o } = n, y = new Overlay({
924
- element: l,
925
- position: fromLonLat([a, o]),
926
- id: "selected-" + s,
927
- positioning: "center-center",
928
- offset: [0, 5],
929
- className: "ship-selected-overlay"
930
- });
931
- return y.set("class", "ship-overlay-selected"), y;
932
- }, selectedShipElement = (e, n) => {
933
- const l = getShipType(e), s = getShipScale(e, n, l), a = l === "ship" ? 109 : 49, o = `
934
- <svg style="transform:scale(${s});" xmlns="http://www.w3.org/2000/svg" width="${a}" height="${a}" viewBox="0 0 49 49" fill="none">
935
- <path d="M1.99982 46.9998L1.99982 1.99982L46.9998 1.99982L46.9998 46.9998L1.99982 46.9998Z" fill="#FF2424" fill-opacity="0.2"/>
936
- <path fill-rule="evenodd" clip-rule="evenodd" d="M19.9998 0.5V3.5L3.49976 3.5V20H0.499756V0.500002L19.9998 0.5ZM45.4998 3.5H28.9998V0.5H48.4998V20H45.4998V3.5ZM48.4998 29L48.4998 48.5H28.9998V45.5H45.4998L45.4998 29H48.4998ZM3.49976 45.5L3.49976 29H0.499756L0.499758 48.5L19.9998 48.5V45.5L3.49976 45.5Z" fill="#FF2424"/>
937
- </svg>
938
- `, y = document.createElement("div");
939
- return y.className = "ship-overlay-selected", y.innerHTML = o, y;
940
- }, createLabelStyle = (e, n) => {
941
- const { shipData: l, blinking: s } = n.getProperties(), { lon: a, lat: o } = l, y = createLabelElement(n);
942
- a && o && addOverlay(e, fromLonLat([a, o]), y, { ...l, blinking: s });
943
- }, createLabelElement = (e) => {
944
- const n = document.createElement("div");
945
- n.className = "ship-overlay-box", n.style.position = "relative";
946
- const l = e.getProperties(), { shipData: s, blinking: a, blinkingColor: o, name: y } = l, { lon: T, lat: t } = s, r = createVNode({
947
- setup() {
948
- return useShipOverlay({
949
- selected: a,
950
- name: y,
951
- color: o,
952
- existDevice: s == null ? void 0 : s.existDevice,
953
- existMobile: s == null ? void 0 : s.existMobile,
954
- existWaterGauge: s == null ? void 0 : s.existWaterGauge
955
- });
956
- }
957
- });
958
- return render(r, n), n;
959
- }, getRightIcons = (e) => {
960
- const n = [];
961
- return e.existDevice && n.push("&#xe687;"), e.existMobile && n.push("&#xe688;"), e.existWaterGauge && n.push("&#xe686;"), n;
962
- }, createLabelFeatureStyle = (e) => {
963
- const { name: n, rightIcons: l } = e.getProperties(), s = `${n} ${l.map((g) => getIconFont(g)).join(" ")} `, a = [20, -20], y = -Math.atan2(-a[1], a[0]), T = Math.sqrt(a[0] ** 2 + a[1] ** 2), t = `<svg viewBox="0 0 ${T + 10} 20" width="${T + 10}" height="20" xmlns="http://www.w3.org/2000/svg" >
964
- <line x1="0" y1="0" x2="${10 + T}" y2="10" stroke="white" stroke-width="1"></line>
965
- </svg>`;
966
- return [new Style({
967
- text: new Text({
968
- text: s,
969
- fill: new Fill({ color: "#000000" }),
970
- stroke: new Stroke({ color: "#ffffff", width: 1 }),
971
- font: "Normal 12px map-iconfont",
972
- offsetX: a[0],
973
- offsetY: a[1],
974
- backgroundFill: new Fill({ color: "#ffffff" }),
975
- scale: 1
976
- }),
977
- image: new Icon({
978
- src: `data:image/svg+xml;utf8,${encodeURIComponent(t)}`,
979
- displacement: [16, -10],
980
- anchor: [0.5, 0.5],
981
- rotation: y,
982
- rotateWithView: !1
983
- })
984
- })];
985
- }, useShipManager = (e) => {
986
- let n = null, l = null;
987
- const s = new VectorSource(), a = new VectorImageLayer({
988
- source: s,
989
- className: "zh-map--ship-layer",
990
- renderBuffer: 300,
991
- zIndex: 101
992
- }), o = new VectorSource(), y = new VectorLayer({
993
- source: o,
994
- className: "zh-map--ship-label-layer",
995
- zIndex: 102,
996
- updateWhileInteracting: !1,
997
- updateWhileAnimating: !1,
998
- declutter: !0
999
- });
1000
- e == null || e.addLayer(a), e == null || e.addLayer(y);
1001
- let T = "", t = {}, r = {};
1002
- const g = (u) => {
1003
- if (!u || !e) return;
1004
- const L = (l == null ? void 0 : l.id) || (n == null ? void 0 : n.get("id"));
1005
- if (l) {
1006
- const E = u.filter((S) => S.id === L);
1007
- E.length === 0 ? u.push(l) : l = E[0];
1008
- }
1009
- D(), v(!0), H(u), N();
1010
- }, m = (u) => {
1011
- const L = (l == null ? void 0 : l.id) || (n == null ? void 0 : n.get("id")), E = fromLonLat([u == null ? void 0 : u.lon, u == null ? void 0 : u.lat]), S = u.fill || "#04C900", M = getShipDirectPath(u), O = new Feature({
1012
- geometry: new Point(E),
1013
- // 船舶数据
1014
- shipData: u,
1015
- id: u.id,
1016
- name: u.cnname || "未命名船舶",
1017
- selected: u.id === L,
1018
- // 图标
1019
- rightIcons: getRightIcons(u),
1020
- // 是否闪烁
1021
- blinking: t[u.id] || !1,
1022
- // 闪烁颜色
1023
- blinkingColor: r[u.id] || "",
1024
- // 船舶颜色
1025
- color: S,
1026
- // 船艏向的方向
1027
- direct: M,
1028
- // shipType,
1029
- // scale:scaleNum,
1030
- // rotation,
1031
- // 高亮
1032
- isHighlight: !1
1033
- });
1034
- return O.set("clickGeometry", new Circle(E)), O;
1035
- }, N = async () => {
1036
- if (!l || !e) return;
1037
- let L = e.getOverlays().getArray().find((E) => E.get("class") == "ship-overlay-selected");
1038
- if (console.log("selectedOverlay----------", L), L) {
1039
- const E = selectedShipElement(e, l);
1040
- await L.setElement(E), await L.setPosition(fromLonLat([l.lon, l.lat]));
1041
- } else
1042
- L = selectedShipStyle(e, l), L && e.addOverlay(L);
1043
- setTimeout(() => {
1044
- var E;
1045
- L && ((E = L.get("element")) != null && E.parentElement) && (L.get("element").parentElement.style.display = "block");
1046
- }, 20);
1047
- }, D = () => {
1048
- e && s && (s.clear(), o.clear(), v());
1049
- }, v = (u) => {
1050
- const L = e.getOverlays().getArray().filter((E) => E.get("class") == "zh-map-ship-overlay");
1051
- if (L && L.length > 0) {
1052
- for (let E = 0; E < L.length; E++)
1053
- if (!u && L[E].get("class") !== "ship-overlay-selected") {
1054
- const S = L[E];
1055
- S.setPosition(void 0), e.removeOverlay(S), S.dispose();
1056
- }
1057
- }
1058
- }, f = (u, L) => {
1059
- t = u, r = L;
1060
- const E = e.getOverlays().getArray(), S = s.getFeatures();
1061
- for (const M in t) {
1062
- const O = t[M], $ = E.find((F) => F.getId() === "label-" + M), z = S.find((F) => M === F.get("id"));
1063
- if ($ && z) {
1064
- z.set("blinking", O), z.set("blinkingColor", r[M] || "");
1065
- const F = $.getElement(), R = createLabelElement(z), j = R.querySelector(".ship-overlay-line"), K = F == null ? void 0 : F.querySelector(".ship-overlay-line");
1066
- F && F !== R && (K && j && j.replaceWith(K), $.setElement(R));
1067
- }
1068
- }
1069
- }, P = (u) => {
1070
- if (!e) return;
1071
- const L = s.getFeatures(), E = o.getFeatures(), S = n ? n.get("id") : "", M = L.filter((F) => F.get("id") !== S), O = E == null ? void 0 : E.filter((F) => F.get("id") !== S), $ = /* @__PURE__ */ new Map();
1072
- u.forEach((F) => {
1073
- $.set(F.id, !0);
1074
- });
1075
- const z = e.getOverlays().getArray();
1076
- M.forEach((F) => {
1077
- const R = F.get("id");
1078
- if (!$.has(R))
1079
- F.setStyle([]);
1080
- else {
1081
- const K = F.getStyle();
1082
- (K == null ? void 0 : K.length) == 0 && F.setStyle(createShipStyle(e, F));
1083
- }
1084
- const j = z.find((K) => K.getId() === "label-" + R);
1085
- j && j.setPosition(void 0);
1086
- }), O.forEach((F) => {
1087
- const R = F.get("id");
1088
- if (!$.has(R))
1089
- F.setStyle([]);
1090
- else {
1091
- const j = F.getStyle();
1092
- (j == null ? void 0 : j.length) == 0 && F.setStyle(createLabelFeatureStyle(F));
1093
- }
1094
- });
1095
- }, p = (u) => {
1096
- if (u) {
1097
- console.log("选中", u);
1098
- const L = s.getFeatures().find((E) => E.get("id") === u.id);
1099
- L && (n = L), l = u, N();
1100
- } else
1101
- console.log("取消选中"), l = null, n = null, Y();
1102
- }, C = debounce((u, L, E) => {
1103
- if (u) {
1104
- const S = u.get("shipData"), M = u.get("id");
1105
- if (e.getTargetElement().style.cursor = M ? "pointer" : "", L === "click" && (p(S), E && E(M)), L === "hover") {
1106
- T && T !== M && Z(), T = M;
1107
- const O = s.getFeatures().find(($) => $.get("id") === T);
1108
- O == null || O.set("isHighlight", !0), O == null || O.setStyle(createShipStyle(e, O));
1109
- }
1110
- } else
1111
- e.getTargetElement().style.cursor = "", Z();
1112
- }, 10), Z = () => {
1113
- const u = T ? s.getFeatures().find((L) => L.get("id") === T) : null;
1114
- T = null, u == null || u.set("isHighlight", !1), u == null || u.setStyle(createShipStyle(e, u));
1115
- }, Y = () => {
1116
- try {
1117
- const L = e.getOverlays().getArray().find((E) => E.get("class") == "ship-overlay-selected");
1118
- L && L.setPosition(void 0);
1119
- } catch (u) {
1120
- console.log(u);
1121
- }
1122
- }, Q = (u) => {
1123
- const L = fromLonLat([u == null ? void 0 : u.lon, u == null ? void 0 : u.lat]), E = new Feature({
1124
- geometry: new Point(L),
1125
- name: u.cnname || "未命名船舶",
1126
- // 图标
1127
- rightIcons: getRightIcons(u)
1128
- });
1129
- E.set("id", u.id);
1130
- const S = createLabelFeatureStyle(E);
1131
- return E.setStyle(S), E;
1132
- }, H = (u) => {
1133
- const L = e.getView().getZoom();
1134
- u.forEach((E) => {
1135
- const S = m(E);
1136
- if (S.setStyle(createShipStyle(e, S)), s.addFeature(S), (l == null ? void 0 : l.id) == E.id || L >= MAP_ZOOM.shipModelMin)
1137
- if (t[E.id])
1138
- createLabelStyle(e, S);
1139
- else {
1140
- const M = Q(E);
1141
- o.addFeature(M);
1142
- }
1143
- });
1144
- };
1145
- return {
1146
- render: g,
1147
- selected: p,
1148
- filter: P,
1149
- blinking: f,
1150
- clear: D,
1151
- handleShipMapEvent: C
1152
- };
1153
- }, useLayerManager = (e) => {
1154
- const n = () => e == null ? void 0 : e.getLayers(), l = ref("vector"), s = () => l.value, a = (t) => {
1155
- l.value = t;
1156
- const r = n();
1157
- r && (r == null || r.getArray().forEach((g) => {
1158
- (g.className_ === "vector" || g.className_ === "satellite") && g.setVisible(g.className_ === t);
1159
- }));
1160
- }, o = ref(!1);
1161
- return {
1162
- getLayers: n,
1163
- getGreenTileVisible: () => o.value,
1164
- setGreenTileVisible: (t) => {
1165
- if (t !== o.value) {
1166
- if (t) {
1167
- const r = n();
1168
- if (!r.getArray().find((m) => m.className_ === "greenTile")) {
1169
- const m = new TileLayer({
1170
- source: new XYZ({ url: BASE_MAP_LINK.greenTile }),
1171
- visible: t,
1172
- zIndex: 2,
1173
- className: "greenTile"
1174
- });
1175
- r.push(m);
1176
- }
1177
- } else {
1178
- const r = n(), g = r.getArray().find((m) => m.className_ === "greenTile");
1179
- g && r.remove(g);
1180
- }
1181
- o.value = t;
1182
- }
1183
- },
1184
- getShowLayerType: s,
1185
- setShowLayerType: a
1186
- };
1187
- }, usePropsManager = () => {
1188
- const e = ref();
1189
- return {
1190
- setProps: (s) => {
1191
- e.value = s;
1192
- },
1193
- getProps: () => e.value
1194
- };
1195
- }, usePositionManager = (e) => {
1196
- const n = "zh-map-location-layer";
1197
- let l, s, a = null, o = null;
1198
- const y = (v) => {
1199
- if (!(!v || v.length === 0)) {
1200
- if (s || (s = new VectorSource()), s.clear(), o) {
1201
- const f = v.find((P) => P.id === o.id);
1202
- f ? o = f : v.push(o);
1203
- }
1204
- v.forEach((f) => {
1205
- T(f);
1206
- }), l || (l = new VectorLayer({
1207
- className: n,
1208
- source: s,
1209
- zIndex: 100
1210
- }), e == null || e.addLayer(l));
1211
- }
1212
- }, T = (v) => {
1213
- const f = getZoom(), [P, p] = v.latLon.split(","), C = new Feature({
1214
- geometry: new Point(fromLonLat([Number(P), Number(p)]))
1215
- });
1216
- C.setStyle(t(v, f, v.id === (o == null ? void 0 : o.id))), C.set("loactionData", v), s.addFeature(C);
1217
- }, t = (v, f, P) => {
1218
- const p = {
1219
- image: new Icon({
1220
- src: P && v.selectedPath || v.defaultPath,
1221
- scale: 0.5 * f / 10
1222
- })
1223
- };
1224
- return v.name && (p.text = new Text({
1225
- text: v.name,
1226
- font: "12px sans-serif",
1227
- fill: new Fill({
1228
- color: "#000000"
1229
- }),
1230
- backgroundFill: new Fill({
1231
- color: "#FFFFFF"
1232
- }),
1233
- offsetY: 30
1234
- })), new Style(p);
1235
- }, r = () => {
1236
- if (a) {
1237
- const v = a.get("loactionData").id;
1238
- s.getFeatures().forEach((f) => {
1239
- f.get("loactionData").id !== v && s.removeFeature(f);
1240
- });
1241
- } else
1242
- s.clear();
1243
- }, g = () => {
1244
- const v = a.get("loactionData"), f = getZoom();
1245
- s.getFeatures().forEach((p) => {
1246
- p.get("loactionData").id === v.id && (p == null || p.setStyle(t(v, f, !1)));
1247
- }), o = null, a = null;
1248
- }, m = (v) => {
1249
- v ? (N(), D(v)) : clearSelectedPort();
1250
- }, N = () => {
1251
- if (a) {
1252
- const v = a.get("loactionData"), f = getZoom();
1253
- a.setStyle(t(v, f, !1));
1254
- }
1255
- }, D = (v) => {
1256
- const f = s.getFeatures();
1257
- o = v, a = f.find((P) => P.get("loactionData").id === v.id);
1258
- };
1259
- return {
1260
- render: y,
1261
- selected: m,
1262
- clearSelected: g,
1263
- clear: r
1264
- };
1265
- }, disableDoubleClickZoom = (e) => {
1266
- e.getInteractions().forEach((n) => {
1267
- n instanceof DoubleClickZoom && n.setActive(!1);
1268
- });
1269
- }, enableDoubleClickZoom = (e) => {
1270
- e.getInteractions().forEach((n) => {
1271
- n instanceof DoubleClickZoom && n.setActive(!0);
1272
- });
1273
- }, useDrawLineManager = (e, n) => {
1274
- const l = ref([]), s = ref("km"), a = (S) => {
1275
- s.value = S;
1276
- };
1277
- let o;
1278
- const y = ref(!1), T = () => {
1279
- g(), disableDoubleClickZoom(e), v("pointer"), e.on("pointermove", D), e.getViewport().addEventListener("mouseout", () => {
1280
- o && o.classList.add("hidden");
1281
- }), P(), y.value = !0;
1282
- };
1283
- let t, r;
1284
- const g = () => {
1285
- t = new VectorSource(), r = new VectorLayer({
1286
- source: t,
1287
- zIndex: 1e3,
1288
- style: {
1289
- "fill-color": "rgba(255, 255, 255, 0.2)",
1290
- "stroke-color": "#ffcc33",
1291
- "stroke-width": 2,
1292
- "circle-radius": 7,
1293
- "circle-fill-color": "#ffcc33"
1294
- }
1295
- }), e == null || e.addLayer(r);
1296
- };
1297
- let m, N;
1298
- const D = (S) => {
1299
- if (S.dragging)
1300
- return;
1301
- let M = "点击选择起点";
1302
- m && (M = "单击继续,双击结束"), o && (o.innerHTML = M, N.setPosition(S.coordinate), o.classList.remove("hidden"));
1303
- }, v = (S) => {
1304
- const M = e == null ? void 0 : e.getTargetElement();
1305
- M && (M.style.cursor = S);
1306
- };
1307
- let f;
1308
- const P = () => {
1309
- f = new Draw({
1310
- source: t,
1311
- type: "LineString",
1312
- style: new Style({
1313
- fill: new Fill({
1314
- color: "rgba(255, 255, 255, 0.2)"
1315
- }),
1316
- stroke: new Stroke({
1317
- color: "rgba(255,204,51)",
1318
- lineDash: [10, 10],
1319
- width: 2
1320
- }),
1321
- image: new CircleStyle({
1322
- radius: 5,
1323
- stroke: new Stroke({
1324
- color: "rgba(0, 0, 0, 0.7)"
1325
- }),
1326
- fill: new Fill({
1327
- color: "rgba(255, 255, 255, 0.2)"
1328
- })
1329
- })
1330
- }),
1331
- // 添加条件函数,判断是否应该出发点绘制
1332
- condition: (M) => M.originalEvent.target.tagName !== "DIV"
1333
- }), e == null || e.addInteraction(f), Y(), Q();
1334
- let S;
1335
- f.on("drawstart", function(M) {
1336
- var $;
1337
- m = M.feature, m.set("randomId", p());
1338
- let O;
1339
- S = ($ = m.getGeometry()) == null ? void 0 : $.on("change", function(z) {
1340
- const F = z.target, R = computedDistance(F, s.value);
1341
- O = F.getLastCoordinate(), C && R && (C.innerHTML = R), Z.setPosition(O);
1342
- });
1343
- }), f.on("drawend", function() {
1344
- var M, O, $;
1345
- if (C && (C.className = "ol-tooltip ol-tooltip-static ol-tooltip-measure"), C != null && C.innerHTML) {
1346
- const z = (m == null ? void 0 : m.get("randomId")) || p();
1347
- l.value.push({ id: z, value: C == null ? void 0 : C.innerHTML }), C.innerHTML = `${C.innerHTML}<div class="ol-tooltip-delete-button" data-id="${z}"><i class="map-iconfont icon-delete"></i></div>`;
1348
- }
1349
- (M = document.querySelector(".ol-selectable:has(.ol-tooltip-delete-button):last-child .ol-tooltip-delete-button")) == null || M.addEventListener("click", (z) => {
1350
- var R;
1351
- z.preventDefault(), z.stopPropagation();
1352
- const F = (R = z.target) == null ? void 0 : R.getAttribute("data-id");
1353
- F && u(F);
1354
- }), Z.setOffset([0, -7]), m = null, C = null, Y(), S && unByKey(S), ($ = (O = n.getProps()) == null ? void 0 : O.lineDrawEnd) == null || $.call(O, l.value);
1355
- });
1356
- }, p = () => Math.random().toString(36).substring(2, 9);
1357
- let C, Z;
1358
- const Y = () => {
1359
- C != null && C.parentNode && C.parentNode.removeChild(C), C = document.createElement("div"), C.className = "ol-tooltip ol-tooltip-measure", Z = new Overlay({
1360
- element: C,
1361
- offset: [0, -15],
1362
- positioning: "bottom-center",
1363
- stopEvent: !1,
1364
- insertFirst: !1
1365
- }), e == null || e.addOverlay(Z);
1366
- }, Q = () => {
1367
- o != null && o.parentNode && o.parentNode.removeChild(o), o = document.createElement("div"), o.className = "ol-tooltip hidden", N = new Overlay({
1368
- element: o,
1369
- offset: [15, 0],
1370
- positioning: "center-left"
1371
- }), e == null || e.addOverlay(N);
1372
- }, H = () => {
1373
- l.value.forEach((S, M) => {
1374
- var z, F;
1375
- const O = document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");
1376
- O[M] && ((F = (z = O[M]) == null ? void 0 : z.parentNode) == null || F.removeChild(O[M]));
1377
- const $ = t.getFeatures();
1378
- $[M] && t.removeFeature($[M]);
1379
- }), L(), enableDoubleClickZoom(e), y.value = !1;
1380
- }, u = (S) => {
1381
- var O, $, z, F;
1382
- const M = l.value.findIndex((R) => R.id === S);
1383
- if (M !== -1) {
1384
- l.value.splice(M, 1);
1385
- const R = document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");
1386
- R[M] && (($ = (O = R[M]) == null ? void 0 : O.parentNode) == null || $.removeChild(R[M]));
1387
- const j = t.getFeatures();
1388
- j[M] && t.removeFeature(j[M]);
1389
- }
1390
- (F = (z = n.getProps()) == null ? void 0 : z.lineDrawEnd) == null || F.call(z, l.value);
1391
- }, L = () => {
1392
- if (l.value = [], document.querySelectorAll(".ol-tooltip.ol-tooltip-static").forEach((S) => {
1393
- var M;
1394
- (M = S == null ? void 0 : S.parentNode) == null || M.removeChild(S);
1395
- }), t.clear(), f) {
1396
- const S = e.getInteractions().getArray().find((M) => getUid(M) === getUid(f));
1397
- S && e.removeInteraction(S);
1398
- }
1399
- e.removeLayer(r), o != null && o.parentNode && o.parentNode.removeChild(o), C != null && C.parentNode && C.parentNode.removeChild(C);
1400
- };
1401
- return {
1402
- open: T,
1403
- close: H,
1404
- deleteLine: u,
1405
- setUnit: a,
1406
- getState: () => y.value
1407
- };
1408
- }, computedDistance = (e, n) => {
1409
- const s = getLength(e);
1410
- let a = "";
1411
- switch (n) {
1412
- case "m":
1413
- a = `${Math.round(s * 100) / 100} m`;
1414
- break;
1415
- case "km":
1416
- a = `${Math.round(s / 1e3 * 100) / 100} km`;
1417
- break;
1418
- case "nm":
1419
- a = `${Math.round(s / 1.852 * 100) / 100} nm`;
1420
- break;
1421
- }
1422
- return a;
1423
- }, useDrawPolygonManager = (e, n) => {
1424
- let l;
1425
- const s = () => {
1426
- a();
1427
- }, a = () => {
1428
- T(), P(), Z(), N();
1429
- };
1430
- let o = null, y = null;
1431
- const T = () => {
1432
- if (o || y) return;
1433
- const H = new VectorSource(), u = new VectorLayer({
1434
- source: H,
1435
- style: new Style({
1436
- stroke: new Stroke({
1437
- color: "#fbcc33",
1438
- width: 2
1439
- })
1440
- })
1441
- });
1442
- o = u, y = H, e.on("pointermove", r), e.addLayer(u), e.on(["dblclick"], function(L) {
1443
- g && (L.stopPropagation(), L.preventDefault());
1444
- });
1445
- };
1446
- let t;
1447
- const r = (H) => {
1448
- if (H.dragging) return;
1449
- const u = t ? "单击继续,双击结束" : "点击选择起点";
1450
- p && (p.innerHTML = u, C.setPosition(H.coordinate));
1451
- };
1452
- let g, m = !1;
1453
- const N = () => {
1454
- if (l) {
1455
- p != null && p.parentNode && p.parentNode.removeChild(p);
1456
- const u = l.getGeometry();
1457
- if (!u) return;
1458
- const L = D(u, "nm");
1459
- v && (v.innerHTML = `
1460
- <span class="text">面积:${L}${m ? '<span class="error pl-12">超出可以绘画的距离</span>' : ""}</span>
1461
- `), v && (v.innerHTML += '<span class="delete-icon" ><i class="map-iconfont icon-delete" /></div>');
1462
- const E = u.getCoordinates(), S = E[0][E[0].length - 2];
1463
- if (f.setPosition(S), o) {
1464
- const O = o.getSource();
1465
- O && l && (O.clear(), O.addFeature(l));
1466
- }
1467
- setTimeout(() => {
1468
- var O;
1469
- (O = document.querySelector(".delete-icon")) == null || O.addEventListener("click", () => {
1470
- var $, z;
1471
- console.log("delete"), Y(), (z = ($ = n.getProps()) == null ? void 0 : $.areaDrawEnd) == null || z.call($, []);
1472
- });
1473
- }, 0);
1474
- const M = getCenter(l.getGeometry().getExtent());
1475
- e == null || e.getView().setCenter(M);
1476
- return;
1477
- }
1478
- g = new Draw({
1479
- type: "Polygon",
1480
- source: y,
1481
- trace: !0,
1482
- style: [new Style({
1483
- stroke: new Stroke({
1484
- color: "rgba(255, 255, 255, 1)",
1485
- width: 1.5,
1486
- lineDash: [10, 10]
1487
- }),
1488
- fill: new Fill({
1489
- color: "rgba(255, 255, 255, 0.25)"
1490
- })
1491
- }), new Style({
1492
- image: new CircleStyle({
1493
- radius: 5,
1494
- fill: new Fill({
1495
- color: "rgb(51,112,255, 1)"
1496
- })
1497
- }),
1498
- geometry: function(u) {
1499
- const L = u.getGeometry().getCoordinates();
1500
- return new MultiPoint(L);
1501
- }
1502
- })]
1503
- }), e == null || e.addInteraction(g);
1504
- let H;
1505
- g.on("drawstart", (u) => {
1506
- var L;
1507
- t = u.feature, H = (L = t.getGeometry()) == null ? void 0 : L.on("change", (E) => {
1508
- const S = E.target, M = D(S, "nm"), $ = S.getCoordinates()[0], z = new LineString([$[$.length - 2], $[$.length - 1]]), F = computedDistance(z, "nm");
1509
- if (m = Number(getLength(z) / 1e3) > 150, !M) return;
1510
- const R = '<span class="error pl-4">超出可以绘画的距离</span>';
1511
- v && (v.innerHTML = `
1512
- <div class="text">
1513
- 面积:${M}
1514
- ${m ? R : ""}
1515
- </div>
1516
- `), p && (p.innerHTML = `
1517
- <div class="text">
1518
- 面积:${M}
1519
- </div>
1520
- <div class="text ${m ? "error" : ""}">
1521
- 线段 ${$.length - 2}: ${F}
1522
- ${m ? R : ""}
1523
-
1524
- </div>
1525
- <div>
1526
- <span class="text">单击继续,双击结束</span>
1527
- </div>
1528
- `);
1529
- });
1530
- }), g.on("drawend", (u) => {
1531
- var M, O, $, z;
1532
- if (!u.feature.getGeometry()) return;
1533
- l = u.feature, v && (v.innerHTML += '<span class="delete-icon"><i class="map-iconfont icon-delete" /></div>'), f.setOffset([10, 0]);
1534
- const E = u.feature.getGeometry().getCoordinates(), S = E[0][E[0].length - 2];
1535
- if (f.setPosition(S), p != null && p.parentNode && p.parentNode.removeChild(p), (M = n.getProps()) != null && M.areaDrawEnd) {
1536
- const F = E[0].map((R) => transform(R, projection.mercator, projection.data));
1537
- ($ = (O = n.getProps()) == null ? void 0 : O.areaDrawEnd) == null || $.call(O, F);
1538
- }
1539
- g && (g.setActive(!1), e == null || e.removeInteraction(g), (e == null ? void 0 : e.getInteractions()).forEach((R) => {
1540
- R instanceof Draw && (R.setActive(!1), e == null || e.removeInteraction(R));
1541
- })), H && unByKey(H), (z = document.querySelector(".delete-icon")) == null || z.addEventListener("click", () => {
1542
- var F, R;
1543
- Y(), (R = (F = n.getProps()) == null ? void 0 : F.areaDrawEnd) == null || R.call(F, []);
1544
- });
1545
- });
1546
- }, D = (H, u) => {
1547
- const L = getArea(H);
1548
- switch (u) {
1549
- case "km":
1550
- return L > 1e4 ? Math.round(L / 1e6 * 100) / 100 + " km<sup>2</sup>" : Math.round(L * 100) / 100 + " m<sup>2</sup>";
1551
- case "nm":
1552
- return L > 1e4 ? Math.round(L / 1e6 / Math.pow(1.852, 2) * 100) / 100 + " nm<sup>2</sup>" : Math.round(L * 100) / 100 + " m<sup>2</sup>";
1553
- }
1554
- };
1555
- let v, f;
1556
- const P = () => {
1557
- v != null && v.parentNode && v.parentNode.removeChild(v), v = document.createElement("div"), v.style.display = "flex", v.className = "ol-tooltip ol-tooltip-draw-polygon", f = new Overlay({
1558
- element: v,
1559
- offset: [0, -15],
1560
- positioning: "bottom-center",
1561
- stopEvent: !1,
1562
- insertFirst: !1
1563
- }), e == null || e.addOverlay(f);
1564
- };
1565
- let p, C;
1566
- const Z = () => {
1567
- p != null && p.parentNode && p.parentNode.removeChild(p), p = document.createElement("div"), p.className = "ol-tooltip ol-help-tooltip", C = new Overlay({
1568
- element: p,
1569
- offset: [15, 0],
1570
- positioning: "center-left"
1571
- }), e == null || e.addOverlay(C);
1572
- }, Y = () => {
1573
- y == null || y.clear(), l = null, P(), Z(), N();
1574
- };
1575
- return {
1576
- open: s,
1577
- close: () => {
1578
- y == null || y.clear(), y = null, o && (e.removeLayer(o), o = null), t = null, g && (g = null, e.getInteractions().forEach((H) => {
1579
- H instanceof Draw && e.removeInteraction(H);
1580
- })), p != null && p.parentElement && p.parentElement.removeChild(p), v != null && v.parentElement && v.parentElement.removeChild(v), C && e.removeOverlay(C), f && e.removeOverlay(f);
1581
- },
1582
- reset: Y
1583
- };
1584
- }, PORT_LAYER_CLASS_NAME = "zh-map-port-layer", usePortManager = (e) => {
1585
- const n = e.getInstall();
1586
- let l, s, a = null, o = null;
1587
- const y = (f) => {
1588
- if (!(!f || f.length === 0)) {
1589
- if (s || (s = new VectorSource()), s.clear(), o) {
1590
- const P = f.find((p) => p.id === o.id);
1591
- P ? o = P : f.push(o);
1592
- }
1593
- f.forEach((P) => {
1594
- T(P);
1595
- }), l || (l = new VectorLayer({
1596
- className: PORT_LAYER_CLASS_NAME,
1597
- source: s,
1598
- zIndex: 100
1599
- }), n.addLayer(l));
1600
- }
1601
- }, T = (f) => {
1602
- const P = e.getZoom(), [p, C] = f.latLon.split(","), Z = new Feature({
1603
- geometry: new Point(fromLonLat([Number(p), Number(C)]))
1604
- });
1605
- Z.setStyle(t(f, P, f.id === (o == null ? void 0 : o.id))), Z.set("portData", f), s.addFeature(Z);
1606
- }, t = (f, P, p) => {
1607
- const C = (Y) => `<svg width="46" height="46" viewBox="0 0 46 46" fill="none" xmlns="http://www.w3.org/2000/svg">
1608
- <path fill-rule="evenodd" clip-rule="evenodd" d="M22.6563 44.9304C22.5453 44.8844 22.4445 44.817 22.3595 44.7321C22.3595 44.7321 9.36986 31.7424 9.32952 31.6913C7.09059 29.0791 5.64794 25.8802 5.17255 22.4736C4.69716 19.0671 5.20896 15.5957 6.64728 12.471C8.08561 9.34625 10.3902 6.69909 13.2878 4.84325C16.1855 2.98741 19.5548 2.00068 22.9965 2C26.4381 1.99932 29.8078 2.98473 32.7062 4.83943C35.6046 6.69414 37.9102 9.34039 39.3498 12.4646C40.7893 15.5888 41.3025 19.0599 40.8284 22.4666C40.3544 25.8734 38.913 29.0729 36.6751 31.686C36.6401 31.737 23.6531 44.7321 23.6531 44.7321C23.5682 44.817 23.4674 44.8844 23.3564 44.9304C23.2454 44.9763 23.1265 45 23.0063 45C22.8862 45 22.7673 44.9763 22.6563 44.9304Z" fill="${Y}"/>
1609
- <g clip-path="url(#clip0_10059_122082)">
1610
- <path d="M34.8624 22.8687L32.5874 25.6313L33.4812 25.7125C33.4812 25.7125 30.5562 28.0687 27.9562 28.2312C25.3562 28.3937 24.1374 24.9 24.1374 24.9V19.1312H27.6312V17.425H24.2999V15.15C25.7624 14.6625 26.7374 13.2812 26.7374 11.6562C26.7374 9.625 25.1124 8 23.0812 8H22.9999C20.9687 8 19.3437 9.625 19.3437 11.6562C19.3437 13.2812 20.3999 14.6625 21.7812 15.15V17.425H18.4499V19.1312H21.9437V24.9C21.9437 24.9 20.6437 28.3125 18.0437 28.2312C15.4437 28.0687 12.5187 25.7125 12.5187 25.7125L13.4124 25.6313L11.0562 22.8687L10.2437 26.2812L11.2187 26.0375C11.2187 26.0375 13.1687 29.5313 16.1749 30.8313C19.1812 32.2125 22.1874 33.9187 22.8374 34C23.4874 33.9187 26.4937 32.2125 29.4187 30.8313C32.3437 29.45 34.3749 26.0375 34.3749 26.0375L35.3499 26.2812L34.8624 22.8687ZM23.0812 13.6875C21.9437 13.6875 21.0499 12.7937 21.0499 11.6562C21.0499 10.6 21.9437 9.70625 22.9999 9.70625H23.0812C24.1374 9.70625 25.0312 10.6 25.0312 11.6562C25.1124 12.7937 24.1374 13.6875 23.0812 13.6875Z" fill="white"/>
1611
- </g>
1612
- <defs>
1613
- <clipPath id="clip0_10059_122082">
1614
- <rect width="26" height="26" fill="white" transform="translate(10 8)"/>
1615
- </clipPath>
1616
- </defs>
1617
- </svg>
1618
- `, Z = () => `data:image/svg+xml;utf8,${encodeURIComponent(C(p ? "#FF5733" : "#3370FF"))}`;
1619
- return new Style({
1620
- text: new Text({
1621
- text: f.shortName,
1622
- font: "12px sans-serif",
1623
- fill: new Fill({
1624
- color: p ? "#ffffff" : "#000000"
1625
- }),
1626
- backgroundFill: new Fill({
1627
- color: p ? "#FF5733" : "#FFFFFF"
1628
- }),
1629
- offsetY: 30
1630
- }),
1631
- image: new Icon({
1632
- src: Z(),
1633
- scale: 0.5 * P / 10
1634
- })
1635
- });
1636
- }, r = () => {
1637
- if (a) {
1638
- console.log("清除非选中的港口");
1639
- const f = a.get("portData").id;
1640
- s.getFeatures().forEach((P) => {
1641
- P.get("portData").id !== f && s.removeFeature(P);
1642
- });
1643
- } else
1644
- console.log("清除所有港口", s), s.clear();
1645
- }, g = () => {
1646
- const f = a == null ? void 0 : a.get("portData"), P = e.getZoom();
1647
- f && s.getFeatures().forEach((C) => {
1648
- C.get("portData").id === f.id && (C == null || C.setStyle(t(f, P, !1)));
1649
- }), o = null, a = null;
1650
- }, m = (f) => {
1651
- f ? (N(), D(f)) : g();
1652
- }, N = () => {
1653
- if (a) {
1654
- const f = a == null ? void 0 : a.get("portData"), P = e.getZoom();
1655
- a.setStyle(t(f, P, !1));
1656
- }
1657
- }, D = (f) => {
1658
- const P = s.getFeatures();
1659
- o = f, a = P.find((p) => p.get("portData").id === f.id);
1660
- };
1661
- return {
1662
- render: y,
1663
- clear: r,
1664
- selected: m,
1665
- handlePortHover: (f) => {
1666
- const P = n == null ? void 0 : n.getTargetElement();
1667
- f && f.get("portData") && P && (P.style.cursor = "pointer");
1668
- }
1669
- };
1670
- }, useEventManager = (e, n, l, s, a, o) => {
1671
- const y = e.getInstall();
1672
- y.on("moveend", () => {
1673
- var t, r;
1674
- const T = e.getZoom();
1675
- (r = (t = n.getProps()).mapMoveEnd) == null || r.call(t, T), l.reRenderTrackLine();
1676
- }), y.on("pointermove", (T) => {
1677
- const t = y.getEventPixel(T.originalEvent), r = y.forEachFeatureAtPixel(t, (g) => g);
1678
- s.handleShipMapEvent(r, "hover"), l.handleTrackMapEvent(r, "hover", T), r && a.handlePortHover(r);
1679
- }), y.on("movestart", () => {
1680
- console.log("movestart-----------------------");
1681
- }), y.on("click", debounce((T) => {
1682
- var g, m, N;
1683
- if (console.log("1", o.getState()), o.getState()) return;
1684
- const t = y.getEventPixel(T.originalEvent), r = y.forEachFeatureAtPixel(
1685
- t,
1686
- (D) => {
1687
- if (D != null && D.get("shipData") || D != null && D.get("portData"))
1688
- return D;
1689
- }
1690
- );
1691
- if (console.log("2", r), !!r) {
1692
- if (T.preventDefault(), T.stopPropagation(), r.get("shipData"))
1693
- s.handleShipMapEvent(r, "click", (g = n.getProps()) == null ? void 0 : g.selectShip);
1694
- else if (r.get("portData")) {
1695
- const D = r.get("portData");
1696
- a.selected(D), (N = (m = n.getProps()) == null ? void 0 : m.selectPort) == null || N.call(m, D);
1697
- }
1698
- }
1699
- }, 150));
1700
- }, useMapController = () => {
1701
- const e = reactive([]);
1702
- return {
1703
- createInstance: (s, a) => {
1704
- const o = useMapInitializer();
1705
- o.initMap(s, a);
1706
- const y = o.getInstall(), T = useLayerManager(y), t = usePropsManager();
1707
- t.setProps(a), T.setShowLayerType(a.layerType), T.setGreenTileVisible(a.showGreenLayer);
1708
- const r = useTrackManager(y), g = useCarTrackManager(y, r), m = useShipManager(y), N = usePositionManager(y), D = useDrawLineManager(y, t), v = useDrawPolygonManager(y, t), f = usePortManager(o);
1709
- useEventManager(o, t, r, m, f, D);
1710
- const P = () => {
1711
- const C = y.getView().calculateExtent(o.getSize()), Z = transform([C[0], C[1]], projection.mercator, projection.data), Y = transform([C[2], C[3]], projection.mercator, projection.data);
1712
- return [Z[0], Z[1], Y[0], Y[1]];
1713
- }, p = {
1714
- id: Symbol("map-instance"),
1715
- innerMap: null,
1716
- map: o.getInstall(),
1717
- destroy: () => {
1718
- e.splice(e.indexOf(p), 1);
1719
- },
1720
- methods: {
1721
- ...o,
1722
- layer: T,
1723
- ship: m,
1724
- track: r,
1725
- carTrack: g,
1726
- port: {
1727
- render: f.render,
1728
- clear: f.clear,
1729
- selected: f.selected
1730
- },
1731
- position: N,
1732
- drawLine: D,
1733
- drawPolygon: v,
1734
- // 子模块
1735
- utils: {
1736
- getCalculateExtent: P,
1737
- convertSixHundredThousandToLatLng,
1738
- calculateCirclePoints
1739
- }
1740
- }
1741
- };
1742
- return e.push(p), p;
1743
- },
1744
- destroyInstance: (s) => {
1745
- const a = e.findIndex((o) => o.id === s);
1746
- a > -1 && (e[a].destroy(), e.splice(a, 1));
1747
- },
1748
- destroyAll: () => {
1749
- e.forEach((s) => s.destroy()), e.splice(0, e.length);
1750
- },
1751
- getAllInstances: () => [...e]
1752
- };
1753
- }, _hoisted_1 = { class: "zh-map-box" }, _sfc_main = /* @__PURE__ */ defineComponent({
1754
- __name: "Map",
1755
- props: {
1756
- zoom: { default: MAP_ZOOM.default },
1757
- center: { default: MAP_DEFAULT_CENTER },
1758
- layerType: { default: "vector" },
1759
- showGreenLayer: { type: Boolean, default: !1 },
1760
- showScale: { type: Boolean, default: !0 },
1761
- scaleLineUnit: { default: "metric" },
1762
- mapMoveEnd: { type: Function, default: () => {
1763
- } },
1764
- lineDrawEnd: {},
1765
- areaDrawEnd: { type: Function, default: () => {
1766
- } },
1767
- selectShip: { type: Function, default: () => {
1768
- } },
1769
- selectPort: { type: Function, default: () => {
1770
- } }
1771
- },
1772
- setup(e, { expose: n }) {
1773
- const l = ref(), s = ref(), a = useMapController(), o = ref(), y = e, T = ref({
1774
- getInstall() {
1775
- }
1776
- });
1777
- return onMounted(() => {
1778
- var t;
1779
- o.value = a.createInstance(l.value, y), console.log(" instance.value?.methods", o.value.map), T.value = o.value.methods, (t = s.value) == null || t.setScaleLine(o.value.map, y.scaleLineUnit);
1780
- }), onUnmounted(() => {
1781
- var t, r;
1782
- a.destroyInstance((t = o == null ? void 0 : o.value) == null ? void 0 : t.id), (r = o.value) == null || r.destroy();
1783
- }), n({
1784
- getZoom: () => {
1785
- var t;
1786
- return (t = o.value) == null ? void 0 : t.methods.getZoom();
1787
- },
1788
- setZoom: (t) => {
1789
- var r;
1790
- return (r = o.value) == null ? void 0 : r.methods.setZoom(t);
1791
- },
1792
- getInstall: () => {
1793
- var t;
1794
- return (t = o.value) == null ? void 0 : t.methods.getInstall();
1795
- },
1796
- getView: () => {
1797
- var t;
1798
- return (t = o.value) == null ? void 0 : t.methods.getView();
1799
- },
1800
- setCenter: (t, r) => {
1801
- var g;
1802
- return (g = o.value) == null ? void 0 : g.methods.setCenter(t, r);
1803
- },
1804
- getSize: () => {
1805
- var t;
1806
- return (t = o.value) == null ? void 0 : t.methods.getSize();
1807
- },
1808
- getCenter: (t, r) => {
1809
- var g;
1810
- return (g = o.value) == null ? void 0 : g.methods.getCenter();
1811
- },
1812
- layer: {
1813
- setGreenTileVisible: (t) => {
1814
- var r;
1815
- return (r = o.value) == null ? void 0 : r.methods.layer.setGreenTileVisible(t);
1816
- },
1817
- getGreenTileVisible: () => {
1818
- var t;
1819
- return (t = o.value) == null ? void 0 : t.methods.layer.getGreenTileVisible();
1820
- },
1821
- getShowLayerType: () => {
1822
- var t;
1823
- return (t = o.value) == null ? void 0 : t.methods.layer.getShowLayerType();
1824
- },
1825
- setShowLayerType: (t) => {
1826
- var r;
1827
- return (r = o.value) == null ? void 0 : r.methods.layer.setShowLayerType(t);
1828
- }
1829
- },
1830
- ship: {
1831
- render: (...t) => {
1832
- var r;
1833
- return (r = o.value) == null ? void 0 : r.methods.ship.render(...t);
1834
- },
1835
- selected: (...t) => {
1836
- var r;
1837
- return (r = o.value) == null ? void 0 : r.methods.ship.selected(...t);
1838
- },
1839
- filter: (...t) => {
1840
- var r;
1841
- return (r = o.value) == null ? void 0 : r.methods.ship.filter(...t);
1842
- },
1843
- blinking: (...t) => {
1844
- var r;
1845
- return (r = o.value) == null ? void 0 : r.methods.ship.blinking(...t);
1846
- },
1847
- clear: () => {
1848
- var t;
1849
- return (t = o.value) == null ? void 0 : t.methods.ship.clear();
1850
- }
1851
- },
1852
- track: {
1853
- render: (...t) => {
1854
- var r;
1855
- return (r = o.value) == null ? void 0 : r.methods.track.render(...t);
1856
- },
1857
- remove: (...t) => {
1858
- var r;
1859
- return (r = o.value) == null ? void 0 : r.methods.track.remove(...t);
1860
- },
1861
- play: (...t) => {
1862
- var r;
1863
- return (r = o.value) == null ? void 0 : r.methods.track.play(...t);
1864
- },
1865
- setCenter: (...t) => {
1866
- var r;
1867
- return (r = o.value) == null ? void 0 : r.methods.track.setCenter(...t);
1868
- },
1869
- close: (...t) => {
1870
- var r;
1871
- return (r = o.value) == null ? void 0 : r.methods.track.close(...t);
1872
- },
1873
- getLength: (...t) => {
1874
- var r;
1875
- return (r = o.value) == null ? void 0 : r.methods.track.getLength(...t);
1876
- }
1877
- },
1878
- carTrack: {
1879
- location: (...t) => {
1880
- var r;
1881
- return (r = o.value) == null ? void 0 : r.methods.carTrack.location(...t);
1882
- },
1883
- remove: (...t) => {
1884
- var r;
1885
- return (r = o.value) == null ? void 0 : r.methods.carTrack.remove(...t);
1886
- },
1887
- renderTrack: (...t) => {
1888
- var r;
1889
- return (r = o.value) == null ? void 0 : r.methods.carTrack.renderTrack(...t);
1890
- },
1891
- setCenter: (...t) => {
1892
- var r;
1893
- return (r = o.value) == null ? void 0 : r.methods.carTrack.setCenter(...t);
1894
- },
1895
- closeTrack: () => {
1896
- var t;
1897
- return (t = o.value) == null ? void 0 : t.methods.carTrack.closeTrack();
1898
- },
1899
- playTrack: (...t) => {
1900
- var r;
1901
- return (r = o.value) == null ? void 0 : r.methods.carTrack.playTrack(...t);
1902
- }
1903
- },
1904
- port: {
1905
- render: (t) => {
1906
- var r;
1907
- return (r = o.value) == null ? void 0 : r.methods.port.render(t);
1908
- },
1909
- clear: () => {
1910
- var t;
1911
- return (t = o.value) == null ? void 0 : t.methods.port.clear();
1912
- },
1913
- selected: (t) => {
1914
- var r;
1915
- return (r = o.value) == null ? void 0 : r.methods.port.selected(t);
1916
- }
1917
- },
1918
- position: {
1919
- render: (...t) => {
1920
- var r;
1921
- return (r = o.value) == null ? void 0 : r.methods.position.render(...t);
1922
- },
1923
- selected: (...t) => {
1924
- var r;
1925
- return (r = o.value) == null ? void 0 : r.methods.position.selected(...t);
1926
- },
1927
- clearSelected: (...t) => {
1928
- var r;
1929
- return (r = o.value) == null ? void 0 : r.methods.position.clearSelected(...t);
1930
- },
1931
- clear: () => {
1932
- var t;
1933
- return (t = o.value) == null ? void 0 : t.methods.position.clear();
1934
- }
1935
- },
1936
- drawLine: {
1937
- open: () => {
1938
- var t;
1939
- return (t = o.value) == null ? void 0 : t.methods.drawLine.open();
1940
- },
1941
- close: () => {
1942
- var t;
1943
- return (t = o.value) == null ? void 0 : t.methods.drawLine.close();
1944
- },
1945
- deleteLine: (t) => {
1946
- var r;
1947
- return (r = o.value) == null ? void 0 : r.methods.drawLine.deleteLine(t);
1948
- },
1949
- setUnit: (t) => {
1950
- var r;
1951
- return (r = o.value) == null ? void 0 : r.methods.drawLine.setUnit(t);
1952
- },
1953
- getState: () => {
1954
- var t;
1955
- return (t = o.value) == null ? void 0 : t.methods.drawLine.getState();
1956
- }
1957
- },
1958
- drawPolygon: {
1959
- open: () => {
1960
- var t;
1961
- return (t = o.value) == null ? void 0 : t.methods.drawPolygon.open();
1962
- },
1963
- close: () => {
1964
- var t;
1965
- return (t = o.value) == null ? void 0 : t.methods.drawPolygon.close();
1966
- },
1967
- reset: () => {
1968
- var t;
1969
- return (t = o.value) == null ? void 0 : t.methods.drawPolygon.reset();
1970
- }
1971
- },
1972
- // 子模块
1973
- utils: {
1974
- getCalculateExtent: (...t) => {
1975
- var r;
1976
- return (r = o.value) == null ? void 0 : r.methods.utils.getCalculateExtent(...t);
1977
- },
1978
- convertSixHundredThousandToLatLng: (...t) => {
1979
- var r;
1980
- return (r = o.value) == null ? void 0 : r.methods.utils.convertSixHundredThousandToLatLng(...t);
1981
- },
1982
- calculateCirclePoints: (t, r) => {
1983
- var g;
1984
- return (g = o.value) == null ? void 0 : g.methods.utils.calculateCirclePoints(t, r);
1985
- }
1986
- }
1987
- }), (t, r) => (openBlock(), createElementBlock("div", _hoisted_1, [
1988
- createElementVNode("div", {
1989
- id: "map",
1990
- ref_key: "zhMapRef",
1991
- ref: l,
1992
- class: "zh-map"
1993
- }, null, 512),
1994
- createVNode(ScaleLine, {
1995
- ref_key: "scaleLineRef",
1996
- ref: s
1997
- }, null, 512),
1998
- createVNode(ZoomControl, {
1999
- ref: "zoomControlRef",
2000
- "map-instance": o.value
2001
- }, null, 8, ["map-instance"])
2002
- ]));
2003
- }
2004
- }), Map$1 = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-117d7b5a"]]), ZhMap = withInstall(Map$1);
2005
- export {
2006
- ZhMap as Z
2007
- };