egovamap 0.16.2 → 0.16.3

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