egovamap 0.17.20 → 0.17.21

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,990 +1,990 @@
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
- globeMap.drawPoints(layerName, positions, options);
308
- }
309
- if(gisMap && mapType == "map"){
310
- deal2DPoints(layerName, positions, options).then(args => {
311
- gisMap.showMultiObjectCurrentPosition(
312
- args.datalist,
313
- args.zoom,
314
- args.clear,
315
- args.highLightType,
316
- args.infoStyle,
317
- args.renderCanvas,
318
- args.tagName,
319
- options.clickCallback,
320
- options.mouseOverCallback,
321
- args.clusterOption,
322
- args.hasHover,
323
- layerName,
324
- options.mouseOutCallback,
325
- options.option
326
- );
327
- });
328
- }
329
- }
330
- this.getLabel = function (attributes) {
331
- if (!attributes) return;
332
- var label = [], field = {};
333
- for (var key in attributes) {
334
- field = {};
335
- field[key] = attributes[key];
336
- label.push(field);
337
- }
338
- return label;
339
- };
340
- this.drawParts = function (options, data, callback) {
341
- var self = this;
342
- function showParts(data) {
343
- var drawParam = options.drawParam || {};
344
- var ctrOption = drawParam.clusterOption;
345
- var clusterOption = {
346
- clusterType: ctrOption.clusterType,
347
- level: ctrOption.level || 0,
348
- style: {
349
- "type": "simple-marker",
350
- "style": "circle",
351
- "color": ctrOption.color || [255, 0, 0, 0.6],
352
- "size": ctrOption.size || 20,
353
- "outline": { //if outline has been specified
354
- "color": ctrOption.outlineColor || [255, 168, 0, 1],
355
- "width": ctrOption.outlineWidth || 2
356
- }
357
- },
358
- labelStyle: {
359
- "type": "text",
360
- "color": ctrOption.labelColor || [255, 255, 255, 1],
361
- "text": "",
362
- "zlevel": ctrOption.labelZlevel || 1,
363
- "yoffset": 0,
364
- "font": ctrOption.labelFont || {
365
- "family": "Arial",
366
- "size": 10
367
- }
368
- },
369
- distance: ctrOption.distance || 50
370
- };
371
-
372
- var param = [data, true, false, null, null, false, drawParam.tagName, drawParam.clickCallback, drawParam.mouseOverCallback, clusterOption, false, drawParam.layerName, drawParam.callback, drawParam.drawOptions];
373
- //三维聚类参数
374
- var globeOptions = {
375
- zoom:true,
376
- scale: 0.9,
377
- clear :true,
378
- nearFarScalar:[8000, 1.0, 10000, 0.6],
379
- clickCallBack: drawParam.clickCallback,
380
- layerName: drawParam.layerName,
381
- minSize:30,
382
- clusterLimit: 20,
383
- style:"default",
384
- clusterImageInfo: {
385
- horizontalOrigin: "center",
386
- verticalOrigin: "bottom",
387
- cssStyle: {
388
- "borderRadius": 500,
389
- "fillColor": "rgba(0,0,0,0.7)",
390
- "borderLineWidth": 3,
391
- "borderLineColor": "rgba(250,140,0,0.9)",
392
- "paddingX": 15,
393
- "paddingY": 6,
394
- "marginBottom": 2
395
- },
396
- textStyle: {
397
- "font": "60px Helvetica",
398
- "fillColor": "rgba(220,220,220,1.0)",
399
- "outlineColor": "black",
400
- "outlineWidth": 1,
401
- "padding": 1,
402
- "textScale": 0.5,
403
- "textStartX": 40,
404
- "textStartY": 15
405
- }
406
- }
407
- }
408
- if (globeMap) {
409
- globeMap.addClusterLayer({
410
- data,
411
- options:globeOptions
412
- })
413
- } else if (gisMap) {
414
- gisMap.showMultiObjectCurrentPosition(...param );
415
- }
416
- }
417
-
418
- if (data) {
419
- showParts(data);
420
- } else {
421
- let queryFromGIS = () => {
422
- let queryParam = options.queryParam;
423
- var subTypeName = options.subTypeName;
424
- var subUniqueCode = options.subUniqueCode;
425
- let queryCallback = function (featureInfos) {
426
- var features = featureInfos[queryParam.phyLayerIDs];
427
- if (features.length == 0) {
428
- callback && callback([]);
429
- return;
430
- }
431
- if (!features || !features.length) return;
432
- var symbolUrl = "";
433
- if (subUniqueCode.indexOf("http") > -1) {
434
- symbolUrl = subUniqueCode;
435
- } else if (subUniqueCode.indexOf(".") > -1) {
436
- symbolUrl = subUniqueCode;
437
- } else {
438
- symbolUrl = "".concat(subUniqueCode, ".png");
439
- if(globeMap) symbolUrl = queryParam.gisServerURL ? `${queryParam.gisServerURL}/symbol/${symbolUrl}` : symbolUrl;
440
- }
441
- var dataList = features.map((function (feature) {
442
- return Object.assign({}, { x: feature.geometry.x, y: feature.geometry.y }, {
443
- attributes: feature.attributes,
444
- // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
445
- symbolType: -1,
446
- symbolUrl: symbolUrl,
447
- scale: 0.5
448
- });
449
- }));
450
- callback && callback(dataList);
451
- showParts(dataList);
452
- };
453
- if (gisMap) {
454
- gisMap.queryPhylayerFeatures(queryParam, queryCallback);
455
- }
456
- }
457
- queryFromGIS();
458
- }
459
- };
460
-
461
- this.drawOtherParts = function (options, data) {
462
- var self = this;
463
- const geomType = options.geomType;
464
- let queryParam = options.queryParam || {};
465
- function showParts(data) {
466
-
467
- }
468
-
469
- if (data) {
470
- showParts(data);
471
- } else {
472
- const layerID = queryParam.phyLayerIDs;
473
- const layerName = queryParam.layerName;
474
- const keyField = null;
475
- const keyValue = null;
476
- const clearMap = queryParam.clearMap || true;
477
- let inStyle = queryParam.style || {
478
- color: "blue"
479
- };
480
- let inHStyle = queryParam.hStyle || {
481
- color: "blue"
482
- };
483
- let style = null, hStyle = null;
484
- if (geomType == 1) {
485
- } else if (geomType == 2) {
486
- style = {
487
- type: "simple-line", // autocasts as new SimpleLineSymbol()
488
- color: inStyle.color || "blue",
489
- width: inStyle.width || "2px",
490
- style: inStyle.style || "solid",
491
- cap: inStyle.cap || "round",
492
- join: inStyle.join || "round",
493
- };
494
- hStyle = {
495
- type: "simple-line", // autocasts as new SimpleLineSymbol()
496
- color: inHStyle.color || "red",
497
- width: inHStyle.width || inStyle.width || "2px",
498
- style: inHStyle.style || inStyle.style || "solid",
499
- cap: inHStyle.cap || inStyle.cap || "round",
500
- join: inHStyle.join || inStyle.join || "round",
501
- };
502
- } else if (geomType == 3) {
503
- style = {
504
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
505
- color: inStyle.color || [51, 51, 204, 0.9],
506
- style: inStyle.style || "solid",
507
- outline: { // autocasts as new SimpleLineSymbol()
508
- color: inStyle.outlineColor || "blue",
509
- width: inStyle.outlineWidth || "1px",
510
- style: inStyle.outlineStyle || "solid",
511
- cap: inStyle.outlineCap || "round",
512
- join: inStyle.outlineJoin || "round",
513
- }
514
- };
515
- hStyle = {
516
- type: "simple-fill", // autocasts as new SimpleFillSymbol()
517
- color: inHStyle.color || [51, 51, 204, 0.9],
518
- style: inHStyle.style || inStyle.style || "solid",
519
- outline: { // autocasts as new SimpleLineSymbol()
520
- color: inHStyle.outlineColor || "red",
521
- width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
522
- style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
523
- cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
524
- join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
525
- }
526
- };
527
- }
528
- const bZoom = queryParam.bZoom || true;
529
- const randomColor = null;
530
- const labelField = null;
531
- const labelstyle = null;
532
- const geometry = null;
533
- const where = queryParam.where || "1=1";
534
- const opts = {
535
- layerId: layerName,
536
- mouseOverCallback: queryParam.mouseOverCallback
537
- };
538
-
539
- 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];
540
- //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
541
- if (globeMap) {
542
- gisMap.locateFeatureByIDs(...param);
543
- } else if (gisMap) {
544
- gisMap.locateFeatureByIDs(...param);
545
- }
546
-
547
- }
548
- };
549
-
550
- /*
551
- * @description:新的轨迹线接口
552
- * @method traceOperation
553
- * @param {Array} posArr 位置数组
554
- * @param {Object} options 配置项
555
- *
556
- * @return {Void} 无返回
557
- *
558
- * @author: Hetianhong
559
- * @date: 2021-09-09 14:49:49
560
- */
561
- this.traceOperation = function (posArr, options) {
562
- globeMap.traceOperation(posArr, options);
563
- }
564
- /*
565
- * @description:网格接口
566
- * 先查询idb的data,没有的话,再查询queryFeature的data
567
- * @method regionOperation
568
- * @param {Object} options 配置项
569
- * @param {Array} data 数据,可不传
570
- *
571
- * @return {Void} 无返回
572
- *
573
- * @author: Hetianhong
574
- * @date: 2021-10-19 17:27:02
575
- */
576
- this.regionOperation = function (options, data, callback) {
577
-
578
- function execOperation(data) {
579
- if (globeMap) {
580
- globeMap.regionOperation(options, data);
581
- callback && callback();
582
- } else if (gisMap) {
583
- gridPolygon2dOperation(options, data, callback);
584
- }
585
- }
586
-
587
- if (data) {
588
- execOperation(data);
589
- } else {
590
- if (!options.idbSetting.usageID) { return }
591
-
592
- let storeName = !!globeMap ? "usageID" : "usage2D" + "_" + options.idbSetting.usageID;
593
- let queryFromGIS = () => {
594
- let filterString = options.idbSetting.filterString || "1=1";
595
- let queryParam = {
596
- layerID: options.idbSetting.usageID,
597
- where: filterString,
598
- geometry: '',
599
- outGeometry: true,
600
- options: {
601
- originalData: true
602
- }
603
- }
604
- //二维地图不获取原始数据
605
- if(!globeMap) queryParam.options.originalData = false;
606
- let queryCallback = function (featureInfos) {
607
- execOperation(featureInfos);
608
- }
609
- if (gisMap) {
610
- gisMap.queryFeature(queryParam, queryCallback)
611
- }
612
- }
613
-
614
- if (!options.idbSetting.enabled) {
615
- // 直接查询
616
- queryFromGIS()
617
- } else {
618
- // 查询是否存在表
619
- checkObjectStore(storeName)
620
- .then(function (hasObjStore) {
621
- if (hasObjStore) {
622
- // 如果有,读取本地
623
- execOperation();
624
- } else {
625
- // 如果没有,查询queryFeature
626
- queryFromGIS()
627
- }
628
- })
629
- }
630
- }
631
- }
632
- /*
633
- * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
634
- * @method showPolyline_BI
635
- * @param {参数类型} 参数名 参数说明
636
- *
637
- * @return {返回值类型} 返回值说明
638
- *
639
- * @author: Hetianhong
640
- * @date: 2021-11-11 15:40:31
641
- */
642
- this.showPolyline_BI = function (layerName, positions = [], options = {}) {
643
- if (globeMap !== null) {
644
- // 默认参数
645
- let defaultOpt = {
646
- // 样式类
647
- styleOpt: {
648
- period: 4, // 动画线段的周期,越短越快
649
- image: 'road.png', // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
650
- repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
651
- repeatY: 1, //纵向纹理重复(type为image限定)
652
- glowPower: 0, //中心亮度
653
- intensity: 1.2, //纹理图片颜色强度
654
- gapColor: 'rgba(0, 0, 0, 0)', //间隙颜色(type为dash限定)
655
- dashLength: 15, //间隙宽(type为dash限定)
656
- outlineWidth: 0, // 边框线宽(type为outline限定)
657
- outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
658
- type: 'color', // 线条类型,有 image color dash outline glow
659
- width: 10,
660
- color: "rgba(255,255,0,1)"
661
- },
662
- // 视角缩放类
663
- zoomOpt: {
664
- //zoom参数
665
- heading: 0,
666
- pitch: -90,
667
- range: null,
668
- //可视级别
669
- minZoom: 0,
670
- maxZoom: 24,
671
- //泛光绘制
672
- // 下面两项,不暴露,全部为false
673
- bloom: false,
674
- merge: false
675
- },
676
- // 交互类
677
- interactOpt: {
678
- //click相关
679
- clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
680
- clickWidth: 30, // 点击后的宽度
681
- clickCallback: undefined, // function(e) {console.log('click polyline', e)},
682
- mouseOverCallBack: undefined
683
- }
684
- }
685
- let getMergedOptions = (options) => {
686
- let mergedOptions = {};
687
- mergedOptions.styleOpt = Object.assign({}, defaultOpt.styleOpt, options.styleOpt);
688
- mergedOptions.zoomOpt = Object.assign({}, defaultOpt.zoomOpt, options.zoomOpt);
689
- mergedOptions.interactOpt = Object.assign({}, defaultOpt.interactOpt, options.interactOpt);
690
- return mergedOptions
691
- }
692
- let mergedOptions = getMergedOptions(options);
693
-
694
-
695
- let opt = {}
696
- // let styleOpt = options.styleOpt;
697
- // let zoomOpt = options.zoomOpt;
698
- // let interactOpt = options.interactOpt;
699
- //hth 此处进行参数转换
700
- switch (mergedOptions.styleOpt.type) {
701
- case "image":
702
- opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
703
- opt.image = defaultValue(mergedOptions.styleOpt.image, 'road.png'); //纹理图片,data3d/polyline/目录下
704
- opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
705
- opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
706
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
707
- opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
708
- break;
709
- case "glow":
710
- opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
711
- break;
712
- case "dash":
713
- opt.gapColor = defaultValue(mergedOptions.styleOpt.gapColor, 'rgba(0, 0, 0, 0)'); //间隙颜色
714
- opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
715
- break;
716
- case "outline":
717
- opt.outlineWidth = defaultValue(mergedOptions.styleOpt.outlineWidth, 0);
718
- opt.outlineColor = defaultValue(mergedOptions.styleOpt.outlineColor, "rgba(0, 0, 0, 0)");
719
- break;
720
- default:
721
- // color
722
- };
723
-
724
- opt.type = mergedOptions.styleOpt.type;
725
- opt.width = mergedOptions.styleOpt.width;
726
- opt.color = mergedOptions.styleOpt.color;
727
-
728
- // 遍历位置数组中的每一项
729
- for(let pos of positions) {
730
- // 遍历opt中每一个key赋值到每一个pos中
731
- for(let k in opt) {
732
- pos[k] = opt[k]
733
- }
734
- }
735
-
736
-
737
- let zoom = mergedOptions.zoomOpt.zoom
738
- let clear = mergedOptions.zoomOpt.clear
739
- let clickCallback = mergedOptions.interactOpt.clickCallback
740
- let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack
741
- let commonOpt = {
742
- //zoom参数
743
- heading: mergedOptions.zoomOpt.heading,
744
- pitch: mergedOptions.zoomOpt.pitch,
745
- range: mergedOptions.zoomOpt.range,
746
- //可视级别
747
- minZoom: mergedOptions.zoomOpt.minZoom,
748
- maxZoom: mergedOptions.zoomOpt.maxZoom,
749
- //click相关
750
- clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
751
- clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
752
- //泛光绘制
753
- // 下面两项,不暴露,全部为false
754
- bloom: false,
755
- merge: false
756
- }
757
-
758
-
759
- globeMap.showPolyline(positions, zoom, clear, commonOpt, layerName, clickCallback, mouseOverCallBack);
760
- }
761
- }
762
- /*
763
- * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
764
- * @method activeLayer
765
- * @param {String} layerName 图层名
766
- * @param {Object} options 配置项
767
- * @param {String} options.type 操作类型,'clear', 'active'
768
- * @param {Boolean} options.zoom 是否缩放
769
- * @param {Object} filter 过滤项
770
- * @param {String} filter.keyFieldName 过滤键名
771
- * @param {Array} filter.values 过滤值内容数组
772
- *
773
- * @return {返回值类型} 返回值说明
774
- *
775
- * @author: Hetianhong
776
- * @date: 2021-11-26 09:49:16
777
- */
778
- this.activeLayer = function (layerName, options, filter) {
779
- if (globeMap != null && mapType == "globe") {
780
- globeMap.activeLayer(layerName, options, filter);
781
- }
782
- if (gisMap != null && mapType == "map") {
783
- gisMap.activeLayer(layerName, options, filter);
784
- }
785
- }
786
-
787
- function gridPolygon2dOperation(options, data, callback) {
788
- var storeName = `usage2D_${options.idbSetting.usageID}`;
789
- function showGrid(realData) {
790
- // 转换一下
791
- var geometries = [];
792
- var extraGeometries = [];
793
- for (var i = 0; i < realData.length; i++) {
794
- var feature = realData[i];
795
- var geom = feature.geometry;
796
- geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
797
- geometries.push(geom);
798
- }
799
- if (options.specialArea && options.selectedSetting.selected.length) {
800
- var extraIds = options.selectedSetting.selected.map(s => s.selectID);
801
- for (var i = geometries.length - 1; i > -1; i--) {
802
- var geom = geometries[i];
803
- if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
804
- geometries.splice(i, 1);
805
- extraGeometries.push(geom);
806
- if (extraGeometries.length === extraIds.length) break;
807
- }
808
- }
809
- }
810
- gisMap.locateFeatureByCoords(geometries, 'polygon',
811
- options.layerName, // id,如果已经有attributes就没用了
812
- options.style, // style
813
- options.highlightStyle, // highlightStyle
814
- options.commonSetting.zoom, // zoom
815
- options.keyFieldName,
816
- options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
817
- options.labelStyle, // labelStyle
818
- options.customColor ? interpolateColor(options.customColor[0], options.customColor[1], Math.min(geometries.length, 10)) : 10, // randomColor
819
- false, // renderCanvas
820
- true, // singleSelect
821
- {
822
- minZoom: options.visiblitySetting.beginLevel,
823
- maxZoom: options.visiblitySetting.endLevel,
824
- layerId: options.layerName,
825
- comCallbak: callback
826
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
827
- },
828
- options.layerName, // layerTag
829
- options.eventSetting.clickCallback
830
- );
831
- if (extraGeometries.length) {
832
- gisMap.locateFeatureByCoords(extraGeometries, 'polygon',
833
- options.layerName, // id,如果已经有attributes就没用了
834
- options.specialAreaStyle, // style
835
- options.highlightStyle, // highlightStyle
836
- false, // zoom
837
- options.keyFieldName,
838
- options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
839
- options.specialAreaLabelStyle, // labelStyle
840
- false, // randomColor
841
- false, // renderCanvas
842
- true, // singleSelect
843
- {
844
- minZoom: options.visiblitySetting.beginLevel,
845
- maxZoom: options.visiblitySetting.endLevel,
846
- layerId: options.layerName
847
- // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
848
- },
849
- options.layerName, // layerTag
850
- options.eventSetting.clickCallback
851
- );
852
- }
853
- }
854
-
855
- if (!data) {
856
- // 数据来自本地
857
- var dbOpenRequest = window.indexedDB.open('regionDB');
858
- dbOpenRequest.onsuccess = function(event) {
859
- var db = this.result;
860
- var store = db.transaction(storeName).objectStore(storeName);
861
- var request = store.getAll();
862
- request.onsuccess = function() {
863
- var features = this.result;
864
- showGrid(features);
865
- }
866
- }
867
- } else {
868
- var _data = JSON.parse(JSON.stringify(data[0]));
869
- var newData = data[0];
870
- if (newData && newData.geometry) {
871
- _data = JSON.parse(JSON.stringify(data));
872
- showGrid(data);
873
- } else {
874
- showGrid(data[0]);
875
- }
876
-
877
- var dbRequest = window.indexedDB.open('regionDB');
878
- dbRequest.onsuccess = function() {
879
- addStore(this.result.version);
880
- }
881
- function addStore(version) {
882
- var dbOpenRequest = window.indexedDB.open('regionDB', version + 1);
883
- dbOpenRequest.onupgradeneeded = function(event) {
884
- var db = event.target.result;
885
- if (!db.objectStoreNames.contains(storeName)) {
886
- var store = db.createObjectStore(storeName, { autoIncrement: true });
887
- for (var i = 0; i < _data.length; i++) {
888
- store.put(_data[i]);
889
- }
890
- store.transaction.oncomplete = function() {
891
- console.log("complete");
892
- }
893
- }
894
-
895
- }
896
- }
897
- }
898
- }
899
-
900
- this.networkCloud = function (options, positions) {
901
- if(!globeMap) {return}
902
- globeMap.networkCloud(options, positions)
903
- }
904
- this.clearNetworkCloud = function (layerNames) {
905
- if(!globeMap) {return}
906
- globeMap.clearNetworkCloud(layerNames)
907
- }
908
- this.lineOperation = function(options, data) {
909
- if(!options || !options.layerName){
910
- console.log('图层名必须传递')
911
- return
912
- }
913
- // 数据获取
914
- let queryFeature = (queryParams) => {
915
- if(gisMap) {
916
- return new Promise(function(resolve) {
917
- let cb = function(result) {
918
- resolve(result)
919
- }
920
- gisMap.queryFeature(queryParams, cb)
921
- })
922
- } else {
923
- return Promise.resolve(undefined)
924
- }
925
- }
926
- // 执行绘制
927
- let drawLine = (options, data) => {
928
- if (globeMap) globeMap.lineOperation(options, data);
929
- else if (gisMap) {
930
- let style = options.style || {};
931
- let hStyle = options.hStyle || {};
932
- let symbol = {
933
- type: "simple-line", // autocasts as new SimpleLineSymbol()
934
- color: style.color || "lightblue",
935
- width: (style.width || 2) + "px",
936
- style: style.style || "short-dot"
937
- };
938
- let hsymbol = {
939
- type: "simple-line", // autocasts as new SimpleLineSymbol()
940
- color: hStyle.color || "lightblue",
941
- width: (hStyle.width || 2) + "px",
942
- style: hStyle.style || "short-dot"
943
- };
944
- var opt = options.options || {};
945
- gisMap.locateFeatureByCoords(data, options.type, options.id, symbol, hsymbol, options.zoom, options.keyField,
946
- options.labelField,
947
- options.labelStyle,
948
- options.randomColor,
949
- options.renderCanvas,
950
- options.singleSelected,
951
- opt,
952
- options.layerTag,
953
- options.callback
954
- );
955
- }
956
- }
957
-
958
- // 主逻辑
959
- if(!!data&&data.length) {
960
- drawLine(options, data)
961
- } else {
962
- if(!options.usageID) {
963
- console.log('图层用途必须传递')
964
- return
965
- }
966
-
967
- let originalData = false;
968
- if (globeMap) originalData = true;
969
- let queryParams = {
970
- layerID: options.usageID,
971
- where: options.filterString || "1=1",
972
- geometry: '',
973
- outGeometry: true,
974
- options: { originalData: originalData }
975
- }
976
- queryFeature(queryParams)
977
- .then(function(resultData) {
978
- if(!resultData) {
979
- console.log('没有查询到数据,请检查查询参数')
980
- return
981
- }
982
- drawLine(options, resultData)
983
- })
984
- }
985
-
986
- }
987
- }
988
-
989
-
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
+ globeMap.drawPoints(layerName, positions, options);
308
+ }
309
+ if(gisMap && mapType == "map"){
310
+ deal2DPoints(layerName, positions, options).then(args => {
311
+ gisMap.showMultiObjectCurrentPosition(
312
+ args.datalist,
313
+ args.zoom,
314
+ args.clear,
315
+ args.highLightType,
316
+ args.infoStyle,
317
+ args.renderCanvas,
318
+ args.tagName,
319
+ options.clickCallback,
320
+ options.mouseOverCallback,
321
+ args.clusterOption,
322
+ args.hasHover,
323
+ layerName,
324
+ options.mouseOutCallback,
325
+ options.option
326
+ );
327
+ });
328
+ }
329
+ }
330
+ this.getLabel = function (attributes) {
331
+ if (!attributes) return;
332
+ var label = [], field = {};
333
+ for (var key in attributes) {
334
+ field = {};
335
+ field[key] = attributes[key];
336
+ label.push(field);
337
+ }
338
+ return label;
339
+ };
340
+ this.drawParts = function (options, data, callback) {
341
+ var self = this;
342
+ function showParts(data) {
343
+ var drawParam = options.drawParam || {};
344
+ var ctrOption = drawParam.clusterOption;
345
+ var clusterOption = {
346
+ clusterType: ctrOption.clusterType,
347
+ level: ctrOption.level || 0,
348
+ style: {
349
+ "type": "simple-marker",
350
+ "style": "circle",
351
+ "color": ctrOption.color || [255, 0, 0, 0.6],
352
+ "size": ctrOption.size || 20,
353
+ "outline": { //if outline has been specified
354
+ "color": ctrOption.outlineColor || [255, 168, 0, 1],
355
+ "width": ctrOption.outlineWidth || 2
356
+ }
357
+ },
358
+ labelStyle: {
359
+ "type": "text",
360
+ "color": ctrOption.labelColor || [255, 255, 255, 1],
361
+ "text": "",
362
+ "zlevel": ctrOption.labelZlevel || 1,
363
+ "yoffset": 0,
364
+ "font": ctrOption.labelFont || {
365
+ "family": "Arial",
366
+ "size": 10
367
+ }
368
+ },
369
+ distance: ctrOption.distance || 50
370
+ };
371
+
372
+ var param = [data, true, false, null, null, false, drawParam.tagName, drawParam.clickCallback, drawParam.mouseOverCallback, clusterOption, false, drawParam.layerName, drawParam.callback, drawParam.drawOptions];
373
+ //三维聚类参数
374
+ var globeOptions = {
375
+ zoom:true,
376
+ scale: 0.9,
377
+ clear :true,
378
+ nearFarScalar:[8000, 1.0, 10000, 0.6],
379
+ clickCallBack: drawParam.clickCallback,
380
+ layerName: drawParam.layerName,
381
+ minSize:30,
382
+ clusterLimit: 20,
383
+ style:"default",
384
+ clusterImageInfo: {
385
+ horizontalOrigin: "center",
386
+ verticalOrigin: "bottom",
387
+ cssStyle: {
388
+ "borderRadius": 500,
389
+ "fillColor": "rgba(0,0,0,0.7)",
390
+ "borderLineWidth": 3,
391
+ "borderLineColor": "rgba(250,140,0,0.9)",
392
+ "paddingX": 15,
393
+ "paddingY": 6,
394
+ "marginBottom": 2
395
+ },
396
+ textStyle: {
397
+ "font": "60px Helvetica",
398
+ "fillColor": "rgba(220,220,220,1.0)",
399
+ "outlineColor": "black",
400
+ "outlineWidth": 1,
401
+ "padding": 1,
402
+ "textScale": 0.5,
403
+ "textStartX": 40,
404
+ "textStartY": 15
405
+ }
406
+ }
407
+ }
408
+ if (globeMap) {
409
+ globeMap.addClusterLayer({
410
+ data,
411
+ options:globeOptions
412
+ })
413
+ } else if (gisMap) {
414
+ gisMap.showMultiObjectCurrentPosition(...param );
415
+ }
416
+ }
417
+
418
+ if (data) {
419
+ showParts(data);
420
+ } else {
421
+ let queryFromGIS = () => {
422
+ let queryParam = options.queryParam;
423
+ var subTypeName = options.subTypeName;
424
+ var subUniqueCode = options.subUniqueCode;
425
+ let queryCallback = function (featureInfos) {
426
+ var features = featureInfos[queryParam.phyLayerIDs];
427
+ if (features.length == 0) {
428
+ callback && callback([]);
429
+ return;
430
+ }
431
+ if (!features || !features.length) return;
432
+ var symbolUrl = "";
433
+ if (subUniqueCode.indexOf("http") > -1) {
434
+ symbolUrl = subUniqueCode;
435
+ } else if (subUniqueCode.indexOf(".") > -1) {
436
+ symbolUrl = subUniqueCode;
437
+ } else {
438
+ symbolUrl = "".concat(subUniqueCode, ".png");
439
+ if(globeMap) symbolUrl = queryParam.gisServerURL ? `${queryParam.gisServerURL}/symbol/${symbolUrl}` : symbolUrl;
440
+ }
441
+ var dataList = features.map((function (feature) {
442
+ return Object.assign({}, { x: feature.geometry.x, y: feature.geometry.y }, {
443
+ attributes: feature.attributes,
444
+ // label:self.getLabel(feature.attributes), //去除内部弹框的可能性
445
+ symbolType: -1,
446
+ symbolUrl: symbolUrl,
447
+ scale: 0.5
448
+ });
449
+ }));
450
+ callback && callback(dataList);
451
+ showParts(dataList);
452
+ };
453
+ if (gisMap) {
454
+ gisMap.queryPhylayerFeatures(queryParam, queryCallback);
455
+ }
456
+ }
457
+ queryFromGIS();
458
+ }
459
+ };
460
+
461
+ this.drawOtherParts = function (options, data) {
462
+ var self = this;
463
+ const geomType = options.geomType;
464
+ let queryParam = options.queryParam || {};
465
+ function showParts(data) {
466
+
467
+ }
468
+
469
+ if (data) {
470
+ showParts(data);
471
+ } else {
472
+ const layerID = queryParam.phyLayerIDs;
473
+ const layerName = queryParam.layerName;
474
+ const keyField = null;
475
+ const keyValue = null;
476
+ const clearMap = queryParam.clearMap || true;
477
+ let inStyle = queryParam.style || {
478
+ color: "blue"
479
+ };
480
+ let inHStyle = queryParam.hStyle || {
481
+ color: "blue"
482
+ };
483
+ let style = null, hStyle = null;
484
+ if (geomType == 1) {
485
+ } else if (geomType == 2) {
486
+ style = {
487
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
488
+ color: inStyle.color || "blue",
489
+ width: inStyle.width || "2px",
490
+ style: inStyle.style || "solid",
491
+ cap: inStyle.cap || "round",
492
+ join: inStyle.join || "round",
493
+ };
494
+ hStyle = {
495
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
496
+ color: inHStyle.color || "red",
497
+ width: inHStyle.width || inStyle.width || "2px",
498
+ style: inHStyle.style || inStyle.style || "solid",
499
+ cap: inHStyle.cap || inStyle.cap || "round",
500
+ join: inHStyle.join || inStyle.join || "round",
501
+ };
502
+ } else if (geomType == 3) {
503
+ style = {
504
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
505
+ color: inStyle.color || [51, 51, 204, 0.9],
506
+ style: inStyle.style || "solid",
507
+ outline: { // autocasts as new SimpleLineSymbol()
508
+ color: inStyle.outlineColor || "blue",
509
+ width: inStyle.outlineWidth || "1px",
510
+ style: inStyle.outlineStyle || "solid",
511
+ cap: inStyle.outlineCap || "round",
512
+ join: inStyle.outlineJoin || "round",
513
+ }
514
+ };
515
+ hStyle = {
516
+ type: "simple-fill", // autocasts as new SimpleFillSymbol()
517
+ color: inHStyle.color || [51, 51, 204, 0.9],
518
+ style: inHStyle.style || inStyle.style || "solid",
519
+ outline: { // autocasts as new SimpleLineSymbol()
520
+ color: inHStyle.outlineColor || "red",
521
+ width: inHStyle.outlineWidth || inStyle.outlineWidth || "1px",
522
+ style: inHStyle.outlineStyle || inStyle.outlineStyle || "solid",
523
+ cap: inHStyle.outlineCap || inStyle.outlineCap || "round",
524
+ join: inHStyle.outlineJoin || inStyle.outlineJoin || "round",
525
+ }
526
+ };
527
+ }
528
+ const bZoom = queryParam.bZoom || true;
529
+ const randomColor = null;
530
+ const labelField = null;
531
+ const labelstyle = null;
532
+ const geometry = null;
533
+ const where = queryParam.where || "1=1";
534
+ const opts = {
535
+ layerId: layerName,
536
+ mouseOverCallback: queryParam.mouseOverCallback
537
+ };
538
+
539
+ 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];
540
+ //let param = [layerID, keyField, keyValue, clearMap, style, hStyle, bZoom, randomColor, labelField, labelstyle, geometry, where, null, null, opts, null, null, null, null, queryParam.callback];
541
+ if (globeMap) {
542
+ gisMap.locateFeatureByIDs(...param);
543
+ } else if (gisMap) {
544
+ gisMap.locateFeatureByIDs(...param);
545
+ }
546
+
547
+ }
548
+ };
549
+
550
+ /*
551
+ * @description:新的轨迹线接口
552
+ * @method traceOperation
553
+ * @param {Array} posArr 位置数组
554
+ * @param {Object} options 配置项
555
+ *
556
+ * @return {Void} 无返回
557
+ *
558
+ * @author: Hetianhong
559
+ * @date: 2021-09-09 14:49:49
560
+ */
561
+ this.traceOperation = function (posArr, options) {
562
+ globeMap.traceOperation(posArr, options);
563
+ }
564
+ /*
565
+ * @description:网格接口
566
+ * 先查询idb的data,没有的话,再查询queryFeature的data
567
+ * @method regionOperation
568
+ * @param {Object} options 配置项
569
+ * @param {Array} data 数据,可不传
570
+ *
571
+ * @return {Void} 无返回
572
+ *
573
+ * @author: Hetianhong
574
+ * @date: 2021-10-19 17:27:02
575
+ */
576
+ this.regionOperation = function (options, data, callback) {
577
+
578
+ function execOperation(data) {
579
+ if (globeMap) {
580
+ globeMap.regionOperation(options, data);
581
+ callback && callback();
582
+ } else if (gisMap) {
583
+ gridPolygon2dOperation(options, data, callback);
584
+ }
585
+ }
586
+
587
+ if (data) {
588
+ execOperation(data);
589
+ } else {
590
+ if (!options.idbSetting.usageID) { return }
591
+
592
+ let storeName = !!globeMap ? "usageID" : "usage2D" + "_" + options.idbSetting.usageID;
593
+ let queryFromGIS = () => {
594
+ let filterString = options.idbSetting.filterString || "1=1";
595
+ let queryParam = {
596
+ layerID: options.idbSetting.usageID,
597
+ where: filterString,
598
+ geometry: '',
599
+ outGeometry: true,
600
+ options: {
601
+ originalData: true
602
+ }
603
+ }
604
+ //二维地图不获取原始数据
605
+ if(!globeMap) queryParam.options.originalData = false;
606
+ let queryCallback = function (featureInfos) {
607
+ execOperation(featureInfos);
608
+ }
609
+ if (gisMap) {
610
+ gisMap.queryFeature(queryParam, queryCallback)
611
+ }
612
+ }
613
+
614
+ if (!options.idbSetting.enabled) {
615
+ // 直接查询
616
+ queryFromGIS()
617
+ } else {
618
+ // 查询是否存在表
619
+ checkObjectStore(storeName)
620
+ .then(function (hasObjStore) {
621
+ if (hasObjStore) {
622
+ // 如果有,读取本地
623
+ execOperation();
624
+ } else {
625
+ // 如果没有,查询queryFeature
626
+ queryFromGIS()
627
+ }
628
+ })
629
+ }
630
+ }
631
+ }
632
+ /*
633
+ * @description:新参数格式的旧线接口,主要用来做中间层参数格式转换
634
+ * @method showPolyline_BI
635
+ * @param {参数类型} 参数名 参数说明
636
+ *
637
+ * @return {返回值类型} 返回值说明
638
+ *
639
+ * @author: Hetianhong
640
+ * @date: 2021-11-11 15:40:31
641
+ */
642
+ this.showPolyline_BI = function (layerName, positions = [], options = {}) {
643
+ if (globeMap !== null) {
644
+ // 默认参数
645
+ let defaultOpt = {
646
+ // 样式类
647
+ styleOpt: {
648
+ period: 4, // 动画线段的周期,越短越快
649
+ image: 'road.png', // type为image时线段所使用的纹理图案,位置在data3d/polyline/目录下(type为image限定)
650
+ repeatX: 2, // 横向纹理重复,越大则越密(type为image限定)
651
+ repeatY: 1, //纵向纹理重复(type为image限定)
652
+ glowPower: 0, //中心亮度
653
+ intensity: 1.2, //纹理图片颜色强度
654
+ gapColor: 'rgba(0, 0, 0, 0)', //间隙颜色(type为dash限定)
655
+ dashLength: 15, //间隙宽(type为dash限定)
656
+ outlineWidth: 0, // 边框线宽(type为outline限定)
657
+ outlineColor: "rgba(0, 0, 0, 0)", // 边框颜色(type为outline限定)
658
+ type: 'color', // 线条类型,有 image color dash outline glow
659
+ width: 10,
660
+ color: "rgba(255,255,0,1)"
661
+ },
662
+ // 视角缩放类
663
+ zoomOpt: {
664
+ //zoom参数
665
+ heading: 0,
666
+ pitch: -90,
667
+ range: null,
668
+ //可视级别
669
+ minZoom: 0,
670
+ maxZoom: 24,
671
+ //泛光绘制
672
+ // 下面两项,不暴露,全部为false
673
+ bloom: false,
674
+ merge: false
675
+ },
676
+ // 交互类
677
+ interactOpt: {
678
+ //click相关
679
+ clickColor: "rgb(255, 255, 0.0)", // 点击后的颜色
680
+ clickWidth: 30, // 点击后的宽度
681
+ clickCallback: undefined, // function(e) {console.log('click polyline', e)},
682
+ mouseOverCallBack: undefined
683
+ }
684
+ }
685
+ let getMergedOptions = (options) => {
686
+ let mergedOptions = {};
687
+ mergedOptions.styleOpt = Object.assign({}, defaultOpt.styleOpt, options.styleOpt);
688
+ mergedOptions.zoomOpt = Object.assign({}, defaultOpt.zoomOpt, options.zoomOpt);
689
+ mergedOptions.interactOpt = Object.assign({}, defaultOpt.interactOpt, options.interactOpt);
690
+ return mergedOptions
691
+ }
692
+ let mergedOptions = getMergedOptions(options);
693
+
694
+
695
+ let opt = {}
696
+ // let styleOpt = options.styleOpt;
697
+ // let zoomOpt = options.zoomOpt;
698
+ // let interactOpt = options.interactOpt;
699
+ //hth 此处进行参数转换
700
+ switch (mergedOptions.styleOpt.type) {
701
+ case "image":
702
+ opt.period = defaultValue(mergedOptions.styleOpt.period, 4); // 纹理流动周期,越小越快
703
+ opt.image = defaultValue(mergedOptions.styleOpt.image, 'road.png'); //纹理图片,data3d/polyline/目录下
704
+ opt.repeatX = defaultValue(mergedOptions.styleOpt.repeatX, 2); //横向纹理重复,越大越密
705
+ opt.repeatY = defaultValue(mergedOptions.styleOpt.repeatY, 1); //纵向纹理重复
706
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0); //中心亮度
707
+ opt.intensity = defaultValue(mergedOptions.styleOpt.intensity, 1.2); //纹理图片颜色强度
708
+ break;
709
+ case "glow":
710
+ opt.glowPower = defaultValue(mergedOptions.styleOpt.glowPower, 0.2); //中心亮度
711
+ break;
712
+ case "dash":
713
+ opt.gapColor = defaultValue(mergedOptions.styleOpt.gapColor, 'rgba(0, 0, 0, 0)'); //间隙颜色
714
+ opt.dashLength = defaultValue(mergedOptions.styleOpt.dashLength, 15); //间隙宽
715
+ break;
716
+ case "outline":
717
+ opt.outlineWidth = defaultValue(mergedOptions.styleOpt.outlineWidth, 0);
718
+ opt.outlineColor = defaultValue(mergedOptions.styleOpt.outlineColor, "rgba(0, 0, 0, 0)");
719
+ break;
720
+ default:
721
+ // color
722
+ };
723
+
724
+ opt.type = mergedOptions.styleOpt.type;
725
+ opt.width = mergedOptions.styleOpt.width;
726
+ opt.color = mergedOptions.styleOpt.color;
727
+
728
+ // 遍历位置数组中的每一项
729
+ for(let pos of positions) {
730
+ // 遍历opt中每一个key赋值到每一个pos中
731
+ for(let k in opt) {
732
+ pos[k] = opt[k]
733
+ }
734
+ }
735
+
736
+
737
+ let zoom = mergedOptions.zoomOpt.zoom
738
+ let clear = mergedOptions.zoomOpt.clear
739
+ let clickCallback = mergedOptions.interactOpt.clickCallback
740
+ let mouseOverCallBack = mergedOptions.interactOpt.mouseOverCallBack
741
+ let commonOpt = {
742
+ //zoom参数
743
+ heading: mergedOptions.zoomOpt.heading,
744
+ pitch: mergedOptions.zoomOpt.pitch,
745
+ range: mergedOptions.zoomOpt.range,
746
+ //可视级别
747
+ minZoom: mergedOptions.zoomOpt.minZoom,
748
+ maxZoom: mergedOptions.zoomOpt.maxZoom,
749
+ //click相关
750
+ clickColor: mergedOptions.interactOpt.clickColor, // 点击后的颜色
751
+ clickWidth: mergedOptions.interactOpt.clickWidth, // 点击后的宽度
752
+ //泛光绘制
753
+ // 下面两项,不暴露,全部为false
754
+ bloom: false,
755
+ merge: false
756
+ }
757
+
758
+
759
+ globeMap.showPolyline(positions, zoom, clear, commonOpt, layerName, clickCallback, mouseOverCallBack);
760
+ }
761
+ }
762
+ /*
763
+ * @description:被动触发图层类似点击效果,需要在图层内在单独定义Event
764
+ * @method activeLayer
765
+ * @param {String} layerName 图层名
766
+ * @param {Object} options 配置项
767
+ * @param {String} options.type 操作类型,'clear', 'active'
768
+ * @param {Boolean} options.zoom 是否缩放
769
+ * @param {Object} filter 过滤项
770
+ * @param {String} filter.keyFieldName 过滤键名
771
+ * @param {Array} filter.values 过滤值内容数组
772
+ *
773
+ * @return {返回值类型} 返回值说明
774
+ *
775
+ * @author: Hetianhong
776
+ * @date: 2021-11-26 09:49:16
777
+ */
778
+ this.activeLayer = function (layerName, options, filter) {
779
+ if (globeMap != null && mapType == "globe") {
780
+ globeMap.activeLayer(layerName, options, filter);
781
+ }
782
+ if (gisMap != null && mapType == "map") {
783
+ gisMap.activeLayer(layerName, options, filter);
784
+ }
785
+ }
786
+
787
+ function gridPolygon2dOperation(options, data, callback) {
788
+ var storeName = `usage2D_${options.idbSetting.usageID}`;
789
+ function showGrid(realData) {
790
+ // 转换一下
791
+ var geometries = [];
792
+ var extraGeometries = [];
793
+ for (var i = 0; i < realData.length; i++) {
794
+ var feature = realData[i];
795
+ var geom = feature.geometry;
796
+ geom.attributes = feature.attributes; // attributes会导致id没用,使用自带的id
797
+ geometries.push(geom);
798
+ }
799
+ if (options.specialArea && options.selectedSetting.selected.length) {
800
+ var extraIds = options.selectedSetting.selected.map(s => s.selectID);
801
+ for (var i = geometries.length - 1; i > -1; i--) {
802
+ var geom = geometries[i];
803
+ if (extraIds.indexOf(geom.attributes[options.keyFieldName]) > -1) {
804
+ geometries.splice(i, 1);
805
+ extraGeometries.push(geom);
806
+ if (extraGeometries.length === extraIds.length) break;
807
+ }
808
+ }
809
+ }
810
+ gisMap.locateFeatureByCoords(geometries, 'polygon',
811
+ options.layerName, // id,如果已经有attributes就没用了
812
+ options.style, // style
813
+ options.highlightStyle, // highlightStyle
814
+ options.commonSetting.zoom, // zoom
815
+ options.keyFieldName,
816
+ options.labelSetting.showLabel && options.labelFieldName, // keyField, labelField
817
+ options.labelStyle, // labelStyle
818
+ options.customColor ? interpolateColor(options.customColor[0], options.customColor[1], Math.min(geometries.length, 10)) : 10, // randomColor
819
+ false, // renderCanvas
820
+ true, // singleSelect
821
+ {
822
+ minZoom: options.visiblitySetting.beginLevel,
823
+ maxZoom: options.visiblitySetting.endLevel,
824
+ layerId: options.layerName,
825
+ comCallbak: callback
826
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
827
+ },
828
+ options.layerName, // layerTag
829
+ options.eventSetting.clickCallback
830
+ );
831
+ if (extraGeometries.length) {
832
+ gisMap.locateFeatureByCoords(extraGeometries, 'polygon',
833
+ options.layerName, // id,如果已经有attributes就没用了
834
+ options.specialAreaStyle, // style
835
+ options.highlightStyle, // highlightStyle
836
+ false, // zoom
837
+ options.keyFieldName,
838
+ options.selectedSetting.showLabel && options.labelFieldName, // keyField, labelField
839
+ options.specialAreaLabelStyle, // labelStyle
840
+ false, // randomColor
841
+ false, // renderCanvas
842
+ true, // singleSelect
843
+ {
844
+ minZoom: options.visiblitySetting.beginLevel,
845
+ maxZoom: options.visiblitySetting.endLevel,
846
+ layerId: options.layerName
847
+ // hLabelStyle: options.hLabelStyle, // 选中文字时效果,没用
848
+ },
849
+ options.layerName, // layerTag
850
+ options.eventSetting.clickCallback
851
+ );
852
+ }
853
+ }
854
+
855
+ if (!data) {
856
+ // 数据来自本地
857
+ var dbOpenRequest = window.indexedDB.open('regionDB');
858
+ dbOpenRequest.onsuccess = function(event) {
859
+ var db = this.result;
860
+ var store = db.transaction(storeName).objectStore(storeName);
861
+ var request = store.getAll();
862
+ request.onsuccess = function() {
863
+ var features = this.result;
864
+ showGrid(features);
865
+ }
866
+ }
867
+ } else {
868
+ var _data = JSON.parse(JSON.stringify(data[0]));
869
+ var newData = data[0];
870
+ if (newData && newData.geometry) {
871
+ _data = JSON.parse(JSON.stringify(data));
872
+ showGrid(data);
873
+ } else {
874
+ showGrid(data[0]);
875
+ }
876
+
877
+ var dbRequest = window.indexedDB.open('regionDB');
878
+ dbRequest.onsuccess = function() {
879
+ addStore(this.result.version);
880
+ }
881
+ function addStore(version) {
882
+ var dbOpenRequest = window.indexedDB.open('regionDB', version + 1);
883
+ dbOpenRequest.onupgradeneeded = function(event) {
884
+ var db = event.target.result;
885
+ if (!db.objectStoreNames.contains(storeName)) {
886
+ var store = db.createObjectStore(storeName, { autoIncrement: true });
887
+ for (var i = 0; i < _data.length; i++) {
888
+ store.put(_data[i]);
889
+ }
890
+ store.transaction.oncomplete = function() {
891
+ console.log("complete");
892
+ }
893
+ }
894
+
895
+ }
896
+ }
897
+ }
898
+ }
899
+
900
+ this.networkCloud = function (options, positions) {
901
+ if(!globeMap) {return}
902
+ globeMap.networkCloud(options, positions)
903
+ }
904
+ this.clearNetworkCloud = function (layerNames) {
905
+ if(!globeMap) {return}
906
+ globeMap.clearNetworkCloud(layerNames)
907
+ }
908
+ this.lineOperation = function(options, data) {
909
+ if(!options || !options.layerName){
910
+ console.log('图层名必须传递')
911
+ return
912
+ }
913
+ // 数据获取
914
+ let queryFeature = (queryParams) => {
915
+ if(gisMap) {
916
+ return new Promise(function(resolve) {
917
+ let cb = function(result) {
918
+ resolve(result)
919
+ }
920
+ gisMap.queryFeature(queryParams, cb)
921
+ })
922
+ } else {
923
+ return Promise.resolve(undefined)
924
+ }
925
+ }
926
+ // 执行绘制
927
+ let drawLine = (options, data) => {
928
+ if (globeMap) globeMap.lineOperation(options, data);
929
+ else if (gisMap) {
930
+ let style = options.style || {};
931
+ let hStyle = options.hStyle || {};
932
+ let symbol = {
933
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
934
+ color: style.color || "lightblue",
935
+ width: (style.width || 2) + "px",
936
+ style: style.style || "short-dot"
937
+ };
938
+ let hsymbol = {
939
+ type: "simple-line", // autocasts as new SimpleLineSymbol()
940
+ color: hStyle.color || "lightblue",
941
+ width: (hStyle.width || 2) + "px",
942
+ style: hStyle.style || "short-dot"
943
+ };
944
+ var opt = options.options || {};
945
+ gisMap.locateFeatureByCoords(data, options.type, options.id, symbol, hsymbol, options.zoom, options.keyField,
946
+ options.labelField,
947
+ options.labelStyle,
948
+ options.randomColor,
949
+ options.renderCanvas,
950
+ options.singleSelected,
951
+ opt,
952
+ options.layerTag,
953
+ options.callback
954
+ );
955
+ }
956
+ }
957
+
958
+ // 主逻辑
959
+ if(!!data&&data.length) {
960
+ drawLine(options, data)
961
+ } else {
962
+ if(!options.usageID) {
963
+ console.log('图层用途必须传递')
964
+ return
965
+ }
966
+
967
+ let originalData = false;
968
+ if (globeMap) originalData = true;
969
+ let queryParams = {
970
+ layerID: options.usageID,
971
+ where: options.filterString || "1=1",
972
+ geometry: '',
973
+ outGeometry: true,
974
+ options: { originalData: originalData }
975
+ }
976
+ queryFeature(queryParams)
977
+ .then(function(resultData) {
978
+ if(!resultData) {
979
+ console.log('没有查询到数据,请检查查询参数')
980
+ return
981
+ }
982
+ drawLine(options, resultData)
983
+ })
984
+ }
985
+
986
+ }
987
+ }
988
+
989
+
990
990
  export default egovaBI