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