@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,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 { HitCloverShape } from './graphic/HitCloverShape';
6
+ import { CloverShape } from './graphic/CloverShape';
7
+ import { Util as CommonUtil} from '@supermapgis/iclient-common/commontypes/Util';
8
+ import { GraphicWebGLRenderer } from './graphic/WebGLRenderer';
9
+ import { GraphicCanvasRenderer } from './graphic/CanvasRenderer';
10
+ import { Graphic as OverlayGraphic } from './graphic/Graphic';
11
+ import ImageCanvasSource from 'ol/source/ImageCanvas';
12
+ import Style from 'ol/style/Style';
13
+ import CircleStyle from 'ol/style/Circle';
14
+ import FillStyle from 'ol/style/Fill';
15
+ import StrokeStyle from 'ol/style/Stroke';
16
+ import * as olExtent from 'ol/extent';
17
+ import Polygon from 'ol/geom/Polygon';
18
+ import Point from 'ol/geom/Point';
19
+ import ImageLayer from 'ol/layer/Image';
20
+
21
+ const defaultProps = {
22
+ color: [0, 0, 0, 255],
23
+ opacity: 0.8,
24
+ radius: 10,
25
+ radiusScale: 1,
26
+ radiusMinPixels: 0,
27
+ radiusMaxPixels: Number.MAX_SAFE_INTEGER,
28
+ strokeWidth: 1,
29
+ outline: false
30
+ };
31
+
32
+ const Renderer = ['canvas', 'webgl'];
33
+
34
+ /**
35
+ * @class Graphic
36
+ * @browsernamespace ol.source
37
+ * @category Visualization Graphic
38
+ * @classdesc 高效率点图层源。
39
+ * @param {Object} options - 参数。
40
+ * @param {ol.Map} options.map - openlayers 地图对象。
41
+ * @param {OverlayGraphic} options.graphics - 高效率点图层点要素。
42
+ * @param {string} [options.render ='canvas'] - 指定使用的渲染器。可选值:"webgl","canvas"(webgl 渲染目前只支持散点)。
43
+ * @param {boolean} [options.isHighLight=true] - 事件响应是否支持要素高亮。
44
+ * @param {ol.style.Style} [options.highLightStyle=defaultHighLightStyle] - 高亮风格。
45
+ * @param {Array.<number>} [options.color=[0, 0, 0, 255]] - 要素颜色。当 {@link OverlayGraphic} 的 style 参数传入设置了 fill 的 {@link HitCloverShape} 或 {@link CloverShape},此参数无效。
46
+ * @param {Array.<number>} [options.highlightColor] - webgl 渲染时要素高亮颜色。
47
+ * @param {number} [options.opacity=0.8] - 要素透明度。当 {@link OverlayGraphic} 的 style 参数传入设置了 fillOpacity 或 strokeOpacity 的 {@link HitCloverShape} 或 {@link CloverShape},此参数无效。
48
+ * @param {number} [options.radius=10] - 要素半径,单位像素。当 {@link OverlayGraphic} 的 style 参数传入设置了 radius 的 {@link HitCloverShape} 或 {@link CloverShape},此参数无效。
49
+ * @param {number} [options.radiusScale=1] - webgl 渲染时的要素放大倍数。
50
+ * @param {number} [options.radiusMinPixels=0] - webgl 渲染时的要素半径最小值(像素)。
51
+ * @param {number} [options.radiusMaxPixels=Number.MAX_SAFE_INTEGER] - webgl 渲染时的要素半径最大值(像素)。
52
+ * @param {number} [options.strokeWidth=1] - 边框大小。
53
+ * @param {boolean} [options.outline=false] - 是否显示边框。
54
+ * @param {function} [options.onHover] - 图层鼠标悬停响应事件(只有 webgl 渲染时有用)。
55
+ * @param {function} [options.onClick] - 图层鼠标点击响应事件(webgl、canvas 渲染时都有用)。
56
+ * @extends {ol.source.ImageCanvas}
57
+ * @usage
58
+ */
59
+ export class Graphic extends ImageCanvasSource {
60
+ constructor(options) {
61
+ super({
62
+ attributions: options.attributions,
63
+ canvasFunction: canvasFunctionInternal_,
64
+ logo: Util.getOlVersion() === '4' ? options.logo : null,
65
+ projection: options.projection,
66
+ ratio: options.ratio,
67
+ resolutions: options.resolutions,
68
+ state: options.state
69
+ });
70
+ this.graphics = [].concat(options.graphics);
71
+ this.map = options.map;
72
+ CommonUtil.extend(this, options);
73
+ this.render = options.render || Renderer[0];
74
+ if (!Util.supportWebGL2()) {
75
+ this.render = Renderer[0];
76
+ }
77
+ this.highLightStyle = options.highLightStyle;
78
+ //是否支持高亮,默认支持
79
+ this.isHighLight = typeof options.isHighLight === 'undefined' ? true : options.isHighLight;
80
+ this.hitGraphicLayer = null;
81
+ this._forEachFeatureAtCoordinate = _forEachFeatureAtCoordinate;
82
+ this._options = options;
83
+ const me = this;
84
+ if (options.onClick) {
85
+ me.map.on('click', function(e) {
86
+ if (me.isDeckGLRender) {
87
+ const params = me.renderer.deckGL.pickObject({ x: e.pixel[0], y: e.pixel[1] });
88
+ options.onClick(params);
89
+ return;
90
+ }
91
+ const graphic = me.findGraphicByPixel(e, me);
92
+ if (graphic) {
93
+ options.onClick(graphic, e);
94
+ if (me.isHighLight) {
95
+ me._highLight(
96
+ graphic.getGeometry().getCoordinates(),
97
+ new Style({
98
+ image: graphic.getStyle()
99
+ }).getImage(),
100
+ graphic,
101
+ e.pixel
102
+ );
103
+ }
104
+
105
+ }
106
+ });
107
+ }
108
+ me.map.on('pointermove', function(e) {
109
+ if (me.isDeckGLRender) {
110
+ const params = me.renderer.deckGL.pickObject({ x: e.pixel[0], y: e.pixel[1] });
111
+ if (options.onHover) {
112
+ options.onHover(params);
113
+ }
114
+ }
115
+ });
116
+ //eslint-disable-next-line no-unused-vars
117
+ function canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) {
118
+ var mapWidth = size[0] / pixelRatio;
119
+ var mapHeight = size[1] / pixelRatio;
120
+ var width = me.map.getSize()[0];
121
+ var height = me.map.getSize()[1];
122
+ if (!me.renderer) {
123
+ me.renderer = createRenderer(size, pixelRatio);
124
+ }
125
+ me.renderer.mapWidth = mapWidth;
126
+ me.renderer.mapHeight = mapHeight;
127
+ me.renderer.pixelRatio = pixelRatio;
128
+ me.renderer.offset = [(mapWidth - width) / 2, (mapHeight - height) / 2];
129
+ let graphics = this.getGraphicsInExtent(extent);
130
+ me.renderer._clearBuffer();
131
+ me.renderer.selected = this.selected;
132
+ me.renderer.drawGraphics(graphics);
133
+ me.isDeckGLRender = me.renderer instanceof GraphicWebGLRenderer;
134
+ if(me.isDeckGLRender){
135
+ if (!me.context) {
136
+ me.context = Util.createCanvasContext2D(mapWidth, mapHeight);
137
+ }
138
+ return me.context.canvas;
139
+ }
140
+ return me.renderer.getCanvas();
141
+ }
142
+
143
+ function createRenderer(size, pixelRatio) {
144
+ let renderer;
145
+ if (me.render === Renderer[0]) {
146
+ renderer = new GraphicCanvasRenderer(me, {
147
+ size,
148
+ pixelRatio
149
+ });
150
+ } else {
151
+ let optDefault = CommonUtil.extend({}, defaultProps);
152
+ let opt = CommonUtil.extend(optDefault, {
153
+ color: me.color,
154
+ opacity: me.opacity,
155
+ radius: me.radius,
156
+ radiusScale: me.radiusScale,
157
+ radiusMinPixels: me.radiusMinPixels,
158
+ radiusMaxPixels: me.radiusMaxPixels,
159
+ strokeWidth: me.strokeWidth,
160
+ outline: me.outline,
161
+ onClick: me.onClick,
162
+ onHover: me.onHover
163
+ });
164
+ opt = CommonUtil.extend(me, opt);
165
+ opt.pixelRatio = pixelRatio;
166
+ opt.container = me.map.getViewport().getElementsByClassName('ol-overlaycontainer')[0];
167
+ opt.onBeforeRender = function() {
168
+ return false;
169
+ };
170
+ opt.onAfterRender = function() {
171
+ return false;
172
+ };
173
+
174
+ renderer = new GraphicWebGLRenderer(me, opt);
175
+ }
176
+ return renderer;
177
+ }
178
+
179
+ /**
180
+ * @private
181
+ * @function Graphic.prototype._forEachFeatureAtCoordinate
182
+ * @description 获取在视图上的要素。
183
+ * @param {string} coordinate -坐标。
184
+ * @param {number} resolution -分辨率。
185
+ * @param {RequestCallback} callback -回调函数。
186
+ * @param {ol.Pixel} evtPixel - 当前选中的屏幕像素坐标。
187
+ */
188
+ function _forEachFeatureAtCoordinate(coordinate, resolution, callback, evtPixel, e) {
189
+ let graphics = me.getGraphicsInExtent();
190
+ // FIX 无法高亮元素
191
+ me._highLightClose();
192
+ for (let i = graphics.length - 1; i >= 0; i--) {
193
+ let style = graphics[i].getStyle();
194
+ if (!style) {
195
+ return;
196
+ }
197
+ //已经被高亮的graphics 不被选选中
198
+ if (style instanceof HitCloverShape) {
199
+ continue;
200
+ }
201
+ let center = graphics[i].getGeometry().getCoordinates();
202
+ let image = new Style({
203
+ image: style
204
+ }).getImage();
205
+
206
+ let contain = false;
207
+ //icl-1047 当只有一个叶片的时候,判断是否选中的逻辑处理的更准确一点
208
+ if (image instanceof CloverShape && image.getCount() === 1) {
209
+ const ratation = (image.getRotation() * 180) / Math.PI;
210
+ const angle = Number.parseFloat(image.getAngle());
211
+ const r = image.getRadius() * resolution;
212
+ //if(image.getAngle() )
213
+ let geo = null;
214
+ if (angle > 355) {
215
+ geo = new CircleStyle(center, r);
216
+ } else {
217
+ const coors = [];
218
+ coors.push(center);
219
+ const perAngle = angle / 8;
220
+ for (let index = 0; index < 8; index++) {
221
+ const radian = ((ratation + index * perAngle) / 180) * Math.PI;
222
+ coors.push([center[0] + r * Math.cos(radian), center[1] - r * Math.sin(radian)]);
223
+ }
224
+ coors.push(center);
225
+ geo = new Polygon([coors]);
226
+ }
227
+ if (geo.intersectsCoordinate(this.map.getCoordinateFromPixel(evtPixel))) {
228
+ contain = true;
229
+ }
230
+ } else {
231
+ let extent = [];
232
+ extent[0] = center[0] - image.getAnchor()[0] * resolution;
233
+ extent[2] = center[0] + image.getAnchor()[0] * resolution;
234
+ extent[1] = center[1] - image.getAnchor()[1] * resolution;
235
+ extent[3] = center[1] + image.getAnchor()[1] * resolution;
236
+ if (olExtent.containsCoordinate(extent, coordinate)) {
237
+ contain = true;
238
+ }
239
+ }
240
+
241
+ if (contain === true) {
242
+ if (callback) {
243
+ callback(graphics[i], e);
244
+ }
245
+ continue;
246
+ }
247
+ // if (me.isHighLight) {
248
+ // // me._highLightClose();
249
+ // }
250
+ }
251
+ return undefined;
252
+ }
253
+ }
254
+
255
+ findGraphicByPixel(e, me) {
256
+ const features = me.map.getFeaturesAtPixel(e.pixel) || [];
257
+ for (let index = 0; index < features.length; index++) {
258
+ const graphic = features[index];
259
+ if (me.graphics.indexOf(graphic) > -1) {
260
+ return graphic;
261
+ }
262
+ }
263
+ return undefined;
264
+ }
265
+
266
+ /**
267
+ * @function Graphic.prototype.setGraphics
268
+ * @description 设置绘制的点要素,会覆盖之前的所有要素。
269
+ * @param {Array.<OverlayGraphic>} graphics - 点要素对象数组。
270
+ */
271
+ setGraphics(graphics) {
272
+ this.graphics = this.graphics || [];
273
+ this.graphics.length = 0;
274
+ let sGraphics = !Util.isArray(graphics) ? [graphics] : [].concat(graphics);
275
+ this.graphics = [].concat(sGraphics);
276
+ this.update();
277
+ }
278
+
279
+ /**
280
+ * @function Graphic.prototype.addGraphics
281
+ * @description 追加点要素,不会覆盖之前的要素。
282
+ * @param {Array.<OverlayGraphic>} graphics - 点要素对象数组。
283
+ */
284
+ addGraphics(graphics) {
285
+ this.graphics = this.graphics || [];
286
+ let sGraphics = !Util.isArray(graphics) ? [graphics] : [].concat(graphics);
287
+ this.graphics = this.graphics.concat(sGraphics);
288
+ this.update();
289
+ }
290
+
291
+ /**
292
+ * @function Graphic.prototype.getGraphicBy
293
+ * @description 在 Vector 的要素数组 graphics 里面遍历每一个 graphic,当 graphic[property]===value 时,返回此 graphic(并且只返回第一个)。
294
+ * @param {string} property - graphic 的属性名称。
295
+ * @param {string} value - property 所对应的值。
296
+ * @returns {OverlayGraphic} 一个匹配的 graphic。
297
+ */
298
+ getGraphicBy(property, value) {
299
+ let graphic = null;
300
+ for (let index in this.graphics) {
301
+ if (this.graphics[index][property] === value) {
302
+ graphic = this.graphics[index];
303
+ break;
304
+ }
305
+ }
306
+ return graphic;
307
+ }
308
+
309
+ /**
310
+ * @function Graphic.prototype.getGraphicById
311
+ * @description 通过给定一个 ID,返回对应的矢量要素。
312
+ * @param {string} graphicId - 矢量要素的属性 ID。
313
+ * @returns {OverlayGraphic} 一个匹配的 graphic。
314
+ */
315
+ getGraphicById(graphicId) {
316
+ return this.getGraphicBy('id', graphicId);
317
+ }
318
+
319
+ /**
320
+ * @function Graphic.prototype.getGraphicsByAttribute
321
+ * @description 通过给定一个属性的 key 值和 value 值,返回所有匹配的要素数组。
322
+ * @param {string} attrName - graphic 的某个属性名称。
323
+ * @param {string} attrValue - property 所对应的值。
324
+ * @returns {Array.<OverlayGraphic>} 一个匹配的 graphic 数组。
325
+ */
326
+ getGraphicsByAttribute(attrName, attrValue) {
327
+ var graphic,
328
+ foundgraphics = [];
329
+ for (let index in this.graphics) {
330
+ graphic = this.graphics[index];
331
+ if (graphic && graphic.attributes) {
332
+ if (graphic.attributes[attrName] === attrValue) {
333
+ foundgraphics.push(graphic);
334
+ }
335
+ }
336
+ }
337
+ return foundgraphics;
338
+ }
339
+
340
+ /**
341
+ * @function Graphic.prototype.removeGraphics
342
+ * @description 删除要素数组,默认将删除所有要素。
343
+ * @param {Array.<OverlayGraphic>} [graphics] - 删除的 graphics 数组。
344
+ */
345
+ removeGraphics(graphics = null) {
346
+ //当 graphics 为 null 、为空数组,或 === this.graphics,则清除所有要素
347
+ if (!graphics || graphics.length === 0 || graphics === this.graphics) {
348
+ this.graphics.length = 0;
349
+ this.update();
350
+ return;
351
+ }
352
+
353
+ if (!CommonUtil.isArray(graphics)) {
354
+ graphics = [graphics];
355
+ }
356
+
357
+ for (let i = graphics.length - 1; i >= 0; i--) {
358
+ let graphic = graphics[i];
359
+
360
+ //如果我们传入的grapchic在graphics数组中没有的话,则不进行删除,
361
+ //并将其放入未删除的数组中。
362
+ let findex = CommonUtil.indexOf(this.graphics, graphic);
363
+
364
+ if (findex === -1) {
365
+ continue;
366
+ }
367
+ this.graphics.splice(findex, 1);
368
+ }
369
+
370
+ //删除完成后重新设置 setGraphics,以更新
371
+ this.update();
372
+ }
373
+
374
+ /**
375
+ * @function Graphic.prototype.clear
376
+ * @description 释放图层资源。
377
+ */
378
+ clear() {
379
+ this.removeGraphics();
380
+ }
381
+
382
+ /**
383
+ * @function Graphic.prototype.update
384
+ * @description 更新图层。
385
+ */
386
+ update() {
387
+ this.renderer.update(this.graphics, this._getDefaultStyle());
388
+ }
389
+
390
+ _getDefaultStyle() {
391
+ const target = {};
392
+ if (this.color) {
393
+ target.fill = new FillStyle({
394
+ color: this.toRGBA(this.color)
395
+ });
396
+ }
397
+ if (this.radius) {
398
+ target.radius = this.radius;
399
+ }
400
+ if (this.outline) {
401
+ target.stroke = new FillStyle({
402
+ color: this.toRGBA(this.color),
403
+ width: this.strokeWidth
404
+ });
405
+ }
406
+ return new CircleStyle(target);
407
+ }
408
+
409
+ toRGBA(colorArray) {
410
+ return `rgba(${colorArray[0]},${colorArray[1]},${colorArray[2]},${(colorArray[3] || 255) / 255})`;
411
+ }
412
+
413
+ /**
414
+ * @function Graphic.prototype.setStyle
415
+ * @description 设置图层要素整体样式(接口仅在 webgl 渲染时有用)。
416
+ * @param {Object} styleOptions - 样式对象。
417
+ * @param {Array.<number>} [styleOptions.color=[0, 0, 0, 255]] - 点颜色。
418
+ * @param {number} [styleOptions.radius=10] - 点半径。
419
+ * @param {number} [styleOptions.opacity=0.8] - 不透明度。
420
+ * @param {Array} [styleOptions.highlightColor] - 高亮颜色,目前只支持 rgba 数组。
421
+ * @param {number} [styleOptions.radiusScale=1] - 点放大倍数。
422
+ * @param {number} [styleOptions.radiusMinPixels=0] - 半径最小值(像素)。
423
+ * @param {number} [styleOptions.radiusMaxPixels=Number.MAX_SAFE_INTEGER] - 半径最大值(像素)。
424
+ * @param {number} [styleOptions.strokeWidth=1] - 边框大小。
425
+ * @param {boolean} [styleOptions.outline=false] - 是否显示边框。
426
+ */
427
+ setStyle(styleOptions) {
428
+ let self = this;
429
+ let styleOpt = {
430
+ color: self.color,
431
+ radius: self.radius,
432
+ opacity: self.opacity,
433
+ highlightColor: self.highlightColor,
434
+ radiusScale: self.radiusScale,
435
+ radiusMinPixels: self.radiusMinPixels,
436
+ radiusMaxPixels: self.radiusMaxPixels,
437
+ strokeWidth: self.strokeWidth,
438
+ outline: self.outline
439
+ };
440
+
441
+ CommonUtil.extend(self, CommonUtil.extend(styleOpt, styleOptions));
442
+ self.update();
443
+ }
444
+
445
+ /**
446
+ * @function Graphic.prototype.getLayerState
447
+ * @description 获取当前地图及图层状态。
448
+ * @returns {Object} 地图及图层状态,包含地图状态信息和本图层相关状态。
449
+ */
450
+ getLayerState() {
451
+ let map = this.map;
452
+ let width = map.getSize()[0];
453
+ let height = map.getSize()[1];
454
+
455
+ let view = map.getView();
456
+ let center = view.getCenter();
457
+ let longitude = center[0];
458
+ let latitude = center[1];
459
+
460
+ let zoom = view.getZoom();
461
+ let maxZoom = view.getMaxZoom();
462
+ let rotationRadians = view.getRotation();
463
+
464
+ let rotation = (-rotationRadians * 180) / Math.PI;
465
+
466
+ let mapViewport = {
467
+ longitude: longitude,
468
+ latitude: latitude,
469
+ zoom: zoom,
470
+ maxZoom: maxZoom,
471
+ pitch: 0,
472
+ bearing: rotation
473
+ };
474
+ let state = {};
475
+ for (let key in mapViewport) {
476
+ state[key] = mapViewport[key];
477
+ }
478
+ state.width = width;
479
+ state.height = height;
480
+
481
+ state.color = this.color;
482
+ state.radius = this.radius;
483
+ state.opacity = this.opacity;
484
+ state.highlightColor = this.highlightColor;
485
+ state.radiusScale = this.radiusScale;
486
+ state.radiusMinPixels = this.radiusMinPixels;
487
+ state.radiusMaxPixels = this.radiusMaxPixels;
488
+ state.strokeWidth = this.strokeWidth;
489
+ state.outline = this.outline;
490
+ return state;
491
+ }
492
+
493
+ /**
494
+ * @function Graphic.prototype._highLightClose
495
+ * @description 关闭高亮要素显示。
496
+ * @private
497
+ */
498
+ _highLightClose() {
499
+ this.selected = null;
500
+ if (this.hitGraphicLayer) {
501
+ this.map.removeLayer(this.hitGraphicLayer);
502
+ this.hitGraphicLayer = null;
503
+ }
504
+ this.changed();
505
+ }
506
+
507
+ /**
508
+ * @function Graphic.prototype._highLight
509
+ * @description 高亮显示选中要素。
510
+ * @param {Array.<number>} center - 中心点。
511
+ * @param {ol.style.Style} image - 点样式。
512
+ * @param {OverlayGraphic} selectGraphic - 高效率点图层点要素。
513
+ * @param {ol.Pixel} evtPixel - 当前选中的屏幕像素坐标。
514
+ * @private
515
+ */
516
+ _highLight(center, image, selectGraphic, evtPixel) {
517
+ if (selectGraphic.getStyle() instanceof CloverShape) {
518
+ if (this.hitGraphicLayer) {
519
+ this.map.removeLayer(this.hitGraphicLayer);
520
+ this.hitGraphicLayer = null;
521
+ }
522
+ var pixel = this.map.getPixelFromCoordinate([center[0], center[1]]);
523
+ //点击点与中心点的角度
524
+ evtPixel = evtPixel || [0, 0];
525
+ var angle = (Math.atan2(evtPixel[1] - pixel[1], evtPixel[0] - pixel[0]) / Math.PI) * 180;
526
+ angle = angle > 0 ? angle : 360 + angle;
527
+ //确定扇叶
528
+ var index = Math.ceil(angle / (image.getAngle() + image.getSpaceAngle()));
529
+ //扇叶的起始角度
530
+ var sAngle = (index - 1) * (image.getAngle() + image.getSpaceAngle());
531
+ //渲染参数
532
+ var opts = {
533
+ stroke: new StrokeStyle({
534
+ color: '#ff0000',
535
+ width: 1
536
+ }),
537
+ fill: new FillStyle({
538
+ color: '#0099ff'
539
+ }),
540
+ radius: image.getRadius(),
541
+ angle: image.getAngle(),
542
+ eAngle: sAngle + image.getAngle(),
543
+ sAngle: sAngle,
544
+ rotation: image.getRotation()
545
+ };
546
+ if (this.highLightStyle && this.highLightStyle instanceof HitCloverShape) {
547
+ opts.stroke = this.highLightStyle.getStroke();
548
+ opts.fill = this.highLightStyle.getFill();
549
+ opts.radius = this.highLightStyle.getRadius();
550
+ opts.angle = this.highLightStyle.getAngle();
551
+ }
552
+ var hitGraphic = new OverlayGraphic(new Point(center));
553
+ hitGraphic.setStyle(new HitCloverShape(opts));
554
+ this.hitGraphicLayer = new ImageLayer({
555
+ source: new Graphic({
556
+ map: this.map,
557
+ graphics: [hitGraphic]
558
+ })
559
+ });
560
+ this.map.addLayer(this.hitGraphicLayer);
561
+ } else {
562
+ this.selected = selectGraphic;
563
+ this.changed();
564
+ }
565
+ }
566
+
567
+ /**
568
+ * @function Graphic.prototype.getGraphicsInExtent
569
+ * @description 在指定范围中获取几何要素面积。
570
+ * @param {Object} extent - 长度范围。
571
+ */
572
+ getGraphicsInExtent(extent) {
573
+ var graphics = [];
574
+ if (!extent) {
575
+ this.graphics.forEach(graphic => {
576
+ graphics.push(graphic);
577
+ });
578
+ return graphics;
579
+ }
580
+ this.graphics.forEach(graphic => {
581
+ if (olExtent.containsExtent(extent, graphic.getGeometry().getExtent())) {
582
+ graphics.push(graphic);
583
+ }
584
+ });
585
+ return graphics;
586
+ }
587
+ }