my-openlayer 2.4.12 → 2.5.1

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 (171) hide show
  1. package/CHANGELOG.md +251 -251
  2. package/LICENSE +21 -21
  3. package/MyOl.d.ts +9 -9
  4. package/MyOl.js +17 -14
  5. package/README.md +174 -148
  6. package/core/line/Line.d.ts +40 -0
  7. package/core/line/Line.js +144 -0
  8. package/core/line/LineFeatureFactory.d.ts +17 -0
  9. package/core/line/LineFeatureFactory.js +75 -0
  10. package/core/line/LineFlowAnimator.d.ts +53 -0
  11. package/core/line/LineFlowAnimator.js +297 -0
  12. package/core/line/LineStyleFactory.d.ts +43 -0
  13. package/core/line/LineStyleFactory.js +135 -0
  14. package/core/{RiverLayerManager.d.ts → line/RiverLayerManager.d.ts} +2 -2
  15. package/core/{RiverLayerManager.js → line/RiverLayerManager.js} +3 -5
  16. package/core/line/index.d.ts +6 -0
  17. package/core/line/index.js +5 -0
  18. package/core/{ConfigManager.d.ts → map/ConfigManager.d.ts} +25 -1
  19. package/core/{ConfigManager.js → map/ConfigManager.js} +22 -1
  20. package/core/{EventManager.d.ts → map/EventManager.d.ts} +1 -1
  21. package/core/{EventManager.js → map/EventManager.js} +2 -2
  22. package/core/{MapBaseLayers.d.ts → map/MapBaseLayers.d.ts} +1 -1
  23. package/core/{MapBaseLayers.js → map/MapBaseLayers.js} +3 -3
  24. package/core/{MapTools.d.ts → map/MapTools.d.ts} +5 -2
  25. package/core/{MapTools.js → map/MapTools.js} +11 -5
  26. package/core/{MeasureHandler.d.ts → map/MeasureHandler.d.ts} +1 -1
  27. package/core/{MeasureHandler.js → map/MeasureHandler.js} +41 -41
  28. package/core/map/index.d.ts +5 -0
  29. package/core/map/index.js +5 -0
  30. package/core/{Point.d.ts → point/Point.d.ts} +6 -14
  31. package/core/point/Point.js +272 -0
  32. package/core/point/PointClusterLayer.d.ts +10 -0
  33. package/core/point/PointClusterLayer.js +52 -0
  34. package/core/point/PointOverlay.d.ts +13 -0
  35. package/core/point/PointOverlay.js +57 -0
  36. package/core/point/PointPulseLayer.d.ts +13 -0
  37. package/core/point/PointPulseLayer.js +207 -0
  38. package/core/point/index.d.ts +4 -0
  39. package/core/point/index.js +4 -0
  40. package/core/{Polygon.d.ts → polygon/Polygon.d.ts} +4 -50
  41. package/core/polygon/Polygon.js +248 -0
  42. package/core/polygon/PolygonHeatmapLayer.d.ts +11 -0
  43. package/core/polygon/PolygonHeatmapLayer.js +40 -0
  44. package/core/polygon/PolygonImageLayer.d.ts +9 -0
  45. package/core/polygon/PolygonImageLayer.js +61 -0
  46. package/core/polygon/PolygonMaskLayer.d.ts +20 -0
  47. package/core/polygon/PolygonMaskLayer.js +107 -0
  48. package/core/polygon/PolygonStyleFactory.d.ts +12 -0
  49. package/core/polygon/PolygonStyleFactory.js +100 -0
  50. package/core/polygon/index.d.ts +5 -0
  51. package/core/polygon/index.js +5 -0
  52. package/core/{SelectHandler.d.ts → select/SelectHandler.d.ts} +2 -3
  53. package/core/{SelectHandler.js → select/SelectHandler.js} +4 -4
  54. package/core/select/index.d.ts +1 -0
  55. package/core/select/index.js +1 -0
  56. package/core/{VueTemplatePoint.d.ts → vue-template-point/VueTemplatePoint.d.ts} +1 -1
  57. package/core/{VueTemplatePoint.js → vue-template-point/VueTemplatePoint.js} +4 -4
  58. package/core/vue-template-point/index.d.ts +1 -0
  59. package/core/vue-template-point/index.js +1 -0
  60. package/docs/.vitepress/config.mts +57 -57
  61. package/docs/ConfigManager.md +71 -71
  62. package/docs/ErrorHandler.md +106 -106
  63. package/docs/EventManager.md +142 -142
  64. package/docs/Line.md +215 -187
  65. package/docs/MapBaseLayers.md +198 -198
  66. package/docs/MapTools.md +172 -172
  67. package/docs/MeasureHandler.md +87 -87
  68. package/docs/MyOl.md +247 -247
  69. package/docs/Point.md +136 -136
  70. package/docs/Polygon.md +241 -241
  71. package/docs/RiverLayerManager.md +187 -187
  72. package/docs/SelectHandler.md +147 -147
  73. package/docs/ValidationUtils.md +83 -83
  74. package/docs/VueTemplatePoint.md +214 -214
  75. package/docs/index.md +73 -73
  76. package/index.d.ts +10 -15
  77. package/index.js +7 -13
  78. package/package.json +11 -1
  79. package/types/base.d.ts +47 -0
  80. package/types/base.js +1 -0
  81. package/types/common.d.ts +59 -0
  82. package/types/common.js +1 -0
  83. package/types/index.d.ts +9 -0
  84. package/types/index.js +1 -0
  85. package/types/line.d.ts +41 -0
  86. package/types/line.js +1 -0
  87. package/types/map.d.ts +77 -0
  88. package/types/map.js +1 -0
  89. package/types/point.d.ts +54 -0
  90. package/types/point.js +1 -0
  91. package/types/polygon.d.ts +8 -0
  92. package/types/polygon.js +1 -0
  93. package/types/select.d.ts +25 -0
  94. package/types/select.js +1 -0
  95. package/types/vue-template-point.d.ts +54 -0
  96. package/{types.js → types/vue-template-point.js} +0 -3
  97. package/utils/ProjectionUtils.d.ts +28 -0
  98. package/utils/ProjectionUtils.js +34 -0
  99. package/utils/ValidationUtils.d.ts +33 -86
  100. package/utils/ValidationUtils.js +60 -165
  101. package/core/Line.d.ts +0 -49
  102. package/core/Line.js +0 -114
  103. package/core/Point.js +0 -560
  104. package/core/Polygon.js +0 -646
  105. package/docs/.vitepress/dist/404.html +0 -22
  106. package/docs/.vitepress/dist/ConfigManager.html +0 -46
  107. package/docs/.vitepress/dist/ErrorHandler.html +0 -52
  108. package/docs/.vitepress/dist/EventManager.html +0 -58
  109. package/docs/.vitepress/dist/Line.html +0 -92
  110. package/docs/.vitepress/dist/MapBaseLayers.html +0 -52
  111. package/docs/.vitepress/dist/MapTools.html +0 -81
  112. package/docs/.vitepress/dist/MeasureHandler.html +0 -32
  113. package/docs/.vitepress/dist/MyOl.html +0 -62
  114. package/docs/.vitepress/dist/Point.html +0 -81
  115. package/docs/.vitepress/dist/Polygon.html +0 -102
  116. package/docs/.vitepress/dist/RiverLayerManager.html +0 -66
  117. package/docs/.vitepress/dist/SelectHandler.html +0 -46
  118. package/docs/.vitepress/dist/ValidationUtils.html +0 -47
  119. package/docs/.vitepress/dist/VueTemplatePoint.html +0 -112
  120. package/docs/.vitepress/dist/assets/ConfigManager.md.BOMdGTaa.js +0 -22
  121. package/docs/.vitepress/dist/assets/ConfigManager.md.BOMdGTaa.lean.js +0 -1
  122. package/docs/.vitepress/dist/assets/ErrorHandler.md.yUiuJ9w9.js +0 -28
  123. package/docs/.vitepress/dist/assets/ErrorHandler.md.yUiuJ9w9.lean.js +0 -1
  124. package/docs/.vitepress/dist/assets/EventManager.md.BhCUVy1f.js +0 -34
  125. package/docs/.vitepress/dist/assets/EventManager.md.BhCUVy1f.lean.js +0 -1
  126. package/docs/.vitepress/dist/assets/Line.md.BAQOzmSt.js +0 -68
  127. package/docs/.vitepress/dist/assets/Line.md.BAQOzmSt.lean.js +0 -1
  128. package/docs/.vitepress/dist/assets/MapBaseLayers.md.Bw0L_m0b.js +0 -28
  129. package/docs/.vitepress/dist/assets/MapBaseLayers.md.Bw0L_m0b.lean.js +0 -1
  130. package/docs/.vitepress/dist/assets/MapTools.md.DaYgiDPe.js +0 -57
  131. package/docs/.vitepress/dist/assets/MapTools.md.DaYgiDPe.lean.js +0 -1
  132. package/docs/.vitepress/dist/assets/MeasureHandler.md.7Sf4ymRv.js +0 -8
  133. package/docs/.vitepress/dist/assets/MeasureHandler.md.7Sf4ymRv.lean.js +0 -1
  134. package/docs/.vitepress/dist/assets/MyOl.md.D-14Gzjy.js +0 -38
  135. package/docs/.vitepress/dist/assets/MyOl.md.D-14Gzjy.lean.js +0 -1
  136. package/docs/.vitepress/dist/assets/Point.md.Bi9juuuv.js +0 -57
  137. package/docs/.vitepress/dist/assets/Point.md.Bi9juuuv.lean.js +0 -1
  138. package/docs/.vitepress/dist/assets/Polygon.md.-JIqEvzD.js +0 -78
  139. package/docs/.vitepress/dist/assets/Polygon.md.-JIqEvzD.lean.js +0 -1
  140. package/docs/.vitepress/dist/assets/RiverLayerManager.md.CfUu2RxH.js +0 -42
  141. package/docs/.vitepress/dist/assets/RiverLayerManager.md.CfUu2RxH.lean.js +0 -1
  142. package/docs/.vitepress/dist/assets/SelectHandler.md.COR4ez_p.js +0 -22
  143. package/docs/.vitepress/dist/assets/SelectHandler.md.COR4ez_p.lean.js +0 -1
  144. package/docs/.vitepress/dist/assets/ValidationUtils.md.ReTVWa73.js +0 -23
  145. package/docs/.vitepress/dist/assets/ValidationUtils.md.ReTVWa73.lean.js +0 -1
  146. package/docs/.vitepress/dist/assets/VueTemplatePoint.md.CtxSb5Pm.js +0 -88
  147. package/docs/.vitepress/dist/assets/VueTemplatePoint.md.CtxSb5Pm.lean.js +0 -1
  148. package/docs/.vitepress/dist/assets/app.YvjVuxaB.js +0 -1
  149. package/docs/.vitepress/dist/assets/chunks/framework.C_W0ODpn.js +0 -18
  150. package/docs/.vitepress/dist/assets/chunks/theme.Bf87fILP.js +0 -1
  151. package/docs/.vitepress/dist/assets/index.md.BJz6tHSr.js +0 -26
  152. package/docs/.vitepress/dist/assets/index.md.BJz6tHSr.lean.js +0 -1
  153. package/docs/.vitepress/dist/assets/inter-italic-cyrillic-ext.r48I6akx.woff2 +0 -0
  154. package/docs/.vitepress/dist/assets/inter-italic-cyrillic.By2_1cv3.woff2 +0 -0
  155. package/docs/.vitepress/dist/assets/inter-italic-greek-ext.1u6EdAuj.woff2 +0 -0
  156. package/docs/.vitepress/dist/assets/inter-italic-greek.DJ8dCoTZ.woff2 +0 -0
  157. package/docs/.vitepress/dist/assets/inter-italic-latin-ext.CN1xVJS-.woff2 +0 -0
  158. package/docs/.vitepress/dist/assets/inter-italic-latin.C2AdPX0b.woff2 +0 -0
  159. package/docs/.vitepress/dist/assets/inter-italic-vietnamese.BSbpV94h.woff2 +0 -0
  160. package/docs/.vitepress/dist/assets/inter-roman-cyrillic-ext.BBPuwvHQ.woff2 +0 -0
  161. package/docs/.vitepress/dist/assets/inter-roman-cyrillic.C5lxZ8CY.woff2 +0 -0
  162. package/docs/.vitepress/dist/assets/inter-roman-greek-ext.CqjqNYQ-.woff2 +0 -0
  163. package/docs/.vitepress/dist/assets/inter-roman-greek.BBVDIX6e.woff2 +0 -0
  164. package/docs/.vitepress/dist/assets/inter-roman-latin-ext.4ZJIpNVo.woff2 +0 -0
  165. package/docs/.vitepress/dist/assets/inter-roman-latin.Di8DUHzh.woff2 +0 -0
  166. package/docs/.vitepress/dist/assets/inter-roman-vietnamese.BjW4sHH5.woff2 +0 -0
  167. package/docs/.vitepress/dist/assets/style.C2pAQzDq.css +0 -1
  168. package/docs/.vitepress/dist/hashmap.json +0 -1
  169. package/docs/.vitepress/dist/index.html +0 -50
  170. package/docs/.vitepress/dist/vp-icons.css +0 -1
  171. package/types.d.ts +0 -431
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  import VectorSource from "ol/source/Vector";
3
3
  import GeoJSON from "ol/format/GeoJSON";
4
- import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
5
- import { ValidationUtils } from "../utils/ValidationUtils";
4
+ import { ErrorHandler, ErrorType } from "../../utils/ErrorHandler";
5
+ import ValidationUtils from "../../utils/ValidationUtils";
6
+ import ProjectionUtils from "../../utils/ProjectionUtils";
6
7
  import { createEmpty, extend, isEmpty } from "ol/extent";
7
8
  /**
8
9
  * 地图工具类
@@ -181,15 +182,20 @@ class MapTools {
181
182
  * @param duration 动画时长
182
183
  * @returns 定位是否成功
183
184
  */
184
- locationAction(lgtd, lttd, zoom = 20, duration = 3000) {
185
+ locationAction(lgtd, lttd, zoom = 20, duration = 3000, projection) {
185
186
  if (!this.map) {
186
187
  throw new Error('Map instance is not available');
187
188
  }
188
- if (!ValidationUtils.validateLngLat(lgtd, lttd)) {
189
+ const hasProjection = !!projection?.dataProjection || !!projection?.featureProjection;
190
+ const isValidCoordinate = hasProjection
191
+ ? typeof lgtd === 'number' && typeof lttd === 'number' && Number.isFinite(lgtd) && Number.isFinite(lttd)
192
+ : ValidationUtils.validateLngLat(lgtd, lttd);
193
+ if (!isValidCoordinate) {
189
194
  return false;
190
195
  }
191
196
  try {
192
- this.map.getView().animate({ center: [lgtd, lttd], zoom, duration });
197
+ const center = ProjectionUtils.transformCoordinate([lgtd, lttd], projection);
198
+ this.map.getView().animate({ center, zoom, duration });
193
199
  return true;
194
200
  }
195
201
  catch (error) {
@@ -1,5 +1,5 @@
1
1
  import Map from "ol/Map";
2
- import { MeasureHandlerType } from "../types";
2
+ import { MeasureHandlerType } from "../../types";
3
3
  /**
4
4
  * 测量工具处理类
5
5
  * 提供距离和面积测量功能
@@ -6,8 +6,8 @@ import { Vector as VectorSource } from 'ol/source.js';
6
6
  import { Vector as VectorLayer } from 'ol/layer.js';
7
7
  import { getArea, getLength } from 'ol/sphere.js';
8
8
  import { unByKey } from 'ol/Observable.js';
9
- import { ValidationUtils } from '../utils/ValidationUtils';
10
- import { ErrorHandler } from '../utils/ErrorHandler';
9
+ import ValidationUtils from '../../utils/ValidationUtils';
10
+ import { ErrorHandler } from '../../utils/ErrorHandler';
11
11
  /**
12
12
  * 测量工具处理类
13
13
  * 提供距离和面积测量功能
@@ -322,45 +322,45 @@ export default class MeasureHandler {
322
322
  }
323
323
  const style = document.createElement('style');
324
324
  style.id = styleId;
325
- style.innerHTML = `
326
- .ol-tooltip {
327
- position: relative;
328
- background: rgba(0, 0, 0, 0.5);
329
- border-radius: 4px;
330
- color: white;
331
- padding: 4px 8px;
332
- opacity: 0.7;
333
- white-space: nowrap;
334
- font-size: 12px;
335
- cursor: default;
336
- user-select: none;
337
- border: 1px solid #cccccc;
338
- text-shadow: 1px 1px 2px #000;
339
- }
340
- .ol-tooltip-measure {
341
- opacity: 1;
342
- font-weight: bold;
343
- }
344
- .ol-tooltip-static {
345
- background-color: #ffcc33;
346
- color: black;
347
- border: 1px solid white;
348
- text-shadow: none;
349
- }
350
- .ol-tooltip-measure:before,
351
- .ol-tooltip-static:before {
352
- border-top: 6px solid rgba(0, 0, 0, 0.5);
353
- border-right: 6px solid transparent;
354
- border-left: 6px solid transparent;
355
- content: "";
356
- position: absolute;
357
- bottom: -6px;
358
- margin-left: -7px;
359
- left: 50%;
360
- }
361
- .ol-tooltip-static:before {
362
- border-top-color: #ffcc33;
363
- }
325
+ style.innerHTML = `
326
+ .ol-tooltip {
327
+ position: relative;
328
+ background: rgba(0, 0, 0, 0.5);
329
+ border-radius: 4px;
330
+ color: white;
331
+ padding: 4px 8px;
332
+ opacity: 0.7;
333
+ white-space: nowrap;
334
+ font-size: 12px;
335
+ cursor: default;
336
+ user-select: none;
337
+ border: 1px solid #cccccc;
338
+ text-shadow: 1px 1px 2px #000;
339
+ }
340
+ .ol-tooltip-measure {
341
+ opacity: 1;
342
+ font-weight: bold;
343
+ }
344
+ .ol-tooltip-static {
345
+ background-color: #ffcc33;
346
+ color: black;
347
+ border: 1px solid white;
348
+ text-shadow: none;
349
+ }
350
+ .ol-tooltip-measure:before,
351
+ .ol-tooltip-static:before {
352
+ border-top: 6px solid rgba(0, 0, 0, 0.5);
353
+ border-right: 6px solid transparent;
354
+ border-left: 6px solid transparent;
355
+ content: "";
356
+ position: absolute;
357
+ bottom: -6px;
358
+ margin-left: -7px;
359
+ left: 50%;
360
+ }
361
+ .ol-tooltip-static:before {
362
+ border-top-color: #ffcc33;
363
+ }
364
364
  `;
365
365
  document.head.appendChild(style);
366
366
  }
@@ -0,0 +1,5 @@
1
+ export { default as MapTools } from './MapTools';
2
+ export { default as MapBaseLayers } from './MapBaseLayers';
3
+ export { default as MeasureHandler } from './MeasureHandler';
4
+ export { default as EventManager } from './EventManager';
5
+ export { default as ConfigManager } from './ConfigManager';
@@ -0,0 +1,5 @@
1
+ export { default as MapTools } from './MapTools';
2
+ export { default as MapBaseLayers } from './MapBaseLayers';
3
+ export { default as MeasureHandler } from './MeasureHandler';
4
+ export { default as EventManager } from './EventManager';
5
+ export { default as ConfigManager } from './ConfigManager';
@@ -1,8 +1,7 @@
1
1
  import Map from "ol/Map";
2
- import Overlay from 'ol/Overlay';
3
2
  import VectorLayer from "ol/layer/Vector";
4
3
  import VectorSource from "ol/source/Vector";
5
- import { PointOptions, ClusterOptions, PointData, VueTemplatePointInstance, TwinkleItem, PulsePointOptions, PulsePointLayerHandle } from '../types';
4
+ import { PointOptions, ClusterOptions, PointData, VueTemplatePointInstance, TwinkleItem, PulsePointOptions, PulsePointLayerHandle } from '../../types';
6
5
  export default class Point {
7
6
  private map;
8
7
  constructor(map: Map);
@@ -37,16 +36,6 @@ export default class Point {
37
36
  * @returns 样式对象
38
37
  */
39
38
  private createClusterStyle;
40
- /**
41
- * 将颜色透明度按动画进度衰减。
42
- * @private
43
- */
44
- private withOpacity;
45
- /**
46
- * 创建高性能闪烁点要素。
47
- * @private
48
- */
49
- private createPulsePointFeatures;
50
39
  /**
51
40
  * 配置图层属性
52
41
  * @private
@@ -78,7 +67,7 @@ export default class Point {
78
67
  * @param callback
79
68
  */
80
69
  addDomPoint(twinkleList: TwinkleItem[], callback?: Function): {
81
- anchors: Overlay[];
70
+ anchors: import('ol/Overlay').default[];
82
71
  remove: () => void;
83
72
  setVisible: (visible: boolean) => void;
84
73
  };
@@ -107,5 +96,8 @@ export default class Point {
107
96
  * @param zoom 缩放级别
108
97
  * @param duration 动画时长
109
98
  */
110
- locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number): boolean;
99
+ locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number, projection?: {
100
+ dataProjection?: string;
101
+ featureProjection?: string;
102
+ }): boolean;
111
103
  }
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ import Feature from "ol/Feature";
3
+ import { Point as olPoint } from "ol/geom";
4
+ import { Text, Style, Fill, Stroke, Icon } from "ol/style";
5
+ import VectorLayer from "ol/layer/Vector";
6
+ import VectorSource from "ol/source/Vector";
7
+ import { VueTemplatePoint } from '../vue-template-point';
8
+ import ValidationUtils from '../../utils/ValidationUtils';
9
+ import ProjectionUtils from '../../utils/ProjectionUtils';
10
+ import { ConfigManager, MapTools } from "../map";
11
+ import PointClusterLayer from './PointClusterLayer';
12
+ import PointOverlay from './PointOverlay';
13
+ import PointPulseLayer from './PointPulseLayer';
14
+ export default class Point {
15
+ constructor(map) {
16
+ this.map = map;
17
+ }
18
+ /**
19
+ * 创建文本样式
20
+ * @private
21
+ * @param options 选项
22
+ * @param text 文本内容
23
+ * @returns 文本样式
24
+ */
25
+ createTextStyle(options, text) {
26
+ const defaultTextOptions = ConfigManager.DEFAULT_POINT_TEXT_OPTIONS;
27
+ return new Text({
28
+ text: text,
29
+ font: options.textFont || defaultTextOptions.textFont,
30
+ fill: new Fill({
31
+ color: options.textFillColor || defaultTextOptions.textFillColor
32
+ }),
33
+ stroke: new Stroke({
34
+ color: options.textStrokeColor || defaultTextOptions.textStrokeColor,
35
+ width: options.textStrokeWidth || defaultTextOptions.textStrokeWidth
36
+ }),
37
+ offsetY: options.textOffsetY || defaultTextOptions.textOffsetY,
38
+ });
39
+ }
40
+ /**
41
+ * 创建图标样式
42
+ * @private
43
+ * @param options 选项
44
+ * @returns 图标样式
45
+ */
46
+ createIconStyle(options) {
47
+ const iconOptions = {
48
+ src: options.img,
49
+ scale: options.scale ?? ConfigManager.DEFAULT_POINT_ICON_SCALE,
50
+ };
51
+ if (options.iconColor) {
52
+ iconOptions.color = options.iconColor;
53
+ }
54
+ return new Icon(iconOptions);
55
+ }
56
+ /**
57
+ * 创建点样式
58
+ * @private
59
+ * @param options 选项
60
+ * @param item 数据项
61
+ * @returns 样式对象
62
+ */
63
+ createPointStyle(options, item) {
64
+ const style = {};
65
+ if (options.textKey && item) {
66
+ style.text = this.createTextStyle(options, item[options.textKey]);
67
+ }
68
+ if (options.img) {
69
+ style.image = this.createIconStyle(options);
70
+ }
71
+ return new Style(style);
72
+ }
73
+ /**
74
+ * 创建集群样式
75
+ * @private
76
+ * @param options 选项
77
+ * @param name 名称
78
+ * @returns 样式对象
79
+ */
80
+ createClusterStyle(options, name) {
81
+ const style = {};
82
+ if (options.textKey) {
83
+ style.text = this.createTextStyle(options, name);
84
+ }
85
+ if (options.img) {
86
+ style.image = this.createIconStyle(options);
87
+ }
88
+ return new Style(style);
89
+ }
90
+ /**
91
+ * 配置图层属性
92
+ * @private
93
+ * @param layer 图层
94
+ * @param options 选项
95
+ */
96
+ configureLayer(layer, options) {
97
+ layer.setVisible(options.visible === undefined ? true : options.visible);
98
+ this.map.addLayer(layer);
99
+ }
100
+ /**
101
+ *
102
+ * @param pointData
103
+ * @param type
104
+ * @param options {
105
+ * textKey: String 数据中的文本的key
106
+ * img: String 图标
107
+ * }
108
+ */
109
+ addPoint(pointData, options) {
110
+ if (!ValidationUtils.validatePointData(pointData)) {
111
+ return null;
112
+ }
113
+ const pointFeatureList = [];
114
+ pointData.forEach((item) => {
115
+ if (!ValidationUtils.validateCoordinates(item)) {
116
+ return;
117
+ }
118
+ const pointFeature = new Feature({
119
+ rawData: item,
120
+ type: options.layerName,
121
+ layerName: options.layerName,
122
+ geometry: new olPoint(ProjectionUtils.transformCoordinate([item.lgtd, item.lttd], options))
123
+ });
124
+ if (options.style) {
125
+ if (typeof options.style === 'function') {
126
+ pointFeature.setStyle(options.style(pointFeature));
127
+ }
128
+ else {
129
+ pointFeature.setStyle(options.style);
130
+ }
131
+ }
132
+ else {
133
+ pointFeature.setStyle(this.createPointStyle(options, item));
134
+ }
135
+ pointFeatureList.push(pointFeature);
136
+ });
137
+ const PointVectorLayer = new VectorLayer({
138
+ layerName: options.layerName,
139
+ source: new VectorSource({
140
+ features: pointFeatureList
141
+ }),
142
+ zIndex: options.zIndex || ConfigManager.DEFAULT_POINT_OPTIONS.zIndex,
143
+ });
144
+ this.configureLayer(PointVectorLayer, options);
145
+ return PointVectorLayer;
146
+ }
147
+ addClusterPoint(pointData, options) {
148
+ if (!ValidationUtils.validatePointData(pointData)) {
149
+ return null;
150
+ }
151
+ return PointClusterLayer.create(this.map, pointData, options, this.createClusterStyle.bind(this));
152
+ }
153
+ /**
154
+ * 添加高性能闪烁点图层。
155
+ *
156
+ * 与 addDomPoint 不同,该方法使用 VectorLayer 批量渲染点位,并通过单个
157
+ * requestAnimationFrame 驱动闪烁圈,适合村庄预警等大量点位场景。
158
+ */
159
+ addPulsePointLayer(pointData, options) {
160
+ if (!ValidationUtils.validatePointData(pointData)) {
161
+ return null;
162
+ }
163
+ return PointPulseLayer.create(this.map, pointData, options);
164
+ }
165
+ // // 在流域中心添加闪烁点位
166
+ // addTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: MapJSONData, options?: PolygonOptions) {
167
+ // new MapTools(this.map).removeLayer('twinklePoint')
168
+ // // 计算多边形的中心点坐标
169
+ // const calculatePolygonCenter = (polygonCoordinates: any) => {
170
+ // const polygon = turf.polygon(polygonCoordinates[0]);
171
+ // const centroid = turf.centroid(polygon);
172
+ // return centroid.geometry.coordinates;
173
+ // };
174
+ // const features: any[] = json.features
175
+ // const vectorSource = new VectorSource({
176
+ // format: new GeoJSON(),
177
+ // });
178
+ // twinkleList.forEach(item => {
179
+ // const feature = features.find((ele: any) => {
180
+ // return ele.properties.BASIN === item.idx
181
+ // })
182
+ // if (!feature) return
183
+ // feature.properties.level = item.lev
184
+ // const geojson = new GeoJSON();
185
+ // const olFeature = geojson.readFeature(feature);
186
+ // if (Array.isArray(olFeature)) {
187
+ // vectorSource.addFeatures(olFeature);
188
+ // } else {
189
+ // vectorSource.addFeature(olFeature);
190
+ // }
191
+ // if (feature) {
192
+ // const polygonCenter = calculatePolygonCenter(feature.geometry.coordinates)
193
+ // item.lgtd = polygonCenter[0]
194
+ // item.lttd = polygonCenter[1]
195
+ // }
196
+ // })
197
+ // const basinLayer = new VectorLayer({
198
+ // name: 'twinklePoint',
199
+ // layerName: 'twinklePoint',
200
+ // source: vectorSource,
201
+ // style: function (feature: any) {
202
+ // if (options?.style) {
203
+ // if (typeof options.style === 'function') {
204
+ // return options.style(feature);
205
+ // } else {
206
+ // return options.style;
207
+ // }
208
+ // }
209
+ // return new Style({
210
+ // stroke: new Stroke({
211
+ // color: 'rgb(139,188,245)',
212
+ // width: 3
213
+ // }),
214
+ // fill: new Fill({ color: 'rgba(255, 255, 255, 0)' }),
215
+ // text: new Text({
216
+ // text: feature.values_['BASIN'] || "",
217
+ // font: '14px Calibri,sans-serif',
218
+ // fill: new Fill({ color: '#FFF' }),
219
+ // stroke: new Stroke({
220
+ // color: '#409EFF', width: 2
221
+ // }),
222
+ // })
223
+ // })
224
+ // },
225
+ // zIndex: 21
226
+ // } as any)
227
+ // this.map.addLayer(basinLayer)
228
+ // this.addTwinkleLayer(twinkleList.map(item => ({...item, className: item[key]})), className, key)
229
+ // }
230
+ /**
231
+ * 添加闪烁点
232
+ * @param twinkleList 闪烁点数据
233
+ * @param callback
234
+ */
235
+ addDomPoint(twinkleList, callback) {
236
+ return PointOverlay.create(this.map, twinkleList, callback);
237
+ }
238
+ /**
239
+ * 添加vue组件为点位
240
+ * @param pointDataList 点位信息列表
241
+ * @param template vue组件模板
242
+ * @param Vue Vue实例
243
+ * @returns 返回控制对象,包含显示、隐藏、移除方法
244
+ * @throws 当参数无效时抛出错误
245
+ */
246
+ addVueTemplatePoint(pointDataList, template, options) {
247
+ if (!pointDataList || !Array.isArray(pointDataList) || pointDataList.length === 0) {
248
+ throw new Error('Valid point info list is required');
249
+ }
250
+ if (!template) {
251
+ throw new Error('Vue template is required');
252
+ }
253
+ try {
254
+ const vueTemplatePoint = new VueTemplatePoint(this.map);
255
+ return vueTemplatePoint.addVueTemplatePoint(pointDataList, template, options);
256
+ }
257
+ catch (error) {
258
+ throw new Error(`Failed to create Vue template points: ${error}`);
259
+ }
260
+ }
261
+ /**
262
+ * 地图定位
263
+ * @deprecated 请使用 MapTools.locationAction 方法代替
264
+ * @param lgtd 经度
265
+ * @param lttd 纬度
266
+ * @param zoom 缩放级别
267
+ * @param duration 动画时长
268
+ */
269
+ locationAction(lgtd, lttd, zoom = 20, duration = 3000, projection) {
270
+ return new MapTools(this.map).locationAction(lgtd, lttd, zoom, duration, projection);
271
+ }
272
+ }
@@ -0,0 +1,10 @@
1
+ import Map from "ol/Map";
2
+ import VectorLayer from "ol/layer/Vector";
3
+ import VectorSource from "ol/source/Vector";
4
+ import type { ClusterOptions, PointData } from "../../types";
5
+ /**
6
+ * 点聚合图层构建器。
7
+ */
8
+ export default class PointClusterLayer {
9
+ static create(map: Map, pointData: PointData[], options: ClusterOptions, createClusterStyle: (options: ClusterOptions, name: string) => any): VectorLayer<VectorSource>;
10
+ }
@@ -0,0 +1,52 @@
1
+ import Feature from "ol/Feature";
2
+ import { Point as OlPoint } from "ol/geom";
3
+ import VectorLayer from "ol/layer/Vector";
4
+ import VectorSource from "ol/source/Vector";
5
+ import { Cluster } from "ol/source";
6
+ import ProjectionUtils from "../../utils/ProjectionUtils";
7
+ import ValidationUtils from "../../utils/ValidationUtils";
8
+ import { ConfigManager } from "../map";
9
+ /**
10
+ * 点聚合图层构建器。
11
+ */
12
+ export default class PointClusterLayer {
13
+ static create(map, pointData, options, createClusterStyle) {
14
+ const pointFeatureList = [];
15
+ pointData.forEach(item => {
16
+ if (!ValidationUtils.validateCoordinates(item)) {
17
+ return;
18
+ }
19
+ pointFeatureList.push(new Feature({
20
+ type: options.layerName,
21
+ layerName: options.layerName,
22
+ geometry: new OlPoint(ProjectionUtils.transformCoordinate([item.lgtd, item.lttd], options)),
23
+ name: options.textKey ? item[options.textKey] : '',
24
+ rawData: item,
25
+ }));
26
+ });
27
+ const source = new VectorSource({ features: pointFeatureList });
28
+ const clusterSource = new Cluster({
29
+ distance: options.distance || ConfigManager.DEFAULT_CLUSTER_OPTIONS.distance,
30
+ minDistance: options.minDistance || ConfigManager.DEFAULT_CLUSTER_OPTIONS.minDistance,
31
+ source,
32
+ });
33
+ const clusterLayer = new VectorLayer({
34
+ layerName: options.layerName,
35
+ source: clusterSource,
36
+ style: (feature) => {
37
+ if (options.style) {
38
+ if (typeof options.style === 'function') {
39
+ return options.style(feature);
40
+ }
41
+ return options.style;
42
+ }
43
+ const name = feature.get('features')[0].get('name');
44
+ return createClusterStyle(options, name);
45
+ },
46
+ zIndex: options.zIndex || ConfigManager.DEFAULT_CLUSTER_OPTIONS.zIndex,
47
+ });
48
+ clusterLayer.setVisible(options.visible === undefined ? true : options.visible);
49
+ map.addLayer(clusterLayer);
50
+ return clusterLayer;
51
+ }
52
+ }
@@ -0,0 +1,13 @@
1
+ import Overlay from 'ol/Overlay';
2
+ import Map from 'ol/Map';
3
+ import type { TwinkleItem } from '../../types';
4
+ /**
5
+ * DOM 点位覆盖物构建器。
6
+ */
7
+ export default class PointOverlay {
8
+ static create(map: Map, twinkleList: TwinkleItem[], callback?: Function): {
9
+ anchors: Overlay[];
10
+ remove: () => void;
11
+ setVisible: (visible: boolean) => void;
12
+ };
13
+ }
@@ -0,0 +1,57 @@
1
+ import Overlay from 'ol/Overlay';
2
+ import { ConfigManager } from '../map';
3
+ /**
4
+ * DOM 点位覆盖物构建器。
5
+ */
6
+ export default class PointOverlay {
7
+ static create(map, twinkleList, callback) {
8
+ let anchors = [];
9
+ twinkleList.forEach(twinkleItem => {
10
+ let element;
11
+ if (twinkleItem.element) {
12
+ element = typeof twinkleItem.element === 'function'
13
+ ? twinkleItem.element(twinkleItem)
14
+ : twinkleItem.element;
15
+ if (twinkleItem.className) {
16
+ const classes = twinkleItem.className.split(/\s+/).filter(Boolean);
17
+ if (classes.length > 0) {
18
+ element.classList.add(...classes);
19
+ }
20
+ }
21
+ }
22
+ else {
23
+ element = document.createElement('div');
24
+ element.className = twinkleItem.className || '';
25
+ }
26
+ if (callback) {
27
+ element.addEventListener('click', () => callback(twinkleItem));
28
+ }
29
+ const anchor = new Overlay({
30
+ element,
31
+ positioning: ConfigManager.DEFAULT_DOM_POINT_OVERLAY_OPTIONS.positioning,
32
+ stopEvent: ConfigManager.DEFAULT_DOM_POINT_OVERLAY_OPTIONS.stopEvent
33
+ });
34
+ anchor.setPosition([twinkleItem.lgtd, twinkleItem.lttd]);
35
+ map.addOverlay(anchor);
36
+ anchors.push(anchor);
37
+ });
38
+ return {
39
+ anchors,
40
+ remove: () => {
41
+ anchors.forEach(anchor => {
42
+ anchor.getElement()?.remove();
43
+ map.removeOverlay(anchor);
44
+ });
45
+ anchors = [];
46
+ },
47
+ setVisible: (visible) => {
48
+ anchors.forEach(anchor => {
49
+ const element = anchor.getElement();
50
+ if (element) {
51
+ element.style.display = visible ? '' : 'none';
52
+ }
53
+ });
54
+ }
55
+ };
56
+ }
57
+ }
@@ -0,0 +1,13 @@
1
+ import Feature from "ol/Feature";
2
+ import Map from "ol/Map";
3
+ import { Text } from "ol/style";
4
+ import type { PointData, PulsePointLayerHandle, PulsePointOptions } from "../../types";
5
+ /**
6
+ * 高性能闪烁点图层构建器。
7
+ */
8
+ export default class PointPulseLayer {
9
+ static createTextStyle(options: PulsePointOptions, text: string): Text;
10
+ static withOpacity(color: string, opacity: number): string;
11
+ static createFeatures(pointData: PointData[], options: PulsePointOptions): Feature[];
12
+ static create(map: Map, pointData: PointData[], options: PulsePointOptions): PulsePointLayerHandle;
13
+ }