zhihao-ui 1.3.17 → 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,2003 +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: s }) {
8
- return s({
9
- setScaleLine: (n, a) => {
10
- a || (a = "metric");
11
- const o = new ScaleLine$1({
12
- units: a
13
- }), m = document.getElementById("scale-line-container");
14
- m && (o.setTarget(m), n.addControl(o));
15
- }
16
- }), (n, 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 s = e;
28
- console.log("props", s);
29
- const l = () => {
30
- console.log("props");
31
- const { setZoom: a, getZoom: o, getInstall: m } = s.mapInstance.methods;
32
- if (!m()) return;
33
- const t = o();
34
- t && a(t + 1);
35
- }, n = () => {
36
- const { setZoom: a, getZoom: o, getInstall: m } = s.mapInstance.methods;
37
- if (!m()) 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: n
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(), s = () => e.value, l = () => s().getView(), n = () => {
76
- var v;
77
- return (v = l()) == null ? void 0 : v.getZoom();
78
- }, a = (v) => {
79
- var P;
80
- (P = l()) == null || P.setZoom(v);
81
- }, o = (v, P) => {
82
- var O;
83
- (O = l()) == null || O.setCenter(fromLonLat([v, P]));
84
- }, m = () => {
85
- var P;
86
- const v = (P = l()) == null ? void 0 : P.getCenter();
87
- return toLonLat(v);
88
- }, L = () => {
89
- var v;
90
- return (v = s()) == null ? void 0 : v.getSize();
91
- }, t = new Map$2(), r = (v, P) => {
92
- w(P);
93
- const O = {
94
- zoom: P.zoom,
95
- center: fromLonLat(P.center),
96
- minZoom: MAP_ZOOM.min,
97
- maxZoom: MAP_ZOOM.max,
98
- constrainResolution: !0,
99
- enableRotation: !1,
100
- multiWorld: !0
101
- }, f = new Map$2({
102
- target: v,
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(O)
113
- });
114
- e.value = f;
115
- }, w = (v) => {
116
- t.set("vectorTile", new TileLayer({
117
- source: new XYZ({ url: BASE_MAP_LINK.vectorTile }),
118
- visible: v.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: v.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: v.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: v.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: v.showGreenLayer,
143
- zIndex: 2,
144
- className: "greenTile"
145
- }));
146
- };
147
- return {
148
- getInstall: s,
149
- getView: l,
150
- getZoom: n,
151
- setZoom: a,
152
- setCenter: o,
153
- getCenter: m,
154
- getSize: L,
155
- initMap: r,
156
- setBaseLayerMap: w
157
- };
158
- }
159
- const convertSixHundredThousandToLatLng = function(e, s) {
160
- const l = Number(s) / 6e5;
161
- return [Number(e) / 6e5, l];
162
- }, calculateCirclePoints = (e, s) => {
163
- const l = fromLonLat(e), n = s * 1e3, a = [
164
- l[0] - n,
165
- l[1] - n,
166
- l[0] + n,
167
- l[1] + n
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, s) {
176
- const n = getLength(e);
177
- let a = "";
178
- switch (console.log(s, LENGTH_UNIT), s) {
179
- case LENGTH_UNIT.M:
180
- a = Math.round(n * 100) / 100 + " m";
181
- break;
182
- case LENGTH_UNIT.KM:
183
- a = Math.round(n / 1e3 * 100) / 100 + " km";
184
- break;
185
- case LENGTH_UNIT.NM:
186
- a = (Math.round(n / 1e3 * 100) / 100 / 1.852).toFixed(2) + " nm";
187
- break;
188
- }
189
- return a;
190
- };
191
- function lonLatToMercator(e) {
192
- const s = 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, [s, 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 s = 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: s,
208
- zIndex: 100
209
- });
210
- }, mercatorToLonLat = (e, s = "lonlat") => {
211
- const l = { lon: 0, lat: 0 }, n = 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 = n, l.lat = a, s === "lonlat" ? l : [n, a];
214
- }, formatMinutesToDDHHMM = (e) => {
215
- const s = hooks.duration(e, "minutes"), l = Math.floor(s.asDays()), n = s.hours(), a = s.minutes();
216
- let o = `${String(a).padStart(2, "0")}分`;
217
- return n !== 0 && (o = `${String(n).padStart(2, "0")}时${o}`), l !== 0 && (o = `${String(l).padStart(2, "0")}天${o}`), o;
218
- }, useCarTrackManager = (e, s) => {
219
- let l = null;
220
- const n = async (w) => {
221
- if (!e || (console.log("vehicleInfo", w), !(w != null && w.lon && (w != null && w.lat)))) return;
222
- const v = Math.abs(Number(w.lon)) > 180 ? convertSixHundredThousandToLatLng(w.lon, w.lat) : [w.lon, w.lat];
223
- a(w, fromLonLat(v));
224
- const P = e == null ? void 0 : e.getView(), O = new Point(v);
225
- P.setCenter(transform(O.getCoordinates(), projection.data, projection.mercator));
226
- }, a = (w, v) => {
227
- const P = `${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 O = l.getElement();
235
- O.style.backgroundImage = `url(${P})`, O.style.width = "80px", O.style.height = "80px";
236
- const f = (w == null ? void 0 : w.drc) || "";
237
- O.style.transform = `rotate(${f}deg)`, O.style.backgroundSize = "cover", l == null || l.setPosition(v);
238
- };
239
- return {
240
- location: n,
241
- remove: () => {
242
- const w = l == null ? void 0 : l.getElement();
243
- w && (w.innerHTML = "");
244
- },
245
- renderTrack: (w, v, P) => {
246
- s.render(w, v, P, "truck", 1e3);
247
- },
248
- setCenter: (w) => {
249
- s.setCenter(w);
250
- },
251
- closeTrack: () => {
252
- s.close();
253
- },
254
- playTrack: (w, v) => {
255
- s.play(w, v);
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 s = /* @__PURE__ */ new Map(), l = {};
262
- let n = null;
263
- const a = "--";
264
- let o = null;
265
- const m = document.createElement("div"), L = new Overlay({
266
- element: m,
267
- positioning: "top-left",
268
- stopEvent: !1,
269
- className: "track-label-popup"
270
- });
271
- let t, r, w, v, P, O = !1, f = Date.now(), y, F = 0, E = null, T = 20, G = !1;
272
- const q = 5, W = [], Q = (i) => {
273
- var c;
274
- for (W.unshift(i); W.length > q; ) {
275
- const d = W.pop(), p = s.get(d);
276
- p && ((c = p.getSource()) == null || c.clear(), e == null || e.removeLayer(p), s.delete(d), delete l[d]);
277
- }
278
- };
279
- let u = "";
280
- const x = ["#ff0000", "#00ff00", "#0079ff", "#ffa500", "#800080", "#008080", "#ffc0cb", "#800000", "#000080", "#808000"], g = debounce(() => {
281
- if (n && l[n] && s.get(n).getVisible() && G) {
282
- console.log("reRenderTrackLine------------");
283
- const i = cloneDeep(M(n, l[n]));
284
- ce(n, i);
285
- }
286
- }, 300), M = (i, c) => {
287
- let d = [];
288
- const p = Math.max(1, Math.floor(c.length / T));
289
- return d = c.filter((k, _) => _ % p === 0).map((k, _) => {
290
- if (Number(k.lon) > 180 || Number(k.lat) > 180) {
291
- const [N, z] = convertSixHundredThousandToLatLng(k.lon, k.lat);
292
- k.lon = N, k.lat = z;
293
- }
294
- return k.center = [k.lon, k.lat], k.centerPoint = lonLatToMercator(k.center), k.time = hooks(k.createdAt).format("YYYY-MM-DD HH:mm:ss"), k.id = i, k.index = _, k;
295
- }), d;
296
- }, V = async (i, c, d, p = "ship", b = 200) => {
297
- if (!e || (c = c == null ? void 0 : c.reverse(), L && p === "ship" && (e != null && e.getOverlays().getArray().includes(L) || e.addOverlay(L)), (c == null ? void 0 : c.length) < 2))
298
- return;
299
- Q(i), n = i, l[i] = c, T = b;
300
- const k = Object.keys(l).findIndex((_) => _ === i) || 0;
301
- u = d || x[k > 10 ? 10 : k], G = !0, await R(), await ne(n);
302
- }, D = (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
- s.forEach((c, d) => {
314
- var b;
315
- const p = d === i;
316
- c.getVisible() !== p && (c.setVisible(p), e.getLayers().getArray().includes(c) || e.addLayer(c), p || (b = c.getSource()) == null || b.clear());
317
- }), n = i;
318
- }, R = async () => {
319
- const i = n;
320
- if (!s.has(i)) {
321
- const k = D(i);
322
- s.set(i, k);
323
- }
324
- await $(i);
325
- const c = u || "", d = l[i] || [];
326
- if (!(d && d.length > 1)) return [];
327
- let p = [];
328
- p = M(i, d);
329
- const b = p.map((k) => k.centerPoint);
330
- p.length >= 2 && await S(i, b, c);
331
- }, S = (i, c, d) => {
332
- const p = new LineString(c), b = s.get(i).getSource(), k = b.getFeatureById(i);
333
- if (k)
334
- k.setGeometry(p), k.setId(i), k.setStyle(A(d)), E = k;
335
- else {
336
- const _ = new Feature({ geometry: p });
337
- _.setId(i), _.set("type", "line"), _.setStyle(A(d)), b.addFeature(_), E = _;
338
- }
339
- return E;
340
- }, A = (i) => new Style({
341
- stroke: new Stroke({
342
- color: i,
343
- width: 2
344
- })
345
- }), X = (i, c, d) => {
346
- const p = i == null ? void 0 : i.get("trackId");
347
- if (i && p && c === "hover") {
348
- e.getTargetElement().style.cursor = p ? "pointer" : "";
349
- const b = i.get("data"), k = K(b), _ = d == null ? void 0 : d.coordinate;
350
- _ && (m.querySelector(".popup-content"), m.innerHTML = k, L == null || L.setPosition(_));
351
- } else
352
- L && L.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((N) => {
395
- const z = e.getPixelFromCoordinate(fromLonLat(N.center));
396
- return {
397
- ...N,
398
- original: N,
399
- pixel: z,
400
- distance: 0
401
- // 先初始化,后续计算
402
- };
403
- });
404
- let p = 0;
405
- d[0].distance = 0;
406
- for (let N = 1; N < d.length; N++) {
407
- const z = d[N - 1].pixel, H = d[N].pixel, Y = H[0] - z[0], C = H[1] - z[1];
408
- p += Math.sqrt(Y * Y + C * C), d[N].distance = p;
409
- }
410
- const b = d.filter(
411
- (N, z) => z === 0 || z === d.length - 1
412
- ), k = [];
413
- for (let N = 0; N < b.length; N++) {
414
- const z = b[N];
415
- if (k.push(z), N < b.length - 1) {
416
- const H = b[N + 1], Y = H.distance - z.distance, C = Math.floor(Y / 100);
417
- for (let Z = 1; Z <= C; Z++) {
418
- const B = z.distance + Z * 100;
419
- if (B >= H.distance) break;
420
- const j = ae(
421
- d,
422
- B
423
- );
424
- j && k.push(j);
425
- }
426
- }
427
- }
428
- return Array.from(
429
- new Map(k.map((N) => [N.distance.toFixed(2), N])).values()
430
- ).map((N) => ({
431
- ...N.original,
432
- // 优先保留原始数据
433
- ...N,
434
- // 覆盖坐标等计算属性
435
- coord: N.coord,
436
- // 确保使用插值后的坐标
437
- pixel: N.pixel,
438
- distance: N.distance
439
- }));
440
- };
441
- function ae(i, c) {
442
- for (let d = 1; d < i.length; d++) {
443
- const p = i[d - 1], b = i[d];
444
- if (c >= p.distance && c <= b.distance) {
445
- const k = (c - p.distance) / (b.distance - p.distance), _ = p.pixel[0] + k * (b.pixel[0] - p.pixel[0]), N = p.pixel[1] + k * (b.pixel[1] - p.pixel[1]), z = e == null ? void 0 : e.getCoordinateFromPixel([_, N]);
446
- return {
447
- ...p,
448
- // 继承前一个点的属性(可调整)
449
- coord: z,
450
- pixel: [_, N],
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), p = d.map((k) => de(k));
462
- s.get(i).getSource().addFeatures(p), he(i, d, c, u), d.forEach((k) => {
463
- const _ = ue(i, u, k);
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 = [...ve(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 p = document.createElement("div");
478
- p.className = "track-overlay-label", p.style.position = "relative", p.style.backgroundColor = "rgba(255,255,255,0.8)", p.style.border = `1px solid ${c}`, p.style.fontSize = "12px", p.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 b = new Overlay({
492
- element: p,
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 b.set("class", "track-label-overlay"), b.set("trackId", i), b;
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 = s.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", p = "&#xe6d2", b = new Style({
529
- text: new Text({
530
- font: "Normal 22px map-iconfont",
531
- text: getIconFont(p),
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;"), z = getIconStyle("&#xe703;"), H = [];
539
- return Number(i.state) === 0 ? H.push(_) : Number(i.state) === 1 && H.push(z), H.push(b), H;
540
- }, he = (i, c, d, p) => {
541
- const b = c || [], k = c.length;
542
- k || (b.push(d[0]), b.push(d[d.length - 1]));
543
- const _ = [];
544
- for (let z = 0; z < k - 1; z++) {
545
- let H;
546
- const Y = c[z], C = (c[z + 1].index + Y.index) / 2;
547
- if (C % 2 === 0)
548
- H = d[C].centerPoint;
549
- else {
550
- const Z = d[Math.floor(C)], B = d[Math.ceil(C)];
551
- if (Z && B) {
552
- const [j, J] = Z.centerPoint, [I, ee] = B.centerPoint;
553
- H = [(j + I) / 2, (J + ee) / 2];
554
- }
555
- }
556
- if (H) {
557
- const Z = new Feature({
558
- geometry: new Point(H)
559
- });
560
- Z.set("type", "track_arrow"), Z.setStyle(
561
- new Style({
562
- text: new Text({
563
- font: "700 12px map-iconfont",
564
- text: getIconFont("&#xe6bc;"),
565
- fill: new Fill({ color: p }),
566
- // 设置箭头旋转 角度转为弧度
567
- rotation: le(
568
- c[z].center,
569
- c[z + 1].center
570
- ) * (Math.PI / 180)
571
- })
572
- })
573
- ), _.push(Z);
574
- }
575
- }
576
- const N = s.get(i).getSource();
577
- N == null || N.addFeatures(_);
578
- }, ne = (i) => {
579
- var k, _;
580
- const c = e.getView(), d = (k = s == null ? void 0 : s.get(i)) == null ? void 0 : k.getSource(), p = E || (i ? d == null ? void 0 : d.getFeatureById(i) : null);
581
- if (!p) return;
582
- const b = (_ = p == null ? void 0 : p.getGeometry()) == null ? void 0 : _.getExtent();
583
- if (b != null && b.length)
584
- try {
585
- const N = buffer(b, Math.max(b[2] - b[0], b[3] - b[1]) * 0.02);
586
- c.fit(N);
587
- } catch (N) {
588
- console.log(N);
589
- }
590
- }, ve = (i) => {
591
- const c = "&#xe69b;", b = 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: b })
597
- }),
598
- zIndex: 101
599
- })];
600
- }, me = () => {
601
- console.log("清除所有的轨迹-----"), U(), s.forEach((c) => {
602
- var d;
603
- (d = c.getSource()) == null || d.clear(), e == null || e.removeLayer(c);
604
- }), Object.keys(l).forEach((c) => {
605
- s.delete(c), delete l[c];
606
- }), G = !1, re();
607
- }, we = (i) => {
608
- const c = s.get(i || n);
609
- c == null || c.setVisible(!1);
610
- const d = e.getOverlays().getArray();
611
- for (let p = 0; p < d.length; ) {
612
- const b = d[p];
613
- b.get("class") === "track-label-overlay" ? (b.setPosition(void 0), e.removeOverlay(b)) : p++;
614
- }
615
- U();
616
- }, pe = (i, c = LENGTH_UNIT.NM) => {
617
- const d = {
618
- id: i,
619
- length: "--"
620
- }, b = (l[i] || []).map(
621
- (_) => transform([_.lon, _.lat], projection.data, projection.mercator)
622
- ), k = new LineString(b);
623
- return d.length = formatLength(k, c) || "--", d;
624
- }, Le = (i, c) => {
625
- xe(String(i), c);
626
- }, xe = (i, c) => {
627
- const d = l[String(i)], p = d == null ? void 0 : d.map((b) => [b.lon, b.lat]);
628
- p && ke(p, 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 C, Z;
639
- const d = Number(50 * c), p = ((C = i.frameState) == null ? void 0 : C.time) ?? Date.now(), b = p - f;
640
- if (F = (F + d * b / 1e6) % 2, f = p, F >= 1) {
641
- U();
642
- return;
643
- }
644
- const k = r.getCoordinateAt(
645
- F > 1 ? 2 - F : F
646
- ), _ = r.getCoordinateAt(
647
- F > 1 ? F - 0.01 : F
648
- ), N = r.getCoordinateAt(
649
- F > 1 ? 2 - F : F + 0.01
650
- ), H = le(
651
- mercatorToLonLat(_, "array"),
652
- mercatorToLonLat(N, "array")
653
- ) * Math.PI / 180;
654
- (Z = te.getText()) == null || Z.setRotation(H), v.setCoordinates(k);
655
- const Y = getVectorContext(i);
656
- Y.setStyle(te), Y.drawGeometry(v), e == null || e.render();
657
- }, be = () => {
658
- var i;
659
- O = !0, f = Date.now(), F = 0, v = ((i = w.getGeometry()) == null ? void 0 : i.clone()) || new Point([0, 0]), o && (y == null || y.on("postrender", o)), P == null || P.setGeometry(void 0);
660
- }, U = () => {
661
- O && (O = !1, P == null || P.setGeometry(void 0), o && y && y.un("postrender", o), y && (e == null || e.removeLayer(y)), y = null, P = null);
662
- }, ke = (i, c) => {
663
- O && 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
- }), w = new Feature({
671
- type: "icon",
672
- geometry: new Point(r.getFirstCoordinate())
673
- });
674
- const d = w.getGeometry();
675
- v = d ? d.clone() : new Point([0, 0]), P = new Feature({
676
- type: "geoMarker",
677
- style: te,
678
- geometry: v
679
- }), y = new VectorLayer({
680
- source: new VectorSource({
681
- features: [P]
682
- })
683
- }), e == null || e.addLayer(y), o = (p) => Me(p, c), be();
684
- }, le = (i, c, d) => {
685
- function p(C) {
686
- return 180 * (C % (2 * Math.PI)) / Math.PI;
687
- }
688
- function b(C) {
689
- return C % 360 * Math.PI / 180;
690
- }
691
- function k(C) {
692
- var Z;
693
- if (!C) throw new Error("Coordinate is required");
694
- if (!Array.isArray(C)) {
695
- if ((C == null ? void 0 : C.type) === "Feature" && (C == null ? void 0 : C.geometry) !== null && ((Z = C == null ? void 0 : C.geometry) == null ? void 0 : Z.type) === "Point")
696
- return C == null ? void 0 : C.geometry.coordinates;
697
- if (C.type === "Point") return (C == null ? void 0 : C.coordinates) || [];
698
- }
699
- if (Array.isArray(C) && C.length >= 2 && !Array.isArray(C[0]) && !Array.isArray(C[1]))
700
- return C;
701
- throw new Error(
702
- "Coordinate must be GeoJSON Point or an Array of numbers"
703
- );
704
- }
705
- function _(C, Z, B = {}) {
706
- if (B.final)
707
- return function(Te, Se) {
708
- return (_(Se, Te) + 180) % 360;
709
- }(C, Z);
710
- const j = k(C), J = k(Z), I = b(j[0]), ee = b(J[0]), se = b(j[1]), oe = b(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 p(Math.atan2(Ce, Ee));
712
- }
713
- function N(C) {
714
- return !isNaN(C) && C !== null && !Array.isArray(C);
715
- }
716
- function z(C, Z = {}, B = {}) {
717
- return C || console.log("Coordinates are required"), Array.isArray(C) || console.log("Coordinates must be an Array"), C.length < 2 && console.log("Coordinates must be at least 2 numbers long"), (!N(C[0]) || !N(C[1])) && console.log("Coordinates must contain numbers"), H({ type: "Point", coordinates: C }, Z, B);
718
- }
719
- function H(C, Z = {}, B = {}) {
720
- const j = {
721
- type: "Feature",
722
- id: "",
723
- properties: {},
724
- bbox: {},
725
- geometry: {}
726
- };
727
- return B.id !== void 0 && (j.id = B.id), B.bbox && (j.bbox = B.bbox), j.properties = Z, j.geometry = C, j;
728
- }
729
- const Y = _(z(i), z(c), d);
730
- return Y < 0 ? 360 + Y : Y;
731
- };
732
- return {
733
- render: V,
734
- remove: me,
735
- play: Le,
736
- setCenter: ne,
737
- close: we,
738
- getLength: pe,
739
- handleTrackMapEvent: X,
740
- reRenderTrackLine: g
741
- };
742
- };
743
- function useShipOverlay(e) {
744
- const s = 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
- })), n = 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: s,
788
- class: "ship-overlay-container",
789
- style: l.value
790
- }, [
791
- h(
792
- "div",
793
- {
794
- class: "ship-overlay-content",
795
- style: n.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, s, l, n) {
853
- if (s) {
854
- const a = new Overlay({
855
- element: l,
856
- positioning: "top-left",
857
- id: "label-" + (n == null ? void 0 : n.id),
858
- offset: [20, -20],
859
- autoPan: !1,
860
- position: s,
861
- className: n.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: s, hdg: l, cog: n } = e;
868
- return s ? l !== null && +l != 511 && n !== null ? n - +l >= 3 ? SHIP_DIRECT.right : n - +l <= -3 ? SHIP_DIRECT.left : SHIP_DIRECT.front : SHIP_DIRECT.front : "";
869
- }, createShipStyle = (e, s) => {
870
- const { shipData: l } = s.getProperties(), n = getShipType(e), a = getShipScale(e, l, n);
871
- return initShipStyle(s, a, n);
872
- }, getShipType = (e) => {
873
- const s = e == null ? void 0 : e.getView().getZoom();
874
- return s <= MAP_ZOOM.shipModelMax && s >= MAP_ZOOM.shipTriggleMin ? "ship" : "triangle";
875
- }, getShipScale = (e, s, l) => {
876
- if (l === "ship") {
877
- const { len: n, wid: a } = s, o = 97, m = 20, t = 1 / (e == null ? void 0 : e.getView().getResolution()), r = n * t / o, w = a * t / m;
878
- return Math.max(r, w);
879
- }
880
- return MAP_ZOOM.scaleNum;
881
- }, initShipStyle = (e, s, l) => {
882
- const { color: n, direct: a, isHighlight: o, shipData: m } = e.getProperties(), L = ((m == null ? void 0 : m.cog) - 90 + 360) % 360;
883
- return new Style({
884
- image: new Icon({
885
- src: t(),
886
- scale: s || MAP_ZOOM.scaleNum,
887
- anchor: [0.5, 0.5],
888
- rotation: L * 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="${n}" 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="${n}" 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, s) => {
923
- const l = selectedShipElement(e, s), n = s.id, { lon: a, lat: o } = s, m = new Overlay({
924
- element: l,
925
- position: fromLonLat([a, o]),
926
- id: "selected-" + n,
927
- positioning: "center-center",
928
- offset: [0, 5],
929
- className: "ship-selected-overlay"
930
- });
931
- return m.set("class", "ship-overlay-selected"), m;
932
- }, selectedShipElement = (e, s) => {
933
- const l = getShipType(e), n = getShipScale(e, s, l), a = l === "ship" ? 109 : 49, o = `
934
- <svg style="transform:scale(${n});" 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
- `, m = document.createElement("div");
939
- return m.className = "ship-overlay-selected", m.innerHTML = o, m;
940
- }, createLabelStyle = (e, s) => {
941
- const { shipData: l, blinking: n } = s.getProperties(), { lon: a, lat: o } = l, m = createLabelElement(s);
942
- a && o && addOverlay(e, fromLonLat([a, o]), m, { ...l, blinking: n });
943
- }, createLabelElement = (e) => {
944
- const s = document.createElement("div");
945
- s.className = "ship-overlay-box", s.style.position = "relative";
946
- const l = e.getProperties(), { shipData: n, blinking: a, blinkingColor: o, name: m } = l, { lon: L, lat: t } = n, r = createVNode({
947
- setup() {
948
- return useShipOverlay({
949
- selected: a,
950
- name: m,
951
- color: o,
952
- existDevice: n == null ? void 0 : n.existDevice,
953
- existMobile: n == null ? void 0 : n.existMobile,
954
- existWaterGauge: n == null ? void 0 : n.existWaterGauge
955
- });
956
- }
957
- });
958
- return render(r, s), s;
959
- }, getRightIcons = (e) => {
960
- const s = [];
961
- return e.existDevice && s.push("&#xe687;"), e.existMobile && s.push("&#xe688;"), e.existWaterGauge && s.push("&#xe686;"), s;
962
- }, createLabelFeatureStyle = (e) => {
963
- const { name: s, rightIcons: l } = e.getProperties(), n = `${s} ${l.map((w) => getIconFont(w)).join(" ")} `, a = [20, -20], m = -Math.atan2(-a[1], a[0]), L = Math.sqrt(a[0] ** 2 + a[1] ** 2), t = `<svg viewBox="0 0 ${L + 10} 20" width="${L + 10}" height="20" xmlns="http://www.w3.org/2000/svg" >
964
- <line x1="0" y1="0" x2="${10 + L}" y2="10" stroke="white" stroke-width="1"></line>
965
- </svg>`;
966
- return [new Style({
967
- text: new Text({
968
- text: n,
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: m,
982
- rotateWithView: !1
983
- })
984
- })];
985
- }, useShipManager = (e) => {
986
- let s = null, l = null;
987
- const n = new VectorSource(), a = new VectorImageLayer({
988
- source: n,
989
- className: "zh-map--ship-layer",
990
- renderBuffer: 300,
991
- zIndex: 101
992
- }), o = new VectorSource(), m = 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(m);
1001
- let L = "", t = {}, r = {};
1002
- const w = (u) => {
1003
- if (!u || !e) return;
1004
- const x = (l == null ? void 0 : l.id) || (s == null ? void 0 : s.get("id"));
1005
- if (l) {
1006
- const g = u.filter((M) => M.id === x);
1007
- g.length === 0 ? u.push(l) : l = g[0];
1008
- }
1009
- O(), f(!0), Q(u), P();
1010
- }, v = (u) => {
1011
- const x = (l == null ? void 0 : l.id) || (s == null ? void 0 : s.get("id")), g = fromLonLat([u == null ? void 0 : u.lon, u == null ? void 0 : u.lat]), M = u.fill || "#04C900", V = getShipDirectPath(u), D = new Feature({
1012
- geometry: new Point(g),
1013
- // 船舶数据
1014
- shipData: u,
1015
- id: u.id,
1016
- name: u.cnname || "未命名船舶",
1017
- selected: u.id === x,
1018
- // 图标
1019
- rightIcons: getRightIcons(u),
1020
- // 是否闪烁
1021
- blinking: t[u.id] || !1,
1022
- // 闪烁颜色
1023
- blinkingColor: r[u.id] || "",
1024
- // 船舶颜色
1025
- color: M,
1026
- // 船艏向的方向
1027
- direct: V,
1028
- // shipType,
1029
- // scale:scaleNum,
1030
- // rotation,
1031
- // 高亮
1032
- isHighlight: !1
1033
- });
1034
- return D.set("clickGeometry", new Circle(g)), D;
1035
- }, P = async () => {
1036
- if (!l || !e) return;
1037
- let x = e.getOverlays().getArray().find((g) => g.get("class") == "ship-overlay-selected");
1038
- if (console.log("selectedOverlay----------", x), x) {
1039
- const g = selectedShipElement(e, l);
1040
- await x.setElement(g), await x.setPosition(fromLonLat([l.lon, l.lat]));
1041
- } else
1042
- x = selectedShipStyle(e, l), x && e.addOverlay(x);
1043
- setTimeout(() => {
1044
- var g;
1045
- x && ((g = x.get("element")) != null && g.parentElement) && (x.get("element").parentElement.style.display = "block");
1046
- }, 20);
1047
- }, O = () => {
1048
- e && n && (n.clear(), o.clear(), f());
1049
- }, f = (u) => {
1050
- const x = e.getOverlays().getArray().filter((g) => g.get("class") == "zh-map-ship-overlay");
1051
- if (x && x.length > 0) {
1052
- for (let g = 0; g < x.length; g++)
1053
- if (!u && x[g].get("class") !== "ship-overlay-selected") {
1054
- const M = x[g];
1055
- M.setPosition(void 0), e.removeOverlay(M), M.dispose();
1056
- }
1057
- }
1058
- }, y = (u, x) => {
1059
- t = u, r = x;
1060
- const g = e.getOverlays().getArray(), M = n.getFeatures();
1061
- for (const V in t) {
1062
- const D = t[V], $ = g.find((S) => S.getId() === "label-" + V), R = M.find((S) => V === S.get("id"));
1063
- if ($ && R) {
1064
- R.set("blinking", D), R.set("blinkingColor", r[V] || "");
1065
- const S = $.getElement(), A = createLabelElement(R), X = A.querySelector(".ship-overlay-line"), K = S == null ? void 0 : S.querySelector(".ship-overlay-line");
1066
- S && S !== A && (K && X && X.replaceWith(K), $.setElement(A));
1067
- }
1068
- }
1069
- }, F = (u) => {
1070
- if (!e) return;
1071
- const x = n.getFeatures(), g = o.getFeatures(), M = s ? s.get("id") : "", V = x.filter((S) => S.get("id") !== M), D = g == null ? void 0 : g.filter((S) => S.get("id") !== M), $ = /* @__PURE__ */ new Map();
1072
- u.forEach((S) => {
1073
- $.set(S.id, !0);
1074
- });
1075
- const R = e.getOverlays().getArray();
1076
- V.forEach((S) => {
1077
- const A = S.get("id");
1078
- if (!$.has(A))
1079
- S.setStyle([]);
1080
- else {
1081
- const K = S.getStyle();
1082
- (K == null ? void 0 : K.length) == 0 && S.setStyle(createShipStyle(e, S));
1083
- }
1084
- const X = R.find((K) => K.getId() === "label-" + A);
1085
- X && X.setPosition(void 0);
1086
- }), D.forEach((S) => {
1087
- const A = S.get("id");
1088
- if (!$.has(A))
1089
- S.setStyle([]);
1090
- else {
1091
- const X = S.getStyle();
1092
- (X == null ? void 0 : X.length) == 0 && S.setStyle(createLabelFeatureStyle(S));
1093
- }
1094
- });
1095
- }, E = (u) => {
1096
- if (u) {
1097
- console.log("选中", u);
1098
- const x = n.getFeatures().find((g) => g.get("id") === u.id);
1099
- x && (s = x), l = u, P();
1100
- } else
1101
- console.log("取消选中"), l = null, s = null, q();
1102
- }, T = debounce((u, x, g) => {
1103
- if (u) {
1104
- const M = u.get("shipData"), V = u.get("id");
1105
- if (e.getTargetElement().style.cursor = V ? "pointer" : "", x === "click" && (E(M), g && g(V)), x === "hover") {
1106
- L && L !== V && G(), L = V;
1107
- const D = n.getFeatures().find(($) => $.get("id") === L);
1108
- D == null || D.set("isHighlight", !0), D == null || D.setStyle(createShipStyle(e, D));
1109
- }
1110
- } else
1111
- e.getTargetElement().style.cursor = "", G();
1112
- }, 10), G = () => {
1113
- const u = L ? n.getFeatures().find((x) => x.get("id") === L) : null;
1114
- L = null, u == null || u.set("isHighlight", !1), u == null || u.setStyle(createShipStyle(e, u));
1115
- }, q = () => {
1116
- try {
1117
- const x = e.getOverlays().getArray().find((g) => g.get("class") == "ship-overlay-selected");
1118
- x && x.setPosition(void 0);
1119
- } catch (u) {
1120
- console.log(u);
1121
- }
1122
- }, W = (u) => {
1123
- const x = fromLonLat([u == null ? void 0 : u.lon, u == null ? void 0 : u.lat]), g = new Feature({
1124
- geometry: new Point(x),
1125
- name: u.cnname || "未命名船舶",
1126
- // 图标
1127
- rightIcons: getRightIcons(u)
1128
- });
1129
- g.set("id", u.id);
1130
- const M = createLabelFeatureStyle(g);
1131
- return g.setStyle(M), g;
1132
- }, Q = (u) => {
1133
- const x = e.getView().getZoom();
1134
- u.forEach((g) => {
1135
- const M = v(g);
1136
- if (M.setStyle(createShipStyle(e, M)), n.addFeature(M), (l == null ? void 0 : l.id) == g.id || x >= MAP_ZOOM.shipModelMin)
1137
- if (t[g.id])
1138
- createLabelStyle(e, M);
1139
- else {
1140
- const V = W(g);
1141
- o.addFeature(V);
1142
- }
1143
- });
1144
- };
1145
- return {
1146
- render: w,
1147
- selected: E,
1148
- filter: F,
1149
- blinking: y,
1150
- clear: O,
1151
- handleShipMapEvent: T
1152
- };
1153
- }, useLayerManager = (e) => {
1154
- const s = () => e == null ? void 0 : e.getLayers(), l = ref("vector"), n = () => l.value, a = (t) => {
1155
- l.value = t;
1156
- const r = s();
1157
- r && (r == null || r.getArray().forEach((w) => {
1158
- (w.className_ === "vector" || w.className_ === "satellite") && w.setVisible(w.className_ === t);
1159
- }));
1160
- }, o = ref(!1);
1161
- return {
1162
- getLayers: s,
1163
- getGreenTileVisible: () => o.value,
1164
- setGreenTileVisible: (t) => {
1165
- if (t !== o.value) {
1166
- if (t) {
1167
- const r = s();
1168
- if (!r.getArray().find((v) => v.className_ === "greenTile")) {
1169
- const v = new TileLayer({
1170
- source: new XYZ({ url: BASE_MAP_LINK.greenTile }),
1171
- visible: t,
1172
- zIndex: 2,
1173
- className: "greenTile"
1174
- });
1175
- r.push(v);
1176
- }
1177
- } else {
1178
- const r = s(), w = r.getArray().find((v) => v.className_ === "greenTile");
1179
- w && r.remove(w);
1180
- }
1181
- o.value = t;
1182
- }
1183
- },
1184
- getShowLayerType: n,
1185
- setShowLayerType: a
1186
- };
1187
- }, usePropsManager = () => {
1188
- const e = ref();
1189
- return {
1190
- setProps: (n) => {
1191
- e.value = n;
1192
- },
1193
- getProps: () => e.value
1194
- };
1195
- }, usePositionManager = (e) => {
1196
- const s = "zh-map-location-layer";
1197
- let l, n, a = null, o = null;
1198
- const m = (f) => {
1199
- if (!(!f || f.length === 0)) {
1200
- if (n || (n = new VectorSource()), n.clear(), o) {
1201
- const y = f.find((F) => F.id === o.id);
1202
- y ? o = y : f.push(o);
1203
- }
1204
- f.forEach((y) => {
1205
- L(y);
1206
- }), l || (l = new VectorLayer({
1207
- className: s,
1208
- source: n,
1209
- zIndex: 100
1210
- }), e == null || e.addLayer(l));
1211
- }
1212
- }, L = (f) => {
1213
- const y = getZoom(), [F, E] = f.latLon.split(","), T = new Feature({
1214
- geometry: new Point(fromLonLat([Number(F), Number(E)]))
1215
- });
1216
- T.setStyle(t(f, y, f.id === (o == null ? void 0 : o.id))), T.set("loactionData", f), n.addFeature(T);
1217
- }, t = (f, y, F) => {
1218
- const E = {
1219
- image: new Icon({
1220
- src: F && f.selectedPath || f.defaultPath,
1221
- scale: 0.5 * y / 10
1222
- })
1223
- };
1224
- return f.name && (E.text = new Text({
1225
- text: f.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(E);
1235
- }, r = () => {
1236
- if (a) {
1237
- const f = a.get("loactionData").id;
1238
- n.getFeatures().forEach((y) => {
1239
- y.get("loactionData").id !== f && n.removeFeature(y);
1240
- });
1241
- } else
1242
- n.clear();
1243
- }, w = () => {
1244
- const f = a.get("loactionData"), y = getZoom();
1245
- n.getFeatures().forEach((E) => {
1246
- E.get("loactionData").id === f.id && (E == null || E.setStyle(t(f, y, !1)));
1247
- }), o = null, a = null;
1248
- }, v = (f) => {
1249
- f ? (P(), O(f)) : clearSelectedPort();
1250
- }, P = () => {
1251
- if (a) {
1252
- const f = a.get("loactionData"), y = getZoom();
1253
- a.setStyle(t(f, y, !1));
1254
- }
1255
- }, O = (f) => {
1256
- const y = n.getFeatures();
1257
- o = f, a = y.find((F) => F.get("loactionData").id === f.id);
1258
- };
1259
- return {
1260
- render: m,
1261
- selected: v,
1262
- clearSelected: w,
1263
- clear: r
1264
- };
1265
- }, disableDoubleClickZoom = (e) => {
1266
- e.getInteractions().forEach((s) => {
1267
- s instanceof DoubleClickZoom && s.setActive(!1);
1268
- });
1269
- }, enableDoubleClickZoom = (e) => {
1270
- e.getInteractions().forEach((s) => {
1271
- s instanceof DoubleClickZoom && s.setActive(!0);
1272
- });
1273
- }, changeCursor = (e, s) => {
1274
- const l = e.getViewport();
1275
- l && (l.style.cursor = s);
1276
- }, useDrawLineManager = (e, s) => {
1277
- const l = ref([]), n = ref("km"), a = (g) => {
1278
- n.value = g;
1279
- };
1280
- let o;
1281
- const m = ref(!1), L = () => {
1282
- w(), disableDoubleClickZoom(e), changeCursor(e, "crosshair"), e.on("pointermove", O), e.getViewport().addEventListener("mouseout", () => {
1283
- o && o.classList.add("hidden");
1284
- }), y(), m.value = !0;
1285
- };
1286
- let t, r;
1287
- const w = () => {
1288
- t = new VectorSource(), r = new VectorLayer({
1289
- source: t,
1290
- zIndex: 1e3,
1291
- style: {
1292
- "fill-color": "rgba(255, 255, 255, 0.2)",
1293
- "stroke-color": "#ffcc33",
1294
- "stroke-width": 2,
1295
- "circle-radius": 7,
1296
- "circle-fill-color": "#ffcc33"
1297
- }
1298
- }), e == null || e.addLayer(r);
1299
- };
1300
- let v, P;
1301
- const O = (g) => {
1302
- if (g.dragging)
1303
- return;
1304
- let M = "点击选择起点";
1305
- v && (M = "单击继续,双击结束"), o && (o.innerHTML = M, P.setPosition(g.coordinate), o.classList.remove("hidden"));
1306
- };
1307
- let f;
1308
- const y = () => {
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), G(), q();
1334
- let g;
1335
- f.on("drawstart", function(M) {
1336
- var D;
1337
- v = M.feature, v.set("randomId", F());
1338
- let V;
1339
- g = (D = v.getGeometry()) == null ? void 0 : D.on("change", function($) {
1340
- const R = $.target, S = computedDistance(R, n.value);
1341
- V = R.getLastCoordinate(), E && S && (E.innerHTML = S), T.setPosition(V);
1342
- });
1343
- }), f.on("drawend", function() {
1344
- var M, V, D;
1345
- if (E && (E.className = "ol-tooltip ol-tooltip-static ol-tooltip-measure"), E != null && E.innerHTML) {
1346
- const $ = (v == null ? void 0 : v.get("randomId")) || F();
1347
- l.value.push({ id: $, value: E == null ? void 0 : E.innerHTML }), E.innerHTML = `${E.innerHTML}<div class="ol-tooltip-delete-button" data-id="${$}"><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", ($) => {
1350
- var S;
1351
- $.preventDefault(), $.stopPropagation();
1352
- const R = (S = $.target) == null ? void 0 : S.getAttribute("data-id");
1353
- R && Q(R);
1354
- }), T.setOffset([0, -7]), v = null, E = null, G(), g && unByKey(g), (D = (V = s.getProps()) == null ? void 0 : V.lineDrawEnd) == null || D.call(V, l.value);
1355
- });
1356
- }, F = () => Math.random().toString(36).substring(2, 9);
1357
- let E, T;
1358
- const G = () => {
1359
- E != null && E.parentNode && E.parentNode.removeChild(E), E = document.createElement("div"), E.className = "ol-tooltip ol-tooltip-measure", T = new Overlay({
1360
- element: E,
1361
- offset: [0, -15],
1362
- positioning: "bottom-center",
1363
- stopEvent: !1,
1364
- insertFirst: !1
1365
- }), e == null || e.addOverlay(T);
1366
- }, q = () => {
1367
- o != null && o.parentNode && o.parentNode.removeChild(o), o = document.createElement("div"), o.className = "ol-tooltip hidden", P = new Overlay({
1368
- element: o,
1369
- offset: [15, 0],
1370
- positioning: "center-left"
1371
- }), e == null || e.addOverlay(P);
1372
- }, W = () => {
1373
- l.value.forEach((g, M) => {
1374
- var $, R;
1375
- const V = document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");
1376
- V[M] && ((R = ($ = V[M]) == null ? void 0 : $.parentNode) == null || R.removeChild(V[M]));
1377
- const D = t.getFeatures();
1378
- D[M] && t.removeFeature(D[M]);
1379
- }), u(), enableDoubleClickZoom(e), m.value = !1;
1380
- }, Q = (g) => {
1381
- var V, D, $, R;
1382
- const M = l.value.findIndex((S) => S.id === g);
1383
- if (M !== -1) {
1384
- l.value.splice(M, 1);
1385
- const S = document.querySelectorAll(".ol-tooltip.ol-tooltip-static.ol-tooltip-measure");
1386
- S[M] && ((D = (V = S[M]) == null ? void 0 : V.parentNode) == null || D.removeChild(S[M]));
1387
- const A = t.getFeatures();
1388
- A[M] && t.removeFeature(A[M]);
1389
- }
1390
- (R = ($ = s.getProps()) == null ? void 0 : $.lineDrawEnd) == null || R.call($, l.value);
1391
- }, u = () => {
1392
- if (l.value = [], document.querySelectorAll(".ol-tooltip.ol-tooltip-static").forEach((g) => {
1393
- var M;
1394
- (M = g == null ? void 0 : g.parentNode) == null || M.removeChild(g);
1395
- }), t.clear(), f) {
1396
- const g = e.getInteractions().getArray().find((M) => getUid(M) === getUid(f));
1397
- g && e.removeInteraction(g);
1398
- }
1399
- e.removeLayer(r), o != null && o.parentNode && o.parentNode.removeChild(o), E != null && E.parentNode && E.parentNode.removeChild(E);
1400
- };
1401
- return {
1402
- open: L,
1403
- close: W,
1404
- deleteLine: Q,
1405
- setUnit: a,
1406
- getState: () => m.value
1407
- };
1408
- }, computedDistance = (e, s) => {
1409
- const n = getLength(e);
1410
- let a = "";
1411
- switch (s) {
1412
- case "m":
1413
- a = `${Math.round(n * 100) / 100} m`;
1414
- break;
1415
- case "km":
1416
- a = `${Math.round(n / 1e3 * 100) / 100} km`;
1417
- break;
1418
- case "nm":
1419
- a = `${Math.round(n / 1.852 * 100) / 100} nm`;
1420
- break;
1421
- }
1422
- return a;
1423
- }, useDrawPolygonManager = (e, s) => {
1424
- let l, n;
1425
- const a = () => {
1426
- o(), changeCursor(e, "crosshair");
1427
- }, o = () => {
1428
- t(), E(), q(), O();
1429
- };
1430
- let m = null, L = null;
1431
- const t = () => {
1432
- if (m && L) return;
1433
- const u = new VectorSource(), x = new VectorLayer({
1434
- source: u,
1435
- style: new Style({
1436
- stroke: new Stroke({
1437
- color: "#fbcc33",
1438
- width: 2
1439
- })
1440
- })
1441
- });
1442
- m = x, L = u, e.on("pointermove", w), e.addLayer(x), e.on(["dblclick"], function(g) {
1443
- v && (g.stopPropagation(), g.preventDefault());
1444
- });
1445
- };
1446
- let r;
1447
- const w = (u) => {
1448
- if (u.dragging) return;
1449
- const x = r ? "单击继续,双击结束" : "点击选择起点";
1450
- T && (T.innerHTML = x, G.setPosition(u.coordinate));
1451
- };
1452
- let v, P = !1;
1453
- const O = () => {
1454
- if (l) {
1455
- T != null && T.parentNode && T.parentNode.removeChild(T);
1456
- const u = l.getGeometry();
1457
- if (!u) return;
1458
- const x = f(u, "nm");
1459
- y && (y.innerHTML = `
1460
- <span class="text">面积:${x}${P ? '<span class="error pl-12">超出可以绘画的距离</span>' : ""}</span>
1461
- `), y && (y.innerHTML += '<span class="delete-icon" ><i class="map-iconfont icon-delete" /></div>');
1462
- const g = u.getCoordinates(), M = g[0][g[0].length - 2];
1463
- if (F.setPosition(M), m) {
1464
- const D = m.getSource();
1465
- D && l && (D.clear(), D.addFeature(l));
1466
- }
1467
- setTimeout(() => {
1468
- var D;
1469
- (D = document.querySelector(".delete-icon")) == null || D.addEventListener("click", () => {
1470
- var $, R;
1471
- console.log("delete"), W(), (R = ($ = s.getProps()) == null ? void 0 : $.areaDrawEnd) == null || R.call($, []);
1472
- });
1473
- }, 0);
1474
- const V = getCenter(l.getGeometry().getExtent());
1475
- e == null || e.getView().setCenter(V);
1476
- return;
1477
- }
1478
- v = new Draw({
1479
- type: "Polygon",
1480
- source: L,
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 x = u.getGeometry().getCoordinates();
1500
- return new MultiPoint(x);
1501
- }
1502
- })]
1503
- }), e == null || e.addInteraction(v), v.on("drawstart", (u) => {
1504
- var x;
1505
- r = u.feature, n = (x = r.getGeometry()) == null ? void 0 : x.on("change", (g) => {
1506
- const M = g.target, V = f(M, "nm"), $ = M.getCoordinates()[0], R = new LineString([$[$.length - 2], $[$.length - 1]]), S = computedDistance(R, "nm");
1507
- if (P = Number(getLength(R) / 1e3) > 150, !V) return;
1508
- const A = '<span class="error pl-4">超出可以绘画的距离</span>';
1509
- y && (y.innerHTML = `
1510
- <div class="text">
1511
- 面积:${V}
1512
- ${P ? A : ""}
1513
- </div>
1514
- `), T && (T.innerHTML = `
1515
- <div class="text">
1516
- 面积:${V}
1517
- </div>
1518
- <div class="text ${P ? "error" : ""}">
1519
- 线段 ${$.length - 2}: ${S}
1520
- ${P ? A : ""}
1521
-
1522
- </div>
1523
- <div>
1524
- <span class="text">单击继续,双击结束</span>
1525
- </div>
1526
- `);
1527
- });
1528
- }), v.on("drawend", (u) => {
1529
- var V, D, $, R;
1530
- if (!u.feature.getGeometry()) return;
1531
- l = u.feature, y && (y.innerHTML += '<span class="delete-icon"><i class="map-iconfont icon-delete" /></div>'), F.setOffset([10, 0]);
1532
- const g = u.feature.getGeometry().getCoordinates(), M = g[0][g[0].length - 2];
1533
- if (F.setPosition(M), T != null && T.parentNode && T.parentNode.removeChild(T), (V = s.getProps()) != null && V.areaDrawEnd) {
1534
- const S = g[0].map((A) => transform(A, projection.mercator, projection.data));
1535
- ($ = (D = s.getProps()) == null ? void 0 : D.areaDrawEnd) == null || $.call(D, S);
1536
- }
1537
- v && (v.setActive(!1), e == null || e.removeInteraction(v), (e == null ? void 0 : e.getInteractions()).forEach((A) => {
1538
- A instanceof Draw && (A.setActive(!1), e == null || e.removeInteraction(A));
1539
- })), n && unByKey(n), (R = document.querySelector(".delete-icon")) == null || R.addEventListener("click", () => {
1540
- var S, A;
1541
- W(), (A = (S = s.getProps()) == null ? void 0 : S.areaDrawEnd) == null || A.call(S, []);
1542
- });
1543
- });
1544
- }, f = (u, x) => {
1545
- const g = getArea(u);
1546
- switch (x) {
1547
- case "km":
1548
- return g > 1e4 ? Math.round(g / 1e6 * 100) / 100 + " km<sup>2</sup>" : Math.round(g * 100) / 100 + " m<sup>2</sup>";
1549
- case "nm":
1550
- return g > 1e4 ? Math.round(g / 1e6 / Math.pow(1.852, 2) * 100) / 100 + " nm<sup>2</sup>" : Math.round(g * 100) / 100 + " m<sup>2</sup>";
1551
- }
1552
- };
1553
- let y, F;
1554
- const E = () => {
1555
- y != null && y.parentNode && y.parentNode.removeChild(y), y = document.createElement("div"), y.style.display = "flex", y.className = "ol-tooltip ol-tooltip-draw-polygon", F = new Overlay({
1556
- element: y,
1557
- offset: [0, -15],
1558
- positioning: "bottom-center",
1559
- stopEvent: !1,
1560
- insertFirst: !1
1561
- }), e == null || e.addOverlay(F);
1562
- };
1563
- let T, G;
1564
- const q = () => {
1565
- T != null && T.parentNode && T.parentNode.removeChild(T), T = document.createElement("div"), T.className = "ol-tooltip ol-help-tooltip", G = new Overlay({
1566
- element: T,
1567
- offset: [15, 0],
1568
- positioning: "center-left"
1569
- }), e == null || e.addOverlay(G);
1570
- }, W = () => {
1571
- L == null || L.clear(), l = null, E(), q(), O();
1572
- };
1573
- return {
1574
- open: a,
1575
- close: () => {
1576
- L == null || L.clear(), L = null, m && (e.removeLayer(m), m = null), r = null, v && (v.setActive(!1), (e == null ? void 0 : e.getInteractions()).forEach((x) => {
1577
- x instanceof Draw && (x.setActive(!1), e == null || e.removeInteraction(x));
1578
- }), v = null), n && unByKey(n), T != null && T.parentElement && T.parentElement.removeChild(T), y != null && y.parentElement && y.parentElement.removeChild(y), G && e.removeOverlay(G), F && e.removeOverlay(F), changeCursor(e, "pointer");
1579
- },
1580
- reset: W
1581
- };
1582
- }, PORT_LAYER_CLASS_NAME = "zh-map-port-layer", usePortManager = (e) => {
1583
- const s = e.getInstall();
1584
- let l, n, a = null, o = null;
1585
- const m = (f) => {
1586
- if (!(!f || f.length === 0)) {
1587
- if (n || (n = new VectorSource()), n.clear(), o) {
1588
- const y = f.find((F) => F.id === o.id);
1589
- y ? o = y : f.push(o);
1590
- }
1591
- f.forEach((y) => {
1592
- L(y);
1593
- }), l || (l = new VectorLayer({
1594
- className: PORT_LAYER_CLASS_NAME,
1595
- source: n,
1596
- zIndex: 100
1597
- }), s.addLayer(l));
1598
- }
1599
- }, L = (f) => {
1600
- const y = e.getZoom(), [F, E] = f.latLon.split(","), T = new Feature({
1601
- geometry: new Point(fromLonLat([Number(F), Number(E)]))
1602
- });
1603
- T.setStyle(t(f, y, f.id === (o == null ? void 0 : o.id))), T.set("portData", f), n.addFeature(T);
1604
- }, t = (f, y, F) => {
1605
- const E = (G) => `<svg width="46" height="46" viewBox="0 0 46 46" fill="none" xmlns="http://www.w3.org/2000/svg">
1606
- <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="${G}"/>
1607
- <g clip-path="url(#clip0_10059_122082)">
1608
- <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"/>
1609
- </g>
1610
- <defs>
1611
- <clipPath id="clip0_10059_122082">
1612
- <rect width="26" height="26" fill="white" transform="translate(10 8)"/>
1613
- </clipPath>
1614
- </defs>
1615
- </svg>
1616
- `, T = () => `data:image/svg+xml;utf8,${encodeURIComponent(E(F ? "#FF5733" : "#3370FF"))}`;
1617
- return new Style({
1618
- text: new Text({
1619
- text: f.shortName,
1620
- font: "12px sans-serif",
1621
- fill: new Fill({
1622
- color: F ? "#ffffff" : "#000000"
1623
- }),
1624
- backgroundFill: new Fill({
1625
- color: F ? "#FF5733" : "#FFFFFF"
1626
- }),
1627
- offsetY: 30
1628
- }),
1629
- image: new Icon({
1630
- src: T(),
1631
- scale: 0.5 * y / 10
1632
- }),
1633
- zIndex: F ? 110 : 100
1634
- });
1635
- }, r = () => {
1636
- if (a) {
1637
- console.log("清除非选中的港口");
1638
- const f = a.get("portData").id;
1639
- n.getFeatures().forEach((y) => {
1640
- y.get("portData").id !== f && n.removeFeature(y);
1641
- });
1642
- } else
1643
- console.log("清除所有港口", n), n == null || n.clear();
1644
- }, w = (f) => {
1645
- if (!f)
1646
- return v();
1647
- (a == null ? void 0 : a.get("portData").id) !== f.id && (v(), P(f));
1648
- }, v = () => {
1649
- if (a) {
1650
- const f = a == null ? void 0 : a.get("portData"), y = e.getZoom();
1651
- a.setStyle(t(f, y, !1));
1652
- }
1653
- }, P = (f) => {
1654
- const y = n.getFeatures();
1655
- o = f, a = y.find((F) => F.get("portData").id === f.id), a.setStyle(t(f, e.getZoom(), !0));
1656
- };
1657
- return {
1658
- render: m,
1659
- clear: r,
1660
- selected: w,
1661
- handlePortHover: (f) => {
1662
- const y = s == null ? void 0 : s.getTargetElement();
1663
- f && f.get("portData") && y && (y.style.cursor = "pointer");
1664
- }
1665
- };
1666
- }, useEventManager = (e, s, l, n, a, o) => {
1667
- const m = e.getInstall();
1668
- m.on("moveend", () => {
1669
- var t, r;
1670
- const L = e.getZoom();
1671
- (r = (t = s.getProps()).mapMoveEnd) == null || r.call(t, L), l.reRenderTrackLine();
1672
- }), m.on("pointermove", (L) => {
1673
- const t = m.getEventPixel(L.originalEvent), r = m.forEachFeatureAtPixel(t, (w) => w);
1674
- n.handleShipMapEvent(r, "hover"), l.handleTrackMapEvent(r, "hover", L), r && a.handlePortHover(r);
1675
- }), m.on("movestart", () => {
1676
- console.log("movestart-----------------------");
1677
- }), m.on("click", debounce((L) => {
1678
- var w, v, P;
1679
- if (console.log("1", o.getState()), o.getState()) return;
1680
- const t = m.getEventPixel(L.originalEvent), r = m.forEachFeatureAtPixel(
1681
- t,
1682
- (O) => {
1683
- if (O != null && O.get("shipData") || O != null && O.get("portData"))
1684
- return O;
1685
- }
1686
- );
1687
- if (console.log("2", r), !!r) {
1688
- if (L.preventDefault(), L.stopPropagation(), r.get("shipData"))
1689
- n.handleShipMapEvent(r, "click", (w = s.getProps()) == null ? void 0 : w.selectShip);
1690
- else if (r.get("portData")) {
1691
- const O = r.get("portData");
1692
- a.selected(O), (P = (v = s.getProps()) == null ? void 0 : v.selectPort) == null || P.call(v, O);
1693
- }
1694
- }
1695
- }, 150));
1696
- }, useMapController = () => {
1697
- const e = reactive([]);
1698
- return {
1699
- createInstance: (n, a) => {
1700
- const o = useMapInitializer();
1701
- o.initMap(n, a);
1702
- const m = o.getInstall(), L = useLayerManager(m), t = usePropsManager();
1703
- t.setProps(a), L.setShowLayerType(a.layerType), L.setGreenTileVisible(a.showGreenLayer);
1704
- const r = useTrackManager(m), w = useCarTrackManager(m, r), v = useShipManager(m), P = usePositionManager(m), O = useDrawLineManager(m, t), f = useDrawPolygonManager(m, t), y = usePortManager(o);
1705
- useEventManager(o, t, r, v, y, O);
1706
- const F = () => {
1707
- const T = m.getView().calculateExtent(o.getSize()), G = transform([T[0], T[1]], projection.mercator, projection.data), q = transform([T[2], T[3]], projection.mercator, projection.data);
1708
- return [G[0], G[1], q[0], q[1]];
1709
- }, E = {
1710
- id: Symbol("map-instance"),
1711
- innerMap: null,
1712
- map: o.getInstall(),
1713
- destroy: () => {
1714
- e.splice(e.indexOf(E), 1);
1715
- },
1716
- methods: {
1717
- ...o,
1718
- layer: L,
1719
- ship: v,
1720
- track: r,
1721
- carTrack: w,
1722
- port: {
1723
- render: y.render,
1724
- clear: y.clear,
1725
- selected: y.selected
1726
- },
1727
- position: P,
1728
- drawLine: O,
1729
- drawPolygon: f,
1730
- // 子模块
1731
- utils: {
1732
- getCalculateExtent: F,
1733
- convertSixHundredThousandToLatLng,
1734
- calculateCirclePoints
1735
- }
1736
- }
1737
- };
1738
- return e.push(E), E;
1739
- },
1740
- destroyInstance: (n) => {
1741
- const a = e.findIndex((o) => o.id === n);
1742
- a > -1 && (e[a].destroy(), e.splice(a, 1));
1743
- },
1744
- destroyAll: () => {
1745
- e.forEach((n) => n.destroy()), e.splice(0, e.length);
1746
- },
1747
- getAllInstances: () => [...e]
1748
- };
1749
- }, _hoisted_1 = { class: "zh-map-box" }, _sfc_main = /* @__PURE__ */ defineComponent({
1750
- __name: "Map",
1751
- props: {
1752
- zoom: { default: MAP_ZOOM.default },
1753
- center: { default: MAP_DEFAULT_CENTER },
1754
- layerType: { default: "vector" },
1755
- showGreenLayer: { type: Boolean, default: !1 },
1756
- showScale: { type: Boolean, default: !0 },
1757
- scaleLineUnit: { default: "metric" },
1758
- mapMoveEnd: { type: Function, default: () => {
1759
- } },
1760
- lineDrawEnd: {},
1761
- areaDrawEnd: { type: Function, default: () => {
1762
- } },
1763
- selectShip: { type: Function, default: () => {
1764
- } },
1765
- selectPort: { type: Function, default: () => {
1766
- } }
1767
- },
1768
- setup(e, { expose: s }) {
1769
- const l = ref(), n = ref(), a = useMapController(), o = ref(), m = e, L = ref({
1770
- getInstall() {
1771
- }
1772
- });
1773
- return onMounted(() => {
1774
- var t;
1775
- o.value = a.createInstance(l.value, m), console.log(" instance.value?.methods", o.value.map), L.value = o.value.methods, (t = n.value) == null || t.setScaleLine(o.value.map, m.scaleLineUnit);
1776
- }), onUnmounted(() => {
1777
- var t, r;
1778
- a.destroyInstance((t = o == null ? void 0 : o.value) == null ? void 0 : t.id), (r = o.value) == null || r.destroy();
1779
- }), s({
1780
- getZoom: () => {
1781
- var t;
1782
- return (t = o.value) == null ? void 0 : t.methods.getZoom();
1783
- },
1784
- setZoom: (t) => {
1785
- var r;
1786
- return (r = o.value) == null ? void 0 : r.methods.setZoom(t);
1787
- },
1788
- getInstall: () => {
1789
- var t;
1790
- return (t = o.value) == null ? void 0 : t.methods.getInstall();
1791
- },
1792
- getView: () => {
1793
- var t;
1794
- return (t = o.value) == null ? void 0 : t.methods.getView();
1795
- },
1796
- setCenter: (t, r) => {
1797
- var w;
1798
- return (w = o.value) == null ? void 0 : w.methods.setCenter(t, r);
1799
- },
1800
- getSize: () => {
1801
- var t;
1802
- return (t = o.value) == null ? void 0 : t.methods.getSize();
1803
- },
1804
- getCenter: (t, r) => {
1805
- var w;
1806
- return (w = o.value) == null ? void 0 : w.methods.getCenter();
1807
- },
1808
- layer: {
1809
- setGreenTileVisible: (t) => {
1810
- var r;
1811
- return (r = o.value) == null ? void 0 : r.methods.layer.setGreenTileVisible(t);
1812
- },
1813
- getGreenTileVisible: () => {
1814
- var t;
1815
- return (t = o.value) == null ? void 0 : t.methods.layer.getGreenTileVisible();
1816
- },
1817
- getShowLayerType: () => {
1818
- var t;
1819
- return (t = o.value) == null ? void 0 : t.methods.layer.getShowLayerType();
1820
- },
1821
- setShowLayerType: (t) => {
1822
- var r;
1823
- return (r = o.value) == null ? void 0 : r.methods.layer.setShowLayerType(t);
1824
- }
1825
- },
1826
- ship: {
1827
- render: (...t) => {
1828
- var r;
1829
- return (r = o.value) == null ? void 0 : r.methods.ship.render(...t);
1830
- },
1831
- selected: (...t) => {
1832
- var r;
1833
- return (r = o.value) == null ? void 0 : r.methods.ship.selected(...t);
1834
- },
1835
- filter: (...t) => {
1836
- var r;
1837
- return (r = o.value) == null ? void 0 : r.methods.ship.filter(...t);
1838
- },
1839
- blinking: (...t) => {
1840
- var r;
1841
- return (r = o.value) == null ? void 0 : r.methods.ship.blinking(...t);
1842
- },
1843
- clear: () => {
1844
- var t;
1845
- return (t = o.value) == null ? void 0 : t.methods.ship.clear();
1846
- }
1847
- },
1848
- track: {
1849
- render: (...t) => {
1850
- var r;
1851
- return (r = o.value) == null ? void 0 : r.methods.track.render(...t);
1852
- },
1853
- remove: (...t) => {
1854
- var r;
1855
- return (r = o.value) == null ? void 0 : r.methods.track.remove(...t);
1856
- },
1857
- play: (...t) => {
1858
- var r;
1859
- return (r = o.value) == null ? void 0 : r.methods.track.play(...t);
1860
- },
1861
- setCenter: (...t) => {
1862
- var r;
1863
- return (r = o.value) == null ? void 0 : r.methods.track.setCenter(...t);
1864
- },
1865
- close: (...t) => {
1866
- var r;
1867
- return (r = o.value) == null ? void 0 : r.methods.track.close(...t);
1868
- },
1869
- getLength: (...t) => {
1870
- var r;
1871
- return (r = o.value) == null ? void 0 : r.methods.track.getLength(...t);
1872
- }
1873
- },
1874
- carTrack: {
1875
- location: (...t) => {
1876
- var r;
1877
- return (r = o.value) == null ? void 0 : r.methods.carTrack.location(...t);
1878
- },
1879
- remove: (...t) => {
1880
- var r;
1881
- return (r = o.value) == null ? void 0 : r.methods.carTrack.remove(...t);
1882
- },
1883
- renderTrack: (...t) => {
1884
- var r;
1885
- return (r = o.value) == null ? void 0 : r.methods.carTrack.renderTrack(...t);
1886
- },
1887
- setCenter: (...t) => {
1888
- var r;
1889
- return (r = o.value) == null ? void 0 : r.methods.carTrack.setCenter(...t);
1890
- },
1891
- closeTrack: () => {
1892
- var t;
1893
- return (t = o.value) == null ? void 0 : t.methods.carTrack.closeTrack();
1894
- },
1895
- playTrack: (...t) => {
1896
- var r;
1897
- return (r = o.value) == null ? void 0 : r.methods.carTrack.playTrack(...t);
1898
- }
1899
- },
1900
- port: {
1901
- render: (t) => {
1902
- var r;
1903
- return (r = o.value) == null ? void 0 : r.methods.port.render(t);
1904
- },
1905
- clear: () => {
1906
- var t;
1907
- return (t = o.value) == null ? void 0 : t.methods.port.clear();
1908
- },
1909
- selected: (t) => {
1910
- var r;
1911
- return (r = o.value) == null ? void 0 : r.methods.port.selected(t);
1912
- }
1913
- },
1914
- position: {
1915
- render: (...t) => {
1916
- var r;
1917
- return (r = o.value) == null ? void 0 : r.methods.position.render(...t);
1918
- },
1919
- selected: (...t) => {
1920
- var r;
1921
- return (r = o.value) == null ? void 0 : r.methods.position.selected(...t);
1922
- },
1923
- clearSelected: (...t) => {
1924
- var r;
1925
- return (r = o.value) == null ? void 0 : r.methods.position.clearSelected(...t);
1926
- },
1927
- clear: () => {
1928
- var t;
1929
- return (t = o.value) == null ? void 0 : t.methods.position.clear();
1930
- }
1931
- },
1932
- drawLine: {
1933
- open: () => {
1934
- var t;
1935
- return (t = o.value) == null ? void 0 : t.methods.drawLine.open();
1936
- },
1937
- close: () => {
1938
- var t;
1939
- return (t = o.value) == null ? void 0 : t.methods.drawLine.close();
1940
- },
1941
- deleteLine: (t) => {
1942
- var r;
1943
- return (r = o.value) == null ? void 0 : r.methods.drawLine.deleteLine(t);
1944
- },
1945
- setUnit: (t) => {
1946
- var r;
1947
- return (r = o.value) == null ? void 0 : r.methods.drawLine.setUnit(t);
1948
- },
1949
- getState: () => {
1950
- var t;
1951
- return (t = o.value) == null ? void 0 : t.methods.drawLine.getState();
1952
- }
1953
- },
1954
- drawPolygon: {
1955
- open: () => {
1956
- var t;
1957
- return (t = o.value) == null ? void 0 : t.methods.drawPolygon.open();
1958
- },
1959
- close: () => {
1960
- var t;
1961
- return (t = o.value) == null ? void 0 : t.methods.drawPolygon.close();
1962
- },
1963
- reset: () => {
1964
- var t;
1965
- return (t = o.value) == null ? void 0 : t.methods.drawPolygon.reset();
1966
- }
1967
- },
1968
- // 子模块
1969
- utils: {
1970
- getCalculateExtent: (...t) => {
1971
- var r;
1972
- return (r = o.value) == null ? void 0 : r.methods.utils.getCalculateExtent(...t);
1973
- },
1974
- convertSixHundredThousandToLatLng: (...t) => {
1975
- var r;
1976
- return (r = o.value) == null ? void 0 : r.methods.utils.convertSixHundredThousandToLatLng(...t);
1977
- },
1978
- calculateCirclePoints: (t, r) => {
1979
- var w;
1980
- return (w = o.value) == null ? void 0 : w.methods.utils.calculateCirclePoints(t, r);
1981
- }
1982
- }
1983
- }), (t, r) => (openBlock(), createElementBlock("div", _hoisted_1, [
1984
- createElementVNode("div", {
1985
- id: "map",
1986
- ref_key: "zhMapRef",
1987
- ref: l,
1988
- class: "zh-map"
1989
- }, null, 512),
1990
- createVNode(ScaleLine, {
1991
- ref_key: "scaleLineRef",
1992
- ref: n
1993
- }, null, 512),
1994
- createVNode(ZoomControl, {
1995
- ref: "zoomControlRef",
1996
- "map-instance": o.value
1997
- }, null, 8, ["map-instance"])
1998
- ]));
1999
- }
2000
- }), Map$1 = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-117d7b5a"]]), ZhMap = withInstall(Map$1);
2001
- export {
2002
- ZhMap as Z
2003
- };