egovamap 0.18.13 → 0.18.14

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,1113 +1,1119 @@
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-regular"
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-regular"
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 map = globeMap || gisMap;
506
- //验证图标是否可查询
507
- map.getMapConfig("serverURL", function(key,data){
508
- var symbolServiceURL = `${data}/symbol`;
509
- var picUrl = (symbolUrl.indexOf("http") > -1 || symbolUrl.indexOf("https") > -1) ? symbolUrl:`${symbolServiceURL}/${symbolUrl}`;
510
- getImgSize(picUrl).then(size => {
511
- var dataList = features.map((function (feature) {
512
- return Object.assign({}, { x: feature.geometry.x, y: feature.geometry.y }, {
513
- attributes: feature.attributes,
514
- // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
515
- symbolType: -1,
516
- symbolUrl: (size.width || size.height) ? picUrl: (globeMap ?`${symbolServiceURL}/20100.png` : `20100.png`),
517
- scale: 0.5
518
- });
519
- }));
520
- callback && callback(dataList);
521
- showParts(dataList);
522
- })
523
- })
524
- };
525
- if (gisMap) {
526
- gisMap.queryPhylayerFeatures(queryParam, queryCallback);
527
- }
528
- }
529
- queryFromGIS();
530
- }
531
- };
532
-
533
- this.drawOtherParts = function (options, data) {
534
- var self = this;
535
- const geomType = options.geomType;
536
- let queryParam = options.queryParam || {};
537
- function showParts(data) {
538
-
539
- }
540
-
541
- if (data) {
542
- showParts(data);
543
- } else {
544
- const layerID = queryParam.phyLayerIDs;
545
- const layerName = queryParam.layerName;
546
- const keyField = null;
547
- const keyValue = null;
548
- const clearMap = queryParam.clearMap || true;
549
- let inStyle = queryParam.style || {
550
- color: "blue"
551
- };
552
- let inHStyle = queryParam.hStyle || {
553
- color: "blue"
554
- };
555
- let style = null, hStyle = null;
556
- if (geomType == 1) {
557
- } else if (geomType == 2) {
558
- style = {
559
- type: "simple-line", // autocasts as new SimpleLineSymbol()
560
- color: inStyle.color || "blue",
561
- width: inStyle.width || "2px",
562
- style: inStyle.style || "solid",
563
- cap: inStyle.cap || "round",
564
- join: inStyle.join || "round",
565
- };
566
- hStyle = {
567
- type: "simple-line", // autocasts as new SimpleLineSymbol()
568
- color: inHStyle.color || "red",
569
- width: inHStyle.width || inStyle.width || "2px",
570
- style: inHStyle.style || inStyle.style || "solid",
571
- cap: inHStyle.cap || inStyle.cap || "round",
572
- join: inHStyle.join || inStyle.join || "round",
573
- };
574
- } else if (geomType == 3) {
575
- style = {
576
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
577
- color: inStyle.color || [51, 51, 204, 0.9],
578
- style: inStyle.style || "solid",
579
- outline: { // autocasts as new SimpleLineSymbol()
580
- color: inStyle.outlineColor || "blue",
581
- width: inStyle.outlineWidth || "1px",
582
- style: inStyle.outlineStyle || "solid",
583
- cap: inStyle.outlineCap || "round",
584
- join: inStyle.outlineJoin || "round",
585
- }
586
- };
587
- hStyle = {
588
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
589
- color: inHStyle.color || [51, 51, 204, 0.9],
590
- style: inHStyle.style || inStyle.style || "solid",
591
- outline: { // autocasts as new SimpleLineSymbol()
592
- color: inHStyle.outlineColor || "red",
593
- width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
594
- style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
595
- cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
596
- join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
597
- }
598
- };
599
- }
600
- const bZoom = queryParam.bZoom || true;
601
- const randomColor = null;
602
- const labelField = null;
603
- const labelstyle = null;
604
- const geometry = null;
605
- const where = queryParam.where || "1=1";
606
- const opts = {
607
- layerId: layerName,
608
- mouseOverCallback: queryParam.mouseOverCallback
609
- };
610
-
611
- 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];
612
- //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
613
- if (globeMap) {
614
- gisMap.locateFeatureByIDs(...param);
615
- } else if (gisMap) {
616
- gisMap.locateFeatureByIDs(...param);
617
- }
618
-
619
- }
620
- };
621
-
622
- /*
623
- * @description:新的轨迹线接口
624
- * @method traceOperation
625
- * @param {Array} posArr 位置数组
626
- * @param {Object} options 配置项
627
- *
628
- * @return {Void} 无返回
629
- *
630
- * @author: Hetianhong
631
- * @date: 2021-09-09 14:49:49
632
- */
633
- this.traceOperation = function (posArr, options) {
634
- globeMap.traceOperation(posArr, options);
635
- }
636
- /*
637
- * @description:网格接口
638
- * 先查询idb的data,没有的话,再查询queryFeature的data
639
- * @method regionOperation
640
- * @param {Object} options 配置项
641
- * @param {Array} data 数据,可不传
642
- *
643
- * @return {Void} 无返回
644
- *
645
- * @author: Hetianhong
646
- * @date: 2021-10-19 17:27:02
647
- */
648
- this.regionOperation = function (options, data, callback) {
649
-
650
- function execOperation(data) {
651
- if (globeMap) {
652
- globeMap.regionOperation(options, data);
653
- callback && callback();
654
- } else if (gisMap) {
655
- gridPolygon2dOperation(options, data, callback);
656
- }
657
- }
658
-
659
- if (data) {
660
- execOperation(data);
661
- } else {
662
- if (!options.idbSetting.usageID) { return }
663
-
664
- let storeName = !!globeMap ? "usageID" : "usage2D" + "_" + options.idbSetting.usageID;
665
- let queryFromGIS = () => {
666
- let filterString = options.idbSetting.filterString || "1=1";
667
- let queryParam = {
668
- layerID: options.idbSetting.usageID,
669
- where: filterString,
670
- geometry: '',
671
- outGeometry: true,
672
- options: {
673
- originalData: true
674
- }
675
- }
676
- //二维地图不获取原始数据
677
- if(!globeMap) queryParam.options.originalData = false;
678
- let queryCallback = function (featureInfos) {
679
- execOperation(featureInfos);
680
- }
681
- if (gisMap) {
682
- gisMap.queryFeature(queryParam, queryCallback)
683
- }
684
- }
685
-
686
- if (!options.idbSetting.enabled) {
687
- // 直接查询
688
- queryFromGIS()
689
- } else {
690
- // 查询是否存在表
691
- checkObjectStore(storeName)
692
- .then(function (hasObjStore) {
693
- if (hasObjStore) {
694
- // 如果有,读取本地
695
- execOperation();
696
- } else {
697
- // 如果没有,查询queryFeature
698
- queryFromGIS()
699
- }
700
- })
701
- }
702
- }
703
- }
704
- this.cancelHighlightedRegion=function(layerName){
705
- globeMap.cancelHighlightedRegion(layerName);
706
- }
707
- /*
708
- * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
709
- * @method showPolyline_BI
710
- * @param {参数类型} 参数名 参数说明
711
- *
712
- * @return {返回值类型} 返回值说明
713
- *
714
- * @author: Hetianhong
715
- * @date: 2021-11-11 15:40:31
716
- */
717
- this.showPolyline_BI = function (layerName, positions = [], options = {}) {
718
- if (globeMap !== null) {
719
- // 默认参数
720
- let defaultOpt = {
721
- // 样式类
722
- styleOpt: {
723
- period: 4, // 动画线段的周期,越短越快
724
- image: 'road.png', // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
725
- repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
726
- repeatY: 1, //纵向纹理重复(type为image限定)
727
- glowPower: 0, //中心亮度
728
- intensity: 1.2, //纹理图片颜色强度
729
- gapColor: 'rgba(0, 0, 0, 0)', //间隙颜色(type为dash限定)
730
- dashLength: 15, //间隙宽(type为dash限定)
731
- outlineWidth: 0, // 边框线宽(type为outline限定)
732
- outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
733
- type: 'color', // 线条类型,有 image color dash outline glow
734
- width: 10,
735
- color: "rgba(255,255,0,1)"
736
- },
737
- // 视角缩放类
738
- zoomOpt: {
739
- //zoom参数
740
- heading: 0,
741
- pitch: -90,
742
- range: null,
743
- //可视级别
744
- minZoom: 0,
745
- maxZoom: 24,
746
- //泛光绘制
747
- // 下面两项,不暴露,全部为false
748
- bloom: false,
749
- merge: false
750
- },
751
- // 交互类
752
- interactOpt: {
753
- //click相关
754
- clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
755
- clickWidth: 30, // 点击后的宽度
756
- clickCallback: undefined, // function(e) {console.log('click polyline', e)},
757
- mouseOverCallBack: undefined
758
- }
759
- }
760
- let getMergedOptions = (options) => {
761
- let mergedOptions = {};
762
- mergedOptions.styleOpt = Object.assign({}, defaultOpt.styleOpt, options.styleOpt);
763
- mergedOptions.zoomOpt = Object.assign({}, defaultOpt.zoomOpt, options.zoomOpt);
764
- mergedOptions.interactOpt = Object.assign({}, defaultOpt.interactOpt, options.interactOpt);
765
- return mergedOptions
766
- }
767
- let mergedOptions = getMergedOptions(options);
768
-
769
-
770
- let opt = {}
771
- // let styleOpt = options.styleOpt;
772
- // let zoomOpt = options.zoomOpt;
773
- // let interactOpt = options.interactOpt;
774
- //hth 此处进行参数转换
775
- switch (mergedOptions.styleOpt.type) {
776
- case "image":
777
- opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
778
- opt.image = defaultValue(mergedOptions.styleOpt.image, 'road.png'); //纹理图片,data3d/polyline/目录下
779
- opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
780
- opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
781
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
782
- opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
783
- break;
784
- case "glow":
785
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
786
- break;
787
- case "dash":
788
- opt.gapColor = defaultValue(mergedOptions.styleOpt.gapColor, 'rgba(0, 0, 0, 0)'); //间隙颜色
789
- opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
790
- break;
791
- case "outline":
792
- opt.outlineWidth = defaultValue(mergedOptions.styleOpt.outlineWidth, 0);
793
- opt.outlineColor = defaultValue(mergedOptions.styleOpt.outlineColor, "rgba(0, 0, 0, 0)");
794
- break;
795
- default:
796
- // color
797
- };
798
-
799
- opt.type = mergedOptions.styleOpt.type;
800
- opt.width = mergedOptions.styleOpt.width;
801
- opt.color = mergedOptions.styleOpt.color;
802
-
803
- // 遍历位置数组中的每一项
804
- for(let pos of positions) {
805
- // 遍历opt中每一个key赋值到每一个pos中
806
- for(let k in opt) {
807
- pos[k] = opt[k]
808
- }
809
- }
810
-
811
-
812
- let zoom = mergedOptions.zoomOpt.zoom
813
- let clear = mergedOptions.zoomOpt.clear
814
- let clickCallback = mergedOptions.interactOpt.clickCallback
815
- let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack
816
- let commonOpt = {
817
- //zoom参数
818
- heading: mergedOptions.zoomOpt.heading,
819
- pitch: mergedOptions.zoomOpt.pitch,
820
- range: mergedOptions.zoomOpt.range,
821
- //可视级别
822
- minZoom: mergedOptions.zoomOpt.minZoom,
823
- maxZoom: mergedOptions.zoomOpt.maxZoom,
824
- //click相关
825
- clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
826
- clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
827
- //泛光绘制
828
- // 下面两项,不暴露,全部为false
829
- bloom: false,
830
- merge: false
831
- }
832
-
833
-
834
- globeMap.showPolyline(positions, zoom, clear, commonOpt, layerName, clickCallback, mouseOverCallBack);
835
- }
836
- }
837
- /*
838
- * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
839
- * @method activeLayer
840
- * @param {String} layerName 图层名
841
- * @param {Object} options 配置项
842
- * @param {String} options.type 操作类型,'clear', 'active'
843
- * @param {Boolean} options.zoom 是否缩放
844
- * @param {Object} filter 过滤项
845
- * @param {String} filter.keyFieldName 过滤键名
846
- * @param {Array} filter.values 过滤值内容数组
847
- *
848
- * @return {返回值类型} 返回值说明
849
- *
850
- * @author: Hetianhong
851
- * @date: 2021-11-26 09:49:16
852
- */
853
- this.activeLayer = function (layerName, options, filter) {
854
- if (globeMap != null && mapType == "globe") {
855
- globeMap.activeLayer(layerName, options, filter);
856
- }
857
- if (gisMap != null && mapType == "map") {
858
- gisMap.activeLayer(layerName, options, filter);
859
- }
860
- }
861
-
862
- function gridPolygon2dOperation(options, data, callback) {
863
- var storeName = `usage2D_${options.idbSetting.usageID}`;
864
- function showGrid(realData) {
865
- // 转换一下
866
- var geometries = [];
867
- var extraGeometries = [];
868
- var specialAreaS=options.specialAreaS;//玲珑平台分类设色
869
- for (var i = 0; i < realData.length; i++) {
870
- var feature = realData[i];
871
- var geom = feature.geometry;
872
- geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
873
- var hasPush=false;
874
- if(specialAreaS&&specialAreaS.length>0){
875
- for (var j = 0; j < specialAreaS.length; j++) {
876
- var specialArea=specialAreaS[j];
877
- if(!specialArea.geometries){
878
- specialArea.geometries=[];
879
- }
880
- var attributes=JSON.parse(JSON.stringify(feature.attributes));
881
- let filterResult=new Function(`return ${specialArea.statusControl.compiled}`)().call(null,attributes);
882
- if(filterResult==true){
883
- specialArea.geometries.push(geom);
884
- hasPush=true;
885
- }
886
- }
887
- }
888
- !hasPush&&(geometries.push(geom));
889
- }
890
- if (options.specialArea && options.selectedSetting.selected.length) {
891
- var extraIds = options.selectedSetting.selected.map(s => s.selectID);
892
- for (var i = geometries.length - 1; i > -1; i--) {
893
- var geom = geometries[i];
894
- if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
895
- geometries.splice(i, 1);
896
- extraGeometries.push(geom);
897
- if (extraGeometries.length === extraIds.length) break;
898
- }
899
- }
900
- }
901
- gisMap.locateFeatureByCoords(geometries, 'polygon',
902
- options.layerName, // id,如果已经有attributes就没用了
903
- options.style, // style
904
- options.highlightStyle, // highlightStyle
905
- options.commonSetting.zoom, // zoom
906
- options.keyFieldName,
907
- options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
908
- options.labelStyle, // labelStyle
909
- options.customColor ? interpolateColor(options.customColor[0], options.customColor[1], Math.min(geometries.length, 10)) : 10, // randomColor
910
- false, // renderCanvas
911
- true, // singleSelect
912
- {
913
- minZoom: options.visiblitySetting.beginLevel,
914
- maxZoom: options.visiblitySetting.endLevel,
915
- layerId: options.layerName,
916
- comCallbak: callback,
917
- order: options.order
918
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
919
- },
920
- options.layerName, // layerTag
921
- options.eventSetting.clickCallback
922
- );
923
- if (extraGeometries.length) {
924
- gisMap.locateFeatureByCoords(extraGeometries, 'polygon',
925
- options.layerName, // id,如果已经有attributes就没用了
926
- options.specialAreaStyle, // style
927
- options.highlightStyle, // highlightStyle
928
- false, // zoom
929
- options.keyFieldName,
930
- options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
931
- options.specialAreaLabelStyle, // labelStyle
932
- false, // randomColor
933
- false, // renderCanvas
934
- true, // singleSelect
935
- {
936
- minZoom: options.visiblitySetting.beginLevel,
937
- maxZoom: options.visiblitySetting.endLevel,
938
- layerId: options.layerName,
939
- order: options.order
940
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
941
- },
942
- options.layerName, // layerTag
943
- options.eventSetting.clickCallback
944
- );
945
- }
946
- if(specialAreaS&&specialAreaS.length>0){
947
- for (var j = 0; j < specialAreaS.length; j++) {
948
- var specialArea=specialAreaS[j];
949
- if(specialArea.geometries.length>0){
950
- gisMap.locateFeatureByCoords(specialArea.geometries, 'polygon',
951
- options.layerName, // id,如果已经有attributes就没用了
952
- specialArea.style, // style
953
- options.highlightStyle, // highlightStyle
954
- options.commonSetting.zoom, // zoom
955
- options.keyFieldName,
956
- specialArea.specialAreaStyle.textLabelShowEnabled&&specialArea.specialAreaStyle.labelFieldName, // keyField, labelField
957
- specialArea.labelStyle, // labelStyle
958
- false,// randomColor
959
- false, // renderCanvas
960
- true, // singleSelect
961
- {
962
- minZoom: options.visiblitySetting.beginLevel,
963
- maxZoom: options.visiblitySetting.endLevel,
964
- layerId: options.layerName,
965
- comCallbak: callback,
966
- order: options.order
967
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
968
- },
969
- options.layerName, // layerTag
970
- options.eventSetting.clickCallback
971
- );
972
- }
973
-
974
- }
975
- }
976
- }
977
-
978
- if (!data) {
979
- // 数据来自本地
980
- var dbOpenRequest = window.indexedDB.open('regionDB');
981
- dbOpenRequest.onsuccess = function(event) {
982
- var db = this.result;
983
- var store = db.transaction(storeName).objectStore(storeName);
984
- var request = store.getAll();
985
- request.onsuccess = function() {
986
- var features = this.result;
987
- showGrid(features);
988
- }
989
- }
990
- } else {
991
- var _data = JSON.parse(JSON.stringify(data[0]));
992
- var newData = data[0];
993
- if (newData && newData.geometry) {
994
- _data = JSON.parse(JSON.stringify(data));
995
- showGrid(data);
996
- } else {
997
- showGrid(data[0]);
998
- }
999
-
1000
- var dbRequest = window.indexedDB.open('regionDB');
1001
- dbRequest.onsuccess = function() {
1002
- addStore(this.result.version);
1003
- }
1004
- function addStore(version) {
1005
- var dbOpenRequest = window.indexedDB.open('regionDB', version + 1);
1006
- dbOpenRequest.onupgradeneeded = function(event) {
1007
- var db = event.target.result;
1008
- if (!db.objectStoreNames.contains(storeName)) {
1009
- var store = db.createObjectStore(storeName, { autoIncrement: true });
1010
- for (var i = 0; i < _data.length; i++) {
1011
- store.put(_data[i]);
1012
- }
1013
- store.transaction.oncomplete = function() {
1014
- console.log("complete");
1015
- }
1016
- }
1017
-
1018
- }
1019
- }
1020
- }
1021
- }
1022
-
1023
- this.networkCloud = function (options, positions) {
1024
- if(!globeMap) {return}
1025
- globeMap.networkCloud(options, positions)
1026
- }
1027
- this.clearNetworkCloud = function (layerNames) {
1028
- if(!globeMap) {return}
1029
- globeMap.clearNetworkCloud(layerNames)
1030
- }
1031
- this.lineOperation = function(options, data) {
1032
- if(!options || !options.layerName){
1033
- console.log('图层名必须传递')
1034
- return
1035
- }
1036
- // 数据获取
1037
- let queryFeature = (queryParams) => {
1038
- if(gisMap) {
1039
- return new Promise(function(resolve) {
1040
- let cb = function(result) {
1041
- resolve(result)
1042
- }
1043
- gisMap.queryFeature(queryParams, cb)
1044
- })
1045
- } else {
1046
- return Promise.resolve(undefined)
1047
- }
1048
- }
1049
- // 执行绘制
1050
- let drawLine = (options, data) => {
1051
- if (globeMap) globeMap.lineOperation(options, data);
1052
- else if (gisMap) {
1053
- let style = options.style || {};
1054
- let hStyle = options.hStyle || {};
1055
- let symbol = {
1056
- type: "simple-line", // autocasts as new SimpleLineSymbol()
1057
- color: style.color || "lightblue",
1058
- width: (style.width || 2) + "px",
1059
- style: style.style || "short-dot"
1060
- };
1061
- let hsymbol = {
1062
- type: "simple-line", // autocasts as new SimpleLineSymbol()
1063
- color: hStyle.color || "lightblue",
1064
- width: (hStyle.width || 2) + "px",
1065
- style: hStyle.style || "short-dot"
1066
- };
1067
- var opt = options.options || {};
1068
- gisMap.locateFeatureByCoords(data, options.type, options.id, symbol, hsymbol, options.zoom, options.keyField,
1069
- options.labelField,
1070
- options.labelStyle,
1071
- options.randomColor,
1072
- options.renderCanvas,
1073
- options.singleSelected,
1074
- opt,
1075
- options.layerTag,
1076
- options.callback
1077
- );
1078
- }
1079
- }
1080
-
1081
- // 主逻辑
1082
- if(!!data&&data.length) {
1083
- drawLine(options, data)
1084
- } else {
1085
- if(!options.usageID) {
1086
- console.log('图层用途必须传递')
1087
- return
1088
- }
1089
-
1090
- let originalData = false;
1091
- if (globeMap) originalData = true;
1092
- let queryParams = {
1093
- layerID: options.usageID,
1094
- where: options.filterString || "1=1",
1095
- geometry: '',
1096
- outGeometry: true,
1097
- options: { originalData: originalData }
1098
- }
1099
- queryFeature(queryParams)
1100
- .then(function(resultData) {
1101
- if(!resultData) {
1102
- console.log('没有查询到数据,请检查查询参数')
1103
- return
1104
- }
1105
- drawLine(options, resultData)
1106
- })
1107
- }
1108
-
1109
- }
1110
- }
1111
-
1112
-
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-regular"
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-regular"
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 map = globeMap || gisMap;
506
+ //验证图标是否可查询
507
+ map.getMapConfig("serverURL", function(key,data){
508
+ var symbolServiceURL = `${data}/symbol`;
509
+ var picUrl = (symbolUrl.indexOf("http") > -1 || symbolUrl.indexOf("https") > -1) ? symbolUrl:`${symbolServiceURL}/${symbolUrl}`;
510
+ getImgSize(picUrl).then(size => {
511
+ var dataList = features.map((function (feature) {
512
+ return Object.assign({}, { x: feature.geometry.x, y: feature.geometry.y }, {
513
+ attributes: feature.attributes,
514
+ // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
515
+ symbolType: -1,
516
+ symbolUrl: (size.width || size.height) ? picUrl: (globeMap ?`${symbolServiceURL}/20100.png` : `20100.png`),
517
+ scale: 0.5
518
+ });
519
+ }));
520
+ callback && callback(dataList);
521
+ showParts(dataList);
522
+ })
523
+ })
524
+ };
525
+ if (gisMap) {
526
+ gisMap.queryPhylayerFeatures(queryParam, queryCallback);
527
+ }
528
+ }
529
+ queryFromGIS();
530
+ }
531
+ };
532
+
533
+ this.drawOtherParts = function (options, data) {
534
+ var self = this;
535
+ const geomType = options.geomType;
536
+ let queryParam = options.queryParam || {};
537
+ function showParts(data) {
538
+
539
+ }
540
+
541
+ if (data) {
542
+ showParts(data);
543
+ } else {
544
+ const layerID = queryParam.phyLayerIDs;
545
+ const layerName = queryParam.layerName;
546
+ const keyField = null;
547
+ const keyValue = null;
548
+ const clearMap = queryParam.clearMap || true;
549
+ let inStyle = queryParam.style || {
550
+ color: "blue"
551
+ };
552
+ let inHStyle = queryParam.hStyle || {
553
+ color: "blue"
554
+ };
555
+ let style = null, hStyle = null;
556
+ if (geomType == 1) {
557
+ } else if (geomType == 2) {
558
+ style = {
559
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
560
+ color: inStyle.color || "blue",
561
+ width: inStyle.width || "2px",
562
+ style: inStyle.style || "solid",
563
+ cap: inStyle.cap || "round",
564
+ join: inStyle.join || "round",
565
+ };
566
+ hStyle = {
567
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
568
+ color: inHStyle.color || "red",
569
+ width: inHStyle.width || inStyle.width || "2px",
570
+ style: inHStyle.style || inStyle.style || "solid",
571
+ cap: inHStyle.cap || inStyle.cap || "round",
572
+ join: inHStyle.join || inStyle.join || "round",
573
+ };
574
+ } else if (geomType == 3) {
575
+ style = {
576
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
577
+ color: inStyle.color || [51, 51, 204, 0.9],
578
+ style: inStyle.style || "solid",
579
+ outline: { // autocasts as new SimpleLineSymbol()
580
+ color: inStyle.outlineColor || "blue",
581
+ width: inStyle.outlineWidth || "1px",
582
+ style: inStyle.outlineStyle || "solid",
583
+ cap: inStyle.outlineCap || "round",
584
+ join: inStyle.outlineJoin || "round",
585
+ }
586
+ };
587
+ hStyle = {
588
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
589
+ color: inHStyle.color || [51, 51, 204, 0.9],
590
+ style: inHStyle.style || inStyle.style || "solid",
591
+ outline: { // autocasts as new SimpleLineSymbol()
592
+ color: inHStyle.outlineColor || "red",
593
+ width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
594
+ style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
595
+ cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
596
+ join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
597
+ }
598
+ };
599
+ }
600
+ const bZoom = queryParam.bZoom || true;
601
+ const randomColor = null;
602
+ const labelField = null;
603
+ const labelstyle = null;
604
+ const geometry = null;
605
+ const where = queryParam.where || "1=1";
606
+ const opts = {
607
+ layerId: layerName,
608
+ mouseOverCallback: queryParam.mouseOverCallback
609
+ };
610
+
611
+ 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];
612
+ //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
613
+ if (globeMap) {
614
+ gisMap.locateFeatureByIDs(...param);
615
+ } else if (gisMap) {
616
+ gisMap.locateFeatureByIDs(...param);
617
+ }
618
+
619
+ }
620
+ };
621
+
622
+ /*
623
+ * @description:新的轨迹线接口
624
+ * @method traceOperation
625
+ * @param {Array} posArr 位置数组
626
+ * @param {Object} options 配置项
627
+ *
628
+ * @return {Void} 无返回
629
+ *
630
+ * @author: Hetianhong
631
+ * @date: 2021-09-09 14:49:49
632
+ */
633
+ this.traceOperation = function (posArr, options) {
634
+ globeMap.traceOperation(posArr, options);
635
+ }
636
+ /*
637
+ * @description:网格接口
638
+ * 先查询idb的data,没有的话,再查询queryFeature的data
639
+ * @method regionOperation
640
+ * @param {Object} options 配置项
641
+ * @param {Array} data 数据,可不传
642
+ *
643
+ * @return {Void} 无返回
644
+ *
645
+ * @author: Hetianhong
646
+ * @date: 2021-10-19 17:27:02
647
+ */
648
+ this.regionOperation = function (options, data, callback) {
649
+
650
+ function execOperation(data) {
651
+ if (globeMap) {
652
+ globeMap.regionOperation(options, data);
653
+ callback && callback();
654
+ } else if (gisMap) {
655
+ gridPolygon2dOperation(options, data, callback);
656
+ }
657
+ }
658
+
659
+ if (data) {
660
+ execOperation(data);
661
+ } else {
662
+ if (!options.idbSetting.usageID) { return }
663
+
664
+ let storeName = !!globeMap ? "usageID" : "usage2D" + "_" + options.idbSetting.usageID;
665
+ let queryFromGIS = () => {
666
+ let filterString = options.idbSetting.filterString || "1=1";
667
+ let queryParam = {
668
+ layerID: options.idbSetting.usageID,
669
+ where: filterString,
670
+ geometry: '',
671
+ outGeometry: true,
672
+ options: {
673
+ originalData: true
674
+ }
675
+ }
676
+ //二维地图不获取原始数据
677
+ if(!globeMap) queryParam.options.originalData = false;
678
+ let queryCallback = function (featureInfos) {
679
+ execOperation(featureInfos);
680
+ }
681
+ if (gisMap) {
682
+ gisMap.queryFeature(queryParam, queryCallback)
683
+ }
684
+ }
685
+
686
+ if (!options.idbSetting.enabled) {
687
+ // 直接查询
688
+ queryFromGIS()
689
+ } else {
690
+ // 查询是否存在表
691
+ checkObjectStore(storeName)
692
+ .then(function (hasObjStore) {
693
+ if (hasObjStore) {
694
+ // 如果有,读取本地
695
+ execOperation();
696
+ } else {
697
+ // 如果没有,查询queryFeature
698
+ queryFromGIS()
699
+ }
700
+ })
701
+ }
702
+ }
703
+ }
704
+ this.cancelHighlightedRegion=function(layerName){
705
+ globeMap.cancelHighlightedRegion(layerName);
706
+ }
707
+ /*
708
+ * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
709
+ * @method showPolyline_BI
710
+ * @param {参数类型} 参数名 参数说明
711
+ *
712
+ * @return {返回值类型} 返回值说明
713
+ *
714
+ * @author: Hetianhong
715
+ * @date: 2021-11-11 15:40:31
716
+ */
717
+ this.showPolyline_BI = function (layerName, positions = [], options = {}) {
718
+ if (globeMap !== null) {
719
+ // 默认参数
720
+ let defaultOpt = {
721
+ // 样式类
722
+ styleOpt: {
723
+ period: 4, // 动画线段的周期,越短越快
724
+ image: 'road.png', // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
725
+ repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
726
+ repeatY: 1, //纵向纹理重复(type为image限定)
727
+ glowPower: 0, //中心亮度
728
+ intensity: 1.2, //纹理图片颜色强度
729
+ gapColor: 'rgba(0, 0, 0, 0)', //间隙颜色(type为dash限定)
730
+ dashLength: 15, //间隙宽(type为dash限定)
731
+ outlineWidth: 0, // 边框线宽(type为outline限定)
732
+ outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
733
+ type: 'color', // 线条类型,有 image color dash outline glow
734
+ width: 10,
735
+ color: "rgba(255,255,0,1)"
736
+ },
737
+ // 视角缩放类
738
+ zoomOpt: {
739
+ //zoom参数
740
+ heading: 0,
741
+ pitch: -90,
742
+ range: null,
743
+ //可视级别
744
+ minZoom: 0,
745
+ maxZoom: 24,
746
+ //泛光绘制
747
+ // 下面两项,不暴露,全部为false
748
+ bloom: false,
749
+ merge: false
750
+ },
751
+ // 交互类
752
+ interactOpt: {
753
+ //click相关
754
+ clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
755
+ clickWidth: 30, // 点击后的宽度
756
+ clickCallback: undefined, // function(e) {console.log('click polyline', e)},
757
+ mouseOverCallBack: undefined
758
+ }
759
+ }
760
+ let getMergedOptions = (options) => {
761
+ let mergedOptions = {};
762
+ mergedOptions.styleOpt = Object.assign({}, defaultOpt.styleOpt, options.styleOpt);
763
+ mergedOptions.zoomOpt = Object.assign({}, defaultOpt.zoomOpt, options.zoomOpt);
764
+ mergedOptions.interactOpt = Object.assign({}, defaultOpt.interactOpt, options.interactOpt);
765
+ return mergedOptions
766
+ }
767
+ let mergedOptions = getMergedOptions(options);
768
+
769
+
770
+ let opt = {}
771
+ // let styleOpt = options.styleOpt;
772
+ // let zoomOpt = options.zoomOpt;
773
+ // let interactOpt = options.interactOpt;
774
+ //hth 此处进行参数转换
775
+ switch (mergedOptions.styleOpt.type) {
776
+ case "image":
777
+ opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
778
+ opt.image = defaultValue(mergedOptions.styleOpt.image, 'road.png'); //纹理图片,data3d/polyline/目录下
779
+ opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
780
+ opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
781
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
782
+ opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
783
+ break;
784
+ case "glow":
785
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
786
+ break;
787
+ case "dash":
788
+ opt.gapColor = defaultValue(mergedOptions.styleOpt.gapColor, 'rgba(0, 0, 0, 0)'); //间隙颜色
789
+ opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
790
+ break;
791
+ case "outline":
792
+ opt.outlineWidth = defaultValue(mergedOptions.styleOpt.outlineWidth, 0);
793
+ opt.outlineColor = defaultValue(mergedOptions.styleOpt.outlineColor, "rgba(0, 0, 0, 0)");
794
+ break;
795
+ default:
796
+ // color
797
+ };
798
+
799
+ opt.type = mergedOptions.styleOpt.type;
800
+ opt.width = mergedOptions.styleOpt.width;
801
+ opt.color = mergedOptions.styleOpt.color;
802
+
803
+ // 遍历位置数组中的每一项
804
+ for(let pos of positions) {
805
+ // 遍历opt中每一个key赋值到每一个pos中
806
+ for(let k in opt) {
807
+ pos[k] = opt[k]
808
+ }
809
+ }
810
+
811
+
812
+ let zoom = mergedOptions.zoomOpt.zoom
813
+ let clear = mergedOptions.zoomOpt.clear
814
+ let clickCallback = mergedOptions.interactOpt.clickCallback
815
+ let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack
816
+ let commonOpt = {
817
+ //zoom参数
818
+ heading: mergedOptions.zoomOpt.heading,
819
+ pitch: mergedOptions.zoomOpt.pitch,
820
+ range: mergedOptions.zoomOpt.range,
821
+ //可视级别
822
+ minZoom: mergedOptions.zoomOpt.minZoom,
823
+ maxZoom: mergedOptions.zoomOpt.maxZoom,
824
+ //click相关
825
+ clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
826
+ clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
827
+ //泛光绘制
828
+ // 下面两项,不暴露,全部为false
829
+ bloom: false,
830
+ merge: false
831
+ }
832
+
833
+
834
+ globeMap.showPolyline(positions, zoom, clear, commonOpt, layerName, clickCallback, mouseOverCallBack);
835
+ }
836
+ }
837
+ /*
838
+ * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
839
+ * @method activeLayer
840
+ * @param {String} layerName 图层名
841
+ * @param {Object} options 配置项
842
+ * @param {String} options.type 操作类型,'clear', 'active'
843
+ * @param {Boolean} options.zoom 是否缩放
844
+ * @param {Object} filter 过滤项
845
+ * @param {String} filter.keyFieldName 过滤键名
846
+ * @param {Array} filter.values 过滤值内容数组
847
+ *
848
+ * @return {返回值类型} 返回值说明
849
+ *
850
+ * @author: Hetianhong
851
+ * @date: 2021-11-26 09:49:16
852
+ */
853
+ this.activeLayer = function (layerName, options, filter) {
854
+ if (globeMap != null && mapType == "globe") {
855
+ globeMap.activeLayer(layerName, options, filter);
856
+ }
857
+ if (gisMap != null && mapType == "map") {
858
+ gisMap.activeLayer(layerName, options, filter);
859
+ }
860
+ }
861
+
862
+ function gridPolygon2dOperation(options, data, callback) {
863
+ var storeName = `usage2D_${options.idbSetting.usageID}`;
864
+ function showGrid(realData) {
865
+ // 转换一下
866
+ var geometries = [];
867
+ var extraGeometries = [];
868
+ var specialAreaS=options.specialAreaS;//玲珑平台分类设色
869
+ for (var i = 0; i < realData.length; i++) {
870
+ var feature = realData[i];
871
+ var geom = feature.geometry;
872
+ geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
873
+ var hasPush=false;
874
+ if(specialAreaS&&specialAreaS.length>0){
875
+ for (var j = 0; j < specialAreaS.length; j++) {
876
+ var specialArea=specialAreaS[j];
877
+ if(!specialArea.geometries){
878
+ specialArea.geometries=[];
879
+ }
880
+ var attributes=JSON.parse(JSON.stringify(feature.attributes));
881
+ let filterResult=new Function(`return ${specialArea.statusControl.compiled}`)().call(null,attributes);
882
+ if(filterResult==true){
883
+ specialArea.geometries.push(geom);
884
+ hasPush=true;
885
+ }
886
+ }
887
+ }
888
+ !hasPush&&(geometries.push(geom));
889
+ }
890
+ if (options.specialArea && options.selectedSetting.selected.length) {
891
+ var extraIds = options.selectedSetting.selected.map(s => s.selectID);
892
+ for (var i = geometries.length - 1; i > -1; i--) {
893
+ var geom = geometries[i];
894
+ if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
895
+ geometries.splice(i, 1);
896
+ extraGeometries.push(geom);
897
+ if (extraGeometries.length === extraIds.length) break;
898
+ }
899
+ }
900
+ }
901
+ var color = options.customColor ? interpolateColor(options.customColor[0], options.customColor[1], Math.min(geometries.length, 10)) : 10;
902
+ if(options.setFieldColor && options.layeredColor) {
903
+ var colorConfig = options.layeredColor(geometries);
904
+ geometries = colorConfig.data;
905
+ color = colorConfig.color;
906
+ }
907
+ gisMap.locateFeatureByCoords(geometries, 'polygon',
908
+ options.layerName, // id,如果已经有attributes就没用了
909
+ options.style, // style
910
+ options.highlightStyle, // highlightStyle
911
+ options.commonSetting.zoom, // zoom
912
+ options.keyFieldName,
913
+ options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
914
+ options.labelStyle, // labelStyle
915
+ color,
916
+ false, // renderCanvas
917
+ true, // singleSelect
918
+ {
919
+ minZoom: options.visiblitySetting.beginLevel,
920
+ maxZoom: options.visiblitySetting.endLevel,
921
+ layerId: options.layerName,
922
+ comCallbak: callback,
923
+ order: options.order
924
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
925
+ },
926
+ options.layerName, // layerTag
927
+ options.eventSetting.clickCallback
928
+ );
929
+ if (extraGeometries.length) {
930
+ gisMap.locateFeatureByCoords(extraGeometries, 'polygon',
931
+ options.layerName, // id,如果已经有attributes就没用了
932
+ options.specialAreaStyle, // style
933
+ options.highlightStyle, // highlightStyle
934
+ false, // zoom
935
+ options.keyFieldName,
936
+ options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
937
+ options.specialAreaLabelStyle, // labelStyle
938
+ false, // randomColor
939
+ false, // renderCanvas
940
+ true, // singleSelect
941
+ {
942
+ minZoom: options.visiblitySetting.beginLevel,
943
+ maxZoom: options.visiblitySetting.endLevel,
944
+ layerId: options.layerName,
945
+ order: options.order
946
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
947
+ },
948
+ options.layerName, // layerTag
949
+ options.eventSetting.clickCallback
950
+ );
951
+ }
952
+ if(specialAreaS&&specialAreaS.length>0){
953
+ for (var j = 0; j < specialAreaS.length; j++) {
954
+ var specialArea=specialAreaS[j];
955
+ if(specialArea.geometries.length>0){
956
+ gisMap.locateFeatureByCoords(specialArea.geometries, 'polygon',
957
+ options.layerName, // id,如果已经有attributes就没用了
958
+ specialArea.style, // style
959
+ options.highlightStyle, // highlightStyle
960
+ options.commonSetting.zoom, // zoom
961
+ options.keyFieldName,
962
+ specialArea.specialAreaStyle.textLabelShowEnabled&&specialArea.specialAreaStyle.labelFieldName, // keyField, labelField
963
+ specialArea.labelStyle, // labelStyle
964
+ false,// randomColor
965
+ false, // renderCanvas
966
+ true, // singleSelect
967
+ {
968
+ minZoom: options.visiblitySetting.beginLevel,
969
+ maxZoom: options.visiblitySetting.endLevel,
970
+ layerId: options.layerName,
971
+ comCallbak: callback,
972
+ order: options.order
973
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
974
+ },
975
+ options.layerName, // layerTag
976
+ options.eventSetting.clickCallback
977
+ );
978
+ }
979
+
980
+ }
981
+ }
982
+ }
983
+
984
+ if (!data) {
985
+ // 数据来自本地
986
+ var dbOpenRequest = window.indexedDB.open('regionDB');
987
+ dbOpenRequest.onsuccess = function(event) {
988
+ var db = this.result;
989
+ var store = db.transaction(storeName).objectStore(storeName);
990
+ var request = store.getAll();
991
+ request.onsuccess = function() {
992
+ var features = this.result;
993
+ showGrid(features);
994
+ }
995
+ }
996
+ } else {
997
+ var _data = JSON.parse(JSON.stringify(data[0]));
998
+ var newData = data[0];
999
+ if (newData && newData.geometry) {
1000
+ _data = JSON.parse(JSON.stringify(data));
1001
+ showGrid(data);
1002
+ } else {
1003
+ showGrid(data[0]);
1004
+ }
1005
+
1006
+ var dbRequest = window.indexedDB.open('regionDB');
1007
+ dbRequest.onsuccess = function() {
1008
+ addStore(this.result.version);
1009
+ }
1010
+ function addStore(version) {
1011
+ var dbOpenRequest = window.indexedDB.open('regionDB', version + 1);
1012
+ dbOpenRequest.onupgradeneeded = function(event) {
1013
+ var db = event.target.result;
1014
+ if (!db.objectStoreNames.contains(storeName)) {
1015
+ var store = db.createObjectStore(storeName, { autoIncrement: true });
1016
+ for (var i = 0; i < _data.length; i++) {
1017
+ store.put(_data[i]);
1018
+ }
1019
+ store.transaction.oncomplete = function() {
1020
+ console.log("complete");
1021
+ }
1022
+ }
1023
+
1024
+ }
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ this.networkCloud = function (options, positions) {
1030
+ if(!globeMap) {return}
1031
+ globeMap.networkCloud(options, positions)
1032
+ }
1033
+ this.clearNetworkCloud = function (layerNames) {
1034
+ if(!globeMap) {return}
1035
+ globeMap.clearNetworkCloud(layerNames)
1036
+ }
1037
+ this.lineOperation = function(options, data) {
1038
+ if(!options || !options.layerName){
1039
+ console.log('图层名必须传递')
1040
+ return
1041
+ }
1042
+ // 数据获取
1043
+ let queryFeature = (queryParams) => {
1044
+ if(gisMap) {
1045
+ return new Promise(function(resolve) {
1046
+ let cb = function(result) {
1047
+ resolve(result)
1048
+ }
1049
+ gisMap.queryFeature(queryParams, cb)
1050
+ })
1051
+ } else {
1052
+ return Promise.resolve(undefined)
1053
+ }
1054
+ }
1055
+ // 执行绘制
1056
+ let drawLine = (options, data) => {
1057
+ if (globeMap) globeMap.lineOperation(options, data);
1058
+ else if (gisMap) {
1059
+ let style = options.style || {};
1060
+ let hStyle = options.hStyle || {};
1061
+ let symbol = {
1062
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
1063
+ color: style.color || "lightblue",
1064
+ width: (style.width || 2) + "px",
1065
+ style: style.style || "short-dot"
1066
+ };
1067
+ let hsymbol = {
1068
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
1069
+ color: hStyle.color || "lightblue",
1070
+ width: (hStyle.width || 2) + "px",
1071
+ style: hStyle.style || "short-dot"
1072
+ };
1073
+ var opt = options.options || {};
1074
+ gisMap.locateFeatureByCoords(data, options.type, options.id, symbol, hsymbol, options.zoom, options.keyField,
1075
+ options.labelField,
1076
+ options.labelStyle,
1077
+ options.randomColor,
1078
+ options.renderCanvas,
1079
+ options.singleSelected,
1080
+ opt,
1081
+ options.layerTag,
1082
+ options.callback
1083
+ );
1084
+ }
1085
+ }
1086
+
1087
+ // 主逻辑
1088
+ if(!!data&&data.length) {
1089
+ drawLine(options, data)
1090
+ } else {
1091
+ if(!options.usageID) {
1092
+ console.log('图层用途必须传递')
1093
+ return
1094
+ }
1095
+
1096
+ let originalData = false;
1097
+ if (globeMap) originalData = true;
1098
+ let queryParams = {
1099
+ layerID: options.usageID,
1100
+ where: options.filterString || "1=1",
1101
+ geometry: '',
1102
+ outGeometry: true,
1103
+ options: { originalData: originalData }
1104
+ }
1105
+ queryFeature(queryParams)
1106
+ .then(function(resultData) {
1107
+ if(!resultData) {
1108
+ console.log('没有查询到数据,请检查查询参数')
1109
+ return
1110
+ }
1111
+ drawLine(options, resultData)
1112
+ })
1113
+ }
1114
+
1115
+ }
1116
+ }
1117
+
1118
+
1113
1119
  export default egovaBI