@supermapgis/iclient-ol 11.2.0

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 +97 -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 +500 -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 +124963 -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 +142946 -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 +150 -0
  23. package/mapping/SuperMapCloud.js +56 -0
  24. package/mapping/Tianditu.js +152 -0
  25. package/mapping/TileSuperMapRest.js +374 -0
  26. package/mapping/WebMap.js +5485 -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 +100 -0
  35. package/overlay/Graph.js +439 -0
  36. package/overlay/GraphMap.js +140 -0
  37. package/overlay/Graphic.js +588 -0
  38. package/overlay/HeatMap.js +450 -0
  39. package/overlay/Label.js +966 -0
  40. package/overlay/Mapv.js +149 -0
  41. package/overlay/Range.js +129 -0
  42. package/overlay/RankSymbol.js +94 -0
  43. package/overlay/Turf.js +299 -0
  44. package/overlay/Unique.js +124 -0
  45. package/overlay/VectorTileSuperMapRest.js +501 -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 +64 -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 +413 -0
  55. package/overlay/mapv/index.js +5 -0
  56. package/overlay/theme/GeoFeature.js +275 -0
  57. package/overlay/theme/Theme.js +587 -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 +377 -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 +30 -0
  67. package/services/AddressMatchService.js +60 -0
  68. package/services/ChartService.js +97 -0
  69. package/services/DataFlowService.js +119 -0
  70. package/services/DatasetService.js +104 -0
  71. package/services/DatasourceService.js +76 -0
  72. package/services/FeatureService.js +260 -0
  73. package/services/FieldService.js +53 -0
  74. package/services/GeoprocessingService.js +157 -0
  75. package/services/GridCellInfosService.js +53 -0
  76. package/services/ImageCollectionService.js +93 -0
  77. package/services/ImageService.js +70 -0
  78. package/services/KnowledgeGraphService.js +96 -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 +93 -0
  83. package/services/NetworkAnalystService.js +268 -0
  84. package/services/ProcessingService.js +507 -0
  85. package/services/QueryService.js +116 -0
  86. package/services/ServiceBase.js +26 -0
  87. package/services/SpatialAnalystService.js +466 -0
  88. package/services/ThemeService.js +50 -0
  89. package/services/TrafficTransferAnalystService.js +93 -0
  90. package/services/WebPrintingJobService.js +112 -0
  91. package/services/index.js +27 -0
@@ -0,0 +1,587 @@
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 {Util} from '../../core/Util';
5
+ import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
6
+ import { LevelRenderer } from '@supermapgis/iclient-common/overlay/levelRenderer/LevelRenderer';
7
+ import { ServerFeature } from '@supermapgis/iclient-common/iServer/ServerFeature';
8
+ import { GeoText } from '@supermapgis/iclient-common/commontypes/geometry/GeoText';
9
+ import { GeoJSON as GeoJSONFormat } from '@supermapgis/iclient-common/format/GeoJSON';
10
+ import { Point as GeometryPoint } from '@supermapgis/iclient-common/commontypes/geometry/Point';
11
+ import { Vector as FeatureVector } from '@supermapgis/iclient-common/commontypes/Vector';
12
+ import { LonLat } from '@supermapgis/iclient-common/commontypes/LonLat';
13
+ import {ThemeFeature} from './ThemeFeature';
14
+ import ImageCanvasSource from 'ol/source/ImageCanvas';
15
+ import Feature from 'ol/Feature';
16
+ import GeoJSON from 'ol/format/GeoJSON';
17
+
18
+ /**
19
+ * @class Theme
20
+ * @browsernamespace ol.source
21
+ * @category Visualization Theme
22
+ * @classdesc 专题图基类。地图学中将突出而深入地表示一种或几种要素或现象,即集中表示一个主题内容的地图称为专题地图。
23
+ * 在 SuperMap 中,专题图是地图图层的符号化显示,即用各种图形渲染风格(大小,颜色,线型,填充等)来图形化地表现专题要素的某方面特征。
24
+ * 调用建议:使用其子类实现该类。
25
+ * @modulecategory Overlay
26
+ * @param {string} name - 专题图图层名称。
27
+ * @param {Object} opt_option - 参数。
28
+ * @param {ol.Map} opt_option.map - 当前 OpenLayers 的地图对象。
29
+ * @param {string} [opt_option.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。
30
+ * @param {number} [opt_option.opacity=1] - 图层不透明度。
31
+ * @param {string} [opt_option.logo] - Logo(OpenLayers 5.0.0 及更高版本不再支持此参数)。
32
+ * @param {ol.proj.Projection} [opt_option.projection] - 投影信息。
33
+ * @param {number} [opt_option.ratio=1.5] - 视图比,1 表示画布是地图视口的大小,2 表示地图视口的宽度和高度的两倍,依此类推。必须是 1 或更高。
34
+ * @param {Array} [opt_option.resolutions] - 分辨率数组。
35
+ * @param {ol.source.State} [opt_option.state] - 资源状态。
36
+ * @param {(string|Object)} [opt_option.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>'] - 版权描述信息。
37
+ * @extends {ol.source.ImageCanvas}
38
+ * @usage
39
+ */
40
+ export class Theme extends ImageCanvasSource {
41
+
42
+ constructor(name, opt_options) {
43
+ var options = opt_options ? opt_options : {};
44
+ super({
45
+ attributions: options.attributions || "Map Data <span>© SuperMap iServer</span> with <span>© SuperMap iClient</span>",
46
+ canvasFunction: canvasFunctionInternal_,
47
+ logo: Util.getOlVersion() === '4' ? options.logo : null,
48
+ projection: options.projection,
49
+ ratio: options.ratio,
50
+ resolutions: options.resolutions,
51
+ state: options.state
52
+ });
53
+ /**
54
+ * @function Theme.prototype.on
55
+ * @description 添加专题要素事件监听。支持的事件包括: click、mousedown、mousemove、mouseout、mouseover、mouseup。
56
+ * @param {string} event - 事件名称。
57
+ * @param {RequestCallback} callback - 事件回调函数。
58
+ */
59
+ this.on = this.onInternal;
60
+ this.id = options.id ? options.id : CommonUtil.createUniqueID("themeLayer_");
61
+
62
+ function canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) { // eslint-disable-line no-unused-vars
63
+ var mapWidth = size[0] * pixelRatio;
64
+ var mapHeight = size[1] * pixelRatio;
65
+ if (!this.context) {
66
+ this.context = Util.createCanvasContext2D(mapWidth, mapHeight);
67
+ }
68
+ if (!this.features) {
69
+ return this.context.canvas;
70
+ }
71
+ this.pixelRatio = pixelRatio;
72
+
73
+ var width = this.map.getSize()[0] * pixelRatio;
74
+ var height = this.map.getSize()[1] * pixelRatio;
75
+ this.offset = [(mapWidth - width) / 2 / pixelRatio, (mapHeight - height) / 2 / pixelRatio];
76
+ if (!this.notFirst) {
77
+ this.redrawThematicFeatures(extent);
78
+ this.notFirst = true;
79
+ }
80
+ this.div.id = this.id;
81
+ this.div.className = "themeLayer";
82
+ this.div.style.width = mapWidth + "px";
83
+ this.div.style.height = mapHeight + "px";
84
+ this.map.getViewport().appendChild(this.div);
85
+ this.renderer.resize();
86
+ this.map.getViewport().removeChild(this.div);
87
+ this.themeCanvas = this.renderer.painter.root.getElementsByTagName('canvas')[0];
88
+ this.themeCanvas.width = mapWidth;
89
+ this.themeCanvas.height = mapHeight;
90
+ this.themeCanvas.style.width = mapWidth + "px";
91
+ this.themeCanvas.style.height = mapHeight + "px";
92
+ this.themeCanvas.getContext('2d').clearRect(0, 0, mapWidth, mapHeight);
93
+
94
+ var highLightContext = this.renderer.painter._layers.hover.ctx;
95
+ var highlightCanvas = highLightContext.canvas;
96
+ var copyHighLightContext = Util.createCanvasContext2D(mapWidth, mapHeight);
97
+ copyHighLightContext.drawImage(highlightCanvas, 0, 0, highlightCanvas.width, highlightCanvas.height, 0, 0, mapWidth, mapHeight);
98
+
99
+ this.redrawThematicFeatures(extent);
100
+ var canvas = this.context.canvas;
101
+ this.context.clearRect(0, 0, canvas.width, canvas.height);
102
+ canvas.width = mapWidth;
103
+ canvas.height = mapHeight;
104
+ canvas.style.width = mapWidth + "px";
105
+ canvas.style.height = mapHeight + "px";
106
+ this.context.drawImage(this.themeCanvas, 0, 0);
107
+ this.context.drawImage(copyHighLightContext.canvas, 0, 0);
108
+ return this.context.canvas;
109
+ }
110
+
111
+ this.canvasFunctionInternal_ = canvasFunctionInternal_;
112
+ this.EVENT_TYPES = ["loadstart", "loadend", "loadcancel",
113
+ "visibilitychanged", "move", "moveend", "added", "removed",
114
+ "tileloaded", "beforefeaturesadded", "featuresadded", "featuresremoved"];
115
+ this.features = [];
116
+ this.TFEvents = options.TFEvents || [];
117
+ this.map = options.map;
118
+ var size = this.map.getSize();
119
+ this.div = document.createElement('div');
120
+ this.map.getViewport().appendChild(this.div);
121
+ this.div.style.width = size[0] + "px";
122
+ this.div.style.height = size[1] + "px";
123
+ this.setOpacity(options.opacity);
124
+ this.levelRenderer = new LevelRenderer();
125
+ this.movingOffset = [0, 0];
126
+ this.renderer = this.levelRenderer.init(this.div);
127
+ this.map.getViewport().removeChild(this.div);
128
+ this.renderer.clear();
129
+ //处理用户预先(在图层添加到 map 前)监听的事件
130
+ this.addTFEvents();
131
+ }
132
+
133
+ /**
134
+ * @function Theme.prototype.destroy
135
+ * @description 释放资源,将引用资源的属性置空。
136
+ */
137
+ destroy() {
138
+ this.EVENT_TYPES = null;
139
+ this.isBaseLayer = null;
140
+ this.TFEvents = null;
141
+ this.destroyFeatures();
142
+ this.features = null;
143
+ if (this.renderer) {
144
+ this.renderer.dispose();
145
+ }
146
+ this.renderer = null;
147
+ this.levelRenderer = null;
148
+ this.movingOffset = null;
149
+ this.currentMousePosition = null;
150
+ }
151
+
152
+ /**
153
+ * @function Theme.prototype.destroyFeatures
154
+ * @description 销毁要素。
155
+ * @param {Array.<FeatureVector>|FeatureVector} features - 将被销毁的要素。
156
+ */
157
+ destroyFeatures(features) {
158
+ var all = (features == undefined);
159
+ if (all) {
160
+ features = this.features;
161
+ }
162
+ if (features) {
163
+ this.removeFeatures(features);
164
+ if (!Array.isArray(features)) {
165
+ features = [features];
166
+ }
167
+ for (var i = features.length - 1; i >= 0; i--) {
168
+ features[i].destroy();
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ * @function Theme.prototype.setOpacity
175
+ * @description 设置图层的不透明度,取值范围:[0-1]。
176
+ * @param {number} opacity - 不透明度。
177
+ */
178
+ setOpacity(opacity) {
179
+ if (opacity !== this.opacity) {
180
+ this.opacity = opacity;
181
+ var element = this.div;
182
+ CommonUtil.modifyDOMElement(element, null, null, null,
183
+ null, null, null, opacity);
184
+
185
+ if (this.map !== null) {
186
+ this.dispatchEvent({type: 'changelayer', value: {layer: this, property: "opacity"}});
187
+ }
188
+ }
189
+ }
190
+
191
+ /**
192
+ * @function Theme.prototype.addFeatures
193
+ * @param {(Array.<ThemeFeature>|Array.<GeoJSONObject>|Array.<ol.Feature>|ThemeFeature|GeoJSONObject|ol.Feature)} features - 待添加要素。
194
+ * @description 抽象方法,可实例化子类必须实现此方法。向专题图图层中添加数据,
195
+ * 专题图仅接收 FeatureVector 类型数据,
196
+ * feature 将储存于 features 属性中,其存储形式为数组。
197
+ */
198
+ addFeatures(features) { // eslint-disable-line no-unused-vars
199
+
200
+ }
201
+
202
+ /**
203
+ * @function Theme.prototype.removeFeatures
204
+ * @param {(Array.<FeatureVector>|FeatureVector|Function)} features - 要删除要素的数组或用来过滤的回调函数。
205
+ * @description 从专题图中删除要素。这个函数删除所有传递进来的矢量要素。
206
+ * 参数中的要素数组中的每一项,必须是已经添加到当前图层中的要素,
207
+ * 如果无法确定要素数组,则可以调用 removeAllFeatures 来删除所有要素。
208
+ * 如果要删除的要素数组中的元素特别多,推荐使用 removeAllFeatures,
209
+ * 删除所有要素后再重新添加。这样效率会更高。
210
+ */
211
+ removeFeatures(features) {
212
+ var me = this;
213
+ if (!features) {
214
+ return;
215
+ }
216
+ if (features === me.features) {
217
+ return me.removeAllFeatures();
218
+ }
219
+ if (!CommonUtil.isArray(features) && !(typeof features === 'function')) {
220
+ features = [features];
221
+ }
222
+
223
+ var featuresFailRemoved = [];
224
+
225
+ for (var i = 0; i < me.features.length; i++) {
226
+ var feature = me.features[i];
227
+
228
+ //如果我们传入的feature在features数组中没有的话,则不进行删除,
229
+ //并将其放入未删除的数组中。
230
+ if (features && typeof features === 'function') {
231
+ if (features(feature)) {
232
+ me.features.splice(i--, 1);
233
+ }
234
+ } else {
235
+ var findex = CommonUtil.indexOf(features, feature);
236
+ if (findex === -1) {
237
+ featuresFailRemoved.push(feature);
238
+ } else {
239
+ me.features.splice(i--, 1);
240
+ }
241
+ }
242
+ }
243
+ var drawFeatures = [];
244
+ for (var hex = 0, len = this.features.length; hex < len; hex++) {
245
+ feature = this.features[hex];
246
+ drawFeatures.push(feature);
247
+ }
248
+ this.features = [];
249
+ this.addFeatures(drawFeatures);
250
+ //绘制专题要素
251
+ if (this.renderer) {
252
+ this.redrawThematicFeatures(this.map.getView().calculateExtent());
253
+ }
254
+ var succeed = featuresFailRemoved.length == 0 ? true : false;
255
+ this.dispatchEvent({type: "featuresremoved", value: {features: featuresFailRemoved, succeed: succeed}});
256
+ }
257
+
258
+ /**
259
+ * @function Theme.prototype.removeAllFeatures
260
+ * @description 清除当前图层所有的矢量要素。
261
+ */
262
+ removeAllFeatures() {
263
+ if (this.renderer) {
264
+ this.renderer.clear();
265
+ }
266
+ this.features = [];
267
+ this.dispatchEvent({type: 'featuresremoved', value: {features: [], succeed: true}});
268
+ }
269
+
270
+ /**
271
+ * @function Theme.prototype.getFeatures
272
+ * @description 查看当前图层中的有效数据。
273
+ * @param {Function} [filter] - 根据条件过滤要素的回调函数。
274
+ * @returns {Array.<FeatureVector>} 用户加入图层的有效数据。
275
+ */
276
+ getFeatures(filter) {
277
+ var len = this.features.length;
278
+ var clonedFeatures = [];
279
+ for (var i = 0; i < len; ++i) {
280
+ if (!filter || (filter && typeof filter === 'function' && filter(this.features[i]))) {
281
+ clonedFeatures.push(this.features[i]);
282
+ }
283
+ }
284
+ return clonedFeatures;
285
+ }
286
+
287
+ /**
288
+ * @function Theme.prototype.getFeatureBy
289
+ * @description 在专题图的要素数组 features 里面遍历每一个 feature,当 feature[property] === value 时,
290
+ * 返回此 feature(并且只返回第一个)。
291
+ * @param {string} property - 要素的某个属性名称。
292
+ * @param {string} value - property 所对应的值。
293
+ * @returns {FeatureVector} 第一个匹配属性和值的矢量要素。
294
+ */
295
+ getFeatureBy(property, value) {
296
+ var feature = null;
297
+ for (var id in this.features) {
298
+ if (this.features[id][property] === value) {
299
+ feature = this.features[id];
300
+ //feature = this.features[id].clone();
301
+ break;
302
+ }
303
+ }
304
+ return feature;
305
+ }
306
+
307
+ /**
308
+ * @function Theme.prototype.getFeatureById
309
+ * @description 通过给定一个 ID,返回对应的矢量要素。
310
+ * @param {string} featureId - 矢量要素的属性 ID。
311
+ * @returns {FeatureVector} 对应 ID 的要素,如果不存在则返回 null。
312
+ */
313
+ getFeatureById(featureId) {
314
+ return this.getFeatureBy('id', featureId);
315
+ }
316
+
317
+ /**
318
+ * @function Theme.prototype.getFeaturesByAttribute
319
+ * @description 通过给定一个属性的 key 值和 value 值,返回所有匹配的要素数组。
320
+ * @param {string} attrName - 属性的 key 值。
321
+ * @param {string} attrValue - 属性的 value 值。
322
+ * @returns {Array.<FeatureVector>} 一个匹配的要素数组。
323
+ */
324
+ getFeaturesByAttribute(attrName, attrValue) {
325
+ var feature,
326
+ foundFeatures = [];
327
+ for (var id in this.features) {
328
+ feature = this.features[id];
329
+ //feature = this.features[id].clone();
330
+ if (feature && feature.attributes) {
331
+ if (feature.attributes[attrName] === attrValue) {
332
+ foundFeatures.push(feature);
333
+ }
334
+ }
335
+ }
336
+ return foundFeatures;
337
+ }
338
+
339
+ /**
340
+ * @function Theme.prototype.redrawThematicFeatures
341
+ * @description 抽象方法,可实例化子类必须实现此方法。重绘专题要素。
342
+ * @param {Array} extent - 当前级别下计算出的地图范围。
343
+ */
344
+ redrawThematicFeatures(extent) { //eslint-disable-line no-unused-vars
345
+ }
346
+
347
+ /**
348
+ * @private
349
+ * @function Theme.prototype.onInternal
350
+ * @description 添加专题要素事件监听。支持的事件包括: click、mousedown、mousemove、mouseout、mouseover、mouseup。
351
+ * @param {string} event - 事件名称。
352
+ * @param {RequestCallback} callback - 事件回调函数。
353
+ */
354
+ onInternal(event, callback) {
355
+ var cb = callback;
356
+ if (!this.renderer) {
357
+ var evn = [];
358
+ evn.push(event);
359
+ evn.push(cb);
360
+ this.TFEvents.push(evn);
361
+ } else {
362
+ this.renderer.on(event, cb);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * @function Theme.prototype.fire
368
+ * @description 添加专题要素事件监听。
369
+ * @param {string} type - 事件类型。
370
+ * @param {string} event - 事件名称。
371
+ */
372
+ fire(type, event) {
373
+ if (!this.offset) {
374
+ return;
375
+ }
376
+ event = event.originalEvent;
377
+ var x = this.getX(event);
378
+ var y = this.getY(event);
379
+ var rotation = -this.map.getView().getRotation();
380
+ var center = this.map.getPixelFromCoordinate(this.map.getView().getCenter());
381
+ var scaledP = this.scale([x, y], center, this.pixelRatio);
382
+ var rotatedP = this.rotate(scaledP, rotation, center);
383
+ var resultP = [rotatedP[0] + this.offset[0], rotatedP[1] + this.offset[1]];
384
+ var offsetEvent = document.createEvent('Event');
385
+ offsetEvent.initEvent('pointermove', true, true);
386
+ offsetEvent.offsetX = resultP[0];
387
+ offsetEvent.offsetY = resultP[1];
388
+ offsetEvent.layerX = resultP[0];
389
+ offsetEvent.layerY = resultP[1];
390
+ offsetEvent.clientX = resultP[0];
391
+ offsetEvent.clientY = resultP[1];
392
+ offsetEvent.x = x;
393
+ offsetEvent.y = y;
394
+ if (type === 'click') {
395
+ this.renderer.handler._clickHandler(offsetEvent);
396
+ }
397
+ if (type === 'dblclick') {
398
+ this.renderer.handler._dblclickHandler(offsetEvent);
399
+ }
400
+ if (type === 'onmousewheel') {
401
+ this.renderer.handler._mousewheelHandler(offsetEvent);
402
+ }
403
+ if (type === 'mousemove') {
404
+ this.renderer.handler._mousemoveHandler(offsetEvent);
405
+ this.changed();
406
+ }
407
+ if (type === 'onmouseout') {
408
+ this.renderer.handler._mouseoutHandler(offsetEvent);
409
+ }
410
+ if (type === 'onmousedown') {
411
+ this.renderer.handler._mousedownHandler(offsetEvent);
412
+ }
413
+ if (type === 'onmouseup') {
414
+ this.renderer.handler._mouseupHandler(offsetEvent);
415
+ }
416
+
417
+ }
418
+
419
+ getX(e) {
420
+ return typeof e.zrenderX != 'undefined' && e.zrenderX
421
+ || typeof e.offsetX != 'undefined' && e.offsetX
422
+ || typeof e.layerX != 'undefined' && e.layerX
423
+ || typeof e.clientX != 'undefined' && e.clientX;
424
+ }
425
+
426
+ getY(e) {
427
+ return typeof e.zrenderY != 'undefined' && e.zrenderY
428
+ || typeof e.offsetY != 'undefined' && e.offsetY
429
+ || typeof e.layerY != 'undefined' && e.layerY
430
+ || typeof e.clientY != 'undefined' && e.clientY;
431
+ }
432
+
433
+ /**
434
+ * @function Theme.prototype.un
435
+ * @description 移除专题要素事件监听。
436
+ * @param {string} event - 事件名称。
437
+ * @param {RequestCallback} callback - 事件回调函数。
438
+ */
439
+ un(event, callback) {
440
+ var cb = callback;
441
+ if (!this.renderer) {
442
+ var tfEs = this.TFEvents;
443
+ var len = tfEs.length;
444
+ var newtfEs = [];
445
+ for (var i = 0; i < len; i++) {
446
+ var tfEs_i = tfEs[i];
447
+
448
+ if (!(tfEs_i[0] === event && tfEs_i[1] === cb)) {
449
+ newtfEs.push(tfEs_i)
450
+ }
451
+ }
452
+ this.TFEvents = newtfEs;
453
+ } else {
454
+ this.renderer.un(event, cb);
455
+ }
456
+ }
457
+
458
+ /**
459
+ * @function Theme.prototype.addTFEvents
460
+ * @description 将图层添加到地图上之前用户要求添加的事件监听添加到图层。
461
+ * @private
462
+ */
463
+ addTFEvents() {
464
+ var tfEs = this.TFEvents;
465
+ var len = tfEs.length;
466
+ for (var i = 0; i < len; i++) {
467
+ this.renderer.on(tfEs[i][0], tfEs[i][1]);
468
+ }
469
+ }
470
+
471
+ /**
472
+ * @function Theme.prototype.getLocalXY
473
+ * @description 地理坐标转为像素坐标。
474
+ * @param {Object} coordinate - 坐标位置。
475
+ * @returns {Array.<number>} 长度为 2 的像素坐标数组,第一个元素表示 x 坐标,第二个元素表示 y 坐标。
476
+ */
477
+ getLocalXY(coordinate) {
478
+ var pixelP, map = this.map;
479
+ if (coordinate instanceof GeometryPoint || coordinate instanceof GeoText) {
480
+ pixelP = map.getPixelFromCoordinate([coordinate.x, coordinate.y]);
481
+ }
482
+ if (coordinate instanceof LonLat) {
483
+ pixelP = map.getPixelFromCoordinate([coordinate.lon, coordinate.lat]);
484
+ }
485
+ var rotation = -map.getView().getRotation();
486
+ var center = map.getPixelFromCoordinate(map.getView().getCenter());
487
+ var rotatedP = pixelP;
488
+ if (this.pixelRatio) {
489
+ rotatedP = this.scale(pixelP, center, this.pixelRatio);
490
+ }
491
+ if (pixelP && center) {
492
+ rotatedP = this.rotate(rotatedP, rotation, center);
493
+ }
494
+ if (this.offset && rotatedP) {
495
+ return [rotatedP[0] + this.offset[0], rotatedP[1] + this.offset[1]];
496
+ }
497
+ return rotatedP;
498
+ }
499
+
500
+ /**
501
+ * @function Theme.prototype.rotate
502
+ * @description 获取某像素坐标点 pixelP 绕中心 center 逆时针旋转 rotation 弧度后的像素点坐标。
503
+ * @param {number} pixelP - 像素坐标点位置。
504
+ * @param {number} rotation - 旋转角度。
505
+ * @param {number} center - 中心位置。
506
+ * @returns {Array.<number>} 旋转后的像素坐标数组。
507
+ */
508
+ rotate(pixelP, rotation, center) {
509
+ var x = Math.cos(rotation) * (pixelP[0] - center[0]) - Math.sin(rotation) * (pixelP[1] - center[1]) + center[0];
510
+ var y = Math.sin(rotation) * (pixelP[0] - center[0]) + Math.cos(rotation) * (pixelP[1] - center[1]) + center[1];
511
+ return [x, y];
512
+ }
513
+
514
+ /**
515
+ * @function Theme.prototype.scale
516
+ * @description 获取某像素坐标点 pixelP 相对于中心 center 进行缩放 scaleRatio 倍后的像素点坐标。
517
+ * @param {Object} pixelP - 像素点。
518
+ * @param {Object} center - 中心点。
519
+ * @param {number} scaleRatio - 缩放倍数。
520
+ * @returns {Array.<number>} 返回数组型比例。
521
+ */
522
+ scale(pixelP, center, scaleRatio) {
523
+ var x = (pixelP[0] - center[0]) * scaleRatio + center[0];
524
+ var y = (pixelP[1] - center[1]) * scaleRatio + center[1];
525
+ return [x, y];
526
+ }
527
+
528
+ /**
529
+ * @function Theme.prototype.toiClientFeature
530
+ * @description 转为 iClient 要素。
531
+ * @param {(Array.<ThemeFeature>|Array.<GeoJSONObject>|Array.<ol.Feature>|ThemeFeature|GeoJSONObject|ol.Feature)} features - 待转要素。
532
+ * @returns {Array.<FeatureVector>} 转换后的 iClient 要素。
533
+ */
534
+ toiClientFeature(features) {
535
+ if (!CommonUtil.isArray(features)) {
536
+ features = [features];
537
+ }
538
+
539
+ let featuresTemp = [];
540
+ for (let i = 0; i < features.length; i++) {
541
+
542
+ if (features[i] instanceof ThemeFeature) {
543
+ // ThemeFeature 类型
544
+ featuresTemp.push(features[i].toFeature());
545
+ continue;
546
+ } else if (features[i] instanceof Feature) {
547
+ //ol.Feature 数据类型
548
+ //_toFeature 统一处理 ol.Feature 所有 geometry 类型
549
+ featuresTemp.push(this._toFeature(features[i]));
550
+ continue;
551
+ } else if (features[i] instanceof FeatureVector) {
552
+ // 若是 FeatureVector 直接返回
553
+ featuresTemp.push(features[i]);
554
+ continue;
555
+ } else if (features[i].geometry && features[i].geometry.parts) {
556
+ //iServer服务器返回数据格式
557
+ featuresTemp.push(ServerFeature.fromJson(features[i]).toFeature());
558
+ } else if (["FeatureCollection", "Feature", "Geometry"].indexOf(features[i].type) != -1) {
559
+ //GeoJSON 规范数据类型
560
+ const format = new GeoJSONFormat();
561
+ featuresTemp = featuresTemp.concat(format.read(features[i]));
562
+ } else {
563
+ throw new Error(`features[${i}]'s type is not be supported.`);
564
+ }
565
+
566
+ }
567
+ return featuresTemp;
568
+ }
569
+
570
+ /**
571
+ * @function Theme.prototype.toFeature
572
+ * @deprecated
573
+ * @description 转为 iClient 要素,该方法将被弃用,由 {@link Theme#toiClientFeature} 代替。
574
+ * @param {(Array.<ThemeFeature>|Array.<GeoJSONObject>|Array.<ol.Feature>|ThemeFeature|GeoJSONObject|ol.Feature)} features - 待转要素。
575
+ * @returns {Array.<FeatureVector>} 转换后的 iClient 要素。
576
+ */
577
+ toFeature(features) {
578
+ return this.toiClientFeature(features);
579
+ }
580
+
581
+ //统一处理 ol.feature所有 geometry 类型
582
+ _toFeature(feature) {
583
+ let geoFeature = (new GeoJSON()).writeFeature(feature);
584
+ return new GeoJSONFormat().read(geoFeature, "Feature");
585
+ }
586
+
587
+ }
@@ -0,0 +1,46 @@
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 { GeoJSON as GeoJSONFormat } from '@supermapgis/iclient-common/format/GeoJSON';
5
+ import { GeoText } from '@supermapgis/iclient-common/commontypes/geometry/GeoText';
6
+ import { Vector as FeatureVector} from '@supermapgis/iclient-common/commontypes/Vector';
7
+ import Geometry from 'ol/geom/Geometry';
8
+ import Feature from 'ol/Feature';
9
+ import GeoJSON from 'ol/format/GeoJSON';
10
+
11
+ /**
12
+ * @class ThemeFeature
13
+ * @category Visualization Theme
14
+ * @classdesc 专题图要素类。支持的 geometry 参数类型为 ol.geom.Geometry 和 GeometryGeoText 标签数组类型。
15
+ * @modulecategory Overlay
16
+ * @param {Object} geometry - 要量算的几何对象,支持 {@link ol.geom.Geometry} 和 GeometryGeoText 标签数组类型 geometry = [x,y,text]。
17
+ * @param {Object} [attributes] - 属性。
18
+ * @usage
19
+ */
20
+ export class ThemeFeature {
21
+
22
+ constructor(geometry, attributes) {
23
+ this.geometry = geometry;
24
+ this.attributes = attributes;
25
+ }
26
+
27
+ /**
28
+ * @function ThemeFeature.prototype.toFeature
29
+ * @description 转为矢量要素。
30
+ */
31
+ toFeature() {
32
+ var geometry = this.geometry;
33
+ if (geometry instanceof Geometry) {
34
+ //先把数据属性与要素合并
35
+ let featureOption = this.attributes;
36
+ featureOption.geometry = geometry;
37
+ let olFeature = new Feature(featureOption);
38
+ return new GeoJSONFormat().read((new GeoJSON()).writeFeature(olFeature), "Feature");
39
+
40
+ } else if (geometry.length === 3) {
41
+ geometry = new GeoText(geometry[0], geometry[1], geometry[2]);
42
+ return new FeatureVector(geometry, this.attributes);
43
+ }
44
+
45
+ }
46
+ }
@@ -0,0 +1,6 @@
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 {GeoFeature} from './GeoFeature';
5
+ export {Theme} from './Theme';
6
+ export {ThemeFeature} from './ThemeFeature';