egovamap 0.18.2 → 0.18.3

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,1080 +1,1099 @@
1
- var egovaBI = function(globeMap, gisMap, mapType){
2
-
3
- function defaultValue(a, b) {
4
- if (a !== undefined && a !== null) {
5
- return a;
6
- }
7
- return b;
8
- }
9
-
10
- function getImgSize(url) {
11
- return new Promise((resolve, reject) => {
12
- let img = new Image();
13
- img.onload = function() {
14
- resolve({ width: img.width, height: img.height });
15
- img = null;
16
- };
17
- img.onerror = function() {
18
- resolve({ width: 0, height: 0 });
19
- img = null;
20
- };
21
- img.src = url;
22
- });
23
- }
24
-
25
- function interpolateColor(startColor, endColor, count) {
26
- if (count < 2) return [startColor, endColor];
27
-
28
- var start = rgbToRgbArray(startColor);
29
- var end = rgbToRgbArray(endColor);
30
- var end0 = end[0];
31
- var end1 = end[1];
32
- var end2 = end[2];
33
- var end3 = end[3];
34
- var start0 = start[0];
35
- var start1 = start[1];
36
- var start2 = start[2];
37
- var start3 = start[3];
38
-
39
- var r = end0 - start0;
40
- var g = end1 - start1;
41
- var b = end2 - start2;
42
- var opacity = end3 - start3;
43
- var step = 1.0 / count;
44
- var colors = [startColor];
45
- var _count = count - 1;
46
- for (var i = 1; i < _count; i++) {
47
- var interval = step * i;
48
- colors.push([
49
- Math.round(start0 + interval * r),
50
- Math.round(start1 + interval * g),
51
- Math.round(start2 + interval * b),
52
- (start3 + interval * opacity)
53
- ])
54
- }
55
- colors.push(endColor);
56
- return colors;
57
- }
58
-
59
- function rgbToRgbArray(color) {
60
- if (!color || typeof color !== 'string' || (typeof color == 'string'&&color.indexOf('rgb') == -1) ) return color;
61
-
62
- var r, g, b, a;
63
- var rgbaAttr = color.match(/[\d.]+/g);
64
- if (rgbaAttr.length >= 3) {
65
- r = parseInt(rgbaAttr[0]);
66
- g = parseInt(rgbaAttr[1]);
67
- b = parseInt(rgbaAttr[2]);
68
- if (rgbaAttr.length > 3) a = parseFloat(rgbaAttr[3]);
69
- else a = 1;
70
- }
71
- return [ r, g, b, a];
72
- };
73
-
74
- // 查询idb是否存在表
75
- function checkObjectStore (storeName) {
76
- return new Promise((resolve, reject) => {
77
- // 打开网格数据库
78
- let idbRequest = window.indexedDB.open('regionDB');
79
- idbRequest.onblocked = function(event) {
80
- // 如果其他的一些页签加载了该数据库,在我们继续之前需要关闭它们
81
- // alert("请关闭其他由该站点打开的页签!");
82
- console.log("请关闭其他由该站点打开的页签!")
83
- };
84
- idbRequest.onerror = (event) => {
85
- console.log('数据库打开报错(checkObjectStore)');
86
- // resolve(undefined)
87
- reject(event.target.error.message)
88
- };
89
-
90
- idbRequest.onsuccess = () => {
91
- let db = idbRequest.result;
92
- // console.log('数据库打开成功(hasObjectStore)')
93
- resolve(db.objectStoreNames.contains(storeName))
94
- db.close()
95
- };
96
- })
97
- }
98
-
99
- function deal2DPoints(layerName, positions, options) {
100
- let datalist = [];
101
- let zoom = options.common.zoom;
102
- let clear = options.common.clear;
103
- let highLightType = -1;
104
- let infoStyle = null;
105
- let renderCanvas = null;
106
- let tagName = layerName;
107
- let clusterOption = null;
108
-
109
- let hasHover = null;
110
- let callback = null;
111
- datalist = positions.map(function(p) {
112
- if(options.textStyle.label) {
113
- for (const key in p) {
114
- if(key !== "id" && key !== "x" && key !== "y" && key !== "objectID"){
115
- if(!p.label) p.label = [];
116
- var labelItem = {};
117
- labelItem[key] = p[key];
118
- p.label.push(labelItem);
119
- }
120
- }
121
- }
122
- p.minZoom = options.common.beginLevel;
123
- p.maxZoom = options.common.endLevel;
124
- p.symbolType = -1;
125
- p.symbolUrl = options.textStyle.symbolUrl || "location.png";
126
- p.scale = options.textStyle.scale;
127
- p.angle = options.textStyle.angle;
128
- //textValue
129
- if (options.textStyle.enableText) {
130
- p.labelStyle = {
131
- type: "text",
132
- xoffset: options.textStyle.xoffset + "px",
133
- yoffset: options.textStyle.yoffset + "px",
134
- text: p.textValue,
135
- color: options.textStyle.fillColor,
136
- font: {
137
- size: options.textStyle.fontSize + "px",
138
- weight: options.textStyle.fontWeight,
139
- family: options.textStyle.family || "microsoft-yahei"
140
- }
141
- };
142
- }
143
- p.useLabelBg = options.textStyle.textBackground;
144
- if (p.useLabelBg) {
145
- p.labelBgStyle = {
146
- type: "picture-marker",
147
- url: options.textStyle.textBackgroundUrl
148
- };
149
- }
150
- return p;
151
- });
152
-
153
- return new Promise((resolve, reject) => {
154
- try {
155
- let args = {
156
- datalist: datalist,
157
- zoom: zoom,
158
- clear: clear,
159
- highLightType: highLightType,
160
- infoStyle: infoStyle,
161
- renderCanvas: renderCanvas,
162
- tagName: tagName,
163
- clusterOption: null,
164
- hasHover: hasHover,
165
- callback: callback
166
- };
167
- if (options.clusterStyle.clusterEnabled) {
168
- clusterOption = {
169
- clusterType: options.clusterStyle.clusterType,
170
- distance: options.clusterStyle.clusterDistance,
171
- style: null,
172
- labelStyle: {
173
- type: "text",
174
- color: options.clusterStyle.fillColor,
175
- text: "",
176
- xoffset: options.clusterStyle.xoffset + "px",
177
- yoffset: options.clusterStyle.yoffset + "px",
178
- font: {
179
- size: options.clusterStyle.fontSize + "px",
180
- weight: options.clusterStyle.fontWeight || "normal",
181
- family: options.clusterStyle.family || "microsoft-yahei"
182
- }
183
- }
184
- };
185
-
186
- let useCustomClusterStyle = options.clusterStyle.symbolUrl && options.clusterStyle.useCustomStyle;
187
- let clusterStyle = {
188
- type: "simple-marker",
189
- style: "circle",
190
- color: [255, 168, 0, 200],
191
- size: 25 * options.clusterStyle.scale + "px",
192
- outline: {
193
- color: [255, 168, 0, 200],
194
- width: 2
195
- }
196
- };
197
- clusterOption.style = clusterStyle;
198
- if (useCustomClusterStyle) {
199
- getImgSize(options.clusterStyle.symbolUrl).then(szie => {
200
- clusterStyle = {
201
- type: "picture-marker",
202
- url: options.clusterStyle.symbolUrl,
203
- width: szie.width * options.clusterStyle.scale + "px",
204
- height: szie.height * options.clusterStyle.scale + "px"
205
- };
206
- clusterOption.style = clusterStyle;
207
- args.clusterOption = clusterOption;
208
- resolve(args);
209
- });
210
- } else {
211
- args.clusterOption = clusterOption;
212
- resolve(args);
213
- }
214
- } else {
215
- resolve(args);
216
- }
217
- } catch (err) {
218
- reject(err);
219
- }
220
- });
221
- }
222
-
223
- /*
224
- * @description:新参数格式的旧热力接口,主要用来做中间层参数格式转换
225
- * @method showHeatImage3D_BI
226
- * @param {String} layerName 热力参数数组
227
- * @param {Array} data 热力值和坐标的数据数组
228
- * @param {Object} options 配置项
229
- * @param {Object} options.heatOpt 热力配置项
230
- * @param {Object} options.commonOpt 通用配置项
231
- *
232
- * @return {Void}} 无返回
233
- *
234
- * @author: Hetianhong
235
- * @date: 2021-08-31 14:13:42
236
- */
237
- this.showHeatImage3D_BI = function (layerName, data, option) {
238
- //data必须包含x y value属性
239
- if(
240
- data.length === 0 ||
241
- !data[0].hasOwnProperty('x') ||
242
- !data[0].hasOwnProperty('y') ||
243
- !data[0].hasOwnProperty('value')
244
- ) {
245
- return
246
- }
247
- if (globeMap != null) {
248
- //hth 此处进行参数转换
249
- let commonOpt = option.commonOpt; // 通用配置项
250
- let heatOpt = option.heatOpt; // 热力配置项
251
-
252
- let info = {};
253
- let zoom = defaultValue(commonOpt.zoom, false);
254
- let clear = defaultValue(commonOpt.clear, true);
255
- let options = {
256
- heading: defaultValue(commonOpt.heading, 0),
257
- pitch: defaultValue(commonOpt.pitch, -45),
258
- range: defaultValue(commonOpt.range, 8000),
259
- maxDataLength : defaultValue(commonOpt.maxDataLength, 5),
260
- layerName: layerName
261
- }
262
-
263
- // 开始组装info
264
- //组装info.data,其实也没啥组装的
265
- info.data = data
266
-
267
- //组装info.options
268
- info.options = {
269
- clampStyle: (heatOpt.heatType === 0) ? 0 : 3, // 如果设置了为0,则为0,其余则全部为旧逻辑的3绘制方式,即贴地贴建筑
270
- renderType: defaultValue(heatOpt.renderType, "line"),
271
- dynamicGranularity: defaultValue(heatOpt.dynamicGranularity, false),
272
- granularity: defaultValue(heatOpt.granularity, 500),
273
- maxHeight: defaultValue(heatOpt.maxHeight, -1),
274
- height: defaultValue(heatOpt.height, 10),
275
- radiusScale: defaultValue(heatOpt.radiusScale, 1.0),
276
- radius: defaultValue(heatOpt.radius, 40),
277
- gradient: defaultValue(heatOpt.gradient, {
278
- 0.35: "rgb(136,218,104)",
279
- 0.7: "rgb(241,238,124)",
280
- 1.0: "rgb(243,118,116)"
281
- }),
282
-
283
- // 下面的部分不建议传,逐步舍弃
284
- gridSize: defaultValue(heatOpt.gridSize, null),
285
- blur: defaultValue(heatOpt.blur, 0.85),
286
- }
287
-
288
- // 转换过后,使用旧的参数格式调用原热力接口
289
- globeMap.showHeatImage3D(info, zoom, clear, options);
290
- }
291
- }
292
-
293
- /*
294
- * @description:打点和聚类接口进行整合后的新接口
295
- * @method drawPoint
296
- * @param {String} layerName 图层名
297
- * @param {Array} positions 位置数组
298
- * @param {Object} options 配置项
299
- *
300
- * @return {Void} 无返回
301
- *
302
- * @author: Hetianhong
303
- * @date: 2021-09-09 14:49:49
304
- */
305
- this.drawPoints = function (layerName, positions, options) {
306
- if(globeMap && mapType == "globe"){
307
- if (!options.layerUsage || !options.layerUsage.usageID) {
308
- globeMap.drawPoints(layerName, positions, options);
309
- return;
310
- }
311
- let queryFeature = (queryParams) => {
312
- return new Promise(function(resolve) {
313
- let cb = function(result) {
314
- resolve(result)
315
- }
316
- if(gisMap) {
317
- gisMap.queryFeature(queryParams, cb);
318
- }else{
319
- return Promise.resolve(undefined)
320
- }
321
- })
322
-
323
- }
324
- let queryParams = {
325
- layerID: options.layerUsage.usageID,
326
- outGeometry: true,
327
- }
328
- queryFeature(queryParams)
329
- .then(function(resultData) {
330
- if(!resultData) {
331
- console.log('没有查询到数据,请检查查询参数')
332
- return
333
- }
334
- let dataCache=[];
335
- let errorSize=0;
336
- resultData.forEach(element => {
337
- let x,y;
338
- if(element.geometry){
339
- x=element.geometry.x;
340
- y=element.geometry.y;
341
- }
342
- if(x&&y){
343
- let item={...element.attributes,x,y};
344
- dataCache.push(item);
345
- }else{
346
- errorSize++;
347
- }
348
- });
349
- if(errorSize>0){
350
- console.error(`${errorSize}个点格式错误,无法正常加载`);
351
- }
352
- globeMap.drawPoints(layerName, dataCache, options);
353
- })
354
- }
355
- if(gisMap && mapType == "map"){
356
- deal2DPoints(layerName, positions, options).then(args => {
357
- gisMap.showMultiObjectCurrentPosition(
358
- args.datalist,
359
- args.zoom,
360
- args.clear,
361
- args.highLightType,
362
- args.infoStyle,
363
- args.renderCanvas,
364
- args.tagName,
365
- options.clickCallback,
366
- options.mouseOverCallback,
367
- args.clusterOption,
368
- args.hasHover,
369
- layerName,
370
- options.mouseOutCallback,
371
- options.option
372
- );
373
- });
374
- }
375
- }
376
- this.getLabel = function (attributes) {
377
- if (!attributes) return;
378
- var label = [], field = {};
379
- for (var key in attributes) {
380
- field = {};
381
- field[key] = attributes[key];
382
- label.push(field);
383
- }
384
- return label;
385
- };
386
- this.drawParts = function (options, data, callback) {
387
- var self = this;
388
- function showParts(data) {
389
- var drawParam = options.drawParam || {};
390
- var ctrOption = drawParam.clusterOption;
391
- var clusterOption = {
392
- clusterType: ctrOption.clusterType,
393
- level: ctrOption.level || 0,
394
- style: {
395
- "type": "simple-marker",
396
- "style": "circle",
397
- "color": ctrOption.color || [255, 0, 0, 0.6],
398
- "size": ctrOption.size || 20,
399
- "outline": { //if outline has been specified
400
- "color": ctrOption.outlineColor || [255, 168, 0, 1],
401
- "width": ctrOption.outlineWidth || 2
402
- }
403
- },
404
- labelStyle: {
405
- "type": "text",
406
- "color": ctrOption.labelColor || [255, 255, 255, 1],
407
- "text": "",
408
- "zlevel": ctrOption.labelZlevel || 1,
409
- "yoffset": 0,
410
- "font": ctrOption.labelFont || {
411
- "family": "Arial",
412
- "size": 10
413
- }
414
- },
415
- distance: ctrOption.distance || 50
416
- };
417
-
418
- var param = [data, true, false, null, null, false, drawParam.tagName, drawParam.clickCallback, drawParam.mouseOverCallback, clusterOption, false, drawParam.layerName, drawParam.callback, drawParam.drawOptions];
419
- //三维聚类参数
420
- var globeOptions = {
421
- zoom:true,
422
- scale: 0.9,
423
- clear :true,
424
- nearFarScalar:[8000, 1.0, 10000, 0.6],
425
- clickCallBack: drawParam.clickCallback,
426
- layerName: drawParam.layerName,
427
- minSize:30,
428
- clusterLimit: 20,
429
- style:"default",
430
- clusterImageInfo: {
431
- horizontalOrigin: "center",
432
- verticalOrigin: "bottom",
433
- cssStyle: {
434
- "borderRadius": 500,
435
- "fillColor": "rgba(0,0,0,0.7)",
436
- "borderLineWidth": 3,
437
- "borderLineColor": "rgba(250,140,0,0.9)",
438
- "paddingX": 15,
439
- "paddingY": 6,
440
- "marginBottom": 2
441
- },
442
- textStyle: {
443
- "font": "60px Helvetica",
444
- "fillColor": "rgba(220,220,220,1.0)",
445
- "outlineColor": "black",
446
- "outlineWidth": 1,
447
- "padding": 1,
448
- "textScale": 0.5,
449
- "textStartX": 40,
450
- "textStartY": 15
451
- }
452
- }
453
- }
454
- if (globeMap) {
455
- globeMap.addClusterLayer({
456
- data,
457
- options:globeOptions
458
- })
459
- } else if (gisMap) {
460
- gisMap.showMultiObjectCurrentPosition(...param );
461
- }
462
- }
463
-
464
- if (data) {
465
- showParts(data);
466
- } else {
467
- let queryFromGIS = () => {
468
- let queryParam = options.queryParam;
469
- var subTypeName = options.subTypeName;
470
- var subUniqueCode = options.subUniqueCode;
471
- let queryCallback = function (featureInfos) {
472
- var features = featureInfos[queryParam.phyLayerIDs];
473
- if (features.length == 0) {
474
- callback && callback([]);
475
- return;
476
- }
477
- if (!features || !features.length) return;
478
- var symbolUrl = "";
479
- if (subUniqueCode.indexOf("http") > -1) {
480
- symbolUrl = subUniqueCode;
481
- } else if (subUniqueCode.indexOf(".") > -1) {
482
- symbolUrl = subUniqueCode;
483
- } else {
484
- symbolUrl = "".concat(subUniqueCode, ".png");
485
- if(globeMap) symbolUrl = queryParam.gisServerURL ? `${queryParam.gisServerURL}/symbol/${symbolUrl}` : symbolUrl;
486
- }
487
- var dataList = features.map((function (feature) {
488
- return Object.assign({}, { x: feature.geometry.x, y: feature.geometry.y }, {
489
- attributes: feature.attributes,
490
- // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
491
- symbolType: -1,
492
- symbolUrl: symbolUrl,
493
- scale: 0.5
494
- });
495
- }));
496
- callback && callback(dataList);
497
- showParts(dataList);
498
- };
499
- if (gisMap) {
500
- gisMap.queryPhylayerFeatures(queryParam, queryCallback);
501
- }
502
- }
503
- queryFromGIS();
504
- }
505
- };
506
-
507
- this.drawOtherParts = function (options, data) {
508
- var self = this;
509
- const geomType = options.geomType;
510
- let queryParam = options.queryParam || {};
511
- function showParts(data) {
512
-
513
- }
514
-
515
- if (data) {
516
- showParts(data);
517
- } else {
518
- const layerID = queryParam.phyLayerIDs;
519
- const layerName = queryParam.layerName;
520
- const keyField = null;
521
- const keyValue = null;
522
- const clearMap = queryParam.clearMap || true;
523
- let inStyle = queryParam.style || {
524
- color: "blue"
525
- };
526
- let inHStyle = queryParam.hStyle || {
527
- color: "blue"
528
- };
529
- let style = null, hStyle = null;
530
- if (geomType == 1) {
531
- } else if (geomType == 2) {
532
- style = {
533
- type: "simple-line", // autocasts as new SimpleLineSymbol()
534
- color: inStyle.color || "blue",
535
- width: inStyle.width || "2px",
536
- style: inStyle.style || "solid",
537
- cap: inStyle.cap || "round",
538
- join: inStyle.join || "round",
539
- };
540
- hStyle = {
541
- type: "simple-line", // autocasts as new SimpleLineSymbol()
542
- color: inHStyle.color || "red",
543
- width: inHStyle.width || inStyle.width || "2px",
544
- style: inHStyle.style || inStyle.style || "solid",
545
- cap: inHStyle.cap || inStyle.cap || "round",
546
- join: inHStyle.join || inStyle.join || "round",
547
- };
548
- } else if (geomType == 3) {
549
- style = {
550
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
551
- color: inStyle.color || [51, 51, 204, 0.9],
552
- style: inStyle.style || "solid",
553
- outline: { // autocasts as new SimpleLineSymbol()
554
- color: inStyle.outlineColor || "blue",
555
- width: inStyle.outlineWidth || "1px",
556
- style: inStyle.outlineStyle || "solid",
557
- cap: inStyle.outlineCap || "round",
558
- join: inStyle.outlineJoin || "round",
559
- }
560
- };
561
- hStyle = {
562
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
563
- color: inHStyle.color || [51, 51, 204, 0.9],
564
- style: inHStyle.style || inStyle.style || "solid",
565
- outline: { // autocasts as new SimpleLineSymbol()
566
- color: inHStyle.outlineColor || "red",
567
- width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
568
- style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
569
- cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
570
- join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
571
- }
572
- };
573
- }
574
- const bZoom = queryParam.bZoom || true;
575
- const randomColor = null;
576
- const labelField = null;
577
- const labelstyle = null;
578
- const geometry = null;
579
- const where = queryParam.where || "1=1";
580
- const opts = {
581
- layerId: layerName,
582
- mouseOverCallback: queryParam.mouseOverCallback
583
- };
584
-
585
- let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, null, null, queryParam.clickCallback];
586
- //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
587
- if (globeMap) {
588
- gisMap.locateFeatureByIDs(...param);
589
- } else if (gisMap) {
590
- gisMap.locateFeatureByIDs(...param);
591
- }
592
-
593
- }
594
- };
595
-
596
- /*
597
- * @description:新的轨迹线接口
598
- * @method traceOperation
599
- * @param {Array} posArr 位置数组
600
- * @param {Object} options 配置项
601
- *
602
- * @return {Void} 无返回
603
- *
604
- * @author: Hetianhong
605
- * @date: 2021-09-09 14:49:49
606
- */
607
- this.traceOperation = function (posArr, options) {
608
- globeMap.traceOperation(posArr, options);
609
- }
610
- /*
611
- * @description:网格接口
612
- * 先查询idb的data,没有的话,再查询queryFeature的data
613
- * @method regionOperation
614
- * @param {Object} options 配置项
615
- * @param {Array} data 数据,可不传
616
- *
617
- * @return {Void} 无返回
618
- *
619
- * @author: Hetianhong
620
- * @date: 2021-10-19 17:27:02
621
- */
622
- this.regionOperation = function (options, data, callback) {
623
-
624
- function execOperation(data) {
625
- if (globeMap) {
626
- globeMap.regionOperation(options, data);
627
- callback && callback();
628
- } else if (gisMap) {
629
- gridPolygon2dOperation(options, data, callback);
630
- }
631
- }
632
-
633
- if (data) {
634
- execOperation(data);
635
- } else {
636
- if (!options.idbSetting.usageID) { return }
637
-
638
- let storeName = !!globeMap ? "usageID" : "usage2D" + "_" + options.idbSetting.usageID;
639
- let queryFromGIS = () => {
640
- let filterString = options.idbSetting.filterString || "1=1";
641
- let queryParam = {
642
- layerID: options.idbSetting.usageID,
643
- where: filterString,
644
- geometry: '',
645
- outGeometry: true,
646
- options: {
647
- originalData: true
648
- }
649
- }
650
- //二维地图不获取原始数据
651
- if(!globeMap) queryParam.options.originalData = false;
652
- let queryCallback = function (featureInfos) {
653
- execOperation(featureInfos);
654
- }
655
- if (gisMap) {
656
- gisMap.queryFeature(queryParam, queryCallback)
657
- }
658
- }
659
-
660
- if (!options.idbSetting.enabled) {
661
- // 直接查询
662
- queryFromGIS()
663
- } else {
664
- // 查询是否存在表
665
- checkObjectStore(storeName)
666
- .then(function (hasObjStore) {
667
- if (hasObjStore) {
668
- // 如果有,读取本地
669
- execOperation();
670
- } else {
671
- // 如果没有,查询queryFeature
672
- queryFromGIS()
673
- }
674
- })
675
- }
676
- }
677
- }
678
- /*
679
- * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
680
- * @method showPolyline_BI
681
- * @param {参数类型} 参数名 参数说明
682
- *
683
- * @return {返回值类型} 返回值说明
684
- *
685
- * @author: Hetianhong
686
- * @date: 2021-11-11 15:40:31
687
- */
688
- this.showPolyline_BI = function (layerName, positions = [], options = {}) {
689
- if (globeMap !== null) {
690
- // 默认参数
691
- let defaultOpt = {
692
- // 样式类
693
- styleOpt: {
694
- period: 4, // 动画线段的周期,越短越快
695
- image: 'road.png', // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
696
- repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
697
- repeatY: 1, //纵向纹理重复(type为image限定)
698
- glowPower: 0, //中心亮度
699
- intensity: 1.2, //纹理图片颜色强度
700
- gapColor: 'rgba(0, 0, 0, 0)', //间隙颜色(type为dash限定)
701
- dashLength: 15, //间隙宽(type为dash限定)
702
- outlineWidth: 0, // 边框线宽(type为outline限定)
703
- outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
704
- type: 'color', // 线条类型,有 image color dash outline glow
705
- width: 10,
706
- color: "rgba(255,255,0,1)"
707
- },
708
- // 视角缩放类
709
- zoomOpt: {
710
- //zoom参数
711
- heading: 0,
712
- pitch: -90,
713
- range: null,
714
- //可视级别
715
- minZoom: 0,
716
- maxZoom: 24,
717
- //泛光绘制
718
- // 下面两项,不暴露,全部为false
719
- bloom: false,
720
- merge: false
721
- },
722
- // 交互类
723
- interactOpt: {
724
- //click相关
725
- clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
726
- clickWidth: 30, // 点击后的宽度
727
- clickCallback: undefined, // function(e) {console.log('click polyline', e)},
728
- mouseOverCallBack: undefined
729
- }
730
- }
731
- let getMergedOptions = (options) => {
732
- let mergedOptions = {};
733
- mergedOptions.styleOpt = Object.assign({}, defaultOpt.styleOpt, options.styleOpt);
734
- mergedOptions.zoomOpt = Object.assign({}, defaultOpt.zoomOpt, options.zoomOpt);
735
- mergedOptions.interactOpt = Object.assign({}, defaultOpt.interactOpt, options.interactOpt);
736
- return mergedOptions
737
- }
738
- let mergedOptions = getMergedOptions(options);
739
-
740
-
741
- let opt = {}
742
- // let styleOpt = options.styleOpt;
743
- // let zoomOpt = options.zoomOpt;
744
- // let interactOpt = options.interactOpt;
745
- //hth 此处进行参数转换
746
- switch (mergedOptions.styleOpt.type) {
747
- case "image":
748
- opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
749
- opt.image = defaultValue(mergedOptions.styleOpt.image, 'road.png'); //纹理图片,data3d/polyline/目录下
750
- opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
751
- opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
752
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
753
- opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
754
- break;
755
- case "glow":
756
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
757
- break;
758
- case "dash":
759
- opt.gapColor = defaultValue(mergedOptions.styleOpt.gapColor, 'rgba(0, 0, 0, 0)'); //间隙颜色
760
- opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
761
- break;
762
- case "outline":
763
- opt.outlineWidth = defaultValue(mergedOptions.styleOpt.outlineWidth, 0);
764
- opt.outlineColor = defaultValue(mergedOptions.styleOpt.outlineColor, "rgba(0, 0, 0, 0)");
765
- break;
766
- default:
767
- // color
768
- };
769
-
770
- opt.type = mergedOptions.styleOpt.type;
771
- opt.width = mergedOptions.styleOpt.width;
772
- opt.color = mergedOptions.styleOpt.color;
773
-
774
- // 遍历位置数组中的每一项
775
- for(let pos of positions) {
776
- // 遍历opt中每一个key赋值到每一个pos中
777
- for(let k in opt) {
778
- pos[k] = opt[k]
779
- }
780
- }
781
-
782
-
783
- let zoom = mergedOptions.zoomOpt.zoom
784
- let clear = mergedOptions.zoomOpt.clear
785
- let clickCallback = mergedOptions.interactOpt.clickCallback
786
- let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack
787
- let commonOpt = {
788
- //zoom参数
789
- heading: mergedOptions.zoomOpt.heading,
790
- pitch: mergedOptions.zoomOpt.pitch,
791
- range: mergedOptions.zoomOpt.range,
792
- //可视级别
793
- minZoom: mergedOptions.zoomOpt.minZoom,
794
- maxZoom: mergedOptions.zoomOpt.maxZoom,
795
- //click相关
796
- clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
797
- clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
798
- //泛光绘制
799
- // 下面两项,不暴露,全部为false
800
- bloom: false,
801
- merge: false
802
- }
803
-
804
-
805
- globeMap.showPolyline(positions, zoom, clear, commonOpt, layerName, clickCallback, mouseOverCallBack);
806
- }
807
- }
808
- /*
809
- * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
810
- * @method activeLayer
811
- * @param {String} layerName 图层名
812
- * @param {Object} options 配置项
813
- * @param {String} options.type 操作类型,'clear', 'active'
814
- * @param {Boolean} options.zoom 是否缩放
815
- * @param {Object} filter 过滤项
816
- * @param {String} filter.keyFieldName 过滤键名
817
- * @param {Array} filter.values 过滤值内容数组
818
- *
819
- * @return {返回值类型} 返回值说明
820
- *
821
- * @author: Hetianhong
822
- * @date: 2021-11-26 09:49:16
823
- */
824
- this.activeLayer = function (layerName, options, filter) {
825
- if (globeMap != null && mapType == "globe") {
826
- globeMap.activeLayer(layerName, options, filter);
827
- }
828
- if (gisMap != null && mapType == "map") {
829
- gisMap.activeLayer(layerName, options, filter);
830
- }
831
- }
832
-
833
- function gridPolygon2dOperation(options, data, callback) {
834
- var storeName = `usage2D_${options.idbSetting.usageID}`;
835
- function showGrid(realData) {
836
- // 转换一下
837
- var geometries = [];
838
- var extraGeometries = [];
839
- var specialAreaS=options.specialAreaS;//玲珑平台分类设色
840
- for (var i = 0; i < realData.length; i++) {
841
- var feature = realData[i];
842
- var geom = feature.geometry;
843
- geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
844
- var hasPush=false;
845
- if(specialAreaS&&specialAreaS.length>0){
846
- for (var j = 0; j < specialAreaS.length; j++) {
847
- var specialArea=specialAreaS[j];
848
- if(!specialArea.geometries){
849
- specialArea.geometries=[];
850
- }
851
- let filterResult=new Function(`return ${specialArea.statusControl.compiled}`)().call(null,feature.attributes);
852
- if(filterResult==true){
853
- specialArea.geometries.push(geom);
854
- hasPush=true;
855
- }
856
- }
857
- }
858
- !hasPush&&(geometries.push(geom));
859
- }
860
- if (options.specialArea && options.selectedSetting.selected.length) {
861
- var extraIds = options.selectedSetting.selected.map(s => s.selectID);
862
- for (var i = geometries.length - 1; i > -1; i--) {
863
- var geom = geometries[i];
864
- if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
865
- geometries.splice(i, 1);
866
- extraGeometries.push(geom);
867
- if (extraGeometries.length === extraIds.length) break;
868
- }
869
- }
870
- }
871
- gisMap.locateFeatureByCoords(geometries, 'polygon',
872
- options.layerName, // id,如果已经有attributes就没用了
873
- options.style, // style
874
- options.highlightStyle, // highlightStyle
875
- options.commonSetting.zoom, // zoom
876
- options.keyFieldName,
877
- options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
878
- options.labelStyle, // labelStyle
879
- options.customColor ? interpolateColor(options.customColor[0], options.customColor[1], Math.min(geometries.length, 10)) : 10, // randomColor
880
- false, // renderCanvas
881
- true, // singleSelect
882
- {
883
- minZoom: options.visiblitySetting.beginLevel,
884
- maxZoom: options.visiblitySetting.endLevel,
885
- layerId: options.layerName,
886
- comCallbak: callback
887
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
888
- },
889
- options.layerName, // layerTag
890
- options.eventSetting.clickCallback
891
- );
892
- if (extraGeometries.length) {
893
- gisMap.locateFeatureByCoords(extraGeometries, 'polygon',
894
- options.layerName, // id,如果已经有attributes就没用了
895
- options.specialAreaStyle, // style
896
- options.highlightStyle, // highlightStyle
897
- false, // zoom
898
- options.keyFieldName,
899
- options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
900
- options.specialAreaLabelStyle, // labelStyle
901
- false, // randomColor
902
- false, // renderCanvas
903
- true, // singleSelect
904
- {
905
- minZoom: options.visiblitySetting.beginLevel,
906
- maxZoom: options.visiblitySetting.endLevel,
907
- layerId: options.layerName
908
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
909
- },
910
- options.layerName, // layerTag
911
- options.eventSetting.clickCallback
912
- );
913
- }
914
- if(specialAreaS&&specialAreaS.length>0){
915
- for (var j = 0; j < specialAreaS.length; j++) {
916
- var specialArea=specialAreaS[j];
917
- if(specialArea.geometries.length>0){
918
- gisMap.locateFeatureByCoords(specialArea.geometries, 'polygon',
919
- options.layerName, // id,如果已经有attributes就没用了
920
- specialArea.style, // style
921
- options.highlightStyle, // highlightStyle
922
- options.commonSetting.zoom, // zoom
923
- options.keyFieldName,
924
- specialArea.specialAreaStyle.textLabelShowEnabled&&specialArea.specialAreaStyle.labelFieldName, // keyField, labelField
925
- specialArea.labelStyle, // labelStyle
926
- false,// randomColor
927
- false, // renderCanvas
928
- true, // singleSelect
929
- {
930
- minZoom: options.visiblitySetting.beginLevel,
931
- maxZoom: options.visiblitySetting.endLevel,
932
- layerId: options.layerName,
933
- comCallbak: callback
934
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
935
- },
936
- options.layerName, // layerTag
937
- options.eventSetting.clickCallback
938
- );
939
- }
940
-
941
- }
942
- }
943
- }
944
-
945
- if (!data) {
946
- // 数据来自本地
947
- var dbOpenRequest = window.indexedDB.open('regionDB');
948
- dbOpenRequest.onsuccess = function(event) {
949
- var db = this.result;
950
- var store = db.transaction(storeName).objectStore(storeName);
951
- var request = store.getAll();
952
- request.onsuccess = function() {
953
- var features = this.result;
954
- showGrid(features);
955
- }
956
- }
957
- } else {
958
- var _data = JSON.parse(JSON.stringify(data[0]));
959
- var newData = data[0];
960
- if (newData && newData.geometry) {
961
- _data = JSON.parse(JSON.stringify(data));
962
- showGrid(data);
963
- } else {
964
- showGrid(data[0]);
965
- }
966
-
967
- var dbRequest = window.indexedDB.open('regionDB');
968
- dbRequest.onsuccess = function() {
969
- addStore(this.result.version);
970
- }
971
- function addStore(version) {
972
- var dbOpenRequest = window.indexedDB.open('regionDB', version + 1);
973
- dbOpenRequest.onupgradeneeded = function(event) {
974
- var db = event.target.result;
975
- if (!db.objectStoreNames.contains(storeName)) {
976
- var store = db.createObjectStore(storeName, { autoIncrement: true });
977
- for (var i = 0; i < _data.length; i++) {
978
- store.put(_data[i]);
979
- }
980
- store.transaction.oncomplete = function() {
981
- console.log("complete");
982
- }
983
- }
984
-
985
- }
986
- }
987
- }
988
- }
989
-
990
- this.networkCloud = function (options, positions) {
991
- if(!globeMap) {return}
992
- globeMap.networkCloud(options, positions)
993
- }
994
- this.clearNetworkCloud = function (layerNames) {
995
- if(!globeMap) {return}
996
- globeMap.clearNetworkCloud(layerNames)
997
- }
998
- this.lineOperation = function(options, data) {
999
- if(!options || !options.layerName){
1000
- console.log('图层名必须传递')
1001
- return
1002
- }
1003
- // 数据获取
1004
- let queryFeature = (queryParams) => {
1005
- if(gisMap) {
1006
- return new Promise(function(resolve) {
1007
- let cb = function(result) {
1008
- resolve(result)
1009
- }
1010
- gisMap.queryFeature(queryParams, cb)
1011
- })
1012
- } else {
1013
- return Promise.resolve(undefined)
1014
- }
1015
- }
1016
- // 执行绘制
1017
- let drawLine = (options, data) => {
1018
- if (globeMap) globeMap.lineOperation(options, data);
1019
- else if (gisMap) {
1020
- let style = options.style || {};
1021
- let hStyle = options.hStyle || {};
1022
- let symbol = {
1023
- type: "simple-line", // autocasts as new SimpleLineSymbol()
1024
- color: style.color || "lightblue",
1025
- width: (style.width || 2) + "px",
1026
- style: style.style || "short-dot"
1027
- };
1028
- let hsymbol = {
1029
- type: "simple-line", // autocasts as new SimpleLineSymbol()
1030
- color: hStyle.color || "lightblue",
1031
- width: (hStyle.width || 2) + "px",
1032
- style: hStyle.style || "short-dot"
1033
- };
1034
- var opt = options.options || {};
1035
- gisMap.locateFeatureByCoords(data, options.type, options.id, symbol, hsymbol, options.zoom, options.keyField,
1036
- options.labelField,
1037
- options.labelStyle,
1038
- options.randomColor,
1039
- options.renderCanvas,
1040
- options.singleSelected,
1041
- opt,
1042
- options.layerTag,
1043
- options.callback
1044
- );
1045
- }
1046
- }
1047
-
1048
- // 主逻辑
1049
- if(!!data&&data.length) {
1050
- drawLine(options, data)
1051
- } else {
1052
- if(!options.usageID) {
1053
- console.log('图层用途必须传递')
1054
- return
1055
- }
1056
-
1057
- let originalData = false;
1058
- if (globeMap) originalData = true;
1059
- let queryParams = {
1060
- layerID: options.usageID,
1061
- where: options.filterString || "1=1",
1062
- geometry: '',
1063
- outGeometry: true,
1064
- options: { originalData: originalData }
1065
- }
1066
- queryFeature(queryParams)
1067
- .then(function(resultData) {
1068
- if(!resultData) {
1069
- console.log('没有查询到数据,请检查查询参数')
1070
- return
1071
- }
1072
- drawLine(options, resultData)
1073
- })
1074
- }
1075
-
1076
- }
1077
- }
1078
-
1079
-
1
+ var egovaBI = function(globeMap, gisMap, mapType){
2
+
3
+ function defaultValue(a, b) {
4
+ if (a !== undefined && a !== null) {
5
+ return a;
6
+ }
7
+ return b;
8
+ }
9
+
10
+ function getImgSize(url) {
11
+ return new Promise((resolve, reject) => {
12
+ let img = new Image();
13
+ img.onload = function() {
14
+ resolve({ width: img.width, height: img.height });
15
+ img = null;
16
+ };
17
+ img.onerror = function() {
18
+ resolve({ width: 0, height: 0 });
19
+ img = null;
20
+ };
21
+ img.src = url;
22
+ });
23
+ }
24
+
25
+ function interpolateColor(startColor, endColor, count) {
26
+ if (count < 2) return [startColor, endColor];
27
+
28
+ var start = rgbToRgbArray(startColor);
29
+ var end = rgbToRgbArray(endColor);
30
+ var end0 = end[0];
31
+ var end1 = end[1];
32
+ var end2 = end[2];
33
+ var end3 = end[3];
34
+ var start0 = start[0];
35
+ var start1 = start[1];
36
+ var start2 = start[2];
37
+ var start3 = start[3];
38
+
39
+ var r = end0 - start0;
40
+ var g = end1 - start1;
41
+ var b = end2 - start2;
42
+ var opacity = end3 - start3;
43
+ var step = 1.0 / count;
44
+ var colors = [startColor];
45
+ var _count = count - 1;
46
+ for (var i = 1; i < _count; i++) {
47
+ var interval = step * i;
48
+ colors.push([
49
+ Math.round(start0 + interval * r),
50
+ Math.round(start1 + interval * g),
51
+ Math.round(start2 + interval * b),
52
+ (start3 + interval * opacity)
53
+ ])
54
+ }
55
+ colors.push(endColor);
56
+ return colors;
57
+ }
58
+
59
+ function rgbToRgbArray(color) {
60
+ if (!color || typeof color !== 'string' || (typeof color == 'string'&&color.indexOf('rgb') == -1) ) return color;
61
+
62
+ var r, g, b, a;
63
+ var rgbaAttr = color.match(/[\d.]+/g);
64
+ if (rgbaAttr.length >= 3) {
65
+ r = parseInt(rgbaAttr[0]);
66
+ g = parseInt(rgbaAttr[1]);
67
+ b = parseInt(rgbaAttr[2]);
68
+ if (rgbaAttr.length > 3) a = parseFloat(rgbaAttr[3]);
69
+ else a = 1;
70
+ }
71
+ return [ r, g, b, a];
72
+ };
73
+
74
+ // 查询idb是否存在表
75
+ function checkObjectStore (storeName) {
76
+ return new Promise((resolve, reject) => {
77
+ // 打开网格数据库
78
+ let idbRequest = window.indexedDB.open('regionDB');
79
+ idbRequest.onblocked = function(event) {
80
+ // 如果其他的一些页签加载了该数据库,在我们继续之前需要关闭它们
81
+ // alert("请关闭其他由该站点打开的页签!");
82
+ console.log("请关闭其他由该站点打开的页签!")
83
+ };
84
+ idbRequest.onerror = (event) => {
85
+ console.log('数据库打开报错(checkObjectStore)');
86
+ // resolve(undefined)
87
+ reject(event.target.error.message)
88
+ };
89
+
90
+ idbRequest.onsuccess = () => {
91
+ let db = idbRequest.result;
92
+ // console.log('数据库打开成功(hasObjectStore)')
93
+ resolve(db.objectStoreNames.contains(storeName))
94
+ db.close()
95
+ };
96
+ })
97
+ }
98
+
99
+ function deal2DPoints(layerName, positions, options) {
100
+ let datalist = [];
101
+ let zoom = options.common.zoom;
102
+ let clear = options.common.clear;
103
+ let highLightType = -1;
104
+ let infoStyle = null;
105
+ let renderCanvas = null;
106
+ let tagName = layerName;
107
+ let clusterOption = null;
108
+
109
+ let hasHover = null;
110
+ let callback = null;
111
+ datalist = positions.map(function(p) {
112
+ if(options.textStyle.label) {
113
+ for (const key in p) {
114
+ if(key !== "id" && key !== "x" && key !== "y" && key !== "objectID"){
115
+ if(!p.label) p.label = [];
116
+ var labelItem = {};
117
+ labelItem[key] = p[key];
118
+ p.label.push(labelItem);
119
+ }
120
+ }
121
+ }
122
+ p.minZoom = options.common.beginLevel;
123
+ p.maxZoom = options.common.endLevel;
124
+ p.symbolType = -1;
125
+ p.symbolUrl = options.textStyle.symbolUrl || "location.png";
126
+ p.scale = options.textStyle.scale;
127
+ p.angle = options.textStyle.angle;
128
+ //classify symbol
129
+ if (options.textStyle.enableClassify) {
130
+ const customScheme = options.textStyle.customScheme;
131
+ const classField = options.textStyle.classField;
132
+ if (p[classField] && Object.prototype.toString.call(customScheme)=="[object Array]" && customScheme.length) {
133
+ customScheme.forEach(scheme => {
134
+ if (scheme.type == p[classField]) {
135
+ scheme.imageUrl && (p.symbolUrl = scheme.imageUrl);
136
+ }
137
+ });
138
+ }
139
+ }
140
+ //textValue
141
+ if (options.textStyle.enableText) {
142
+ p.labelStyle = {
143
+ type: "text",
144
+ xoffset: options.textStyle.xoffset + "px",
145
+ yoffset: options.textStyle.yoffset + "px",
146
+ text: p.textValue,
147
+ color: options.textStyle.fillColor,
148
+ font: {
149
+ size: options.textStyle.fontSize + "px",
150
+ weight: options.textStyle.fontWeight,
151
+ family: options.textStyle.family || "microsoft-yahei"
152
+ }
153
+ };
154
+ }
155
+ p.useLabelBg = options.textStyle.textBackground;
156
+ if (p.useLabelBg) {
157
+ p.labelBgStyle = {
158
+ type: "picture-marker",
159
+ url: options.textStyle.textBackgroundUrl
160
+ };
161
+ }
162
+ return p;
163
+ });
164
+
165
+ return new Promise((resolve, reject) => {
166
+ try {
167
+ let args = {
168
+ datalist: datalist,
169
+ zoom: zoom,
170
+ clear: clear,
171
+ highLightType: highLightType,
172
+ infoStyle: infoStyle,
173
+ renderCanvas: renderCanvas,
174
+ tagName: tagName,
175
+ clusterOption: null,
176
+ hasHover: hasHover,
177
+ callback: callback
178
+ };
179
+ if (options.clusterStyle.clusterEnabled) {
180
+ clusterOption = {
181
+ clusterType: options.clusterStyle.clusterType,
182
+ distance: options.clusterStyle.clusterDistance,
183
+ style: null,
184
+ labelStyle: {
185
+ type: "text",
186
+ color: options.clusterStyle.fillColor,
187
+ text: "",
188
+ xoffset: options.clusterStyle.xoffset + "px",
189
+ yoffset: options.clusterStyle.yoffset + "px",
190
+ font: {
191
+ size: options.clusterStyle.fontSize + "px",
192
+ weight: options.clusterStyle.fontWeight || "normal",
193
+ family: options.clusterStyle.family || "microsoft-yahei"
194
+ }
195
+ }
196
+ };
197
+
198
+ let useCustomClusterStyle = options.clusterStyle.symbolUrl && options.clusterStyle.useCustomStyle;
199
+ let clusterStyle = {
200
+ type: "simple-marker",
201
+ style: "circle",
202
+ color: [255, 168, 0, 200],
203
+ size: 25 * options.clusterStyle.scale + "px",
204
+ outline: {
205
+ color: [255, 168, 0, 200],
206
+ width: 2
207
+ }
208
+ };
209
+ clusterOption.style = clusterStyle;
210
+ if (useCustomClusterStyle) {
211
+ getImgSize(options.clusterStyle.symbolUrl).then(szie => {
212
+ clusterStyle = {
213
+ type: "picture-marker",
214
+ url: options.clusterStyle.symbolUrl,
215
+ width: szie.width * options.clusterStyle.scale + "px",
216
+ height: szie.height * options.clusterStyle.scale + "px"
217
+ };
218
+ clusterOption.style = clusterStyle;
219
+ args.clusterOption = clusterOption;
220
+ resolve(args);
221
+ });
222
+ } else {
223
+ args.clusterOption = clusterOption;
224
+ resolve(args);
225
+ }
226
+ } else {
227
+ resolve(args);
228
+ }
229
+ } catch (err) {
230
+ reject(err);
231
+ }
232
+ });
233
+ }
234
+
235
+ /*
236
+ * @description:新参数格式的旧热力接口,主要用来做中间层参数格式转换
237
+ * @method showHeatImage3D_BI
238
+ * @param {String} layerName 热力参数数组
239
+ * @param {Array} data 热力值和坐标的数据数组
240
+ * @param {Object} options 配置项
241
+ * @param {Object} options.heatOpt 热力配置项
242
+ * @param {Object} options.commonOpt 通用配置项
243
+ *
244
+ * @return {Void}} 无返回
245
+ *
246
+ * @author: Hetianhong
247
+ * @date: 2021-08-31 14:13:42
248
+ */
249
+ this.showHeatImage3D_BI = function (layerName, data, option) {
250
+ //data必须包含x y value属性
251
+ if(
252
+ data.length === 0 ||
253
+ !data[0].hasOwnProperty('x') ||
254
+ !data[0].hasOwnProperty('y') ||
255
+ !data[0].hasOwnProperty('value')
256
+ ) {
257
+ return
258
+ }
259
+ if (globeMap != null) {
260
+ //hth 此处进行参数转换
261
+ let commonOpt = option.commonOpt; // 通用配置项
262
+ let heatOpt = option.heatOpt; // 热力配置项
263
+
264
+ let info = {};
265
+ let zoom = defaultValue(commonOpt.zoom, false);
266
+ let clear = defaultValue(commonOpt.clear, true);
267
+ let options = {
268
+ heading: defaultValue(commonOpt.heading, 0),
269
+ pitch: defaultValue(commonOpt.pitch, -45),
270
+ range: defaultValue(commonOpt.range, 8000),
271
+ maxDataLength : defaultValue(commonOpt.maxDataLength, 5),
272
+ layerName: layerName
273
+ }
274
+
275
+ // 开始组装info
276
+ //组装info.data,其实也没啥组装的
277
+ info.data = data
278
+
279
+ //组装info.options
280
+ info.options = {
281
+ clampStyle: (heatOpt.heatType === 0) ? 0 : 3, // 如果设置了为0,则为0,其余则全部为旧逻辑的3绘制方式,即贴地贴建筑
282
+ renderType: defaultValue(heatOpt.renderType, "line"),
283
+ dynamicGranularity: defaultValue(heatOpt.dynamicGranularity, false),
284
+ granularity: defaultValue(heatOpt.granularity, 500),
285
+ maxHeight: defaultValue(heatOpt.maxHeight, -1),
286
+ height: defaultValue(heatOpt.height, 10),
287
+ radiusScale: defaultValue(heatOpt.radiusScale, 1.0),
288
+ radius: defaultValue(heatOpt.radius, 40),
289
+ gradient: defaultValue(heatOpt.gradient, {
290
+ 0.35: "rgb(136,218,104)",
291
+ 0.7: "rgb(241,238,124)",
292
+ 1.0: "rgb(243,118,116)"
293
+ }),
294
+
295
+ // 下面的部分不建议传,逐步舍弃
296
+ gridSize: defaultValue(heatOpt.gridSize, null),
297
+ blur: defaultValue(heatOpt.blur, 0.85),
298
+ }
299
+
300
+ // 转换过后,使用旧的参数格式调用原热力接口
301
+ globeMap.showHeatImage3D(info, zoom, clear, options);
302
+ }
303
+ }
304
+
305
+ /*
306
+ * @description:打点和聚类接口进行整合后的新接口
307
+ * @method drawPoint
308
+ * @param {String} layerName 图层名
309
+ * @param {Array} positions 位置数组
310
+ * @param {Object} options 配置项
311
+ *
312
+ * @return {Void} 无返回
313
+ *
314
+ * @author: Hetianhong
315
+ * @date: 2021-09-09 14:49:49
316
+ */
317
+ this.drawPoints = function (layerName, positions, options) {
318
+ let drawData = function (layerName, positions, options) {
319
+ if (globeMap && mapType == "globe") {
320
+ globeMap.drawPoints(layerName, positions, options);
321
+ }else if(gisMap && mapType == "map"){
322
+ deal2DPoints(layerName, positions, options).then(args => {
323
+ gisMap.showMultiObjectCurrentPosition(
324
+ args.datalist,
325
+ args.zoom,
326
+ args.clear,
327
+ args.highLightType,
328
+ args.infoStyle,
329
+ args.renderCanvas,
330
+ args.tagName,
331
+ options.clickCallback,
332
+ options.mouseOverCallback,
333
+ args.clusterOption,
334
+ args.hasHover,
335
+ layerName,
336
+ options.mouseOutCallback,
337
+ options.option
338
+ );
339
+ });
340
+ }
341
+ }
342
+
343
+
344
+ if (!options.usageID) {
345
+ drawData(layerName, positions, options);
346
+ return;
347
+ }
348
+ let queryFeature = (queryParams) => {
349
+ return new Promise(function(resolve) {
350
+ let cb = function(result) {
351
+ resolve(result)
352
+ }
353
+ if(gisMap) {
354
+ gisMap.queryFeature(queryParams, cb);
355
+ }else{
356
+ return Promise.resolve(undefined)
357
+ }
358
+ })
359
+
360
+ }
361
+ let queryParams = {
362
+ layerID: options.usageID,
363
+ outGeometry: true,
364
+ }
365
+ queryFeature(queryParams)
366
+ .then(function(resultData) {
367
+ if(!resultData) {
368
+ console.log('没有查询到数据,请检查查询参数')
369
+ return
370
+ }
371
+ let dataCache=[];
372
+ let errorSize=0;
373
+ resultData.forEach(element => {
374
+ let x,y;
375
+ if(element.geometry){
376
+ x=element.geometry.x;
377
+ y=element.geometry.y;
378
+ }
379
+ if(x&&y){
380
+ let item={...element.attributes,x,y};
381
+ dataCache.push(item);
382
+ }else{
383
+ errorSize++;
384
+ }
385
+ });
386
+ if(errorSize>0){
387
+ console.error(`${errorSize}个点格式错误,无法正常加载`);
388
+ }
389
+
390
+ drawData(layerName, dataCache, options);
391
+ })
392
+
393
+ }
394
+ this.getLabel = function (attributes) {
395
+ if (!attributes) return;
396
+ var label = [], field = {};
397
+ for (var key in attributes) {
398
+ field = {};
399
+ field[key] = attributes[key];
400
+ label.push(field);
401
+ }
402
+ return label;
403
+ };
404
+ this.drawParts = function (options, data, callback) {
405
+ var self = this;
406
+ function showParts(data) {
407
+ var drawParam = options.drawParam || {};
408
+ var ctrOption = drawParam.clusterOption;
409
+ var clusterOption = {
410
+ clusterType: ctrOption.clusterType,
411
+ level: ctrOption.level || 0,
412
+ style: {
413
+ "type": "simple-marker",
414
+ "style": "circle",
415
+ "color": ctrOption.color || [255, 0, 0, 0.6],
416
+ "size": ctrOption.size || 20,
417
+ "outline": { //if outline has been specified
418
+ "color": ctrOption.outlineColor || [255, 168, 0, 1],
419
+ "width": ctrOption.outlineWidth || 2
420
+ }
421
+ },
422
+ labelStyle: {
423
+ "type": "text",
424
+ "color": ctrOption.labelColor || [255, 255, 255, 1],
425
+ "text": "",
426
+ "zlevel": ctrOption.labelZlevel || 1,
427
+ "yoffset": 0,
428
+ "font": ctrOption.labelFont || {
429
+ "family": "Arial",
430
+ "size": 10
431
+ }
432
+ },
433
+ distance: ctrOption.distance || 50
434
+ };
435
+
436
+ var param = [data, true, false, null, null, false, drawParam.tagName, drawParam.clickCallback, drawParam.mouseOverCallback, clusterOption, false, drawParam.layerName, drawParam.callback, drawParam.drawOptions];
437
+ //三维聚类参数
438
+ var globeOptions = {
439
+ zoom:true,
440
+ scale: 0.9,
441
+ clear :true,
442
+ nearFarScalar:[8000, 1.0, 10000, 0.6],
443
+ clickCallBack: drawParam.clickCallback,
444
+ layerName: drawParam.layerName,
445
+ minSize:30,
446
+ clusterLimit: 20,
447
+ style:"default",
448
+ clusterImageInfo: {
449
+ horizontalOrigin: "center",
450
+ verticalOrigin: "bottom",
451
+ cssStyle: {
452
+ "borderRadius": 500,
453
+ "fillColor": "rgba(0,0,0,0.7)",
454
+ "borderLineWidth": 3,
455
+ "borderLineColor": "rgba(250,140,0,0.9)",
456
+ "paddingX": 15,
457
+ "paddingY": 6,
458
+ "marginBottom": 2
459
+ },
460
+ textStyle: {
461
+ "font": "60px Helvetica",
462
+ "fillColor": "rgba(220,220,220,1.0)",
463
+ "outlineColor": "black",
464
+ "outlineWidth": 1,
465
+ "padding": 1,
466
+ "textScale": 0.5,
467
+ "textStartX": 40,
468
+ "textStartY": 15
469
+ }
470
+ }
471
+ }
472
+ if (globeMap) {
473
+ globeMap.addClusterLayer({
474
+ data,
475
+ options:globeOptions
476
+ })
477
+ } else if (gisMap) {
478
+ gisMap.showMultiObjectCurrentPosition(...param );
479
+ }
480
+ }
481
+
482
+ if (data) {
483
+ showParts(data);
484
+ } else {
485
+ let queryFromGIS = () => {
486
+ let queryParam = options.queryParam;
487
+ var subTypeName = options.subTypeName;
488
+ var subUniqueCode = options.subUniqueCode;
489
+ let queryCallback = function (featureInfos) {
490
+ var features = featureInfos[queryParam.phyLayerIDs];
491
+ if (features.length == 0) {
492
+ callback && callback([]);
493
+ return;
494
+ }
495
+ if (!features || !features.length) return;
496
+ var symbolUrl = "";
497
+ if (subUniqueCode.indexOf("http") > -1) {
498
+ symbolUrl = subUniqueCode;
499
+ } else if (subUniqueCode.indexOf(".") > -1) {
500
+ symbolUrl = subUniqueCode;
501
+ } else {
502
+ symbolUrl = "".concat(subUniqueCode, ".png");
503
+ if(globeMap) symbolUrl = queryParam.gisServerURL ? `${queryParam.gisServerURL}/symbol/${symbolUrl}` : symbolUrl;
504
+ }
505
+ var dataList = features.map((function (feature) {
506
+ return Object.assign({}, { x: feature.geometry.x, y: feature.geometry.y }, {
507
+ attributes: feature.attributes,
508
+ // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
509
+ symbolType: -1,
510
+ symbolUrl: symbolUrl,
511
+ scale: 0.5
512
+ });
513
+ }));
514
+ callback && callback(dataList);
515
+ showParts(dataList);
516
+ };
517
+ if (gisMap) {
518
+ gisMap.queryPhylayerFeatures(queryParam, queryCallback);
519
+ }
520
+ }
521
+ queryFromGIS();
522
+ }
523
+ };
524
+
525
+ this.drawOtherParts = function (options, data) {
526
+ var self = this;
527
+ const geomType = options.geomType;
528
+ let queryParam = options.queryParam || {};
529
+ function showParts(data) {
530
+
531
+ }
532
+
533
+ if (data) {
534
+ showParts(data);
535
+ } else {
536
+ const layerID = queryParam.phyLayerIDs;
537
+ const layerName = queryParam.layerName;
538
+ const keyField = null;
539
+ const keyValue = null;
540
+ const clearMap = queryParam.clearMap || true;
541
+ let inStyle = queryParam.style || {
542
+ color: "blue"
543
+ };
544
+ let inHStyle = queryParam.hStyle || {
545
+ color: "blue"
546
+ };
547
+ let style = null, hStyle = null;
548
+ if (geomType == 1) {
549
+ } else if (geomType == 2) {
550
+ style = {
551
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
552
+ color: inStyle.color || "blue",
553
+ width: inStyle.width || "2px",
554
+ style: inStyle.style || "solid",
555
+ cap: inStyle.cap || "round",
556
+ join: inStyle.join || "round",
557
+ };
558
+ hStyle = {
559
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
560
+ color: inHStyle.color || "red",
561
+ width: inHStyle.width || inStyle.width || "2px",
562
+ style: inHStyle.style || inStyle.style || "solid",
563
+ cap: inHStyle.cap || inStyle.cap || "round",
564
+ join: inHStyle.join || inStyle.join || "round",
565
+ };
566
+ } else if (geomType == 3) {
567
+ style = {
568
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
569
+ color: inStyle.color || [51, 51, 204, 0.9],
570
+ style: inStyle.style || "solid",
571
+ outline: { // autocasts as new SimpleLineSymbol()
572
+ color: inStyle.outlineColor || "blue",
573
+ width: inStyle.outlineWidth || "1px",
574
+ style: inStyle.outlineStyle || "solid",
575
+ cap: inStyle.outlineCap || "round",
576
+ join: inStyle.outlineJoin || "round",
577
+ }
578
+ };
579
+ hStyle = {
580
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
581
+ color: inHStyle.color || [51, 51, 204, 0.9],
582
+ style: inHStyle.style || inStyle.style || "solid",
583
+ outline: { // autocasts as new SimpleLineSymbol()
584
+ color: inHStyle.outlineColor || "red",
585
+ width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
586
+ style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
587
+ cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
588
+ join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
589
+ }
590
+ };
591
+ }
592
+ const bZoom = queryParam.bZoom || true;
593
+ const randomColor = null;
594
+ const labelField = null;
595
+ const labelstyle = null;
596
+ const geometry = null;
597
+ const where = queryParam.where || "1=1";
598
+ const opts = {
599
+ layerId: layerName,
600
+ mouseOverCallback: queryParam.mouseOverCallback
601
+ };
602
+
603
+ let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, null, null, queryParam.clickCallback];
604
+ //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
605
+ if (globeMap) {
606
+ gisMap.locateFeatureByIDs(...param);
607
+ } else if (gisMap) {
608
+ gisMap.locateFeatureByIDs(...param);
609
+ }
610
+
611
+ }
612
+ };
613
+
614
+ /*
615
+ * @description:新的轨迹线接口
616
+ * @method traceOperation
617
+ * @param {Array} posArr 位置数组
618
+ * @param {Object} options 配置项
619
+ *
620
+ * @return {Void} 无返回
621
+ *
622
+ * @author: Hetianhong
623
+ * @date: 2021-09-09 14:49:49
624
+ */
625
+ this.traceOperation = function (posArr, options) {
626
+ globeMap.traceOperation(posArr, options);
627
+ }
628
+ /*
629
+ * @description:网格接口
630
+ * 先查询idb的data,没有的话,再查询queryFeature的data
631
+ * @method regionOperation
632
+ * @param {Object} options 配置项
633
+ * @param {Array} data 数据,可不传
634
+ *
635
+ * @return {Void} 无返回
636
+ *
637
+ * @author: Hetianhong
638
+ * @date: 2021-10-19 17:27:02
639
+ */
640
+ this.regionOperation = function (options, data, callback) {
641
+
642
+ function execOperation(data) {
643
+ if (globeMap) {
644
+ globeMap.regionOperation(options, data);
645
+ callback && callback();
646
+ } else if (gisMap) {
647
+ gridPolygon2dOperation(options, data, callback);
648
+ }
649
+ }
650
+
651
+ if (data) {
652
+ execOperation(data);
653
+ } else {
654
+ if (!options.idbSetting.usageID) { return }
655
+
656
+ let storeName = !!globeMap ? "usageID" : "usage2D" + "_" + options.idbSetting.usageID;
657
+ let queryFromGIS = () => {
658
+ let filterString = options.idbSetting.filterString || "1=1";
659
+ let queryParam = {
660
+ layerID: options.idbSetting.usageID,
661
+ where: filterString,
662
+ geometry: '',
663
+ outGeometry: true,
664
+ options: {
665
+ originalData: true
666
+ }
667
+ }
668
+ //二维地图不获取原始数据
669
+ if(!globeMap) queryParam.options.originalData = false;
670
+ let queryCallback = function (featureInfos) {
671
+ execOperation(featureInfos);
672
+ }
673
+ if (gisMap) {
674
+ gisMap.queryFeature(queryParam, queryCallback)
675
+ }
676
+ }
677
+
678
+ if (!options.idbSetting.enabled) {
679
+ // 直接查询
680
+ queryFromGIS()
681
+ } else {
682
+ // 查询是否存在表
683
+ checkObjectStore(storeName)
684
+ .then(function (hasObjStore) {
685
+ if (hasObjStore) {
686
+ // 如果有,读取本地
687
+ execOperation();
688
+ } else {
689
+ // 如果没有,查询queryFeature
690
+ queryFromGIS()
691
+ }
692
+ })
693
+ }
694
+ }
695
+ }
696
+ /*
697
+ * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
698
+ * @method showPolyline_BI
699
+ * @param {参数类型} 参数名 参数说明
700
+ *
701
+ * @return {返回值类型} 返回值说明
702
+ *
703
+ * @author: Hetianhong
704
+ * @date: 2021-11-11 15:40:31
705
+ */
706
+ this.showPolyline_BI = function (layerName, positions = [], options = {}) {
707
+ if (globeMap !== null) {
708
+ // 默认参数
709
+ let defaultOpt = {
710
+ // 样式类
711
+ styleOpt: {
712
+ period: 4, // 动画线段的周期,越短越快
713
+ image: 'road.png', // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
714
+ repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
715
+ repeatY: 1, //纵向纹理重复(type为image限定)
716
+ glowPower: 0, //中心亮度
717
+ intensity: 1.2, //纹理图片颜色强度
718
+ gapColor: 'rgba(0, 0, 0, 0)', //间隙颜色(type为dash限定)
719
+ dashLength: 15, //间隙宽(type为dash限定)
720
+ outlineWidth: 0, // 边框线宽(type为outline限定)
721
+ outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
722
+ type: 'color', // 线条类型,有 image color dash outline glow
723
+ width: 10,
724
+ color: "rgba(255,255,0,1)"
725
+ },
726
+ // 视角缩放类
727
+ zoomOpt: {
728
+ //zoom参数
729
+ heading: 0,
730
+ pitch: -90,
731
+ range: null,
732
+ //可视级别
733
+ minZoom: 0,
734
+ maxZoom: 24,
735
+ //泛光绘制
736
+ // 下面两项,不暴露,全部为false
737
+ bloom: false,
738
+ merge: false
739
+ },
740
+ // 交互类
741
+ interactOpt: {
742
+ //click相关
743
+ clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
744
+ clickWidth: 30, // 点击后的宽度
745
+ clickCallback: undefined, // function(e) {console.log('click polyline', e)},
746
+ mouseOverCallBack: undefined
747
+ }
748
+ }
749
+ let getMergedOptions = (options) => {
750
+ let mergedOptions = {};
751
+ mergedOptions.styleOpt = Object.assign({}, defaultOpt.styleOpt, options.styleOpt);
752
+ mergedOptions.zoomOpt = Object.assign({}, defaultOpt.zoomOpt, options.zoomOpt);
753
+ mergedOptions.interactOpt = Object.assign({}, defaultOpt.interactOpt, options.interactOpt);
754
+ return mergedOptions
755
+ }
756
+ let mergedOptions = getMergedOptions(options);
757
+
758
+
759
+ let opt = {}
760
+ // let styleOpt = options.styleOpt;
761
+ // let zoomOpt = options.zoomOpt;
762
+ // let interactOpt = options.interactOpt;
763
+ //hth 此处进行参数转换
764
+ switch (mergedOptions.styleOpt.type) {
765
+ case "image":
766
+ opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
767
+ opt.image = defaultValue(mergedOptions.styleOpt.image, 'road.png'); //纹理图片,data3d/polyline/目录下
768
+ opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
769
+ opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
770
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
771
+ opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
772
+ break;
773
+ case "glow":
774
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
775
+ break;
776
+ case "dash":
777
+ opt.gapColor = defaultValue(mergedOptions.styleOpt.gapColor, 'rgba(0, 0, 0, 0)'); //间隙颜色
778
+ opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
779
+ break;
780
+ case "outline":
781
+ opt.outlineWidth = defaultValue(mergedOptions.styleOpt.outlineWidth, 0);
782
+ opt.outlineColor = defaultValue(mergedOptions.styleOpt.outlineColor, "rgba(0, 0, 0, 0)");
783
+ break;
784
+ default:
785
+ // color
786
+ };
787
+
788
+ opt.type = mergedOptions.styleOpt.type;
789
+ opt.width = mergedOptions.styleOpt.width;
790
+ opt.color = mergedOptions.styleOpt.color;
791
+
792
+ // 遍历位置数组中的每一项
793
+ for(let pos of positions) {
794
+ // 遍历opt中每一个key赋值到每一个pos中
795
+ for(let k in opt) {
796
+ pos[k] = opt[k]
797
+ }
798
+ }
799
+
800
+
801
+ let zoom = mergedOptions.zoomOpt.zoom
802
+ let clear = mergedOptions.zoomOpt.clear
803
+ let clickCallback = mergedOptions.interactOpt.clickCallback
804
+ let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack
805
+ let commonOpt = {
806
+ //zoom参数
807
+ heading: mergedOptions.zoomOpt.heading,
808
+ pitch: mergedOptions.zoomOpt.pitch,
809
+ range: mergedOptions.zoomOpt.range,
810
+ //可视级别
811
+ minZoom: mergedOptions.zoomOpt.minZoom,
812
+ maxZoom: mergedOptions.zoomOpt.maxZoom,
813
+ //click相关
814
+ clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
815
+ clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
816
+ //泛光绘制
817
+ // 下面两项,不暴露,全部为false
818
+ bloom: false,
819
+ merge: false
820
+ }
821
+
822
+
823
+ globeMap.showPolyline(positions, zoom, clear, commonOpt, layerName, clickCallback, mouseOverCallBack);
824
+ }
825
+ }
826
+ /*
827
+ * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
828
+ * @method activeLayer
829
+ * @param {String} layerName 图层名
830
+ * @param {Object} options 配置项
831
+ * @param {String} options.type 操作类型,'clear', 'active'
832
+ * @param {Boolean} options.zoom 是否缩放
833
+ * @param {Object} filter 过滤项
834
+ * @param {String} filter.keyFieldName 过滤键名
835
+ * @param {Array} filter.values 过滤值内容数组
836
+ *
837
+ * @return {返回值类型} 返回值说明
838
+ *
839
+ * @author: Hetianhong
840
+ * @date: 2021-11-26 09:49:16
841
+ */
842
+ this.activeLayer = function (layerName, options, filter) {
843
+ if (globeMap != null && mapType == "globe") {
844
+ globeMap.activeLayer(layerName, options, filter);
845
+ }
846
+ if (gisMap != null && mapType == "map") {
847
+ gisMap.activeLayer(layerName, options, filter);
848
+ }
849
+ }
850
+
851
+ function gridPolygon2dOperation(options, data, callback) {
852
+ var storeName = `usage2D_${options.idbSetting.usageID}`;
853
+ function showGrid(realData) {
854
+ // 转换一下
855
+ var geometries = [];
856
+ var extraGeometries = [];
857
+ var specialAreaS=options.specialAreaS;//玲珑平台分类设色
858
+ for (var i = 0; i < realData.length; i++) {
859
+ var feature = realData[i];
860
+ var geom = feature.geometry;
861
+ geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
862
+ var hasPush=false;
863
+ if(specialAreaS&&specialAreaS.length>0){
864
+ for (var j = 0; j < specialAreaS.length; j++) {
865
+ var specialArea=specialAreaS[j];
866
+ if(!specialArea.geometries){
867
+ specialArea.geometries=[];
868
+ }
869
+ var attributes=JSON.parse(JSON.stringify(feature.attributes));
870
+ let filterResult=new Function(`return ${specialArea.statusControl.compiled}`)().call(null,attributes);
871
+ if(filterResult==true){
872
+ specialArea.geometries.push(geom);
873
+ hasPush=true;
874
+ }
875
+ }
876
+ }
877
+ !hasPush&&(geometries.push(geom));
878
+ }
879
+ if (options.specialArea && options.selectedSetting.selected.length) {
880
+ var extraIds = options.selectedSetting.selected.map(s => s.selectID);
881
+ for (var i = geometries.length - 1; i > -1; i--) {
882
+ var geom = geometries[i];
883
+ if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
884
+ geometries.splice(i, 1);
885
+ extraGeometries.push(geom);
886
+ if (extraGeometries.length === extraIds.length) break;
887
+ }
888
+ }
889
+ }
890
+ gisMap.locateFeatureByCoords(geometries, 'polygon',
891
+ options.layerName, // id,如果已经有attributes就没用了
892
+ options.style, // style
893
+ options.highlightStyle, // highlightStyle
894
+ options.commonSetting.zoom, // zoom
895
+ options.keyFieldName,
896
+ options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
897
+ options.labelStyle, // labelStyle
898
+ options.customColor ? interpolateColor(options.customColor[0], options.customColor[1], Math.min(geometries.length, 10)) : 10, // randomColor
899
+ false, // renderCanvas
900
+ true, // singleSelect
901
+ {
902
+ minZoom: options.visiblitySetting.beginLevel,
903
+ maxZoom: options.visiblitySetting.endLevel,
904
+ layerId: options.layerName,
905
+ comCallbak: callback
906
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
907
+ },
908
+ options.layerName, // layerTag
909
+ options.eventSetting.clickCallback
910
+ );
911
+ if (extraGeometries.length) {
912
+ gisMap.locateFeatureByCoords(extraGeometries, 'polygon',
913
+ options.layerName, // id,如果已经有attributes就没用了
914
+ options.specialAreaStyle, // style
915
+ options.highlightStyle, // highlightStyle
916
+ false, // zoom
917
+ options.keyFieldName,
918
+ options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
919
+ options.specialAreaLabelStyle, // labelStyle
920
+ false, // randomColor
921
+ false, // renderCanvas
922
+ true, // singleSelect
923
+ {
924
+ minZoom: options.visiblitySetting.beginLevel,
925
+ maxZoom: options.visiblitySetting.endLevel,
926
+ layerId: options.layerName
927
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
928
+ },
929
+ options.layerName, // layerTag
930
+ options.eventSetting.clickCallback
931
+ );
932
+ }
933
+ if(specialAreaS&&specialAreaS.length>0){
934
+ for (var j = 0; j < specialAreaS.length; j++) {
935
+ var specialArea=specialAreaS[j];
936
+ if(specialArea.geometries.length>0){
937
+ gisMap.locateFeatureByCoords(specialArea.geometries, 'polygon',
938
+ options.layerName, // id,如果已经有attributes就没用了
939
+ specialArea.style, // style
940
+ options.highlightStyle, // highlightStyle
941
+ options.commonSetting.zoom, // zoom
942
+ options.keyFieldName,
943
+ specialArea.specialAreaStyle.textLabelShowEnabled&&specialArea.specialAreaStyle.labelFieldName, // keyField, labelField
944
+ specialArea.labelStyle, // labelStyle
945
+ false,// randomColor
946
+ false, // renderCanvas
947
+ true, // singleSelect
948
+ {
949
+ minZoom: options.visiblitySetting.beginLevel,
950
+ maxZoom: options.visiblitySetting.endLevel,
951
+ layerId: options.layerName,
952
+ comCallbak: callback
953
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
954
+ },
955
+ options.layerName, // layerTag
956
+ options.eventSetting.clickCallback
957
+ );
958
+ }
959
+
960
+ }
961
+ }
962
+ }
963
+
964
+ if (!data) {
965
+ // 数据来自本地
966
+ var dbOpenRequest = window.indexedDB.open('regionDB');
967
+ dbOpenRequest.onsuccess = function(event) {
968
+ var db = this.result;
969
+ var store = db.transaction(storeName).objectStore(storeName);
970
+ var request = store.getAll();
971
+ request.onsuccess = function() {
972
+ var features = this.result;
973
+ showGrid(features);
974
+ }
975
+ }
976
+ } else {
977
+ var _data = JSON.parse(JSON.stringify(data[0]));
978
+ var newData = data[0];
979
+ if (newData && newData.geometry) {
980
+ _data = JSON.parse(JSON.stringify(data));
981
+ showGrid(data);
982
+ } else {
983
+ showGrid(data[0]);
984
+ }
985
+
986
+ var dbRequest = window.indexedDB.open('regionDB');
987
+ dbRequest.onsuccess = function() {
988
+ addStore(this.result.version);
989
+ }
990
+ function addStore(version) {
991
+ var dbOpenRequest = window.indexedDB.open('regionDB', version + 1);
992
+ dbOpenRequest.onupgradeneeded = function(event) {
993
+ var db = event.target.result;
994
+ if (!db.objectStoreNames.contains(storeName)) {
995
+ var store = db.createObjectStore(storeName, { autoIncrement: true });
996
+ for (var i = 0; i < _data.length; i++) {
997
+ store.put(_data[i]);
998
+ }
999
+ store.transaction.oncomplete = function() {
1000
+ console.log("complete");
1001
+ }
1002
+ }
1003
+
1004
+ }
1005
+ }
1006
+ }
1007
+ }
1008
+
1009
+ this.networkCloud = function (options, positions) {
1010
+ if(!globeMap) {return}
1011
+ globeMap.networkCloud(options, positions)
1012
+ }
1013
+ this.clearNetworkCloud = function (layerNames) {
1014
+ if(!globeMap) {return}
1015
+ globeMap.clearNetworkCloud(layerNames)
1016
+ }
1017
+ this.lineOperation = function(options, data) {
1018
+ if(!options || !options.layerName){
1019
+ console.log('图层名必须传递')
1020
+ return
1021
+ }
1022
+ // 数据获取
1023
+ let queryFeature = (queryParams) => {
1024
+ if(gisMap) {
1025
+ return new Promise(function(resolve) {
1026
+ let cb = function(result) {
1027
+ resolve(result)
1028
+ }
1029
+ gisMap.queryFeature(queryParams, cb)
1030
+ })
1031
+ } else {
1032
+ return Promise.resolve(undefined)
1033
+ }
1034
+ }
1035
+ // 执行绘制
1036
+ let drawLine = (options, data) => {
1037
+ if (globeMap) globeMap.lineOperation(options, data);
1038
+ else if (gisMap) {
1039
+ let style = options.style || {};
1040
+ let hStyle = options.hStyle || {};
1041
+ let symbol = {
1042
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
1043
+ color: style.color || "lightblue",
1044
+ width: (style.width || 2) + "px",
1045
+ style: style.style || "short-dot"
1046
+ };
1047
+ let hsymbol = {
1048
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
1049
+ color: hStyle.color || "lightblue",
1050
+ width: (hStyle.width || 2) + "px",
1051
+ style: hStyle.style || "short-dot"
1052
+ };
1053
+ var opt = options.options || {};
1054
+ gisMap.locateFeatureByCoords(data, options.type, options.id, symbol, hsymbol, options.zoom, options.keyField,
1055
+ options.labelField,
1056
+ options.labelStyle,
1057
+ options.randomColor,
1058
+ options.renderCanvas,
1059
+ options.singleSelected,
1060
+ opt,
1061
+ options.layerTag,
1062
+ options.callback
1063
+ );
1064
+ }
1065
+ }
1066
+
1067
+ // 主逻辑
1068
+ if(!!data&&data.length) {
1069
+ drawLine(options, data)
1070
+ } else {
1071
+ if(!options.usageID) {
1072
+ console.log('图层用途必须传递')
1073
+ return
1074
+ }
1075
+
1076
+ let originalData = false;
1077
+ if (globeMap) originalData = true;
1078
+ let queryParams = {
1079
+ layerID: options.usageID,
1080
+ where: options.filterString || "1=1",
1081
+ geometry: '',
1082
+ outGeometry: true,
1083
+ options: { originalData: originalData }
1084
+ }
1085
+ queryFeature(queryParams)
1086
+ .then(function(resultData) {
1087
+ if(!resultData) {
1088
+ console.log('没有查询到数据,请检查查询参数')
1089
+ return
1090
+ }
1091
+ drawLine(options, resultData)
1092
+ })
1093
+ }
1094
+
1095
+ }
1096
+ }
1097
+
1098
+
1080
1099
  export default egovaBI