my-openlayer 2.1.2 → 2.1.4

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.js CHANGED
@@ -34,10 +34,13 @@ class MyOl {
34
34
  this.configManager = new ConfigManager();
35
35
  // 合并配置(处理 undefined 情况)
36
36
  this.options = ConfigManager.mergeOptions(MyOl.DefaultOptions, options || {});
37
+ // 初始化日志配置(默认关闭,级别为 error)
38
+ this.errorHandler.setEnabled(this.options.enableLog ?? false);
39
+ this.errorHandler.setLogLevel(this.options.logLevel ?? 'error');
37
40
  // 参数验证
38
41
  this.validateConstructorParams(id, this.options);
39
42
  // 初始化坐标系
40
- MyOl.initializeProjections();
43
+ MyOl.initializeProjections(this.options);
41
44
  // 准备图层
42
45
  const layers = Array.isArray(this.options.layers) ? this.options.layers : [];
43
46
  // 创建地图实例
@@ -82,7 +85,7 @@ class MyOl {
82
85
  * 初始化坐标系
83
86
  * @private
84
87
  */
85
- static initializeProjections() {
88
+ static initializeProjections(options) {
86
89
  // 定义 CGCS2000 坐标系
87
90
  proj4.defs(MyOl.PROJECTIONS.CGCS2000, "+proj=longlat +ellps=GRS80 +no_defs");
88
91
  proj4.defs(MyOl.PROJECTIONS.CGCS2000_3_DEGREE, "+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");
@@ -96,6 +99,19 @@ class MyOl {
96
99
  units: "degrees"
97
100
  });
98
101
  olProjAddProjection(cgsc2000);
102
+ if (options.projection?.code) {
103
+ const code = options.projection.code;
104
+ if (options.projection.def) {
105
+ proj4.defs(code, options.projection.def);
106
+ }
107
+ const customProj = new olProjProjection({
108
+ code,
109
+ extent: options.projection.extent ?? cgsc2000.getExtent(),
110
+ worldExtent: options.projection.worldExtent ?? cgsc2000.getWorldExtent(),
111
+ units: options.projection.units ?? cgsc2000.getUnits()
112
+ });
113
+ olProjAddProjection(customProj);
114
+ }
99
115
  }
100
116
  /**
101
117
  * 创建地图控件
@@ -116,7 +132,7 @@ class MyOl {
116
132
  const eventManager = this.getEventManager();
117
133
  // 地图加载完成事件
118
134
  eventManager.on('rendercomplete', (eventData) => {
119
- console.debug('地图初始化完成', { map: this.map });
135
+ this.errorHandler.debug('地图初始化完成', { map: this.map });
120
136
  }, { once: true });
121
137
  // 地图错误事件
122
138
  eventManager.on('error', (eventData) => {
@@ -130,11 +146,12 @@ class MyOl {
130
146
  */
131
147
  static createView(options = MyOl.DefaultOptions) {
132
148
  try {
149
+ const code = options.projection?.code ?? MyOl.PROJECTIONS.CGCS2000;
133
150
  const projection = new olProjProjection({
134
- code: MyOl.PROJECTIONS.CGCS2000,
135
- extent: [-180, -90, 180, 90],
136
- worldExtent: [-180, -90, 180, 90],
137
- units: "degrees"
151
+ code,
152
+ extent: options.projection?.extent ?? [-180, -90, 180, 90],
153
+ worldExtent: options.projection?.worldExtent ?? [-180, -90, 180, 90],
154
+ units: options.projection?.units ?? "degrees"
138
155
  });
139
156
  const viewOptions = {
140
157
  projection,
@@ -155,7 +172,7 @@ class MyOl {
155
172
  * @deprecated 请使用 createView 方法
156
173
  */
157
174
  static getView(options = MyOl.DefaultOptions) {
158
- console.warn('getView 方法已废弃,请使用 createView 方法');
175
+ ErrorHandler.getInstance().warn('getView 方法已废弃,请使用 createView 方法');
159
176
  return MyOl.createView(options);
160
177
  }
161
178
  // ==========================================
@@ -169,7 +186,7 @@ class MyOl {
169
186
  try {
170
187
  if (!this._polygon) {
171
188
  this._polygon = new Polygon(this.map);
172
- console.debug('面要素模块已加载');
189
+ this.errorHandler.debug('面要素模块已加载');
173
190
  }
174
191
  return this._polygon;
175
192
  }
@@ -187,7 +204,7 @@ class MyOl {
187
204
  if (!this._baseLayers) {
188
205
  // 检查是否设置了自定义底图
189
206
  if (Array.isArray(this.options.layers)) {
190
- console.warn('已设置默认底图,MapBaseLayers 中的 switchBaseLayer 方法将失效');
207
+ this.errorHandler.warn('已设置默认底图,MapBaseLayers 中的 switchBaseLayer 方法将失效');
191
208
  }
192
209
  const layerOptions = {
193
210
  layers: this.options.layers,
@@ -198,7 +215,7 @@ class MyOl {
198
215
  token: this.options.token || ''
199
216
  };
200
217
  this._baseLayers = new MapBaseLayers(this.map, layerOptions);
201
- console.debug('基础图层模块已加载');
218
+ this.errorHandler.debug('基础图层模块已加载');
202
219
  }
203
220
  return this._baseLayers;
204
221
  }
@@ -215,7 +232,7 @@ class MyOl {
215
232
  try {
216
233
  if (!this._point) {
217
234
  this._point = new Point(this.map);
218
- console.debug('点要素模块已加载');
235
+ this.errorHandler.debug('点要素模块已加载');
219
236
  }
220
237
  return this._point;
221
238
  }
@@ -232,7 +249,7 @@ class MyOl {
232
249
  try {
233
250
  if (!this._line) {
234
251
  this._line = new Line(this.map);
235
- console.debug('线要素模块已加载');
252
+ this.errorHandler.debug('线要素模块已加载');
236
253
  }
237
254
  return this._line;
238
255
  }
@@ -249,7 +266,7 @@ class MyOl {
249
266
  try {
250
267
  if (!this._selectHandler) {
251
268
  this._selectHandler = new SelectHandler(this.map);
252
- console.debug('要素选择模块已加载');
269
+ this.errorHandler.debug('要素选择模块已加载');
253
270
  }
254
271
  return this._selectHandler;
255
272
  }
@@ -266,7 +283,7 @@ class MyOl {
266
283
  try {
267
284
  if (!this._mapTools) {
268
285
  this._mapTools = new MapTools(this.map);
269
- console.debug('工具模块已加载');
286
+ this.errorHandler.debug('工具模块已加载');
270
287
  }
271
288
  return this._mapTools;
272
289
  }
@@ -315,7 +332,7 @@ class MyOl {
315
332
  }
316
333
  this.getPoint().locationAction(longitude, latitude, zoom, duration);
317
334
  // 记录定位操作
318
- console.debug('地图定位完成', {
335
+ this.errorHandler.debug('地图定位完成', {
319
336
  longitude,
320
337
  latitude,
321
338
  zoom,
@@ -379,7 +396,7 @@ class MyOl {
379
396
  this._selectHandler = undefined;
380
397
  // 销毁地图
381
398
  this.map.setTarget(undefined);
382
- console.debug('地图实例已销毁', { map: this.map });
399
+ this.errorHandler.debug('地图实例已销毁', { map: this.map });
383
400
  }
384
401
  catch (error) {
385
402
  this.errorHandler.handleError(new MyOpenLayersError(`销毁地图失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.MAP_ERROR));
package/core/Line.js CHANGED
@@ -6,6 +6,7 @@ import { Feature } from "ol";
6
6
  import MapTools from "./MapTools";
7
7
  import { ValidationUtils } from "../utils/ValidationUtils";
8
8
  import { EventManager } from "./EventManager";
9
+ import { ErrorHandler } from "../utils/ErrorHandler";
9
10
  /**
10
11
  * 线要素管理类
11
12
  * 用于在地图上添加和管理线要素,包括普通线要素、河流图层等
@@ -183,7 +184,7 @@ export default class Line {
183
184
  }
184
185
  }
185
186
  catch (error) {
186
- console.warn(`Failed to load river feature at level ${level}:`, error);
187
+ ErrorHandler.getInstance().warn(`Failed to load river feature at level ${level}:`, error);
187
188
  }
188
189
  }
189
190
  });
@@ -278,14 +279,14 @@ export default class Line {
278
279
  }
279
280
  }
280
281
  catch (error) {
281
- console.warn(`Failed to load river feature at level ${level}:`, error);
282
+ ErrorHandler.getInstance().warn(`Failed to load river feature at level ${level}:`, error);
282
283
  }
283
284
  }
284
285
  });
285
286
  success?.(vectorSource.getFeatures());
286
287
  })
287
288
  .catch(error => {
288
- console.error('Error loading river data:', error);
289
+ ErrorHandler.getInstance().error('Error loading river data:', error);
289
290
  failure?.();
290
291
  });
291
292
  }
package/core/MapTools.js CHANGED
@@ -62,7 +62,7 @@ class MapTools {
62
62
  });
63
63
  }
64
64
  catch (error) {
65
- console.error('Error getting layers:', error);
65
+ ErrorHandler.getInstance().error('Error getting layers:', error);
66
66
  throw new Error('Failed to retrieve layers from map');
67
67
  }
68
68
  return targetLayer;
@@ -117,7 +117,7 @@ class MapTools {
117
117
  });
118
118
  }
119
119
  catch (error) {
120
- console.error('Error removing layers:', error);
120
+ ErrorHandler.getInstance().error('Error removing layers:', error);
121
121
  throw new Error('Failed to remove layers from map');
122
122
  }
123
123
  }
@@ -138,7 +138,7 @@ class MapTools {
138
138
  });
139
139
  }
140
140
  catch (error) {
141
- console.error('Error removing layers:', error);
141
+ ErrorHandler.getInstance().error('Error removing layers:', error);
142
142
  throw new Error('Failed to remove layers from map');
143
143
  }
144
144
  }
@@ -159,7 +159,7 @@ class MapTools {
159
159
  });
160
160
  }
161
161
  catch (error) {
162
- console.error('Error setting layer visibility:', error);
162
+ ErrorHandler.getInstance().error('Error setting layer visibility:', error);
163
163
  throw new Error('Failed to set layer visibility');
164
164
  }
165
165
  }
@@ -195,7 +195,7 @@ MapTools.setLayerVisible = (map, layerName, visible) => {
195
195
  });
196
196
  }
197
197
  catch (error) {
198
- console.error('Error setting layer visibility:', error);
198
+ ErrorHandler.getInstance().error('Error setting layer visibility:', error);
199
199
  throw new Error('Failed to set layer visibility');
200
200
  }
201
201
  };
@@ -7,6 +7,7 @@ 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
9
  import { ValidationUtils } from '../utils/ValidationUtils';
10
+ import { ErrorHandler } from '../utils/ErrorHandler';
10
11
  /**
11
12
  * 测量工具处理类
12
13
  * 提供距离和面积测量功能
@@ -171,7 +172,7 @@ export default class MeasureHandler {
171
172
  }
172
173
  }
173
174
  catch (error) {
174
- console.error('Error starting measurement:', error);
175
+ ErrorHandler.getInstance().error('Error starting measurement:', error);
175
176
  throw new Error('Failed to start measurement');
176
177
  }
177
178
  this._draw = new Draw({
package/core/Point.js CHANGED
@@ -11,6 +11,7 @@ import GeoJSON from "ol/format/GeoJSON";
11
11
  import VueTemplatePoint from './VueTemplatePoint';
12
12
  import MapTools from "./MapTools";
13
13
  import { ValidationUtils } from '../utils/ValidationUtils';
14
+ import { ErrorHandler } from '../utils/ErrorHandler';
14
15
  export default class Point {
15
16
  constructor(map) {
16
17
  this.map = map;
@@ -286,7 +287,7 @@ export default class Point {
286
287
  return true;
287
288
  }
288
289
  catch (error) {
289
- console.error('[地图定位]', '定位失败:', error);
290
+ ErrorHandler.getInstance().error('[地图定位]', '定位失败:', error);
290
291
  return false;
291
292
  }
292
293
  }
@@ -295,7 +296,7 @@ export default class Point {
295
296
  */
296
297
  addDomPoint(id, lgtd, lttd) {
297
298
  if (!id) {
298
- console.error('Element ID is required');
299
+ ErrorHandler.getInstance().error('Element ID is required');
299
300
  return false;
300
301
  }
301
302
  if (!ValidationUtils.validateLngLat(lgtd, lttd)) {
@@ -303,7 +304,7 @@ export default class Point {
303
304
  }
304
305
  const el = document.getElementById(id);
305
306
  if (!el) {
306
- console.error(`Element with id '${id}' not found`);
307
+ ErrorHandler.getInstance().error(`Element with id '${id}' not found`);
307
308
  return false;
308
309
  }
309
310
  try {
@@ -318,7 +319,7 @@ export default class Point {
318
319
  return true;
319
320
  }
320
321
  catch (error) {
321
- console.error('Failed to set DOM point:', error);
322
+ ErrorHandler.getInstance().error('Failed to set DOM point:', error);
322
323
  return false;
323
324
  }
324
325
  }
package/core/Polygon.js CHANGED
@@ -9,6 +9,7 @@ import { fromExtent } from "ol/geom/Polygon";
9
9
  import Feature from "ol/Feature";
10
10
  import ImageStatic from "ol/source/ImageStatic";
11
11
  import MapTools from "./MapTools";
12
+ import { ErrorHandler } from '../utils/ErrorHandler';
12
13
  import { ValidationUtils } from '../utils/ValidationUtils';
13
14
  /**
14
15
  * Polygon 类用于处理地图上的面要素操作
@@ -276,7 +277,7 @@ export default class Polygon {
276
277
  };
277
278
  const features = layer.getSource()?.getFeatures();
278
279
  if (!features) {
279
- console.warn(`No features found in layer '${layerName}'`);
280
+ ErrorHandler.getInstance().warn(`No features found in layer '${layerName}'`);
280
281
  return;
281
282
  }
282
283
  features.forEach((feature) => {
@@ -345,7 +346,7 @@ export default class Polygon {
345
346
  });
346
347
  }
347
348
  else {
348
- console.log('暂时不支持的类型');
349
+ ErrorHandler.getInstance().warn('暂时不支持的类型');
349
350
  }
350
351
  return group;
351
352
  }
@@ -578,7 +579,7 @@ export default class Polygon {
578
579
  throw new Error(`Invalid GeoJSON data: ${error}`);
579
580
  }
580
581
  if (!features || features.length === 0) {
581
- console.warn('No features found in mask data');
582
+ ErrorHandler.getInstance().warn('No features found in mask data');
582
583
  }
583
584
  const maskLayer = new VectorLayer({
584
585
  source: new VectorSource({ features }),
@@ -94,7 +94,7 @@ export default class SelectHandler {
94
94
  // 添加到地图
95
95
  this.map.addInteraction(this.selectInteraction);
96
96
  this.isEnabled = true;
97
- console.debug('要素选择已启用', { mode, options: mergedOptions });
97
+ this.errorHandler.debug('要素选择已启用', { mode, options: mergedOptions });
98
98
  return this;
99
99
  }
100
100
  catch (error) {
@@ -114,7 +114,7 @@ export default class SelectHandler {
114
114
  }
115
115
  this.isEnabled = false;
116
116
  this.currentMode = undefined;
117
- console.debug('要素选择已禁用');
117
+ this.errorHandler.debug('要素选择已禁用');
118
118
  return this;
119
119
  }
120
120
  catch (error) {
@@ -152,11 +152,11 @@ export default class SelectHandler {
152
152
  selectByIds(featureIds, options) {
153
153
  try {
154
154
  if (!this.selectInteraction) {
155
- console.warn('选择交互未启用,无法选择要素');
155
+ this.errorHandler.warn('选择交互未启用,无法选择要素');
156
156
  return this;
157
157
  }
158
158
  if (!featureIds || featureIds.length === 0) {
159
- console.warn('要素ID列表为空');
159
+ this.errorHandler.warn('要素ID列表为空');
160
160
  return this;
161
161
  }
162
162
  // 清除当前选择
@@ -216,7 +216,7 @@ export default class SelectHandler {
216
216
  selectByProperty(propertyName, propertyValue, options) {
217
217
  try {
218
218
  if (!this.selectInteraction) {
219
- console.warn('选择交互未启用,无法选择要素');
219
+ this.errorHandler.warn('选择交互未启用,无法选择要素');
220
220
  return this;
221
221
  }
222
222
  if (!propertyName) {
@@ -323,7 +323,7 @@ export default class SelectHandler {
323
323
  }
324
324
  }
325
325
  catch (error) {
326
- console.error('定位至要素失败:', error);
326
+ this.errorHandler.error('定位至要素失败:', error);
327
327
  }
328
328
  }
329
329
  /**
@@ -332,7 +332,7 @@ export default class SelectHandler {
332
332
  destroy() {
333
333
  try {
334
334
  this.disableSelect();
335
- console.debug('选择处理器已销毁');
335
+ this.errorHandler.debug('选择处理器已销毁');
336
336
  }
337
337
  catch (error) {
338
338
  this.errorHandler.handleError(new MyOpenLayersError(`销毁选择处理器失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.COMPONENT_ERROR));
@@ -442,7 +442,7 @@ export default class SelectHandler {
442
442
  */
443
443
  updateSelectStyle(selectStyle) {
444
444
  if (!this.selectInteraction) {
445
- console.warn('选择交互未启用,无法更新样式');
445
+ this.errorHandler.warn('选择交互未启用,无法更新样式');
446
446
  return this;
447
447
  }
448
448
  try {
@@ -484,7 +484,7 @@ export default class SelectHandler {
484
484
  options.onSelect(callbackEvent);
485
485
  }
486
486
  catch (error) {
487
- console.error('选择回调执行失败:', error);
487
+ this.errorHandler.error('选择回调执行失败:', error);
488
488
  }
489
489
  }
490
490
  // 触发取消选择回调
@@ -493,7 +493,7 @@ export default class SelectHandler {
493
493
  options.onDeselect(callbackEvent);
494
494
  }
495
495
  catch (error) {
496
- console.error('取消选择回调执行失败:', error);
496
+ this.errorHandler.error('取消选择回调执行失败:', error);
497
497
  }
498
498
  }
499
499
  });
@@ -20,7 +20,7 @@ async function detectAndImportVue() {
20
20
  }
21
21
  }
22
22
  catch (e) {
23
- console.warn('Vue not found. Please ensure Vue is installed in your project.');
23
+ ErrorHandler.getInstance().warn('Vue not found. Please ensure Vue is installed in your project.');
24
24
  Vue = null;
25
25
  }
26
26
  }
@@ -42,13 +42,13 @@ function detectVueSync() {
42
42
  isVue3 = !!(Vue.version?.startsWith('3') || Vue.createApp);
43
43
  }
44
44
  catch (e) {
45
- console.warn('Vue not found. Please ensure Vue is installed in your project.');
45
+ ErrorHandler.getInstance().warn('Vue not found. Please ensure Vue is installed in your project.');
46
46
  Vue = null;
47
47
  }
48
48
  }
49
49
  }
50
50
  catch (e) {
51
- console.warn('Failed to detect Vue:', e);
51
+ ErrorHandler.getInstance().warn('Failed to detect Vue:', e);
52
52
  }
53
53
  }
54
54
  // 初始化Vue导入
@@ -457,7 +457,7 @@ class VueTemplatePointInstanceImpl {
457
457
  */
458
458
  remove() {
459
459
  if (this.state === VueTemplatePointState.DESTROYED) {
460
- console.warn('DOM point already destroyed');
460
+ this.errorHandler.warn('DOM point already destroyed');
461
461
  return;
462
462
  }
463
463
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "2.1.2",
4
+ "version": "2.1.4",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
package/types.d.ts CHANGED
@@ -5,6 +5,7 @@ import View from "ol/View";
5
5
  import Feature, { FeatureLike } from "ol/Feature";
6
6
  import { Style } from "ol/style";
7
7
  import MapBrowserEvent from "ol/MapBrowserEvent";
8
+ import { Units } from "ol/proj/Units";
8
9
  export interface FeatureData {
9
10
  type: string;
10
11
  properties: any;
@@ -32,6 +33,15 @@ export interface MapInitType {
32
33
  mapClipData?: MapJSONData;
33
34
  token?: string;
34
35
  annotation?: boolean;
36
+ enableLog?: boolean;
37
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
38
+ projection?: {
39
+ code: string;
40
+ def?: string;
41
+ extent?: number[];
42
+ worldExtent?: number[];
43
+ units?: Units;
44
+ };
35
45
  }
36
46
  export type AnnotationType = 'cva_c' | 'cia_c' | 'cta_c';
37
47
  export type TiandituType = 'vec_c' | 'img_c' | 'ter_c';
@@ -25,6 +25,7 @@ export declare class ErrorHandler {
25
25
  private static instance;
26
26
  private errorCallbacks;
27
27
  private logLevel;
28
+ private enabled;
28
29
  private constructor();
29
30
  /**
30
31
  * 获取单例实例
@@ -35,6 +36,19 @@ export declare class ErrorHandler {
35
36
  * @param level 日志级别
36
37
  */
37
38
  setLogLevel(level: 'debug' | 'info' | 'warn' | 'error'): void;
39
+ /**
40
+ * 设置日志开关
41
+ * @param enabled 是否启用日志输出
42
+ */
43
+ setEnabled(enabled: boolean): void;
44
+ /**
45
+ * 日志门槛判断
46
+ */
47
+ private shouldLog;
48
+ debug(...args: any[]): void;
49
+ info(...args: any[]): void;
50
+ warn(...args: any[]): void;
51
+ error(...args: any[]): void;
38
52
  /**
39
53
  * 添加错误回调
40
54
  * @param callback 错误回调函数
@@ -37,6 +37,7 @@ export class ErrorHandler {
37
37
  constructor() {
38
38
  this.errorCallbacks = [];
39
39
  this.logLevel = 'error';
40
+ this.enabled = false;
40
41
  }
41
42
  /**
42
43
  * 获取单例实例
@@ -54,6 +55,45 @@ export class ErrorHandler {
54
55
  setLogLevel(level) {
55
56
  this.logLevel = level;
56
57
  }
58
+ /**
59
+ * 设置日志开关
60
+ * @param enabled 是否启用日志输出
61
+ */
62
+ setEnabled(enabled) {
63
+ this.enabled = enabled;
64
+ }
65
+ /**
66
+ * 日志门槛判断
67
+ */
68
+ shouldLog(target) {
69
+ const levelOrder = {
70
+ debug: 0,
71
+ info: 1,
72
+ warn: 2,
73
+ error: 3
74
+ };
75
+ return this.enabled && levelOrder[target] >= levelOrder[this.logLevel];
76
+ }
77
+ debug(...args) {
78
+ if (this.shouldLog('debug')) {
79
+ console.debug(...args);
80
+ }
81
+ }
82
+ info(...args) {
83
+ if (this.shouldLog('info')) {
84
+ console.info(...args);
85
+ }
86
+ }
87
+ warn(...args) {
88
+ if (this.shouldLog('warn')) {
89
+ console.warn(...args);
90
+ }
91
+ }
92
+ error(...args) {
93
+ if (this.shouldLog('error')) {
94
+ console.error(...args);
95
+ }
96
+ }
57
97
  /**
58
98
  * 添加错误回调
59
99
  * @param callback 错误回调函数
@@ -112,21 +152,7 @@ export class ErrorHandler {
112
152
  context: error.context,
113
153
  stack: error.stack
114
154
  };
115
- switch (this.logLevel) {
116
- case 'debug':
117
- console.debug(logMessage, logData);
118
- break;
119
- case 'info':
120
- console.info(logMessage, logData);
121
- break;
122
- case 'warn':
123
- console.warn(logMessage, logData);
124
- break;
125
- case 'error':
126
- default:
127
- console.error(logMessage, logData);
128
- break;
129
- }
155
+ this.error(logMessage, logData);
130
156
  }
131
157
  /**
132
158
  * 验证参数
@@ -1,7 +1,3 @@
1
- /**
2
- * 验证工具类
3
- * 统一管理所有验证方法
4
- */
5
1
  export declare class ValidationUtils {
6
2
  /**
7
3
  * 验证坐标是否有效
@@ -2,6 +2,7 @@
2
2
  * 验证工具类
3
3
  * 统一管理所有验证方法
4
4
  */
5
+ import { ErrorHandler } from './ErrorHandler';
5
6
  export class ValidationUtils {
6
7
  /**
7
8
  * 验证坐标是否有效
@@ -27,7 +28,7 @@ export class ValidationUtils {
27
28
  */
28
29
  static validateLngLat(lgtd, lttd) {
29
30
  if (!lgtd || !lttd || isNaN(lgtd) || isNaN(lttd)) {
30
- console.error('Invalid longitude or latitude coordinates');
31
+ ErrorHandler.getInstance().error('Invalid longitude or latitude coordinates');
31
32
  return false;
32
33
  }
33
34
  return true;
@@ -39,7 +40,7 @@ export class ValidationUtils {
39
40
  */
40
41
  static validatePointData(pointData) {
41
42
  if (!pointData || pointData.length === 0) {
42
- console.warn('Point data is empty or undefined');
43
+ ErrorHandler.getInstance().warn('Point data is empty or undefined');
43
44
  return false;
44
45
  }
45
46
  return true;
@@ -51,7 +52,7 @@ export class ValidationUtils {
51
52
  */
52
53
  static validateCoordinates(item) {
53
54
  if (!item.lgtd || !item.lttd) {
54
- console.warn('Invalid coordinates for point:', item);
55
+ ErrorHandler.getInstance().warn('Invalid coordinates for point:', item);
55
56
  return false;
56
57
  }
57
58
  return true;
@@ -99,11 +100,11 @@ export class ValidationUtils {
99
100
  */
100
101
  static validateGeoJSONData(data) {
101
102
  if (!data) {
102
- console.warn('GeoJSON data is required');
103
+ ErrorHandler.getInstance().warn('GeoJSON data is required');
103
104
  return false;
104
105
  }
105
106
  if (!data.features || !Array.isArray(data.features)) {
106
- console.warn('Invalid GeoJSON data: features array is required');
107
+ ErrorHandler.getInstance().warn('Invalid GeoJSON data: features array is required');
107
108
  return false;
108
109
  }
109
110
  return true;
@@ -115,7 +116,7 @@ export class ValidationUtils {
115
116
  */
116
117
  static validateOptions(options) {
117
118
  if (!options || typeof options !== 'object') {
118
- console.warn('Options are required and must be an object');
119
+ ErrorHandler.getInstance().warn('Options are required and must be an object');
119
120
  return false;
120
121
  }
121
122
  return true;
@@ -140,7 +141,7 @@ export class ValidationUtils {
140
141
  */
141
142
  static validateElementId(id) {
142
143
  if (!id) {
143
- console.error('Element ID is required');
144
+ ErrorHandler.getInstance().error('Element ID is required');
144
145
  return false;
145
146
  }
146
147
  return true;
@@ -154,15 +155,15 @@ export class ValidationUtils {
154
155
  */
155
156
  static validateVueParams(pointInfoList, template, Vue) {
156
157
  if (!pointInfoList || !Array.isArray(pointInfoList) || pointInfoList.length === 0) {
157
- console.error('Valid point info list is required');
158
+ ErrorHandler.getInstance().error('Valid point info list is required');
158
159
  return false;
159
160
  }
160
161
  if (!template) {
161
- console.error('Vue template is required');
162
+ ErrorHandler.getInstance().error('Vue template is required');
162
163
  return false;
163
164
  }
164
165
  if (!Vue) {
165
- console.error('Vue instance is required');
166
+ ErrorHandler.getInstance().error('Vue instance is required');
166
167
  return false;
167
168
  }
168
169
  return true;