@supermapgis/iclient-ol 11.1.2

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.
Files changed (91) hide show
  1. package/README.md +56 -0
  2. package/control/ChangeTileVersion.js +438 -0
  3. package/control/Logo.js +99 -0
  4. package/control/ScaleLine.js +164 -0
  5. package/control/index.js +6 -0
  6. package/core/MapExtend.js +49 -0
  7. package/core/StyleUtils.js +1253 -0
  8. package/core/Util.js +478 -0
  9. package/core/index.js +6 -0
  10. package/css/ChangeTileVersion.css +347 -0
  11. package/css/index.js +5 -0
  12. package/dist/iclient-openlayers-es6.js +121806 -0
  13. package/dist/iclient-openlayers-es6.min.js +8 -0
  14. package/dist/iclient-openlayers.css +668 -0
  15. package/dist/iclient-openlayers.js +132335 -0
  16. package/dist/iclient-openlayers.min.css +8 -0
  17. package/dist/iclient-openlayers.min.js +8 -0
  18. package/index.js +9 -0
  19. package/mapping/BaiduMap.js +121 -0
  20. package/mapping/ImageSuperMapRest.js +252 -0
  21. package/mapping/ImageTileSuperMapRest.js +99 -0
  22. package/mapping/InitMap.js +125 -0
  23. package/mapping/SuperMapCloud.js +56 -0
  24. package/mapping/Tianditu.js +152 -0
  25. package/mapping/TileSuperMapRest.js +358 -0
  26. package/mapping/WebMap.js +5185 -0
  27. package/mapping/index.js +11 -0
  28. package/mapping/webmap/Util.js +176 -0
  29. package/mapping/webmap/config/MunicipalCenter.json +1 -0
  30. package/mapping/webmap/config/ProvinceCenter.json +1 -0
  31. package/mapping/webmap/config/SampleDataInfo.json +55 -0
  32. package/namespace.js +150 -0
  33. package/overlay/DataFlow.js +114 -0
  34. package/overlay/FGB.js +97 -0
  35. package/overlay/Graph.js +436 -0
  36. package/overlay/GraphMap.js +91 -0
  37. package/overlay/Graphic.js +587 -0
  38. package/overlay/HeatMap.js +444 -0
  39. package/overlay/Label.js +964 -0
  40. package/overlay/Mapv.js +146 -0
  41. package/overlay/Range.js +127 -0
  42. package/overlay/RankSymbol.js +94 -0
  43. package/overlay/Turf.js +298 -0
  44. package/overlay/Unique.js +123 -0
  45. package/overlay/VectorTileSuperMapRest.js +466 -0
  46. package/overlay/graphic/CanvasRenderer.js +177 -0
  47. package/overlay/graphic/CloverShape.js +133 -0
  48. package/overlay/graphic/Graphic.js +174 -0
  49. package/overlay/graphic/HitCloverShape.js +63 -0
  50. package/overlay/graphic/WebGLRenderer.js +356 -0
  51. package/overlay/graphic/index.js +9 -0
  52. package/overlay/index.js +21 -0
  53. package/overlay/mapv/MapvCanvasLayer.js +104 -0
  54. package/overlay/mapv/MapvLayer.js +410 -0
  55. package/overlay/mapv/index.js +5 -0
  56. package/overlay/theme/GeoFeature.js +275 -0
  57. package/overlay/theme/Theme.js +585 -0
  58. package/overlay/theme/ThemeFeature.js +46 -0
  59. package/overlay/theme/index.js +6 -0
  60. package/overlay/vectortile/DeafultCanvasStyle.js +125 -0
  61. package/overlay/vectortile/MapboxStyles.js +375 -0
  62. package/overlay/vectortile/StyleMap.js +252 -0
  63. package/overlay/vectortile/VectorTileStyles.js +554 -0
  64. package/overlay/vectortile/index.js +7 -0
  65. package/overlay/vectortile/olExtends.js +382 -0
  66. package/package.json +29 -0
  67. package/services/AddressMatchService.js +60 -0
  68. package/services/ChartService.js +74 -0
  69. package/services/DataFlowService.js +118 -0
  70. package/services/DatasetService.js +104 -0
  71. package/services/DatasourceService.js +76 -0
  72. package/services/FeatureService.js +196 -0
  73. package/services/FieldService.js +53 -0
  74. package/services/GeoprocessingService.js +156 -0
  75. package/services/GridCellInfosService.js +53 -0
  76. package/services/ImageCollectionService.js +92 -0
  77. package/services/ImageService.js +69 -0
  78. package/services/KnowledgeGraphService.js +82 -0
  79. package/services/LayerInfoService.js +85 -0
  80. package/services/MapService.js +85 -0
  81. package/services/MeasureService.js +77 -0
  82. package/services/NetworkAnalyst3DService.js +88 -0
  83. package/services/NetworkAnalystService.js +252 -0
  84. package/services/ProcessingService.js +478 -0
  85. package/services/QueryService.js +116 -0
  86. package/services/ServiceBase.js +26 -0
  87. package/services/SpatialAnalystService.js +432 -0
  88. package/services/ThemeService.js +50 -0
  89. package/services/TrafficTransferAnalystService.js +88 -0
  90. package/services/WebPrintingJobService.js +112 -0
  91. package/services/index.js +27 -0
@@ -0,0 +1,410 @@
1
+ /* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2
+ * This program are made available under the terms of the Apache License, Version 2.0
3
+ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
+ import {
5
+ MapvCanvasLayer
6
+ } from './MapvCanvasLayer';
7
+ import {
8
+ baiduMapLayer
9
+ } from "mapv";
10
+ import PointerInteraction from 'ol/interaction/Pointer';
11
+
12
+ var BaiduMapLayer = baiduMapLayer ? baiduMapLayer.__proto__ : Function;
13
+
14
+ /**
15
+ * @class MapvLayer
16
+ * @classdesc MapV 图层类。
17
+ * @private
18
+ * @param {Object} map - 地图。
19
+ * @param {Mapv.DataSet} [dataSet] - 数据集。
20
+ * @param {Object} options - 参数。
21
+ * @param {number} mapWidth - 地图宽度。
22
+ * @param {number} mapHeight - 地图高度。
23
+ * @param {Object} source - 资源。
24
+ * @param {number} options.width - 画布宽。
25
+ * @param {number} options.height - 画布高。
26
+ * @param {string} [options.paneName='mapPane'] - 窗口名。
27
+ * @param {string} [options.context] - 内容。
28
+ * @param {number} [options.zIndex] - 层级。
29
+ * @param {string} [options.mixBlendMode] - 最小混合模式。
30
+
31
+ * @extends {Mapv.BaiduMapLayer}
32
+ */
33
+ export class MapvLayer extends BaiduMapLayer {
34
+
35
+ constructor(map, dataSet, options, mapWidth, mapHeight, source) {
36
+ super(map, dataSet, options);
37
+ this.dataSet = dataSet;
38
+ this.mapWidth = mapWidth;
39
+ this.mapHeight = mapHeight;
40
+ var self = this;
41
+ options = options || {};
42
+ this.source = source;
43
+ self.animator = null;
44
+ self.map = map;
45
+ self.init(options);
46
+ self.argCheck(options);
47
+ this.canvasLayer = new MapvCanvasLayer({
48
+ map: map,
49
+ context: this.context,
50
+ paneName: options.paneName,
51
+ mixBlendMode: options.mixBlendMode,
52
+ enableMassClear: options.enableMassClear,
53
+ zIndex: options.zIndex,
54
+ width: mapWidth,
55
+ height: mapHeight,
56
+ update: function update() {
57
+ self._canvasUpdate();
58
+ }
59
+ });
60
+ this.clickEvent = this.clickEvent.bind(this);
61
+ this.mousemoveEvent = this.mousemoveEvent.bind(this);
62
+ map.on('movestart', this.moveStartEvent.bind(this));
63
+ map.on('moveend', this.moveEndEvent.bind(this));
64
+ map.getView().on('change:center', this.zoomEvent.bind(this));
65
+ map.getView().on('change:size', this.sizeEvent.bind(this));
66
+ map.on('pointerdrag', this.dragEvent.bind(this));
67
+ this.bindEvent();
68
+ }
69
+
70
+ /**
71
+ * @function MapvLayer.prototype.init
72
+ * @param {Object} options - 参数。
73
+ * @description 初始化参数。
74
+ */
75
+ init(options) {
76
+ var self = this;
77
+ self.options = options;
78
+ this.initDataRange(options);
79
+ this.context = self.options.context || '2d';
80
+ if (self.options.zIndex) {
81
+ this.canvasLayer && this.canvasLayer.setZIndex(self.options.zIndex);
82
+ }
83
+ this.initAnimator();
84
+ }
85
+
86
+ /**
87
+ * @function MapvLayer.prototype.clickEvent
88
+ * @param {Object} e - 事件参数。
89
+ * @description 点击事件。
90
+ */
91
+ clickEvent(e) {
92
+ var pixel = e.pixel;
93
+ super.clickEvent({
94
+ x: pixel[0] + this.offset[0],
95
+ y: pixel[1] + this.offset[1]
96
+ }, e);
97
+ }
98
+
99
+ /**
100
+ * @function MapvLayer.prototype.mousemoveEvent
101
+ * @param {Object} e - 事件参数。
102
+ * @description 鼠标移动事件。
103
+ */
104
+ mousemoveEvent(e) {
105
+ var pixel = e.pixel;
106
+ super.mousemoveEvent({
107
+ x: pixel[0],
108
+ y: pixel[1]
109
+ }, e);
110
+ }
111
+
112
+ /**
113
+ * @function MapvLayer.prototype.dragEvent
114
+ * @description 鼠标拖动事件。
115
+ */
116
+ dragEvent() {
117
+ this.clear(this.getContext());
118
+ }
119
+
120
+ /**
121
+ * @function MapvLayer.prototype.zoomEvent
122
+ * @description 缩放事件。
123
+ */
124
+ zoomEvent() {
125
+ this.clear(this.getContext());
126
+ }
127
+ /**
128
+ * @function MapvLayer.prototype.sizeEvent
129
+ * @description 地图窗口大小发生变化时触发。
130
+ */
131
+ sizeEvent() {
132
+ this.canvasLayer.resize();
133
+ }
134
+
135
+
136
+ /**
137
+ * @function MapvLayer.prototype.moveStartEvent
138
+ * @description 开始移动事件。
139
+ */
140
+ moveStartEvent() {
141
+ var animationOptions = this.options.animation;
142
+ if (this.isEnabledTime() && this.animator) {
143
+ this.steps.step = animationOptions.stepsRange.start;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * @function MapvLayer.prototype.moveEndEvent
149
+ * @description 结束移动事件。
150
+ */
151
+ moveEndEvent() {
152
+ this.canvasLayer.draw();
153
+ }
154
+
155
+ /**
156
+ * @function MapvLayer.prototype.bindEvent
157
+ * @description 绑定事件。
158
+ */
159
+ bindEvent() {
160
+ var me = this;
161
+ var map = me.map;
162
+ if (me.options.methods) {
163
+ if (me.options.methods.click) {
164
+ map.on('click', me.clickEvent);
165
+ }
166
+ if (me.options.methods.mousemove) {
167
+ me.pointerInteraction = new PointerInteraction();
168
+ me.pointerInteraction.handleMoveEvent_ = function (event) {
169
+ me.mousemoveEvent(event);
170
+ };
171
+ map.addInteraction(me.pointerInteraction);
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ * @function MapvLayer.prototype.unbindEvent
178
+ * @description 解除绑定事件。
179
+ */
180
+ unbindEvent() {
181
+ var map = this.map;
182
+ if (this.options.methods) {
183
+ if (this.options.methods.click) {
184
+ map.un('click', this.clickEvent);
185
+ }
186
+ if (this.options.methods.mousemove) {
187
+ map.removeInteraction(this.pointerInteraction)
188
+ }
189
+ }
190
+ }
191
+
192
+ /**
193
+ * @function MapvLayer.prototype.addData
194
+ * @description 添加数据。
195
+ * @param {Object} data - 待添加的数据。
196
+ * @param {Object} options - 待添加的数据信息。
197
+ */
198
+ addData(data, options) {
199
+ var _data = data;
200
+ if (data && data.get) {
201
+ _data = data.get();
202
+ }
203
+ this.dataSet.add(_data);
204
+ this.update({
205
+ options: options
206
+ });
207
+ }
208
+
209
+ /**
210
+ * @function MapvLayer.prototype.update
211
+ * @description 更新图层。
212
+ * @param {Object} opt - 待更新的数据。
213
+ * @param {Object} opt.data - mapv 数据集。
214
+ */
215
+ update(opt) {
216
+ var update = opt || {};
217
+ var _data = update.data;
218
+ if (_data && _data.get) {
219
+ _data = _data.get();
220
+ }
221
+ if (_data != undefined) {
222
+ this.dataSet.set(_data);
223
+ }
224
+ super.update({
225
+ options: update.options
226
+ });
227
+ }
228
+
229
+ draw() {
230
+ this.canvasLayer.draw();
231
+ }
232
+
233
+ /**
234
+ * @function MapvLayer.prototype.getData
235
+ * @description 获取数据。
236
+ */
237
+ getData() {
238
+ return this.dataSet;
239
+ }
240
+
241
+ /**
242
+ * @function MapvLayer.prototype.removeData
243
+ * @description 删除符合过滤条件的数据。
244
+ * @param {function} filter - 过滤条件。条件参数为数据项,返回值为 true,表示删除该元素;否则表示不删除。
245
+ */
246
+ removeData(filter) {
247
+ if (!this.dataSet) {
248
+ return;
249
+ }
250
+ var newData = this.dataSet.get({
251
+ filter: function (data) {
252
+ return (filter != null && typeof filter === "function") ? !filter(data) : true;
253
+ }
254
+ });
255
+ this.dataSet.set(newData);
256
+ this.update({
257
+ options: null
258
+ });
259
+ }
260
+
261
+ /**
262
+ * @function MapvLayer.prototype.clearData
263
+ * @description 清除数据。
264
+ */
265
+ clearData() {
266
+ this.dataSet && this.dataSet.clear();
267
+ this.update({
268
+ options: null
269
+ });
270
+ }
271
+
272
+ _canvasUpdate(time) {
273
+ if (!this.canvasLayer) {
274
+ return;
275
+ }
276
+ var self = this;
277
+ var animationOptions = self.options.animation;
278
+ var map = self.map;
279
+ var context = self.canvasLayer.canvas.getContext(self.context);
280
+ if (self.isEnabledTime()) {
281
+ if (time === undefined) {
282
+ self.clear(context);
283
+ return;
284
+ }
285
+ if (!self.context || self.context === '2d') {
286
+ context.save();
287
+ context.globalCompositeOperation = 'destination-out';
288
+ context.fillStyle = 'rgba(0, 0, 0, .1)';
289
+ context.fillRect(0, 0, context.canvas.width, context.canvas.height);
290
+ context.restore();
291
+ }
292
+ } else {
293
+ this.clear(context);
294
+ }
295
+ if (!self.context || self.context === '2d') {
296
+ for (var key in self.options) {
297
+ context[key] = self.options[key];
298
+ }
299
+ } else {
300
+ context.clear(context.COLOR_BUFFER_BIT);
301
+ }
302
+ var ext = map.getView().calculateExtent();
303
+ var topLeftPx = map.getPixelFromCoordinate([ext[0], ext[3]]);
304
+
305
+ self._mapCenter = map.getView().getCenter();
306
+ self._mapCenterPx = map.getPixelFromCoordinate(self._mapCenter);
307
+ self._reselutions = map.getView().getResolution();
308
+ self._rotation = -map.getView().getRotation();
309
+ var zoomUnit = self._reselutions;
310
+ var scaleRatio = 1;
311
+ if (this.context != '2d') {
312
+ var global$2 = typeof window === 'undefined' ? {} : window;
313
+ var devicePixelRatio = global$2.devicePixelRatio || 1;
314
+ scaleRatio = devicePixelRatio;
315
+ }
316
+ var dataGetOptions = {
317
+ transferCoordinate: function (coordinate) {
318
+ var x = (coordinate[0] - self._mapCenter[0]) / self._reselutions,
319
+ y = (self._mapCenter[1] - coordinate[1]) / self._reselutions;
320
+ var scaledP = [x + self._mapCenterPx[0], y + self._mapCenterPx[1]];
321
+ scaledP = scale(scaledP, self._mapCenterPx, 1);
322
+ /*//有旋转量的时候处理旋转
323
+ if (self._rotation !== 0) {
324
+ var rotatedP = rotate(scaledP, self._rotation, self._mapCenterPx);
325
+ return [rotatedP[0] + self.offset[0], rotatedP[1] + self.offset[1]];
326
+ }
327
+ //处理放大或缩小级别*/
328
+ return [(scaledP[0] + self.offset[0]) * scaleRatio, (scaledP[1] + self.offset[1]) * scaleRatio];
329
+ }
330
+ };
331
+
332
+ // //获取某像素坐标点pixelP绕中心center逆时针旋转rotation弧度后的像素点坐标。
333
+ // function rotate(pixelP, rotation, center) {
334
+ // var x = Math.cos(rotation) * (pixelP[0] - center[0]) - Math.sin(rotation) * (pixelP[1] - center[1]) + center[0];
335
+ // var y = Math.sin(rotation) * (pixelP[0] - center[0]) + Math.cos(rotation) * (pixelP[1] - center[1]) + center[1];
336
+ // return [x, y];
337
+ // }
338
+
339
+ //获取某像素坐标点pixelP相对于中心center进行缩放scaleRatio倍后的像素点坐标。
340
+ function scale(pixelP, center, scaleRatio) {
341
+ var x = (pixelP[0] - center[0]) * scaleRatio + center[0];
342
+ var y = (pixelP[1] - center[1]) * scaleRatio + center[1];
343
+ return [x, y];
344
+ }
345
+
346
+ if (time !== undefined) {
347
+ dataGetOptions.filter = function (item) {
348
+ var trails = animationOptions.trails || 10;
349
+ return (time && item.time > (time - trails) && item.time < time);
350
+ };
351
+ }
352
+ if (self.isEnabledTime() && !self.notFirst) {
353
+ self.canvasLayer.resize(self.mapWidth, self.mapHeight);
354
+ self.notFirst = true;
355
+ }
356
+ var data = self.dataSet.get(dataGetOptions);
357
+ self.processData(data);
358
+ // 兼容unit为'm'的情况
359
+ if (self.options.unit === 'm') {
360
+ if (self.options.size) {
361
+ self.options._size = self.options.size / zoomUnit;
362
+ }
363
+ if (self.options.width) {
364
+ self.options._width = self.options.width / zoomUnit;
365
+ }
366
+ if (self.options.height) {
367
+ self.options._height = self.options.height / zoomUnit;
368
+ }
369
+ } else {
370
+ self.options._size = self.options.size;
371
+ self.options._height = self.options.height;
372
+ self.options._width = self.options.width;
373
+ }
374
+
375
+ var pixel = map.getPixelFromCoordinate([0, 0]);
376
+ pixel = [pixel[0] - topLeftPx[0], pixel[1] - topLeftPx[1]];
377
+ this.drawContext(context, data, self.options, {
378
+ x: pixel[0],
379
+ y: pixel[1]
380
+ });
381
+ if (self.isEnabledTime()) {
382
+ this.source.changed();
383
+ }
384
+ self.options.updateCallback && self.options.updateCallback(time);
385
+ }
386
+
387
+
388
+ isEnabledTime() {
389
+ var animationOptions = this.options.animation;
390
+ return animationOptions && !(animationOptions.enabled === false);
391
+ }
392
+
393
+
394
+ argCheck(options) {
395
+ if (options.draw === 'heatmap') {
396
+ if (options.strokeStyle) {
397
+ console.warn('[heatmap] options.strokeStyle is discard, pleause use options.strength [eg: options.strength = 0.1]');
398
+ }
399
+ }
400
+ }
401
+
402
+ getContext() {
403
+ return this.canvasLayer.canvas.getContext(this.context);
404
+ }
405
+
406
+
407
+ clear(context) {
408
+ context && context.clearRect && context.clearRect(0, 0, context.canvas.width, context.canvas.height);
409
+ }
410
+ }
@@ -0,0 +1,5 @@
1
+ /* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2
+ * This program are made available under the terms of the Apache License, Version 2.0
3
+ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
+ export {MapvCanvasLayer} from './MapvCanvasLayer';
5
+ export {MapvLayer} from './MapvLayer';
@@ -0,0 +1,275 @@
1
+ /* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2
+ * This program are made available under the terms of the Apache License, Version 2.0
3
+ * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
+ import { Bounds } from '@supermapgis/iclient-common/commontypes/Bounds';
5
+ import { ShapeFactory } from '@supermapgis/iclient-common/overlay/feature/ShapeFactory';
6
+ import { ThemeVector as Vector} from '@supermapgis/iclient-common/overlay/ThemeVector';
7
+ import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
8
+ import {Theme} from './Theme';
9
+
10
+ /**
11
+ * @class GeoFeature
12
+ * @browsernamespace ol.source
13
+ * @category Visualization Theme
14
+ * @classdesc 地理几何专题要素型专题图层基类。
15
+ * @param {string} name - 图层名称。
16
+ * @param {Object} opt_options - 参数。
17
+ * @param {ol.Map} opt_options.map - 当前 OpenLayers Map 对象。
18
+ * @param {string} [opt_options.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。
19
+ * @param {number} [opt_options.opacity=1] - 图层透明度。
20
+ * @param {string} [opt_options.logo] - Logo(openLayers 5.0.0 及更高版本不再支持此参数)。
21
+ * @param {ol.proj.Projection} [opt_options.projection] - 投影信息。
22
+ * @param {number} [opt_options.ratio=1.5] - 视图比,1 表示画布是地图视口的大小,2 表示地图视口的宽度和高度的两倍,依此类推。必须是 1 或更高。
23
+ * @param {Array} [opt_options.resolutions] - 分辨率数组。
24
+ * @param {ol.source.State} [opt_options.state] - 资源状态。
25
+ * @param {Object} [opt_options.style] - 专题图样式。
26
+ * @param {Object} [opt_options.styleGroups] - 各专题类型样式组。
27
+ * @param {boolean} [opt_options.isHoverAble=false] - 是否开启 hover 事件。
28
+ * @param {Object} [opt_options.highlightStyle] - 开启 hover 事件后,触发的样式风格。
29
+ * @param {(string|Object)} [opt_options.attributions='Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>'] - 版权信息。
30
+ * @extends {Theme}
31
+ * @usage
32
+ */
33
+
34
+ export class GeoFeature extends Theme {
35
+
36
+ constructor(name, opt_options) {
37
+ super(name, opt_options);
38
+ this.cache = opt_options.cache || {};
39
+ this.cacheFields = opt_options.cacheFields || [];
40
+ this.style = opt_options.style || {};
41
+ this.maxCacheCount = opt_options.maxCacheCount || 0;
42
+ this.isCustomSetMaxCacheCount = opt_options.isCustomSetMaxCacheCount === undefined ? false : opt_options.isCustomSetMaxCacheCount;
43
+ this.nodesClipPixel = opt_options.nodesClipPixel || 2;
44
+ this.isHoverAble = opt_options.isHoverAble === undefined ? false : opt_options.isHoverAble;
45
+ this.isMultiHover = opt_options.isMultiHover === undefined ? false : opt_options.isMultiHover;
46
+ this.isClickAble = opt_options.isClickAble === undefined ? true : opt_options.isClickAble;
47
+ this.highlightStyle = opt_options.highlightStyle || null;
48
+ this.isAllowFeatureStyle = opt_options.isAllowFeatureStyle === undefined ? false : opt_options.isAllowFeatureStyle;
49
+ }
50
+
51
+ /**
52
+ * @function GeoFeature.prototype.destroy
53
+ * @description 释放资源,将引用资源的属性置空。
54
+ */
55
+ destroy() {
56
+ this.maxCacheCount = null;
57
+ this.isCustomSetMaxCacheCount = null;
58
+ this.nodesClipPixel = null;
59
+ this.isHoverAble = null;
60
+ this.isMultiHover = null;
61
+ this.isClickAble = null;
62
+ this.cache = null;
63
+ this.cacheFields = null;
64
+ this.style = null;
65
+ this.highlightStyle = null;
66
+ this.isAllowFeatureStyle = null;
67
+ }
68
+
69
+ /**
70
+ * @function GeoFeature.prototype.addFeatures
71
+ * @description 添加要素。
72
+ * @param {(Array.<ThemeFeature>|Array.<GeoJSONObject>|Array.<ol.Feature>|ThemeFeature|GeoJSONObject|ol.Feature)} features - 要素对象。
73
+ */
74
+ addFeatures(features) {
75
+ this.dispatchEvent({type: 'beforefeaturesadded', value: {features: features}});
76
+ //转换 features 形式
77
+ this.features = this.toiClientFeature(features);
78
+ if (!this.isCustomSetMaxCacheCount) {
79
+ this.maxCacheCount = this.features.length * 5;
80
+ }
81
+ //绘制专题要素
82
+ if (this.renderer) {
83
+ this.changed();
84
+ }
85
+ }
86
+
87
+ /**
88
+ * @function GeoFeature.prototype.removeFeatures
89
+ * @description 从专题图中删除 feature。这个函数删除所有传递进来的矢量要素。
90
+ * @param {(Array.<FeatureVector>|FeatureVector|Function)} features - 待删除的要素对象或用于过滤的回调函数。
91
+ */
92
+ removeFeatures(features) { // eslint-disable-line no-unused-vars
93
+ this.clearCache();
94
+ Theme.prototype.removeFeatures.call(this, features);
95
+ }
96
+
97
+ /**
98
+ * @function GeoFeature.prototype.removeAllFeatures
99
+ * @description 清除当前图层所有的矢量要素。
100
+ */
101
+ removeAllFeatures() {
102
+ this.clearCache();
103
+ Theme.prototype.removeAllFeatures.apply(this, arguments);
104
+ }
105
+
106
+ /**
107
+ * @function GeoFeature.prototype.redrawThematicFeatures
108
+ * @description 重绘所有专题要素。
109
+ * @param {Object} extent - 视图范围数据。
110
+ */
111
+ redrawThematicFeatures(extent) {
112
+ //获取高亮专题要素对应的用户 id
113
+ var hoverone = this.renderer.getHoverOne();
114
+ var hoverFid = null;
115
+ if (hoverone && hoverone.refDataID) {
116
+ hoverFid = hoverone.refDataID;
117
+ }
118
+ //清除当前所有可视元素
119
+ this.renderer.clearAll();
120
+
121
+ var features = this.features;
122
+ var cache = this.cache;
123
+ var cacheFields = this.cacheFields;
124
+ var cmZoom = this.map.getView().getZoom();
125
+
126
+ var maxCC = this.maxCacheCount;
127
+
128
+ for (var i = 0, len = features.length; i < len; i++) {
129
+ var feature = features[i];
130
+ if (!feature.geometry) {
131
+ continue;
132
+ }
133
+ var feaBounds = feature.geometry.getBounds();
134
+
135
+ //剔除当前视图(地理)范围以外的数据
136
+ if (extent) {
137
+ var bounds = new Bounds(extent[0], extent[1], extent[2], extent[3]);
138
+ if (!bounds.intersectsBounds(feaBounds)) {
139
+ continue;
140
+ }
141
+ }
142
+
143
+ //缓存字段
144
+ var fields = feature.id + "_zoom_" + cmZoom.toString();
145
+
146
+ var thematicFeature;
147
+
148
+ //判断专题要素缓存是否存在
149
+ if (cache[fields]) {
150
+ cache[fields].updateAndAddShapes();
151
+ } else {
152
+ //如果专题要素缓存不存在,创建专题要素
153
+ thematicFeature = this.createThematicFeature(features[i]);
154
+
155
+ //检查 thematicFeature 是否有可视化图形
156
+ if (thematicFeature.getShapesCount() < 1) {
157
+ continue;
158
+ }
159
+
160
+ //加入缓存
161
+ cache[fields] = thematicFeature;
162
+ cacheFields.push(fields);
163
+
164
+ //缓存数量限制
165
+ if (cacheFields.length > maxCC) {
166
+ var fieldsTemp = cacheFields[0];
167
+ cacheFields.splice(0, 1);
168
+ delete cache[fieldsTemp];
169
+ }
170
+ }
171
+
172
+ }
173
+ this.renderer.render();
174
+
175
+ //地图漫游后,重新高亮图形
176
+ if (hoverFid && this.isHoverAble && this.isMultiHover) {
177
+ var hShapes = this.getShapesByFeatureID(hoverFid);
178
+ this.renderer.updateHoverShapes(hShapes);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * @function GeoFeature.prototype.createThematicFeature
184
+ * @description 创建专题要素。
185
+ * @param {Object} feature - 要素对象。
186
+ * @returns {Array.<FeatureVector>} 返回矢量要素。
187
+ */
188
+ createThematicFeature(feature) {
189
+ var style = CommonUtil.copyAttributesWithClip(this.style);
190
+ if (feature.style && this.isAllowFeatureStyle === true) {
191
+ style = CommonUtil.copyAttributesWithClip(feature.style);
192
+ }
193
+ //创建专题要素时的可选参数
194
+ var options = {};
195
+ options.nodesClipPixel = this.nodesClipPixel;
196
+ options.isHoverAble = this.isHoverAble;
197
+ options.isMultiHover = this.isMultiHover;
198
+ options.isClickAble = this.isClickAble;
199
+ options.highlightStyle = ShapeFactory.transformStyle(this.highlightStyle);
200
+ //将数据转为专题要素(Vector)
201
+ var thematicFeature = new Vector(feature, this, ShapeFactory.transformStyle(style), options);
202
+ //直接添加图形到渲染器
203
+ for (var m = 0; m < thematicFeature.shapes.length; m++) {
204
+ this.renderer.addShape(thematicFeature.shapes[m]);
205
+ }
206
+ return thematicFeature;
207
+ }
208
+
209
+ canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) { // eslint-disable-line no-unused-vars
210
+ return Theme.prototype.canvasFunctionInternal_.apply(this, arguments);
211
+ }
212
+
213
+ /**
214
+ * @function GeoFeature.prototype.clearCache
215
+ * @description 清除缓存。
216
+ */
217
+ clearCache() {
218
+ this.cache = {};
219
+ this.cacheFields = [];
220
+ }
221
+
222
+ /**
223
+ * @function GeoFeature.prototype.clear
224
+ * @description 清除的内容包括数据(features)、专题要素、缓存。
225
+ */
226
+ clear() {
227
+ this.renderer.clearAll();
228
+ this.renderer.refresh();
229
+ this.removeAllFeatures();
230
+ this.clearCache();
231
+ }
232
+
233
+ /**
234
+ * @function GeoFeature.prototype.getCacheCount
235
+ * @description 获取当前缓存数量。
236
+ * @returns {number} 返回当前缓存数量。
237
+ */
238
+ getCacheCount() {
239
+ return this.cacheFields.length;
240
+ }
241
+
242
+ /**
243
+ * @function GeoFeature.prototype.setMaxCacheCount
244
+ * @param {number} cacheCount - 缓存总数。
245
+ * @description 设置最大缓存条数。
246
+ */
247
+ setMaxCacheCount(cacheCount) {
248
+ if (!isNaN(cacheCount)) {
249
+ this.maxCacheCount = cacheCount;
250
+ this.isCustomSetMaxCacheCount = true;
251
+ }
252
+ }
253
+
254
+ /**
255
+ * @function GeoFeature.prototype.getShapesByFeatureID
256
+ * @param {number} featureID - 要素 ID。
257
+ * @description 通过 FeatureID 获取 feature 关联的所有图形。如果不传入此参数,函数将返回所有图形。
258
+ * @returns {Array} 返回图形数组。
259
+ */
260
+ getShapesByFeatureID(featureID) {
261
+ var list = [];
262
+ var shapeList = this.renderer.getAllShapes();
263
+ if (!featureID) {
264
+ return shapeList
265
+ }
266
+ for (var i = 0, len = shapeList.length; i < len; i++) {
267
+ var si = shapeList[i];
268
+ if (si.refDataID && featureID === si.refDataID) {
269
+ list.push(si);
270
+ }
271
+ }
272
+ return list;
273
+ }
274
+
275
+ }