my-openlayer 1.0.14 → 2.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.
@@ -1,112 +1,112 @@
1
- /**
2
- * 配置管理类
3
- * 用于统一管理默认配置和验证
4
- */
5
- export class ConfigManager {
6
- /**
7
- * 合并配置选项
8
- * @param defaultOptions 默认配置
9
- * @param userOptions 用户配置
10
- * @returns 合并后的配置
11
- */
12
- static mergeOptions(defaultOptions, userOptions) {
13
- return {
14
- ...defaultOptions,
15
- ...userOptions
16
- };
17
- }
18
- /**
19
- * 生成唯一ID
20
- * @param prefix 前缀
21
- * @returns 唯一ID
22
- */
23
- static generateId(prefix = 'id') {
24
- return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
25
- }
26
- /**
27
- * 深度克隆对象
28
- * @param obj 要克隆的对象
29
- * @returns 克隆后的对象
30
- */
31
- static deepClone(obj) {
32
- if (obj === null || typeof obj !== 'object') {
33
- return obj;
34
- }
35
- if (obj instanceof Date) {
36
- return new Date(obj.getTime());
37
- }
38
- if (Array.isArray(obj)) {
39
- return obj.map(item => ConfigManager.deepClone(item));
40
- }
41
- const cloned = {};
42
- for (const key in obj) {
43
- if (obj.hasOwnProperty(key)) {
44
- cloned[key] = ConfigManager.deepClone(obj[key]);
45
- }
46
- }
47
- return cloned;
48
- }
49
- }
50
- /**
51
- * 默认点位配置
52
- */
53
- ConfigManager.DEFAULT_POINT_OPTIONS = {
54
- strokeColor: '#409EFF',
55
- strokeWidth: 2,
56
- fillColor: 'rgba(64, 158, 255, 0.3)',
57
- opacity: 1,
58
- visible: true,
59
- layerName: 'pointLayer',
60
- zIndex: 10
61
- };
62
- /**
63
- * 默认线配置
64
- */
65
- ConfigManager.DEFAULT_LINE_OPTIONS = {
66
- strokeColor: '#409EFF',
67
- strokeWidth: 2,
68
- opacity: 1,
69
- visible: true,
70
- layerName: 'lineLayer',
71
- zIndex: 10
72
- };
73
- /**
74
- * 默认面配置
75
- */
76
- ConfigManager.DEFAULT_POLYGON_OPTIONS = {
77
- strokeColor: '#EBEEF5',
78
- strokeWidth: 2,
79
- fillColor: 'rgba(255, 255, 255, 0.3)',
80
- opacity: 1,
81
- visible: true,
82
- layerName: 'polygonLayer',
83
- zIndex: 10
84
- };
85
- /**
86
- * 默认图片图层配置
87
- */
88
- ConfigManager.DEFAULT_IMAGE_OPTIONS = {
89
- opacity: 1,
90
- visible: true,
91
- layerName: 'imageLayer',
92
- zIndex: 11
93
- };
94
- /**
95
- * 默认遮罩图层配置
96
- */
97
- ConfigManager.DEFAULT_MASK_OPTIONS = {
98
- fillColor: 'rgba(0, 0, 0, 0.5)',
99
- opacity: 1,
100
- visible: true,
101
- layerName: 'maskLayer',
102
- zIndex: 12
103
- };
104
- /**
105
- * 默认文本配置
106
- */
107
- ConfigManager.DEFAULT_TEXT_OPTIONS = {
108
- textFont: '14px Calibri,sans-serif',
109
- textFillColor: '#FFF',
110
- textStrokeColor: '#409EFF',
111
- textStrokeWidth: 2
112
- };
1
+ /**
2
+ * 配置管理类
3
+ * 用于统一管理默认配置和验证
4
+ */
5
+ export class ConfigManager {
6
+ /**
7
+ * 合并配置选项
8
+ * @param defaultOptions 默认配置
9
+ * @param userOptions 用户配置
10
+ * @returns 合并后的配置
11
+ */
12
+ static mergeOptions(defaultOptions, userOptions) {
13
+ return {
14
+ ...defaultOptions,
15
+ ...userOptions
16
+ };
17
+ }
18
+ /**
19
+ * 生成唯一ID
20
+ * @param prefix 前缀
21
+ * @returns 唯一ID
22
+ */
23
+ static generateId(prefix = 'id') {
24
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
25
+ }
26
+ /**
27
+ * 深度克隆对象
28
+ * @param obj 要克隆的对象
29
+ * @returns 克隆后的对象
30
+ */
31
+ static deepClone(obj) {
32
+ if (obj === null || typeof obj !== 'object') {
33
+ return obj;
34
+ }
35
+ if (obj instanceof Date) {
36
+ return new Date(obj.getTime());
37
+ }
38
+ if (Array.isArray(obj)) {
39
+ return obj.map(item => ConfigManager.deepClone(item));
40
+ }
41
+ const cloned = {};
42
+ for (const key in obj) {
43
+ if (obj.hasOwnProperty(key)) {
44
+ cloned[key] = ConfigManager.deepClone(obj[key]);
45
+ }
46
+ }
47
+ return cloned;
48
+ }
49
+ }
50
+ /**
51
+ * 默认点位配置
52
+ */
53
+ ConfigManager.DEFAULT_POINT_OPTIONS = {
54
+ strokeColor: '#409EFF',
55
+ strokeWidth: 2,
56
+ fillColor: 'rgba(64, 158, 255, 0.3)',
57
+ opacity: 1,
58
+ visible: true,
59
+ layerName: 'pointLayer',
60
+ zIndex: 10
61
+ };
62
+ /**
63
+ * 默认线配置
64
+ */
65
+ ConfigManager.DEFAULT_LINE_OPTIONS = {
66
+ strokeColor: '#409EFF',
67
+ strokeWidth: 2,
68
+ opacity: 1,
69
+ visible: true,
70
+ layerName: 'lineLayer',
71
+ zIndex: 10
72
+ };
73
+ /**
74
+ * 默认面配置
75
+ */
76
+ ConfigManager.DEFAULT_POLYGON_OPTIONS = {
77
+ strokeColor: '#EBEEF5',
78
+ strokeWidth: 2,
79
+ fillColor: 'rgba(255, 255, 255, 0.3)',
80
+ opacity: 1,
81
+ visible: true,
82
+ layerName: 'polygonLayer',
83
+ zIndex: 10
84
+ };
85
+ /**
86
+ * 默认图片图层配置
87
+ */
88
+ ConfigManager.DEFAULT_IMAGE_OPTIONS = {
89
+ opacity: 1,
90
+ visible: true,
91
+ layerName: 'imageLayer',
92
+ zIndex: 11
93
+ };
94
+ /**
95
+ * 默认遮罩图层配置
96
+ */
97
+ ConfigManager.DEFAULT_MASK_OPTIONS = {
98
+ fillColor: 'rgba(0, 0, 0, 0.5)',
99
+ opacity: 1,
100
+ visible: true,
101
+ layerName: 'maskLayer',
102
+ zIndex: 12
103
+ };
104
+ /**
105
+ * 默认文本配置
106
+ */
107
+ ConfigManager.DEFAULT_TEXT_OPTIONS = {
108
+ textFont: '14px Calibri,sans-serif',
109
+ textFillColor: '#FFF',
110
+ textStrokeColor: '#409EFF',
111
+ textStrokeWidth: 2
112
+ };
@@ -0,0 +1,21 @@
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 {};
@@ -0,0 +1,36 @@
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
+ }
@@ -1,141 +1,141 @@
1
- import { Map as OLMap } from 'ol';
2
- import { Pixel } from 'ol/pixel';
3
- import { FeatureLike } from 'ol/Feature';
4
- /**
5
- * 事件类型定义
6
- */
7
- export type MapEventType = 'click' | 'dblclick' | 'hover' | 'moveend' | 'zoomend' | 'pointermove' | 'rendercomplete' | 'error';
8
- /**
9
- * 事件回调函数类型
10
- */
11
- export type EventCallback = (event: MapEventData) => void;
12
- /**
13
- * 地图事件数据接口
14
- */
15
- export interface MapEventData {
16
- type: MapEventType;
17
- originalEvent?: Event;
18
- coordinate?: number[];
19
- pixel?: Pixel;
20
- features?: FeatureLike[];
21
- feature?: FeatureLike;
22
- zoom?: number;
23
- [key: string]: any;
24
- }
25
- /**
26
- * 事件管理器类
27
- * 用于统一管理地图事件的注册、触发和移除
28
- */
29
- export declare class EventManager {
30
- private readonly map;
31
- private listeners;
32
- private eventCounters;
33
- private mapEventListeners;
34
- /**
35
- * 构造函数
36
- * @param map OpenLayers地图实例
37
- */
38
- constructor(map: OLMap);
39
- /**
40
- * 初始化事件计数器
41
- */
42
- private initializeEventCounters;
43
- /**
44
- * 注册事件监听器
45
- * @param type 事件类型
46
- * @param callback 回调函数
47
- * @param options 选项
48
- * @returns 事件监听器ID
49
- */
50
- on(type: MapEventType, callback: EventCallback, options?: {
51
- once?: boolean;
52
- filter?: (event: MapEventData) => boolean;
53
- }): string;
54
- /**
55
- * 移除事件监听器
56
- * @param id 监听器ID
57
- */
58
- off(id: string): boolean;
59
- /**
60
- * 移除指定类型的所有事件监听器
61
- * @param type 事件类型
62
- */
63
- offAll(type: MapEventType): void;
64
- /**
65
- * 清除所有事件监听器
66
- */
67
- clear(): void;
68
- /**
69
- * 获取指定类型的监听器数量
70
- * @param type 事件类型
71
- */
72
- getListenerCount(type: MapEventType): number;
73
- /**
74
- * 生成监听器ID
75
- * @param type 事件类型
76
- */
77
- private generateListenerId;
78
- /**
79
- * 附加地图事件
80
- * @param type 事件类型
81
- */
82
- private attachMapEvent;
83
- /**
84
- * 移除地图事件监听器
85
- * @param type 事件类型
86
- */
87
- private detachMapEvent;
88
- /**
89
- * 处理点击事件
90
- * @param event 地图浏览器事件
91
- */
92
- private handleClickEvent;
93
- /**
94
- * 处理双击事件
95
- * @param event 地图浏览器事件
96
- */
97
- private handleDblClickEvent;
98
- /**
99
- * 处理指针移动事件
100
- * @param event 地图浏览器事件
101
- */
102
- private handlePointerMoveEvent;
103
- /**
104
- * 处理移动结束事件
105
- */
106
- private handleMoveEndEvent;
107
- /**
108
- * 处理缩放结束事件
109
- */
110
- private handleZoomEndEvent;
111
- /**
112
- * 处理渲染完成事件
113
- */
114
- private handleRenderCompleteEvent;
115
- /**
116
- * 处理错误事件
117
- * @param error 错误对象
118
- */
119
- private handleErrorEvent;
120
- /**
121
- * 创建事件数据
122
- * @param type 事件类型
123
- * @param event 原始事件
124
- */
125
- private createEventData;
126
- /**
127
- * 触发监听器
128
- * @param type 事件类型
129
- * @param eventData 事件数据
130
- */
131
- private triggerListeners;
132
- /**
133
- * 获取监听器信息(用于调试)
134
- */
135
- getListenersInfo(): Array<{
136
- id: string;
137
- type: MapEventType;
138
- hasFilter: boolean;
139
- isOnce: boolean;
140
- }>;
141
- }
1
+ import { Map as OLMap } from 'ol';
2
+ import { Pixel } from 'ol/pixel';
3
+ import { FeatureLike } from 'ol/Feature';
4
+ /**
5
+ * 事件类型定义
6
+ */
7
+ export type MapEventType = 'click' | 'dblclick' | 'hover' | 'moveend' | 'zoomend' | 'pointermove' | 'rendercomplete' | 'error';
8
+ /**
9
+ * 事件回调函数类型
10
+ */
11
+ export type EventCallback = (event: MapEventData) => void;
12
+ /**
13
+ * 地图事件数据接口
14
+ */
15
+ export interface MapEventData {
16
+ type: MapEventType;
17
+ originalEvent?: Event;
18
+ coordinate?: number[];
19
+ pixel?: Pixel;
20
+ features?: FeatureLike[];
21
+ feature?: FeatureLike;
22
+ zoom?: number;
23
+ [key: string]: any;
24
+ }
25
+ /**
26
+ * 事件管理器类
27
+ * 用于统一管理地图事件的注册、触发和移除
28
+ */
29
+ export declare class EventManager {
30
+ private readonly map;
31
+ private listeners;
32
+ private eventCounters;
33
+ private mapEventListeners;
34
+ /**
35
+ * 构造函数
36
+ * @param map OpenLayers地图实例
37
+ */
38
+ constructor(map: OLMap);
39
+ /**
40
+ * 初始化事件计数器
41
+ */
42
+ private initializeEventCounters;
43
+ /**
44
+ * 注册事件监听器
45
+ * @param type 事件类型
46
+ * @param callback 回调函数
47
+ * @param options 选项
48
+ * @returns 事件监听器ID
49
+ */
50
+ on(type: MapEventType, callback: EventCallback, options?: {
51
+ once?: boolean;
52
+ filter?: (event: MapEventData) => boolean;
53
+ }): string;
54
+ /**
55
+ * 移除事件监听器
56
+ * @param id 监听器ID
57
+ */
58
+ off(id: string): boolean;
59
+ /**
60
+ * 移除指定类型的所有事件监听器
61
+ * @param type 事件类型
62
+ */
63
+ offAll(type: MapEventType): void;
64
+ /**
65
+ * 清除所有事件监听器
66
+ */
67
+ clear(): void;
68
+ /**
69
+ * 获取指定类型的监听器数量
70
+ * @param type 事件类型
71
+ */
72
+ getListenerCount(type: MapEventType): number;
73
+ /**
74
+ * 生成监听器ID
75
+ * @param type 事件类型
76
+ */
77
+ private generateListenerId;
78
+ /**
79
+ * 附加地图事件
80
+ * @param type 事件类型
81
+ */
82
+ private attachMapEvent;
83
+ /**
84
+ * 移除地图事件监听器
85
+ * @param type 事件类型
86
+ */
87
+ private detachMapEvent;
88
+ /**
89
+ * 处理点击事件
90
+ * @param event 地图浏览器事件
91
+ */
92
+ private handleClickEvent;
93
+ /**
94
+ * 处理双击事件
95
+ * @param event 地图浏览器事件
96
+ */
97
+ private handleDblClickEvent;
98
+ /**
99
+ * 处理指针移动事件
100
+ * @param event 地图浏览器事件
101
+ */
102
+ private handlePointerMoveEvent;
103
+ /**
104
+ * 处理移动结束事件
105
+ */
106
+ private handleMoveEndEvent;
107
+ /**
108
+ * 处理缩放结束事件
109
+ */
110
+ private handleZoomEndEvent;
111
+ /**
112
+ * 处理渲染完成事件
113
+ */
114
+ private handleRenderCompleteEvent;
115
+ /**
116
+ * 处理错误事件
117
+ * @param error 错误对象
118
+ */
119
+ private handleErrorEvent;
120
+ /**
121
+ * 创建事件数据
122
+ * @param type 事件类型
123
+ * @param event 原始事件
124
+ */
125
+ private createEventData;
126
+ /**
127
+ * 触发监听器
128
+ * @param type 事件类型
129
+ * @param eventData 事件数据
130
+ */
131
+ private triggerListeners;
132
+ /**
133
+ * 获取监听器信息(用于调试)
134
+ */
135
+ getListenersInfo(): Array<{
136
+ id: string;
137
+ type: MapEventType;
138
+ hasFilter: boolean;
139
+ isOnce: boolean;
140
+ }>;
141
+ }