my-openlayer 2.4.10 → 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 (119) hide show
  1. package/CHANGELOG.md +167 -265
  2. package/MyOl.d.ts +9 -9
  3. package/MyOl.js +17 -16
  4. package/README.md +217 -156
  5. package/core/line/Line.d.ts +40 -0
  6. package/core/line/Line.js +144 -0
  7. package/core/line/LineFeatureFactory.d.ts +17 -0
  8. package/core/line/LineFeatureFactory.js +75 -0
  9. package/core/line/LineFlowAnimator.d.ts +53 -0
  10. package/core/line/LineFlowAnimator.js +297 -0
  11. package/core/line/LineStyleFactory.d.ts +43 -0
  12. package/core/line/LineStyleFactory.js +135 -0
  13. package/core/{RiverLayerManager.d.ts → line/RiverLayerManager.d.ts} +2 -2
  14. package/core/{RiverLayerManager.js → line/RiverLayerManager.js} +3 -5
  15. package/core/line/index.d.ts +6 -0
  16. package/core/line/index.js +5 -0
  17. package/core/{ConfigManager.d.ts → map/ConfigManager.d.ts} +25 -1
  18. package/core/{ConfigManager.js → map/ConfigManager.js} +22 -1
  19. package/core/{EventManager.d.ts → map/EventManager.d.ts} +1 -1
  20. package/core/{EventManager.js → map/EventManager.js} +2 -2
  21. package/core/{MapBaseLayers.d.ts → map/MapBaseLayers.d.ts} +1 -1
  22. package/core/{MapBaseLayers.js → map/MapBaseLayers.js} +10 -12
  23. package/core/{MapTools.d.ts → map/MapTools.d.ts} +5 -2
  24. package/core/{MapTools.js → map/MapTools.js} +11 -5
  25. package/core/{MeasureHandler.d.ts → map/MeasureHandler.d.ts} +1 -1
  26. package/core/{MeasureHandler.js → map/MeasureHandler.js} +41 -41
  27. package/core/map/index.d.ts +5 -0
  28. package/core/map/index.js +5 -0
  29. package/core/{Point.d.ts → point/Point.d.ts} +13 -4
  30. package/core/{Point.js → point/Point.js} +24 -112
  31. package/core/point/PointClusterLayer.d.ts +10 -0
  32. package/core/point/PointClusterLayer.js +52 -0
  33. package/core/point/PointOverlay.d.ts +13 -0
  34. package/core/point/PointOverlay.js +57 -0
  35. package/core/point/PointPulseLayer.d.ts +13 -0
  36. package/core/point/PointPulseLayer.js +207 -0
  37. package/core/point/index.d.ts +4 -0
  38. package/core/point/index.js +4 -0
  39. package/core/{Polygon.d.ts → polygon/Polygon.d.ts} +4 -50
  40. package/core/polygon/Polygon.js +248 -0
  41. package/core/polygon/PolygonHeatmapLayer.d.ts +11 -0
  42. package/core/polygon/PolygonHeatmapLayer.js +40 -0
  43. package/core/polygon/PolygonImageLayer.d.ts +9 -0
  44. package/core/polygon/PolygonImageLayer.js +61 -0
  45. package/core/polygon/PolygonMaskLayer.d.ts +20 -0
  46. package/core/polygon/PolygonMaskLayer.js +107 -0
  47. package/core/polygon/PolygonStyleFactory.d.ts +12 -0
  48. package/core/polygon/PolygonStyleFactory.js +100 -0
  49. package/core/polygon/index.d.ts +5 -0
  50. package/core/polygon/index.js +5 -0
  51. package/core/{SelectHandler.d.ts → select/SelectHandler.d.ts} +2 -3
  52. package/core/{SelectHandler.js → select/SelectHandler.js} +4 -4
  53. package/core/select/index.d.ts +1 -0
  54. package/core/select/index.js +1 -0
  55. package/core/{VueTemplatePoint.d.ts → vue-template-point/VueTemplatePoint.d.ts} +1 -1
  56. package/core/{VueTemplatePoint.js → vue-template-point/VueTemplatePoint.js} +4 -4
  57. package/core/vue-template-point/index.d.ts +1 -0
  58. package/core/vue-template-point/index.js +1 -0
  59. package/docs/.vitepress/config.mts +57 -57
  60. package/docs/ConfigManager.md +71 -71
  61. package/docs/ErrorHandler.md +106 -106
  62. package/docs/EventManager.md +142 -142
  63. package/docs/Line.md +215 -187
  64. package/docs/MapBaseLayers.md +198 -198
  65. package/docs/MapTools.md +172 -172
  66. package/docs/MeasureHandler.md +87 -87
  67. package/docs/MyOl.md +247 -247
  68. package/docs/Point.md +233 -165
  69. package/docs/Polygon.md +241 -241
  70. package/docs/RiverLayerManager.md +187 -187
  71. package/docs/SelectHandler.md +147 -147
  72. package/docs/ValidationUtils.md +83 -83
  73. package/docs/VueTemplatePoint.md +214 -214
  74. package/docs/index.md +79 -78
  75. package/index.d.ts +11 -16
  76. package/index.js +7 -13
  77. package/package.json +11 -1
  78. package/types/base.d.ts +47 -0
  79. package/types/base.js +1 -0
  80. package/types/common.d.ts +59 -0
  81. package/types/common.js +1 -0
  82. package/types/index.d.ts +9 -0
  83. package/types/index.js +1 -0
  84. package/types/line.d.ts +41 -0
  85. package/types/line.js +1 -0
  86. package/types/map.d.ts +77 -0
  87. package/types/map.js +1 -0
  88. package/types/point.d.ts +54 -0
  89. package/types/point.js +1 -0
  90. package/types/polygon.d.ts +8 -0
  91. package/types/polygon.js +1 -0
  92. package/types/select.d.ts +25 -0
  93. package/types/select.js +1 -0
  94. package/types/vue-template-point.d.ts +54 -0
  95. package/{types.js → types/vue-template-point.js} +0 -3
  96. package/utils/ProjectionUtils.d.ts +28 -0
  97. package/utils/ProjectionUtils.js +34 -0
  98. package/utils/ValidationUtils.d.ts +33 -86
  99. package/utils/ValidationUtils.js +60 -165
  100. package/core/DomPoint.d.ts +0 -21
  101. package/core/DomPoint.js +0 -36
  102. package/core/Line.d.ts +0 -49
  103. package/core/Line.js +0 -114
  104. package/core/Polygon.js +0 -646
  105. package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
  106. package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  107. package/docs/.vitepress/cache/deps/_metadata.json +0 -40
  108. package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js +0 -12542
  109. package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js.map +0 -7
  110. package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js +0 -9719
  111. package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js.map +0 -7
  112. package/docs/.vitepress/cache/deps/package.json +0 -3
  113. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4505
  114. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  115. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
  116. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  117. package/docs/.vitepress/cache/deps/vue.js +0 -343
  118. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  119. package/types.d.ts +0 -372
@@ -1,188 +1,112 @@
1
1
  /**
2
2
  * 验证工具类
3
- * 统一管理所有验证方法
3
+ * 统一管理参数校验逻辑,错误记录由调用方或 ErrorHandler 负责。
4
4
  */
5
- import { ErrorHandler } from './ErrorHandler';
6
- export class ValidationUtils {
5
+ export default class ValidationUtils {
7
6
  /**
8
- * 验证坐标是否有效
9
- * @param longitude 经度
10
- * @param latitude 纬度
11
- * @returns 是否有效
7
+ * 判断值是否为有效数字。
8
+ */
9
+ static isFiniteNumber(value) {
10
+ return typeof value === 'number' && Number.isFinite(value);
11
+ }
12
+ /**
13
+ * 验证坐标是否有效。
12
14
  */
13
15
  static isValidCoordinate(longitude, latitude) {
14
- return (typeof longitude === 'number' &&
15
- typeof latitude === 'number' &&
16
- !isNaN(longitude) &&
17
- !isNaN(latitude) &&
16
+ return (ValidationUtils.isFiniteNumber(longitude) &&
17
+ ValidationUtils.isFiniteNumber(latitude) &&
18
18
  longitude >= -180 &&
19
19
  longitude <= 180 &&
20
20
  latitude >= -90 &&
21
21
  latitude <= 90);
22
22
  }
23
23
  /**
24
- * 验证经纬度坐标(简化版本)
25
- * @param lgtd 经度
26
- * @param lttd 纬度
27
- * @returns 是否有效
24
+ * 验证经纬度坐标,保留布尔返回以兼容旧调用。
28
25
  */
29
26
  static validateLngLat(lgtd, lttd) {
30
- if (!lgtd || !lttd || isNaN(lgtd) || isNaN(lttd)) {
31
- ErrorHandler.getInstance().error('Invalid longitude or latitude coordinates');
32
- return false;
33
- }
34
- return true;
27
+ return ValidationUtils.isValidCoordinate(lgtd, lttd);
35
28
  }
36
29
  /**
37
- * 验证点数据数组
38
- * @param pointData 点数据数组
39
- * @returns 是否有效
30
+ * 验证点数据数组,保留布尔返回以兼容旧调用。
40
31
  */
41
32
  static validatePointData(pointData) {
42
- if (!pointData || pointData.length === 0) {
43
- ErrorHandler.getInstance().warn('Point data is empty or undefined');
44
- return false;
45
- }
46
- return true;
33
+ return Array.isArray(pointData) && pointData.length > 0;
47
34
  }
48
35
  /**
49
- * 验证单个点的坐标
50
- * @param item 包含坐标的数据项
51
- * @returns 是否有效
36
+ * 验证单个点的坐标,保留布尔返回以兼容旧调用。
52
37
  */
53
38
  static validateCoordinates(item) {
54
- if (!item.lgtd || !item.lttd) {
55
- ErrorHandler.getInstance().warn('Invalid coordinates for point:', item);
39
+ if (!item || item.lgtd === undefined || item.lgtd === null || item.lttd === undefined || item.lttd === null) {
56
40
  return false;
57
41
  }
58
- return true;
42
+ return ValidationUtils.isValidCoordinate(Number(item.lgtd), Number(item.lttd));
59
43
  }
60
44
  /**
61
- * 验证颜色字符串是否有效
62
- * @param color 颜色字符串
63
- * @returns 是否有效
45
+ * 验证颜色字符串是否有效。
64
46
  */
65
47
  static isValidColor(color) {
66
48
  if (!color || typeof color !== 'string') {
67
49
  return false;
68
50
  }
69
- // 简单的颜色格式验证
70
51
  const colorRegex = /^(#[0-9A-Fa-f]{3,8}|rgba?\([^)]+\)|[a-zA-Z]+)$/;
71
52
  return colorRegex.test(color);
72
53
  }
73
54
  /**
74
- * 验证图层名称是否有效
75
- * @param layerName 图层名称
76
- * @returns 是否有效
55
+ * 验证图层名称是否有效。
77
56
  */
78
57
  static isValidLayerName(layerName) {
79
- return (typeof layerName === 'string' &&
80
- layerName.length > 0 &&
81
- layerName.trim().length > 0);
58
+ return typeof layerName === 'string' && layerName.trim().length > 0;
82
59
  }
83
60
  /**
84
- * 验证范围是否有效
85
- * @param extent 范围数组 [minX, minY, maxX, maxY]
86
- * @returns 是否有效
61
+ * 验证范围是否有效。
87
62
  */
88
63
  static isValidExtent(extent) {
89
64
  return (Array.isArray(extent) &&
90
65
  extent.length === 4 &&
91
- extent.every(coord => typeof coord === 'number' && !isNaN(coord)) &&
92
- extent[0] < extent[2] && // minX < maxX
93
- extent[1] < extent[3] // minY < maxY
94
- );
66
+ extent.every(coord => ValidationUtils.isFiniteNumber(coord)) &&
67
+ extent[0] < extent[2] &&
68
+ extent[1] < extent[3]);
95
69
  }
96
70
  /**
97
- * 验证GeoJSON数据
98
- * @param data GeoJSON数据
99
- * @returns 是否有效
71
+ * 验证 GeoJSON 数据,保留布尔返回以兼容旧调用。
100
72
  */
101
73
  static validateGeoJSONData(data) {
102
- if (!data) {
103
- ErrorHandler.getInstance().warn('GeoJSON data is required');
104
- return false;
105
- }
106
- if (!data.features || !Array.isArray(data.features)) {
107
- ErrorHandler.getInstance().warn('Invalid GeoJSON data: features array is required');
108
- return false;
109
- }
110
- return true;
74
+ return !!data && Array.isArray(data.features);
111
75
  }
112
76
  /**
113
- * 验证配置选项
114
- * @param options 配置选项
115
- * @returns 是否有效
77
+ * 验证配置选项,保留布尔返回以兼容旧调用。
116
78
  */
117
79
  static validateOptions(options) {
118
- if (!options || typeof options !== 'object') {
119
- ErrorHandler.getInstance().warn('Options are required and must be an object');
120
- return false;
121
- }
122
- return true;
80
+ return !!options && typeof options === 'object';
123
81
  }
124
82
  /**
125
- * 验证数值范围
126
- * @param value 数值
127
- * @param min 最小值
128
- * @param max 最大值
129
- * @returns 是否有效
83
+ * 验证数值范围。
130
84
  */
131
85
  static validateNumberRange(value, min, max) {
132
- return (typeof value === 'number' &&
133
- !isNaN(value) &&
134
- value >= min &&
135
- value <= max);
86
+ return ValidationUtils.isFiniteNumber(value) && value >= min && value <= max;
136
87
  }
137
88
  /**
138
- * 验证DOM元素ID
139
- * @param id 元素ID
140
- * @returns 是否有效
89
+ * 验证 DOM 元素 ID,保留布尔返回以兼容旧调用。
141
90
  */
142
91
  static validateElementId(id) {
143
- if (!id) {
144
- ErrorHandler.getInstance().error('Element ID is required');
145
- return false;
146
- }
147
- return true;
92
+ return typeof id === 'string' && id.trim().length > 0;
148
93
  }
149
94
  /**
150
- * 验证Vue相关参数
151
- * @param pointInfoList 点位信息列表
152
- * @param template Vue组件模板
153
- * @param Vue Vue实例
154
- * @returns 是否有效
95
+ * 验证 Vue 相关参数,保留布尔返回以兼容旧调用。
155
96
  */
156
97
  static validateVueParams(pointInfoList, template, Vue) {
157
- if (!pointInfoList || !Array.isArray(pointInfoList) || pointInfoList.length === 0) {
158
- ErrorHandler.getInstance().error('Valid point info list is required');
159
- return false;
160
- }
161
- if (!template) {
162
- ErrorHandler.getInstance().error('Vue template is required');
163
- return false;
164
- }
165
- if (!Vue) {
166
- ErrorHandler.getInstance().error('Vue instance is required');
167
- return false;
168
- }
169
- return true;
98
+ return Array.isArray(pointInfoList) && pointInfoList.length > 0 && !!template && !!Vue;
170
99
  }
171
100
  /**
172
- * 验证图层名称(抛出异常版本)
173
- * @param layerName 图层名称
174
- * @throws 如果图层名称无效则抛出异常
101
+ * 验证图层名称(抛出异常版本)。
175
102
  */
176
103
  static validateLayerName(layerName) {
177
- if (!layerName) {
104
+ if (!ValidationUtils.isValidLayerName(layerName)) {
178
105
  throw new Error('Layer name is required');
179
106
  }
180
107
  }
181
108
  /**
182
- * 验证图像数据
183
- * @param imageData 图像数据
184
- * @param allowEmptyImg 是否允许img为空
185
- * @throws 如果图像数据无效则抛出异常
109
+ * 验证图像数据。
186
110
  */
187
111
  static validateImageData(imageData, allowEmptyImg = false) {
188
112
  if (!imageData) {
@@ -191,53 +115,38 @@ export class ValidationUtils {
191
115
  if (!allowEmptyImg && !imageData.img) {
192
116
  throw new Error('Invalid image data: img is required');
193
117
  }
194
- if (imageData.extent && (!Array.isArray(imageData.extent) || imageData.extent.length !== 4)) {
118
+ if (imageData.extent && !ValidationUtils.isValidExtent(imageData.extent)) {
195
119
  throw new Error('Invalid extent: must be an array of 4 numbers [minX, minY, maxX, maxY]');
196
120
  }
197
121
  }
198
122
  /**
199
- * 验证遮罩数据
200
- * @param data 遮罩数据
201
- * @throws 如果遮罩数据无效则抛出异常
123
+ * 验证遮罩数据。
202
124
  */
203
125
  static validateMaskData(data) {
204
- if (!data) {
126
+ if (data === undefined || data === null) {
205
127
  throw new Error('Mask data is required');
206
128
  }
207
129
  }
208
130
  /**
209
- * 验证地图实例
210
- * @param map 地图实例
211
- * @throws 如果地图实例无效则抛出异常
131
+ * 验证地图实例。
212
132
  */
213
133
  static validateMapInstance(map) {
214
- if (!map) {
215
- throw new Error('Map instance is required');
216
- }
134
+ ValidationUtils.validateMap(map);
217
135
  }
218
136
  /**
219
- * 验证必需参数
220
- * @param value 要验证的值
221
- * @param message 错误消息
222
- * @throws 如果值为空则抛出异常
137
+ * 验证必需参数。
223
138
  */
224
139
  static validateRequired(value, message) {
225
- if (!value) {
140
+ if (value === undefined || value === null || value === '') {
226
141
  throw new Error(message);
227
142
  }
228
143
  }
229
144
  /**
230
- * 验证坐标(抛出异常版本)
231
- * @param longitude 经度
232
- * @param latitude 纬度
233
- * @throws 如果坐标无效则抛出异常
145
+ * 验证坐标(抛出异常版本)。
234
146
  */
235
147
  static validateCoordinate(longitude, latitude) {
236
- if (typeof longitude !== 'number' || typeof latitude !== 'number') {
237
- throw new Error('Longitude and latitude must be numbers');
238
- }
239
- if (isNaN(longitude) || isNaN(latitude)) {
240
- throw new Error('Valid longitude and latitude are required');
148
+ if (!ValidationUtils.isFiniteNumber(longitude) || !ValidationUtils.isFiniteNumber(latitude)) {
149
+ throw new Error('Longitude and latitude must be valid numbers');
241
150
  }
242
151
  if (longitude < -180 || longitude > 180) {
243
152
  throw new Error('Longitude must be between -180 and 180');
@@ -247,11 +156,7 @@ export class ValidationUtils {
247
156
  }
248
157
  }
249
158
  /**
250
- * 验证类型
251
- * @param value 要验证的值
252
- * @param expectedType 期望的类型
253
- * @param message 错误消息
254
- * @throws 如果类型不匹配则抛出异常
159
+ * 验证类型。
255
160
  */
256
161
  static validateType(value, expectedType, message) {
257
162
  if (typeof value !== expectedType) {
@@ -259,20 +164,15 @@ export class ValidationUtils {
259
164
  }
260
165
  }
261
166
  /**
262
- * 验证非空字符串(抛出异常版本)
263
- * @param str 字符串
264
- * @param message 错误消息
265
- * @throws 如果字符串为空则抛出异常
167
+ * 验证非空字符串。
266
168
  */
267
169
  static validateNonEmptyString(str, message) {
268
- if (!str || typeof str !== 'string') {
170
+ if (!ValidationUtils.isValidLayerName(str)) {
269
171
  throw new Error(message);
270
172
  }
271
173
  }
272
174
  /**
273
- * 验证地图实例(通用版本)
274
- * @param map 地图实例
275
- * @throws 如果地图实例无效则抛出异常
175
+ * 验证地图实例(通用版本)。
276
176
  */
277
177
  static validateMap(map) {
278
178
  if (!map) {
@@ -280,33 +180,28 @@ export class ValidationUtils {
280
180
  }
281
181
  }
282
182
  /**
283
- * 验证测量类型
284
- * @param type 测量类型
285
- * @throws 如果测量类型无效则抛出异常
183
+ * 验证测量类型。
286
184
  */
287
185
  static validateMeasureType(type) {
288
- if (!type || (type !== 'LineString' && type !== 'Polygon')) {
186
+ if (type !== 'LineString' && type !== 'Polygon') {
289
187
  throw new Error('Invalid measure type. Must be "LineString" or "Polygon"');
290
188
  }
291
189
  }
292
190
  /**
293
- * 验证正数
294
- * @param value 数值
295
- * @param message 错误消息
296
- * @throws 如果数值不是正数则抛出异常
191
+ * 验证正数。
297
192
  */
298
193
  static validatePositiveNumber(value, message) {
299
- if (!value || value <= 0) {
194
+ if (!ValidationUtils.isFiniteNumber(value) || value <= 0) {
300
195
  throw new Error(message);
301
196
  }
302
197
  }
303
198
  /**
304
- * 验证图层名称参数
305
- * @param layerName 图层名称(字符串或字符串数组)
306
- * @throws 如果图层名称参数无效则抛出异常
199
+ * 验证图层名称参数。
307
200
  */
308
201
  static validateLayerNameParam(layerName) {
309
- if (!layerName || (typeof layerName !== 'string' && !Array.isArray(layerName))) {
202
+ const isValidString = typeof layerName === 'string' && layerName.trim().length > 0;
203
+ const isValidArray = Array.isArray(layerName) && layerName.length > 0 && layerName.every(ValidationUtils.isValidLayerName);
204
+ if (!isValidString && !isValidArray) {
310
205
  throw new Error('Valid layer name is required');
311
206
  }
312
207
  }
@@ -1,21 +0,0 @@
1
- import Map from "ol/Map";
2
- interface Options {
3
- Vue: any;
4
- Template: any;
5
- lgtd: number;
6
- lttd: number;
7
- props?: any;
8
- type?: string;
9
- sttp?: string;
10
- zIndex?: number;
11
- }
12
- export default class DomPoint {
13
- private map;
14
- private app;
15
- private anchor;
16
- private dom;
17
- constructor(map: Map, options: Options);
18
- setVisible(visible: boolean): void;
19
- remove(): void;
20
- }
21
- export {};
package/core/DomPoint.js DELETED
@@ -1,36 +0,0 @@
1
- // import { createApp } from "vue";
2
- import Overlay from "ol/Overlay";
3
- export default class DomPoint {
4
- constructor(map, options) {
5
- this.map = map;
6
- const { Vue, Template, lgtd, lttd, props, } = options;
7
- this.dom = document.createElement('div');
8
- this.map.getViewport().appendChild(this.dom);
9
- if (Vue.version.startsWith('3')) {
10
- this.app = Vue.createApp(Object.assign(Template, {
11
- props: { ...props }
12
- }));
13
- this.app.mount(this.dom);
14
- }
15
- else {
16
- this.app = new Vue({
17
- el: this.dom,
18
- render: (h) => h(Template, { props })
19
- });
20
- }
21
- this.anchor = new Overlay({
22
- element: this.dom,
23
- positioning: 'center-center',
24
- stopEvent: false
25
- });
26
- this.anchor.setPosition([lgtd, lttd]);
27
- this.map.addOverlay(this.anchor);
28
- }
29
- setVisible(visible) {
30
- this.dom.style.visibility = visible ? 'visible' : 'hidden';
31
- }
32
- remove() {
33
- this.app.unmount();
34
- this.map.removeOverlay(this.anchor);
35
- }
36
- }
package/core/Line.d.ts DELETED
@@ -1,49 +0,0 @@
1
- import Map from "ol/Map";
2
- import VectorSource from "ol/source/Vector";
3
- import VectorLayer from "ol/layer/Vector";
4
- import { LineOptions, MapJSONData } from "../types";
5
- /**
6
- * 线要素管理类
7
- * 用于在地图上添加和管理线要素
8
- *
9
- * @example
10
- * ```typescript
11
- * const lineManager = new Line(map);
12
- * const layer = lineManager.addLine(geoJsonData, {
13
- * type: 'road',
14
- * strokeColor: '#ff0000',
15
- * strokeWidth: 3
16
- * });
17
- * ```
18
- */
19
- export default class Line {
20
- /** OpenLayers 地图实例 */
21
- private readonly map;
22
- private mergeDefaultOptions;
23
- private createStyleFunction;
24
- private createLayer;
25
- /**
26
- * 构造函数
27
- * @param map OpenLayers地图实例
28
- */
29
- constructor(map: Map);
30
- /**
31
- * 添加线要素
32
- * @param data GeoJSON格式的线数据
33
- * @param options 配置项
34
- * @returns 创建的矢量图层
35
- */
36
- addLine(data: MapJSONData, options?: LineOptions): VectorLayer<VectorSource>;
37
- /**
38
- * 从URL添加线要素
39
- * @param url 数据URL
40
- * @param options 配置项
41
- * @returns 创建的矢量图层
42
- */
43
- addLineByUrl(url: string, options?: LineOptions): VectorLayer<VectorSource>;
44
- /**
45
- * 移除线图层
46
- * @param layerName 图层名称
47
- */
48
- removeLineLayer(layerName: string): void;
49
- }
package/core/Line.js DELETED
@@ -1,114 +0,0 @@
1
- import VectorSource from "ol/source/Vector";
2
- import GeoJSON from "ol/format/GeoJSON";
3
- import VectorLayer from "ol/layer/Vector";
4
- import { Stroke, Style } from "ol/style";
5
- import { Feature } from "ol";
6
- import MapTools from "./MapTools";
7
- import { ValidationUtils } from "../utils/ValidationUtils";
8
- import { ConfigManager } from "./ConfigManager";
9
- /**
10
- * 线要素管理类
11
- * 用于在地图上添加和管理线要素
12
- *
13
- * @example
14
- * ```typescript
15
- * const lineManager = new Line(map);
16
- * const layer = lineManager.addLine(geoJsonData, {
17
- * type: 'road',
18
- * strokeColor: '#ff0000',
19
- * strokeWidth: 3
20
- * });
21
- * ```
22
- */
23
- export default class Line {
24
- mergeDefaultOptions(options) {
25
- const layerName = options?.layerName || ConfigManager.DEFAULT_LINE_OPTIONS.layerName;
26
- const defaultOptions = {
27
- ...ConfigManager.DEFAULT_LINE_OPTIONS,
28
- layerName
29
- };
30
- const mergedOptions = { ...defaultOptions, ...options };
31
- return { ...mergedOptions, layerName };
32
- }
33
- createStyleFunction(mergedOptions) {
34
- return (feature) => {
35
- if (feature instanceof Feature) {
36
- feature.set('type', mergedOptions.type);
37
- feature.set('layerName', mergedOptions.layerName);
38
- }
39
- if (mergedOptions.style) {
40
- if (typeof mergedOptions.style === 'function') {
41
- return mergedOptions.style(feature);
42
- }
43
- else {
44
- return mergedOptions.style;
45
- }
46
- }
47
- return new Style({
48
- stroke: new Stroke({
49
- color: mergedOptions.strokeColor,
50
- width: mergedOptions.strokeWidth,
51
- lineDash: mergedOptions.lineDash,
52
- lineDashOffset: mergedOptions.lineDashOffset
53
- })
54
- });
55
- };
56
- }
57
- createLayer(source, mergedOptions) {
58
- const layer = new VectorLayer({
59
- properties: {
60
- name: mergedOptions.layerName,
61
- layerName: mergedOptions.layerName
62
- },
63
- source,
64
- style: this.createStyleFunction(mergedOptions),
65
- zIndex: mergedOptions.zIndex
66
- });
67
- layer.setVisible(mergedOptions.visible);
68
- this.map.addLayer(layer);
69
- return layer;
70
- }
71
- /**
72
- * 构造函数
73
- * @param map OpenLayers地图实例
74
- */
75
- constructor(map) {
76
- ValidationUtils.validateMapInstance(map);
77
- this.map = map;
78
- }
79
- /**
80
- * 添加线要素
81
- * @param data GeoJSON格式的线数据
82
- * @param options 配置项
83
- * @returns 创建的矢量图层
84
- */
85
- addLine(data, options) {
86
- ValidationUtils.validateGeoJSONData(data);
87
- const mergedOptions = this.mergeDefaultOptions(options);
88
- const features = new GeoJSON().readFeatures(data, options?.projectionOptOptions);
89
- const source = new VectorSource({ features });
90
- return this.createLayer(source, mergedOptions);
91
- }
92
- /**
93
- * 从URL添加线要素
94
- * @param url 数据URL
95
- * @param options 配置项
96
- * @returns 创建的矢量图层
97
- */
98
- addLineByUrl(url, options = {}) {
99
- const mergedOptions = this.mergeDefaultOptions(options);
100
- const source = new VectorSource({
101
- url,
102
- format: new GeoJSON(options.projectionOptOptions)
103
- });
104
- return this.createLayer(source, mergedOptions);
105
- }
106
- /**
107
- * 移除线图层
108
- * @param layerName 图层名称
109
- */
110
- removeLineLayer(layerName) {
111
- ValidationUtils.validateLayerName(layerName);
112
- MapTools.removeLayer(this.map, layerName);
113
- }
114
- }