my-openlayer 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MyOl.d.ts +135 -128
- package/MyOl.js +401 -381
- package/README.md +0 -21
- package/core/ConfigManager.d.ts +88 -88
- package/core/ConfigManager.js +112 -112
- package/core/EventManager.d.ts +141 -141
- package/core/EventManager.js +316 -316
- package/core/Line.d.ts +130 -109
- package/core/Line.js +512 -288
- package/core/MapBaseLayers.d.ts +234 -234
- package/core/MapBaseLayers.js +573 -573
- package/core/MapTools.d.ts +68 -68
- package/core/MapTools.js +202 -201
- package/core/MeasureHandler.d.ts +65 -65
- package/core/MeasureHandler.js +312 -312
- package/core/Point.d.ts +94 -94
- package/core/Point.js +348 -348
- package/core/Polygon.d.ts +157 -139
- package/core/Polygon.js +605 -529
- package/core/SelectHandler.d.ts +138 -0
- package/core/SelectHandler.js +395 -0
- package/core/VueTemplatePoint.d.ts +51 -51
- package/core/VueTemplatePoint.js +529 -529
- package/index.d.ts +19 -18
- package/index.js +18 -17
- package/package.json +1 -1
- package/types.d.ts +340 -302
- package/types.js +11 -11
- package/utils/ErrorHandler.d.ts +102 -102
- package/utils/ErrorHandler.js +191 -191
- package/utils/ValidationUtils.d.ts +163 -163
- package/utils/ValidationUtils.js +312 -312
package/utils/ValidationUtils.js
CHANGED
|
@@ -1,312 +1,312 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 验证工具类
|
|
3
|
-
* 统一管理所有验证方法
|
|
4
|
-
*/
|
|
5
|
-
export class ValidationUtils {
|
|
6
|
-
/**
|
|
7
|
-
* 验证坐标是否有效
|
|
8
|
-
* @param longitude 经度
|
|
9
|
-
* @param latitude 纬度
|
|
10
|
-
* @returns 是否有效
|
|
11
|
-
*/
|
|
12
|
-
static isValidCoordinate(longitude, latitude) {
|
|
13
|
-
return (typeof longitude === 'number' &&
|
|
14
|
-
typeof latitude === 'number' &&
|
|
15
|
-
!isNaN(longitude) &&
|
|
16
|
-
!isNaN(latitude) &&
|
|
17
|
-
longitude >= -180 &&
|
|
18
|
-
longitude <= 180 &&
|
|
19
|
-
latitude >= -90 &&
|
|
20
|
-
latitude <= 90);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 验证经纬度坐标(简化版本)
|
|
24
|
-
* @param lgtd 经度
|
|
25
|
-
* @param lttd 纬度
|
|
26
|
-
* @returns 是否有效
|
|
27
|
-
*/
|
|
28
|
-
static validateLngLat(lgtd, lttd) {
|
|
29
|
-
if (!lgtd || !lttd || isNaN(lgtd) || isNaN(lttd)) {
|
|
30
|
-
console.error('Invalid longitude or latitude coordinates');
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 验证点数据数组
|
|
37
|
-
* @param pointData 点数据数组
|
|
38
|
-
* @returns 是否有效
|
|
39
|
-
*/
|
|
40
|
-
static validatePointData(pointData) {
|
|
41
|
-
if (!pointData || pointData.length === 0) {
|
|
42
|
-
console.warn('Point data is empty or undefined');
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 验证单个点的坐标
|
|
49
|
-
* @param item 包含坐标的数据项
|
|
50
|
-
* @returns 是否有效
|
|
51
|
-
*/
|
|
52
|
-
static validateCoordinates(item) {
|
|
53
|
-
if (!item.lgtd || !item.lttd) {
|
|
54
|
-
console.warn('Invalid coordinates for point:', item);
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 验证颜色字符串是否有效
|
|
61
|
-
* @param color 颜色字符串
|
|
62
|
-
* @returns 是否有效
|
|
63
|
-
*/
|
|
64
|
-
static isValidColor(color) {
|
|
65
|
-
if (!color || typeof color !== 'string') {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
// 简单的颜色格式验证
|
|
69
|
-
const colorRegex = /^(#[0-9A-Fa-f]{3,8}|rgba?\([^)]+\)|[a-zA-Z]+)$/;
|
|
70
|
-
return colorRegex.test(color);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* 验证图层名称是否有效
|
|
74
|
-
* @param layerName 图层名称
|
|
75
|
-
* @returns 是否有效
|
|
76
|
-
*/
|
|
77
|
-
static isValidLayerName(layerName) {
|
|
78
|
-
return (typeof layerName === 'string' &&
|
|
79
|
-
layerName.length > 0 &&
|
|
80
|
-
layerName.trim().length > 0);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* 验证范围是否有效
|
|
84
|
-
* @param extent 范围数组 [minX, minY, maxX, maxY]
|
|
85
|
-
* @returns 是否有效
|
|
86
|
-
*/
|
|
87
|
-
static isValidExtent(extent) {
|
|
88
|
-
return (Array.isArray(extent) &&
|
|
89
|
-
extent.length === 4 &&
|
|
90
|
-
extent.every(coord => typeof coord === 'number' && !isNaN(coord)) &&
|
|
91
|
-
extent[0] < extent[2] && // minX < maxX
|
|
92
|
-
extent[1] < extent[3] // minY < maxY
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 验证GeoJSON数据
|
|
97
|
-
* @param data GeoJSON数据
|
|
98
|
-
* @returns 是否有效
|
|
99
|
-
*/
|
|
100
|
-
static validateGeoJSONData(data) {
|
|
101
|
-
if (!data) {
|
|
102
|
-
console.warn('GeoJSON data is required');
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
if (!data.features || !Array.isArray(data.features)) {
|
|
106
|
-
console.warn('Invalid GeoJSON data: features array is required');
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* 验证配置选项
|
|
113
|
-
* @param options 配置选项
|
|
114
|
-
* @returns 是否有效
|
|
115
|
-
*/
|
|
116
|
-
static validateOptions(options) {
|
|
117
|
-
if (!options || typeof options !== 'object') {
|
|
118
|
-
console.warn('Options are required and must be an object');
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* 验证数值范围
|
|
125
|
-
* @param value 数值
|
|
126
|
-
* @param min 最小值
|
|
127
|
-
* @param max 最大值
|
|
128
|
-
* @returns 是否有效
|
|
129
|
-
*/
|
|
130
|
-
static validateNumberRange(value, min, max) {
|
|
131
|
-
return (typeof value === 'number' &&
|
|
132
|
-
!isNaN(value) &&
|
|
133
|
-
value >= min &&
|
|
134
|
-
value <= max);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 验证DOM元素ID
|
|
138
|
-
* @param id 元素ID
|
|
139
|
-
* @returns 是否有效
|
|
140
|
-
*/
|
|
141
|
-
static validateElementId(id) {
|
|
142
|
-
if (!id) {
|
|
143
|
-
console.error('Element ID is required');
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 验证Vue相关参数
|
|
150
|
-
* @param pointInfoList 点位信息列表
|
|
151
|
-
* @param template Vue组件模板
|
|
152
|
-
* @param Vue Vue实例
|
|
153
|
-
* @returns 是否有效
|
|
154
|
-
*/
|
|
155
|
-
static validateVueParams(pointInfoList, template, Vue) {
|
|
156
|
-
if (!pointInfoList || !Array.isArray(pointInfoList) || pointInfoList.length === 0) {
|
|
157
|
-
console.error('Valid point info list is required');
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
if (!template) {
|
|
161
|
-
console.error('Vue template is required');
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
if (!Vue) {
|
|
165
|
-
console.error('Vue instance is required');
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* 验证图层名称(抛出异常版本)
|
|
172
|
-
* @param layerName 图层名称
|
|
173
|
-
* @throws 如果图层名称无效则抛出异常
|
|
174
|
-
*/
|
|
175
|
-
static validateLayerName(layerName) {
|
|
176
|
-
if (!layerName) {
|
|
177
|
-
throw new Error('Layer name is required');
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* 验证图像数据
|
|
182
|
-
* @param imageData 图像数据
|
|
183
|
-
* @param allowEmptyImg 是否允许img为空
|
|
184
|
-
* @throws 如果图像数据无效则抛出异常
|
|
185
|
-
*/
|
|
186
|
-
static validateImageData(imageData, allowEmptyImg = false) {
|
|
187
|
-
if (!imageData) {
|
|
188
|
-
throw new Error('Invalid image data: imageData is required');
|
|
189
|
-
}
|
|
190
|
-
if (!allowEmptyImg && !imageData.img) {
|
|
191
|
-
throw new Error('Invalid image data: img is required');
|
|
192
|
-
}
|
|
193
|
-
if (imageData.extent && (!Array.isArray(imageData.extent) || imageData.extent.length !== 4)) {
|
|
194
|
-
throw new Error('Invalid extent: must be an array of 4 numbers [minX, minY, maxX, maxY]');
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 验证遮罩数据
|
|
199
|
-
* @param data 遮罩数据
|
|
200
|
-
* @throws 如果遮罩数据无效则抛出异常
|
|
201
|
-
*/
|
|
202
|
-
static validateMaskData(data) {
|
|
203
|
-
if (!data) {
|
|
204
|
-
throw new Error('Mask data is required');
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* 验证地图实例
|
|
209
|
-
* @param map 地图实例
|
|
210
|
-
* @throws 如果地图实例无效则抛出异常
|
|
211
|
-
*/
|
|
212
|
-
static validateMapInstance(map) {
|
|
213
|
-
if (!map) {
|
|
214
|
-
throw new Error('Map instance is required');
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* 验证必需参数
|
|
219
|
-
* @param value 要验证的值
|
|
220
|
-
* @param message 错误消息
|
|
221
|
-
* @throws 如果值为空则抛出异常
|
|
222
|
-
*/
|
|
223
|
-
static validateRequired(value, message) {
|
|
224
|
-
if (!value) {
|
|
225
|
-
throw new Error(message);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* 验证坐标(抛出异常版本)
|
|
230
|
-
* @param longitude 经度
|
|
231
|
-
* @param latitude 纬度
|
|
232
|
-
* @throws 如果坐标无效则抛出异常
|
|
233
|
-
*/
|
|
234
|
-
static validateCoordinate(longitude, latitude) {
|
|
235
|
-
if (typeof longitude !== 'number' || typeof latitude !== 'number') {
|
|
236
|
-
throw new Error('Longitude and latitude must be numbers');
|
|
237
|
-
}
|
|
238
|
-
if (isNaN(longitude) || isNaN(latitude)) {
|
|
239
|
-
throw new Error('Valid longitude and latitude are required');
|
|
240
|
-
}
|
|
241
|
-
if (longitude < -180 || longitude > 180) {
|
|
242
|
-
throw new Error('Longitude must be between -180 and 180');
|
|
243
|
-
}
|
|
244
|
-
if (latitude < -90 || latitude > 90) {
|
|
245
|
-
throw new Error('Latitude must be between -90 and 90');
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* 验证类型
|
|
250
|
-
* @param value 要验证的值
|
|
251
|
-
* @param expectedType 期望的类型
|
|
252
|
-
* @param message 错误消息
|
|
253
|
-
* @throws 如果类型不匹配则抛出异常
|
|
254
|
-
*/
|
|
255
|
-
static validateType(value, expectedType, message) {
|
|
256
|
-
if (typeof value !== expectedType) {
|
|
257
|
-
throw new Error(message);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* 验证非空字符串(抛出异常版本)
|
|
262
|
-
* @param str 字符串
|
|
263
|
-
* @param message 错误消息
|
|
264
|
-
* @throws 如果字符串为空则抛出异常
|
|
265
|
-
*/
|
|
266
|
-
static validateNonEmptyString(str, message) {
|
|
267
|
-
if (!str || typeof str !== 'string') {
|
|
268
|
-
throw new Error(message);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* 验证地图实例(通用版本)
|
|
273
|
-
* @param map 地图实例
|
|
274
|
-
* @throws 如果地图实例无效则抛出异常
|
|
275
|
-
*/
|
|
276
|
-
static validateMap(map) {
|
|
277
|
-
if (!map) {
|
|
278
|
-
throw new Error('Map instance is required');
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* 验证测量类型
|
|
283
|
-
* @param type 测量类型
|
|
284
|
-
* @throws 如果测量类型无效则抛出异常
|
|
285
|
-
*/
|
|
286
|
-
static validateMeasureType(type) {
|
|
287
|
-
if (!type || (type !== 'LineString' && type !== 'Polygon')) {
|
|
288
|
-
throw new Error('Invalid measure type. Must be "LineString" or "Polygon"');
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* 验证正数
|
|
293
|
-
* @param value 数值
|
|
294
|
-
* @param message 错误消息
|
|
295
|
-
* @throws 如果数值不是正数则抛出异常
|
|
296
|
-
*/
|
|
297
|
-
static validatePositiveNumber(value, message) {
|
|
298
|
-
if (!value || value <= 0) {
|
|
299
|
-
throw new Error(message);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* 验证图层名称参数
|
|
304
|
-
* @param layerName 图层名称(字符串或字符串数组)
|
|
305
|
-
* @throws 如果图层名称参数无效则抛出异常
|
|
306
|
-
*/
|
|
307
|
-
static validateLayerNameParam(layerName) {
|
|
308
|
-
if (!layerName || (typeof layerName !== 'string' && !Array.isArray(layerName))) {
|
|
309
|
-
throw new Error('Valid layer name is required');
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 验证工具类
|
|
3
|
+
* 统一管理所有验证方法
|
|
4
|
+
*/
|
|
5
|
+
export class ValidationUtils {
|
|
6
|
+
/**
|
|
7
|
+
* 验证坐标是否有效
|
|
8
|
+
* @param longitude 经度
|
|
9
|
+
* @param latitude 纬度
|
|
10
|
+
* @returns 是否有效
|
|
11
|
+
*/
|
|
12
|
+
static isValidCoordinate(longitude, latitude) {
|
|
13
|
+
return (typeof longitude === 'number' &&
|
|
14
|
+
typeof latitude === 'number' &&
|
|
15
|
+
!isNaN(longitude) &&
|
|
16
|
+
!isNaN(latitude) &&
|
|
17
|
+
longitude >= -180 &&
|
|
18
|
+
longitude <= 180 &&
|
|
19
|
+
latitude >= -90 &&
|
|
20
|
+
latitude <= 90);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 验证经纬度坐标(简化版本)
|
|
24
|
+
* @param lgtd 经度
|
|
25
|
+
* @param lttd 纬度
|
|
26
|
+
* @returns 是否有效
|
|
27
|
+
*/
|
|
28
|
+
static validateLngLat(lgtd, lttd) {
|
|
29
|
+
if (!lgtd || !lttd || isNaN(lgtd) || isNaN(lttd)) {
|
|
30
|
+
console.error('Invalid longitude or latitude coordinates');
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 验证点数据数组
|
|
37
|
+
* @param pointData 点数据数组
|
|
38
|
+
* @returns 是否有效
|
|
39
|
+
*/
|
|
40
|
+
static validatePointData(pointData) {
|
|
41
|
+
if (!pointData || pointData.length === 0) {
|
|
42
|
+
console.warn('Point data is empty or undefined');
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 验证单个点的坐标
|
|
49
|
+
* @param item 包含坐标的数据项
|
|
50
|
+
* @returns 是否有效
|
|
51
|
+
*/
|
|
52
|
+
static validateCoordinates(item) {
|
|
53
|
+
if (!item.lgtd || !item.lttd) {
|
|
54
|
+
console.warn('Invalid coordinates for point:', item);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 验证颜色字符串是否有效
|
|
61
|
+
* @param color 颜色字符串
|
|
62
|
+
* @returns 是否有效
|
|
63
|
+
*/
|
|
64
|
+
static isValidColor(color) {
|
|
65
|
+
if (!color || typeof color !== 'string') {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// 简单的颜色格式验证
|
|
69
|
+
const colorRegex = /^(#[0-9A-Fa-f]{3,8}|rgba?\([^)]+\)|[a-zA-Z]+)$/;
|
|
70
|
+
return colorRegex.test(color);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 验证图层名称是否有效
|
|
74
|
+
* @param layerName 图层名称
|
|
75
|
+
* @returns 是否有效
|
|
76
|
+
*/
|
|
77
|
+
static isValidLayerName(layerName) {
|
|
78
|
+
return (typeof layerName === 'string' &&
|
|
79
|
+
layerName.length > 0 &&
|
|
80
|
+
layerName.trim().length > 0);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 验证范围是否有效
|
|
84
|
+
* @param extent 范围数组 [minX, minY, maxX, maxY]
|
|
85
|
+
* @returns 是否有效
|
|
86
|
+
*/
|
|
87
|
+
static isValidExtent(extent) {
|
|
88
|
+
return (Array.isArray(extent) &&
|
|
89
|
+
extent.length === 4 &&
|
|
90
|
+
extent.every(coord => typeof coord === 'number' && !isNaN(coord)) &&
|
|
91
|
+
extent[0] < extent[2] && // minX < maxX
|
|
92
|
+
extent[1] < extent[3] // minY < maxY
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 验证GeoJSON数据
|
|
97
|
+
* @param data GeoJSON数据
|
|
98
|
+
* @returns 是否有效
|
|
99
|
+
*/
|
|
100
|
+
static validateGeoJSONData(data) {
|
|
101
|
+
if (!data) {
|
|
102
|
+
console.warn('GeoJSON data is required');
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (!data.features || !Array.isArray(data.features)) {
|
|
106
|
+
console.warn('Invalid GeoJSON data: features array is required');
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 验证配置选项
|
|
113
|
+
* @param options 配置选项
|
|
114
|
+
* @returns 是否有效
|
|
115
|
+
*/
|
|
116
|
+
static validateOptions(options) {
|
|
117
|
+
if (!options || typeof options !== 'object') {
|
|
118
|
+
console.warn('Options are required and must be an object');
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 验证数值范围
|
|
125
|
+
* @param value 数值
|
|
126
|
+
* @param min 最小值
|
|
127
|
+
* @param max 最大值
|
|
128
|
+
* @returns 是否有效
|
|
129
|
+
*/
|
|
130
|
+
static validateNumberRange(value, min, max) {
|
|
131
|
+
return (typeof value === 'number' &&
|
|
132
|
+
!isNaN(value) &&
|
|
133
|
+
value >= min &&
|
|
134
|
+
value <= max);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 验证DOM元素ID
|
|
138
|
+
* @param id 元素ID
|
|
139
|
+
* @returns 是否有效
|
|
140
|
+
*/
|
|
141
|
+
static validateElementId(id) {
|
|
142
|
+
if (!id) {
|
|
143
|
+
console.error('Element ID is required');
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 验证Vue相关参数
|
|
150
|
+
* @param pointInfoList 点位信息列表
|
|
151
|
+
* @param template Vue组件模板
|
|
152
|
+
* @param Vue Vue实例
|
|
153
|
+
* @returns 是否有效
|
|
154
|
+
*/
|
|
155
|
+
static validateVueParams(pointInfoList, template, Vue) {
|
|
156
|
+
if (!pointInfoList || !Array.isArray(pointInfoList) || pointInfoList.length === 0) {
|
|
157
|
+
console.error('Valid point info list is required');
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
if (!template) {
|
|
161
|
+
console.error('Vue template is required');
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (!Vue) {
|
|
165
|
+
console.error('Vue instance is required');
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 验证图层名称(抛出异常版本)
|
|
172
|
+
* @param layerName 图层名称
|
|
173
|
+
* @throws 如果图层名称无效则抛出异常
|
|
174
|
+
*/
|
|
175
|
+
static validateLayerName(layerName) {
|
|
176
|
+
if (!layerName) {
|
|
177
|
+
throw new Error('Layer name is required');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 验证图像数据
|
|
182
|
+
* @param imageData 图像数据
|
|
183
|
+
* @param allowEmptyImg 是否允许img为空
|
|
184
|
+
* @throws 如果图像数据无效则抛出异常
|
|
185
|
+
*/
|
|
186
|
+
static validateImageData(imageData, allowEmptyImg = false) {
|
|
187
|
+
if (!imageData) {
|
|
188
|
+
throw new Error('Invalid image data: imageData is required');
|
|
189
|
+
}
|
|
190
|
+
if (!allowEmptyImg && !imageData.img) {
|
|
191
|
+
throw new Error('Invalid image data: img is required');
|
|
192
|
+
}
|
|
193
|
+
if (imageData.extent && (!Array.isArray(imageData.extent) || imageData.extent.length !== 4)) {
|
|
194
|
+
throw new Error('Invalid extent: must be an array of 4 numbers [minX, minY, maxX, maxY]');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 验证遮罩数据
|
|
199
|
+
* @param data 遮罩数据
|
|
200
|
+
* @throws 如果遮罩数据无效则抛出异常
|
|
201
|
+
*/
|
|
202
|
+
static validateMaskData(data) {
|
|
203
|
+
if (!data) {
|
|
204
|
+
throw new Error('Mask data is required');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 验证地图实例
|
|
209
|
+
* @param map 地图实例
|
|
210
|
+
* @throws 如果地图实例无效则抛出异常
|
|
211
|
+
*/
|
|
212
|
+
static validateMapInstance(map) {
|
|
213
|
+
if (!map) {
|
|
214
|
+
throw new Error('Map instance is required');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 验证必需参数
|
|
219
|
+
* @param value 要验证的值
|
|
220
|
+
* @param message 错误消息
|
|
221
|
+
* @throws 如果值为空则抛出异常
|
|
222
|
+
*/
|
|
223
|
+
static validateRequired(value, message) {
|
|
224
|
+
if (!value) {
|
|
225
|
+
throw new Error(message);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 验证坐标(抛出异常版本)
|
|
230
|
+
* @param longitude 经度
|
|
231
|
+
* @param latitude 纬度
|
|
232
|
+
* @throws 如果坐标无效则抛出异常
|
|
233
|
+
*/
|
|
234
|
+
static validateCoordinate(longitude, latitude) {
|
|
235
|
+
if (typeof longitude !== 'number' || typeof latitude !== 'number') {
|
|
236
|
+
throw new Error('Longitude and latitude must be numbers');
|
|
237
|
+
}
|
|
238
|
+
if (isNaN(longitude) || isNaN(latitude)) {
|
|
239
|
+
throw new Error('Valid longitude and latitude are required');
|
|
240
|
+
}
|
|
241
|
+
if (longitude < -180 || longitude > 180) {
|
|
242
|
+
throw new Error('Longitude must be between -180 and 180');
|
|
243
|
+
}
|
|
244
|
+
if (latitude < -90 || latitude > 90) {
|
|
245
|
+
throw new Error('Latitude must be between -90 and 90');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 验证类型
|
|
250
|
+
* @param value 要验证的值
|
|
251
|
+
* @param expectedType 期望的类型
|
|
252
|
+
* @param message 错误消息
|
|
253
|
+
* @throws 如果类型不匹配则抛出异常
|
|
254
|
+
*/
|
|
255
|
+
static validateType(value, expectedType, message) {
|
|
256
|
+
if (typeof value !== expectedType) {
|
|
257
|
+
throw new Error(message);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 验证非空字符串(抛出异常版本)
|
|
262
|
+
* @param str 字符串
|
|
263
|
+
* @param message 错误消息
|
|
264
|
+
* @throws 如果字符串为空则抛出异常
|
|
265
|
+
*/
|
|
266
|
+
static validateNonEmptyString(str, message) {
|
|
267
|
+
if (!str || typeof str !== 'string') {
|
|
268
|
+
throw new Error(message);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 验证地图实例(通用版本)
|
|
273
|
+
* @param map 地图实例
|
|
274
|
+
* @throws 如果地图实例无效则抛出异常
|
|
275
|
+
*/
|
|
276
|
+
static validateMap(map) {
|
|
277
|
+
if (!map) {
|
|
278
|
+
throw new Error('Map instance is required');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 验证测量类型
|
|
283
|
+
* @param type 测量类型
|
|
284
|
+
* @throws 如果测量类型无效则抛出异常
|
|
285
|
+
*/
|
|
286
|
+
static validateMeasureType(type) {
|
|
287
|
+
if (!type || (type !== 'LineString' && type !== 'Polygon')) {
|
|
288
|
+
throw new Error('Invalid measure type. Must be "LineString" or "Polygon"');
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* 验证正数
|
|
293
|
+
* @param value 数值
|
|
294
|
+
* @param message 错误消息
|
|
295
|
+
* @throws 如果数值不是正数则抛出异常
|
|
296
|
+
*/
|
|
297
|
+
static validatePositiveNumber(value, message) {
|
|
298
|
+
if (!value || value <= 0) {
|
|
299
|
+
throw new Error(message);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* 验证图层名称参数
|
|
304
|
+
* @param layerName 图层名称(字符串或字符串数组)
|
|
305
|
+
* @throws 如果图层名称参数无效则抛出异常
|
|
306
|
+
*/
|
|
307
|
+
static validateLayerNameParam(layerName) {
|
|
308
|
+
if (!layerName || (typeof layerName !== 'string' && !Array.isArray(layerName))) {
|
|
309
|
+
throw new Error('Valid layer name is required');
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|