my-openlayer 2.4.8 → 2.4.10

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/core/Point.js CHANGED
@@ -262,9 +262,27 @@ export default class Point {
262
262
  addDomPoint(twinkleList, callback) {
263
263
  let anchors = [];
264
264
  twinkleList.forEach(twinkleItem => {
265
- // 创建DOM元素
266
- const element = document.createElement('div');
267
- element.className = twinkleItem.className || '';
265
+ let element;
266
+ // 创建或获取DOM元素
267
+ if (twinkleItem.element) {
268
+ if (typeof twinkleItem.element === 'function') {
269
+ element = twinkleItem.element(twinkleItem);
270
+ }
271
+ else {
272
+ element = twinkleItem.element;
273
+ }
274
+ // 如果有className,追加到自定义元素
275
+ if (twinkleItem.className) {
276
+ const classes = twinkleItem.className.split(/\s+/).filter(Boolean);
277
+ if (classes.length > 0) {
278
+ element.classList.add(...classes);
279
+ }
280
+ }
281
+ }
282
+ else {
283
+ element = document.createElement('div');
284
+ element.className = twinkleItem.className || '';
285
+ }
268
286
  // 添加点击事件
269
287
  if (callback) {
270
288
  element.addEventListener('click', () => {
@@ -1,57 +1,57 @@
1
- import { defineConfig } from 'vitepress'
2
-
3
- export default defineConfig({
4
- base: '/my-openlayer/',
5
- title: "MyOpenLayer",
6
- description: "基于 OpenLayers 的现代地图组件库",
7
- lang: 'zh-CN',
8
- themeConfig: {
9
- nav: [
10
- { text: '首页', link: '/' },
11
- { text: '指南', link: '/MyOl' },
12
- { text: 'API', link: '/MyOl' },
13
- { text: 'GitHub', link: 'https://github.com/cuteyuchen/my-openlayer' }
14
- ],
15
-
16
- sidebar: [
17
- {
18
- text: '核心类库',
19
- items: [
20
- { text: 'MyOl 地图入口', link: '/MyOl' },
21
- { text: 'MapBaseLayers 底图管理', link: '/MapBaseLayers' },
22
- { text: 'ConfigManager 配置管理', link: '/ConfigManager' },
23
- { text: 'EventManager 事件管理', link: '/EventManager' },
24
- { text: 'ErrorHandler 错误处理', link: '/ErrorHandler' }
25
- ]
26
- },
27
- {
28
- text: '要素操作',
29
- items: [
30
- { text: 'Point 点要素', link: '/Point' },
31
- { text: 'Line 线要素', link: '/Line' },
32
- { text: 'Polygon 面要素', link: '/Polygon' },
33
- { text: 'VueTemplatePoint Vue点位', link: '/VueTemplatePoint' },
34
- { text: 'RiverLayerManager 河流图层', link: '/RiverLayerManager' }
35
- ]
36
- },
37
- {
38
- text: '交互与工具',
39
- items: [
40
- { text: 'SelectHandler 要素选择', link: '/SelectHandler' },
41
- { text: 'MeasureHandler 测量工具', link: '/MeasureHandler' },
42
- { text: 'MapTools 地图工具', link: '/MapTools' },
43
- { text: 'ValidationUtils 验证工具', link: '/ValidationUtils' }
44
- ]
45
- }
46
- ],
47
-
48
- socialLinks: [
49
- { icon: 'github', link: 'https://github.com/cuteyuchen/my-openlayer' }
50
- ],
51
-
52
- footer: {
53
- message: 'Released under the MIT License.',
54
- copyright: 'Copyright © 2024-present'
55
- }
56
- }
57
- })
1
+ import { defineConfig } from 'vitepress'
2
+
3
+ export default defineConfig({
4
+ base: '/my-openlayer/',
5
+ title: "MyOpenLayer",
6
+ description: "基于 OpenLayers 的现代地图组件库",
7
+ lang: 'zh-CN',
8
+ themeConfig: {
9
+ nav: [
10
+ { text: '首页', link: '/' },
11
+ { text: '指南', link: '/MyOl' },
12
+ { text: 'API', link: '/MyOl' },
13
+ { text: 'GitHub', link: 'https://github.com/cuteyuchen/my-openlayer' }
14
+ ],
15
+
16
+ sidebar: [
17
+ {
18
+ text: '核心类库',
19
+ items: [
20
+ { text: 'MyOl 地图入口', link: '/MyOl' },
21
+ { text: 'MapBaseLayers 底图管理', link: '/MapBaseLayers' },
22
+ { text: 'ConfigManager 配置管理', link: '/ConfigManager' },
23
+ { text: 'EventManager 事件管理', link: '/EventManager' },
24
+ { text: 'ErrorHandler 错误处理', link: '/ErrorHandler' }
25
+ ]
26
+ },
27
+ {
28
+ text: '要素操作',
29
+ items: [
30
+ { text: 'Point 点要素', link: '/Point' },
31
+ { text: 'Line 线要素', link: '/Line' },
32
+ { text: 'Polygon 面要素', link: '/Polygon' },
33
+ { text: 'VueTemplatePoint Vue点位', link: '/VueTemplatePoint' },
34
+ { text: 'RiverLayerManager 河流图层', link: '/RiverLayerManager' }
35
+ ]
36
+ },
37
+ {
38
+ text: '交互与工具',
39
+ items: [
40
+ { text: 'SelectHandler 要素选择', link: '/SelectHandler' },
41
+ { text: 'MeasureHandler 测量工具', link: '/MeasureHandler' },
42
+ { text: 'MapTools 地图工具', link: '/MapTools' },
43
+ { text: 'ValidationUtils 验证工具', link: '/ValidationUtils' }
44
+ ]
45
+ }
46
+ ],
47
+
48
+ socialLinks: [
49
+ { icon: 'github', link: 'https://github.com/cuteyuchen/my-openlayer' }
50
+ ],
51
+
52
+ footer: {
53
+ message: 'Released under the MIT License.',
54
+ copyright: 'Copyright © 2024-present'
55
+ }
56
+ }
57
+ })
@@ -1,71 +1,71 @@
1
- # ConfigManager 配置管理
2
-
3
- `ConfigManager` 类用于统一管理地图组件的默认配置和常量。它提供了一系列静态只读属性,确保整个应用中使用一致的配置默认值。
4
-
5
- ## 导入
6
-
7
- ```typescript
8
- import { ConfigManager } from 'my-openlayer';
9
- ```
10
-
11
- ## 静态属性
12
-
13
- `ConfigManager` 包含以下类别的默认配置:
14
-
15
- ### 点位配置 (Point Options)
16
-
17
- | 属性名 | 类型 | 描述 | 默认值 |
18
- | :--- | :--- | :--- | :--- |
19
- | `DEFAULT_POINT_OPTIONS` | `object` | 默认点位基础配置 | `{ visible: true, zIndex: 21 }` |
20
- | `DEFAULT_POINT_TEXT_OPTIONS` | `object` | 默认点位文本配置 | `{ textFont: '12px Calibri,sans-serif', textFillColor: '#FFF', textStrokeColor: '#000', textStrokeWidth: 3, textOffsetY: 20 }` |
21
- | `DEFAULT_POINT_ICON_SCALE` | `number` | 默认图标缩放比例 | `1` |
22
- | `DEFAULT_CLUSTER_OPTIONS` | `object` | 默认聚合配置 | `{ distance: 40, minDistance: 0, zIndex: 21 }` |
23
- | `DEFAULT_DOM_POINT_OVERLAY_OPTIONS` | `object` | 默认 DOM 点覆盖物配置 | `{ positioning: 'center-center', stopEvent: false }` |
24
-
25
- ### 线配置 (Line Options)
26
-
27
- | 属性名 | 类型 | 描述 | 默认值 |
28
- | :--- | :--- | :--- | :--- |
29
- | `DEFAULT_LINE_OPTIONS` | `object` | 默认线样式配置 | `{ type: 'line', strokeColor: 'rgba(3, 122, 255, 1)', strokeWidth: 2, visible: true, layerName: 'lineLayer', zIndex: 15 }` |
30
-
31
- ### 面配置 (Polygon Options)
32
-
33
- | 属性名 | 类型 | 描述 | 默认值 |
34
- | :--- | :--- | :--- | :--- |
35
- | `DEFAULT_POLYGON_OPTIONS` | `object` | 默认面样式配置 | `{ zIndex: 11, visible: true, textFont: '14px Calibri,sans-serif', textFillColor: '#FFF', textStrokeColor: '#409EFF', textStrokeWidth: 2 }` |
36
- | `DEFAULT_POLYGON_COLOR_MAP` | `object` | 默认面颜色映射 (用于分级渲染) | `{ '0': 'rgba(255, 0, 0, 0.6)', '1': 'rgba(245, 154, 35, 0.6)', ... }` |
37
-
38
- ## 使用示例
39
-
40
- ### 获取默认配置
41
-
42
- ```typescript
43
- import { ConfigManager } from 'my-openlayer';
44
-
45
- // 获取默认点位配置
46
- const pointOptions = {
47
- ...ConfigManager.DEFAULT_POINT_OPTIONS,
48
- ...ConfigManager.DEFAULT_POINT_TEXT_OPTIONS
49
- };
50
-
51
- // 获取默认线配置
52
- const lineOptions = ConfigManager.DEFAULT_LINE_OPTIONS;
53
- ```
54
-
55
- ### 在自定义组件中使用
56
-
57
- ```typescript
58
- import { ConfigManager } from 'my-openlayer';
59
-
60
- class MyComponent {
61
- private options: any;
62
-
63
- constructor(options: any) {
64
- // 合并用户配置和默认配置
65
- this.options = {
66
- ...ConfigManager.DEFAULT_POINT_OPTIONS,
67
- ...options
68
- };
69
- }
70
- }
71
- ```
1
+ # ConfigManager 配置管理
2
+
3
+ `ConfigManager` 类用于统一管理地图组件的默认配置和常量。它提供了一系列静态只读属性,确保整个应用中使用一致的配置默认值。
4
+
5
+ ## 导入
6
+
7
+ ```typescript
8
+ import { ConfigManager } from 'my-openlayer';
9
+ ```
10
+
11
+ ## 静态属性
12
+
13
+ `ConfigManager` 包含以下类别的默认配置:
14
+
15
+ ### 点位配置 (Point Options)
16
+
17
+ | 属性名 | 类型 | 描述 | 默认值 |
18
+ | :--- | :--- | :--- | :--- |
19
+ | `DEFAULT_POINT_OPTIONS` | `object` | 默认点位基础配置 | `{ visible: true, zIndex: 21 }` |
20
+ | `DEFAULT_POINT_TEXT_OPTIONS` | `object` | 默认点位文本配置 | `{ textFont: '12px Calibri,sans-serif', textFillColor: '#FFF', textStrokeColor: '#000', textStrokeWidth: 3, textOffsetY: 20 }` |
21
+ | `DEFAULT_POINT_ICON_SCALE` | `number` | 默认图标缩放比例 | `1` |
22
+ | `DEFAULT_CLUSTER_OPTIONS` | `object` | 默认聚合配置 | `{ distance: 40, minDistance: 0, zIndex: 21 }` |
23
+ | `DEFAULT_DOM_POINT_OVERLAY_OPTIONS` | `object` | 默认 DOM 点覆盖物配置 | `{ positioning: 'center-center', stopEvent: false }` |
24
+
25
+ ### 线配置 (Line Options)
26
+
27
+ | 属性名 | 类型 | 描述 | 默认值 |
28
+ | :--- | :--- | :--- | :--- |
29
+ | `DEFAULT_LINE_OPTIONS` | `object` | 默认线样式配置 | `{ type: 'line', strokeColor: 'rgba(3, 122, 255, 1)', strokeWidth: 2, visible: true, layerName: 'lineLayer', zIndex: 15 }` |
30
+
31
+ ### 面配置 (Polygon Options)
32
+
33
+ | 属性名 | 类型 | 描述 | 默认值 |
34
+ | :--- | :--- | :--- | :--- |
35
+ | `DEFAULT_POLYGON_OPTIONS` | `object` | 默认面样式配置 | `{ zIndex: 11, visible: true, textFont: '14px Calibri,sans-serif', textFillColor: '#FFF', textStrokeColor: '#409EFF', textStrokeWidth: 2 }` |
36
+ | `DEFAULT_POLYGON_COLOR_MAP` | `object` | 默认面颜色映射 (用于分级渲染) | `{ '0': 'rgba(255, 0, 0, 0.6)', '1': 'rgba(245, 154, 35, 0.6)', ... }` |
37
+
38
+ ## 使用示例
39
+
40
+ ### 获取默认配置
41
+
42
+ ```typescript
43
+ import { ConfigManager } from 'my-openlayer';
44
+
45
+ // 获取默认点位配置
46
+ const pointOptions = {
47
+ ...ConfigManager.DEFAULT_POINT_OPTIONS,
48
+ ...ConfigManager.DEFAULT_POINT_TEXT_OPTIONS
49
+ };
50
+
51
+ // 获取默认线配置
52
+ const lineOptions = ConfigManager.DEFAULT_LINE_OPTIONS;
53
+ ```
54
+
55
+ ### 在自定义组件中使用
56
+
57
+ ```typescript
58
+ import { ConfigManager } from 'my-openlayer';
59
+
60
+ class MyComponent {
61
+ private options: any;
62
+
63
+ constructor(options: any) {
64
+ // 合并用户配置和默认配置
65
+ this.options = {
66
+ ...ConfigManager.DEFAULT_POINT_OPTIONS,
67
+ ...options
68
+ };
69
+ }
70
+ }
71
+ ```
@@ -1,106 +1,106 @@
1
- # ErrorHandler 错误处理
2
-
3
- `ErrorHandler` 类是一个单例工具类,用于统一管理和分发应用程序中的错误。它支持不同的日志级别,并允许注册自定义错误回调。
4
-
5
- ## 导入
6
-
7
- ```typescript
8
- import { ErrorHandler, ErrorType, MyOpenLayersError } from 'my-openlayer';
9
- ```
10
-
11
- ## 枚举与类定义
12
-
13
- ### ErrorType 枚举
14
-
15
- 定义了系统中可能的错误类型:
16
-
17
- | 成员 | 值 | 描述 |
18
- | :--- | :--- | :--- |
19
- | `VALIDATION_ERROR` | `'VALIDATION_ERROR'` | 参数验证错误 |
20
- | `MAP_ERROR` | `'MAP_ERROR'` | 地图相关错误 |
21
- | `LAYER_ERROR` | `'LAYER_ERROR'` | 图层相关错误 |
22
- | `COORDINATE_ERROR` | `'COORDINATE_ERROR'` | 坐标无效错误 |
23
- | `DATA_ERROR` | `'DATA_ERROR'` | 数据格式错误 |
24
- | `COMPONENT_ERROR` | `'COMPONENT_ERROR'` | 组件内部错误 |
25
-
26
- ### MyOpenLayersError 类
27
-
28
- 自定义错误类,继承自 `Error`。
29
-
30
- | 属性 | 类型 | 描述 |
31
- | :--- | :--- | :--- |
32
- | `message` | `string` | 错误消息 |
33
- | `type` | `ErrorType` | 错误类型 |
34
- | `timestamp` | `Date` | 错误发生的时间戳 |
35
- | `context` | `any` | 错误相关的上下文数据 |
36
-
37
- ## 方法
38
-
39
- ### 静态方法
40
-
41
- | 方法名 | 参数 | 返回值 | 描述 |
42
- | :--- | :--- | :--- | :--- |
43
- | `getInstance()` | - | `ErrorHandler` | 获取 `ErrorHandler` 的单例实例 |
44
- | `validate(condition, message, context?)` | `condition: boolean`<br>`message: string`<br>`context?: any` | `void` | 验证条件,如果为 `false` 则抛出 `VALIDATION_ERROR` |
45
- | `validateMap(map)` | `map: any` | `void` | 验证地图实例是否存在 |
46
- | `validateCoordinates(longitude, latitude)` | `longitude: number`<br>`latitude: number` | `void` | 验证经纬度坐标是否有效 |
47
- | `validateLayerName(layerName)` | `layerName: string` | `void` | 验证图层名称是否有效 |
48
- | `validateData(data, dataType)` | `data: any`<br>`dataType: string` | `void` | 验证数据是否存在 |
49
- | `safeExecute<T>(fn, errorMessage, errorType?, context?)` | `fn: () => T`<br>`errorMessage: string`<br>`errorType?: ErrorType`<br>`context?: any` | `T` | 安全执行函数,捕获并处理异常 |
50
-
51
- ### 实例方法
52
-
53
- | 方法名 | 参数 | 返回值 | 描述 |
54
- | :--- | :--- | :--- | :--- |
55
- | `setLogLevel(level)` | `level: 'debug' \| 'info' \| 'warn' \| 'error'` | `void` | 设置日志级别 |
56
- | `debug(...args)` | `...args: any[]` | `void` | 输出调试日志 |
57
- | `info(...args)` | `...args: any[]` | `void` | 输出信息日志 |
58
- | `warn(...args)` | `...args: any[]` | `void` | 输出警告日志 |
59
- | `createAndHandleError(message, type, context?)` | `message: string`<br>`type: ErrorType`<br>`context?: any` | `MyOpenLayersError` | 创建并处理错误,通知监听器 |
60
-
61
- ## 使用示例
62
-
63
- ### 基本验证
64
-
65
- ```typescript
66
- import { ErrorHandler } from 'my-openlayer';
67
-
68
- function setCenter(longitude: number, latitude: number) {
69
- // 验证坐标,如果不合法会自动抛出异常
70
- ErrorHandler.validateCoordinates(longitude, latitude);
71
-
72
- // ...设置中心点逻辑
73
- }
74
- ```
75
-
76
- ### 捕获和处理错误
77
-
78
- ```typescript
79
- import { ErrorHandler, ErrorType } from 'my-openlayer';
80
-
81
- try {
82
- // 可能出错的代码
83
- throw new Error('Something went wrong');
84
- } catch (error) {
85
- ErrorHandler.getInstance().createAndHandleError(
86
- 'Operation failed',
87
- ErrorType.COMPONENT_ERROR,
88
- { originalError: error }
89
- );
90
- }
91
- ```
92
-
93
- ### 安全执行函数
94
-
95
- ```typescript
96
- import { ErrorHandler } from 'my-openlayer';
97
-
98
- const result = ErrorHandler.safeExecute(
99
- () => {
100
- // 危险操作
101
- return JSON.parse(someJsonString);
102
- },
103
- 'Failed to parse JSON',
104
- ErrorType.DATA_ERROR
105
- );
106
- ```
1
+ # ErrorHandler 错误处理
2
+
3
+ `ErrorHandler` 类是一个单例工具类,用于统一管理和分发应用程序中的错误。它支持不同的日志级别,并允许注册自定义错误回调。
4
+
5
+ ## 导入
6
+
7
+ ```typescript
8
+ import { ErrorHandler, ErrorType, MyOpenLayersError } from 'my-openlayer';
9
+ ```
10
+
11
+ ## 枚举与类定义
12
+
13
+ ### ErrorType 枚举
14
+
15
+ 定义了系统中可能的错误类型:
16
+
17
+ | 成员 | 值 | 描述 |
18
+ | :--- | :--- | :--- |
19
+ | `VALIDATION_ERROR` | `'VALIDATION_ERROR'` | 参数验证错误 |
20
+ | `MAP_ERROR` | `'MAP_ERROR'` | 地图相关错误 |
21
+ | `LAYER_ERROR` | `'LAYER_ERROR'` | 图层相关错误 |
22
+ | `COORDINATE_ERROR` | `'COORDINATE_ERROR'` | 坐标无效错误 |
23
+ | `DATA_ERROR` | `'DATA_ERROR'` | 数据格式错误 |
24
+ | `COMPONENT_ERROR` | `'COMPONENT_ERROR'` | 组件内部错误 |
25
+
26
+ ### MyOpenLayersError 类
27
+
28
+ 自定义错误类,继承自 `Error`。
29
+
30
+ | 属性 | 类型 | 描述 |
31
+ | :--- | :--- | :--- |
32
+ | `message` | `string` | 错误消息 |
33
+ | `type` | `ErrorType` | 错误类型 |
34
+ | `timestamp` | `Date` | 错误发生的时间戳 |
35
+ | `context` | `any` | 错误相关的上下文数据 |
36
+
37
+ ## 方法
38
+
39
+ ### 静态方法
40
+
41
+ | 方法名 | 参数 | 返回值 | 描述 |
42
+ | :--- | :--- | :--- | :--- |
43
+ | `getInstance()` | - | `ErrorHandler` | 获取 `ErrorHandler` 的单例实例 |
44
+ | `validate(condition, message, context?)` | `condition: boolean`<br>`message: string`<br>`context?: any` | `void` | 验证条件,如果为 `false` 则抛出 `VALIDATION_ERROR` |
45
+ | `validateMap(map)` | `map: any` | `void` | 验证地图实例是否存在 |
46
+ | `validateCoordinates(longitude, latitude)` | `longitude: number`<br>`latitude: number` | `void` | 验证经纬度坐标是否有效 |
47
+ | `validateLayerName(layerName)` | `layerName: string` | `void` | 验证图层名称是否有效 |
48
+ | `validateData(data, dataType)` | `data: any`<br>`dataType: string` | `void` | 验证数据是否存在 |
49
+ | `safeExecute<T>(fn, errorMessage, errorType?, context?)` | `fn: () => T`<br>`errorMessage: string`<br>`errorType?: ErrorType`<br>`context?: any` | `T` | 安全执行函数,捕获并处理异常 |
50
+
51
+ ### 实例方法
52
+
53
+ | 方法名 | 参数 | 返回值 | 描述 |
54
+ | :--- | :--- | :--- | :--- |
55
+ | `setLogLevel(level)` | `level: 'debug' \| 'info' \| 'warn' \| 'error'` | `void` | 设置日志级别 |
56
+ | `debug(...args)` | `...args: any[]` | `void` | 输出调试日志 |
57
+ | `info(...args)` | `...args: any[]` | `void` | 输出信息日志 |
58
+ | `warn(...args)` | `...args: any[]` | `void` | 输出警告日志 |
59
+ | `createAndHandleError(message, type, context?)` | `message: string`<br>`type: ErrorType`<br>`context?: any` | `MyOpenLayersError` | 创建并处理错误,通知监听器 |
60
+
61
+ ## 使用示例
62
+
63
+ ### 基本验证
64
+
65
+ ```typescript
66
+ import { ErrorHandler } from 'my-openlayer';
67
+
68
+ function setCenter(longitude: number, latitude: number) {
69
+ // 验证坐标,如果不合法会自动抛出异常
70
+ ErrorHandler.validateCoordinates(longitude, latitude);
71
+
72
+ // ...设置中心点逻辑
73
+ }
74
+ ```
75
+
76
+ ### 捕获和处理错误
77
+
78
+ ```typescript
79
+ import { ErrorHandler, ErrorType } from 'my-openlayer';
80
+
81
+ try {
82
+ // 可能出错的代码
83
+ throw new Error('Something went wrong');
84
+ } catch (error) {
85
+ ErrorHandler.getInstance().createAndHandleError(
86
+ 'Operation failed',
87
+ ErrorType.COMPONENT_ERROR,
88
+ { originalError: error }
89
+ );
90
+ }
91
+ ```
92
+
93
+ ### 安全执行函数
94
+
95
+ ```typescript
96
+ import { ErrorHandler } from 'my-openlayer';
97
+
98
+ const result = ErrorHandler.safeExecute(
99
+ () => {
100
+ // 危险操作
101
+ return JSON.parse(someJsonString);
102
+ },
103
+ 'Failed to parse JSON',
104
+ ErrorType.DATA_ERROR
105
+ );
106
+ ```