gis-common 4.1.7 → 4.1.8
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/gis-common.es.js +617 -457
- 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/CommUtil.d.ts +1 -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 +1 -1
package/dist/gis-common.es.js
CHANGED
|
@@ -1,83 +1,8 @@
|
|
|
1
1
|
var D = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var d = (t, e, n) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
MAP_READY: "mapReady",
|
|
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 {
|
|
2
|
+
var O = (t, e, n) => e in t ? D(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var d = (t, e, n) => O(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
var R = /* @__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))(R || {}), C = /* @__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))(C || {}), I = /* @__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))(I || {}), _ = /* @__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))(_ || {}), P = /* @__PURE__ */ ((t) => (t.DISTANCE = "distance", t.AREA = "area", t.HEIGHT = "height", t))(P || {}), L = /* @__PURE__ */ ((t) => (t.ADD = "add", t.REMOVE = "remove", t.INIT = "init", t))(L || {});
|
|
5
|
+
class F {
|
|
81
6
|
constructor(e) {
|
|
82
7
|
/**
|
|
83
8
|
* Creates an instance of AudioPlayer.
|
|
@@ -173,7 +98,7 @@ const m = {
|
|
|
173
98
|
return Math.max(Math.min(t, n), e);
|
|
174
99
|
}
|
|
175
100
|
};
|
|
176
|
-
class
|
|
101
|
+
class B {
|
|
177
102
|
constructor(e) {
|
|
178
103
|
d(this, "context", null);
|
|
179
104
|
if (typeof e == "string" && (e = document.querySelector("#" + e), !e))
|
|
@@ -199,8 +124,8 @@ class C {
|
|
|
199
124
|
if (!this.context)
|
|
200
125
|
throw new Error("Canvas context is null or undefined");
|
|
201
126
|
this.context.beginPath();
|
|
202
|
-
const
|
|
203
|
-
this.context.lineWidth =
|
|
127
|
+
const a = i.width || 1, o = i.color || "#000";
|
|
128
|
+
this.context.lineWidth = a, this.context.strokeStyle = o, this.context.moveTo(e, n), this.context.lineTo(r, s), this.context.stroke();
|
|
204
129
|
}
|
|
205
130
|
/**
|
|
206
131
|
* 绘制圆弧
|
|
@@ -215,10 +140,10 @@ class C {
|
|
|
215
140
|
* @param bgColor 背景颜色
|
|
216
141
|
* @throws 当Canvas context为null或undefined时抛出错误
|
|
217
142
|
*/
|
|
218
|
-
drawArc({ x: e, y: n }, r, s, i,
|
|
143
|
+
drawArc({ x: e, y: n }, r, s, i, a, o, l) {
|
|
219
144
|
if (!this.context)
|
|
220
145
|
throw new Error("Canvas context is null or undefined");
|
|
221
|
-
|
|
146
|
+
o ? (this.context.fillStyle = l, this.context.beginPath(), this.context.arc(e, n, r, m.degreesToRadians(s), m.degreesToRadians(i), a), this.context.fill()) : (this.context.strokeStyle = l, this.context.beginPath(), this.context.arc(e, n, r, m.degreesToRadians(s), m.degreesToRadians(i), a), this.context.stroke());
|
|
222
147
|
}
|
|
223
148
|
static createCanvas(e = 1, n = 1) {
|
|
224
149
|
let r;
|
|
@@ -226,8 +151,7 @@ class C {
|
|
|
226
151
|
return r = document.createElement("canvas"), e && (r.width = e), n && (r.height = n), r;
|
|
227
152
|
}
|
|
228
153
|
}
|
|
229
|
-
|
|
230
|
-
class T {
|
|
154
|
+
class v {
|
|
231
155
|
constructor() {
|
|
232
156
|
d(this, "_listeners");
|
|
233
157
|
d(this, "_mutex", {});
|
|
@@ -235,8 +159,8 @@ class T {
|
|
|
235
159
|
}
|
|
236
160
|
addEventListener(e, n, r, s = !1) {
|
|
237
161
|
this._listeners === void 0 && (this._listeners = {}), this._context = r;
|
|
238
|
-
const i = this._mutex,
|
|
239
|
-
return
|
|
162
|
+
const i = this._mutex, a = this._listeners;
|
|
163
|
+
return a[e] === void 0 && (a[e] = []), a[e].indexOf(n) === -1 && (s && (i[e] = n), a[e].push(n)), this;
|
|
240
164
|
}
|
|
241
165
|
hasEventListener(e, n) {
|
|
242
166
|
if (this._listeners === null || this._listeners === void 0) return !1;
|
|
@@ -247,7 +171,7 @@ class T {
|
|
|
247
171
|
if (this._listeners === void 0) return;
|
|
248
172
|
const s = this._listeners[e];
|
|
249
173
|
if (this._mutex[e] === n && (this._mutex[e] = null), s !== void 0) {
|
|
250
|
-
const i = s.map((
|
|
174
|
+
const i = s.map((a) => a.toString()).indexOf(n.toString());
|
|
251
175
|
i !== -1 && s.splice(i, 1);
|
|
252
176
|
}
|
|
253
177
|
}
|
|
@@ -258,15 +182,15 @@ class T {
|
|
|
258
182
|
e.target = this;
|
|
259
183
|
const s = r.slice(0);
|
|
260
184
|
if (this._mutex[e.type] !== void 0) {
|
|
261
|
-
const i = s.find((
|
|
185
|
+
const i = s.find((a) => a === this._mutex[e.type]);
|
|
262
186
|
if (i) {
|
|
263
187
|
i.call(this._context || this, e);
|
|
264
188
|
return;
|
|
265
189
|
}
|
|
266
190
|
}
|
|
267
|
-
for (let i = 0,
|
|
268
|
-
const
|
|
269
|
-
typeof
|
|
191
|
+
for (let i = 0, a = s.length; i < a; i++) {
|
|
192
|
+
const o = s[i];
|
|
193
|
+
typeof o == "function" && o.call(this._context || this, e);
|
|
270
194
|
}
|
|
271
195
|
}
|
|
272
196
|
}
|
|
@@ -276,7 +200,7 @@ class T {
|
|
|
276
200
|
this._listeners[e] = [];
|
|
277
201
|
}
|
|
278
202
|
}
|
|
279
|
-
class
|
|
203
|
+
class x extends Map {
|
|
280
204
|
isEmpty() {
|
|
281
205
|
return this.size === 0;
|
|
282
206
|
}
|
|
@@ -292,13 +216,13 @@ class A extends Map {
|
|
|
292
216
|
fromEntries() {
|
|
293
217
|
}
|
|
294
218
|
}
|
|
295
|
-
|
|
296
|
-
const e = new
|
|
219
|
+
x.prototype.fromEntries = function(t = []) {
|
|
220
|
+
const e = new x();
|
|
297
221
|
return t.forEach((n) => {
|
|
298
222
|
Array.isArray(n) && n.length === 2 && e.set(n[0], n[1]);
|
|
299
223
|
}), e;
|
|
300
224
|
};
|
|
301
|
-
class
|
|
225
|
+
class $ extends v {
|
|
302
226
|
constructor(n = "ws://127.0.0.1:10088") {
|
|
303
227
|
super();
|
|
304
228
|
d(this, "maxCheckTimes", 10);
|
|
@@ -361,7 +285,7 @@ class U extends T {
|
|
|
361
285
|
}, 1e3);
|
|
362
286
|
}
|
|
363
287
|
}
|
|
364
|
-
const
|
|
288
|
+
const y = {
|
|
365
289
|
/**
|
|
366
290
|
* 获取数据类型
|
|
367
291
|
*
|
|
@@ -453,12 +377,12 @@ const M = {
|
|
|
453
377
|
*/
|
|
454
378
|
convertToTree2(t, e = "id", n = "parentId", r = "children") {
|
|
455
379
|
const s = [];
|
|
456
|
-
function i(
|
|
457
|
-
const
|
|
458
|
-
|
|
380
|
+
function i(a) {
|
|
381
|
+
const o = t.filter((l) => l[n] === a[e]).map((l) => (s.some((h) => h[e] === l[e]) || i(l), l));
|
|
382
|
+
o.length > 0 && (a[r] = o);
|
|
459
383
|
}
|
|
460
|
-
return t.forEach((
|
|
461
|
-
t.some((
|
|
384
|
+
return t.forEach((a) => {
|
|
385
|
+
t.some((o) => o[n] === a[e]) || (i(a), s.push(a));
|
|
462
386
|
}), s;
|
|
463
387
|
},
|
|
464
388
|
/**
|
|
@@ -509,7 +433,7 @@ const M = {
|
|
|
509
433
|
return t.replace(n, (r, s) => {
|
|
510
434
|
const i = e[s];
|
|
511
435
|
if (i === void 0)
|
|
512
|
-
throw new Error(`${
|
|
436
|
+
throw new Error(`${C.JSON_VALUE_ERROR}: ${r}`);
|
|
513
437
|
return typeof i == "function" ? i(e) : i;
|
|
514
438
|
});
|
|
515
439
|
},
|
|
@@ -565,6 +489,259 @@ const M = {
|
|
|
565
489
|
},
|
|
566
490
|
isNumber(t) {
|
|
567
491
|
return typeof t == "number" && !isNaN(t) || typeof t == "string" && Number.isFinite(+t);
|
|
492
|
+
},
|
|
493
|
+
isFunction(t) {
|
|
494
|
+
return this.isNil(t) ? !1 : typeof t == "function" || t.constructor !== null && t.constructor === Function;
|
|
495
|
+
}
|
|
496
|
+
}, T = {
|
|
497
|
+
deepClone(t) {
|
|
498
|
+
return structuredClone(t);
|
|
499
|
+
},
|
|
500
|
+
isEqual(t, e) {
|
|
501
|
+
return JSON.stringify(t) === JSON.stringify(e);
|
|
502
|
+
},
|
|
503
|
+
parse(t) {
|
|
504
|
+
return !t || typeof t != "string" ? t : JSON.parse(t);
|
|
505
|
+
}
|
|
506
|
+
}, k = {
|
|
507
|
+
emptyImageUrl: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
|
|
508
|
+
/**
|
|
509
|
+
*
|
|
510
|
+
* @param image image,类型可以是HTMLCanvasElement、ImageData
|
|
511
|
+
* @returns
|
|
512
|
+
*/
|
|
513
|
+
getURL(t) {
|
|
514
|
+
let e;
|
|
515
|
+
if (/^data:/i.test(t.src) || typeof HTMLCanvasElement > "u")
|
|
516
|
+
return t.src;
|
|
517
|
+
let n;
|
|
518
|
+
if (t instanceof HTMLCanvasElement)
|
|
519
|
+
n = t;
|
|
520
|
+
else {
|
|
521
|
+
e === void 0 && (e = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas")), e.width = t.width, e.height = t.height;
|
|
522
|
+
const r = e.getContext("2d");
|
|
523
|
+
r && (t instanceof ImageData ? r.putImageData(t, 0, 0) : r.drawImage(t, 0, 0, t.width, t.height)), n = e;
|
|
524
|
+
}
|
|
525
|
+
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");
|
|
526
|
+
},
|
|
527
|
+
/**
|
|
528
|
+
* 将图片的URL转换为Base64编码
|
|
529
|
+
*
|
|
530
|
+
* @param url 图片的URL地址
|
|
531
|
+
* @param width 图片的宽度,默认为图片原始宽度
|
|
532
|
+
* @param height 图片的高度,默认为图片原始高度
|
|
533
|
+
* @returns 返回Promise对象,解析后得到包含Base64编码数据的对象
|
|
534
|
+
*/
|
|
535
|
+
getBase64(t) {
|
|
536
|
+
return new Promise((e, n) => {
|
|
537
|
+
let r = new Image();
|
|
538
|
+
r.setAttribute("crossOrigin", "Anonymous"), r.src = t, r.onload = () => {
|
|
539
|
+
let s = this.getURL(r);
|
|
540
|
+
e(s);
|
|
541
|
+
}, r.onerror = n;
|
|
542
|
+
});
|
|
543
|
+
},
|
|
544
|
+
/**
|
|
545
|
+
* 解析base64编码
|
|
546
|
+
*
|
|
547
|
+
* @param base64 base64编码字符串
|
|
548
|
+
* @returns 返回一个对象,包含type(类型)、ext(扩展名)和data(数据)字段,如果解析失败则返回null
|
|
549
|
+
*/
|
|
550
|
+
parseBase64(t) {
|
|
551
|
+
let n = new RegExp("data:(?<type>.*?);base64,(?<data>.*)").exec(t);
|
|
552
|
+
return n && n.groups ? {
|
|
553
|
+
type: n.groups.type,
|
|
554
|
+
ext: n.groups.type.split("/").slice(-1)[0],
|
|
555
|
+
data: n.groups.data
|
|
556
|
+
} : null;
|
|
557
|
+
},
|
|
558
|
+
/**
|
|
559
|
+
* 复制图片到剪贴板
|
|
560
|
+
*
|
|
561
|
+
* @param url 图片的URL地址
|
|
562
|
+
* @returns 无返回值
|
|
563
|
+
* @throws 如果解析base64数据失败,则抛出异常
|
|
564
|
+
*/
|
|
565
|
+
async copyImage(t) {
|
|
566
|
+
try {
|
|
567
|
+
const e = await this.getBase64(t), n = this.parseBase64(e.dataURL);
|
|
568
|
+
if (!n)
|
|
569
|
+
throw new Error("Failed to parse base64 data.");
|
|
570
|
+
let r = n.type, s = atob(n.data), i = new ArrayBuffer(s.length), a = new Uint8Array(i);
|
|
571
|
+
for (let l = 0; l < s.length; l++)
|
|
572
|
+
a[l] = s.charCodeAt(l);
|
|
573
|
+
let o = new Blob([i], { type: r });
|
|
574
|
+
await navigator.clipboard.write([new ClipboardItem({ [r]: o })]);
|
|
575
|
+
} catch (e) {
|
|
576
|
+
console.error("Failed to copy image to clipboard:", e);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}, w = {
|
|
580
|
+
/**
|
|
581
|
+
* Get JSON data by jsonp
|
|
582
|
+
* @param url - resource url
|
|
583
|
+
* @param callback - callback function when completed
|
|
584
|
+
*/
|
|
585
|
+
jsonp(t, e) {
|
|
586
|
+
const n = "_jsonp_" + y.guid(), r = document.getElementsByTagName("head")[0];
|
|
587
|
+
t.includes("?") ? t += "&callback=" + n : t += "?callback=" + n;
|
|
588
|
+
let s = document.createElement("script");
|
|
589
|
+
s.type = "text/javascript", s.src = t, window[n] = function(i) {
|
|
590
|
+
e(null, i), r.removeChild(s), s = null, delete window[n];
|
|
591
|
+
}, r.appendChild(s);
|
|
592
|
+
},
|
|
593
|
+
/**
|
|
594
|
+
* Fetch remote resource by HTTP "GET" method
|
|
595
|
+
* @param {String} url - resource url
|
|
596
|
+
* @param {Object} [options=null] - request options
|
|
597
|
+
* @param {Object} [options.headers=null] - HTTP headers
|
|
598
|
+
* @param {String} [options.responseType=null] - responseType
|
|
599
|
+
* @param {String} [options.credentials=null] - if with credentials, set it to "include"
|
|
600
|
+
* @param {Function} cb - callback function when completed
|
|
601
|
+
* @return {Ajax} Ajax
|
|
602
|
+
* @example
|
|
603
|
+
* AjaxUtil.get(
|
|
604
|
+
* 'url/to/resource',
|
|
605
|
+
* (err, data) => {
|
|
606
|
+
* if (err) {
|
|
607
|
+
* throw new Error(err);
|
|
608
|
+
* }
|
|
609
|
+
* // do things with data
|
|
610
|
+
* }
|
|
611
|
+
* );
|
|
612
|
+
*/
|
|
613
|
+
get(t, e, n) {
|
|
614
|
+
if (y.isFunction(e)) {
|
|
615
|
+
const s = n;
|
|
616
|
+
n = e, e = s;
|
|
617
|
+
}
|
|
618
|
+
const r = w._getClient(n);
|
|
619
|
+
if (r.open("GET", t, !0), e) {
|
|
620
|
+
for (const s in e.headers)
|
|
621
|
+
r.setRequestHeader(s, e.headers[s]);
|
|
622
|
+
r.withCredentials = e.credentials === "include", e.responseType && (r.responseType = e.responseType);
|
|
623
|
+
}
|
|
624
|
+
return r.send(null), r;
|
|
625
|
+
},
|
|
626
|
+
/**
|
|
627
|
+
* Fetch remote resource by HTTP "POST" method
|
|
628
|
+
* @param {String} url - resource url
|
|
629
|
+
* @param {Object} options - request options
|
|
630
|
+
* @param {String|Object} options.postData - post data
|
|
631
|
+
* @param {Object} [options.headers=null] - HTTP headers
|
|
632
|
+
* @param {Function} cb - callback function when completed
|
|
633
|
+
* @return {Ajax} Ajax
|
|
634
|
+
* @example
|
|
635
|
+
* AjaxUtil.post(
|
|
636
|
+
* 'url/to/post',
|
|
637
|
+
* {
|
|
638
|
+
* postData : {
|
|
639
|
+
* 'param0' : 'val0',
|
|
640
|
+
* 'param1' : 1
|
|
641
|
+
* }
|
|
642
|
+
* },
|
|
643
|
+
* (err, data) => {
|
|
644
|
+
* if (err) {
|
|
645
|
+
* throw new Error(err);
|
|
646
|
+
* }
|
|
647
|
+
* // do things with data
|
|
648
|
+
* }
|
|
649
|
+
* );
|
|
650
|
+
*/
|
|
651
|
+
post(t, e = {}, n) {
|
|
652
|
+
let r;
|
|
653
|
+
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)
|
|
654
|
+
throw new Error("Callback function is required");
|
|
655
|
+
const s = w._getClient(n);
|
|
656
|
+
return s.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((i) => {
|
|
657
|
+
s.setRequestHeader(i, e.headers[i]);
|
|
658
|
+
}), typeof r != "string" && (r = JSON.stringify(r)), s.send(r), s;
|
|
659
|
+
},
|
|
660
|
+
_wrapCallback(t, e) {
|
|
661
|
+
return function() {
|
|
662
|
+
t.readyState === 4 && (t.status === 200 ? t.responseType === "arraybuffer" ? t.response.byteLength === 0 ? e(new Error("http status 200 returned without content.")) : e(null, {
|
|
663
|
+
data: t.response,
|
|
664
|
+
cacheControl: t.getResponseHeader("Cache-Control"),
|
|
665
|
+
expires: t.getResponseHeader("Expires"),
|
|
666
|
+
contentType: t.getResponseHeader("Content-Type")
|
|
667
|
+
}) : e(null, t.responseText) : e(new Error(t.statusText + "," + t.status)));
|
|
668
|
+
};
|
|
669
|
+
},
|
|
670
|
+
_getClient(t) {
|
|
671
|
+
let e = null;
|
|
672
|
+
try {
|
|
673
|
+
e = new XMLHttpRequest();
|
|
674
|
+
} catch {
|
|
675
|
+
throw new Error("XMLHttpRequest not supported.");
|
|
676
|
+
}
|
|
677
|
+
return e && (e.onreadystatechange = w._wrapCallback(e, t)), e;
|
|
678
|
+
},
|
|
679
|
+
/**
|
|
680
|
+
* Fetch resource as arraybuffer.
|
|
681
|
+
* @param {String} url - url
|
|
682
|
+
* @param {Object} [options=null] - options, same as Ajax.get
|
|
683
|
+
* @param {Function} cb - callback function when completed.
|
|
684
|
+
* @example
|
|
685
|
+
* AjaxUtil.getArrayBuffer(
|
|
686
|
+
* 'url/to/resource.bin',
|
|
687
|
+
* (err, data) => {
|
|
688
|
+
* if (err) {
|
|
689
|
+
* throw new Error(err);
|
|
690
|
+
* }
|
|
691
|
+
* // data is a binary array
|
|
692
|
+
* }
|
|
693
|
+
* );
|
|
694
|
+
*/
|
|
695
|
+
getArrayBuffer(t, e, n) {
|
|
696
|
+
if (y.isFunction(e)) {
|
|
697
|
+
const r = n;
|
|
698
|
+
n = e, e = r;
|
|
699
|
+
}
|
|
700
|
+
return e || (e = {}), e.responseType = "arraybuffer", w.get(t, e, n);
|
|
701
|
+
},
|
|
702
|
+
getImage(t, e, n) {
|
|
703
|
+
return w.getArrayBuffer(e, n, (r, s) => {
|
|
704
|
+
if (r)
|
|
705
|
+
t.onerror && t.onerror(r);
|
|
706
|
+
else if (s) {
|
|
707
|
+
const i = window.URL || window.webkitURL, a = t.onload;
|
|
708
|
+
t.onload = () => {
|
|
709
|
+
a && a(), i.revokeObjectURL(t.src);
|
|
710
|
+
};
|
|
711
|
+
const o = new Blob([new Uint8Array(s.data)], { type: s.contentType });
|
|
712
|
+
t.cacheControl = s.cacheControl, t.expires = s.expires, t.src = s.data.byteLength ? i.createObjectURL(o) : k.emptyImageUrl;
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
},
|
|
716
|
+
/**
|
|
717
|
+
* Fetch resource as a JSON Object.
|
|
718
|
+
* @param {String} url - json's url
|
|
719
|
+
* @param {Object} [options=null] - optional options
|
|
720
|
+
* @param {String} [options.jsonp=false] - fetch by jsonp, false by default
|
|
721
|
+
* @param {Function} cb - callback function when completed.
|
|
722
|
+
* @example
|
|
723
|
+
* AjaxUtil.getJSON(
|
|
724
|
+
* 'url/to/resource.json',
|
|
725
|
+
* { jsonp : true },
|
|
726
|
+
* (err, json) => {
|
|
727
|
+
* if (err) {
|
|
728
|
+
* throw new Error(err);
|
|
729
|
+
* }
|
|
730
|
+
* // json is a JSON Object
|
|
731
|
+
* console.log(json.foo);
|
|
732
|
+
* }
|
|
733
|
+
* );
|
|
734
|
+
*/
|
|
735
|
+
getJSON(t, e, n) {
|
|
736
|
+
if (y.isFunction(e)) {
|
|
737
|
+
const s = n;
|
|
738
|
+
n = e, e = s;
|
|
739
|
+
}
|
|
740
|
+
const r = function(s, i) {
|
|
741
|
+
const a = i ? T.parse(i) : null;
|
|
742
|
+
n && n(s, a);
|
|
743
|
+
};
|
|
744
|
+
return e && e.jsonp ? w.jsonp(t, r) : w.get(t, e, r);
|
|
568
745
|
}
|
|
569
746
|
};
|
|
570
747
|
Array.prototype.groupBy = function(t) {
|
|
@@ -606,9 +783,9 @@ Array.prototype.remove = function(t) {
|
|
|
606
783
|
Array.prototype.clear = function() {
|
|
607
784
|
return this.length = 0, this;
|
|
608
785
|
};
|
|
609
|
-
const
|
|
786
|
+
const G = {
|
|
610
787
|
asArray(t) {
|
|
611
|
-
return
|
|
788
|
+
return y.isEmpty(t) ? [] : Array.isArray(t) ? t : [t];
|
|
612
789
|
},
|
|
613
790
|
/**
|
|
614
791
|
* 创建指定长度的数组,并返回其索引数组
|
|
@@ -661,7 +838,7 @@ const F = {
|
|
|
661
838
|
difference(...t) {
|
|
662
839
|
return this.union(...t).filter((e) => !this.intersection(...t).includes(e));
|
|
663
840
|
}
|
|
664
|
-
},
|
|
841
|
+
}, J = {
|
|
665
842
|
/**
|
|
666
843
|
* 获取浏览器类型
|
|
667
844
|
*
|
|
@@ -702,8 +879,8 @@ const F = {
|
|
|
702
879
|
const t = document.documentElement.clientWidth || 0, e = document.documentElement.clientHeight || 0, n = document.getElementById("app");
|
|
703
880
|
if (!n) return;
|
|
704
881
|
const r = n.style, s = t / e, i = 16 / 9;
|
|
705
|
-
let
|
|
706
|
-
s > i && (
|
|
882
|
+
let a = t / 1920;
|
|
883
|
+
s > i && (a = e / 1080), r.transformOrigin = "left top", r.transform = `scale(${a}) translateX(-49.99%)`, r.width = `${t / a}px`;
|
|
707
884
|
},
|
|
708
885
|
/**
|
|
709
886
|
* 获取HTML字体大小
|
|
@@ -714,7 +891,7 @@ const F = {
|
|
|
714
891
|
const t = document.documentElement.clientWidth || document.body.clientWidth, e = document.querySelector("html");
|
|
715
892
|
e && (e.style.fontSize = t / 192 + "px");
|
|
716
893
|
}
|
|
717
|
-
},
|
|
894
|
+
}, H = {
|
|
718
895
|
set: function(t, e, n = 30) {
|
|
719
896
|
var r = /* @__PURE__ */ new Date();
|
|
720
897
|
r.setTime(r.getTime() + n * 24 * 60 * 60 * 1e3), document.cookie = t + "=" + escape(e) + ";expires=" + r.toUTCString();
|
|
@@ -729,17 +906,17 @@ const F = {
|
|
|
729
906
|
var e = document.cookie.match(new RegExp("(^| )" + t + "=([^;]*)(;|$)"));
|
|
730
907
|
return e != null ? e[2] : "";
|
|
731
908
|
}
|
|
732
|
-
},
|
|
909
|
+
}, q = {
|
|
733
910
|
PI: 3.141592653589793,
|
|
734
911
|
XPI: 3.141592653589793 * 3e3 / 180,
|
|
735
912
|
delta(t, e) {
|
|
736
913
|
const r = 0.006693421622965943;
|
|
737
914
|
let s = this.transformLat(e - 105, t - 35), i = this.transformLon(e - 105, t - 35);
|
|
738
|
-
const
|
|
739
|
-
let
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
return s = s * 180 / (6378245 * (1 - r) / (
|
|
915
|
+
const a = t / 180 * this.PI;
|
|
916
|
+
let o = Math.sin(a);
|
|
917
|
+
o = 1 - r * o * o;
|
|
918
|
+
const l = Math.sqrt(o);
|
|
919
|
+
return s = s * 180 / (6378245 * (1 - r) / (o * l) * this.PI), i = i * 180 / (6378245 / l * Math.cos(a) * this.PI), { lat: s, lng: i };
|
|
743
920
|
},
|
|
744
921
|
/**
|
|
745
922
|
* 判断经纬度是否不在中国境内
|
|
@@ -767,23 +944,23 @@ const F = {
|
|
|
767
944
|
},
|
|
768
945
|
// GCJ-02 to WGS-84 exactly
|
|
769
946
|
gcjDecryptExact(t, e) {
|
|
770
|
-
let s = 0.01, i = 0.01,
|
|
947
|
+
let s = 0.01, i = 0.01, a = t - s, o = e - i, l = t + s, h = e + i, c = 0, u = 0, f = 0;
|
|
771
948
|
for (; ; ) {
|
|
772
|
-
|
|
773
|
-
const p = this.gcjEncrypt(
|
|
774
|
-
if (s = p.lat - t, i = p.lng - e, Math.abs(s) < 1e-9 && Math.abs(i) < 1e-9 || (s > 0 ?
|
|
949
|
+
c = (a + l) / 2, u = (o + h) / 2;
|
|
950
|
+
const p = this.gcjEncrypt(c, u);
|
|
951
|
+
if (s = p.lat - t, i = p.lng - e, Math.abs(s) < 1e-9 && Math.abs(i) < 1e-9 || (s > 0 ? l = c : a = c, i > 0 ? h = u : o = u, ++f > 1e4)) break;
|
|
775
952
|
}
|
|
776
|
-
return { lat:
|
|
953
|
+
return { lat: c, lng: u };
|
|
777
954
|
},
|
|
778
955
|
// GCJ-02 to BD-09
|
|
779
956
|
bdEncrypt(t, e) {
|
|
780
|
-
const n = e, r = t, s = Math.sqrt(n * n + r * r) + 2e-5 * Math.sin(r * this.XPI), i = Math.atan2(r, n) + 3e-6 * Math.cos(n * this.XPI),
|
|
781
|
-
return { lat: s * Math.sin(i) + 6e-3, lng:
|
|
957
|
+
const n = e, r = t, s = Math.sqrt(n * n + r * r) + 2e-5 * Math.sin(r * this.XPI), i = Math.atan2(r, n) + 3e-6 * Math.cos(n * this.XPI), a = s * Math.cos(i) + 65e-4;
|
|
958
|
+
return { lat: s * Math.sin(i) + 6e-3, lng: a };
|
|
782
959
|
},
|
|
783
960
|
// BD-09 to GCJ-02
|
|
784
961
|
bdDecrypt(t, e) {
|
|
785
|
-
const n = e - 65e-4, r = t - 6e-3, s = Math.sqrt(n * n + r * r) - 2e-5 * Math.sin(r * this.XPI), i = Math.atan2(r, n) - 3e-6 * Math.cos(n * this.XPI),
|
|
786
|
-
return { lat: s * Math.sin(i), lng:
|
|
962
|
+
const n = e - 65e-4, r = t - 6e-3, s = Math.sqrt(n * n + r * r) - 2e-5 * Math.sin(r * this.XPI), i = Math.atan2(r, n) - 3e-6 * Math.cos(n * this.XPI), a = s * Math.cos(i);
|
|
963
|
+
return { lat: s * Math.sin(i), lng: a };
|
|
787
964
|
},
|
|
788
965
|
// WGS-84 to Web mercator
|
|
789
966
|
// mercatorLat -> y mercatorLon -> x
|
|
@@ -825,8 +1002,8 @@ const F = {
|
|
|
825
1002
|
return n ? e.call(n, t) : e(t);
|
|
826
1003
|
const r = [];
|
|
827
1004
|
let s, i;
|
|
828
|
-
for (let
|
|
829
|
-
if (s = t[
|
|
1005
|
+
for (let a = 0, o = t.length; a < o; a++) {
|
|
1006
|
+
if (s = t[a], y.isNil(s)) {
|
|
830
1007
|
r.push(null);
|
|
831
1008
|
continue;
|
|
832
1009
|
}
|
|
@@ -834,7 +1011,7 @@ const F = {
|
|
|
834
1011
|
}
|
|
835
1012
|
return r;
|
|
836
1013
|
}
|
|
837
|
-
},
|
|
1014
|
+
}, j = {
|
|
838
1015
|
random() {
|
|
839
1016
|
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
1017
|
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 +1043,11 @@ const F = {
|
|
|
866
1043
|
* @returns 返回rgba格式的颜色值,格式为rgba(r,g,b,1)
|
|
867
1044
|
*/
|
|
868
1045
|
hexToRgba(t) {
|
|
869
|
-
const e = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, n = t.replace(e, (
|
|
1046
|
+
const e = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, n = t.replace(e, (l, h, c, u) => h + h + c + c + u + u), s = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);
|
|
870
1047
|
if (!s)
|
|
871
1048
|
return t;
|
|
872
|
-
const i = parseInt(s[1], 16),
|
|
873
|
-
return `rgba(${i},${
|
|
1049
|
+
const i = parseInt(s[1], 16), a = parseInt(s[2], 16), o = parseInt(s[3], 16);
|
|
1050
|
+
return `rgba(${i},${a},${o},1)`;
|
|
874
1051
|
},
|
|
875
1052
|
/**
|
|
876
1053
|
* 将 HSL 颜色值转换为 RGBA 颜色值
|
|
@@ -885,17 +1062,17 @@ const F = {
|
|
|
885
1062
|
if (!e)
|
|
886
1063
|
return null;
|
|
887
1064
|
const n = parseInt(e[1], 10) / 360, r = parseInt(e[2], 10) / 100, s = parseInt(e[3], 10) / 100, i = e[4] ? parseFloat(e[4]) : 1;
|
|
888
|
-
function
|
|
889
|
-
return f < 0 && (f += 1), f > 1 && (f -= 1), f < 1 / 6 ?
|
|
1065
|
+
function a(c, u, f) {
|
|
1066
|
+
return f < 0 && (f += 1), f > 1 && (f -= 1), f < 1 / 6 ? c + (u - c) * 6 * f : f < 1 / 2 ? u : f < 2 / 3 ? c + (u - c) * (2 / 3 - f) * 6 : c;
|
|
890
1067
|
}
|
|
891
|
-
let
|
|
1068
|
+
let o, l, h;
|
|
892
1069
|
if (r === 0)
|
|
893
|
-
|
|
1070
|
+
o = l = h = s;
|
|
894
1071
|
else {
|
|
895
|
-
const
|
|
896
|
-
|
|
1072
|
+
const c = s < 0.5 ? s * (1 + r) : s + r - s * r, u = 2 * s - c;
|
|
1073
|
+
o = a(u, c, n + 1 / 3), l = a(u, c, n), h = a(u, c, n - 1 / 3);
|
|
897
1074
|
}
|
|
898
|
-
return `rgba(${Math.round(
|
|
1075
|
+
return `rgba(${Math.round(o * 255)},${Math.round(l * 255)},${Math.round(h * 255)},${i})`;
|
|
899
1076
|
},
|
|
900
1077
|
isHex(t) {
|
|
901
1078
|
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);
|
|
@@ -975,7 +1152,7 @@ Date.prototype.addDate = function(t, e) {
|
|
|
975
1152
|
}
|
|
976
1153
|
return n;
|
|
977
1154
|
};
|
|
978
|
-
const
|
|
1155
|
+
const W = {
|
|
979
1156
|
lastMonthDate: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth() - 1, 1),
|
|
980
1157
|
thisMonthDate: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth(), 1),
|
|
981
1158
|
nextMonthDate: new Date((/* @__PURE__ */ new Date()).getFullYear(), (/* @__PURE__ */ new Date()).getMonth() + 1, 1),
|
|
@@ -1019,26 +1196,26 @@ const q = {
|
|
|
1019
1196
|
* @returns 返回格式化后的时间间隔字符串,格式为"天数 天 小时 时 分钟 分 秒 秒"或"少于1秒"
|
|
1020
1197
|
*/
|
|
1021
1198
|
formatDateInterval(t, e) {
|
|
1022
|
-
const n = new Date(t), s = new Date(e).getTime() - n.getTime(), i = Math.floor(s / (24 * 3600 * 1e3)),
|
|
1199
|
+
const n = new Date(t), s = new Date(e).getTime() - n.getTime(), i = Math.floor(s / (24 * 3600 * 1e3)), a = s % (24 * 3600 * 1e3), o = Math.floor(a / (3600 * 1e3)), l = a % (3600 * 1e3), h = Math.floor(l / (60 * 1e3)), c = l % (60 * 1e3), u = Math.round(c / 1e3);
|
|
1023
1200
|
let f = "";
|
|
1024
|
-
return i > 0 && (f += i + "天"),
|
|
1201
|
+
return i > 0 && (f += i + "天"), o > 0 && (f += o + "时"), h > 0 && (f += h + "分"), u > 0 && (f += u + "秒"), i === 0 && o === 0 && h === 0 && u === 0 && (f = "少于1秒"), f;
|
|
1025
1202
|
},
|
|
1026
1203
|
formatterCounter(t) {
|
|
1027
|
-
const e = function(
|
|
1028
|
-
return (
|
|
1029
|
-
}, n = e(Math.floor(t / 3600)), r = t % 3600, s = e(Math.floor(r / 60)), i = r % 60,
|
|
1030
|
-
return `${n}:${s}:${
|
|
1204
|
+
const e = function(o) {
|
|
1205
|
+
return (o > 10 ? "" : "0") + (o || 0);
|
|
1206
|
+
}, n = e(Math.floor(t / 3600)), r = t % 3600, s = e(Math.floor(r / 60)), i = r % 60, a = e(Math.round(i));
|
|
1207
|
+
return `${n}:${s}:${a}`;
|
|
1031
1208
|
},
|
|
1032
1209
|
sleep(t) {
|
|
1033
1210
|
}
|
|
1034
1211
|
};
|
|
1035
|
-
function
|
|
1212
|
+
function U(t) {
|
|
1036
1213
|
return t.trim ? t.trim() : t.replace(/^\s+|\s+$/g, "");
|
|
1037
1214
|
}
|
|
1038
|
-
function
|
|
1039
|
-
return
|
|
1215
|
+
function E(t) {
|
|
1216
|
+
return U(t).split(/\s+/);
|
|
1040
1217
|
}
|
|
1041
|
-
const
|
|
1218
|
+
const K = {
|
|
1042
1219
|
/**
|
|
1043
1220
|
* 获取元素的样式值
|
|
1044
1221
|
*
|
|
@@ -1137,7 +1314,7 @@ const W = {
|
|
|
1137
1314
|
*/
|
|
1138
1315
|
addClass(t, e) {
|
|
1139
1316
|
if (t.classList !== void 0) {
|
|
1140
|
-
const n =
|
|
1317
|
+
const n = E(e);
|
|
1141
1318
|
for (let r = 0, s = n.length; r < s; r++)
|
|
1142
1319
|
t.classList.add(n[r]);
|
|
1143
1320
|
} else if (!this.hasClass(t, e)) {
|
|
@@ -1152,7 +1329,7 @@ const W = {
|
|
|
1152
1329
|
* @param name 要移除的类名,多个类名用空格分隔
|
|
1153
1330
|
*/
|
|
1154
1331
|
removeClass(t, e) {
|
|
1155
|
-
t.classList !== void 0 ?
|
|
1332
|
+
t.classList !== void 0 ? E(e).forEach((r) => t.classList.remove(r)) : this.setClass(t, (" " + this.getClass(t) + " ").replace(" " + e + " ", " ").trim());
|
|
1156
1333
|
},
|
|
1157
1334
|
/**
|
|
1158
1335
|
* 设置元素的 CSS 类名
|
|
@@ -1172,7 +1349,198 @@ const W = {
|
|
|
1172
1349
|
parseFromString(t) {
|
|
1173
1350
|
return new DOMParser().parseFromString(t, "text/xml").children[0];
|
|
1174
1351
|
}
|
|
1175
|
-
},
|
|
1352
|
+
}, M = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon"], Y = {
|
|
1353
|
+
/**
|
|
1354
|
+
* 获取GeoJSON要素的几何类型
|
|
1355
|
+
*
|
|
1356
|
+
* @param feature GeoJSONFeature 类型的要素
|
|
1357
|
+
* @returns 返回要素的几何类型,如果要素没有几何属性则返回 null
|
|
1358
|
+
*/
|
|
1359
|
+
getGeoJsonType(t) {
|
|
1360
|
+
return t.geometry ? t.geometry.type : null;
|
|
1361
|
+
},
|
|
1362
|
+
/**
|
|
1363
|
+
* 判断给定的GeoJSON要素是否为有效的GeoJSON格式
|
|
1364
|
+
*
|
|
1365
|
+
* @param feature 要判断的GeoJSON要素
|
|
1366
|
+
* @returns 如果为有效的GeoJSON格式则返回true,否则返回false
|
|
1367
|
+
*/
|
|
1368
|
+
isGeoJson(t) {
|
|
1369
|
+
const e = this.getGeoJsonType(t);
|
|
1370
|
+
if (e) {
|
|
1371
|
+
for (let n = 0, r = M.length; n < r; n++)
|
|
1372
|
+
if (M[n] === e)
|
|
1373
|
+
return !0;
|
|
1374
|
+
}
|
|
1375
|
+
return !1;
|
|
1376
|
+
},
|
|
1377
|
+
/**
|
|
1378
|
+
* 判断是否为 GeoJSON 多边形
|
|
1379
|
+
*
|
|
1380
|
+
* @param feature GeoJSONFeature 对象
|
|
1381
|
+
* @returns 返回布尔值,表示是否为 GeoJSON 多边形
|
|
1382
|
+
*/
|
|
1383
|
+
isGeoJsonPolygon(t) {
|
|
1384
|
+
const e = this.getGeoJsonType(t);
|
|
1385
|
+
return !!(e && (e === M[4] || e === M[5]));
|
|
1386
|
+
},
|
|
1387
|
+
/**
|
|
1388
|
+
* 判断给定的 GeoJSONFeature 是否为 GeoJSON 线
|
|
1389
|
+
*
|
|
1390
|
+
* @param feature GeoJSONFeature 对象
|
|
1391
|
+
* @returns 是 GeoJSON 线返回 true,否则返回 false
|
|
1392
|
+
*/
|
|
1393
|
+
isGeoJsonLine(t) {
|
|
1394
|
+
const e = this.getGeoJsonType(t);
|
|
1395
|
+
return !!(e && (e === M[2] || e === M[3]));
|
|
1396
|
+
},
|
|
1397
|
+
/**
|
|
1398
|
+
* 判断是否为 GeoJSON 点类型
|
|
1399
|
+
*
|
|
1400
|
+
* @param feature GeoJSONFeature 对象
|
|
1401
|
+
* @returns 是点类型返回 true,否则返回 false
|
|
1402
|
+
*/
|
|
1403
|
+
isGeoJsonPoint(t) {
|
|
1404
|
+
const e = this.getGeoJsonType(t);
|
|
1405
|
+
return !!(e && (e === M[0] || e === M[1]));
|
|
1406
|
+
},
|
|
1407
|
+
/**
|
|
1408
|
+
* 判断传入的 GeoJSONFeature 是否为 Multi 类型的 GeoJSON。
|
|
1409
|
+
*
|
|
1410
|
+
* @param feature GeoJSONFeature 类型的参数,待判断是否为 Multi 类型的 GeoJSON。
|
|
1411
|
+
* @returns 返回一个布尔值,如果传入的 GeoJSONFeature 是 Multi 类型的 GeoJSON,则返回 true,否则返回 false。
|
|
1412
|
+
*/
|
|
1413
|
+
isGeoJsonMulti(t) {
|
|
1414
|
+
const e = this.getGeoJsonType(t);
|
|
1415
|
+
return !!(e && e.indexOf("Multi") > -1);
|
|
1416
|
+
},
|
|
1417
|
+
/**
|
|
1418
|
+
* 获取GeoJSON要素的坐标数组
|
|
1419
|
+
*
|
|
1420
|
+
* @param feature GeoJSONFeature对象
|
|
1421
|
+
* @returns 返回一个包含坐标数组的数组,可以是二维、三维或四维数组
|
|
1422
|
+
*/
|
|
1423
|
+
getGeoJsonCoordinates(t) {
|
|
1424
|
+
return t.geometry ? t.geometry.coordinates : [];
|
|
1425
|
+
},
|
|
1426
|
+
/**
|
|
1427
|
+
* 获取GeoJSON要素的中心点坐标
|
|
1428
|
+
*
|
|
1429
|
+
* @param feature GeoJSON要素
|
|
1430
|
+
* @param out 输出坐标对象,默认为null
|
|
1431
|
+
* @returns 返回中心点坐标,如果无法获取则返回null
|
|
1432
|
+
*/
|
|
1433
|
+
getGeoJsonCenter(t, e) {
|
|
1434
|
+
const n = this.getGeoJsonType(t);
|
|
1435
|
+
if (!n || !t.geometry)
|
|
1436
|
+
return null;
|
|
1437
|
+
const s = t.geometry.coordinates;
|
|
1438
|
+
if (!s)
|
|
1439
|
+
return null;
|
|
1440
|
+
let i = 0, a = 0, o = 0;
|
|
1441
|
+
switch (n) {
|
|
1442
|
+
case "Point": {
|
|
1443
|
+
i = s[0], a = s[1], o++;
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
case "MultiPoint":
|
|
1447
|
+
case "LineString": {
|
|
1448
|
+
for (let c = 0, u = s.length; c < u; c++)
|
|
1449
|
+
i += s[c][0], a += s[c][1], o++;
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
case "MultiLineString":
|
|
1453
|
+
case "Polygon": {
|
|
1454
|
+
for (let c = 0, u = s.length; c < u; c++)
|
|
1455
|
+
for (let f = 0, p = s[c].length; f < p; f++)
|
|
1456
|
+
i += s[c][f][0], a += s[c][f][1], o++;
|
|
1457
|
+
break;
|
|
1458
|
+
}
|
|
1459
|
+
case "MultiPolygon": {
|
|
1460
|
+
for (let c = 0, u = s.length; c < u; c++)
|
|
1461
|
+
for (let f = 0, p = s[c].length; f < p; f++)
|
|
1462
|
+
for (let A = 0, b = s[c][f].length; A < b; A++)
|
|
1463
|
+
i += s[c][f][A][0], a += s[c][f][A][1], o++;
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
const l = i / o, h = a / o;
|
|
1468
|
+
return e ? (e.x = l, e.y = h, e) : { x: l, y: h };
|
|
1469
|
+
},
|
|
1470
|
+
/**
|
|
1471
|
+
* 将一个包含多个点、线或面的 GeoJSON 特征对象拆分成多个独立的 GeoJSON 特征对象数组。
|
|
1472
|
+
*
|
|
1473
|
+
* @param feature 包含多个点、线或面的 GeoJSON 特征对象
|
|
1474
|
+
* @returns 返回一个 GeoJSON 特征对象数组,如果拆分失败则返回 null
|
|
1475
|
+
*/
|
|
1476
|
+
spliteGeoJsonMulti(t) {
|
|
1477
|
+
const e = this.getGeoJsonType(t);
|
|
1478
|
+
if (!e || !t.geometry)
|
|
1479
|
+
return null;
|
|
1480
|
+
const n = t.geometry, r = t.properties || {}, s = n.coordinates;
|
|
1481
|
+
if (!s)
|
|
1482
|
+
return null;
|
|
1483
|
+
const i = [];
|
|
1484
|
+
let a;
|
|
1485
|
+
switch (e) {
|
|
1486
|
+
case "MultiPoint": {
|
|
1487
|
+
a = "Point";
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
case "MultiLineString": {
|
|
1491
|
+
a = "LineString";
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
case "MultiPolygon": {
|
|
1495
|
+
a = "Polygon";
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
if (a)
|
|
1500
|
+
for (let o = 0, l = s.length; o < l; o++)
|
|
1501
|
+
i.push({
|
|
1502
|
+
type: "Feature",
|
|
1503
|
+
geometry: {
|
|
1504
|
+
type: a,
|
|
1505
|
+
coordinates: s[o]
|
|
1506
|
+
},
|
|
1507
|
+
properties: r
|
|
1508
|
+
});
|
|
1509
|
+
else
|
|
1510
|
+
i.push(t);
|
|
1511
|
+
return i;
|
|
1512
|
+
},
|
|
1513
|
+
/**
|
|
1514
|
+
* 根据坐标数组生成GeoJSON要素
|
|
1515
|
+
*
|
|
1516
|
+
* @param coordinates 坐标数组
|
|
1517
|
+
* @returns GeoJSONFeature 生成的GeoJSON要素
|
|
1518
|
+
* @throws Error 如果coordinates参数格式错误
|
|
1519
|
+
*/
|
|
1520
|
+
getGeoJsonByCoordinates(t) {
|
|
1521
|
+
if (!Array.isArray(t))
|
|
1522
|
+
throw Error("coordinates 参数格式错误");
|
|
1523
|
+
let e;
|
|
1524
|
+
if (t.length === 2 && typeof t[0] == "number" && typeof t[1] == "number")
|
|
1525
|
+
e = "Point";
|
|
1526
|
+
else if (Array.isArray(t[0]) && t[0].length === 2)
|
|
1527
|
+
e = "LineString";
|
|
1528
|
+
else if (Array.isArray(t[0]) && Array.isArray(t[0][0])) {
|
|
1529
|
+
const n = t[0];
|
|
1530
|
+
if (n[0].join(",") === n[n.length - 1].join(","))
|
|
1531
|
+
e = "Polygon";
|
|
1532
|
+
else if (t.length > 1)
|
|
1533
|
+
e = "MultiPolygon";
|
|
1534
|
+
else
|
|
1535
|
+
throw Error("coordinates 参数格式错误");
|
|
1536
|
+
} else
|
|
1537
|
+
throw Error("coordinates 参数格式错误");
|
|
1538
|
+
return {
|
|
1539
|
+
type: "Feature",
|
|
1540
|
+
geometry: { type: e, coordinates: t }
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
}, z = {
|
|
1176
1544
|
toRadian: Math.PI / 180,
|
|
1177
1545
|
R: 6371393,
|
|
1178
1546
|
/**
|
|
@@ -1203,9 +1571,9 @@ const W = {
|
|
|
1203
1571
|
* @returns 返回两点之间的距离,单位为米
|
|
1204
1572
|
*/
|
|
1205
1573
|
distanceByPoints(t, e) {
|
|
1206
|
-
const { lng: n, lat: r } = t, { lng: s, lat: i } = e,
|
|
1207
|
-
let h =
|
|
1208
|
-
return h > 1 && (h = 1), h < -1 && (h = -1), Math.acos(h) *
|
|
1574
|
+
const { lng: n, lat: r } = t, { lng: s, lat: i } = e, a = 6371e3, o = Math.cos(r * Math.PI / 180) * Math.cos(i * Math.PI / 180) * Math.cos((n - s) * Math.PI / 180), l = Math.sin(r * Math.PI / 180) * Math.sin(i * Math.PI / 180);
|
|
1575
|
+
let h = o + l;
|
|
1576
|
+
return h > 1 && (h = 1), h < -1 && (h = -1), Math.acos(h) * a;
|
|
1209
1577
|
},
|
|
1210
1578
|
/**
|
|
1211
1579
|
* 格式化经纬度为度分秒格式
|
|
@@ -1217,8 +1585,8 @@ const W = {
|
|
|
1217
1585
|
formatLnglat(t, e) {
|
|
1218
1586
|
let n = "";
|
|
1219
1587
|
function r(s) {
|
|
1220
|
-
const i = Math.floor(s),
|
|
1221
|
-
return `${i}°${
|
|
1588
|
+
const i = Math.floor(s), a = Math.floor((s - i) * 60), o = (s - i) * 3600 - a * 60;
|
|
1589
|
+
return `${i}°${a}′${o.toFixed(2)}″`;
|
|
1222
1590
|
}
|
|
1223
1591
|
return this.isLnglat(t, e) ? n = r(t) + "," + r(e) : isNaN(t) ? isNaN(e) || (n = r(e)) : n = r(t), n;
|
|
1224
1592
|
},
|
|
@@ -1232,11 +1600,11 @@ const W = {
|
|
|
1232
1600
|
transformLnglat(t, e) {
|
|
1233
1601
|
function n(r) {
|
|
1234
1602
|
let i = /[sw]/i.test(r) ? -1 : 1;
|
|
1235
|
-
const
|
|
1236
|
-
let
|
|
1237
|
-
for (let
|
|
1238
|
-
|
|
1239
|
-
return
|
|
1603
|
+
const a = r.match(/[\d.]+/g) || [];
|
|
1604
|
+
let o = 0;
|
|
1605
|
+
for (let l = 0; l < a.length; l++)
|
|
1606
|
+
o += parseFloat(a[l]) / i, i *= 60;
|
|
1607
|
+
return o;
|
|
1240
1608
|
}
|
|
1241
1609
|
if (t && e)
|
|
1242
1610
|
return {
|
|
@@ -1252,12 +1620,12 @@ const W = {
|
|
|
1252
1620
|
* @returns 返回字符串,表示点相对于多边形的位置:'in'表示在多边形内,'out'表示在多边形外,'on'表示在多边形上
|
|
1253
1621
|
*/
|
|
1254
1622
|
rayCasting(t, e) {
|
|
1255
|
-
for (var n = t.x, r = t.y, s = !1, i = 0,
|
|
1256
|
-
var
|
|
1257
|
-
if (
|
|
1623
|
+
for (var n = t.x, r = t.y, s = !1, i = 0, a = e.length, o = a - 1; i < a; o = i, i++) {
|
|
1624
|
+
var l = e[i].x, h = e[i].y, c = e[o].x, u = e[o].y;
|
|
1625
|
+
if (l === n && h === r || c === n && u === r)
|
|
1258
1626
|
return "on";
|
|
1259
1627
|
if (h < r && u >= r || h >= r && u < r) {
|
|
1260
|
-
var f =
|
|
1628
|
+
var f = l + (r - h) * (c - l) / (u - h);
|
|
1261
1629
|
if (f === n)
|
|
1262
1630
|
return "on";
|
|
1263
1631
|
f > n && (s = !s);
|
|
@@ -1285,8 +1653,8 @@ const W = {
|
|
|
1285
1653
|
* @returns 返回一个对象,包含angle和distance属性,分别表示两点之间的角度(以度为单位,取值范围为0~359)和距离
|
|
1286
1654
|
*/
|
|
1287
1655
|
calcBearAndDis(t, e) {
|
|
1288
|
-
const { x: n, y: r } = t, { x: s, y: i } = e,
|
|
1289
|
-
return { angle: (Math.atan2(
|
|
1656
|
+
const { x: n, y: r } = t, { x: s, y: i } = e, a = s - n, o = i - r, l = Math.sqrt(a * a + o * o);
|
|
1657
|
+
return { angle: (Math.atan2(o, a) * (180 / Math.PI) + 360 + 90) % 360, distance: l };
|
|
1290
1658
|
},
|
|
1291
1659
|
/**
|
|
1292
1660
|
* 根据两个经纬度点计算方位角和距离
|
|
@@ -1296,9 +1664,9 @@ const W = {
|
|
|
1296
1664
|
* @returns 包含方位角和距离的对象
|
|
1297
1665
|
*/
|
|
1298
1666
|
calcBearAndDisByPoints(t, e) {
|
|
1299
|
-
var n = t.lat * 1, r = t.lng * 1, s = e.lat * 1, i = e.lng * 1,
|
|
1667
|
+
var n = t.lat * 1, r = t.lng * 1, s = e.lat * 1, i = e.lng * 1, a = Math.sin((i - r) * this.toRadian) * Math.cos(s * this.toRadian), o = 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), l = Math.atan2(a, o) * (180 / Math.PI), h = (s - n) * this.toRadian, c = (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(c / 2) * Math.sin(c / 2), f = 2 * Math.atan2(Math.sqrt(u), Math.sqrt(1 - u)), p = this.R * f;
|
|
1300
1668
|
return {
|
|
1301
|
-
angle:
|
|
1669
|
+
angle: l,
|
|
1302
1670
|
distance: p
|
|
1303
1671
|
};
|
|
1304
1672
|
},
|
|
@@ -1311,13 +1679,13 @@ const W = {
|
|
|
1311
1679
|
* @returns 点P到线段P1P2的最短距离
|
|
1312
1680
|
*/
|
|
1313
1681
|
distanceToSegment(t, e, n) {
|
|
1314
|
-
const r = t.x, s = t.y, i = e.x,
|
|
1682
|
+
const r = t.x, s = t.y, i = e.x, a = e.y, o = n.x, l = n.y, h = (o - i) * (r - i) + (l - a) * (s - a);
|
|
1315
1683
|
if (h <= 0)
|
|
1316
|
-
return Math.sqrt((r - i) * (r - i) + (s -
|
|
1317
|
-
const
|
|
1318
|
-
if (h >=
|
|
1319
|
-
return Math.sqrt((r -
|
|
1320
|
-
const u = h /
|
|
1684
|
+
return Math.sqrt((r - i) * (r - i) + (s - a) * (s - a));
|
|
1685
|
+
const c = (o - i) * (o - i) + (l - a) * (l - a);
|
|
1686
|
+
if (h >= c)
|
|
1687
|
+
return Math.sqrt((r - o) * (r - o) + (s - l) * (s - l));
|
|
1688
|
+
const u = h / c, f = i + (o - i) * u, p = a + (l - a) * u;
|
|
1321
1689
|
return Math.sqrt((r - f) * (r - f) + (s - p) * (s - p));
|
|
1322
1690
|
},
|
|
1323
1691
|
/**
|
|
@@ -1331,10 +1699,10 @@ const W = {
|
|
|
1331
1699
|
calcPointByBearAndDis(t, e, n) {
|
|
1332
1700
|
const r = m.toRadians(t.lat * 1), s = m.toRadians(t.lng * 1), i = n / this.R;
|
|
1333
1701
|
e = m.toRadians(e);
|
|
1334
|
-
const
|
|
1702
|
+
const a = Math.asin(Math.sin(r) * Math.cos(i) + Math.cos(r) * Math.sin(i) * Math.cos(e)), o = s + Math.atan2(Math.sin(e) * Math.sin(i) * Math.cos(r), Math.cos(i) - Math.sin(r) * Math.sin(a));
|
|
1335
1703
|
return {
|
|
1336
|
-
lat: m.toDegrees(
|
|
1337
|
-
lng: m.toDegrees(
|
|
1704
|
+
lat: m.toDegrees(a),
|
|
1705
|
+
lng: m.toDegrees(o)
|
|
1338
1706
|
};
|
|
1339
1707
|
},
|
|
1340
1708
|
/**
|
|
@@ -1363,209 +1731,20 @@ const W = {
|
|
|
1363
1731
|
var s = e * Math.PI / 180;
|
|
1364
1732
|
const i = n / 2 * Math.log((1 + Math.sin(s)) / (1 - Math.sin(s)));
|
|
1365
1733
|
return { x: r, y: i };
|
|
1366
|
-
}
|
|
1367
|
-
}, y = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon"], j = {
|
|
1368
|
-
/**
|
|
1369
|
-
* 获取GeoJSON要素的几何类型
|
|
1370
|
-
*
|
|
1371
|
-
* @param feature GeoJSONFeature 类型的要素
|
|
1372
|
-
* @returns 返回要素的几何类型,如果要素没有几何属性则返回 null
|
|
1373
|
-
*/
|
|
1374
|
-
getGeoJsonType(t) {
|
|
1375
|
-
return t.geometry ? t.geometry.type : null;
|
|
1376
|
-
},
|
|
1377
|
-
/**
|
|
1378
|
-
* 判断给定的GeoJSON要素是否为有效的GeoJSON格式
|
|
1379
|
-
*
|
|
1380
|
-
* @param feature 要判断的GeoJSON要素
|
|
1381
|
-
* @returns 如果为有效的GeoJSON格式则返回true,否则返回false
|
|
1382
|
-
*/
|
|
1383
|
-
isGeoJson(t) {
|
|
1384
|
-
const e = this.getGeoJsonType(t);
|
|
1385
|
-
if (e) {
|
|
1386
|
-
for (let n = 0, r = y.length; n < r; n++)
|
|
1387
|
-
if (y[n] === e)
|
|
1388
|
-
return !0;
|
|
1389
|
-
}
|
|
1390
|
-
return !1;
|
|
1391
|
-
},
|
|
1392
|
-
/**
|
|
1393
|
-
* 判断是否为 GeoJSON 多边形
|
|
1394
|
-
*
|
|
1395
|
-
* @param feature GeoJSONFeature 对象
|
|
1396
|
-
* @returns 返回布尔值,表示是否为 GeoJSON 多边形
|
|
1397
|
-
*/
|
|
1398
|
-
isGeoJsonPolygon(t) {
|
|
1399
|
-
const e = this.getGeoJsonType(t);
|
|
1400
|
-
return !!(e && (e === y[4] || e === y[5]));
|
|
1401
|
-
},
|
|
1402
|
-
/**
|
|
1403
|
-
* 判断给定的 GeoJSONFeature 是否为 GeoJSON 线
|
|
1404
|
-
*
|
|
1405
|
-
* @param feature GeoJSONFeature 对象
|
|
1406
|
-
* @returns 是 GeoJSON 线返回 true,否则返回 false
|
|
1407
|
-
*/
|
|
1408
|
-
isGeoJsonLine(t) {
|
|
1409
|
-
const e = this.getGeoJsonType(t);
|
|
1410
|
-
return !!(e && (e === y[2] || e === y[3]));
|
|
1411
|
-
},
|
|
1412
|
-
/**
|
|
1413
|
-
* 判断是否为 GeoJSON 点类型
|
|
1414
|
-
*
|
|
1415
|
-
* @param feature GeoJSONFeature 对象
|
|
1416
|
-
* @returns 是点类型返回 true,否则返回 false
|
|
1417
|
-
*/
|
|
1418
|
-
isGeoJsonPoint(t) {
|
|
1419
|
-
const e = this.getGeoJsonType(t);
|
|
1420
|
-
return !!(e && (e === y[0] || e === y[1]));
|
|
1421
|
-
},
|
|
1422
|
-
/**
|
|
1423
|
-
* 判断传入的 GeoJSONFeature 是否为 Multi 类型的 GeoJSON。
|
|
1424
|
-
*
|
|
1425
|
-
* @param feature GeoJSONFeature 类型的参数,待判断是否为 Multi 类型的 GeoJSON。
|
|
1426
|
-
* @returns 返回一个布尔值,如果传入的 GeoJSONFeature 是 Multi 类型的 GeoJSON,则返回 true,否则返回 false。
|
|
1427
|
-
*/
|
|
1428
|
-
isGeoJsonMulti(t) {
|
|
1429
|
-
const e = this.getGeoJsonType(t);
|
|
1430
|
-
return !!(e && e.indexOf("Multi") > -1);
|
|
1431
|
-
},
|
|
1432
|
-
/**
|
|
1433
|
-
* 获取GeoJSON要素的坐标数组
|
|
1434
|
-
*
|
|
1435
|
-
* @param feature GeoJSONFeature对象
|
|
1436
|
-
* @returns 返回一个包含坐标数组的数组,可以是二维、三维或四维数组
|
|
1437
|
-
*/
|
|
1438
|
-
getGeoJsonCoordinates(t) {
|
|
1439
|
-
return t.geometry ? t.geometry.coordinates : [];
|
|
1440
|
-
},
|
|
1441
|
-
/**
|
|
1442
|
-
* 获取GeoJSON要素的中心点坐标
|
|
1443
|
-
*
|
|
1444
|
-
* @param feature GeoJSON要素
|
|
1445
|
-
* @param out 输出坐标对象,默认为null
|
|
1446
|
-
* @returns 返回中心点坐标,如果无法获取则返回null
|
|
1447
|
-
*/
|
|
1448
|
-
getGeoJsonCenter(t, e) {
|
|
1449
|
-
const n = this.getGeoJsonType(t);
|
|
1450
|
-
if (!n || !t.geometry)
|
|
1451
|
-
return null;
|
|
1452
|
-
const s = t.geometry.coordinates;
|
|
1453
|
-
if (!s)
|
|
1454
|
-
return null;
|
|
1455
|
-
let i = 0, o = 0, a = 0;
|
|
1456
|
-
switch (n) {
|
|
1457
|
-
case "Point": {
|
|
1458
|
-
i = s[0], o = s[1], a++;
|
|
1459
|
-
break;
|
|
1460
|
-
}
|
|
1461
|
-
case "MultiPoint":
|
|
1462
|
-
case "LineString": {
|
|
1463
|
-
for (let l = 0, u = s.length; l < u; l++)
|
|
1464
|
-
i += s[l][0], o += s[l][1], a++;
|
|
1465
|
-
break;
|
|
1466
|
-
}
|
|
1467
|
-
case "MultiLineString":
|
|
1468
|
-
case "Polygon": {
|
|
1469
|
-
for (let l = 0, u = s.length; l < u; l++)
|
|
1470
|
-
for (let f = 0, p = s[l].length; f < p; f++)
|
|
1471
|
-
i += s[l][f][0], o += s[l][f][1], a++;
|
|
1472
|
-
break;
|
|
1473
|
-
}
|
|
1474
|
-
case "MultiPolygon": {
|
|
1475
|
-
for (let l = 0, u = s.length; l < u; l++)
|
|
1476
|
-
for (let f = 0, p = s[l].length; f < p; f++)
|
|
1477
|
-
for (let E = 0, S = s[l][f].length; E < S; E++)
|
|
1478
|
-
i += s[l][f][E][0], o += s[l][f][E][1], a++;
|
|
1479
|
-
break;
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
const c = i / a, h = o / a;
|
|
1483
|
-
return e ? (e.x = c, e.y = h, e) : { x: c, y: h };
|
|
1484
|
-
},
|
|
1485
|
-
/**
|
|
1486
|
-
* 将一个包含多个点、线或面的 GeoJSON 特征对象拆分成多个独立的 GeoJSON 特征对象数组。
|
|
1487
|
-
*
|
|
1488
|
-
* @param feature 包含多个点、线或面的 GeoJSON 特征对象
|
|
1489
|
-
* @returns 返回一个 GeoJSON 特征对象数组,如果拆分失败则返回 null
|
|
1490
|
-
*/
|
|
1491
|
-
spliteGeoJsonMulti(t) {
|
|
1492
|
-
const e = this.getGeoJsonType(t);
|
|
1493
|
-
if (!e || !t.geometry)
|
|
1494
|
-
return null;
|
|
1495
|
-
const n = t.geometry, r = t.properties || {}, s = n.coordinates;
|
|
1496
|
-
if (!s)
|
|
1497
|
-
return null;
|
|
1498
|
-
const i = [];
|
|
1499
|
-
let o;
|
|
1500
|
-
switch (e) {
|
|
1501
|
-
case "MultiPoint": {
|
|
1502
|
-
o = "Point";
|
|
1503
|
-
break;
|
|
1504
|
-
}
|
|
1505
|
-
case "MultiLineString": {
|
|
1506
|
-
o = "LineString";
|
|
1507
|
-
break;
|
|
1508
|
-
}
|
|
1509
|
-
case "MultiPolygon": {
|
|
1510
|
-
o = "Polygon";
|
|
1511
|
-
break;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
if (o)
|
|
1515
|
-
for (let a = 0, c = s.length; a < c; a++)
|
|
1516
|
-
i.push({
|
|
1517
|
-
type: "Feature",
|
|
1518
|
-
geometry: {
|
|
1519
|
-
type: o,
|
|
1520
|
-
coordinates: s[a]
|
|
1521
|
-
},
|
|
1522
|
-
properties: r
|
|
1523
|
-
});
|
|
1524
|
-
else
|
|
1525
|
-
i.push(t);
|
|
1526
|
-
return i;
|
|
1527
1734
|
},
|
|
1528
1735
|
/**
|
|
1529
|
-
*
|
|
1736
|
+
* 根据百分比获取坐标
|
|
1530
1737
|
*
|
|
1531
|
-
* @param
|
|
1532
|
-
* @
|
|
1533
|
-
* @
|
|
1738
|
+
* @param start 起点坐标
|
|
1739
|
+
* @param end 终点坐标
|
|
1740
|
+
* @param percent 百分比,取值范围0-1
|
|
1741
|
+
* @returns 返回插值后的坐标
|
|
1534
1742
|
*/
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
let e;
|
|
1539
|
-
if (t.length === 2 && typeof t[0] == "number" && typeof t[1] == "number")
|
|
1540
|
-
e = "Point";
|
|
1541
|
-
else if (Array.isArray(t[0]) && t[0].length === 2)
|
|
1542
|
-
e = "LineString";
|
|
1543
|
-
else if (Array.isArray(t[0]) && Array.isArray(t[0][0])) {
|
|
1544
|
-
const n = t[0];
|
|
1545
|
-
if (n[0].join(",") === n[n.length - 1].join(","))
|
|
1546
|
-
e = "Polygon";
|
|
1547
|
-
else if (t.length > 1)
|
|
1548
|
-
e = "MultiPolygon";
|
|
1549
|
-
else
|
|
1550
|
-
throw Error("coordinates 参数格式错误");
|
|
1551
|
-
} else
|
|
1552
|
-
throw Error("coordinates 参数格式错误");
|
|
1553
|
-
return {
|
|
1554
|
-
type: "Feature",
|
|
1555
|
-
geometry: { type: e, coordinates: t }
|
|
1556
|
-
};
|
|
1743
|
+
interpolate({ x: t, y: e, z: n = 0 }, { x: r, y: s, z: i = 0 }, a) {
|
|
1744
|
+
const o = r - t, l = s - e, h = i - n;
|
|
1745
|
+
return { x: t + o * a, y: e + l * a, z: n + h * a };
|
|
1557
1746
|
}
|
|
1558
|
-
},
|
|
1559
|
-
deepClone(t) {
|
|
1560
|
-
return structuredClone(t);
|
|
1561
|
-
},
|
|
1562
|
-
isEqual(t, e) {
|
|
1563
|
-
return JSON.stringify(t) === JSON.stringify(e);
|
|
1564
|
-
},
|
|
1565
|
-
parse(t) {
|
|
1566
|
-
return !t || typeof t != "string" ? t : JSON.parse(t);
|
|
1567
|
-
}
|
|
1568
|
-
}, Y = {
|
|
1747
|
+
}, X = {
|
|
1569
1748
|
/**
|
|
1570
1749
|
* 将Base64编码的字符串转换为Blob对象
|
|
1571
1750
|
*
|
|
@@ -1574,8 +1753,8 @@ const W = {
|
|
|
1574
1753
|
*/
|
|
1575
1754
|
convertBase64ToBlob(t) {
|
|
1576
1755
|
const e = t.split(",")[0].split(":")[1].split(";")[0], n = atob(t.split(",")[1]), r = new Array(n.length);
|
|
1577
|
-
for (let
|
|
1578
|
-
r[
|
|
1756
|
+
for (let a = 0; a < n.length; a++)
|
|
1757
|
+
r[a] = n.charCodeAt(a);
|
|
1579
1758
|
const s = new Uint8Array(r);
|
|
1580
1759
|
return new Blob([s], { type: e });
|
|
1581
1760
|
},
|
|
@@ -1587,27 +1766,6 @@ const W = {
|
|
|
1587
1766
|
* @param height 图片的高度,默认为图片原始高度
|
|
1588
1767
|
* @returns 返回Promise对象,解析后得到包含Base64编码数据的对象
|
|
1589
1768
|
*/
|
|
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
1769
|
/**
|
|
1612
1770
|
* 将base64字符串转换为文件对象
|
|
1613
1771
|
*
|
|
@@ -1616,10 +1774,10 @@ const W = {
|
|
|
1616
1774
|
* @returns 返回文件对象
|
|
1617
1775
|
*/
|
|
1618
1776
|
convertBase64ToFile(t, e) {
|
|
1619
|
-
const n = t.split(","), r = n[0].match(/:(.*?);/), s = r ? r[1] : "image/png", i = atob(n[1]),
|
|
1620
|
-
for (let
|
|
1621
|
-
|
|
1622
|
-
return new File([
|
|
1777
|
+
const n = t.split(","), r = n[0].match(/:(.*?);/), s = r ? r[1] : "image/png", i = atob(n[1]), a = new Uint8Array(i.length);
|
|
1778
|
+
for (let l = 0; l < i.length; l++)
|
|
1779
|
+
a[l] = i.charCodeAt(l);
|
|
1780
|
+
return new File([a], e, { type: s });
|
|
1623
1781
|
},
|
|
1624
1782
|
/**
|
|
1625
1783
|
* 从文件下载数据
|
|
@@ -1642,7 +1800,7 @@ const W = {
|
|
|
1642
1800
|
var n = document.createElement("a");
|
|
1643
1801
|
n.href = t, n.download = e || "", n.click(), window.URL.revokeObjectURL(n.href);
|
|
1644
1802
|
}
|
|
1645
|
-
},
|
|
1803
|
+
}, Q = {
|
|
1646
1804
|
/**
|
|
1647
1805
|
* 防抖函数,在指定的等待时间内,如果连续触发事件,则只在最后一次触发后执行函数。适用于像搜索输入框这种需要用户停止输入后才调用的场景
|
|
1648
1806
|
*
|
|
@@ -1652,15 +1810,15 @@ const W = {
|
|
|
1652
1810
|
* @returns 返回防抖后的函数。
|
|
1653
1811
|
*/
|
|
1654
1812
|
debounce(t, e, n = !0) {
|
|
1655
|
-
let r = null, s, i,
|
|
1656
|
-
const
|
|
1657
|
-
const
|
|
1658
|
-
|
|
1813
|
+
let r = null, s, i, a;
|
|
1814
|
+
const o = () => {
|
|
1815
|
+
const l = Date.now() - i;
|
|
1816
|
+
l < e && l > 0 ? r = setTimeout(o, e - l) : (r = null, n || (a = t.apply(this, s)));
|
|
1659
1817
|
};
|
|
1660
|
-
return (...
|
|
1818
|
+
return (...l) => {
|
|
1661
1819
|
i = Date.now();
|
|
1662
1820
|
const h = n && !r;
|
|
1663
|
-
return r || (r = setTimeout(
|
|
1821
|
+
return r || (r = setTimeout(o, e)), h && (a = t.apply(this, l), r || (l = null)), a;
|
|
1664
1822
|
};
|
|
1665
1823
|
},
|
|
1666
1824
|
/**
|
|
@@ -1675,8 +1833,8 @@ const W = {
|
|
|
1675
1833
|
let r = 0, s = null;
|
|
1676
1834
|
return (...i) => {
|
|
1677
1835
|
if (n === 1) {
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1836
|
+
const a = Date.now();
|
|
1837
|
+
a - r >= e && (t.apply(this, i), r = a);
|
|
1680
1838
|
} else n === 2 && (s || (s = setTimeout(() => {
|
|
1681
1839
|
s = null, t.apply(this, i);
|
|
1682
1840
|
}, e)));
|
|
@@ -1713,7 +1871,7 @@ const W = {
|
|
|
1713
1871
|
r++, r < Math.floor(n / e) && (t.call(this), setTimeout(this.recurve.bind(this, t, e, n), e));
|
|
1714
1872
|
}, e);
|
|
1715
1873
|
}
|
|
1716
|
-
},
|
|
1874
|
+
}, V = {
|
|
1717
1875
|
/**
|
|
1718
1876
|
* 校验字符串是否符合指定类型
|
|
1719
1877
|
*
|
|
@@ -1821,7 +1979,7 @@ const W = {
|
|
|
1821
1979
|
*/
|
|
1822
1980
|
tag(t, ...e) {
|
|
1823
1981
|
return e = e.map((n) => {
|
|
1824
|
-
switch (
|
|
1982
|
+
switch (y.getDataType(n)) {
|
|
1825
1983
|
case "Object":
|
|
1826
1984
|
return n || "{}";
|
|
1827
1985
|
case "Array":
|
|
@@ -1853,9 +2011,9 @@ const W = {
|
|
|
1853
2011
|
if (t.replace(r, "mm").length <= n)
|
|
1854
2012
|
return t;
|
|
1855
2013
|
for (var s = Math.floor(n / 2), i = s; i < t.length; i++) {
|
|
1856
|
-
let
|
|
1857
|
-
if (
|
|
1858
|
-
return
|
|
2014
|
+
let a = t.substring(e, i);
|
|
2015
|
+
if (a.replace(r, "mm").length >= n)
|
|
2016
|
+
return a;
|
|
1859
2017
|
}
|
|
1860
2018
|
return t;
|
|
1861
2019
|
},
|
|
@@ -1866,9 +2024,9 @@ const W = {
|
|
|
1866
2024
|
* @returns 转换后的字符串,如果值为空,则返回空字符串
|
|
1867
2025
|
*/
|
|
1868
2026
|
asString(t) {
|
|
1869
|
-
if (
|
|
2027
|
+
if (y.isEmpty(t))
|
|
1870
2028
|
return "";
|
|
1871
|
-
switch (
|
|
2029
|
+
switch (y.getDataType(t)) {
|
|
1872
2030
|
case "Object":
|
|
1873
2031
|
case "Array":
|
|
1874
2032
|
return JSON.stringify(t);
|
|
@@ -1937,8 +2095,8 @@ const W = {
|
|
|
1937
2095
|
d(g, "prefix", ""), d(g, "_getPrefixedKey", function(e, n) {
|
|
1938
2096
|
return n = n || {}, n.noPrefix ? e : g.prefix + e;
|
|
1939
2097
|
});
|
|
1940
|
-
let
|
|
1941
|
-
const
|
|
2098
|
+
let S = g;
|
|
2099
|
+
const Z = {
|
|
1942
2100
|
/**
|
|
1943
2101
|
* 将json对象转换为查询字符串
|
|
1944
2102
|
*
|
|
@@ -1964,49 +2122,51 @@ const Q = {
|
|
|
1964
2122
|
*/
|
|
1965
2123
|
query2Json(t = window.location.href, e = !0) {
|
|
1966
2124
|
const n = /([^&=]+)=([\w\W]*?)(&|$|#)/g, { search: r, hash: s } = new URL(t), i = [r, s];
|
|
1967
|
-
let
|
|
1968
|
-
for (let
|
|
1969
|
-
const
|
|
1970
|
-
if (
|
|
1971
|
-
const
|
|
1972
|
-
if (
|
|
1973
|
-
for (let u = 1; u <
|
|
2125
|
+
let a = {};
|
|
2126
|
+
for (let o = 0; o < i.length; o++) {
|
|
2127
|
+
const l = i[o];
|
|
2128
|
+
if (l) {
|
|
2129
|
+
const c = l.replace(/#|\//g, "").split("?");
|
|
2130
|
+
if (c.length > 1)
|
|
2131
|
+
for (let u = 1; u < c.length; u++) {
|
|
1974
2132
|
let f;
|
|
1975
|
-
for (; f = n.exec(
|
|
1976
|
-
|
|
2133
|
+
for (; f = n.exec(c[u]); )
|
|
2134
|
+
a[f[1]] = e ? decodeURIComponent(f[2]) : f[2];
|
|
1977
2135
|
}
|
|
1978
2136
|
}
|
|
1979
2137
|
}
|
|
1980
|
-
return
|
|
2138
|
+
return a;
|
|
1981
2139
|
}
|
|
1982
2140
|
};
|
|
1983
2141
|
export {
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
q as
|
|
1992
|
-
W as
|
|
1993
|
-
|
|
1994
|
-
|
|
2142
|
+
w as AjaxUtil,
|
|
2143
|
+
G as ArrayUtil,
|
|
2144
|
+
F as AudioPlayer,
|
|
2145
|
+
J as BrowserUtil,
|
|
2146
|
+
B as CanvasDrawer,
|
|
2147
|
+
j as ColorUtil,
|
|
2148
|
+
H as Cookie,
|
|
2149
|
+
q as CoordsUtil,
|
|
2150
|
+
W as DateUtil,
|
|
2151
|
+
K as DomUtil,
|
|
2152
|
+
C as ErrorType,
|
|
2153
|
+
v as EventDispatcher,
|
|
1995
2154
|
R as EventType,
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2155
|
+
X as FileUtil,
|
|
2156
|
+
Y as GeoJsonUtil,
|
|
2157
|
+
z as GeoUtil,
|
|
1999
2158
|
_ as GraphicType,
|
|
2000
|
-
|
|
2001
|
-
|
|
2159
|
+
x as HashMap,
|
|
2160
|
+
k as ImageUtil,
|
|
2161
|
+
I as LayerType,
|
|
2002
2162
|
m as MathUtil,
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2163
|
+
P as MeasureMode,
|
|
2164
|
+
L as ObjectState,
|
|
2165
|
+
T as ObjectUtil,
|
|
2166
|
+
Q as OptimizeUtil,
|
|
2167
|
+
S as StoreUtil,
|
|
2168
|
+
V as StringUtil,
|
|
2169
|
+
Z as UrlUtil,
|
|
2170
|
+
y as Util,
|
|
2171
|
+
$ as WebSocketClient
|
|
2012
2172
|
};
|