my-openlayer 0.1.17 → 1.0.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.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * 配置管理类
3
+ * 用于统一管理默认配置和验证
4
+ */
5
+ export declare class ConfigManager {
6
+ /**
7
+ * 默认点位配置
8
+ */
9
+ static readonly DEFAULT_POINT_OPTIONS: {
10
+ strokeColor: string;
11
+ strokeWidth: number;
12
+ fillColor: string;
13
+ opacity: number;
14
+ visible: boolean;
15
+ layerName: string;
16
+ zIndex: number;
17
+ };
18
+ /**
19
+ * 默认线配置
20
+ */
21
+ static readonly DEFAULT_LINE_OPTIONS: {
22
+ strokeColor: string;
23
+ strokeWidth: number;
24
+ opacity: number;
25
+ visible: boolean;
26
+ layerName: string;
27
+ zIndex: number;
28
+ };
29
+ /**
30
+ * 默认面配置
31
+ */
32
+ static readonly DEFAULT_POLYGON_OPTIONS: {
33
+ strokeColor: string;
34
+ strokeWidth: number;
35
+ fillColor: string;
36
+ opacity: number;
37
+ visible: boolean;
38
+ layerName: string;
39
+ zIndex: number;
40
+ };
41
+ /**
42
+ * 默认图片图层配置
43
+ */
44
+ static readonly DEFAULT_IMAGE_OPTIONS: {
45
+ opacity: number;
46
+ visible: boolean;
47
+ layerName: string;
48
+ zIndex: number;
49
+ };
50
+ /**
51
+ * 默认遮罩图层配置
52
+ */
53
+ static readonly DEFAULT_MASK_OPTIONS: {
54
+ fillColor: string;
55
+ opacity: number;
56
+ visible: boolean;
57
+ layerName: string;
58
+ zIndex: number;
59
+ };
60
+ /**
61
+ * 默认文本配置
62
+ */
63
+ static readonly DEFAULT_TEXT_OPTIONS: {
64
+ textFont: string;
65
+ textFillColor: string;
66
+ textStrokeColor: string;
67
+ textStrokeWidth: number;
68
+ };
69
+ /**
70
+ * 验证坐标是否有效
71
+ * @param longitude 经度
72
+ * @param latitude 纬度
73
+ * @returns 是否有效
74
+ */
75
+ static isValidCoordinate(longitude: number, latitude: number): boolean;
76
+ /**
77
+ * 验证颜色字符串是否有效
78
+ * @param color 颜色字符串
79
+ * @returns 是否有效
80
+ */
81
+ static isValidColor(color: string): boolean;
82
+ /**
83
+ * 验证图层名称是否有效
84
+ * @param layerName 图层名称
85
+ * @returns 是否有效
86
+ */
87
+ static isValidLayerName(layerName: string): boolean;
88
+ /**
89
+ * 验证范围是否有效
90
+ * @param extent 范围数组 [minX, minY, maxX, maxY]
91
+ * @returns 是否有效
92
+ */
93
+ static isValidExtent(extent: number[]): boolean;
94
+ /**
95
+ * 合并配置选项
96
+ * @param defaultOptions 默认配置
97
+ * @param userOptions 用户配置
98
+ * @returns 合并后的配置
99
+ */
100
+ static mergeOptions<T extends Record<string, any>>(defaultOptions: T, userOptions?: Partial<T>): T;
101
+ /**
102
+ * 生成唯一ID
103
+ * @param prefix 前缀
104
+ * @returns 唯一ID
105
+ */
106
+ static generateId(prefix?: string): string;
107
+ /**
108
+ * 深度克隆对象
109
+ * @param obj 要克隆的对象
110
+ * @returns 克隆后的对象
111
+ */
112
+ static deepClone<T>(obj: T): T;
113
+ }
@@ -0,0 +1,164 @@
1
+ /**
2
+ * 配置管理类
3
+ * 用于统一管理默认配置和验证
4
+ */
5
+ export class ConfigManager {
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 color 颜色字符串
25
+ * @returns 是否有效
26
+ */
27
+ static isValidColor(color) {
28
+ if (!color || typeof color !== 'string') {
29
+ return false;
30
+ }
31
+ // 简单的颜色格式验证
32
+ const colorRegex = /^(#[0-9A-Fa-f]{3,8}|rgba?\([^)]+\)|[a-zA-Z]+)$/;
33
+ return colorRegex.test(color);
34
+ }
35
+ /**
36
+ * 验证图层名称是否有效
37
+ * @param layerName 图层名称
38
+ * @returns 是否有效
39
+ */
40
+ static isValidLayerName(layerName) {
41
+ return (typeof layerName === 'string' &&
42
+ layerName.length > 0 &&
43
+ layerName.trim().length > 0);
44
+ }
45
+ /**
46
+ * 验证范围是否有效
47
+ * @param extent 范围数组 [minX, minY, maxX, maxY]
48
+ * @returns 是否有效
49
+ */
50
+ static isValidExtent(extent) {
51
+ return (Array.isArray(extent) &&
52
+ extent.length === 4 &&
53
+ extent.every(coord => typeof coord === 'number' && !isNaN(coord)) &&
54
+ extent[0] < extent[2] && // minX < maxX
55
+ extent[1] < extent[3] // minY < maxY
56
+ );
57
+ }
58
+ /**
59
+ * 合并配置选项
60
+ * @param defaultOptions 默认配置
61
+ * @param userOptions 用户配置
62
+ * @returns 合并后的配置
63
+ */
64
+ static mergeOptions(defaultOptions, userOptions) {
65
+ return {
66
+ ...defaultOptions,
67
+ ...userOptions
68
+ };
69
+ }
70
+ /**
71
+ * 生成唯一ID
72
+ * @param prefix 前缀
73
+ * @returns 唯一ID
74
+ */
75
+ static generateId(prefix = 'id') {
76
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
77
+ }
78
+ /**
79
+ * 深度克隆对象
80
+ * @param obj 要克隆的对象
81
+ * @returns 克隆后的对象
82
+ */
83
+ static deepClone(obj) {
84
+ if (obj === null || typeof obj !== 'object') {
85
+ return obj;
86
+ }
87
+ if (obj instanceof Date) {
88
+ return new Date(obj.getTime());
89
+ }
90
+ if (Array.isArray(obj)) {
91
+ return obj.map(item => ConfigManager.deepClone(item));
92
+ }
93
+ const cloned = {};
94
+ for (const key in obj) {
95
+ if (obj.hasOwnProperty(key)) {
96
+ cloned[key] = ConfigManager.deepClone(obj[key]);
97
+ }
98
+ }
99
+ return cloned;
100
+ }
101
+ }
102
+ /**
103
+ * 默认点位配置
104
+ */
105
+ ConfigManager.DEFAULT_POINT_OPTIONS = {
106
+ strokeColor: '#409EFF',
107
+ strokeWidth: 2,
108
+ fillColor: 'rgba(64, 158, 255, 0.3)',
109
+ opacity: 1,
110
+ visible: true,
111
+ layerName: 'pointLayer',
112
+ zIndex: 10
113
+ };
114
+ /**
115
+ * 默认线配置
116
+ */
117
+ ConfigManager.DEFAULT_LINE_OPTIONS = {
118
+ strokeColor: '#409EFF',
119
+ strokeWidth: 2,
120
+ opacity: 1,
121
+ visible: true,
122
+ layerName: 'lineLayer',
123
+ zIndex: 10
124
+ };
125
+ /**
126
+ * 默认面配置
127
+ */
128
+ ConfigManager.DEFAULT_POLYGON_OPTIONS = {
129
+ strokeColor: '#EBEEF5',
130
+ strokeWidth: 2,
131
+ fillColor: 'rgba(255, 255, 255, 0.3)',
132
+ opacity: 1,
133
+ visible: true,
134
+ layerName: 'polygonLayer',
135
+ zIndex: 10
136
+ };
137
+ /**
138
+ * 默认图片图层配置
139
+ */
140
+ ConfigManager.DEFAULT_IMAGE_OPTIONS = {
141
+ opacity: 1,
142
+ visible: true,
143
+ layerName: 'imageLayer',
144
+ zIndex: 11
145
+ };
146
+ /**
147
+ * 默认遮罩图层配置
148
+ */
149
+ ConfigManager.DEFAULT_MASK_OPTIONS = {
150
+ fillColor: 'rgba(0, 0, 0, 0.5)',
151
+ opacity: 1,
152
+ visible: true,
153
+ layerName: 'maskLayer',
154
+ zIndex: 12
155
+ };
156
+ /**
157
+ * 默认文本配置
158
+ */
159
+ ConfigManager.DEFAULT_TEXT_OPTIONS = {
160
+ textFont: '14px Calibri,sans-serif',
161
+ textFillColor: '#FFF',
162
+ textStrokeColor: '#409EFF',
163
+ textStrokeWidth: 2
164
+ };
@@ -1,21 +1,170 @@
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
- }
1
+ import { Map } from 'ol';
2
+ import Overlay from 'ol/Overlay';
3
+ import { Coordinate } from 'ol/coordinate';
4
+ import { DomPointOptions, DomPointState } from '../types';
5
+ /**
6
+ * DOM点位管理类
7
+ * 用于在地图上添加和管理DOM元素覆盖物
8
+ */
12
9
  export default class DomPoint {
13
- private map;
10
+ private readonly map;
11
+ private readonly errorHandler;
14
12
  private app;
15
13
  private readonly anchor;
16
14
  private readonly dom;
17
- constructor(map: Map, options: Options);
15
+ private readonly id;
16
+ private readonly options;
17
+ private state;
18
+ private position;
19
+ /**
20
+ * 构造函数
21
+ * @param map OpenLayers地图实例
22
+ * @param options 配置选项
23
+ * @throws 当参数无效时抛出错误
24
+ */
25
+ constructor(map: Map, options: DomPointOptions);
26
+ /**
27
+ * 验证构造函数参数
28
+ * @param map 地图实例
29
+ * @param options 配置选项
30
+ * @private
31
+ */
32
+ private validateConstructorParams;
33
+ /**
34
+ * 合并默认配置选项
35
+ * @param options 用户配置选项
36
+ * @returns 合并后的配置选项
37
+ * @private
38
+ */
39
+ private mergeDefaultOptions;
40
+ /**
41
+ * 生成唯一ID
42
+ * @returns 唯一标识符
43
+ * @private
44
+ */
45
+ private generateUniqueId;
46
+ /**
47
+ * 创建DOM元素
48
+ * @returns DOM元素
49
+ * @private
50
+ */
51
+ private createDomElement;
52
+ /**
53
+ * 创建Vue应用实例
54
+ * @private
55
+ */
56
+ private createVueApp;
57
+ /**
58
+ * 判断是否为Vue 3
59
+ * @param Vue Vue构造函数
60
+ * @returns 是否为Vue 3
61
+ * @private
62
+ */
63
+ private isVue3;
64
+ /**
65
+ * 创建覆盖层
66
+ * @returns 覆盖层实例
67
+ * @private
68
+ */
69
+ private createOverlay;
70
+ /**
71
+ * 错误处理
72
+ * @param message 错误消息
73
+ * @param error 原始错误
74
+ * @param context 错误上下文
75
+ * @private
76
+ */
77
+ private handleError;
78
+ /**
79
+ * 设置可见性
80
+ * @param visible 是否可见
81
+ * @throws 当操作失败时抛出错误
82
+ */
18
83
  setVisible(visible: boolean): void;
84
+ /**
85
+ * 获取当前可见性状态
86
+ * @returns 是否可见
87
+ */
88
+ isVisible(): boolean;
89
+ /**
90
+ * 更新位置
91
+ * @param longitude 新经度
92
+ * @param latitude 新纬度
93
+ * @throws 当操作失败时抛出错误
94
+ */
95
+ updatePosition(longitude: number, latitude: number): void;
96
+ /**
97
+ * 获取当前位置
98
+ * @returns 当前坐标位置
99
+ */
100
+ getPosition(): Coordinate;
101
+ /**
102
+ * 更新组件属性
103
+ * @param newProps 新的属性对象
104
+ * @throws 当操作失败时抛出错误
105
+ */
106
+ updateProps(newProps: Record<string, any>): void;
107
+ /**
108
+ * 设置CSS样式
109
+ * @param styles 样式对象
110
+ * @throws 当操作失败时抛出错误
111
+ */
112
+ setStyle(styles: Partial<CSSStyleDeclaration>): void;
113
+ /**
114
+ * 添加CSS类名
115
+ * @param className 要添加的类名
116
+ * @throws 当操作失败时抛出错误
117
+ */
118
+ addClass(className: string): void;
119
+ /**
120
+ * 移除CSS类名
121
+ * @param className 要移除的类名
122
+ * @throws 当操作失败时抛出错误
123
+ */
124
+ removeClass(className: string): void;
125
+ /**
126
+ * 销毁Vue应用实例
127
+ * @private
128
+ */
129
+ private destroyVueApp;
130
+ /**
131
+ * 移除点位
132
+ * @throws 当移除失败时抛出错误
133
+ */
19
134
  remove(): void;
135
+ /**
136
+ * 获取覆盖层
137
+ * @returns 覆盖层实例
138
+ */
139
+ getOverlay(): Overlay;
140
+ /**
141
+ * 获取点位ID
142
+ * @returns 点位唯一标识符
143
+ */
144
+ getId(): string;
145
+ /**
146
+ * 获取DOM元素
147
+ * @returns DOM元素
148
+ */
149
+ getDomElement(): HTMLElement;
150
+ /**
151
+ * 获取当前状态
152
+ * @returns 当前状态
153
+ */
154
+ getState(): DomPointState;
155
+ /**
156
+ * 获取配置选项
157
+ * @returns 配置选项的副本
158
+ */
159
+ getOptions(): Readonly<DomPointOptions>;
160
+ /**
161
+ * 检查是否已销毁
162
+ * @returns 是否已销毁
163
+ */
164
+ isDestroyed(): boolean;
165
+ /**
166
+ * 获取地图实例
167
+ * @returns 地图实例
168
+ */
169
+ getMap(): Map;
20
170
  }
21
- export {};