gis-common 4.1.7 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constant/ErrorTypeConstant.d.ts +23 -23
- package/dist/constant/EventTypeConstant.d.ts +24 -24
- package/dist/constant/GraphicConstant.d.ts +21 -21
- package/dist/constant/LayerType.d.ts +10 -10
- package/dist/core/CanvasDrawer.d.ts +0 -1
- package/dist/core/EventDispatcher.d.ts +1 -1
- package/dist/core/MqttClient.d.ts +33 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/gis-common.es.js +809 -555
- package/dist/gis-common.umd.js +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/utils/AjaxUtil.d.ts +102 -0
- package/dist/utils/ArrayUtil.d.ts +0 -1
- package/dist/utils/CommUtil.d.ts +15 -0
- package/dist/utils/FileUtil.d.ts +0 -5
- package/dist/utils/GeoUtil.d.ts +9 -0
- package/dist/utils/ImageUtil.d.ts +42 -0
- package/dist/utils/index.d.ts +3 -1
- package/package.json +4 -1
package/dist/gis-common.es.js
CHANGED
|
@@ -1,89 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
MOUSE_CLICK: "click",
|
|
8
|
-
MOUSE_DOUBLE_CLICK: "dblclick",
|
|
9
|
-
MOUSE_MOVE: "mousemove",
|
|
10
|
-
MOUSE_IN: "mousein",
|
|
11
|
-
MOUSE_OUT: "mouseout",
|
|
12
|
-
MOUSE_RIGHT_CLICK: "mouseRightClick",
|
|
13
|
-
KEY_DOWN: "keyDown",
|
|
14
|
-
KEY_UP: "keyUp",
|
|
15
|
-
DRAW_ACTIVE: "drawActive",
|
|
16
|
-
DRAW_MOVE: "drawMove",
|
|
17
|
-
DRAW_COMPLETE: "drawComplete",
|
|
18
|
-
MQTT_CONNECT: "mqttConnect",
|
|
19
|
-
MQTT_ERROR: "mqttError",
|
|
20
|
-
MQTT_MESSAGE: "mqttMessage",
|
|
21
|
-
MQTT_CLOSE: "mqttClose",
|
|
22
|
-
WEB_SOCKET_CONNECT: "webSocketConnect",
|
|
23
|
-
WEB_SOCKET_ERROR: "webSocketError",
|
|
24
|
-
WEB_SOCKET_MESSAGE: "webSocketMessage",
|
|
25
|
-
WEB_SOCKET_CLOSE: "webSocketClose"
|
|
26
|
-
}, O = {
|
|
27
|
-
LOGIN_EXPIRED: "登录信息过期,请重新登录",
|
|
28
|
-
CROSS_ERROR: "跨域访问",
|
|
29
|
-
UNEXIST_RESOURCE: "资源不存在",
|
|
30
|
-
TIMEOUT: "请求超时",
|
|
31
|
-
INTERNAL_ERROR: "内部错误",
|
|
32
|
-
NETWORK_ERROR: "请求失败,请检查网络是否已连接",
|
|
33
|
-
PROCESS_FAIL: "处理失败",
|
|
34
|
-
AUTH_VERIFY_ERROR: "权限验证失败",
|
|
35
|
-
NO_DATA_FOUND: "未找到数据",
|
|
36
|
-
DUPLICATE_INSTANCE: "实例为单例模式,不允许重复构建",
|
|
37
|
-
COORDINATE_ERROR: "坐标验证失败",
|
|
38
|
-
JSON_PARSE_ERROR: "JSON解析失败,格式有误",
|
|
39
|
-
JSON_VALUE_ERROR: "JSON无此键",
|
|
40
|
-
PARAMETER_ERROR: "验证数据类型失败",
|
|
41
|
-
PARAMETER_ERROR_ARRAY: "格式类型验证失败:必须是数组",
|
|
42
|
-
PARAMETER_ERROR_STRING: "格式类型验证失败:必须是字符",
|
|
43
|
-
PARAMETER_ERROR_FUNCTION: "格式类型验证失败:必须是函数",
|
|
44
|
-
PARAMETER_ERROR_OBJECT: "格式类型验证失败:必须是对象",
|
|
45
|
-
PARAMETER_ERROR_LACK: "参数缺失",
|
|
46
|
-
STRING_CHECK_LOSS: "字符缺少关键字"
|
|
47
|
-
}, P = {
|
|
48
|
-
SUPER_MAP_IMAGES: "SuperMapImages",
|
|
49
|
-
// 超图影像服务 栅格数据
|
|
50
|
-
SUPER_MAP_DATA: "SuperMapData",
|
|
51
|
-
// 超图服务 矢量数据
|
|
52
|
-
ARC_GIS_MAP_IMAGES: "ArcGisMapImages",
|
|
53
|
-
// arcGis影像图层 栅格数据
|
|
54
|
-
ARC_GIS_MAP_DATA: "ArcGisMapData",
|
|
55
|
-
// arcGis图层 矢量数据
|
|
56
|
-
OSGB_LAYER: "OSGBLayer",
|
|
57
|
-
S3M_GROUP: "S3MGroup",
|
|
58
|
-
// addS3MGroupLayer(url, options, index) 添加S3M分组图层。
|
|
59
|
-
TERRAIN_LAYER: "TerrainFileLayer"
|
|
60
|
-
// 地形图层, 需要单独处理
|
|
61
|
-
}, _ = {
|
|
62
|
-
POINT: "point",
|
|
63
|
-
POLYLINE: "polyline",
|
|
64
|
-
POLYGON: "polygon",
|
|
65
|
-
BILLBOARD: "billboard",
|
|
66
|
-
CYLINDER: "cylinder",
|
|
67
|
-
ELLIPSOID: "ellipsoid",
|
|
68
|
-
LABEL: "label",
|
|
69
|
-
MODEL: "model",
|
|
70
|
-
WALL: "wall"
|
|
71
|
-
}, L = {
|
|
72
|
-
DISTANCE: "distance",
|
|
73
|
-
AREA: "area",
|
|
74
|
-
HEIGHT: "height"
|
|
75
|
-
}, k = {
|
|
76
|
-
ADD: "add",
|
|
77
|
-
REMOVE: "remove",
|
|
78
|
-
INIT: "init"
|
|
79
|
-
};
|
|
80
|
-
class N {
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var v = (t, e, n) => e in t ? L(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var g = (t, e, n) => v(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { connect as U } from "mqtt-browser";
|
|
5
|
+
var y = /* @__PURE__ */ ((t) => (t.MAP_RENDER = "mapRender", t.MAP_READY = "mapReady", t.MOUSE_CLICK = "click", t.MOUSE_DOUBLE_CLICK = "dblclick", t.MOUSE_MOVE = "mousemove", t.MOUSE_IN = "mousein", t.MOUSE_OUT = "mouseout", t.MOUSE_RIGHT_CLICK = "mouseRightClick", t.KEY_DOWN = "keyDown", t.KEY_UP = "keyUp", t.DRAW_ACTIVE = "drawActive", t.DRAW_MOVE = "drawMove", t.DRAW_COMPLETE = "drawComplete", t.MQTT_CONNECT = "mqttConnect", t.MQTT_ERROR = "mqttError", t.MQTT_MESSAGE = "mqttMessage", t.MQTT_CLOSE = "mqttClose", t.WEB_SOCKET_CONNECT = "webSocketConnect", t.WEB_SOCKET_ERROR = "webSocketError", t.WEB_SOCKET_MESSAGE = "webSocketMessage", t.WEB_SOCKET_CLOSE = "webSocketClose", t))(y || {}), b = /* @__PURE__ */ ((t) => (t.LOGIN_EXPIRED = "登录信息过期,请重新登录", t.CROSS_ERROR = "跨域访问", t.UNEXIST_RESOURCE = "资源不存在", t.TIMEOUT = "请求超时", t.INTERNAL_ERROR = "内部错误", t.NETWORK_ERROR = "请求失败,请检查网络是否已连接", t.PROCESS_FAIL = "处理失败", t.AUTH_VERIFY_ERROR = "权限验证失败", t.NO_DATA_FOUND = "未找到数据", t.DUPLICATE_INSTANCE = "实例为单例模式,不允许重复构建", t.COORDINATE_ERROR = "坐标验证失败", t.JSON_PARSE_ERROR = "JSON解析失败,格式有误", t.JSON_VALUE_ERROR = "JSON无此键", t.PARAMETER_ERROR = "验证数据类型失败", t.PARAMETER_ERROR_ARRAY = "格式类型验证失败:必须是数组", t.PARAMETER_ERROR_STRING = "格式类型验证失败:必须是字符", t.PARAMETER_ERROR_FUNCTION = "格式类型验证失败:必须是函数", t.PARAMETER_ERROR_OBJECT = "格式类型验证失败:必须是对象", t.PARAMETER_ERROR_LACK = "参数缺失", t.STRING_CHECK_LOSS = "字符缺少关键字", t))(b || {}), N = /* @__PURE__ */ ((t) => (t.SUPER_MAP_IMAGES = "SuperMapImages", t.SUPER_MAP_DATA = "SuperMapData", t.ARC_GIS_MAP_IMAGES = "ArcGisMapImages", t.ARC_GIS_MAP_DATA = "ArcGisMapData", t.OSGB_LAYER = "OSGBLayer", t.S3M_GROUP = "S3MGroup", t.TERRAIN_LAYER = "TerrainFileLayer", t))(N || {}), k = /* @__PURE__ */ ((t) => (t.POINT = "point", t.POLYLINE = "polyline", t.POLYGON = "polygon", t.BILLBOARD = "billboard", t.CYLINDER = "cylinder", t.ELLIPSOID = "ellipsoid", t.LABEL = "label", t.MODEL = "model", t.WALL = "wall", t))(k || {}), F = /* @__PURE__ */ ((t) => (t.DISTANCE = "distance", t.AREA = "area", t.HEIGHT = "height", t))(F || {}), B = /* @__PURE__ */ ((t) => (t.ADD = "add", t.REMOVE = "remove", t.INIT = "init", t))(B || {});
|
|
6
|
+
class H {
|
|
81
7
|
constructor(e) {
|
|
82
8
|
/**
|
|
83
9
|
* Creates an instance of AudioPlayer.
|
|
84
10
|
* @param {*} url
|
|
85
11
|
*/
|
|
86
|
-
|
|
12
|
+
g(this, "audio");
|
|
87
13
|
this.audio = new Audio(), this.audio.src = e;
|
|
88
14
|
}
|
|
89
15
|
play() {
|
|
@@ -102,7 +28,7 @@ class N {
|
|
|
102
28
|
this.audio.muted = e;
|
|
103
29
|
}
|
|
104
30
|
}
|
|
105
|
-
const
|
|
31
|
+
const R = {
|
|
106
32
|
DEG2RAD: Math.PI / 180,
|
|
107
33
|
RAD2DEG: 180 / Math.PI,
|
|
108
34
|
randInt(t, e) {
|
|
@@ -173,9 +99,9 @@ const m = {
|
|
|
173
99
|
return Math.max(Math.min(t, n), e);
|
|
174
100
|
}
|
|
175
101
|
};
|
|
176
|
-
class
|
|
102
|
+
class j {
|
|
177
103
|
constructor(e) {
|
|
178
|
-
|
|
104
|
+
g(this, "context", null);
|
|
179
105
|
if (typeof e == "string" && (e = document.querySelector("#" + e), !e))
|
|
180
106
|
throw new Error("Element not found");
|
|
181
107
|
if (e instanceof HTMLElement) {
|
|
@@ -195,12 +121,12 @@ class C {
|
|
|
195
121
|
* @param options 绘制选项,包括线条宽度和颜色
|
|
196
122
|
* @throws 当画布上下文不存在时抛出错误
|
|
197
123
|
*/
|
|
198
|
-
drawLine({ x: e, y: n }, { x: r, y:
|
|
124
|
+
drawLine({ x: e, y: n }, { x: r, y: i }, o = {}) {
|
|
199
125
|
if (!this.context)
|
|
200
126
|
throw new Error("Canvas context is null or undefined");
|
|
201
127
|
this.context.beginPath();
|
|
202
|
-
const
|
|
203
|
-
this.context.lineWidth =
|
|
128
|
+
const a = o.width || 1, c = o.color || "#000";
|
|
129
|
+
this.context.lineWidth = a, this.context.strokeStyle = c, this.context.moveTo(e, n), this.context.lineTo(r, i), this.context.stroke();
|
|
204
130
|
}
|
|
205
131
|
/**
|
|
206
132
|
* 绘制圆弧
|
|
@@ -215,10 +141,10 @@ class C {
|
|
|
215
141
|
* @param bgColor 背景颜色
|
|
216
142
|
* @throws 当Canvas context为null或undefined时抛出错误
|
|
217
143
|
*/
|
|
218
|
-
drawArc({ x: e, y: n }, r,
|
|
144
|
+
drawArc({ x: e, y: n }, r, i, o, a, c, l) {
|
|
219
145
|
if (!this.context)
|
|
220
146
|
throw new Error("Canvas context is null or undefined");
|
|
221
|
-
|
|
147
|
+
c ? (this.context.fillStyle = l, this.context.beginPath(), this.context.arc(e, n, r, R.degreesToRadians(i), R.degreesToRadians(o), a), this.context.fill()) : (this.context.strokeStyle = l, this.context.beginPath(), this.context.arc(e, n, r, R.degreesToRadians(i), R.degreesToRadians(o), a), this.context.stroke());
|
|
222
148
|
}
|
|
223
149
|
static createCanvas(e = 1, n = 1) {
|
|
224
150
|
let r;
|
|
@@ -226,17 +152,16 @@ class C {
|
|
|
226
152
|
return r = document.createElement("canvas"), e && (r.width = e), n && (r.height = n), r;
|
|
227
153
|
}
|
|
228
154
|
}
|
|
229
|
-
|
|
230
|
-
class T {
|
|
155
|
+
class _ {
|
|
231
156
|
constructor() {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
157
|
+
g(this, "_listeners");
|
|
158
|
+
g(this, "_mutex", {});
|
|
159
|
+
g(this, "_context");
|
|
235
160
|
}
|
|
236
|
-
addEventListener(e, n, r,
|
|
161
|
+
addEventListener(e, n, r, i) {
|
|
237
162
|
this._listeners === void 0 && (this._listeners = {}), this._context = r;
|
|
238
|
-
const
|
|
239
|
-
return
|
|
163
|
+
const o = this._mutex, a = this._listeners;
|
|
164
|
+
return a[e] === void 0 && (a[e] = []), a[e].indexOf(n) === -1 && (i && (o[e] = n), a[e].push(n)), this;
|
|
240
165
|
}
|
|
241
166
|
hasEventListener(e, n) {
|
|
242
167
|
if (this._listeners === null || this._listeners === void 0) return !1;
|
|
@@ -245,10 +170,10 @@ class T {
|
|
|
245
170
|
}
|
|
246
171
|
removeEventListener(e, n) {
|
|
247
172
|
if (this._listeners === void 0) return;
|
|
248
|
-
const
|
|
249
|
-
if (this._mutex[e] === n && (this._mutex[e] = null),
|
|
250
|
-
const
|
|
251
|
-
|
|
173
|
+
const i = this._listeners[e];
|
|
174
|
+
if (this._mutex[e] === n && (this._mutex[e] = null), i !== void 0) {
|
|
175
|
+
const o = i.map((a) => a.toString()).indexOf(n.toString());
|
|
176
|
+
o !== -1 && i.splice(o, 1);
|
|
252
177
|
}
|
|
253
178
|
}
|
|
254
179
|
dispatchEvent(e) {
|
|
@@ -256,17 +181,17 @@ class T {
|
|
|
256
181
|
const r = this._listeners[e.type];
|
|
257
182
|
if (r !== void 0) {
|
|
258
183
|
e.target = this;
|
|
259
|
-
const
|
|
184
|
+
const i = r.slice(0);
|
|
260
185
|
if (this._mutex[e.type] !== void 0) {
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
|
|
186
|
+
const o = i.find((a) => a === this._mutex[e.type]);
|
|
187
|
+
if (o) {
|
|
188
|
+
o.call(this._context || this, e);
|
|
264
189
|
return;
|
|
265
190
|
}
|
|
266
191
|
}
|
|
267
|
-
for (let
|
|
268
|
-
const
|
|
269
|
-
typeof
|
|
192
|
+
for (let o = 0, a = i.length; o < a; o++) {
|
|
193
|
+
const c = i[o];
|
|
194
|
+
typeof c == "function" && c.call(this._context || this, e);
|
|
270
195
|
}
|
|
271
196
|
}
|
|
272
197
|
}
|
|
@@ -276,7 +201,7 @@ class T {
|
|
|
276
201
|
this._listeners[e] = [];
|
|
277
202
|
}
|
|
278
203
|
}
|
|
279
|
-
class
|
|
204
|
+
class C extends Map {
|
|
280
205
|
isEmpty() {
|
|
281
206
|
return this.size === 0;
|
|
282
207
|
}
|
|
@@ -292,20 +217,20 @@ class A extends Map {
|
|
|
292
217
|
fromEntries() {
|
|
293
218
|
}
|
|
294
219
|
}
|
|
295
|
-
|
|
296
|
-
const e = new
|
|
220
|
+
C.prototype.fromEntries = function(t = []) {
|
|
221
|
+
const e = new C();
|
|
297
222
|
return t.forEach((n) => {
|
|
298
223
|
Array.isArray(n) && n.length === 2 && e.set(n[0], n[1]);
|
|
299
224
|
}), e;
|
|
300
225
|
};
|
|
301
|
-
class
|
|
226
|
+
class W extends _ {
|
|
302
227
|
constructor(n = "ws://127.0.0.1:10088") {
|
|
303
228
|
super();
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
229
|
+
g(this, "maxCheckTimes", 10);
|
|
230
|
+
g(this, "url");
|
|
231
|
+
g(this, "checkTimes", 0);
|
|
232
|
+
g(this, "connectStatus", !1);
|
|
233
|
+
g(this, "client", null);
|
|
309
234
|
this.maxCheckTimes = 10, this.url = n, this.checkTimes = 0, this.connect(), this.connCheckStatus(this.maxCheckTimes);
|
|
310
235
|
}
|
|
311
236
|
connect() {
|
|
@@ -315,22 +240,22 @@ class U extends T {
|
|
|
315
240
|
const n = this;
|
|
316
241
|
this.client.onopen = function(r) {
|
|
317
242
|
n.dispatchEvent({
|
|
318
|
-
type:
|
|
243
|
+
type: y.WEB_SOCKET_CONNECT,
|
|
319
244
|
message: r
|
|
320
245
|
});
|
|
321
246
|
}, this.client.onmessage = function(r) {
|
|
322
247
|
n.connectStatus = !0, n.dispatchEvent({
|
|
323
|
-
type:
|
|
248
|
+
type: y.WEB_SOCKET_MESSAGE,
|
|
324
249
|
message: r
|
|
325
250
|
});
|
|
326
251
|
}, this.client.onclose = function(r) {
|
|
327
252
|
n.dispatchEvent({
|
|
328
|
-
type:
|
|
253
|
+
type: y.WEB_SOCKET_CLOSE,
|
|
329
254
|
message: r
|
|
330
255
|
});
|
|
331
256
|
}, this.checkTimes === this.maxCheckTimes && (this.client.onerror = function(r) {
|
|
332
257
|
n.dispatchEvent({
|
|
333
|
-
type:
|
|
258
|
+
type: y.WEB_SOCKET_ERROR,
|
|
334
259
|
message: r
|
|
335
260
|
});
|
|
336
261
|
});
|
|
@@ -371,6 +296,18 @@ const M = {
|
|
|
371
296
|
getDataType(t) {
|
|
372
297
|
return Object.prototype.toString.call(t).slice(8, -1);
|
|
373
298
|
},
|
|
299
|
+
asArray(t) {
|
|
300
|
+
return this.isEmpty(t) ? [] : Array.isArray(t) ? t : [t];
|
|
301
|
+
},
|
|
302
|
+
asNumber(t) {
|
|
303
|
+
return Number.isNaN(Number(t)) ? 0 : Number(t);
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* 判断传入的值是否为空
|
|
307
|
+
*
|
|
308
|
+
* @param value 待判断的值
|
|
309
|
+
* @returns 返回布尔值,表示是否为空
|
|
310
|
+
*/
|
|
374
311
|
isEmpty(t) {
|
|
375
312
|
if (t == null)
|
|
376
313
|
return !0;
|
|
@@ -390,6 +327,12 @@ const M = {
|
|
|
390
327
|
isNotEmpty(t) {
|
|
391
328
|
return !this.isEmpty(t);
|
|
392
329
|
},
|
|
330
|
+
/**
|
|
331
|
+
* 将JSON对象转换为FormData对象
|
|
332
|
+
*
|
|
333
|
+
* @param json 待转换的JSON对象,其属性值为字符串或Blob类型
|
|
334
|
+
* @returns 转换后的FormData对象
|
|
335
|
+
*/
|
|
393
336
|
json2form(t) {
|
|
394
337
|
const e = new FormData();
|
|
395
338
|
return Object.keys(t).forEach((n) => {
|
|
@@ -418,8 +361,8 @@ const M = {
|
|
|
418
361
|
if (t.length > 1) {
|
|
419
362
|
const n = t.slice(1, t.length % 2 === 0 ? t.length - 1 : t.length);
|
|
420
363
|
for (let r = 0; r < n.length; r = r + 2) {
|
|
421
|
-
const
|
|
422
|
-
t[0] ===
|
|
364
|
+
const i = n[r];
|
|
365
|
+
t[0] === i && (e = n[r + 1]);
|
|
423
366
|
}
|
|
424
367
|
!e && t.length % 2 === 0 && (e = t[t.length - 1]);
|
|
425
368
|
} else
|
|
@@ -434,11 +377,11 @@ const M = {
|
|
|
434
377
|
* @returns 返回目标对象,包含所有复制的属性。
|
|
435
378
|
*/
|
|
436
379
|
extend(t, ...e) {
|
|
437
|
-
let n, r,
|
|
438
|
-
for (r = 0,
|
|
439
|
-
|
|
440
|
-
for (n in
|
|
441
|
-
t[n] =
|
|
380
|
+
let n, r, i, o;
|
|
381
|
+
for (r = 0, i = e.length; r < i; r++) {
|
|
382
|
+
o = e[r];
|
|
383
|
+
for (n in o)
|
|
384
|
+
t[n] = o[n];
|
|
442
385
|
}
|
|
443
386
|
return t;
|
|
444
387
|
},
|
|
@@ -452,14 +395,14 @@ const M = {
|
|
|
452
395
|
* @returns 转换后的树形结构数组
|
|
453
396
|
*/
|
|
454
397
|
convertToTree2(t, e = "id", n = "parentId", r = "children") {
|
|
455
|
-
const
|
|
456
|
-
function
|
|
457
|
-
const
|
|
458
|
-
|
|
398
|
+
const i = [];
|
|
399
|
+
function o(a) {
|
|
400
|
+
const c = t.filter((l) => l[n] === a[e]).map((l) => (i.some((u) => u[e] === l[e]) || o(l), l));
|
|
401
|
+
c.length > 0 && (a[r] = c);
|
|
459
402
|
}
|
|
460
|
-
return t.forEach((
|
|
461
|
-
t.some((
|
|
462
|
-
}),
|
|
403
|
+
return t.forEach((a) => {
|
|
404
|
+
t.some((c) => c[n] === a[e]) || (o(a), i.push(a));
|
|
405
|
+
}), i;
|
|
463
406
|
},
|
|
464
407
|
/**
|
|
465
408
|
* 异步加载script
|
|
@@ -506,11 +449,11 @@ const M = {
|
|
|
506
449
|
*/
|
|
507
450
|
template(t, e) {
|
|
508
451
|
const n = /\{ *([\w_-]+) *\}/g;
|
|
509
|
-
return t.replace(n, (r,
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
512
|
-
throw new Error(`${
|
|
513
|
-
return typeof
|
|
452
|
+
return t.replace(n, (r, i) => {
|
|
453
|
+
const o = e[i];
|
|
454
|
+
if (o === void 0)
|
|
455
|
+
throw new Error(`${b.JSON_VALUE_ERROR}: ${r}`);
|
|
456
|
+
return typeof o == "function" ? o(e) : o;
|
|
514
457
|
});
|
|
515
458
|
},
|
|
516
459
|
/**
|
|
@@ -565,6 +508,19 @@ const M = {
|
|
|
565
508
|
},
|
|
566
509
|
isNumber(t) {
|
|
567
510
|
return typeof t == "number" && !isNaN(t) || typeof t == "string" && Number.isFinite(+t);
|
|
511
|
+
},
|
|
512
|
+
isFunction(t) {
|
|
513
|
+
return this.isNil(t) ? !1 : typeof t == "function" || t.constructor !== null && t.constructor === Function;
|
|
514
|
+
}
|
|
515
|
+
}, T = {
|
|
516
|
+
deepClone(t) {
|
|
517
|
+
return structuredClone(t);
|
|
518
|
+
},
|
|
519
|
+
isEqual(t, e) {
|
|
520
|
+
return JSON.stringify(t) === JSON.stringify(e);
|
|
521
|
+
},
|
|
522
|
+
parse(t) {
|
|
523
|
+
return !t || typeof t != "string" ? t : JSON.parse(t);
|
|
568
524
|
}
|
|
569
525
|
};
|
|
570
526
|
Array.prototype.groupBy = function(t) {
|
|
@@ -577,8 +533,8 @@ Array.prototype.groupBy = function(t) {
|
|
|
577
533
|
Array.prototype.distinct = function(t = (e) => e) {
|
|
578
534
|
const e = [], n = {};
|
|
579
535
|
return this.forEach((r) => {
|
|
580
|
-
const
|
|
581
|
-
n[
|
|
536
|
+
const i = t(r), o = String(i);
|
|
537
|
+
n[o] || (n[o] = !0, e.push(r));
|
|
582
538
|
}), e;
|
|
583
539
|
};
|
|
584
540
|
Array.prototype.max = function() {
|
|
@@ -606,10 +562,7 @@ Array.prototype.remove = function(t) {
|
|
|
606
562
|
Array.prototype.clear = function() {
|
|
607
563
|
return this.length = 0, this;
|
|
608
564
|
};
|
|
609
|
-
const
|
|
610
|
-
asArray(t) {
|
|
611
|
-
return M.isEmpty(t) ? [] : Array.isArray(t) ? t : [t];
|
|
612
|
-
},
|
|
565
|
+
const S = {
|
|
613
566
|
/**
|
|
614
567
|
* 创建指定长度的数组,并返回其索引数组
|
|
615
568
|
*
|
|
@@ -661,7 +614,324 @@ const F = {
|
|
|
661
614
|
difference(...t) {
|
|
662
615
|
return this.union(...t).filter((e) => !this.intersection(...t).includes(e));
|
|
663
616
|
}
|
|
664
|
-
},
|
|
617
|
+
}, x = class x extends _ {
|
|
618
|
+
constructor(n = {}) {
|
|
619
|
+
super();
|
|
620
|
+
g(this, "state");
|
|
621
|
+
g(this, "context");
|
|
622
|
+
g(this, "options");
|
|
623
|
+
g(this, "client");
|
|
624
|
+
g(this, "topics");
|
|
625
|
+
this.context = M.extend(x.defaultContext, n), this.options = {
|
|
626
|
+
connectTimeout: this.context.MQTT_TIMEOUTM,
|
|
627
|
+
clientId: M.guid(),
|
|
628
|
+
username: this.context.MQTT_USERNAME,
|
|
629
|
+
password: this.context.MQTT_PASSWORD,
|
|
630
|
+
clean: !0
|
|
631
|
+
}, this.client = U(this.context.MQTT_SERVICE, this.options), this._onConnect(), this._onMessage(), this.state = 0, this.topics = [];
|
|
632
|
+
}
|
|
633
|
+
_onConnect() {
|
|
634
|
+
this.client.on("connect", () => {
|
|
635
|
+
this.state = 1, console.log("链接mqtt成功==>" + this.context.MQTT_SERVICE), this.dispatchEvent({ type: y.MQTT_CONNECT, message: this });
|
|
636
|
+
}), this.client.on("error", (n) => {
|
|
637
|
+
console.log("链接mqtt报错", n), this.state = -1, this.dispatchEvent({ type: y.MQTT_ERROR, message: this }), this.client.end(), this.client.reconnect();
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
_onMessage() {
|
|
641
|
+
this.client.on("message", (n, r) => {
|
|
642
|
+
let i = r, o = "";
|
|
643
|
+
r instanceof Uint8Array && (i = r.toString());
|
|
644
|
+
try {
|
|
645
|
+
o = T.parse(i);
|
|
646
|
+
} catch {
|
|
647
|
+
throw new Error(b.JSON_PARSE_ERROR);
|
|
648
|
+
}
|
|
649
|
+
this.dispatchEvent({
|
|
650
|
+
type: y.MQTT_MESSAGE,
|
|
651
|
+
message: { topic: n, data: o }
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
sendMsg(n, r) {
|
|
656
|
+
if (!this.client.connected) {
|
|
657
|
+
console.error("客户端未连接");
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
this.client.publish(n, r, { qos: 1, retain: !0 });
|
|
661
|
+
}
|
|
662
|
+
subscribe(n) {
|
|
663
|
+
return this.state === 1 ? this.client.subscribe(n, { qos: 1 }, (r, i) => {
|
|
664
|
+
r instanceof Error ? console.error("订阅失败==>" + n, r) : (this.topics = S.union(this.topics, n), console.log("订阅成功==>" + n));
|
|
665
|
+
}) : this.addEventListener(y.MQTT_CONNECT, (r) => {
|
|
666
|
+
this.client.subscribe(n, { qos: 1 }, (i, o) => {
|
|
667
|
+
i instanceof Error ? console.error("订阅失败==>" + n, i) : (this.topics = S.union(this.topics, n), console.log("订阅成功==>" + n));
|
|
668
|
+
});
|
|
669
|
+
}), this;
|
|
670
|
+
}
|
|
671
|
+
unsubscribe(n) {
|
|
672
|
+
return this.client.unsubscribe(n, { qos: 1 }, (r, i) => {
|
|
673
|
+
r instanceof Error ? console.error(`取消订阅失败==>${n}`, r) : (this.topics = S.difference(this.topics, s), console.log(`取消订阅成功==>${n}`));
|
|
674
|
+
}), this;
|
|
675
|
+
}
|
|
676
|
+
unsubscribeAll() {
|
|
677
|
+
this.unsubscribe(this.topics);
|
|
678
|
+
}
|
|
679
|
+
unconnect() {
|
|
680
|
+
this.client.end(), this.client = null, this.dispatchEvent({ type: y.MQTT_CLOSE, message: null }), console.log("断开mqtt成功==>" + this.context.MQTT_SERVICE);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
/**
|
|
684
|
+
* Creates an instance of MqttClient.
|
|
685
|
+
* @param {*} config mqtt实例参数
|
|
686
|
+
*/
|
|
687
|
+
g(x, "defaultContext", {
|
|
688
|
+
MQTT_USERNAME: "iRVMS-WEB",
|
|
689
|
+
MQTT_PASSWORD: "novasky888",
|
|
690
|
+
MQTT_SERVICE: `ws://${window.document.domain}:20007/mqtt`,
|
|
691
|
+
MQTT_TIMEOUTM: 2e4
|
|
692
|
+
});
|
|
693
|
+
let O = x;
|
|
694
|
+
const $ = {
|
|
695
|
+
emptyImageUrl: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
|
|
696
|
+
/**
|
|
697
|
+
*
|
|
698
|
+
* @param image image,类型可以是HTMLCanvasElement、ImageData
|
|
699
|
+
* @returns
|
|
700
|
+
*/
|
|
701
|
+
getURL(t) {
|
|
702
|
+
let e;
|
|
703
|
+
if (/^data:/i.test(t.src) || typeof HTMLCanvasElement > "u")
|
|
704
|
+
return t.src;
|
|
705
|
+
let n;
|
|
706
|
+
if (t instanceof HTMLCanvasElement)
|
|
707
|
+
n = t;
|
|
708
|
+
else {
|
|
709
|
+
e === void 0 && (e = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas")), e.width = t.width, e.height = t.height;
|
|
710
|
+
const r = e.getContext("2d");
|
|
711
|
+
r && (t instanceof ImageData ? r.putImageData(t, 0, 0) : r.drawImage(t, 0, 0, t.width, t.height)), n = e;
|
|
712
|
+
}
|
|
713
|
+
return n.width > 2048 || n.height > 2048 ? (console.warn("ImageUtil.getDataURL: Image converted to jpg for performance reasons", t), n.toDataURL("image/jpeg", 0.6)) : n.toDataURL("image/png");
|
|
714
|
+
},
|
|
715
|
+
/**
|
|
716
|
+
* 将图片的URL转换为Base64编码
|
|
717
|
+
*
|
|
718
|
+
* @param url 图片的URL地址
|
|
719
|
+
* @param width 图片的宽度,默认为图片原始宽度
|
|
720
|
+
* @param height 图片的高度,默认为图片原始高度
|
|
721
|
+
* @returns 返回Promise对象,解析后得到包含Base64编码数据的对象
|
|
722
|
+
*/
|
|
723
|
+
getBase64(t) {
|
|
724
|
+
return new Promise((e, n) => {
|
|
725
|
+
let r = new Image();
|
|
726
|
+
r.setAttribute("crossOrigin", "Anonymous"), r.src = t, r.onload = () => {
|
|
727
|
+
let i = this.getURL(r);
|
|
728
|
+
e(i);
|
|
729
|
+
}, r.onerror = n;
|
|
730
|
+
});
|
|
731
|
+
},
|
|
732
|
+
/**
|
|
733
|
+
* 解析base64编码
|
|
734
|
+
*
|
|
735
|
+
* @param base64 base64编码字符串
|
|
736
|
+
* @returns 返回一个对象,包含type(类型)、ext(扩展名)和data(数据)字段,如果解析失败则返回null
|
|
737
|
+
*/
|
|
738
|
+
parseBase64(t) {
|
|
739
|
+
let n = new RegExp("data:(?<type>.*?);base64,(?<data>.*)").exec(t);
|
|
740
|
+
return n && n.groups ? {
|
|
741
|
+
type: n.groups.type,
|
|
742
|
+
ext: n.groups.type.split("/").slice(-1)[0],
|
|
743
|
+
data: n.groups.data
|
|
744
|
+
} : null;
|
|
745
|
+
},
|
|
746
|
+
/**
|
|
747
|
+
* 复制图片到剪贴板
|
|
748
|
+
*
|
|
749
|
+
* @param url 图片的URL地址
|
|
750
|
+
* @returns 无返回值
|
|
751
|
+
* @throws 如果解析base64数据失败,则抛出异常
|
|
752
|
+
*/
|
|
753
|
+
async copyImage(t) {
|
|
754
|
+
try {
|
|
755
|
+
const e = await this.getBase64(t), n = this.parseBase64(e.dataURL);
|
|
756
|
+
if (!n)
|
|
757
|
+
throw new Error("Failed to parse base64 data.");
|
|
758
|
+
let r = n.type, i = atob(n.data), o = new ArrayBuffer(i.length), a = new Uint8Array(o);
|
|
759
|
+
for (let l = 0; l < i.length; l++)
|
|
760
|
+
a[l] = i.charCodeAt(l);
|
|
761
|
+
let c = new Blob([o], { type: r });
|
|
762
|
+
await navigator.clipboard.write([new ClipboardItem({ [r]: c })]);
|
|
763
|
+
} catch (e) {
|
|
764
|
+
console.error("Failed to copy image to clipboard:", e);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}, E = {
|
|
768
|
+
/**
|
|
769
|
+
* Get JSON data by jsonp
|
|
770
|
+
* @param url - resource url
|
|
771
|
+
* @param callback - callback function when completed
|
|
772
|
+
*/
|
|
773
|
+
jsonp(t, e) {
|
|
774
|
+
const n = "_jsonp_" + M.guid(), r = document.getElementsByTagName("head")[0];
|
|
775
|
+
t.includes("?") ? t += "&callback=" + n : t += "?callback=" + n;
|
|
776
|
+
let i = document.createElement("script");
|
|
777
|
+
i.type = "text/javascript", i.src = t, window[n] = function(o) {
|
|
778
|
+
e(null, o), r.removeChild(i), i = null, delete window[n];
|
|
779
|
+
}, r.appendChild(i);
|
|
780
|
+
},
|
|
781
|
+
/**
|
|
782
|
+
* Fetch remote resource by HTTP "GET" method
|
|
783
|
+
* @param {String} url - resource url
|
|
784
|
+
* @param {Object} [options=null] - request options
|
|
785
|
+
* @param {Object} [options.headers=null] - HTTP headers
|
|
786
|
+
* @param {String} [options.responseType=null] - responseType
|
|
787
|
+
* @param {String} [options.credentials=null] - if with credentials, set it to "include"
|
|
788
|
+
* @param {Function} cb - callback function when completed
|
|
789
|
+
* @return {Ajax} Ajax
|
|
790
|
+
* @example
|
|
791
|
+
* AjaxUtil.get(
|
|
792
|
+
* 'url/to/resource',
|
|
793
|
+
* (err, data) => {
|
|
794
|
+
* if (err) {
|
|
795
|
+
* throw new Error(err);
|
|
796
|
+
* }
|
|
797
|
+
* // do things with data
|
|
798
|
+
* }
|
|
799
|
+
* );
|
|
800
|
+
*/
|
|
801
|
+
get(t, e, n) {
|
|
802
|
+
if (M.isFunction(e)) {
|
|
803
|
+
const i = n;
|
|
804
|
+
n = e, e = i;
|
|
805
|
+
}
|
|
806
|
+
const r = E._getClient(n);
|
|
807
|
+
if (r.open("GET", t, !0), e) {
|
|
808
|
+
for (const i in e.headers)
|
|
809
|
+
r.setRequestHeader(i, e.headers[i]);
|
|
810
|
+
r.withCredentials = e.credentials === "include", e.responseType && (r.responseType = e.responseType);
|
|
811
|
+
}
|
|
812
|
+
return r.send(null), r;
|
|
813
|
+
},
|
|
814
|
+
/**
|
|
815
|
+
* Fetch remote resource by HTTP "POST" method
|
|
816
|
+
* @param {String} url - resource url
|
|
817
|
+
* @param {Object} options - request options
|
|
818
|
+
* @param {String|Object} options.postData - post data
|
|
819
|
+
* @param {Object} [options.headers=null] - HTTP headers
|
|
820
|
+
* @param {Function} cb - callback function when completed
|
|
821
|
+
* @return {Ajax} Ajax
|
|
822
|
+
* @example
|
|
823
|
+
* AjaxUtil.post(
|
|
824
|
+
* 'url/to/post',
|
|
825
|
+
* {
|
|
826
|
+
* postData : {
|
|
827
|
+
* 'param0' : 'val0',
|
|
828
|
+
* 'param1' : 1
|
|
829
|
+
* }
|
|
830
|
+
* },
|
|
831
|
+
* (err, data) => {
|
|
832
|
+
* if (err) {
|
|
833
|
+
* throw new Error(err);
|
|
834
|
+
* }
|
|
835
|
+
* // do things with data
|
|
836
|
+
* }
|
|
837
|
+
* );
|
|
838
|
+
*/
|
|
839
|
+
post(t, e = {}, n) {
|
|
840
|
+
let r;
|
|
841
|
+
if (typeof t != "string" ? (n = e.cb, r = e.postData, e = { ...e }, delete e.cb, delete e.postData, t = e.url) : (typeof e == "function" && (n = e, e = {}), r = e.postData), !n)
|
|
842
|
+
throw new Error("Callback function is required");
|
|
843
|
+
const i = E._getClient(n);
|
|
844
|
+
return i.open("POST", t, !0), e.headers = e.headers || {}, e.headers["Content-Type"] || (e.headers["Content-Type"] = "application/x-www-form-urlencoded"), Object.keys(e.headers).forEach((o) => {
|
|
845
|
+
i.setRequestHeader(o, e.headers[o]);
|
|
846
|
+
}), typeof r != "string" && (r = JSON.stringify(r)), i.send(r), i;
|
|
847
|
+
},
|
|
848
|
+
_wrapCallback(t, e) {
|
|
849
|
+
return function() {
|
|
850
|
+
t.readyState === 4 && (t.status === 200 ? t.responseType === "arraybuffer" ? t.response.byteLength === 0 ? e(new Error("http status 200 returned without content.")) : e(null, {
|
|
851
|
+
data: t.response,
|
|
852
|
+
cacheControl: t.getResponseHeader("Cache-Control"),
|
|
853
|
+
expires: t.getResponseHeader("Expires"),
|
|
854
|
+
contentType: t.getResponseHeader("Content-Type")
|
|
855
|
+
}) : e(null, t.responseText) : e(new Error(t.statusText + "," + t.status)));
|
|
856
|
+
};
|
|
857
|
+
},
|
|
858
|
+
_getClient(t) {
|
|
859
|
+
let e = null;
|
|
860
|
+
try {
|
|
861
|
+
e = new XMLHttpRequest();
|
|
862
|
+
} catch {
|
|
863
|
+
throw new Error("XMLHttpRequest not supported.");
|
|
864
|
+
}
|
|
865
|
+
return e && (e.onreadystatechange = E._wrapCallback(e, t)), e;
|
|
866
|
+
},
|
|
867
|
+
/**
|
|
868
|
+
* Fetch resource as arraybuffer.
|
|
869
|
+
* @param {String} url - url
|
|
870
|
+
* @param {Object} [options=null] - options, same as Ajax.get
|
|
871
|
+
* @param {Function} cb - callback function when completed.
|
|
872
|
+
* @example
|
|
873
|
+
* AjaxUtil.getArrayBuffer(
|
|
874
|
+
* 'url/to/resource.bin',
|
|
875
|
+
* (err, data) => {
|
|
876
|
+
* if (err) {
|
|
877
|
+
* throw new Error(err);
|
|
878
|
+
* }
|
|
879
|
+
* // data is a binary array
|
|
880
|
+
* }
|
|
881
|
+
* );
|
|
882
|
+
*/
|
|
883
|
+
getArrayBuffer(t, e, n) {
|
|
884
|
+
if (M.isFunction(e)) {
|
|
885
|
+
const r = n;
|
|
886
|
+
n = e, e = r;
|
|
887
|
+
}
|
|
888
|
+
return e || (e = {}), e.responseType = "arraybuffer", E.get(t, e, n);
|
|
889
|
+
},
|
|
890
|
+
getImage(t, e, n) {
|
|
891
|
+
return E.getArrayBuffer(e, n, (r, i) => {
|
|
892
|
+
if (r)
|
|
893
|
+
t.onerror && t.onerror(r);
|
|
894
|
+
else if (i) {
|
|
895
|
+
const o = window.URL || window.webkitURL, a = t.onload;
|
|
896
|
+
t.onload = () => {
|
|
897
|
+
a && a(), o.revokeObjectURL(t.src);
|
|
898
|
+
};
|
|
899
|
+
const c = new Blob([new Uint8Array(i.data)], { type: i.contentType });
|
|
900
|
+
t.cacheControl = i.cacheControl, t.expires = i.expires, t.src = i.data.byteLength ? o.createObjectURL(c) : $.emptyImageUrl;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
},
|
|
904
|
+
/**
|
|
905
|
+
* Fetch resource as a JSON Object.
|
|
906
|
+
* @param {String} url - json's url
|
|
907
|
+
* @param {Object} [options=null] - optional options
|
|
908
|
+
* @param {String} [options.jsonp=false] - fetch by jsonp, false by default
|
|
909
|
+
* @param {Function} cb - callback function when completed.
|
|
910
|
+
* @example
|
|
911
|
+
* AjaxUtil.getJSON(
|
|
912
|
+
* 'url/to/resource.json',
|
|
913
|
+
* { jsonp : true },
|
|
914
|
+
* (err, json) => {
|
|
915
|
+
* if (err) {
|
|
916
|
+
* throw new Error(err);
|
|
917
|
+
* }
|
|
918
|
+
* // json is a JSON Object
|
|
919
|
+
* console.log(json.foo);
|
|
920
|
+
* }
|
|
921
|
+
* );
|
|
922
|
+
*/
|
|
923
|
+
getJSON(t, e, n) {
|
|
924
|
+
if (M.isFunction(e)) {
|
|
925
|
+
const i = n;
|
|
926
|
+
n = e, e = i;
|
|
927
|
+
}
|
|
928
|
+
const r = function(i, o) {
|
|
929
|
+
const a = o ? T.parse(o) : null;
|
|
930
|
+
n && n(i, a);
|
|
931
|
+
};
|
|
932
|
+
return e && e.jsonp ? E.jsonp(t, r) : E.get(t, e, r);
|
|
933
|
+
}
|
|
934
|
+
}, Q = {
|
|
665
935
|
/**
|
|
666
936
|
* 获取浏览器类型
|
|
667
937
|
*
|
|
@@ -678,8 +948,8 @@ const F = {
|
|
|
678
948
|
*/
|
|
679
949
|
detectOS() {
|
|
680
950
|
let t = "";
|
|
681
|
-
const e = navigator.userAgent.indexOf("Windows", 0) != -1 ? 1 : 0, n = navigator.userAgent.indexOf("mac", 0) != -1 ? 1 : 0, r = navigator.userAgent.indexOf("Linux", 0) != -1 ? 1 : 0,
|
|
682
|
-
return e ? t = "MS Windows" : n ? t = "Apple mac" : r ? t = "Linux" :
|
|
951
|
+
const e = navigator.userAgent.indexOf("Windows", 0) != -1 ? 1 : 0, n = navigator.userAgent.indexOf("mac", 0) != -1 ? 1 : 0, r = navigator.userAgent.indexOf("Linux", 0) != -1 ? 1 : 0, i = navigator.userAgent.indexOf("X11", 0) != -1 ? 1 : 0;
|
|
952
|
+
return e ? t = "MS Windows" : n ? t = "Apple mac" : r ? t = "Linux" : i && (t = "Unix"), t;
|
|
683
953
|
},
|
|
684
954
|
/**
|
|
685
955
|
* 切换全屏状态
|
|
@@ -701,9 +971,9 @@ const F = {
|
|
|
701
971
|
refreshScale() {
|
|
702
972
|
const t = document.documentElement.clientWidth || 0, e = document.documentElement.clientHeight || 0, n = document.getElementById("app");
|
|
703
973
|
if (!n) return;
|
|
704
|
-
const r = n.style,
|
|
705
|
-
let
|
|
706
|
-
|
|
974
|
+
const r = n.style, i = t / e, o = 16 / 9;
|
|
975
|
+
let a = t / 1920;
|
|
976
|
+
i > o && (a = e / 1080), r.transformOrigin = "left top", r.transform = `scale(${a}) translateX(-49.99%)`, r.width = `${t / a}px`;
|
|
707
977
|
},
|
|
708
978
|
/**
|
|
709
979
|
* 获取HTML字体大小
|
|
@@ -714,7 +984,7 @@ const F = {
|
|
|
714
984
|
const t = document.documentElement.clientWidth || document.body.clientWidth, e = document.querySelector("html");
|
|
715
985
|
e && (e.style.fontSize = t / 192 + "px");
|
|
716
986
|
}
|
|
717
|
-
},
|
|
987
|
+
}, K = {
|
|
718
988
|
set: function(t, e, n = 30) {
|
|
719
989
|
var r = /* @__PURE__ */ new Date();
|
|
720
990
|
r.setTime(r.getTime() + n * 24 * 60 * 60 * 1e3), document.cookie = t + "=" + escape(e) + ";expires=" + r.toUTCString();
|
|
@@ -729,17 +999,17 @@ const F = {
|
|
|
729
999
|
var e = document.cookie.match(new RegExp("(^| )" + t + "=([^;]*)(;|$)"));
|
|
730
1000
|
return e != null ? e[2] : "";
|
|
731
1001
|
}
|
|
732
|
-
},
|
|
1002
|
+
}, Y = {
|
|
733
1003
|
PI: 3.141592653589793,
|
|
734
1004
|
XPI: 3.141592653589793 * 3e3 / 180,
|
|
735
1005
|
delta(t, e) {
|
|
736
1006
|
const r = 0.006693421622965943;
|
|
737
|
-
let
|
|
738
|
-
const
|
|
739
|
-
let
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
return
|
|
1007
|
+
let i = this.transformLat(e - 105, t - 35), o = this.transformLon(e - 105, t - 35);
|
|
1008
|
+
const a = t / 180 * this.PI;
|
|
1009
|
+
let c = Math.sin(a);
|
|
1010
|
+
c = 1 - r * c * c;
|
|
1011
|
+
const l = Math.sqrt(c);
|
|
1012
|
+
return i = i * 180 / (6378245 * (1 - r) / (c * l) * this.PI), o = o * 180 / (6378245 / l * Math.cos(a) * this.PI), { lat: i, lng: o };
|
|
743
1013
|
},
|
|
744
1014
|
/**
|
|
745
1015
|
* 判断经纬度是否不在中国境内
|
|
@@ -767,23 +1037,23 @@ const F = {
|
|
|
767
1037
|
},
|
|
768
1038
|
// GCJ-02 to WGS-84 exactly
|
|
769
1039
|
gcjDecryptExact(t, e) {
|
|
770
|
-
let
|
|
1040
|
+
let i = 0.01, o = 0.01, a = t - i, c = e - o, l = t + i, u = e + o, h = 0, d = 0, f = 0;
|
|
771
1041
|
for (; ; ) {
|
|
772
|
-
|
|
773
|
-
const
|
|
774
|
-
if (
|
|
1042
|
+
h = (a + l) / 2, d = (c + u) / 2;
|
|
1043
|
+
const m = this.gcjEncrypt(h, d);
|
|
1044
|
+
if (i = m.lat - t, o = m.lng - e, Math.abs(i) < 1e-9 && Math.abs(o) < 1e-9 || (i > 0 ? l = h : a = h, o > 0 ? u = d : c = d, ++f > 1e4)) break;
|
|
775
1045
|
}
|
|
776
|
-
return { lat:
|
|
1046
|
+
return { lat: h, lng: d };
|
|
777
1047
|
},
|
|
778
1048
|
// GCJ-02 to BD-09
|
|
779
1049
|
bdEncrypt(t, e) {
|
|
780
|
-
const n = e, r = t,
|
|
781
|
-
return { lat:
|
|
1050
|
+
const n = e, r = t, i = Math.sqrt(n * n + r * r) + 2e-5 * Math.sin(r * this.XPI), o = Math.atan2(r, n) + 3e-6 * Math.cos(n * this.XPI), a = i * Math.cos(o) + 65e-4;
|
|
1051
|
+
return { lat: i * Math.sin(o) + 6e-3, lng: a };
|
|
782
1052
|
},
|
|
783
1053
|
// BD-09 to GCJ-02
|
|
784
1054
|
bdDecrypt(t, e) {
|
|
785
|
-
const n = e - 65e-4, r = t - 6e-3,
|
|
786
|
-
return { lat:
|
|
1055
|
+
const n = e - 65e-4, r = t - 6e-3, i = Math.sqrt(n * n + r * r) - 2e-5 * Math.sin(r * this.XPI), o = Math.atan2(r, n) - 3e-6 * Math.cos(n * this.XPI), a = i * Math.cos(o);
|
|
1056
|
+
return { lat: i * Math.sin(o), lng: a };
|
|
787
1057
|
},
|
|
788
1058
|
// WGS-84 to Web mercator
|
|
789
1059
|
// mercatorLat -> y mercatorLon -> x
|
|
@@ -824,17 +1094,17 @@ const F = {
|
|
|
824
1094
|
if (!Array.isArray(t))
|
|
825
1095
|
return n ? e.call(n, t) : e(t);
|
|
826
1096
|
const r = [];
|
|
827
|
-
let
|
|
828
|
-
for (let
|
|
829
|
-
if (
|
|
1097
|
+
let i, o;
|
|
1098
|
+
for (let a = 0, c = t.length; a < c; a++) {
|
|
1099
|
+
if (i = t[a], M.isNil(i)) {
|
|
830
1100
|
r.push(null);
|
|
831
1101
|
continue;
|
|
832
1102
|
}
|
|
833
|
-
Array.isArray(
|
|
1103
|
+
Array.isArray(i) ? r.push(this.deCompose(i, e, n)) : (o = n ? e.call(n, i) : e(i), r.push(o));
|
|
834
1104
|
}
|
|
835
1105
|
return r;
|
|
836
1106
|
}
|
|
837
|
-
},
|
|
1107
|
+
}, z = {
|
|
838
1108
|
random() {
|
|
839
1109
|
let t = Math.floor(Math.random() * 256).toString(16), e = Math.floor(Math.random() * 256).toString(16), n = Math.floor(Math.random() * 256).toString(16);
|
|
840
1110
|
return t = t.length === 1 ? "0" + t : t, e = e.length === 1 ? "0" + e : e, n = n.length === 1 ? "0" + n : n, "#" + t + e + n;
|
|
@@ -866,11 +1136,11 @@ const F = {
|
|
|
866
1136
|
* @returns 返回rgba格式的颜色值,格式为rgba(r,g,b,1)
|
|
867
1137
|
*/
|
|
868
1138
|
hexToRgba(t) {
|
|
869
|
-
const e = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, n = t.replace(e, (
|
|
870
|
-
if (!
|
|
1139
|
+
const e = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, n = t.replace(e, (l, u, h, d) => u + u + h + h + d + d), i = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);
|
|
1140
|
+
if (!i)
|
|
871
1141
|
return t;
|
|
872
|
-
const
|
|
873
|
-
return `rgba(${
|
|
1142
|
+
const o = parseInt(i[1], 16), a = parseInt(i[2], 16), c = parseInt(i[3], 16);
|
|
1143
|
+
return `rgba(${o},${a},${c},1)`;
|
|
874
1144
|
},
|
|
875
1145
|
/**
|
|
876
1146
|
* 将 HSL 颜色值转换为 RGBA 颜色值
|
|
@@ -884,18 +1154,18 @@ const F = {
|
|
|
884
1154
|
const e = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(t);
|
|
885
1155
|
if (!e)
|
|
886
1156
|
return null;
|
|
887
|
-
const n = parseInt(e[1], 10) / 360, r = parseInt(e[2], 10) / 100,
|
|
888
|
-
function
|
|
889
|
-
return f < 0 && (f += 1), f > 1 && (f -= 1), f < 1 / 6 ?
|
|
1157
|
+
const n = parseInt(e[1], 10) / 360, r = parseInt(e[2], 10) / 100, i = parseInt(e[3], 10) / 100, o = e[4] ? parseFloat(e[4]) : 1;
|
|
1158
|
+
function a(h, d, f) {
|
|
1159
|
+
return f < 0 && (f += 1), f > 1 && (f -= 1), f < 1 / 6 ? h + (d - h) * 6 * f : f < 1 / 2 ? d : f < 2 / 3 ? h + (d - h) * (2 / 3 - f) * 6 : h;
|
|
890
1160
|
}
|
|
891
|
-
let
|
|
1161
|
+
let c, l, u;
|
|
892
1162
|
if (r === 0)
|
|
893
|
-
|
|
1163
|
+
c = l = u = i;
|
|
894
1164
|
else {
|
|
895
|
-
const
|
|
896
|
-
|
|
1165
|
+
const h = i < 0.5 ? i * (1 + r) : i + r - i * r, d = 2 * i - h;
|
|
1166
|
+
c = a(d, h, n + 1 / 3), l = a(d, h, n), u = a(d, h, n - 1 / 3);
|
|
897
1167
|
}
|
|
898
|
-
return `rgba(${Math.round(
|
|
1168
|
+
return `rgba(${Math.round(c * 255)},${Math.round(l * 255)},${Math.round(u * 255)},${o})`;
|
|
899
1169
|
},
|
|
900
1170
|
isHex(t) {
|
|
901
1171
|
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);
|
|
@@ -975,7 +1245,7 @@ Date.prototype.addDate = function(t, e) {
|
|
|
975
1245
|
}
|
|
976
1246
|
return n;
|
|
977
1247
|
};
|
|
978
|
-
const
|
|
1248
|
+
const X = {
|
|
979
1249
|
lastMonthDate: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth() - 1, 1),
|
|
980
1250
|
thisMonthDate: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
|
|
981
1251
|
nextMonthDate: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth() + 1, 1),
|
|
@@ -1019,26 +1289,26 @@ const q = {
|
|
|
1019
1289
|
* @returns 返回格式化后的时间间隔字符串,格式为"天数 天 小时 时 分钟 分 秒 秒"或"少于1秒"
|
|
1020
1290
|
*/
|
|
1021
1291
|
formatDateInterval(t, e) {
|
|
1022
|
-
const n = new Date(t),
|
|
1292
|
+
const n = new Date(t), i = new Date(e).getTime() - n.getTime(), o = Math.floor(i / (24 * 3600 * 1e3)), a = i % (24 * 3600 * 1e3), c = Math.floor(a / (3600 * 1e3)), l = a % (3600 * 1e3), u = Math.floor(l / (60 * 1e3)), h = l % (60 * 1e3), d = Math.round(h / 1e3);
|
|
1023
1293
|
let f = "";
|
|
1024
|
-
return
|
|
1294
|
+
return o > 0 && (f += o + "天"), c > 0 && (f += c + "时"), u > 0 && (f += u + "分"), d > 0 && (f += d + "秒"), o === 0 && c === 0 && u === 0 && d === 0 && (f = "少于1秒"), f;
|
|
1025
1295
|
},
|
|
1026
1296
|
formatterCounter(t) {
|
|
1027
|
-
const e = function(
|
|
1028
|
-
return (
|
|
1029
|
-
}, n = e(Math.floor(t / 3600)), r = t % 3600,
|
|
1030
|
-
return `${n}:${
|
|
1297
|
+
const e = function(c) {
|
|
1298
|
+
return (c > 10 ? "" : "0") + (c || 0);
|
|
1299
|
+
}, n = e(Math.floor(t / 3600)), r = t % 3600, i = e(Math.floor(r / 60)), o = r % 60, a = e(Math.round(o));
|
|
1300
|
+
return `${n}:${i}:${a}`;
|
|
1031
1301
|
},
|
|
1032
1302
|
sleep(t) {
|
|
1033
1303
|
}
|
|
1034
1304
|
};
|
|
1035
|
-
function
|
|
1305
|
+
function q(t) {
|
|
1036
1306
|
return t.trim ? t.trim() : t.replace(/^\s+|\s+$/g, "");
|
|
1037
1307
|
}
|
|
1038
|
-
function
|
|
1039
|
-
return
|
|
1308
|
+
function D(t) {
|
|
1309
|
+
return q(t).split(/\s+/);
|
|
1040
1310
|
}
|
|
1041
|
-
const
|
|
1311
|
+
const V = {
|
|
1042
1312
|
/**
|
|
1043
1313
|
* 获取元素的样式值
|
|
1044
1314
|
*
|
|
@@ -1050,8 +1320,8 @@ const W = {
|
|
|
1050
1320
|
var r;
|
|
1051
1321
|
let n = t.style[e];
|
|
1052
1322
|
if (!n || n === "auto") {
|
|
1053
|
-
const
|
|
1054
|
-
n =
|
|
1323
|
+
const i = (r = document.defaultView) == null ? void 0 : r.getComputedStyle(t, null);
|
|
1324
|
+
n = i ? i[e] : null, n === "auto" && (n = null);
|
|
1055
1325
|
}
|
|
1056
1326
|
return n;
|
|
1057
1327
|
},
|
|
@@ -1137,8 +1407,8 @@ const W = {
|
|
|
1137
1407
|
*/
|
|
1138
1408
|
addClass(t, e) {
|
|
1139
1409
|
if (t.classList !== void 0) {
|
|
1140
|
-
const n =
|
|
1141
|
-
for (let r = 0,
|
|
1410
|
+
const n = D(e);
|
|
1411
|
+
for (let r = 0, i = n.length; r < i; r++)
|
|
1142
1412
|
t.classList.add(n[r]);
|
|
1143
1413
|
} else if (!this.hasClass(t, e)) {
|
|
1144
1414
|
const n = this.getClass(t);
|
|
@@ -1152,7 +1422,7 @@ const W = {
|
|
|
1152
1422
|
* @param name 要移除的类名,多个类名用空格分隔
|
|
1153
1423
|
*/
|
|
1154
1424
|
removeClass(t, e) {
|
|
1155
|
-
t.classList !== void 0 ?
|
|
1425
|
+
t.classList !== void 0 ? D(e).forEach((r) => t.classList.remove(r)) : this.setClass(t, (" " + this.getClass(t) + " ").replace(" " + e + " ", " ").trim());
|
|
1156
1426
|
},
|
|
1157
1427
|
/**
|
|
1158
1428
|
* 设置元素的 CSS 类名
|
|
@@ -1172,199 +1442,7 @@ const W = {
|
|
|
1172
1442
|
parseFromString(t) {
|
|
1173
1443
|
return new DOMParser().parseFromString(t, "text/xml").children[0];
|
|
1174
1444
|
}
|
|
1175
|
-
},
|
|
1176
|
-
toRadian: Math.PI / 180,
|
|
1177
|
-
R: 6371393,
|
|
1178
|
-
/**
|
|
1179
|
-
* 判断给定的经纬度是否合法
|
|
1180
|
-
*
|
|
1181
|
-
* @param lng 经度值
|
|
1182
|
-
* @param lat 纬度值
|
|
1183
|
-
* @returns 如果经纬度合法,返回true;否则返回false
|
|
1184
|
-
*/
|
|
1185
|
-
isLnglat(t, e) {
|
|
1186
|
-
return !isNaN(t) && !isNaN(e) && +e > -90 && +e < 90 && +t > -180 && +t < 180;
|
|
1187
|
-
},
|
|
1188
|
-
/**
|
|
1189
|
-
* 计算两哥平面坐标点间的距离
|
|
1190
|
-
*
|
|
1191
|
-
* @param p1 坐标点1,包含x和y属性
|
|
1192
|
-
* @param p2 坐标点2,包含x和y属性
|
|
1193
|
-
* @returns 返回两点间的欧几里得距离
|
|
1194
|
-
*/
|
|
1195
|
-
distance(t, e) {
|
|
1196
|
-
return Math.sqrt(Math.pow(e.x - t.x, 2) + Math.pow(e.y - t.y, 2));
|
|
1197
|
-
},
|
|
1198
|
-
/**
|
|
1199
|
-
* 计算两个经纬度点之间的距离
|
|
1200
|
-
*
|
|
1201
|
-
* @param A 经纬度点A,包含lng(经度)和lat(纬度)两个属性
|
|
1202
|
-
* @param B 经纬度点B,包含lng(经度)和lat(纬度)两个属性
|
|
1203
|
-
* @returns 返回两点之间的距离,单位为米
|
|
1204
|
-
*/
|
|
1205
|
-
distanceByPoints(t, e) {
|
|
1206
|
-
const { lng: n, lat: r } = t, { lng: s, lat: i } = e, o = 6371e3, a = Math.cos(r * Math.PI / 180) * Math.cos(i * Math.PI / 180) * Math.cos((n - s) * Math.PI / 180), c = Math.sin(r * Math.PI / 180) * Math.sin(i * Math.PI / 180);
|
|
1207
|
-
let h = a + c;
|
|
1208
|
-
return h > 1 && (h = 1), h < -1 && (h = -1), Math.acos(h) * o;
|
|
1209
|
-
},
|
|
1210
|
-
/**
|
|
1211
|
-
* 格式化经纬度为度分秒格式
|
|
1212
|
-
*
|
|
1213
|
-
* @param lng 经度
|
|
1214
|
-
* @param lat 纬度
|
|
1215
|
-
* @returns 返回格式化后的经纬度字符串,格式为:经度度分秒,纬度度分秒
|
|
1216
|
-
*/
|
|
1217
|
-
formatLnglat(t, e) {
|
|
1218
|
-
let n = "";
|
|
1219
|
-
function r(s) {
|
|
1220
|
-
const i = Math.floor(s), o = Math.floor((s - i) * 60), a = (s - i) * 3600 - o * 60;
|
|
1221
|
-
return `${i}°${o}′${a.toFixed(2)}″`;
|
|
1222
|
-
}
|
|
1223
|
-
return this.isLnglat(t, e) ? n = r(t) + "," + r(e) : isNaN(t) ? isNaN(e) || (n = r(e)) : n = r(t), n;
|
|
1224
|
-
},
|
|
1225
|
-
/**
|
|
1226
|
-
* 将经纬度字符串转换为度
|
|
1227
|
-
*
|
|
1228
|
-
* @param lng 经度字符串
|
|
1229
|
-
* @param lat 纬度字符串
|
|
1230
|
-
* @returns 转换后的经纬度对象
|
|
1231
|
-
*/
|
|
1232
|
-
transformLnglat(t, e) {
|
|
1233
|
-
function n(r) {
|
|
1234
|
-
let i = /[sw]/i.test(r) ? -1 : 1;
|
|
1235
|
-
const o = r.match(/[\d.]+/g) || [];
|
|
1236
|
-
let a = 0;
|
|
1237
|
-
for (let c = 0; c < o.length; c++)
|
|
1238
|
-
a += parseFloat(o[c]) / i, i *= 60;
|
|
1239
|
-
return a;
|
|
1240
|
-
}
|
|
1241
|
-
if (t && e)
|
|
1242
|
-
return {
|
|
1243
|
-
lng: n(t),
|
|
1244
|
-
lat: n(e)
|
|
1245
|
-
};
|
|
1246
|
-
},
|
|
1247
|
-
/**
|
|
1248
|
-
* 射线法判断点是否在多边形内
|
|
1249
|
-
*
|
|
1250
|
-
* @param p 点对象,包含x和y属性
|
|
1251
|
-
* @param poly 多边形顶点数组,可以是字符串数组或对象数组
|
|
1252
|
-
* @returns 返回字符串,表示点相对于多边形的位置:'in'表示在多边形内,'out'表示在多边形外,'on'表示在多边形上
|
|
1253
|
-
*/
|
|
1254
|
-
rayCasting(t, e) {
|
|
1255
|
-
for (var n = t.x, r = t.y, s = !1, i = 0, o = e.length, a = o - 1; i < o; a = i, i++) {
|
|
1256
|
-
var c = e[i].x, h = e[i].y, l = e[a].x, u = e[a].y;
|
|
1257
|
-
if (c === n && h === r || l === n && u === r)
|
|
1258
|
-
return "on";
|
|
1259
|
-
if (h < r && u >= r || h >= r && u < r) {
|
|
1260
|
-
var f = c + (r - h) * (l - c) / (u - h);
|
|
1261
|
-
if (f === n)
|
|
1262
|
-
return "on";
|
|
1263
|
-
f > n && (s = !s);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
return s ? "in" : "out";
|
|
1267
|
-
},
|
|
1268
|
-
/**
|
|
1269
|
-
* 旋转点
|
|
1270
|
-
*
|
|
1271
|
-
* @param p1 旋转前点坐标
|
|
1272
|
-
* @param p2 旋转中心坐标
|
|
1273
|
-
* @param θ 旋转角度(顺时针旋转为正)
|
|
1274
|
-
* @returns 旋转后点坐标
|
|
1275
|
-
*/
|
|
1276
|
-
rotatePoint(t, e, n) {
|
|
1277
|
-
const r = (t.x - e.x) * Math.cos(Math.PI / 180 * -n) - (t.y - e.y) * Math.sin(Math.PI / 180 * -n) + e.x, s = (t.x - e.x) * Math.sin(Math.PI / 180 * -n) + (t.y - e.y) * Math.cos(Math.PI / 180 * -n) + e.y;
|
|
1278
|
-
return { x: r, y: s };
|
|
1279
|
-
},
|
|
1280
|
-
/**
|
|
1281
|
-
* 根据两个平面坐标点计算方位角和距离
|
|
1282
|
-
*
|
|
1283
|
-
* @param p1 第一个点的坐标对象
|
|
1284
|
-
* @param p2 第二个点的坐标对象
|
|
1285
|
-
* @returns 返回一个对象,包含angle和distance属性,分别表示两点之间的角度(以度为单位,取值范围为0~359)和距离
|
|
1286
|
-
*/
|
|
1287
|
-
calcBearAndDis(t, e) {
|
|
1288
|
-
const { x: n, y: r } = t, { x: s, y: i } = e, o = s - n, a = i - r, c = Math.sqrt(o * o + a * a);
|
|
1289
|
-
return { angle: (Math.atan2(a, o) * (180 / Math.PI) + 360 + 90) % 360, distance: c };
|
|
1290
|
-
},
|
|
1291
|
-
/**
|
|
1292
|
-
* 根据两个经纬度点计算方位角和距离
|
|
1293
|
-
*
|
|
1294
|
-
* @param latlng1 第一个经纬度点
|
|
1295
|
-
* @param latlng2 第二个经纬度点
|
|
1296
|
-
* @returns 包含方位角和距离的对象
|
|
1297
|
-
*/
|
|
1298
|
-
calcBearAndDisByPoints(t, e) {
|
|
1299
|
-
var n = t.lat * 1, r = t.lng * 1, s = e.lat * 1, i = e.lng * 1, o = Math.sin((i - r) * this.toRadian) * Math.cos(s * this.toRadian), a = Math.cos(n * this.toRadian) * Math.sin(s * this.toRadian) - Math.sin(n * this.toRadian) * Math.cos(s * this.toRadian) * Math.cos((i - r) * this.toRadian), c = Math.atan2(o, a) * (180 / Math.PI), h = (s - n) * this.toRadian, l = (i - r) * this.toRadian, u = Math.sin(h / 2) * Math.sin(h / 2) + Math.cos(n * this.toRadian) * Math.cos(s * this.toRadian) * Math.sin(l / 2) * Math.sin(l / 2), f = 2 * Math.atan2(Math.sqrt(u), Math.sqrt(1 - u)), p = this.R * f;
|
|
1300
|
-
return {
|
|
1301
|
-
angle: c,
|
|
1302
|
-
distance: p
|
|
1303
|
-
};
|
|
1304
|
-
},
|
|
1305
|
-
/**
|
|
1306
|
-
* 计算点P到线段P1P2的最短距离
|
|
1307
|
-
*
|
|
1308
|
-
* @param p 点P的坐标
|
|
1309
|
-
* @param p1 线段起点P1的坐标
|
|
1310
|
-
* @param p2 线段终点P2的坐标
|
|
1311
|
-
* @returns 点P到线段P1P2的最短距离
|
|
1312
|
-
*/
|
|
1313
|
-
distanceToSegment(t, e, n) {
|
|
1314
|
-
const r = t.x, s = t.y, i = e.x, o = e.y, a = n.x, c = n.y, h = (a - i) * (r - i) + (c - o) * (s - o);
|
|
1315
|
-
if (h <= 0)
|
|
1316
|
-
return Math.sqrt((r - i) * (r - i) + (s - o) * (s - o));
|
|
1317
|
-
const l = (a - i) * (a - i) + (c - o) * (c - o);
|
|
1318
|
-
if (h >= l)
|
|
1319
|
-
return Math.sqrt((r - a) * (r - a) + (s - c) * (s - c));
|
|
1320
|
-
const u = h / l, f = i + (a - i) * u, p = o + (c - o) * u;
|
|
1321
|
-
return Math.sqrt((r - f) * (r - f) + (s - p) * (s - p));
|
|
1322
|
-
},
|
|
1323
|
-
/**
|
|
1324
|
-
* 根据给定的经纬度、角度和距离计算新的经纬度点
|
|
1325
|
-
*
|
|
1326
|
-
* @param latlng 给定的经纬度点,类型为LngLat
|
|
1327
|
-
* @param angle 角度值,单位为度,表示从当前点出发的方向
|
|
1328
|
-
* @param distance 距离值,单位为米,表示从当前点出发的距离
|
|
1329
|
-
* @returns 返回计算后的新经纬度点,类型为{lat: number, lng: number}
|
|
1330
|
-
*/
|
|
1331
|
-
calcPointByBearAndDis(t, e, n) {
|
|
1332
|
-
const r = m.toRadians(t.lat * 1), s = m.toRadians(t.lng * 1), i = n / this.R;
|
|
1333
|
-
e = m.toRadians(e);
|
|
1334
|
-
const o = Math.asin(Math.sin(r) * Math.cos(i) + Math.cos(r) * Math.sin(i) * Math.cos(e)), a = s + Math.atan2(Math.sin(e) * Math.sin(i) * Math.cos(r), Math.cos(i) - Math.sin(r) * Math.sin(o));
|
|
1335
|
-
return {
|
|
1336
|
-
lat: m.toDegrees(o),
|
|
1337
|
-
lng: m.toDegrees(a)
|
|
1338
|
-
};
|
|
1339
|
-
},
|
|
1340
|
-
/**
|
|
1341
|
-
* 将墨卡托坐标转换为经纬度坐标
|
|
1342
|
-
*
|
|
1343
|
-
* @param x 墨卡托坐标的x值
|
|
1344
|
-
* @param y 墨卡托坐标的y值
|
|
1345
|
-
* @returns 返回包含转换后的经度lng和纬度lat的对象
|
|
1346
|
-
*/
|
|
1347
|
-
mercatorTolonlat(t, e) {
|
|
1348
|
-
const n = t / 2003750834e-2 * 180;
|
|
1349
|
-
var r = e / 2003750834e-2 * 180;
|
|
1350
|
-
const s = 180 / Math.PI * (2 * Math.atan(Math.exp(r * Math.PI / 180)) - Math.PI / 2);
|
|
1351
|
-
return { lng: n, lat: s };
|
|
1352
|
-
},
|
|
1353
|
-
/**
|
|
1354
|
-
* 将经纬度坐标转换为墨卡托坐标
|
|
1355
|
-
*
|
|
1356
|
-
* @param lng 经度值
|
|
1357
|
-
* @param lat 纬度值
|
|
1358
|
-
* @returns 墨卡托坐标对象,包含x和y属性
|
|
1359
|
-
*/
|
|
1360
|
-
lonlatToMercator(t, e) {
|
|
1361
|
-
var n = 6378137;
|
|
1362
|
-
const r = t * Math.PI / 180 * n;
|
|
1363
|
-
var s = e * Math.PI / 180;
|
|
1364
|
-
const i = n / 2 * Math.log((1 + Math.sin(s)) / (1 - Math.sin(s)));
|
|
1365
|
-
return { x: r, y: i };
|
|
1366
|
-
}
|
|
1367
|
-
}, y = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon"], j = {
|
|
1445
|
+
}, w = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon"], Z = {
|
|
1368
1446
|
/**
|
|
1369
1447
|
* 获取GeoJSON要素的几何类型
|
|
1370
1448
|
*
|
|
@@ -1383,8 +1461,8 @@ const W = {
|
|
|
1383
1461
|
isGeoJson(t) {
|
|
1384
1462
|
const e = this.getGeoJsonType(t);
|
|
1385
1463
|
if (e) {
|
|
1386
|
-
for (let n = 0, r =
|
|
1387
|
-
if (
|
|
1464
|
+
for (let n = 0, r = w.length; n < r; n++)
|
|
1465
|
+
if (w[n] === e)
|
|
1388
1466
|
return !0;
|
|
1389
1467
|
}
|
|
1390
1468
|
return !1;
|
|
@@ -1397,7 +1475,7 @@ const W = {
|
|
|
1397
1475
|
*/
|
|
1398
1476
|
isGeoJsonPolygon(t) {
|
|
1399
1477
|
const e = this.getGeoJsonType(t);
|
|
1400
|
-
return !!(e && (e ===
|
|
1478
|
+
return !!(e && (e === w[4] || e === w[5]));
|
|
1401
1479
|
},
|
|
1402
1480
|
/**
|
|
1403
1481
|
* 判断给定的 GeoJSONFeature 是否为 GeoJSON 线
|
|
@@ -1407,7 +1485,7 @@ const W = {
|
|
|
1407
1485
|
*/
|
|
1408
1486
|
isGeoJsonLine(t) {
|
|
1409
1487
|
const e = this.getGeoJsonType(t);
|
|
1410
|
-
return !!(e && (e ===
|
|
1488
|
+
return !!(e && (e === w[2] || e === w[3]));
|
|
1411
1489
|
},
|
|
1412
1490
|
/**
|
|
1413
1491
|
* 判断是否为 GeoJSON 点类型
|
|
@@ -1417,7 +1495,7 @@ const W = {
|
|
|
1417
1495
|
*/
|
|
1418
1496
|
isGeoJsonPoint(t) {
|
|
1419
1497
|
const e = this.getGeoJsonType(t);
|
|
1420
|
-
return !!(e && (e ===
|
|
1498
|
+
return !!(e && (e === w[0] || e === w[1]));
|
|
1421
1499
|
},
|
|
1422
1500
|
/**
|
|
1423
1501
|
* 判断传入的 GeoJSONFeature 是否为 Multi 类型的 GeoJSON。
|
|
@@ -1449,38 +1527,38 @@ const W = {
|
|
|
1449
1527
|
const n = this.getGeoJsonType(t);
|
|
1450
1528
|
if (!n || !t.geometry)
|
|
1451
1529
|
return null;
|
|
1452
|
-
const
|
|
1453
|
-
if (!
|
|
1530
|
+
const i = t.geometry.coordinates;
|
|
1531
|
+
if (!i)
|
|
1454
1532
|
return null;
|
|
1455
|
-
let
|
|
1533
|
+
let o = 0, a = 0, c = 0;
|
|
1456
1534
|
switch (n) {
|
|
1457
1535
|
case "Point": {
|
|
1458
|
-
|
|
1536
|
+
o = i[0], a = i[1], c++;
|
|
1459
1537
|
break;
|
|
1460
1538
|
}
|
|
1461
1539
|
case "MultiPoint":
|
|
1462
1540
|
case "LineString": {
|
|
1463
|
-
for (let
|
|
1464
|
-
|
|
1541
|
+
for (let h = 0, d = i.length; h < d; h++)
|
|
1542
|
+
o += i[h][0], a += i[h][1], c++;
|
|
1465
1543
|
break;
|
|
1466
1544
|
}
|
|
1467
1545
|
case "MultiLineString":
|
|
1468
1546
|
case "Polygon": {
|
|
1469
|
-
for (let
|
|
1470
|
-
for (let f = 0,
|
|
1471
|
-
|
|
1547
|
+
for (let h = 0, d = i.length; h < d; h++)
|
|
1548
|
+
for (let f = 0, m = i[h].length; f < m; f++)
|
|
1549
|
+
o += i[h][f][0], a += i[h][f][1], c++;
|
|
1472
1550
|
break;
|
|
1473
1551
|
}
|
|
1474
1552
|
case "MultiPolygon": {
|
|
1475
|
-
for (let
|
|
1476
|
-
for (let f = 0,
|
|
1477
|
-
for (let
|
|
1478
|
-
|
|
1553
|
+
for (let h = 0, d = i.length; h < d; h++)
|
|
1554
|
+
for (let f = 0, m = i[h].length; f < m; f++)
|
|
1555
|
+
for (let A = 0, P = i[h][f].length; A < P; A++)
|
|
1556
|
+
o += i[h][f][A][0], a += i[h][f][A][1], c++;
|
|
1479
1557
|
break;
|
|
1480
1558
|
}
|
|
1481
1559
|
}
|
|
1482
|
-
const
|
|
1483
|
-
return e ? (e.x =
|
|
1560
|
+
const l = o / c, u = a / c;
|
|
1561
|
+
return e ? (e.x = l, e.y = u, e) : { x: l, y: u };
|
|
1484
1562
|
},
|
|
1485
1563
|
/**
|
|
1486
1564
|
* 将一个包含多个点、线或面的 GeoJSON 特征对象拆分成多个独立的 GeoJSON 特征对象数组。
|
|
@@ -1492,38 +1570,38 @@ const W = {
|
|
|
1492
1570
|
const e = this.getGeoJsonType(t);
|
|
1493
1571
|
if (!e || !t.geometry)
|
|
1494
1572
|
return null;
|
|
1495
|
-
const n = t.geometry, r = t.properties || {},
|
|
1496
|
-
if (!
|
|
1573
|
+
const n = t.geometry, r = t.properties || {}, i = n.coordinates;
|
|
1574
|
+
if (!i)
|
|
1497
1575
|
return null;
|
|
1498
|
-
const
|
|
1499
|
-
let
|
|
1576
|
+
const o = [];
|
|
1577
|
+
let a;
|
|
1500
1578
|
switch (e) {
|
|
1501
1579
|
case "MultiPoint": {
|
|
1502
|
-
|
|
1580
|
+
a = "Point";
|
|
1503
1581
|
break;
|
|
1504
1582
|
}
|
|
1505
1583
|
case "MultiLineString": {
|
|
1506
|
-
|
|
1584
|
+
a = "LineString";
|
|
1507
1585
|
break;
|
|
1508
1586
|
}
|
|
1509
1587
|
case "MultiPolygon": {
|
|
1510
|
-
|
|
1588
|
+
a = "Polygon";
|
|
1511
1589
|
break;
|
|
1512
1590
|
}
|
|
1513
1591
|
}
|
|
1514
|
-
if (
|
|
1515
|
-
for (let
|
|
1516
|
-
|
|
1592
|
+
if (a)
|
|
1593
|
+
for (let c = 0, l = i.length; c < l; c++)
|
|
1594
|
+
o.push({
|
|
1517
1595
|
type: "Feature",
|
|
1518
1596
|
geometry: {
|
|
1519
|
-
type:
|
|
1520
|
-
coordinates:
|
|
1597
|
+
type: a,
|
|
1598
|
+
coordinates: i[c]
|
|
1521
1599
|
},
|
|
1522
1600
|
properties: r
|
|
1523
1601
|
});
|
|
1524
1602
|
else
|
|
1525
|
-
|
|
1526
|
-
return
|
|
1603
|
+
o.push(t);
|
|
1604
|
+
return o;
|
|
1527
1605
|
},
|
|
1528
1606
|
/**
|
|
1529
1607
|
* 根据坐标数组生成GeoJSON要素
|
|
@@ -1555,17 +1633,211 @@ const W = {
|
|
|
1555
1633
|
geometry: { type: e, coordinates: t }
|
|
1556
1634
|
};
|
|
1557
1635
|
}
|
|
1558
|
-
},
|
|
1559
|
-
|
|
1560
|
-
|
|
1636
|
+
}, tt = {
|
|
1637
|
+
toRadian: Math.PI / 180,
|
|
1638
|
+
R: 6371393,
|
|
1639
|
+
/**
|
|
1640
|
+
* 判断给定的经纬度是否合法
|
|
1641
|
+
*
|
|
1642
|
+
* @param lng 经度值
|
|
1643
|
+
* @param lat 纬度值
|
|
1644
|
+
* @returns 如果经纬度合法,返回true;否则返回false
|
|
1645
|
+
*/
|
|
1646
|
+
isLnglat(t, e) {
|
|
1647
|
+
return !isNaN(t) && !isNaN(e) && +e > -90 && +e < 90 && +t > -180 && +t < 180;
|
|
1561
1648
|
},
|
|
1562
|
-
|
|
1563
|
-
|
|
1649
|
+
/**
|
|
1650
|
+
* 计算两哥平面坐标点间的距离
|
|
1651
|
+
*
|
|
1652
|
+
* @param p1 坐标点1,包含x和y属性
|
|
1653
|
+
* @param p2 坐标点2,包含x和y属性
|
|
1654
|
+
* @returns 返回两点间的欧几里得距离
|
|
1655
|
+
*/
|
|
1656
|
+
distance(t, e) {
|
|
1657
|
+
return Math.sqrt(Math.pow(e.x - t.x, 2) + Math.pow(e.y - t.y, 2));
|
|
1564
1658
|
},
|
|
1565
|
-
|
|
1566
|
-
|
|
1659
|
+
/**
|
|
1660
|
+
* 计算两个经纬度点之间的距离
|
|
1661
|
+
*
|
|
1662
|
+
* @param A 经纬度点A,包含lng(经度)和lat(纬度)两个属性
|
|
1663
|
+
* @param B 经纬度点B,包含lng(经度)和lat(纬度)两个属性
|
|
1664
|
+
* @returns 返回两点之间的距离,单位为米
|
|
1665
|
+
*/
|
|
1666
|
+
distanceByPoints(t, e) {
|
|
1667
|
+
const { lng: n, lat: r } = t, { lng: i, lat: o } = e, a = 6371e3, c = Math.cos(r * Math.PI / 180) * Math.cos(o * Math.PI / 180) * Math.cos((n - i) * Math.PI / 180), l = Math.sin(r * Math.PI / 180) * Math.sin(o * Math.PI / 180);
|
|
1668
|
+
let u = c + l;
|
|
1669
|
+
return u > 1 && (u = 1), u < -1 && (u = -1), Math.acos(u) * a;
|
|
1670
|
+
},
|
|
1671
|
+
/**
|
|
1672
|
+
* 格式化经纬度为度分秒格式
|
|
1673
|
+
*
|
|
1674
|
+
* @param lng 经度
|
|
1675
|
+
* @param lat 纬度
|
|
1676
|
+
* @returns 返回格式化后的经纬度字符串,格式为:经度度分秒,纬度度分秒
|
|
1677
|
+
*/
|
|
1678
|
+
formatLnglat(t, e) {
|
|
1679
|
+
let n = "";
|
|
1680
|
+
function r(i) {
|
|
1681
|
+
const o = Math.floor(i), a = Math.floor((i - o) * 60), c = (i - o) * 3600 - a * 60;
|
|
1682
|
+
return `${o}°${a}′${c.toFixed(2)}″`;
|
|
1683
|
+
}
|
|
1684
|
+
return this.isLnglat(t, e) ? n = r(t) + "," + r(e) : isNaN(t) ? isNaN(e) || (n = r(e)) : n = r(t), n;
|
|
1685
|
+
},
|
|
1686
|
+
/**
|
|
1687
|
+
* 将经纬度字符串转换为度
|
|
1688
|
+
*
|
|
1689
|
+
* @param lng 经度字符串
|
|
1690
|
+
* @param lat 纬度字符串
|
|
1691
|
+
* @returns 转换后的经纬度对象
|
|
1692
|
+
*/
|
|
1693
|
+
transformLnglat(t, e) {
|
|
1694
|
+
function n(r) {
|
|
1695
|
+
let o = /[sw]/i.test(r) ? -1 : 1;
|
|
1696
|
+
const a = r.match(/[\d.]+/g) || [];
|
|
1697
|
+
let c = 0;
|
|
1698
|
+
for (let l = 0; l < a.length; l++)
|
|
1699
|
+
c += parseFloat(a[l]) / o, o *= 60;
|
|
1700
|
+
return c;
|
|
1701
|
+
}
|
|
1702
|
+
if (t && e)
|
|
1703
|
+
return {
|
|
1704
|
+
lng: n(t),
|
|
1705
|
+
lat: n(e)
|
|
1706
|
+
};
|
|
1707
|
+
},
|
|
1708
|
+
/**
|
|
1709
|
+
* 射线法判断点是否在多边形内
|
|
1710
|
+
*
|
|
1711
|
+
* @param p 点对象,包含x和y属性
|
|
1712
|
+
* @param poly 多边形顶点数组,可以是字符串数组或对象数组
|
|
1713
|
+
* @returns 返回字符串,表示点相对于多边形的位置:'in'表示在多边形内,'out'表示在多边形外,'on'表示在多边形上
|
|
1714
|
+
*/
|
|
1715
|
+
rayCasting(t, e) {
|
|
1716
|
+
for (var n = t.x, r = t.y, i = !1, o = 0, a = e.length, c = a - 1; o < a; c = o, o++) {
|
|
1717
|
+
var l = e[o].x, u = e[o].y, h = e[c].x, d = e[c].y;
|
|
1718
|
+
if (l === n && u === r || h === n && d === r)
|
|
1719
|
+
return "on";
|
|
1720
|
+
if (u < r && d >= r || u >= r && d < r) {
|
|
1721
|
+
var f = l + (r - u) * (h - l) / (d - u);
|
|
1722
|
+
if (f === n)
|
|
1723
|
+
return "on";
|
|
1724
|
+
f > n && (i = !i);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
return i ? "in" : "out";
|
|
1728
|
+
},
|
|
1729
|
+
/**
|
|
1730
|
+
* 旋转点
|
|
1731
|
+
*
|
|
1732
|
+
* @param p1 旋转前点坐标
|
|
1733
|
+
* @param p2 旋转中心坐标
|
|
1734
|
+
* @param θ 旋转角度(顺时针旋转为正)
|
|
1735
|
+
* @returns 旋转后点坐标
|
|
1736
|
+
*/
|
|
1737
|
+
rotatePoint(t, e, n) {
|
|
1738
|
+
const r = (t.x - e.x) * Math.cos(Math.PI / 180 * -n) - (t.y - e.y) * Math.sin(Math.PI / 180 * -n) + e.x, i = (t.x - e.x) * Math.sin(Math.PI / 180 * -n) + (t.y - e.y) * Math.cos(Math.PI / 180 * -n) + e.y;
|
|
1739
|
+
return { x: r, y: i };
|
|
1740
|
+
},
|
|
1741
|
+
/**
|
|
1742
|
+
* 根据两个平面坐标点计算方位角和距离
|
|
1743
|
+
*
|
|
1744
|
+
* @param p1 第一个点的坐标对象
|
|
1745
|
+
* @param p2 第二个点的坐标对象
|
|
1746
|
+
* @returns 返回一个对象,包含angle和distance属性,分别表示两点之间的角度(以度为单位,取值范围为0~359)和距离
|
|
1747
|
+
*/
|
|
1748
|
+
calcBearAndDis(t, e) {
|
|
1749
|
+
const { x: n, y: r } = t, { x: i, y: o } = e, a = i - n, c = o - r, l = Math.sqrt(a * a + c * c);
|
|
1750
|
+
return { angle: (Math.atan2(c, a) * (180 / Math.PI) + 360 + 90) % 360, distance: l };
|
|
1751
|
+
},
|
|
1752
|
+
/**
|
|
1753
|
+
* 根据两个经纬度点计算方位角和距离
|
|
1754
|
+
*
|
|
1755
|
+
* @param latlng1 第一个经纬度点
|
|
1756
|
+
* @param latlng2 第二个经纬度点
|
|
1757
|
+
* @returns 包含方位角和距离的对象
|
|
1758
|
+
*/
|
|
1759
|
+
calcBearAndDisByPoints(t, e) {
|
|
1760
|
+
var n = t.lat * 1, r = t.lng * 1, i = e.lat * 1, o = e.lng * 1, a = Math.sin((o - r) * this.toRadian) * Math.cos(i * this.toRadian), c = Math.cos(n * this.toRadian) * Math.sin(i * this.toRadian) - Math.sin(n * this.toRadian) * Math.cos(i * this.toRadian) * Math.cos((o - r) * this.toRadian), l = Math.atan2(a, c) * (180 / Math.PI), u = (i - n) * this.toRadian, h = (o - r) * this.toRadian, d = Math.sin(u / 2) * Math.sin(u / 2) + Math.cos(n * this.toRadian) * Math.cos(i * this.toRadian) * Math.sin(h / 2) * Math.sin(h / 2), f = 2 * Math.atan2(Math.sqrt(d), Math.sqrt(1 - d)), m = this.R * f;
|
|
1761
|
+
return {
|
|
1762
|
+
angle: l,
|
|
1763
|
+
distance: m
|
|
1764
|
+
};
|
|
1765
|
+
},
|
|
1766
|
+
/**
|
|
1767
|
+
* 计算点P到线段P1P2的最短距离
|
|
1768
|
+
*
|
|
1769
|
+
* @param p 点P的坐标
|
|
1770
|
+
* @param p1 线段起点P1的坐标
|
|
1771
|
+
* @param p2 线段终点P2的坐标
|
|
1772
|
+
* @returns 点P到线段P1P2的最短距离
|
|
1773
|
+
*/
|
|
1774
|
+
distanceToSegment(t, e, n) {
|
|
1775
|
+
const r = t.x, i = t.y, o = e.x, a = e.y, c = n.x, l = n.y, u = (c - o) * (r - o) + (l - a) * (i - a);
|
|
1776
|
+
if (u <= 0)
|
|
1777
|
+
return Math.sqrt((r - o) * (r - o) + (i - a) * (i - a));
|
|
1778
|
+
const h = (c - o) * (c - o) + (l - a) * (l - a);
|
|
1779
|
+
if (u >= h)
|
|
1780
|
+
return Math.sqrt((r - c) * (r - c) + (i - l) * (i - l));
|
|
1781
|
+
const d = u / h, f = o + (c - o) * d, m = a + (l - a) * d;
|
|
1782
|
+
return Math.sqrt((r - f) * (r - f) + (i - m) * (i - m));
|
|
1783
|
+
},
|
|
1784
|
+
/**
|
|
1785
|
+
* 根据给定的经纬度、角度和距离计算新的经纬度点
|
|
1786
|
+
*
|
|
1787
|
+
* @param latlng 给定的经纬度点,类型为LngLat
|
|
1788
|
+
* @param angle 角度值,单位为度,表示从当前点出发的方向
|
|
1789
|
+
* @param distance 距离值,单位为米,表示从当前点出发的距离
|
|
1790
|
+
* @returns 返回计算后的新经纬度点,类型为{lat: number, lng: number}
|
|
1791
|
+
*/
|
|
1792
|
+
calcPointByBearAndDis(t, e, n) {
|
|
1793
|
+
const r = R.toRadians(t.lat * 1), i = R.toRadians(t.lng * 1), o = n / this.R;
|
|
1794
|
+
e = R.toRadians(e);
|
|
1795
|
+
const a = Math.asin(Math.sin(r) * Math.cos(o) + Math.cos(r) * Math.sin(o) * Math.cos(e)), c = i + Math.atan2(Math.sin(e) * Math.sin(o) * Math.cos(r), Math.cos(o) - Math.sin(r) * Math.sin(a));
|
|
1796
|
+
return {
|
|
1797
|
+
lat: R.toDegrees(a),
|
|
1798
|
+
lng: R.toDegrees(c)
|
|
1799
|
+
};
|
|
1800
|
+
},
|
|
1801
|
+
/**
|
|
1802
|
+
* 将墨卡托坐标转换为经纬度坐标
|
|
1803
|
+
*
|
|
1804
|
+
* @param x 墨卡托坐标的x值
|
|
1805
|
+
* @param y 墨卡托坐标的y值
|
|
1806
|
+
* @returns 返回包含转换后的经度lng和纬度lat的对象
|
|
1807
|
+
*/
|
|
1808
|
+
mercatorTolonlat(t, e) {
|
|
1809
|
+
const n = t / 2003750834e-2 * 180;
|
|
1810
|
+
var r = e / 2003750834e-2 * 180;
|
|
1811
|
+
const i = 180 / Math.PI * (2 * Math.atan(Math.exp(r * Math.PI / 180)) - Math.PI / 2);
|
|
1812
|
+
return { lng: n, lat: i };
|
|
1813
|
+
},
|
|
1814
|
+
/**
|
|
1815
|
+
* 将经纬度坐标转换为墨卡托坐标
|
|
1816
|
+
*
|
|
1817
|
+
* @param lng 经度值
|
|
1818
|
+
* @param lat 纬度值
|
|
1819
|
+
* @returns 墨卡托坐标对象,包含x和y属性
|
|
1820
|
+
*/
|
|
1821
|
+
lonlatToMercator(t, e) {
|
|
1822
|
+
var n = 6378137;
|
|
1823
|
+
const r = t * Math.PI / 180 * n;
|
|
1824
|
+
var i = e * Math.PI / 180;
|
|
1825
|
+
const o = n / 2 * Math.log((1 + Math.sin(i)) / (1 - Math.sin(i)));
|
|
1826
|
+
return { x: r, y: o };
|
|
1827
|
+
},
|
|
1828
|
+
/**
|
|
1829
|
+
* 根据百分比获取坐标
|
|
1830
|
+
*
|
|
1831
|
+
* @param start 起点坐标
|
|
1832
|
+
* @param end 终点坐标
|
|
1833
|
+
* @param percent 百分比,取值范围0-1
|
|
1834
|
+
* @returns 返回插值后的坐标
|
|
1835
|
+
*/
|
|
1836
|
+
interpolate({ x: t, y: e, z: n = 0 }, { x: r, y: i, z: o = 0 }, a) {
|
|
1837
|
+
const c = r - t, l = i - e, u = o - n;
|
|
1838
|
+
return { x: t + c * a, y: e + l * a, z: n + u * a };
|
|
1567
1839
|
}
|
|
1568
|
-
},
|
|
1840
|
+
}, et = {
|
|
1569
1841
|
/**
|
|
1570
1842
|
* 将Base64编码的字符串转换为Blob对象
|
|
1571
1843
|
*
|
|
@@ -1574,10 +1846,10 @@ const W = {
|
|
|
1574
1846
|
*/
|
|
1575
1847
|
convertBase64ToBlob(t) {
|
|
1576
1848
|
const e = t.split(",")[0].split(":")[1].split(";")[0], n = atob(t.split(",")[1]), r = new Array(n.length);
|
|
1577
|
-
for (let
|
|
1578
|
-
r[
|
|
1579
|
-
const
|
|
1580
|
-
return new Blob([
|
|
1849
|
+
for (let a = 0; a < n.length; a++)
|
|
1850
|
+
r[a] = n.charCodeAt(a);
|
|
1851
|
+
const i = new Uint8Array(r);
|
|
1852
|
+
return new Blob([i], { type: e });
|
|
1581
1853
|
},
|
|
1582
1854
|
/**
|
|
1583
1855
|
* 将图片的URL转换为Base64编码
|
|
@@ -1587,27 +1859,6 @@ const W = {
|
|
|
1587
1859
|
* @param height 图片的高度,默认为图片原始高度
|
|
1588
1860
|
* @returns 返回Promise对象,解析后得到包含Base64编码数据的对象
|
|
1589
1861
|
*/
|
|
1590
|
-
convertUrlToBase64(t, e, n) {
|
|
1591
|
-
return new Promise((r, s) => {
|
|
1592
|
-
var i = new Image();
|
|
1593
|
-
i.crossOrigin = "Anonymous", i.src = t, i.onload = function() {
|
|
1594
|
-
var o = document.createElement("canvas");
|
|
1595
|
-
o.width = e || i.width, o.height = n || i.height;
|
|
1596
|
-
var a = o.getContext("2d");
|
|
1597
|
-
if (!a) {
|
|
1598
|
-
s(new Error("Failed to get canvas context"));
|
|
1599
|
-
return;
|
|
1600
|
-
}
|
|
1601
|
-
a.drawImage(i, 0, 0, i.width, i.height);
|
|
1602
|
-
var c = i.src.substring(i.src.lastIndexOf(".") + 1).toLowerCase(), h = o.toDataURL("image/" + c), l = {
|
|
1603
|
-
dataURL: h,
|
|
1604
|
-
type: "image/" + c,
|
|
1605
|
-
ext: c
|
|
1606
|
-
};
|
|
1607
|
-
r(l);
|
|
1608
|
-
}, i.onerror = s;
|
|
1609
|
-
});
|
|
1610
|
-
},
|
|
1611
1862
|
/**
|
|
1612
1863
|
* 将base64字符串转换为文件对象
|
|
1613
1864
|
*
|
|
@@ -1616,10 +1867,10 @@ const W = {
|
|
|
1616
1867
|
* @returns 返回文件对象
|
|
1617
1868
|
*/
|
|
1618
1869
|
convertBase64ToFile(t, e) {
|
|
1619
|
-
const n = t.split(","), r = n[0].match(/:(.*?);/),
|
|
1620
|
-
for (let
|
|
1621
|
-
|
|
1622
|
-
return new File([
|
|
1870
|
+
const n = t.split(","), r = n[0].match(/:(.*?);/), i = r ? r[1] : "image/png", o = atob(n[1]), a = new Uint8Array(o.length);
|
|
1871
|
+
for (let l = 0; l < o.length; l++)
|
|
1872
|
+
a[l] = o.charCodeAt(l);
|
|
1873
|
+
return new File([a], e, { type: i });
|
|
1623
1874
|
},
|
|
1624
1875
|
/**
|
|
1625
1876
|
* 从文件下载数据
|
|
@@ -1632,8 +1883,8 @@ const W = {
|
|
|
1632
1883
|
if (t instanceof Blob)
|
|
1633
1884
|
t = URL.createObjectURL(t);
|
|
1634
1885
|
else {
|
|
1635
|
-
const r = JSON.stringify(t),
|
|
1636
|
-
t = window.URL.createObjectURL(
|
|
1886
|
+
const r = JSON.stringify(t), i = new Blob([r], { type: "text/json" });
|
|
1887
|
+
t = window.URL.createObjectURL(i);
|
|
1637
1888
|
}
|
|
1638
1889
|
else if (typeof t == "string" && t.indexOf("http") === -1) {
|
|
1639
1890
|
const r = new Blob([t], { type: "text/json" });
|
|
@@ -1642,7 +1893,7 @@ const W = {
|
|
|
1642
1893
|
var n = document.createElement("a");
|
|
1643
1894
|
n.href = t, n.download = e || "", n.click(), window.URL.revokeObjectURL(n.href);
|
|
1644
1895
|
}
|
|
1645
|
-
},
|
|
1896
|
+
}, nt = {
|
|
1646
1897
|
/**
|
|
1647
1898
|
* 防抖函数,在指定的等待时间内,如果连续触发事件,则只在最后一次触发后执行函数。适用于像搜索输入框这种需要用户停止输入后才调用的场景
|
|
1648
1899
|
*
|
|
@@ -1652,15 +1903,15 @@ const W = {
|
|
|
1652
1903
|
* @returns 返回防抖后的函数。
|
|
1653
1904
|
*/
|
|
1654
1905
|
debounce(t, e, n = !0) {
|
|
1655
|
-
let r = null,
|
|
1656
|
-
const
|
|
1657
|
-
const
|
|
1658
|
-
|
|
1906
|
+
let r = null, i, o, a;
|
|
1907
|
+
const c = () => {
|
|
1908
|
+
const l = Date.now() - o;
|
|
1909
|
+
l < e && l > 0 ? r = setTimeout(c, e - l) : (r = null, n || (a = t.apply(this, i)));
|
|
1659
1910
|
};
|
|
1660
|
-
return (...
|
|
1661
|
-
|
|
1662
|
-
const
|
|
1663
|
-
return r || (r = setTimeout(
|
|
1911
|
+
return (...l) => {
|
|
1912
|
+
o = Date.now();
|
|
1913
|
+
const u = n && !r;
|
|
1914
|
+
return r || (r = setTimeout(c, e)), u && (a = t.apply(this, l), r || (l = null)), a;
|
|
1664
1915
|
};
|
|
1665
1916
|
},
|
|
1666
1917
|
/**
|
|
@@ -1672,13 +1923,13 @@ const W = {
|
|
|
1672
1923
|
* @returns 返回一个新的函数,该函数在节流控制下执行传入的函数
|
|
1673
1924
|
*/
|
|
1674
1925
|
throttle(t, e, n = 1) {
|
|
1675
|
-
let r = 0,
|
|
1676
|
-
return (...
|
|
1926
|
+
let r = 0, i = null;
|
|
1927
|
+
return (...o) => {
|
|
1677
1928
|
if (n === 1) {
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1680
|
-
} else n === 2 && (
|
|
1681
|
-
|
|
1929
|
+
const a = Date.now();
|
|
1930
|
+
a - r >= e && (t.apply(this, o), r = a);
|
|
1931
|
+
} else n === 2 && (i || (i = setTimeout(() => {
|
|
1932
|
+
i = null, t.apply(this, o);
|
|
1682
1933
|
}, e)));
|
|
1683
1934
|
};
|
|
1684
1935
|
},
|
|
@@ -1695,8 +1946,8 @@ const W = {
|
|
|
1695
1946
|
if (e.has(r))
|
|
1696
1947
|
return e.get(r);
|
|
1697
1948
|
{
|
|
1698
|
-
const
|
|
1699
|
-
return e.set(r,
|
|
1949
|
+
const i = t.apply(this, n);
|
|
1950
|
+
return e.set(r, i), i;
|
|
1700
1951
|
}
|
|
1701
1952
|
};
|
|
1702
1953
|
},
|
|
@@ -1713,7 +1964,7 @@ const W = {
|
|
|
1713
1964
|
r++, r < Math.floor(n / e) && (t.call(this), setTimeout(this.recurve.bind(this, t, e, n), e));
|
|
1714
1965
|
}, e);
|
|
1715
1966
|
}
|
|
1716
|
-
},
|
|
1967
|
+
}, st = {
|
|
1717
1968
|
/**
|
|
1718
1969
|
* 校验字符串是否符合指定类型
|
|
1719
1970
|
*
|
|
@@ -1829,7 +2080,7 @@ const W = {
|
|
|
1829
2080
|
default:
|
|
1830
2081
|
return n || "";
|
|
1831
2082
|
}
|
|
1832
|
-
}), t.reduce((n, r,
|
|
2083
|
+
}), t.reduce((n, r, i) => `${n}${e[i - 1]}${r}`);
|
|
1833
2084
|
},
|
|
1834
2085
|
/**
|
|
1835
2086
|
* 计算字符串的字节长度
|
|
@@ -1852,10 +2103,10 @@ const W = {
|
|
|
1852
2103
|
var r = /[^\x00-\xff]/g;
|
|
1853
2104
|
if (t.replace(r, "mm").length <= n)
|
|
1854
2105
|
return t;
|
|
1855
|
-
for (var
|
|
1856
|
-
let
|
|
1857
|
-
if (
|
|
1858
|
-
return
|
|
2106
|
+
for (var i = Math.floor(n / 2), o = i; o < t.length; o++) {
|
|
2107
|
+
let a = t.substring(e, o);
|
|
2108
|
+
if (a.replace(r, "mm").length >= n)
|
|
2109
|
+
return a;
|
|
1859
2110
|
}
|
|
1860
2111
|
return t;
|
|
1861
2112
|
},
|
|
@@ -1883,62 +2134,62 @@ const W = {
|
|
|
1883
2134
|
t = t.replace(e, n);
|
|
1884
2135
|
return t;
|
|
1885
2136
|
}
|
|
1886
|
-
},
|
|
2137
|
+
}, p = class p {
|
|
1887
2138
|
static set(e, n = null, r = null) {
|
|
1888
|
-
var
|
|
2139
|
+
var i = this._getPrefixedKey(e, r);
|
|
1889
2140
|
try {
|
|
1890
|
-
localStorage.setItem(
|
|
2141
|
+
localStorage.setItem(i, JSON.stringify({ data: n }));
|
|
1891
2142
|
} catch {
|
|
1892
2143
|
console && console.warn("StoreUtil didn't successfully save the '{" + e + ": " + n + "}' pair, because the localStorage is full.");
|
|
1893
2144
|
}
|
|
1894
2145
|
}
|
|
1895
2146
|
static get(e, n, r) {
|
|
1896
|
-
var
|
|
2147
|
+
var i = this._getPrefixedKey(e, r), o;
|
|
1897
2148
|
try {
|
|
1898
|
-
|
|
2149
|
+
o = JSON.parse(localStorage.getItem(i) || "");
|
|
1899
2150
|
} catch {
|
|
1900
|
-
localStorage[
|
|
2151
|
+
localStorage[i] ? o = { data: localStorage.getItem(i) } : o = null;
|
|
1901
2152
|
}
|
|
1902
|
-
if (
|
|
1903
|
-
if (typeof
|
|
1904
|
-
return
|
|
2153
|
+
if (o) {
|
|
2154
|
+
if (typeof o == "object" && typeof o.data < "u")
|
|
2155
|
+
return o.data;
|
|
1905
2156
|
} else return n;
|
|
1906
2157
|
}
|
|
1907
2158
|
static keys() {
|
|
1908
2159
|
const e = [];
|
|
1909
2160
|
var n = Object.keys(localStorage);
|
|
1910
|
-
return
|
|
1911
|
-
r.indexOf(
|
|
2161
|
+
return p.prefix.length === 0 ? n : (n.forEach(function(r) {
|
|
2162
|
+
r.indexOf(p.prefix) !== -1 && e.push(r.replace(p.prefix, ""));
|
|
1912
2163
|
}), e);
|
|
1913
2164
|
}
|
|
1914
2165
|
static getAll(e) {
|
|
1915
|
-
var n =
|
|
2166
|
+
var n = p.keys();
|
|
1916
2167
|
if (e) {
|
|
1917
2168
|
const r = [];
|
|
1918
|
-
return n.forEach((
|
|
1919
|
-
if (e.includes(
|
|
1920
|
-
const
|
|
1921
|
-
i
|
|
2169
|
+
return n.forEach((i) => {
|
|
2170
|
+
if (e.includes(i)) {
|
|
2171
|
+
const o = {};
|
|
2172
|
+
o[i] = p.get(i, null, null), r.push(o);
|
|
1922
2173
|
}
|
|
1923
2174
|
}), r;
|
|
1924
2175
|
}
|
|
1925
|
-
return n.map((r) =>
|
|
2176
|
+
return n.map((r) => p.get(r, null, null));
|
|
1926
2177
|
}
|
|
1927
2178
|
static remove(e, n) {
|
|
1928
2179
|
var r = this._getPrefixedKey(e, n);
|
|
1929
2180
|
localStorage.removeItem(r);
|
|
1930
2181
|
}
|
|
1931
2182
|
static clear(e) {
|
|
1932
|
-
|
|
2183
|
+
p.prefix.length ? this.keys().forEach((n) => {
|
|
1933
2184
|
localStorage.removeItem(this._getPrefixedKey(n, e));
|
|
1934
2185
|
}) : localStorage.clear();
|
|
1935
2186
|
}
|
|
1936
2187
|
};
|
|
1937
|
-
|
|
1938
|
-
return n = n || {}, n.noPrefix ? e :
|
|
2188
|
+
g(p, "prefix", ""), g(p, "_getPrefixedKey", function(e, n) {
|
|
2189
|
+
return n = n || {}, n.noPrefix ? e : p.prefix + e;
|
|
1939
2190
|
});
|
|
1940
|
-
let
|
|
1941
|
-
const
|
|
2191
|
+
let I = p;
|
|
2192
|
+
const rt = {
|
|
1942
2193
|
/**
|
|
1943
2194
|
* 将json对象转换为查询字符串
|
|
1944
2195
|
*
|
|
@@ -1949,11 +2200,11 @@ const Q = {
|
|
|
1949
2200
|
var e = [];
|
|
1950
2201
|
for (var n in t)
|
|
1951
2202
|
if (t.hasOwnProperty(n)) {
|
|
1952
|
-
var r = n,
|
|
1953
|
-
e.push(encodeURIComponent(r) + "=" + encodeURIComponent(
|
|
2203
|
+
var r = n, i = t[n];
|
|
2204
|
+
e.push(encodeURIComponent(r) + "=" + encodeURIComponent(i));
|
|
1954
2205
|
}
|
|
1955
|
-
var
|
|
1956
|
-
return
|
|
2206
|
+
var o = e.join("&");
|
|
2207
|
+
return o;
|
|
1957
2208
|
},
|
|
1958
2209
|
/**
|
|
1959
2210
|
* 从 URL 中解析出查询参数和哈希参数,并以对象的形式返回
|
|
@@ -1963,50 +2214,53 @@ const Q = {
|
|
|
1963
2214
|
* @returns 返回一个包含解析后参数的对象,其中键为参数名,值为参数值
|
|
1964
2215
|
*/
|
|
1965
2216
|
query2Json(t = window.location.href, e = !0) {
|
|
1966
|
-
const n = /([^&=]+)=([\w\W]*?)(&|$|#)/g, { search: r, hash:
|
|
1967
|
-
let
|
|
1968
|
-
for (let
|
|
1969
|
-
const
|
|
1970
|
-
if (
|
|
1971
|
-
const
|
|
1972
|
-
if (
|
|
1973
|
-
for (let
|
|
2217
|
+
const n = /([^&=]+)=([\w\W]*?)(&|$|#)/g, { search: r, hash: i } = new URL(t), o = [r, i];
|
|
2218
|
+
let a = {};
|
|
2219
|
+
for (let c = 0; c < o.length; c++) {
|
|
2220
|
+
const l = o[c];
|
|
2221
|
+
if (l) {
|
|
2222
|
+
const h = l.replace(/#|\//g, "").split("?");
|
|
2223
|
+
if (h.length > 1)
|
|
2224
|
+
for (let d = 1; d < h.length; d++) {
|
|
1974
2225
|
let f;
|
|
1975
|
-
for (; f = n.exec(
|
|
1976
|
-
|
|
2226
|
+
for (; f = n.exec(h[d]); )
|
|
2227
|
+
a[f[1]] = e ? decodeURIComponent(f[2]) : f[2];
|
|
1977
2228
|
}
|
|
1978
2229
|
}
|
|
1979
2230
|
}
|
|
1980
|
-
return
|
|
2231
|
+
return a;
|
|
1981
2232
|
}
|
|
1982
2233
|
};
|
|
1983
2234
|
export {
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2235
|
+
E as AjaxUtil,
|
|
2236
|
+
S as ArrayUtil,
|
|
2237
|
+
H as AudioPlayer,
|
|
2238
|
+
Q as BrowserUtil,
|
|
2239
|
+
j as CanvasDrawer,
|
|
2240
|
+
z as ColorUtil,
|
|
2241
|
+
K as Cookie,
|
|
2242
|
+
Y as CoordsUtil,
|
|
2243
|
+
X as DateUtil,
|
|
2244
|
+
V as DomUtil,
|
|
2245
|
+
b as ErrorType,
|
|
2246
|
+
_ as EventDispatcher,
|
|
2247
|
+
y as EventType,
|
|
2248
|
+
et as FileUtil,
|
|
2249
|
+
Z as GeoJsonUtil,
|
|
2250
|
+
tt as GeoUtil,
|
|
2251
|
+
k as GraphicType,
|
|
2252
|
+
C as HashMap,
|
|
2253
|
+
$ as ImageUtil,
|
|
2254
|
+
N as LayerType,
|
|
2255
|
+
R as MathUtil,
|
|
2256
|
+
F as MeasureMode,
|
|
2257
|
+
O as MqttClient,
|
|
2258
|
+
B as ObjectState,
|
|
2259
|
+
T as ObjectUtil,
|
|
2260
|
+
nt as OptimizeUtil,
|
|
2261
|
+
I as StoreUtil,
|
|
2262
|
+
st as StringUtil,
|
|
2263
|
+
rt as UrlUtil,
|
|
2010
2264
|
M as Util,
|
|
2011
|
-
|
|
2265
|
+
W as WebSocketClient
|
|
2012
2266
|
};
|