egovamap 0.35.38 → 0.35.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1569 +1,1569 @@
1
- var egovaBI = function (globeMap, gisMap, mapType) {
2
- function defaultValue(a, b) {
3
- if (a !== undefined && a !== null) {
4
- return a;
5
- }
6
- return b;
7
- }
8
-
9
- function getImgSize(url) {
10
- return new Promise((resolve, reject) => {
11
- let img = new Image();
12
- img.onload = function () {
13
- resolve({ width: img.width, height: img.height });
14
- img = null;
15
- };
16
- img.onerror = function () {
17
- resolve({ width: 0, height: 0 });
18
- img = null;
19
- };
20
- img.src = url;
21
- });
22
- }
23
-
24
- function interpolateColor(startColor, endColor, count) {
25
- if (count < 2) return [startColor, endColor];
26
-
27
- var start = rgbToRgbArray(startColor);
28
- var end = rgbToRgbArray(endColor);
29
- var end0 = end[0];
30
- var end1 = end[1];
31
- var end2 = end[2];
32
- var end3 = end[3];
33
- var start0 = start[0];
34
- var start1 = start[1];
35
- var start2 = start[2];
36
- var start3 = start[3];
37
-
38
- var r = end0 - start0;
39
- var g = end1 - start1;
40
- var b = end2 - start2;
41
- var opacity = end3 - start3;
42
- var step = 1.0 / count;
43
- var colors = [startColor];
44
- var _count = count - 1;
45
- for (var i = 1; i < _count; i++) {
46
- var interval = step * i;
47
- colors.push([
48
- Math.round(start0 + interval * r),
49
- Math.round(start1 + interval * g),
50
- Math.round(start2 + interval * b),
51
- start3 + interval * opacity,
52
- ]);
53
- }
54
- colors.push(endColor);
55
- return colors;
56
- }
57
-
58
- function rgbToRgbArray(color) {
59
- if (
60
- !color ||
61
- typeof color !== "string" ||
62
- (typeof color == "string" && color.indexOf("rgb") == -1)
63
- )
64
- return color;
65
-
66
- var r, g, b, a;
67
- var rgbaAttr = color.match(/[\d.]+/g);
68
- if (rgbaAttr.length >= 3) {
69
- r = parseInt(rgbaAttr[0]);
70
- g = parseInt(rgbaAttr[1]);
71
- b = parseInt(rgbaAttr[2]);
72
- if (rgbaAttr.length > 3) a = parseFloat(rgbaAttr[3]);
73
- else a = 1;
74
- }
75
- return [r, g, b, a];
76
- }
77
-
78
- // 查询idb是否存在表
79
- function checkObjectStore(storeName) {
80
- return new Promise((resolve, reject) => {
81
- // 打开网格数据库
82
- let idbRequest = window.indexedDB.open("regionDB");
83
- idbRequest.onblocked = function (event) {
84
- // 如果其他的一些页签加载了该数据库,在我们继续之前需要关闭它们
85
- // alert("请关闭其他由该站点打开的页签!");
86
- console.log("请关闭其他由该站点打开的页签!");
87
- };
88
- idbRequest.onerror = (event) => {
89
- console.log("数据库打开报错(checkObjectStore)");
90
- // resolve(undefined)
91
- reject(event.target.error.message);
92
- };
93
-
94
- idbRequest.onsuccess = () => {
95
- let db = idbRequest.result;
96
- // console.log('数据库打开成功(hasObjectStore)')
97
- resolve(db.objectStoreNames.contains(storeName));
98
- db.close();
99
- };
100
- });
101
- }
102
-
103
- function deal2DPoints(layerName, positions, options) {
104
- let datalist = [];
105
- let zoom = options.common.zoom;
106
- let clear = options.common.clear;
107
- let highLightType = -1;
108
- let infoStyle = null;
109
- let renderCanvas = null;
110
- if (options.option && options.option.renderCanvas !== undefined) {
111
- renderCanvas = options.option.renderCanvas;
112
- }
113
- let tagName = layerName;
114
- let clusterOption = null;
115
-
116
- let hasHover = null;
117
- let callback = null;
118
- datalist = positions.map(function (p) {
119
- if (options.textStyle.label) {
120
- for (const key in p) {
121
- if (
122
- key !== "id" &&
123
- key !== "x" &&
124
- key !== "y" &&
125
- key !== "objectID"
126
- ) {
127
- if (!p.label) p.label = [];
128
- var labelItem = {};
129
- labelItem[key] = p[key];
130
- p.label.push(labelItem);
131
- }
132
- }
133
- }
134
- p.minZoom = options.common.beginLevel;
135
- p.maxZoom = options.common.endLevel;
136
- p.symbolType = -1;
137
- p.symbolUrl = options.textStyle.symbolUrl || "location.png";
138
- if (options.selected && options.selected.hSymbolUrl)
139
- p.hSymbolUrl = options.selected.hSymbolUrl;
140
- p.scale = options.textStyle.scale;
141
- p.angle = options.textStyle.angle;
142
- // 适配选中效果的放大倍数和高亮图片
143
- if (options.selectStyle && options.selectStyle.enable) {
144
- if (options.selectStyle.scaleEnabled) {
145
- p.hScale = options.selectStyle.scaleFactor;
146
- }
147
- if (options.selectStyle.imgUrl) {
148
- p.hSymbolUrl = options.selectStyle.imgUrl;
149
- }
150
- }
151
- // 杭州现场,需要叠加图片和地图放大同时存在
152
- if (options.developer) {
153
- if (
154
- options.developer.enableScaleAndOverImage &&
155
- options.developer.scaleAndOverImageFactor
156
- ) {
157
- p.aScale = options.developer.scaleAndOverImageFactor;
158
- }
159
- }
160
- //classify symbol
161
- if (options.textStyle.enableClassify) {
162
- const customScheme = options.textStyle.customScheme;
163
- const classField = options.textStyle.classField;
164
- if (
165
- p[classField] &&
166
- Object.prototype.toString.call(customScheme) == "[object Array]" &&
167
- customScheme.length
168
- ) {
169
- customScheme.forEach((scheme) => {
170
- if (scheme.type == p[classField]) {
171
- scheme.imageUrl && (p.symbolUrl = scheme.imageUrl);
172
- }
173
- });
174
- }
175
- }
176
- //textValue
177
- if (options.textStyle.enableText) {
178
- let labelMinZoom = options.common.beginLevel;
179
- let labelMaxZoom = options.common.endLevel;
180
- if (options.textStyle.labelZoomEnabled) {
181
- labelMinZoom = options.textStyle.textBeginLevel;
182
- labelMaxZoom = options.textStyle.textEndLevel;
183
- }
184
- p.labelStyle = {
185
- type: "text",
186
- minZoom: labelMinZoom,
187
- maxZoom: labelMaxZoom,
188
- xoffset: options.textStyle.xoffset + "px",
189
- yoffset: options.textStyle.yoffset + "px",
190
- text: p.textValue,
191
- color: options.textStyle.fillColor,
192
- font: {
193
- size: options.textStyle.fontSize + "px",
194
- weight: options.textStyle.fontWeight,
195
- family: options.textStyle.family || "microsoft-yahei",
196
- },
197
- };
198
- }
199
- p.useLabelBg = options.textStyle.textBackground;
200
- if (p.useLabelBg) {
201
- p.labelBgStyle = {
202
- type: "picture-marker",
203
- url: options.textStyle.textBackgroundUrl,
204
- };
205
- }
206
- return p;
207
- });
208
-
209
- return new Promise((resolve, reject) => {
210
- try {
211
- let args = {
212
- datalist: datalist,
213
- zoom: zoom,
214
- clear: clear,
215
- highLightType: highLightType,
216
- infoStyle: infoStyle,
217
- renderCanvas: renderCanvas,
218
- tagName: tagName,
219
- clusterOption: null,
220
- hasHover: hasHover,
221
- callback: callback,
222
- };
223
- if (options.clusterStyle.clusterEnabled) {
224
- clusterOption = {
225
- clusterType: options.clusterStyle.clusterType,
226
- distance: options.clusterStyle.clusterDistance,
227
- style: null,
228
- critical: options.clusterStyle.critical || 10,
229
- level: options.clusterStyle.level,
230
- clickShowSpiralPoint: options.clusterStyle.clickShowSpiralPoint,
231
- labelStyle: {
232
- type: "text",
233
- color: options.clusterStyle.fillColor,
234
- text: "",
235
- xoffset: options.clusterStyle.xoffset + "px",
236
- yoffset: options.clusterStyle.yoffset + "px",
237
- font: {
238
- size: options.clusterStyle.fontSize + "px",
239
- weight: options.clusterStyle.fontWeight || "normal",
240
- family: options.clusterStyle.family || "microsoft-yahei",
241
- },
242
- },
243
- };
244
-
245
- let useCustomClusterStyle =
246
- options.clusterStyle.symbolUrl &&
247
- options.clusterStyle.useCustomStyle;
248
- let clusterStyle = {
249
- type: "simple-marker",
250
- style: "circle",
251
- color: [255, 168, 0, 200],
252
- size: 25 * options.clusterStyle.scale + "px",
253
- outline: {
254
- color: [255, 168, 0, 200],
255
- width: 2,
256
- },
257
- };
258
- if (options.clusterStyle.style) {
259
- clusterStyle = Object.assign(
260
- clusterStyle,
261
- options.clusterStyle.style
262
- );
263
- }
264
- clusterOption.style = clusterStyle;
265
- if (useCustomClusterStyle) {
266
- getImgSize(options.clusterStyle.symbolUrl).then((szie) => {
267
- clusterStyle = {
268
- type: "picture-marker",
269
- url: options.clusterStyle.symbolUrl,
270
- width: szie.width * options.clusterStyle.scale + "px",
271
- height: szie.height * options.clusterStyle.scale + "px",
272
- };
273
- clusterOption.style = clusterStyle;
274
- args.clusterOption = clusterOption;
275
- resolve(args);
276
- });
277
- } else {
278
- args.clusterOption = clusterOption;
279
- resolve(args);
280
- }
281
- } else {
282
- resolve(args);
283
- }
284
- } catch (err) {
285
- reject(err);
286
- }
287
- });
288
- }
289
-
290
- /*
291
- * @description:新参数格式的旧热力接口,主要用来做中间层参数格式转换
292
- * @method showHeatImage3D_BI
293
- * @param {String} layerName 热力参数数组
294
- * @param {Array} data 热力值和坐标的数据数组
295
- * @param {Object} options 配置项
296
- * @param {Object} options.heatOpt 热力配置项
297
- * @param {Object} options.commonOpt 通用配置项
298
- *
299
- * @return {Void}} 无返回
300
- *
301
- * @author: Hetianhong
302
- * @date: 2021-08-31 14:13:42
303
- */
304
- this.showHeatImage3D_BI = function (layerName, data, option) {
305
- //data必须包含x y 和 value属性
306
- if (
307
- data.length === 0 ||
308
- !data[0].hasOwnProperty("x") ||
309
- !data[0].hasOwnProperty("y") ||
310
- !data[0].hasOwnProperty("value")
311
- ) {
312
- return;
313
- }
314
- if (globeMap != null) {
315
- //hth 此处进行参数转换
316
- let commonOpt = option.commonOpt; // 通用配置项
317
- let heatOpt = option.heatOpt; // 热力配置项
318
-
319
- let info = {};
320
- let zoom = defaultValue(commonOpt.zoom, false);
321
- let clear = defaultValue(commonOpt.clear, true);
322
- let options = {
323
- heading: defaultValue(commonOpt.heading, 0),
324
- pitch: defaultValue(commonOpt.pitch, -45),
325
- range: defaultValue(commonOpt.range, 8000),
326
- maxDataLength: defaultValue(commonOpt.maxDataLength, 5),
327
- layerName: layerName,
328
- };
329
-
330
- // 开始组装info
331
- //组装info.data,其实也没啥组装的
332
- info.data = data;
333
-
334
- //组装info.options
335
- info.options = {
336
- clampStyle: heatOpt.heatType === 0 ? 0 : 3, // 如果设置了为0,则为0,其余则全部为旧逻辑的3绘制方式,即贴地贴建筑
337
- renderType: defaultValue(heatOpt.renderType, "line"),
338
- dynamicGranularity: defaultValue(heatOpt.dynamicGranularity, false),
339
- granularity: defaultValue(heatOpt.granularity, 500),
340
- maxHeight: defaultValue(heatOpt.maxHeight, -1),
341
- height: defaultValue(heatOpt.height, 10),
342
- radiusScale: defaultValue(heatOpt.radiusScale, 1.0),
343
- radius: defaultValue(heatOpt.radius, 40),
344
- gradient: defaultValue(heatOpt.gradient, {
345
- 0.35: "rgb(136,218,104)",
346
- 0.7: "rgb(241,238,124)",
347
- 1.0: "rgb(243,118,116)",
348
- }),
349
- //动态改变热力半径
350
- dynamicRadius: defaultValue(heatOpt.dynamicRadius, undefined),
351
- dynamicLevel: defaultValue(heatOpt.dynamicLevel, undefined),
352
- // 下面的部分不建议传,逐步舍弃
353
- gridSize: defaultValue(heatOpt.gridSize, null),
354
- blur: defaultValue(heatOpt.blur, 0.85),
355
- };
356
-
357
- // 转换过后,使用旧的参数格式调用原热力接口
358
- globeMap.showHeatImage3D(info, zoom, clear, options);
359
- }
360
- };
361
-
362
- /*
363
- * @description:打点和聚类接口进行整合后的新接口
364
- * @method drawPoint
365
- * @param {String} layerName 图层名
366
- * @param {Array} positions 位置数组
367
- * @param {Object} options 配置项
368
- *
369
- * @return {Void} 无返回
370
- *
371
- * @author: Hetianhong
372
- * @date: 2021-09-09 14:49:49
373
- */
374
- this.drawPoints = function (layerName, positions, options) {
375
- let drawData = function (layerName, positions, options) {
376
- if (globeMap && mapType == "globe") {
377
- globeMap.drawPoints(layerName, positions, options);
378
- } else if (gisMap && mapType == "map") {
379
- deal2DPoints(layerName, positions, options).then((args) => {
380
- gisMap.showMultiObjectCurrentPosition(
381
- args.datalist,
382
- args.zoom,
383
- args.clear,
384
- args.highLightType,
385
- args.infoStyle,
386
- args.renderCanvas,
387
- args.tagName,
388
- options.clickCallback,
389
- options.mouseOverCallback,
390
- args.clusterOption,
391
- args.hasHover,
392
- layerName,
393
- options.mouseOutCallback,
394
- options.option
395
- );
396
- });
397
- }
398
- };
399
-
400
- if (!options.usageID && !options.phyLayerID) {
401
- drawData(layerName, positions, options);
402
- return;
403
- }
404
- let queryFeature = (queryParams) => {
405
- return new Promise(function (resolve) {
406
- let cb = function (result) {
407
- resolve(result);
408
- };
409
- if (gisMap) {
410
- gisMap.queryFeature(queryParams, cb);
411
- } else {
412
- return Promise.resolve(undefined);
413
- }
414
- });
415
- };
416
- var filterString = "1=1";
417
- if (options.filterString) filterString = options.filterString + "";
418
- let queryParams = {
419
- layerID: options.usageID || options.phyLayerID,
420
- where: filterString,
421
- outGeometry: true,
422
- };
423
- queryFeature(queryParams).then(function (resultData) {
424
- if (!resultData) {
425
- console.log("没有查询到数据,请检查查询参数");
426
- return;
427
- }
428
- let dataCache = [];
429
- let errorSize = 0;
430
- resultData.forEach((element) => {
431
- let x, y;
432
- if (element.geometry) {
433
- x = element.geometry.x;
434
- y = element.geometry.y;
435
- }
436
- if (x && y) {
437
- let item = { ...element.attributes, x, y };
438
- if (globeMap && mapType == "globe" && options.primaryKey) {
439
- let primaryKeyValue = item[options.primaryKey];
440
- primaryKeyValue != undefined &&
441
- (item["attributes"] = {
442
- objectID: primaryKeyValue,
443
- });
444
- }
445
- dataCache.push(item);
446
- } else {
447
- errorSize++;
448
- }
449
- });
450
- if (errorSize > 0) {
451
- console.error(`${errorSize}个点格式错误,无法正常加载`);
452
- }
453
- if (options.callback && typeof options.callback === "function") {
454
- options.callback(dataCache);
455
- }
456
- drawData(layerName, dataCache, options);
457
- });
458
- };
459
- this.getLabel = function (attributes) {
460
- if (!attributes) return;
461
- var label = [],
462
- field = {};
463
- for (var key in attributes) {
464
- field = {};
465
- field[key] = attributes[key];
466
- label.push(field);
467
- }
468
- return label;
469
- };
470
- this.drawParts = function (options, data, callback) {
471
- var self = this;
472
- async function showParts(data) {
473
- var drawParam = options.drawParam || {};
474
- var ctrOption = drawParam.clusterOption;
475
- var zoom = options.zoom === undefined ? true : !!options.zoom;
476
- var clusterOption = null;
477
- if (ctrOption) {
478
- clusterOption = {
479
- clusterType: ctrOption.clusterType,
480
- level: ctrOption.level || 0,
481
- style: {
482
- type: "simple-marker",
483
- style: "circle",
484
- color: ctrOption.color || [255, 0, 0, 0.6],
485
- size: (ctrOption.size || 20) + "px",
486
- outline: {
487
- //if outline has been specified
488
- color: ctrOption.outlineColor || [255, 168, 0, 1],
489
- width: ctrOption.outlineWidth || 2,
490
- },
491
- },
492
- critical: ctrOption.critical || 10,
493
- clickShowSpiralPoint: ctrOption.clickShowSpiralPoint,
494
- labelStyle: {
495
- type: "text",
496
- color: ctrOption.labelColor || [255, 255, 255, 1],
497
- text: "",
498
- zlevel: ctrOption.labelZlevel || 1,
499
- xoffset: (ctrOption.labelXOffset || 0) + "px",
500
- yoffset: (ctrOption.labelYOffset || 0) + "px",
501
- font: ctrOption.labelFont || {
502
- family: "Arial",
503
- size: 10,
504
- },
505
- },
506
- distance: ctrOption.distance || 50,
507
- };
508
- if(ctrOption.symbol && ctrOption.symbol.url) {
509
- var size = await getImgSize(ctrOption.symbol.url);
510
- var scale = (ctrOption.symbol.scale) || 1;
511
- var clusterStyle = {
512
- type: "picture-marker",
513
- url: ctrOption.symbol.url,
514
- width: size.width * scale + "px",
515
- height: size.height * scale + "px",
516
- };
517
- clusterOption.style = clusterStyle;
518
- }
519
- }
520
- var param = [
521
- data,
522
- zoom,
523
- false,
524
- null,
525
- null,
526
- false,
527
- drawParam.tagName,
528
- drawParam.clickCallback,
529
- drawParam.mouseOverCallback,
530
- clusterOption,
531
- false,
532
- drawParam.layerName,
533
- drawParam.callback,
534
- drawParam.drawOptions,
535
- ];
536
- //三维聚类参数
537
- var globeOptions = {
538
- zoom: true,
539
- scale: 0.9,
540
- clear: true,
541
- nearFarScalar: [8000, 1.0, 10000, 0.6],
542
- clickCallBack: drawParam.clickCallback,
543
- layerName: drawParam.layerName,
544
- minSize: 30,
545
- clusterLimit: 20,
546
- style: "default",
547
- disableDepthTestDistance: drawParam.disableDepthTestDistance,
548
- clusterImageInfo: {
549
- horizontalOrigin: "center",
550
- verticalOrigin: "bottom",
551
- cssStyle: {
552
- borderRadius: 500,
553
- fillColor: "rgba(0,0,0,0.7)",
554
- borderLineWidth: 3,
555
- borderLineColor: "rgba(250,140,0,0.9)",
556
- paddingX: 15,
557
- paddingY: 6,
558
- marginBottom: 2,
559
- },
560
- textStyle: {
561
- font: "60px Helvetica",
562
- fillColor: "rgba(220,220,220,1.0)",
563
- outlineColor: "black",
564
- outlineWidth: 1,
565
- padding: 1,
566
- textScale: 0.5,
567
- textStartX: 40,
568
- textStartY: 15,
569
- },
570
- },
571
- };
572
- if (globeMap) {
573
- globeMap.addClusterLayer({
574
- data,
575
- options: globeOptions,
576
- });
577
- } else if (gisMap) {
578
- gisMap.showMultiObjectCurrentPosition(...param);
579
- }
580
- }
581
-
582
- if (data) {
583
- showParts(data);
584
- } else {
585
- let queryFromGIS = () => {
586
- let queryParam = options.queryParam;
587
- var subTypeName = options.subTypeName;
588
- var subUniqueCode = options.subUniqueCode;
589
- let queryCallback = function (featureInfos) {
590
- var features = featureInfos[queryParam.phyLayerIDs];
591
- if (features.length == 0) {
592
- callback && callback([]);
593
- return;
594
- }
595
- if (!features || !features.length) return;
596
- var symbolUrl = "";
597
- if (subUniqueCode.indexOf("http") > -1) {
598
- symbolUrl = subUniqueCode;
599
- } else if (subUniqueCode.indexOf(".") > -1) {
600
- symbolUrl = subUniqueCode;
601
- } else {
602
- symbolUrl = "".concat(subUniqueCode, ".png");
603
- if (globeMap)
604
- symbolUrl = queryParam.gisServerURL
605
- ? `${queryParam.gisServerURL}/symbol/${symbolUrl}`
606
- : symbolUrl;
607
- }
608
- var map = globeMap || gisMap;
609
- //验证图标是否可查询
610
- map.getMapConfig("serverURL", function (key, data) {
611
- var symbolServiceURL = `${data}/symbol`;
612
- var picUrl =
613
- symbolUrl.indexOf("http") > -1 || symbolUrl.indexOf("https") > -1
614
- ? symbolUrl
615
- : `${symbolServiceURL}/${symbolUrl}`;
616
- getImgSize(picUrl).then((size) => {
617
- var dataList = features.map(function (feature) {
618
- return Object.assign(
619
- {},
620
- {
621
- x: feature.geometry.x,
622
- y: feature.geometry.y,
623
- },
624
- {
625
- attributes: feature.attributes,
626
- // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
627
- symbolType: -1,
628
- symbolUrl:
629
- size.width || size.height
630
- ? picUrl
631
- : globeMap
632
- ? `${symbolServiceURL}/20100.png`
633
- : `20100.png`,
634
- scale: 0.5,
635
- }
636
- );
637
- });
638
- callback && callback(dataList);
639
- if (!options.onlyGetData) {
640
- showParts(dataList);
641
- }
642
- });
643
- });
644
- };
645
- if (gisMap) {
646
- gisMap.queryPhylayerFeatures(queryParam, queryCallback);
647
- }
648
- };
649
- queryFromGIS();
650
- }
651
- };
652
-
653
- this.drawOtherParts = function (options, data) {
654
- const geomType = options.geomType;
655
- if (globeMap && geomType != 1) {
656
- this.drawOtherPartsGlobe(options, data);
657
- return;
658
- }
659
-
660
- var self = this;
661
- let queryParam = options.queryParam || {};
662
- function showParts(data) {}
663
-
664
- if (data) {
665
- showParts(data);
666
- } else {
667
- const layerID = queryParam.phyLayerIDs;
668
- const layerName = queryParam.layerName;
669
- const keyField = null;
670
- const keyValue = null;
671
- const clearMap = queryParam.clearMap;
672
- let inStyle = queryParam.style || {
673
- color: "blue",
674
- };
675
- let inHStyle = queryParam.hStyle || {
676
- color: "blue",
677
- };
678
- let style = null,
679
- hStyle = null;
680
- if (geomType == 1) {
681
- } else if (geomType == 2) {
682
- style = {
683
- type: "simple-line", // autocasts as new SimpleLineSymbol()
684
- color: inStyle.color || "blue",
685
- width: inStyle.width || "2px",
686
- style: inStyle.style || "solid",
687
- cap: inStyle.cap || "round",
688
- join: inStyle.join || "round",
689
- };
690
- hStyle = {
691
- type: "simple-line", // autocasts as new SimpleLineSymbol()
692
- color: inHStyle.color || "red",
693
- width: inHStyle.width || inStyle.width || "2px",
694
- style: inHStyle.style || inStyle.style || "solid",
695
- cap: inHStyle.cap || inStyle.cap || "round",
696
- join: inHStyle.join || inStyle.join || "round",
697
- };
698
- } else if (geomType == 3) {
699
- style = {
700
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
701
- color: inStyle.color || [51, 51, 204, 0.9],
702
- style: inStyle.style || "solid",
703
- outline: {
704
- // autocasts as new SimpleLineSymbol()
705
- color: inStyle.outlineColor || "blue",
706
- width: inStyle.outlineWidth || "1px",
707
- style: inStyle.outlineStyle || "solid",
708
- cap: inStyle.outlineCap || "round",
709
- join: inStyle.outlineJoin || "round",
710
- },
711
- };
712
- hStyle = {
713
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
714
- color: inHStyle.color || [51, 51, 204, 0.9],
715
- style: inHStyle.style || inStyle.style || "solid",
716
- outline: {
717
- // autocasts as new SimpleLineSymbol()
718
- color: inHStyle.outlineColor || "red",
719
- width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
720
- style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
721
- cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
722
- join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
723
- },
724
- };
725
- }
726
- const bZoom = queryParam.bZoom || true;
727
- const randomColor = null;
728
- const labelField = null;
729
- const labelstyle = null;
730
- const geometry = null;
731
- const where = queryParam.where || "1=1";
732
- const opts = {
733
- ...queryParam.options,
734
- layerId: layerName,
735
- mouseOverCallback: queryParam.mouseOverCallback,
736
- };
737
-
738
- let param = [
739
- layerID,
740
- keyField,
741
- keyValue,
742
- clearMap,
743
- style,
744
- hStyle,
745
- bZoom,
746
- randomColor,
747
- labelField,
748
- labelstyle,
749
- geometry,
750
- where,
751
- null,
752
- null,
753
- opts,
754
- null,
755
- null,
756
- null,
757
- null,
758
- null,
759
- null,
760
- queryParam.clickCallback,
761
- ];
762
- //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
763
- if (globeMap) {
764
- gisMap.locateFeatureByIDs(...param);
765
- } else if (gisMap) {
766
- gisMap.locateFeatureByIDs(...param);
767
- }
768
- }
769
- };
770
-
771
- this.drawOtherPartsGlobe = function (options, data) {
772
- const geomType = options.geomType;
773
- const drawParam = options.drawParam || {};
774
- const color = drawParam.color || "rgba(255, 0.0, 0.0, 0.8)";
775
- const clickColor = drawParam.clickColor || "rgba(255, 255, 0.0, 0.8)";
776
- function showParts(features) {
777
- if (!globeMap) {
778
- return;
779
- }
780
-
781
- if (geomType == 2) {
782
- var infoJson = features.map((feature) => {
783
- var paths = feature.geometry.paths[0];
784
- var positions = paths.map((position) => {
785
- return {
786
- x: position[0],
787
- y: position[1],
788
- };
789
- });
790
- return {
791
- positions,
792
- type: "color",
793
- color: color,
794
- width: 2,
795
- attributes: feature.attributes,
796
- };
797
- });
798
-
799
- var zoom = true;
800
- var clear = true;
801
- var layerName = drawParam.layerName;
802
- var options = {
803
- heading: 0,
804
- pitch: -90,
805
- range: null,
806
- minZoom: 0,
807
- maxZoom: 100,
808
- clickColor: clickColor,
809
- clickWidth: 5,
810
- bloom: false,
811
- };
812
-
813
- globeMap.showPolyline(
814
- infoJson,
815
- zoom,
816
- clear,
817
- options,
818
- layerName,
819
- drawParam.clickCallback
820
- );
821
- } else if (geomType == 3) {
822
- var infoJson = features.map((feature) => {
823
- var rings = feature.geometry.rings[0];
824
- var positions = rings.map((position) => {
825
- return {
826
- x: position[0],
827
- y: position[1],
828
- };
829
- });
830
-
831
- return {
832
- positions,
833
- type: "polygon",
834
- colorType: "color",
835
- color: color,
836
- attributes: feature.attributes,
837
- };
838
- });
839
-
840
- var zoom = true;
841
- var clear = true;
842
- var layerName = drawParam.layerName;
843
- var drawWay = "entityWay";
844
- var options = {
845
- heading: 0,
846
- pitch: -90,
847
- range: null,
848
- minZoom: 0,
849
- maxZoom: 24,
850
- clickColor: clickColor,
851
- clickWidth: 15,
852
- heightAnimation: false,
853
- };
854
- globeMap.showPolygon(
855
- infoJson,
856
- drawWay,
857
- zoom,
858
- clear,
859
- options,
860
- layerName,
861
- drawParam.clickCallback
862
- );
863
- }
864
- }
865
-
866
- if (data) {
867
- showParts(data);
868
- } else {
869
- let queryFromGIS = () => {
870
- let queryParam = options.queryParam;
871
- let queryCallback = function (featureInfos) {
872
- var features = featureInfos[queryParam.phyLayerIDs];
873
- if (!features || !features.length) return;
874
- showParts(features);
875
- };
876
- if (gisMap) {
877
- gisMap.queryPhylayerFeatures(queryParam, queryCallback);
878
- }
879
- };
880
- queryFromGIS();
881
- }
882
- };
883
-
884
- /*
885
- * @description:新的轨迹线接口
886
- * @method traceOperation
887
- * @param {Array} posArr 位置数组
888
- * @param {Object} options 配置项
889
- *
890
- * @return {Void} 无返回
891
- *
892
- * @author: Hetianhong
893
- * @date: 2021-09-09 14:49:49
894
- */
895
- this.traceOperation = function (posArr, options) {
896
- globeMap.traceOperation(posArr, options);
897
- };
898
- /*
899
- * @description:网格接口
900
- * 先查询idb的data,没有的话,再查询queryFeature的data
901
- * @method regionOperation
902
- * @param {Object} options 配置项
903
- * @param {Array} data 数据,可不传
904
- *
905
- * @return {Void} 无返回
906
- *
907
- * @author: Hetianhong
908
- * @date: 2021-10-19 17:27:02
909
- */
910
- this.regionOperation = function (options, data, callback, dataLoadCb) {
911
- function execOperation(data) {
912
- if (globeMap) {
913
- globeMap.regionOperation(options, data);
914
- callback && callback();
915
- } else if (gisMap) {
916
- gridPolygon2dOperation(options, data, callback, dataLoadCb);
917
- }
918
- }
919
-
920
- if (data) {
921
- execOperation(data);
922
- } else {
923
- if (!options.idbSetting.usageID) {
924
- return;
925
- }
926
-
927
- let storeName = !!globeMap
928
- ? "usageID"
929
- : "usage2D" + "_" + options.idbSetting.usageID;
930
- let queryFromGIS = () => {
931
- let filterString = options.idbSetting.filterString || "1=1";
932
- let queryParam = {
933
- layerID: options.idbSetting.usageID,
934
- where: filterString,
935
- geometry: "",
936
- outGeometry: true,
937
- options: {
938
- originalData: true,
939
- },
940
- };
941
- //二维地图不获取原始数据
942
- if (!globeMap) queryParam.options.originalData = false;
943
- let queryCallback = function (featureInfos) {
944
- execOperation(featureInfos);
945
- };
946
- if (gisMap) {
947
- gisMap.queryFeature(queryParam, queryCallback);
948
- }
949
- };
950
-
951
- if (!options.idbSetting.enabled) {
952
- // 直接查询
953
- queryFromGIS();
954
- } else {
955
- // 查询是否存在表
956
- checkObjectStore(storeName).then(function (hasObjStore) {
957
- if (hasObjStore) {
958
- // 如果有,读取本地
959
- execOperation();
960
- } else {
961
- // 如果没有,查询queryFeature
962
- queryFromGIS();
963
- }
964
- });
965
- }
966
- }
967
- };
968
- this.cancelHighlightedRegion = function (layerName) {
969
- globeMap.cancelHighlightedRegion(layerName);
970
- };
971
- /*
972
- * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
973
- * @method showPolyline_BI
974
- * @param {参数类型} 参数名 参数说明
975
- *
976
- * @return {返回值类型} 返回值说明
977
- *
978
- * @author: Hetianhong
979
- * @date: 2021-11-11 15:40:31
980
- */
981
- this.showPolyline_BI = function (layerName, positions = [], options = {}) {
982
- if (globeMap !== null) {
983
- // 默认参数
984
- let defaultOpt = {
985
- // 样式类
986
- styleOpt: {
987
- period: 4, // 动画线段的周期,越短越快
988
- image: "road.png", // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
989
- repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
990
- repeatY: 1, //纵向纹理重复(type为image限定)
991
- glowPower: 0, //中心亮度
992
- intensity: 1.2, //纹理图片颜色强度
993
- gapColor: "rgba(0, 0, 0, 0)", //间隙颜色(type为dash限定)
994
- dashLength: 15, //间隙宽(type为dash限定)
995
- outlineWidth: 0, // 边框线宽(type为outline限定)
996
- outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
997
- type: "color", // 线条类型,有 image color dash outline glow
998
- width: 10,
999
- color: "rgba(255,255,0,1)",
1000
- },
1001
- // 视角缩放类
1002
- zoomOpt: {
1003
- //zoom参数
1004
- heading: 0,
1005
- pitch: -90,
1006
- range: null,
1007
- //可视级别
1008
- minZoom: 0,
1009
- maxZoom: 24,
1010
- //泛光绘制
1011
- // 下面两项,不暴露,全部为false
1012
- bloom: false,
1013
- merge: false,
1014
- },
1015
- // 交互类
1016
- interactOpt: {
1017
- //click相关
1018
- clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
1019
- clickWidth: 30, // 点击后的宽度
1020
- clickCallback: undefined, // function(e) {console.log('click polyline', e)},
1021
- mouseOverCallBack: undefined,
1022
- },
1023
- };
1024
- let getMergedOptions = (options) => {
1025
- let mergedOptions = {};
1026
- mergedOptions.styleOpt = Object.assign(
1027
- {},
1028
- defaultOpt.styleOpt,
1029
- options.styleOpt
1030
- );
1031
- mergedOptions.zoomOpt = Object.assign(
1032
- {},
1033
- defaultOpt.zoomOpt,
1034
- options.zoomOpt
1035
- );
1036
- mergedOptions.interactOpt = Object.assign(
1037
- {},
1038
- defaultOpt.interactOpt,
1039
- options.interactOpt
1040
- );
1041
- return mergedOptions;
1042
- };
1043
- let mergedOptions = getMergedOptions(options);
1044
-
1045
- let opt = {};
1046
- // let styleOpt = options.styleOpt;
1047
- // let zoomOpt = options.zoomOpt;
1048
- // let interactOpt = options.interactOpt;
1049
- //hth 此处进行参数转换
1050
- switch (mergedOptions.styleOpt.type) {
1051
- case "image":
1052
- opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
1053
- opt.image = defaultValue(mergedOptions.styleOpt.image, "road.png"); //纹理图片,data3d/polyline/目录下
1054
- opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
1055
- opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
1056
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
1057
- opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
1058
- break;
1059
- case "glow":
1060
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
1061
- break;
1062
- case "dash":
1063
- opt.gapColor = defaultValue(
1064
- mergedOptions.styleOpt.gapColor,
1065
- "rgba(0, 0, 0, 0)"
1066
- ); //间隙颜色
1067
- opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
1068
- break;
1069
- case "outline":
1070
- opt.outlineWidth = defaultValue(
1071
- mergedOptions.styleOpt.outlineWidth,
1072
- 0
1073
- );
1074
- opt.outlineColor = defaultValue(
1075
- mergedOptions.styleOpt.outlineColor,
1076
- "rgba(0, 0, 0, 0)"
1077
- );
1078
- break;
1079
- default:
1080
- // color
1081
- }
1082
-
1083
- opt.type = mergedOptions.styleOpt.type;
1084
- opt.width = mergedOptions.styleOpt.width;
1085
- opt.color = mergedOptions.styleOpt.color;
1086
-
1087
- // 遍历位置数组中的每一项
1088
- for (let pos of positions) {
1089
- // 遍历opt中每一个key赋值到每一个pos中
1090
- for (let k in opt) {
1091
- pos[k] = opt[k];
1092
- }
1093
- }
1094
-
1095
- let zoom = mergedOptions.zoomOpt.zoom;
1096
- let clear = mergedOptions.zoomOpt.clear;
1097
- let clickCallback = mergedOptions.interactOpt.clickCallback;
1098
- let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack;
1099
- let commonOpt = {
1100
- //zoom参数
1101
- heading: mergedOptions.zoomOpt.heading,
1102
- pitch: mergedOptions.zoomOpt.pitch,
1103
- range: mergedOptions.zoomOpt.range,
1104
- //可视级别
1105
- minZoom: mergedOptions.zoomOpt.minZoom,
1106
- maxZoom: mergedOptions.zoomOpt.maxZoom,
1107
- //click相关
1108
- clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
1109
- clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
1110
- //泛光绘制
1111
- // 下面两项,不暴露,全部为false
1112
- bloom: false,
1113
- merge: false,
1114
- };
1115
-
1116
- globeMap.showPolyline(
1117
- positions,
1118
- zoom,
1119
- clear,
1120
- commonOpt,
1121
- layerName,
1122
- clickCallback,
1123
- mouseOverCallBack
1124
- );
1125
- }
1126
- };
1127
- /*
1128
- * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
1129
- * @method activeLayer
1130
- * @param {String} layerName 图层名
1131
- * @param {Object} options 配置项
1132
- * @param {String} options.type 操作类型,'clear', 'active'
1133
- * @param {Boolean} options.zoom 是否缩放
1134
- * @param {Object} filter 过滤项
1135
- * @param {String} filter.keyFieldName 过滤键名
1136
- * @param {Array} filter.values 过滤值内容数组
1137
- *
1138
- * @return {返回值类型} 返回值说明
1139
- *dataLoadCb:加载状态函数
1140
- * @author: Hetianhong
1141
- * @date: 2021-11-26 09:49:16
1142
- */
1143
- this.activeLayer = function (layerName, options, filter) {
1144
- if (globeMap != null && mapType == "globe") {
1145
- globeMap.activeLayer(layerName, options, filter);
1146
- }
1147
- if (gisMap != null && mapType == "map") {
1148
- gisMap.activeLayer(layerName, options, filter);
1149
- }
1150
- };
1151
-
1152
- this.deActiveLayer = function (layerName, filter) {
1153
- if (gisMap != null && mapType == "map") {
1154
- gisMap.deActiveLayer(layerName, filter);
1155
- }
1156
- };
1157
-
1158
- function gridPolygon2dOperation(options, data, callback, dataLoadCb) {
1159
- var storeName = `usage2D_${options.idbSetting.usageID}`;
1160
- function showGrid(realData) {
1161
- // 转换一下
1162
- var geometries = [];
1163
- var extraGeometries = [];
1164
- var specialAreaS = options.specialAreaS; //玲珑平台分类设色
1165
- for (var i = 0; i < realData.length; i++) {
1166
- var feature = realData[i];
1167
- var geom = feature.geometry;
1168
- geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
1169
- var hasPush = false;
1170
- if (specialAreaS && specialAreaS.length > 0) {
1171
- for (var j = 0; j < specialAreaS.length; j++) {
1172
- var specialArea = specialAreaS[j];
1173
- if (!specialArea.geometries) {
1174
- specialArea.geometries = [];
1175
- }
1176
- var attributes = JSON.parse(JSON.stringify(feature.attributes));
1177
- let filterResult = new Function(
1178
- `return ${specialArea.statusControl.compiled}`
1179
- )().call(null, attributes);
1180
- if (filterResult == true) {
1181
- specialArea.geometries.push(geom);
1182
- hasPush = true;
1183
- }
1184
- }
1185
- }
1186
- !hasPush && geometries.push(geom);
1187
- }
1188
- if (options.specialArea && options.selectedSetting.selected.length) {
1189
- var extraIds = options.selectedSetting.selected.map((s) => s.selectID);
1190
- for (var i = geometries.length - 1; i > -1; i--) {
1191
- var geom = geometries[i];
1192
- if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
1193
- geometries.splice(i, 1);
1194
- extraGeometries.push(geom);
1195
- if (extraGeometries.length === extraIds.length) break;
1196
- }
1197
- }
1198
- }
1199
- var color = options.customColor
1200
- ? interpolateColor(
1201
- options.customColor[0],
1202
- options.customColor[1],
1203
- Math.min(geometries.length, 10)
1204
- )
1205
- : 10;
1206
- if (options.setFieldColor && options.layeredColor) {
1207
- var colorConfig = options.layeredColor(geometries);
1208
- geometries = colorConfig.data;
1209
- color = colorConfig.color;
1210
- }
1211
- var lfcOpt = {
1212
- minZoom: options.visiblitySetting.beginLevel,
1213
- maxZoom: options.visiblitySetting.endLevel,
1214
- layerId: options.layerName,
1215
- comCallbak: callback,
1216
- order: options.order,
1217
- inverse: options.inverse,
1218
- ...options.option, // option的其他参数
1219
- };
1220
- if (options.labelSetting.labelZoomEnabled == "show") {
1221
- lfcOpt.labelMinZoom = options.labelSetting.labelMinZoom;
1222
- lfcOpt.labelMaxZoom = options.labelSetting.labelMaxZoom;
1223
- }
1224
- gisMap.locateFeatureByCoords(
1225
- geometries,
1226
- "polygon",
1227
- options.layerName, // id,如果已经有attributes就没用了
1228
- options.style, // style
1229
- options.highlightStyle, // highlightStyle
1230
- options.commonSetting.zoom, // zoom
1231
- options.keyFieldName,
1232
- options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
1233
- options.labelStyle, // labelStyle
1234
- color,
1235
- false, // renderCanvas
1236
- true, // singleSelect
1237
- lfcOpt,
1238
- options.layerName, // layerTag
1239
- options.eventSetting.clickCallback,
1240
- options.eventSetting.mouseMoveCallback
1241
- );
1242
- if (extraGeometries.length) {
1243
- var lfceOpt = {
1244
- minZoom: options.visiblitySetting.beginLevel,
1245
- maxZoom: options.visiblitySetting.endLevel,
1246
- layerId: options.layerName,
1247
- order: options.order,
1248
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
1249
- };
1250
- if (options.labelSetting.labelZoomEnabled == "show") {
1251
- lfceOpt.labelMinZoom = options.labelSetting.labelMinZoom;
1252
- lfceOpt.labelMaxZoom = options.labelSetting.labelMaxZoom;
1253
- }
1254
- gisMap.locateFeatureByCoords(
1255
- extraGeometries,
1256
- "polygon",
1257
- options.layerName, // id,如果已经有attributes就没用了
1258
- options.specialAreaStyle, // style
1259
- options.highlightStyle, // highlightStyle
1260
- false, // zoom
1261
- options.keyFieldName,
1262
- options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
1263
- options.specialAreaLabelStyle, // labelStyle
1264
- false, // randomColor
1265
- false, // renderCanvas
1266
- true, // singleSelect
1267
- lfceOpt,
1268
- options.layerName, // layerTag
1269
- options.eventSetting.clickCallback,
1270
- options.eventSetting.mouseMoveCallback
1271
- );
1272
- }
1273
- if (specialAreaS && specialAreaS.length > 0) {
1274
- var lfcsOpt = {
1275
- minZoom: options.visiblitySetting.beginLevel,
1276
- maxZoom: options.visiblitySetting.endLevel,
1277
- layerId: options.layerName,
1278
- comCallbak: callback,
1279
- order: options.order,
1280
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
1281
- };
1282
- if (options.labelSetting.labelZoomEnabled == "show") {
1283
- lfcsOpt.labelMinZoom = options.labelSetting.labelMinZoom;
1284
- lfcsOpt.labelMaxZoom = options.labelSetting.labelMaxZoom;
1285
- }
1286
- for (var j = 0; j < specialAreaS.length; j++) {
1287
- var specialArea = specialAreaS[j];
1288
- if (specialArea.geometries.length > 0) {
1289
- gisMap.locateFeatureByCoords(
1290
- specialArea.geometries,
1291
- "polygon",
1292
- options.layerName, // id,如果已经有attributes就没用了
1293
- specialArea.style, // style
1294
- options.highlightStyle, // highlightStyle
1295
- options.commonSetting.zoom, // zoom
1296
- options.keyFieldName,
1297
- specialArea.specialAreaStyle.textLabelShowEnabled &&
1298
- specialArea.specialAreaStyle.labelFieldName, // keyField, labelField
1299
- specialArea.labelStyle, // labelStyle
1300
- false, // randomColor
1301
- false, // renderCanvas
1302
- true, // singleSelect
1303
- lfcsOpt,
1304
- options.layerName, // layerTag
1305
- options.eventSetting.clickCallback,
1306
- options.eventSetting.mouseMoveCallback
1307
- );
1308
- }
1309
- }
1310
- }
1311
- if (dataLoadCb) {
1312
- dataLoadCb(true);
1313
- }
1314
- }
1315
-
1316
- if (!data) {
1317
- // 数据来自本地
1318
- var dbOpenRequest = window.indexedDB.open("regionDB");
1319
- dbOpenRequest.onsuccess = function (event) {
1320
- var db = this.result;
1321
- var store = db.transaction(storeName).objectStore(storeName);
1322
- var request = store.getAll();
1323
- request.onsuccess = function () {
1324
- var features = this.result;
1325
- showGrid(features);
1326
- };
1327
- };
1328
- } else {
1329
- if (data.length == 0) {
1330
- if (dataLoadCb) {
1331
- dataLoadCb(false);
1332
- }
1333
- return;
1334
- }
1335
- var _data = JSON.parse(JSON.stringify(data[0]));
1336
- var newData = data[0];
1337
- if (newData && newData.geometry) {
1338
- _data = JSON.parse(JSON.stringify(data));
1339
- showGrid(data);
1340
- } else {
1341
- showGrid(data[0]);
1342
- }
1343
-
1344
- var dbRequest = window.indexedDB.open("regionDB");
1345
- dbRequest.onsuccess = function () {
1346
- addStore(this.result.version);
1347
- };
1348
- function addStore(version) {
1349
- var dbOpenRequest = window.indexedDB.open("regionDB", version + 1);
1350
- dbOpenRequest.onupgradeneeded = function (event) {
1351
- var db = event.target.result;
1352
- if (!db.objectStoreNames.contains(storeName)) {
1353
- var store = db.createObjectStore(storeName, {
1354
- autoIncrement: true,
1355
- });
1356
- for (var i = 0; i < _data.length; i++) {
1357
- store.put(_data[i]);
1358
- }
1359
- store.transaction.oncomplete = function () {
1360
- console.log("complete");
1361
- };
1362
- }
1363
- };
1364
- }
1365
- }
1366
- }
1367
-
1368
- this.networkCloud = function (options, positions) {
1369
- if (!globeMap) {
1370
- return;
1371
- }
1372
- globeMap.networkCloud(options, positions);
1373
- };
1374
- this.clearNetworkCloud = function (layerNames) {
1375
- if (!globeMap) {
1376
- return;
1377
- }
1378
- globeMap.clearNetworkCloud(layerNames);
1379
- };
1380
- this.lineOperation = function (options, data, dataLoadCb) {
1381
- if (!options || !options.layerName) {
1382
- console.log("图层名必须传递");
1383
- return;
1384
- }
1385
- // 数据获取
1386
- let queryFeature = (queryParams) => {
1387
- if (gisMap) {
1388
- return new Promise(function (resolve) {
1389
- let cb = function (result) {
1390
- resolve(result);
1391
- };
1392
- gisMap.queryFeature(queryParams, cb);
1393
- });
1394
- } else {
1395
- return Promise.resolve(undefined);
1396
- }
1397
- };
1398
- // 执行绘制
1399
- let drawLine = (options, data) => {
1400
- if (globeMap) globeMap.lineOperation(options, data);
1401
- else if (gisMap) {
1402
- let style = options.style || {};
1403
- let hStyle = options.hStyle || {};
1404
- let symbol = {
1405
- type: "simple-line", // autocasts as new SimpleLineSymbol()
1406
- color: style.color || "lightblue",
1407
- width: (style.width || 2) + "px",
1408
- style: style.style || "short-dot",
1409
- };
1410
- let hsymbol = {
1411
- type: "simple-line", // autocasts as new SimpleLineSymbol()
1412
- color: hStyle.color || "lightblue",
1413
- width: (hStyle.width || 2) + "px",
1414
- style: hStyle.style || "short-dot",
1415
- };
1416
- var opt = options.options || {};
1417
- gisMap.locateFeatureByCoords(
1418
- data,
1419
- options.type,
1420
- options.id,
1421
- symbol,
1422
- hsymbol,
1423
- options.zoom,
1424
- options.keyField,
1425
- options.labelField,
1426
- options.labelStyle,
1427
- options.randomColor,
1428
- options.renderCanvas,
1429
- options.singleSelected,
1430
- opt,
1431
- options.layerTag,
1432
- options.callback
1433
- );
1434
- }
1435
- };
1436
-
1437
- // 主逻辑
1438
- if (!!data && data.length) {
1439
- drawLine(options, data);
1440
- } else {
1441
- if (!options.usageID) {
1442
- console.log("图层用途必须传递");
1443
- return;
1444
- }
1445
-
1446
- let originalData = false;
1447
- if (globeMap) originalData = true;
1448
- let queryParams = {
1449
- layerID: options.usageID,
1450
- where: options.filterString || "1=1",
1451
- geometry: "",
1452
- outGeometry: true,
1453
- options: { originalData: originalData },
1454
- };
1455
- queryFeature(queryParams).then(function (resultData) {
1456
- if (dataLoadCb && typeof dataLoadCb === "function") {
1457
- dataLoadCb(resultData);
1458
- }
1459
- if (!resultData) {
1460
- console.log("没有查询到数据,请检查查询参数");
1461
- return;
1462
- }
1463
- drawLine(options, resultData);
1464
- });
1465
- }
1466
- };
1467
- this.enableMapEvents = function (enablePan, enableZoom, callbackArray) {
1468
- if (gisMap != null && mapType == "map") {
1469
- gisMap.enableMapEvents(enablePan, enableZoom, callbackArray);
1470
- }
1471
- };
1472
- this.setMapOpacity = function (opacity) {
1473
- if (gisMap != null && mapType == "map") {
1474
- gisMap.setMapOpacity(opacity);
1475
- }
1476
- };
1477
-
1478
- //地理坐标转屏幕坐标
1479
- this.convertMapToScreen = function (list) {
1480
- if (gisMap != null) {
1481
- return gisMap.convertMapToScreen(list);
1482
- }
1483
- return list;
1484
- };
1485
-
1486
- // 屏幕坐标转地理坐标
1487
- this.convertScreenToMap = function (list) {
1488
- if (gisMap != null) {
1489
- return gisMap.convertScreenToMap(list);
1490
- }
1491
- return list;
1492
- };
1493
-
1494
- //设置地下模式悟空
1495
- this.SetTerrainAlpha = function (alpha) {
1496
- if (globeMap != null) {
1497
- globeMap.onUndergroundModel(alpha);
1498
- }
1499
- };
1500
-
1501
- // 二维引擎下加载图层目录树中的图层接口
1502
- this.setTreeLayerShow = function (options, cb) {
1503
- let mapInstance;
1504
- if (gisMap != null && mapType == "map") {
1505
- mapInstance = gisMap;
1506
- }
1507
- mapInstance.setTreeLayerShow(options, cb);
1508
- };
1509
-
1510
- // 新版通用接口
1511
- // 适配热力图,具体参数转换等逻辑在引擎层面实现,确保后续接口平替时只需要修改引擎层面即可
1512
- this.heatMap = function (options, cb) {
1513
- let mapInstance;
1514
- if (globeMap != null && mapType == "globe") {
1515
- mapInstance = globeMap;
1516
- } else if (gisMap != null && mapType == "map") {
1517
- mapInstance = gisMap;
1518
- }
1519
- mapInstance.heatMap(options, cb);
1520
- };
1521
- // 新版通用接口
1522
- // 适配网格
1523
- this.area = function (options, cb) {
1524
- let mapInstance;
1525
- if (globeMap != null && mapType == "globe") {
1526
- mapInstance = globeMap;
1527
- } else if (gisMap != null && mapType == "map") {
1528
- mapInstance = gisMap;
1529
- }
1530
- mapInstance.area(options, cb);
1531
- };
1532
- // 新版通用接口
1533
- // 适配网格
1534
- this.line = function (options, cb) {
1535
- let mapInstance;
1536
- if (globeMap != null && mapType == "globe") {
1537
- mapInstance = globeMap;
1538
- } else if (gisMap != null && mapType == "map") {
1539
- mapInstance = gisMap;
1540
- }
1541
- mapInstance.line(options, cb);
1542
- };
1543
- // webgl无人机机场接口
1544
- this.addDock = function (options) {
1545
- if (globeMap != null && mapType == "globe") {
1546
- globeMap.addDock(options);
1547
- }
1548
- };
1549
- // webgl十字聚焦特效
1550
- this.lockOnPoint = function (options) {
1551
- if (globeMap !== null && mapType === "globe") {
1552
- globeMap.lockOnPoint(options);
1553
- }
1554
- };
1555
- // 视锥体特效
1556
- this.frustumOperation = function (options) {
1557
- if (globeMap !== null && mapType === "globe") {
1558
- globeMap.frustumOperation(options);
1559
- }
1560
- };
1561
- // 新的机场区域效果
1562
- this.globeImageryFocus = function (options) {
1563
- if (globeMap !== null && mapType === "globe") {
1564
- globeMap.globeImageryFocus(options);
1565
- }
1566
- };
1567
- };
1568
-
1569
- export default egovaBI;
1
+ var egovaBI = function (globeMap, gisMap, mapType) {
2
+ function defaultValue(a, b) {
3
+ if (a !== undefined && a !== null) {
4
+ return a;
5
+ }
6
+ return b;
7
+ }
8
+
9
+ function getImgSize(url) {
10
+ return new Promise((resolve, reject) => {
11
+ let img = new Image();
12
+ img.onload = function () {
13
+ resolve({ width: img.width, height: img.height });
14
+ img = null;
15
+ };
16
+ img.onerror = function () {
17
+ resolve({ width: 0, height: 0 });
18
+ img = null;
19
+ };
20
+ img.src = url;
21
+ });
22
+ }
23
+
24
+ function interpolateColor(startColor, endColor, count) {
25
+ if (count < 2) return [startColor, endColor];
26
+
27
+ var start = rgbToRgbArray(startColor);
28
+ var end = rgbToRgbArray(endColor);
29
+ var end0 = end[0];
30
+ var end1 = end[1];
31
+ var end2 = end[2];
32
+ var end3 = end[3];
33
+ var start0 = start[0];
34
+ var start1 = start[1];
35
+ var start2 = start[2];
36
+ var start3 = start[3];
37
+
38
+ var r = end0 - start0;
39
+ var g = end1 - start1;
40
+ var b = end2 - start2;
41
+ var opacity = end3 - start3;
42
+ var step = 1.0 / count;
43
+ var colors = [startColor];
44
+ var _count = count - 1;
45
+ for (var i = 1; i < _count; i++) {
46
+ var interval = step * i;
47
+ colors.push([
48
+ Math.round(start0 + interval * r),
49
+ Math.round(start1 + interval * g),
50
+ Math.round(start2 + interval * b),
51
+ start3 + interval * opacity,
52
+ ]);
53
+ }
54
+ colors.push(endColor);
55
+ return colors;
56
+ }
57
+
58
+ function rgbToRgbArray(color) {
59
+ if (
60
+ !color ||
61
+ typeof color !== "string" ||
62
+ (typeof color == "string" && color.indexOf("rgb") == -1)
63
+ )
64
+ return color;
65
+
66
+ var r, g, b, a;
67
+ var rgbaAttr = color.match(/[\d.]+/g);
68
+ if (rgbaAttr.length >= 3) {
69
+ r = parseInt(rgbaAttr[0]);
70
+ g = parseInt(rgbaAttr[1]);
71
+ b = parseInt(rgbaAttr[2]);
72
+ if (rgbaAttr.length > 3) a = parseFloat(rgbaAttr[3]);
73
+ else a = 1;
74
+ }
75
+ return [r, g, b, a];
76
+ }
77
+
78
+ // 查询idb是否存在表
79
+ function checkObjectStore(storeName) {
80
+ return new Promise((resolve, reject) => {
81
+ // 打开网格数据库
82
+ let idbRequest = window.indexedDB.open("regionDB");
83
+ idbRequest.onblocked = function (event) {
84
+ // 如果其他的一些页签加载了该数据库,在我们继续之前需要关闭它们
85
+ // alert("请关闭其他由该站点打开的页签!");
86
+ console.log("请关闭其他由该站点打开的页签!");
87
+ };
88
+ idbRequest.onerror = (event) => {
89
+ console.log("数据库打开报错(checkObjectStore)");
90
+ // resolve(undefined)
91
+ reject(event.target.error.message);
92
+ };
93
+
94
+ idbRequest.onsuccess = () => {
95
+ let db = idbRequest.result;
96
+ // console.log('数据库打开成功(hasObjectStore)')
97
+ resolve(db.objectStoreNames.contains(storeName));
98
+ db.close();
99
+ };
100
+ });
101
+ }
102
+
103
+ function deal2DPoints(layerName, positions, options) {
104
+ let datalist = [];
105
+ let zoom = options.common.zoom;
106
+ let clear = options.common.clear;
107
+ let highLightType = -1;
108
+ let infoStyle = null;
109
+ let renderCanvas = null;
110
+ if (options.option && options.option.renderCanvas !== undefined) {
111
+ renderCanvas = options.option.renderCanvas;
112
+ }
113
+ let tagName = layerName;
114
+ let clusterOption = null;
115
+
116
+ let hasHover = null;
117
+ let callback = null;
118
+ datalist = positions.map(function (p) {
119
+ if (options.textStyle.label) {
120
+ for (const key in p) {
121
+ if (
122
+ key !== "id" &&
123
+ key !== "x" &&
124
+ key !== "y" &&
125
+ key !== "objectID"
126
+ ) {
127
+ if (!p.label) p.label = [];
128
+ var labelItem = {};
129
+ labelItem[key] = p[key];
130
+ p.label.push(labelItem);
131
+ }
132
+ }
133
+ }
134
+ p.minZoom = options.common.beginLevel;
135
+ p.maxZoom = options.common.endLevel;
136
+ p.symbolType = -1;
137
+ p.symbolUrl = options.textStyle.symbolUrl || "location.png";
138
+ if (options.selected && options.selected.hSymbolUrl)
139
+ p.hSymbolUrl = options.selected.hSymbolUrl;
140
+ p.scale = options.textStyle.scale;
141
+ p.angle = options.textStyle.angle;
142
+ // 适配选中效果的放大倍数和高亮图片
143
+ if (options.selectStyle && options.selectStyle.enable) {
144
+ if (options.selectStyle.scaleEnabled) {
145
+ p.hScale = options.selectStyle.scaleFactor;
146
+ }
147
+ if (options.selectStyle.imgUrl) {
148
+ p.hSymbolUrl = options.selectStyle.imgUrl;
149
+ }
150
+ }
151
+ // 杭州现场,需要叠加图片和地图放大同时存在
152
+ if (options.developer) {
153
+ if (
154
+ options.developer.enableScaleAndOverImage &&
155
+ options.developer.scaleAndOverImageFactor
156
+ ) {
157
+ p.aScale = options.developer.scaleAndOverImageFactor;
158
+ }
159
+ }
160
+ //classify symbol
161
+ if (options.textStyle.enableClassify) {
162
+ const customScheme = options.textStyle.customScheme;
163
+ const classField = options.textStyle.classField;
164
+ if (
165
+ p[classField] &&
166
+ Object.prototype.toString.call(customScheme) == "[object Array]" &&
167
+ customScheme.length
168
+ ) {
169
+ customScheme.forEach((scheme) => {
170
+ if (scheme.type == p[classField]) {
171
+ scheme.imageUrl && (p.symbolUrl = scheme.imageUrl);
172
+ }
173
+ });
174
+ }
175
+ }
176
+ //textValue
177
+ if (options.textStyle.enableText) {
178
+ let labelMinZoom = options.common.beginLevel;
179
+ let labelMaxZoom = options.common.endLevel;
180
+ if (options.textStyle.labelZoomEnabled) {
181
+ labelMinZoom = options.textStyle.textBeginLevel;
182
+ labelMaxZoom = options.textStyle.textEndLevel;
183
+ }
184
+ p.labelStyle = {
185
+ type: "text",
186
+ minZoom: labelMinZoom,
187
+ maxZoom: labelMaxZoom,
188
+ xoffset: options.textStyle.xoffset + "px",
189
+ yoffset: options.textStyle.yoffset + "px",
190
+ text: p.textValue,
191
+ color: options.textStyle.fillColor,
192
+ font: {
193
+ size: options.textStyle.fontSize + "px",
194
+ weight: options.textStyle.fontWeight,
195
+ family: options.textStyle.family || "microsoft-yahei",
196
+ },
197
+ };
198
+ }
199
+ p.useLabelBg = options.textStyle.textBackground;
200
+ if (p.useLabelBg) {
201
+ p.labelBgStyle = {
202
+ type: "picture-marker",
203
+ url: options.textStyle.textBackgroundUrl,
204
+ };
205
+ }
206
+ return p;
207
+ });
208
+
209
+ return new Promise((resolve, reject) => {
210
+ try {
211
+ let args = {
212
+ datalist: datalist,
213
+ zoom: zoom,
214
+ clear: clear,
215
+ highLightType: highLightType,
216
+ infoStyle: infoStyle,
217
+ renderCanvas: renderCanvas,
218
+ tagName: tagName,
219
+ clusterOption: null,
220
+ hasHover: hasHover,
221
+ callback: callback,
222
+ };
223
+ if (options.clusterStyle.clusterEnabled) {
224
+ clusterOption = {
225
+ clusterType: options.clusterStyle.clusterType,
226
+ distance: options.clusterStyle.clusterDistance,
227
+ style: null,
228
+ critical: options.clusterStyle.critical || 10,
229
+ level: options.clusterStyle.level,
230
+ clickShowSpiralPoint: options.clusterStyle.clickShowSpiralPoint,
231
+ labelStyle: {
232
+ type: "text",
233
+ color: options.clusterStyle.fillColor,
234
+ text: "",
235
+ xoffset: options.clusterStyle.xoffset + "px",
236
+ yoffset: options.clusterStyle.yoffset + "px",
237
+ font: {
238
+ size: options.clusterStyle.fontSize + "px",
239
+ weight: options.clusterStyle.fontWeight || "normal",
240
+ family: options.clusterStyle.family || "microsoft-yahei",
241
+ },
242
+ },
243
+ };
244
+
245
+ let useCustomClusterStyle =
246
+ options.clusterStyle.symbolUrl &&
247
+ options.clusterStyle.useCustomStyle;
248
+ let clusterStyle = {
249
+ type: "simple-marker",
250
+ style: "circle",
251
+ color: [255, 168, 0, 200],
252
+ size: 25 * options.clusterStyle.scale + "px",
253
+ outline: {
254
+ color: [255, 168, 0, 200],
255
+ width: 2,
256
+ },
257
+ };
258
+ if (options.clusterStyle.style) {
259
+ clusterStyle = Object.assign(
260
+ clusterStyle,
261
+ options.clusterStyle.style
262
+ );
263
+ }
264
+ clusterOption.style = clusterStyle;
265
+ if (useCustomClusterStyle) {
266
+ getImgSize(options.clusterStyle.symbolUrl).then((szie) => {
267
+ clusterStyle = {
268
+ type: "picture-marker",
269
+ url: options.clusterStyle.symbolUrl,
270
+ width: szie.width * options.clusterStyle.scale + "px",
271
+ height: szie.height * options.clusterStyle.scale + "px",
272
+ };
273
+ clusterOption.style = clusterStyle;
274
+ args.clusterOption = clusterOption;
275
+ resolve(args);
276
+ });
277
+ } else {
278
+ args.clusterOption = clusterOption;
279
+ resolve(args);
280
+ }
281
+ } else {
282
+ resolve(args);
283
+ }
284
+ } catch (err) {
285
+ reject(err);
286
+ }
287
+ });
288
+ }
289
+
290
+ /*
291
+ * @description:新参数格式的旧热力接口,主要用来做中间层参数格式转换
292
+ * @method showHeatImage3D_BI
293
+ * @param {String} layerName 热力参数数组
294
+ * @param {Array} data 热力值和坐标的数据数组
295
+ * @param {Object} options 配置项
296
+ * @param {Object} options.heatOpt 热力配置项
297
+ * @param {Object} options.commonOpt 通用配置项
298
+ *
299
+ * @return {Void}} 无返回
300
+ *
301
+ * @author: Hetianhong
302
+ * @date: 2021-08-31 14:13:42
303
+ */
304
+ this.showHeatImage3D_BI = function (layerName, data, option) {
305
+ //data必须包含x y 和 value属性
306
+ if (
307
+ data.length === 0 ||
308
+ !data[0].hasOwnProperty("x") ||
309
+ !data[0].hasOwnProperty("y") ||
310
+ !data[0].hasOwnProperty("value")
311
+ ) {
312
+ return;
313
+ }
314
+ if (globeMap != null) {
315
+ //hth 此处进行参数转换
316
+ let commonOpt = option.commonOpt; // 通用配置项
317
+ let heatOpt = option.heatOpt; // 热力配置项
318
+
319
+ let info = {};
320
+ let zoom = defaultValue(commonOpt.zoom, false);
321
+ let clear = defaultValue(commonOpt.clear, true);
322
+ let options = {
323
+ heading: defaultValue(commonOpt.heading, 0),
324
+ pitch: defaultValue(commonOpt.pitch, -45),
325
+ range: defaultValue(commonOpt.range, 8000),
326
+ maxDataLength: defaultValue(commonOpt.maxDataLength, 5),
327
+ layerName: layerName,
328
+ };
329
+
330
+ // 开始组装info
331
+ //组装info.data,其实也没啥组装的
332
+ info.data = data;
333
+
334
+ //组装info.options
335
+ info.options = {
336
+ clampStyle: heatOpt.heatType === 0 ? 0 : 3, // 如果设置了为0,则为0,其余则全部为旧逻辑的3绘制方式,即贴地贴建筑
337
+ renderType: defaultValue(heatOpt.renderType, "line"),
338
+ dynamicGranularity: defaultValue(heatOpt.dynamicGranularity, false),
339
+ granularity: defaultValue(heatOpt.granularity, 500),
340
+ maxHeight: defaultValue(heatOpt.maxHeight, -1),
341
+ height: defaultValue(heatOpt.height, 10),
342
+ radiusScale: defaultValue(heatOpt.radiusScale, 1.0),
343
+ radius: defaultValue(heatOpt.radius, 40),
344
+ gradient: defaultValue(heatOpt.gradient, {
345
+ 0.35: "rgb(136,218,104)",
346
+ 0.7: "rgb(241,238,124)",
347
+ 1.0: "rgb(243,118,116)",
348
+ }),
349
+ //动态改变热力半径
350
+ dynamicRadius: defaultValue(heatOpt.dynamicRadius, undefined),
351
+ dynamicLevel: defaultValue(heatOpt.dynamicLevel, undefined),
352
+ // 下面的部分不建议传,逐步舍弃
353
+ gridSize: defaultValue(heatOpt.gridSize, null),
354
+ blur: defaultValue(heatOpt.blur, 0.85),
355
+ };
356
+
357
+ // 转换过后,使用旧的参数格式调用原热力接口
358
+ globeMap.showHeatImage3D(info, zoom, clear, options);
359
+ }
360
+ };
361
+
362
+ /*
363
+ * @description:打点和聚类接口进行整合后的新接口
364
+ * @method drawPoint
365
+ * @param {String} layerName 图层名
366
+ * @param {Array} positions 位置数组
367
+ * @param {Object} options 配置项
368
+ *
369
+ * @return {Void} 无返回
370
+ *
371
+ * @author: Hetianhong
372
+ * @date: 2021-09-09 14:49:49
373
+ */
374
+ this.drawPoints = function (layerName, positions, options) {
375
+ let drawData = function (layerName, positions, options) {
376
+ if (globeMap && mapType == "globe") {
377
+ globeMap.drawPoints(layerName, positions, options);
378
+ } else if (gisMap && mapType == "map") {
379
+ deal2DPoints(layerName, positions, options).then((args) => {
380
+ gisMap.showMultiObjectCurrentPosition(
381
+ args.datalist,
382
+ args.zoom,
383
+ args.clear,
384
+ args.highLightType,
385
+ args.infoStyle,
386
+ args.renderCanvas,
387
+ args.tagName,
388
+ options.clickCallback,
389
+ options.mouseOverCallback,
390
+ args.clusterOption,
391
+ args.hasHover,
392
+ layerName,
393
+ options.mouseOutCallback,
394
+ options.option
395
+ );
396
+ });
397
+ }
398
+ };
399
+
400
+ if (!options.usageID && !options.phyLayerID) {
401
+ drawData(layerName, positions, options);
402
+ return;
403
+ }
404
+ let queryFeature = (queryParams) => {
405
+ return new Promise(function (resolve) {
406
+ let cb = function (result) {
407
+ resolve(result);
408
+ };
409
+ if (gisMap) {
410
+ gisMap.queryFeature(queryParams, cb);
411
+ } else {
412
+ return Promise.resolve(undefined);
413
+ }
414
+ });
415
+ };
416
+ var filterString = "1=1";
417
+ if (options.filterString) filterString = options.filterString + "";
418
+ let queryParams = {
419
+ layerID: options.usageID || options.phyLayerID,
420
+ where: filterString,
421
+ outGeometry: true,
422
+ };
423
+ queryFeature(queryParams).then(function (resultData) {
424
+ if (!resultData) {
425
+ console.log("没有查询到数据,请检查查询参数");
426
+ return;
427
+ }
428
+ let dataCache = [];
429
+ let errorSize = 0;
430
+ resultData.forEach((element) => {
431
+ let x, y;
432
+ if (element.geometry) {
433
+ x = element.geometry.x;
434
+ y = element.geometry.y;
435
+ }
436
+ if (x && y) {
437
+ let item = { ...element.attributes, x, y };
438
+ if (globeMap && mapType == "globe" && options.primaryKey) {
439
+ let primaryKeyValue = item[options.primaryKey];
440
+ primaryKeyValue != undefined &&
441
+ (item["attributes"] = {
442
+ objectID: primaryKeyValue,
443
+ });
444
+ }
445
+ dataCache.push(item);
446
+ } else {
447
+ errorSize++;
448
+ }
449
+ });
450
+ if (errorSize > 0) {
451
+ console.error(`${errorSize}个点格式错误,无法正常加载`);
452
+ }
453
+ if (options.callback && typeof options.callback === "function") {
454
+ options.callback(dataCache);
455
+ }
456
+ drawData(layerName, dataCache, options);
457
+ });
458
+ };
459
+ this.getLabel = function (attributes) {
460
+ if (!attributes) return;
461
+ var label = [],
462
+ field = {};
463
+ for (var key in attributes) {
464
+ field = {};
465
+ field[key] = attributes[key];
466
+ label.push(field);
467
+ }
468
+ return label;
469
+ };
470
+ this.drawParts = function (options, data, callback) {
471
+ var self = this;
472
+ async function showParts(data) {
473
+ var drawParam = options.drawParam || {};
474
+ var ctrOption = drawParam.clusterOption;
475
+ var zoom = options.zoom === undefined ? true : !!options.zoom;
476
+ var clusterOption = null;
477
+ if (ctrOption) {
478
+ clusterOption = {
479
+ clusterType: ctrOption.clusterType,
480
+ level: ctrOption.level || 0,
481
+ style: {
482
+ type: "simple-marker",
483
+ style: "circle",
484
+ color: ctrOption.color || [255, 0, 0, 0.6],
485
+ size: (ctrOption.size || 20) + "px",
486
+ outline: {
487
+ //if outline has been specified
488
+ color: ctrOption.outlineColor || [255, 168, 0, 1],
489
+ width: ctrOption.outlineWidth || 2,
490
+ },
491
+ },
492
+ critical: ctrOption.critical || 10,
493
+ clickShowSpiralPoint: ctrOption.clickShowSpiralPoint,
494
+ labelStyle: {
495
+ type: "text",
496
+ color: ctrOption.labelColor || [255, 255, 255, 1],
497
+ text: "",
498
+ zlevel: ctrOption.labelZlevel || 1,
499
+ xoffset: (ctrOption.labelXOffset || 0) + "px",
500
+ yoffset: (ctrOption.labelYOffset || 0) + "px",
501
+ font: ctrOption.labelFont || {
502
+ family: "Arial",
503
+ size: 10,
504
+ },
505
+ },
506
+ distance: ctrOption.distance || 50,
507
+ };
508
+ if(ctrOption.symbol && ctrOption.symbol.url) {
509
+ var size = await getImgSize(ctrOption.symbol.url);
510
+ var scale = (ctrOption.symbol.scale) || 1;
511
+ var clusterStyle = {
512
+ type: "picture-marker",
513
+ url: ctrOption.symbol.url,
514
+ width: size.width * scale + "px",
515
+ height: size.height * scale + "px",
516
+ };
517
+ clusterOption.style = clusterStyle;
518
+ }
519
+ }
520
+ var param = [
521
+ data,
522
+ zoom,
523
+ false,
524
+ null,
525
+ null,
526
+ false,
527
+ drawParam.tagName,
528
+ drawParam.clickCallback,
529
+ drawParam.mouseOverCallback,
530
+ clusterOption,
531
+ false,
532
+ drawParam.layerName,
533
+ drawParam.callback,
534
+ drawParam.drawOptions,
535
+ ];
536
+ //三维聚类参数
537
+ var globeOptions = {
538
+ zoom: true,
539
+ scale: 0.9,
540
+ clear: true,
541
+ nearFarScalar: [8000, 1.0, 10000, 0.6],
542
+ clickCallBack: drawParam.clickCallback,
543
+ layerName: drawParam.layerName,
544
+ minSize: 30,
545
+ clusterLimit: 20,
546
+ style: "default",
547
+ disableDepthTestDistance: drawParam.disableDepthTestDistance,
548
+ clusterImageInfo: {
549
+ horizontalOrigin: "center",
550
+ verticalOrigin: "bottom",
551
+ cssStyle: {
552
+ borderRadius: 500,
553
+ fillColor: "rgba(0,0,0,0.7)",
554
+ borderLineWidth: 3,
555
+ borderLineColor: "rgba(250,140,0,0.9)",
556
+ paddingX: 15,
557
+ paddingY: 6,
558
+ marginBottom: 2,
559
+ },
560
+ textStyle: {
561
+ font: "60px Helvetica",
562
+ fillColor: "rgba(220,220,220,1.0)",
563
+ outlineColor: "black",
564
+ outlineWidth: 1,
565
+ padding: 1,
566
+ textScale: 0.5,
567
+ textStartX: 40,
568
+ textStartY: 15,
569
+ },
570
+ },
571
+ };
572
+ if (globeMap) {
573
+ globeMap.addClusterLayer({
574
+ data,
575
+ options: globeOptions,
576
+ });
577
+ } else if (gisMap) {
578
+ gisMap.showMultiObjectCurrentPosition(...param);
579
+ }
580
+ }
581
+
582
+ if (data) {
583
+ showParts(data);
584
+ } else {
585
+ let queryFromGIS = () => {
586
+ let queryParam = options.queryParam;
587
+ var subTypeName = options.subTypeName;
588
+ var subUniqueCode = options.subUniqueCode;
589
+ let queryCallback = function (featureInfos) {
590
+ var features = featureInfos[queryParam.phyLayerIDs];
591
+ if (features.length == 0) {
592
+ callback && callback([]);
593
+ return;
594
+ }
595
+ if (!features || !features.length) return;
596
+ var symbolUrl = "";
597
+ if (subUniqueCode.indexOf("http") > -1) {
598
+ symbolUrl = subUniqueCode;
599
+ } else if (subUniqueCode.indexOf(".") > -1) {
600
+ symbolUrl = subUniqueCode;
601
+ } else {
602
+ symbolUrl = "".concat(subUniqueCode, ".png");
603
+ if (globeMap)
604
+ symbolUrl = queryParam.gisServerURL
605
+ ? `${queryParam.gisServerURL}/symbol/${symbolUrl}`
606
+ : symbolUrl;
607
+ }
608
+ var map = globeMap || gisMap;
609
+ //验证图标是否可查询
610
+ map.getMapConfig("serverURL", function (key, data) {
611
+ var symbolServiceURL = `${data}/symbol`;
612
+ var picUrl =
613
+ symbolUrl.indexOf("http") > -1 || symbolUrl.indexOf("https") > -1
614
+ ? symbolUrl
615
+ : `${symbolServiceURL}/${symbolUrl}`;
616
+ getImgSize(picUrl).then((size) => {
617
+ var dataList = features.map(function (feature) {
618
+ return Object.assign(
619
+ {},
620
+ {
621
+ x: feature.geometry.x,
622
+ y: feature.geometry.y,
623
+ },
624
+ {
625
+ attributes: feature.attributes,
626
+ // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
627
+ symbolType: -1,
628
+ symbolUrl:
629
+ size.width || size.height
630
+ ? picUrl
631
+ : globeMap
632
+ ? `${symbolServiceURL}/20100.png`
633
+ : `20100.png`,
634
+ scale: 0.5,
635
+ }
636
+ );
637
+ });
638
+ callback && callback(dataList);
639
+ if (!options.onlyGetData) {
640
+ showParts(dataList);
641
+ }
642
+ });
643
+ });
644
+ };
645
+ if (gisMap) {
646
+ gisMap.queryPhylayerFeatures(queryParam, queryCallback);
647
+ }
648
+ };
649
+ queryFromGIS();
650
+ }
651
+ };
652
+
653
+ this.drawOtherParts = function (options, data) {
654
+ const geomType = options.geomType;
655
+ if (globeMap && geomType != 1) {
656
+ this.drawOtherPartsGlobe(options, data);
657
+ return;
658
+ }
659
+
660
+ var self = this;
661
+ let queryParam = options.queryParam || {};
662
+ function showParts(data) {}
663
+
664
+ if (data) {
665
+ showParts(data);
666
+ } else {
667
+ const layerID = queryParam.phyLayerIDs;
668
+ const layerName = queryParam.layerName;
669
+ const keyField = null;
670
+ const keyValue = null;
671
+ const clearMap = queryParam.clearMap;
672
+ let inStyle = queryParam.style || {
673
+ color: "blue",
674
+ };
675
+ let inHStyle = queryParam.hStyle || {
676
+ color: "blue",
677
+ };
678
+ let style = null,
679
+ hStyle = null;
680
+ if (geomType == 1) {
681
+ } else if (geomType == 2) {
682
+ style = {
683
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
684
+ color: inStyle.color || "blue",
685
+ width: inStyle.width || "2px",
686
+ style: inStyle.style || "solid",
687
+ cap: inStyle.cap || "round",
688
+ join: inStyle.join || "round",
689
+ };
690
+ hStyle = {
691
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
692
+ color: inHStyle.color || "red",
693
+ width: inHStyle.width || inStyle.width || "2px",
694
+ style: inHStyle.style || inStyle.style || "solid",
695
+ cap: inHStyle.cap || inStyle.cap || "round",
696
+ join: inHStyle.join || inStyle.join || "round",
697
+ };
698
+ } else if (geomType == 3) {
699
+ style = {
700
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
701
+ color: inStyle.color || [51, 51, 204, 0.9],
702
+ style: inStyle.style || "solid",
703
+ outline: {
704
+ // autocasts as new SimpleLineSymbol()
705
+ color: inStyle.outlineColor || "blue",
706
+ width: inStyle.outlineWidth || "1px",
707
+ style: inStyle.outlineStyle || "solid",
708
+ cap: inStyle.outlineCap || "round",
709
+ join: inStyle.outlineJoin || "round",
710
+ },
711
+ };
712
+ hStyle = {
713
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
714
+ color: inHStyle.color || [51, 51, 204, 0.9],
715
+ style: inHStyle.style || inStyle.style || "solid",
716
+ outline: {
717
+ // autocasts as new SimpleLineSymbol()
718
+ color: inHStyle.outlineColor || "red",
719
+ width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
720
+ style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
721
+ cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
722
+ join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
723
+ },
724
+ };
725
+ }
726
+ const bZoom = queryParam.bZoom || true;
727
+ const randomColor = null;
728
+ const labelField = null;
729
+ const labelstyle = null;
730
+ const geometry = null;
731
+ const where = queryParam.where || "1=1";
732
+ const opts = {
733
+ ...queryParam.options,
734
+ layerId: layerName,
735
+ mouseOverCallback: queryParam.mouseOverCallback,
736
+ };
737
+
738
+ let param = [
739
+ layerID,
740
+ keyField,
741
+ keyValue,
742
+ clearMap,
743
+ style,
744
+ hStyle,
745
+ bZoom,
746
+ randomColor,
747
+ labelField,
748
+ labelstyle,
749
+ geometry,
750
+ where,
751
+ null,
752
+ null,
753
+ opts,
754
+ null,
755
+ null,
756
+ null,
757
+ null,
758
+ null,
759
+ null,
760
+ queryParam.clickCallback,
761
+ ];
762
+ //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
763
+ if (globeMap) {
764
+ gisMap.locateFeatureByIDs(...param);
765
+ } else if (gisMap) {
766
+ gisMap.locateFeatureByIDs(...param);
767
+ }
768
+ }
769
+ };
770
+
771
+ this.drawOtherPartsGlobe = function (options, data) {
772
+ const geomType = options.geomType;
773
+ const drawParam = options.drawParam || {};
774
+ const color = drawParam.color || "rgba(255, 0.0, 0.0, 0.8)";
775
+ const clickColor = drawParam.clickColor || "rgba(255, 255, 0.0, 0.8)";
776
+ function showParts(features) {
777
+ if (!globeMap) {
778
+ return;
779
+ }
780
+
781
+ if (geomType == 2) {
782
+ var infoJson = features.map((feature) => {
783
+ var paths = feature.geometry.paths[0];
784
+ var positions = paths.map((position) => {
785
+ return {
786
+ x: position[0],
787
+ y: position[1],
788
+ };
789
+ });
790
+ return {
791
+ positions,
792
+ type: "color",
793
+ color: color,
794
+ width: 2,
795
+ attributes: feature.attributes,
796
+ };
797
+ });
798
+
799
+ var zoom = true;
800
+ var clear = true;
801
+ var layerName = drawParam.layerName;
802
+ var options = {
803
+ heading: 0,
804
+ pitch: -90,
805
+ range: null,
806
+ minZoom: 0,
807
+ maxZoom: 100,
808
+ clickColor: clickColor,
809
+ clickWidth: 5,
810
+ bloom: false,
811
+ };
812
+
813
+ globeMap.showPolyline(
814
+ infoJson,
815
+ zoom,
816
+ clear,
817
+ options,
818
+ layerName,
819
+ drawParam.clickCallback
820
+ );
821
+ } else if (geomType == 3) {
822
+ var infoJson = features.map((feature) => {
823
+ var rings = feature.geometry.rings[0];
824
+ var positions = rings.map((position) => {
825
+ return {
826
+ x: position[0],
827
+ y: position[1],
828
+ };
829
+ });
830
+
831
+ return {
832
+ positions,
833
+ type: "polygon",
834
+ colorType: "color",
835
+ color: color,
836
+ attributes: feature.attributes,
837
+ };
838
+ });
839
+
840
+ var zoom = true;
841
+ var clear = true;
842
+ var layerName = drawParam.layerName;
843
+ var drawWay = "entityWay";
844
+ var options = {
845
+ heading: 0,
846
+ pitch: -90,
847
+ range: null,
848
+ minZoom: 0,
849
+ maxZoom: 24,
850
+ clickColor: clickColor,
851
+ clickWidth: 15,
852
+ heightAnimation: false,
853
+ };
854
+ globeMap.showPolygon(
855
+ infoJson,
856
+ drawWay,
857
+ zoom,
858
+ clear,
859
+ options,
860
+ layerName,
861
+ drawParam.clickCallback
862
+ );
863
+ }
864
+ }
865
+
866
+ if (data) {
867
+ showParts(data);
868
+ } else {
869
+ let queryFromGIS = () => {
870
+ let queryParam = options.queryParam;
871
+ let queryCallback = function (featureInfos) {
872
+ var features = featureInfos[queryParam.phyLayerIDs];
873
+ if (!features || !features.length) return;
874
+ showParts(features);
875
+ };
876
+ if (gisMap) {
877
+ gisMap.queryPhylayerFeatures(queryParam, queryCallback);
878
+ }
879
+ };
880
+ queryFromGIS();
881
+ }
882
+ };
883
+
884
+ /*
885
+ * @description:新的轨迹线接口
886
+ * @method traceOperation
887
+ * @param {Array} posArr 位置数组
888
+ * @param {Object} options 配置项
889
+ *
890
+ * @return {Void} 无返回
891
+ *
892
+ * @author: Hetianhong
893
+ * @date: 2021-09-09 14:49:49
894
+ */
895
+ this.traceOperation = function (posArr, options) {
896
+ globeMap.traceOperation(posArr, options);
897
+ };
898
+ /*
899
+ * @description:网格接口
900
+ * 先查询idb的data,没有的话,再查询queryFeature的data
901
+ * @method regionOperation
902
+ * @param {Object} options 配置项
903
+ * @param {Array} data 数据,可不传
904
+ *
905
+ * @return {Void} 无返回
906
+ *
907
+ * @author: Hetianhong
908
+ * @date: 2021-10-19 17:27:02
909
+ */
910
+ this.regionOperation = function (options, data, callback, dataLoadCb) {
911
+ function execOperation(data) {
912
+ if (globeMap) {
913
+ globeMap.regionOperation(options, data);
914
+ callback && callback();
915
+ } else if (gisMap) {
916
+ gridPolygon2dOperation(options, data, callback, dataLoadCb);
917
+ }
918
+ }
919
+
920
+ if (data) {
921
+ execOperation(data);
922
+ } else {
923
+ if (!options.idbSetting.usageID) {
924
+ return;
925
+ }
926
+
927
+ let storeName = !!globeMap
928
+ ? "usageID"
929
+ : "usage2D" + "_" + options.idbSetting.usageID;
930
+ let queryFromGIS = () => {
931
+ let filterString = options.idbSetting.filterString || "1=1";
932
+ let queryParam = {
933
+ layerID: options.idbSetting.usageID,
934
+ where: filterString,
935
+ geometry: "",
936
+ outGeometry: true,
937
+ options: {
938
+ originalData: true,
939
+ },
940
+ };
941
+ //二维地图不获取原始数据
942
+ if (!globeMap) queryParam.options.originalData = false;
943
+ let queryCallback = function (featureInfos) {
944
+ execOperation(featureInfos);
945
+ };
946
+ if (gisMap) {
947
+ gisMap.queryFeature(queryParam, queryCallback);
948
+ }
949
+ };
950
+
951
+ if (!options.idbSetting.enabled) {
952
+ // 直接查询
953
+ queryFromGIS();
954
+ } else {
955
+ // 查询是否存在表
956
+ checkObjectStore(storeName).then(function (hasObjStore) {
957
+ if (hasObjStore) {
958
+ // 如果有,读取本地
959
+ execOperation();
960
+ } else {
961
+ // 如果没有,查询queryFeature
962
+ queryFromGIS();
963
+ }
964
+ });
965
+ }
966
+ }
967
+ };
968
+ this.cancelHighlightedRegion = function (layerName) {
969
+ globeMap.cancelHighlightedRegion(layerName);
970
+ };
971
+ /*
972
+ * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
973
+ * @method showPolyline_BI
974
+ * @param {参数类型} 参数名 参数说明
975
+ *
976
+ * @return {返回值类型} 返回值说明
977
+ *
978
+ * @author: Hetianhong
979
+ * @date: 2021-11-11 15:40:31
980
+ */
981
+ this.showPolyline_BI = function (layerName, positions = [], options = {}) {
982
+ if (globeMap !== null) {
983
+ // 默认参数
984
+ let defaultOpt = {
985
+ // 样式类
986
+ styleOpt: {
987
+ period: 4, // 动画线段的周期,越短越快
988
+ image: "road.png", // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
989
+ repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
990
+ repeatY: 1, //纵向纹理重复(type为image限定)
991
+ glowPower: 0, //中心亮度
992
+ intensity: 1.2, //纹理图片颜色强度
993
+ gapColor: "rgba(0, 0, 0, 0)", //间隙颜色(type为dash限定)
994
+ dashLength: 15, //间隙宽(type为dash限定)
995
+ outlineWidth: 0, // 边框线宽(type为outline限定)
996
+ outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
997
+ type: "color", // 线条类型,有 image color dash outline glow
998
+ width: 10,
999
+ color: "rgba(255,255,0,1)",
1000
+ },
1001
+ // 视角缩放类
1002
+ zoomOpt: {
1003
+ //zoom参数
1004
+ heading: 0,
1005
+ pitch: -90,
1006
+ range: null,
1007
+ //可视级别
1008
+ minZoom: 0,
1009
+ maxZoom: 24,
1010
+ //泛光绘制
1011
+ // 下面两项,不暴露,全部为false
1012
+ bloom: false,
1013
+ merge: false,
1014
+ },
1015
+ // 交互类
1016
+ interactOpt: {
1017
+ //click相关
1018
+ clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
1019
+ clickWidth: 30, // 点击后的宽度
1020
+ clickCallback: undefined, // function(e) {console.log('click polyline', e)},
1021
+ mouseOverCallBack: undefined,
1022
+ },
1023
+ };
1024
+ let getMergedOptions = (options) => {
1025
+ let mergedOptions = {};
1026
+ mergedOptions.styleOpt = Object.assign(
1027
+ {},
1028
+ defaultOpt.styleOpt,
1029
+ options.styleOpt
1030
+ );
1031
+ mergedOptions.zoomOpt = Object.assign(
1032
+ {},
1033
+ defaultOpt.zoomOpt,
1034
+ options.zoomOpt
1035
+ );
1036
+ mergedOptions.interactOpt = Object.assign(
1037
+ {},
1038
+ defaultOpt.interactOpt,
1039
+ options.interactOpt
1040
+ );
1041
+ return mergedOptions;
1042
+ };
1043
+ let mergedOptions = getMergedOptions(options);
1044
+
1045
+ let opt = {};
1046
+ // let styleOpt = options.styleOpt;
1047
+ // let zoomOpt = options.zoomOpt;
1048
+ // let interactOpt = options.interactOpt;
1049
+ //hth 此处进行参数转换
1050
+ switch (mergedOptions.styleOpt.type) {
1051
+ case "image":
1052
+ opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
1053
+ opt.image = defaultValue(mergedOptions.styleOpt.image, "road.png"); //纹理图片,data3d/polyline/目录下
1054
+ opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
1055
+ opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
1056
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
1057
+ opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
1058
+ break;
1059
+ case "glow":
1060
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
1061
+ break;
1062
+ case "dash":
1063
+ opt.gapColor = defaultValue(
1064
+ mergedOptions.styleOpt.gapColor,
1065
+ "rgba(0, 0, 0, 0)"
1066
+ ); //间隙颜色
1067
+ opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
1068
+ break;
1069
+ case "outline":
1070
+ opt.outlineWidth = defaultValue(
1071
+ mergedOptions.styleOpt.outlineWidth,
1072
+ 0
1073
+ );
1074
+ opt.outlineColor = defaultValue(
1075
+ mergedOptions.styleOpt.outlineColor,
1076
+ "rgba(0, 0, 0, 0)"
1077
+ );
1078
+ break;
1079
+ default:
1080
+ // color
1081
+ }
1082
+
1083
+ opt.type = mergedOptions.styleOpt.type;
1084
+ opt.width = mergedOptions.styleOpt.width;
1085
+ opt.color = mergedOptions.styleOpt.color;
1086
+
1087
+ // 遍历位置数组中的每一项
1088
+ for (let pos of positions) {
1089
+ // 遍历opt中每一个key赋值到每一个pos中
1090
+ for (let k in opt) {
1091
+ pos[k] = opt[k];
1092
+ }
1093
+ }
1094
+
1095
+ let zoom = mergedOptions.zoomOpt.zoom;
1096
+ let clear = mergedOptions.zoomOpt.clear;
1097
+ let clickCallback = mergedOptions.interactOpt.clickCallback;
1098
+ let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack;
1099
+ let commonOpt = {
1100
+ //zoom参数
1101
+ heading: mergedOptions.zoomOpt.heading,
1102
+ pitch: mergedOptions.zoomOpt.pitch,
1103
+ range: mergedOptions.zoomOpt.range,
1104
+ //可视级别
1105
+ minZoom: mergedOptions.zoomOpt.minZoom,
1106
+ maxZoom: mergedOptions.zoomOpt.maxZoom,
1107
+ //click相关
1108
+ clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
1109
+ clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
1110
+ //泛光绘制
1111
+ // 下面两项,不暴露,全部为false
1112
+ bloom: false,
1113
+ merge: false,
1114
+ };
1115
+
1116
+ globeMap.showPolyline(
1117
+ positions,
1118
+ zoom,
1119
+ clear,
1120
+ commonOpt,
1121
+ layerName,
1122
+ clickCallback,
1123
+ mouseOverCallBack
1124
+ );
1125
+ }
1126
+ };
1127
+ /*
1128
+ * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
1129
+ * @method activeLayer
1130
+ * @param {String} layerName 图层名
1131
+ * @param {Object} options 配置项
1132
+ * @param {String} options.type 操作类型,'clear', 'active'
1133
+ * @param {Boolean} options.zoom 是否缩放
1134
+ * @param {Object} filter 过滤项
1135
+ * @param {String} filter.keyFieldName 过滤键名
1136
+ * @param {Array} filter.values 过滤值内容数组
1137
+ *
1138
+ * @return {返回值类型} 返回值说明
1139
+ *dataLoadCb:加载状态函数
1140
+ * @author: Hetianhong
1141
+ * @date: 2021-11-26 09:49:16
1142
+ */
1143
+ this.activeLayer = function (layerName, options, filter) {
1144
+ if (globeMap != null && mapType == "globe") {
1145
+ globeMap.activeLayer(layerName, options, filter);
1146
+ }
1147
+ if (gisMap != null && mapType == "map") {
1148
+ gisMap.activeLayer(layerName, options, filter);
1149
+ }
1150
+ };
1151
+
1152
+ this.deActiveLayer = function (layerName, filter) {
1153
+ if (gisMap != null && mapType == "map") {
1154
+ gisMap.deActiveLayer(layerName, filter);
1155
+ }
1156
+ };
1157
+
1158
+ function gridPolygon2dOperation(options, data, callback, dataLoadCb) {
1159
+ var storeName = `usage2D_${options.idbSetting.usageID}`;
1160
+ function showGrid(realData) {
1161
+ // 转换一下
1162
+ var geometries = [];
1163
+ var extraGeometries = [];
1164
+ var specialAreaS = options.specialAreaS; //玲珑平台分类设色
1165
+ for (var i = 0; i < realData.length; i++) {
1166
+ var feature = realData[i];
1167
+ var geom = feature.geometry;
1168
+ geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
1169
+ var hasPush = false;
1170
+ if (specialAreaS && specialAreaS.length > 0) {
1171
+ for (var j = 0; j < specialAreaS.length; j++) {
1172
+ var specialArea = specialAreaS[j];
1173
+ if (!specialArea.geometries) {
1174
+ specialArea.geometries = [];
1175
+ }
1176
+ var attributes = JSON.parse(JSON.stringify(feature.attributes));
1177
+ let filterResult = new Function(
1178
+ `return ${specialArea.statusControl.compiled}`
1179
+ )().call(null, attributes);
1180
+ if (filterResult == true) {
1181
+ specialArea.geometries.push(geom);
1182
+ hasPush = true;
1183
+ }
1184
+ }
1185
+ }
1186
+ !hasPush && geometries.push(geom);
1187
+ }
1188
+ if (options.specialArea && options.selectedSetting.selected.length) {
1189
+ var extraIds = options.selectedSetting.selected.map((s) => s.selectID);
1190
+ for (var i = geometries.length - 1; i > -1; i--) {
1191
+ var geom = geometries[i];
1192
+ if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
1193
+ geometries.splice(i, 1);
1194
+ extraGeometries.push(geom);
1195
+ if (extraGeometries.length === extraIds.length) break;
1196
+ }
1197
+ }
1198
+ }
1199
+ var color = options.customColor
1200
+ ? interpolateColor(
1201
+ options.customColor[0],
1202
+ options.customColor[1],
1203
+ Math.min(geometries.length, 10)
1204
+ )
1205
+ : 10;
1206
+ if (options.setFieldColor && options.layeredColor) {
1207
+ var colorConfig = options.layeredColor(geometries);
1208
+ geometries = colorConfig.data;
1209
+ color = colorConfig.color;
1210
+ }
1211
+ var lfcOpt = {
1212
+ minZoom: options.visiblitySetting.beginLevel,
1213
+ maxZoom: options.visiblitySetting.endLevel,
1214
+ layerId: options.layerName,
1215
+ comCallbak: callback,
1216
+ order: options.order,
1217
+ inverse: options.inverse,
1218
+ ...options.option, // option的其他参数
1219
+ };
1220
+ if (options.labelSetting.labelZoomEnabled == "show") {
1221
+ lfcOpt.labelMinZoom = options.labelSetting.labelMinZoom;
1222
+ lfcOpt.labelMaxZoom = options.labelSetting.labelMaxZoom;
1223
+ }
1224
+ gisMap.locateFeatureByCoords(
1225
+ geometries,
1226
+ "polygon",
1227
+ options.layerName, // id,如果已经有attributes就没用了
1228
+ options.style, // style
1229
+ options.highlightStyle, // highlightStyle
1230
+ options.commonSetting.zoom, // zoom
1231
+ options.keyFieldName,
1232
+ options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
1233
+ options.labelStyle, // labelStyle
1234
+ color,
1235
+ false, // renderCanvas
1236
+ true, // singleSelect
1237
+ lfcOpt,
1238
+ options.layerName, // layerTag
1239
+ options.eventSetting.clickCallback,
1240
+ options.eventSetting.mouseMoveCallback
1241
+ );
1242
+ if (extraGeometries.length) {
1243
+ var lfceOpt = {
1244
+ minZoom: options.visiblitySetting.beginLevel,
1245
+ maxZoom: options.visiblitySetting.endLevel,
1246
+ layerId: options.layerName,
1247
+ order: options.order,
1248
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
1249
+ };
1250
+ if (options.labelSetting.labelZoomEnabled == "show") {
1251
+ lfceOpt.labelMinZoom = options.labelSetting.labelMinZoom;
1252
+ lfceOpt.labelMaxZoom = options.labelSetting.labelMaxZoom;
1253
+ }
1254
+ gisMap.locateFeatureByCoords(
1255
+ extraGeometries,
1256
+ "polygon",
1257
+ options.layerName, // id,如果已经有attributes就没用了
1258
+ options.specialAreaStyle, // style
1259
+ options.highlightStyle, // highlightStyle
1260
+ false, // zoom
1261
+ options.keyFieldName,
1262
+ options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
1263
+ options.specialAreaLabelStyle, // labelStyle
1264
+ false, // randomColor
1265
+ false, // renderCanvas
1266
+ true, // singleSelect
1267
+ lfceOpt,
1268
+ options.layerName, // layerTag
1269
+ options.eventSetting.clickCallback,
1270
+ options.eventSetting.mouseMoveCallback
1271
+ );
1272
+ }
1273
+ if (specialAreaS && specialAreaS.length > 0) {
1274
+ var lfcsOpt = {
1275
+ minZoom: options.visiblitySetting.beginLevel,
1276
+ maxZoom: options.visiblitySetting.endLevel,
1277
+ layerId: options.layerName,
1278
+ comCallbak: callback,
1279
+ order: options.order,
1280
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
1281
+ };
1282
+ if (options.labelSetting.labelZoomEnabled == "show") {
1283
+ lfcsOpt.labelMinZoom = options.labelSetting.labelMinZoom;
1284
+ lfcsOpt.labelMaxZoom = options.labelSetting.labelMaxZoom;
1285
+ }
1286
+ for (var j = 0; j < specialAreaS.length; j++) {
1287
+ var specialArea = specialAreaS[j];
1288
+ if (specialArea.geometries.length > 0) {
1289
+ gisMap.locateFeatureByCoords(
1290
+ specialArea.geometries,
1291
+ "polygon",
1292
+ options.layerName, // id,如果已经有attributes就没用了
1293
+ specialArea.style, // style
1294
+ options.highlightStyle, // highlightStyle
1295
+ options.commonSetting.zoom, // zoom
1296
+ options.keyFieldName,
1297
+ specialArea.specialAreaStyle.textLabelShowEnabled &&
1298
+ specialArea.specialAreaStyle.labelFieldName, // keyField, labelField
1299
+ specialArea.labelStyle, // labelStyle
1300
+ false, // randomColor
1301
+ false, // renderCanvas
1302
+ true, // singleSelect
1303
+ lfcsOpt,
1304
+ options.layerName, // layerTag
1305
+ options.eventSetting.clickCallback,
1306
+ options.eventSetting.mouseMoveCallback
1307
+ );
1308
+ }
1309
+ }
1310
+ }
1311
+ if (dataLoadCb) {
1312
+ dataLoadCb(true);
1313
+ }
1314
+ }
1315
+
1316
+ if (!data) {
1317
+ // 数据来自本地
1318
+ var dbOpenRequest = window.indexedDB.open("regionDB");
1319
+ dbOpenRequest.onsuccess = function (event) {
1320
+ var db = this.result;
1321
+ var store = db.transaction(storeName).objectStore(storeName);
1322
+ var request = store.getAll();
1323
+ request.onsuccess = function () {
1324
+ var features = this.result;
1325
+ showGrid(features);
1326
+ };
1327
+ };
1328
+ } else {
1329
+ if (data.length == 0) {
1330
+ if (dataLoadCb) {
1331
+ dataLoadCb(false);
1332
+ }
1333
+ return;
1334
+ }
1335
+ var _data = JSON.parse(JSON.stringify(data[0]));
1336
+ var newData = data[0];
1337
+ if (newData && newData.geometry) {
1338
+ _data = JSON.parse(JSON.stringify(data));
1339
+ showGrid(data);
1340
+ } else {
1341
+ showGrid(data[0]);
1342
+ }
1343
+
1344
+ var dbRequest = window.indexedDB.open("regionDB");
1345
+ dbRequest.onsuccess = function () {
1346
+ addStore(this.result.version);
1347
+ };
1348
+ function addStore(version) {
1349
+ var dbOpenRequest = window.indexedDB.open("regionDB", version + 1);
1350
+ dbOpenRequest.onupgradeneeded = function (event) {
1351
+ var db = event.target.result;
1352
+ if (!db.objectStoreNames.contains(storeName)) {
1353
+ var store = db.createObjectStore(storeName, {
1354
+ autoIncrement: true,
1355
+ });
1356
+ for (var i = 0; i < _data.length; i++) {
1357
+ store.put(_data[i]);
1358
+ }
1359
+ store.transaction.oncomplete = function () {
1360
+ console.log("complete");
1361
+ };
1362
+ }
1363
+ };
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
+ this.networkCloud = function (options, positions) {
1369
+ if (!globeMap) {
1370
+ return;
1371
+ }
1372
+ globeMap.networkCloud(options, positions);
1373
+ };
1374
+ this.clearNetworkCloud = function (layerNames) {
1375
+ if (!globeMap) {
1376
+ return;
1377
+ }
1378
+ globeMap.clearNetworkCloud(layerNames);
1379
+ };
1380
+ this.lineOperation = function (options, data, dataLoadCb) {
1381
+ if (!options || !options.layerName) {
1382
+ console.log("图层名必须传递");
1383
+ return;
1384
+ }
1385
+ // 数据获取
1386
+ let queryFeature = (queryParams) => {
1387
+ if (gisMap) {
1388
+ return new Promise(function (resolve) {
1389
+ let cb = function (result) {
1390
+ resolve(result);
1391
+ };
1392
+ gisMap.queryFeature(queryParams, cb);
1393
+ });
1394
+ } else {
1395
+ return Promise.resolve(undefined);
1396
+ }
1397
+ };
1398
+ // 执行绘制
1399
+ let drawLine = (options, data) => {
1400
+ if (globeMap) globeMap.lineOperation(options, data);
1401
+ else if (gisMap) {
1402
+ let style = options.style || {};
1403
+ let hStyle = options.hStyle || {};
1404
+ let symbol = {
1405
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
1406
+ color: style.color || "lightblue",
1407
+ width: (style.width || 2) + "px",
1408
+ style: style.style || "short-dot",
1409
+ };
1410
+ let hsymbol = {
1411
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
1412
+ color: hStyle.color || "lightblue",
1413
+ width: (hStyle.width || 2) + "px",
1414
+ style: hStyle.style || "short-dot",
1415
+ };
1416
+ var opt = options.options || {};
1417
+ gisMap.locateFeatureByCoords(
1418
+ data,
1419
+ options.type,
1420
+ options.id,
1421
+ symbol,
1422
+ hsymbol,
1423
+ options.zoom,
1424
+ options.keyField,
1425
+ options.labelField,
1426
+ options.labelStyle,
1427
+ options.randomColor,
1428
+ options.renderCanvas,
1429
+ options.singleSelected,
1430
+ opt,
1431
+ options.layerTag,
1432
+ options.callback
1433
+ );
1434
+ }
1435
+ };
1436
+
1437
+ // 主逻辑
1438
+ if (!!data && data.length) {
1439
+ drawLine(options, data);
1440
+ } else {
1441
+ if (!options.usageID) {
1442
+ console.log("图层用途必须传递");
1443
+ return;
1444
+ }
1445
+
1446
+ let originalData = false;
1447
+ if (globeMap) originalData = true;
1448
+ let queryParams = {
1449
+ layerID: options.usageID,
1450
+ where: options.filterString || "1=1",
1451
+ geometry: "",
1452
+ outGeometry: true,
1453
+ options: { originalData: originalData },
1454
+ };
1455
+ queryFeature(queryParams).then(function (resultData) {
1456
+ if (dataLoadCb && typeof dataLoadCb === "function") {
1457
+ dataLoadCb(resultData);
1458
+ }
1459
+ if (!resultData) {
1460
+ console.log("没有查询到数据,请检查查询参数");
1461
+ return;
1462
+ }
1463
+ drawLine(options, resultData);
1464
+ });
1465
+ }
1466
+ };
1467
+ this.enableMapEvents = function (enablePan, enableZoom, callbackArray) {
1468
+ if (gisMap != null && mapType == "map") {
1469
+ gisMap.enableMapEvents(enablePan, enableZoom, callbackArray);
1470
+ }
1471
+ };
1472
+ this.setMapOpacity = function (opacity) {
1473
+ if (gisMap != null && mapType == "map") {
1474
+ gisMap.setMapOpacity(opacity);
1475
+ }
1476
+ };
1477
+
1478
+ //地理坐标转屏幕坐标
1479
+ this.convertMapToScreen = function (list) {
1480
+ if (gisMap != null) {
1481
+ return gisMap.convertMapToScreen(list);
1482
+ }
1483
+ return list;
1484
+ };
1485
+
1486
+ // 屏幕坐标转地理坐标
1487
+ this.convertScreenToMap = function (list) {
1488
+ if (gisMap != null) {
1489
+ return gisMap.convertScreenToMap(list);
1490
+ }
1491
+ return list;
1492
+ };
1493
+
1494
+ //设置地下模式悟空
1495
+ this.SetTerrainAlpha = function (alpha) {
1496
+ if (globeMap != null) {
1497
+ globeMap.onUndergroundModel(alpha);
1498
+ }
1499
+ };
1500
+
1501
+ // 二维引擎下加载图层目录树中的图层接口
1502
+ this.setTreeLayerShow = function (options, cb) {
1503
+ let mapInstance;
1504
+ if (gisMap != null && mapType == "map") {
1505
+ mapInstance = gisMap;
1506
+ }
1507
+ mapInstance.setTreeLayerShow(options, cb);
1508
+ };
1509
+
1510
+ // 新版通用接口
1511
+ // 适配热力图,具体参数转换等逻辑在引擎层面实现,确保后续接口平替时只需要修改引擎层面即可
1512
+ this.heatMap = function (options, cb) {
1513
+ let mapInstance;
1514
+ if (globeMap != null && mapType == "globe") {
1515
+ mapInstance = globeMap;
1516
+ } else if (gisMap != null && mapType == "map") {
1517
+ mapInstance = gisMap;
1518
+ }
1519
+ mapInstance.heatMap(options, cb);
1520
+ };
1521
+ // 新版通用接口
1522
+ // 适配网格
1523
+ this.area = function (options, cb) {
1524
+ let mapInstance;
1525
+ if (globeMap != null && mapType == "globe") {
1526
+ mapInstance = globeMap;
1527
+ } else if (gisMap != null && mapType == "map") {
1528
+ mapInstance = gisMap;
1529
+ }
1530
+ mapInstance.area(options, cb);
1531
+ };
1532
+ // 新版通用接口
1533
+ // 适配网格
1534
+ this.line = function (options, cb) {
1535
+ let mapInstance;
1536
+ if (globeMap != null && mapType == "globe") {
1537
+ mapInstance = globeMap;
1538
+ } else if (gisMap != null && mapType == "map") {
1539
+ mapInstance = gisMap;
1540
+ }
1541
+ mapInstance.line(options, cb);
1542
+ };
1543
+ // webgl无人机机场接口
1544
+ this.addDock = function (options) {
1545
+ if (globeMap != null && mapType == "globe") {
1546
+ globeMap.addDock(options);
1547
+ }
1548
+ };
1549
+ // webgl十字聚焦特效
1550
+ this.lockOnPoint = function (options) {
1551
+ if (globeMap !== null && mapType === "globe") {
1552
+ globeMap.lockOnPoint(options);
1553
+ }
1554
+ };
1555
+ // 视锥体特效
1556
+ this.frustumOperation = function (options) {
1557
+ if (globeMap !== null && mapType === "globe") {
1558
+ globeMap.frustumOperation(options);
1559
+ }
1560
+ };
1561
+ // 新的机场区域效果
1562
+ this.globeImageryFocus = function (options) {
1563
+ if (globeMap !== null && mapType === "globe") {
1564
+ globeMap.globeImageryFocus(options);
1565
+ }
1566
+ };
1567
+ };
1568
+
1569
+ export default egovaBI;