my-openlayer 2.0.0 → 2.0.1

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,234 +1,234 @@
1
- /**
2
- * 地图底图图层管理类
3
- * 提供天地图底图、注记图层、GeoServer图层等功能
4
- * 支持图层切换、裁剪等高级功能
5
- */
6
- import Map from "ol/Map";
7
- import { Tile as TileLayer } from "ol/layer";
8
- import { TileWMS } from "ol/source";
9
- import WMTSTileGrid from "ol/tilegrid/WMTS";
10
- import XYZ from "ol/source/XYZ";
11
- import { MapLayersOptions, TiandituType, AnnotationLayerOptions, AnnotationType } from "../types";
12
- /**
13
- * GeoServer图层选项接口
14
- */
15
- interface GeoServerLayerOptions {
16
- /** 图层层级 */
17
- zIndex?: number;
18
- /** 图层可见性 */
19
- visible?: boolean;
20
- /** WMS版本 */
21
- version?: '1.1.1' | '1.3.0';
22
- /** 服务器类型 */
23
- serverType?: string;
24
- /** 跨域设置 */
25
- crossOrigin?: string;
26
- /** WMS参数 */
27
- params?: Record<string, any>;
28
- }
29
- /**
30
- * 天地图图层选项接口
31
- */
32
- interface TiandituLayerOptions {
33
- /** 图层类型 */
34
- type: TiandituType | string;
35
- /** 天地图token */
36
- token: string;
37
- /** 图层层级 */
38
- zIndex: number;
39
- /** 图层可见性 */
40
- visible: boolean;
41
- }
42
- /**
43
- * 地图底图图层管理类
44
- */
45
- export default class MapBaseLayers {
46
- private readonly map;
47
- private readonly options;
48
- private layers;
49
- private readonly errorHandler;
50
- private currentBaseLayerType;
51
- private currentAnnotationLayer;
52
- private currentAnnotationType;
53
- /**
54
- * 构造函数
55
- * @param map OpenLayers地图实例
56
- * @param options 图层配置选项
57
- */
58
- constructor(map: Map, options: MapLayersOptions);
59
- /**
60
- * 验证构造函数参数
61
- * @param map 地图实例
62
- * @param options 配置选项
63
- * @private
64
- */
65
- private validateConstructorParams;
66
- /**
67
- * 合并默认配置选项
68
- * @param options 用户配置选项
69
- * @returns 合并后的配置选项
70
- * @private
71
- */
72
- private mergeDefaultOptions;
73
- /**
74
- * 初始化图层
75
- * @private
76
- */
77
- private initializeLayers;
78
- /**
79
- * 初始化天地图图层
80
- * @private
81
- */
82
- private initTiandituLayers;
83
- /**
84
- * 加载默认注记图层(cia_c)
85
- * @param token 天地图token
86
- * @param baseZIndex 基础层级
87
- * @private
88
- */
89
- private loadDefaultAnnotationLayer;
90
- /**
91
- * 切换注记类别
92
- * @param annotationType 注记类型 ('cva_c' | 'cia_c' | 'cta_c')
93
- */
94
- switchAnnotationLayer(annotationType: AnnotationType): void;
95
- /**
96
- * 设置注记图层(私有方法,用于消除代码重复)
97
- * @param annotationType 注记类型
98
- * @param token 天地图token
99
- * @param baseZIndex 基础层级
100
- * @private
101
- */
102
- private setAnnotationLayer;
103
- /**
104
- * 获取当前注记类型
105
- * @returns 当前注记类型
106
- */
107
- getCurrentAnnotationType(): string | null;
108
- /**
109
- * 显示/隐藏注记图层
110
- * @param visible 是否可见
111
- */
112
- setAnnotationVisible(visible: boolean): void;
113
- /**
114
- * 检查注记图层是否可见
115
- * @returns 是否可见
116
- */
117
- isAnnotationVisible(): boolean;
118
- /**
119
- * 切换底图图层
120
- * @param type 图层类型
121
- */
122
- switchBaseLayer(type: TiandituType | string): void;
123
- /**
124
- * 获取当前底图类型
125
- * @returns 当前底图类型
126
- */
127
- getCurrentBaseLayerType(): string | null;
128
- /**
129
- * 获取可用的图层类型列表
130
- * @returns 图层类型数组
131
- */
132
- getAvailableLayerTypes(): string[];
133
- /**
134
- * 检查指定图层类型是否存在
135
- * @param type 图层类型
136
- * @returns 是否存在
137
- */
138
- hasLayerType(type: string): boolean;
139
- /**
140
- * 添加注记图层(实例方法)
141
- * @param options 注记图层选项(不包含token)
142
- * @returns 创建的图层
143
- */
144
- addAnnotationLayer(options: Omit<AnnotationLayerOptions, 'token'>): TileLayer<XYZ>;
145
- /**
146
- * 添加注记图层(静态方法)
147
- * @param map 地图实例
148
- * @param options 注记图层选项
149
- * @returns 创建的图层
150
- */
151
- static addAnnotationLayer(map: Map, options: AnnotationLayerOptions): TileLayer<XYZ>;
152
- /**
153
- * 将所有图层添加到地图
154
- * @private
155
- */
156
- private addMapLayer;
157
- /**
158
- * 处理图层(应用裁剪等)
159
- * @param layer 原始图层
160
- * @returns 处理后的图层
161
- * @private
162
- */
163
- private processLayer;
164
- /**
165
- * 添加GeoServer图层
166
- * @param url GeoServer服务URL
167
- * @param layerName 图层名称
168
- * @param options 图层选项
169
- * @returns 创建的WMS图层
170
- */
171
- addGeoServerLayer(url: string, layerName: string, options?: GeoServerLayerOptions): TileLayer<TileWMS>;
172
- /**
173
- * 创建天地图图层(实例方法)
174
- * @param options 天地图图层选项
175
- * @returns 创建的图层
176
- * @private
177
- */
178
- private createTiandituLayer;
179
- /**
180
- * 创建注记图层(实例方法)
181
- * @param options 注记图层选项
182
- * @returns 创建的图层
183
- * @private
184
- */
185
- private createAnnotationLayer;
186
- /**
187
- * 创建天地图底图图层(静态方法)
188
- * @param options 天地图图层选项
189
- * @returns 创建的图层
190
- */
191
- static getTiandiTuLayer(options: TiandituLayerOptions): TileLayer<XYZ>;
192
- /**
193
- * 创建天地图注记图层(静态方法)
194
- * @param options 注记图层选项
195
- * @returns 创建的图层
196
- */
197
- static createAnnotationLayer(options: AnnotationLayerOptions): TileLayer<XYZ>;
198
- /**
199
- * 获取天地图注记图层(向后兼容的静态方法)
200
- * @param options 注记图层选项
201
- * @returns 创建的图层
202
- * @deprecated 使用 createAnnotationLayer 替代
203
- */
204
- static getAnnotationLayer(options: AnnotationLayerOptions): TileLayer<XYZ>;
205
- /**
206
- * 创建WMTS瓦片网格
207
- * @param length 层级数量
208
- * @returns WMTS瓦片网格
209
- */
210
- static getTileGrid(length: number): WMTSTileGrid;
211
- /**
212
- * 移除指定类型的图层
213
- * @param type 图层类型
214
- */
215
- removeLayersByType(type: string): void;
216
- /**
217
- * 清除所有图层
218
- */
219
- clearAllLayers(): void;
220
- /**
221
- * 获取图层数量统计
222
- * @returns 图层统计信息
223
- */
224
- getLayerStats(): {
225
- totalTypes: number;
226
- totalLayers: number;
227
- layersByType: Record<string, number>;
228
- };
229
- /**
230
- * 销毁实例,清理资源
231
- */
232
- destroy(): void;
233
- }
234
- export {};
1
+ /**
2
+ * 地图底图图层管理类
3
+ * 提供天地图底图、注记图层、GeoServer图层等功能
4
+ * 支持图层切换、裁剪等高级功能
5
+ */
6
+ import Map from "ol/Map";
7
+ import { Tile as TileLayer } from "ol/layer";
8
+ import { TileWMS } from "ol/source";
9
+ import WMTSTileGrid from "ol/tilegrid/WMTS";
10
+ import XYZ from "ol/source/XYZ";
11
+ import { MapLayersOptions, TiandituType, AnnotationLayerOptions, AnnotationType } from "../types";
12
+ /**
13
+ * GeoServer图层选项接口
14
+ */
15
+ interface GeoServerLayerOptions {
16
+ /** 图层层级 */
17
+ zIndex?: number;
18
+ /** 图层可见性 */
19
+ visible?: boolean;
20
+ /** WMS版本 */
21
+ version?: '1.1.1' | '1.3.0';
22
+ /** 服务器类型 */
23
+ serverType?: string;
24
+ /** 跨域设置 */
25
+ crossOrigin?: string;
26
+ /** WMS参数 */
27
+ params?: Record<string, any>;
28
+ }
29
+ /**
30
+ * 天地图图层选项接口
31
+ */
32
+ interface TiandituLayerOptions {
33
+ /** 图层类型 */
34
+ type: TiandituType | string;
35
+ /** 天地图token */
36
+ token: string;
37
+ /** 图层层级 */
38
+ zIndex: number;
39
+ /** 图层可见性 */
40
+ visible: boolean;
41
+ }
42
+ /**
43
+ * 地图底图图层管理类
44
+ */
45
+ export default class MapBaseLayers {
46
+ private readonly map;
47
+ private readonly options;
48
+ private layers;
49
+ private readonly errorHandler;
50
+ private currentBaseLayerType;
51
+ private currentAnnotationLayer;
52
+ private currentAnnotationType;
53
+ /**
54
+ * 构造函数
55
+ * @param map OpenLayers地图实例
56
+ * @param options 图层配置选项
57
+ */
58
+ constructor(map: Map, options: MapLayersOptions);
59
+ /**
60
+ * 验证构造函数参数
61
+ * @param map 地图实例
62
+ * @param options 配置选项
63
+ * @private
64
+ */
65
+ private validateConstructorParams;
66
+ /**
67
+ * 合并默认配置选项
68
+ * @param options 用户配置选项
69
+ * @returns 合并后的配置选项
70
+ * @private
71
+ */
72
+ private mergeDefaultOptions;
73
+ /**
74
+ * 初始化图层
75
+ * @private
76
+ */
77
+ private initializeLayers;
78
+ /**
79
+ * 初始化天地图图层
80
+ * @private
81
+ */
82
+ private initTiandituLayers;
83
+ /**
84
+ * 加载默认注记图层(cia_c)
85
+ * @param token 天地图token
86
+ * @param baseZIndex 基础层级
87
+ * @private
88
+ */
89
+ private loadDefaultAnnotationLayer;
90
+ /**
91
+ * 切换注记类别
92
+ * @param annotationType 注记类型 ('cva_c' | 'cia_c' | 'cta_c')
93
+ */
94
+ switchAnnotationLayer(annotationType: AnnotationType): void;
95
+ /**
96
+ * 设置注记图层(私有方法,用于消除代码重复)
97
+ * @param annotationType 注记类型
98
+ * @param token 天地图token
99
+ * @param baseZIndex 基础层级
100
+ * @private
101
+ */
102
+ private setAnnotationLayer;
103
+ /**
104
+ * 获取当前注记类型
105
+ * @returns 当前注记类型
106
+ */
107
+ getCurrentAnnotationType(): string | null;
108
+ /**
109
+ * 显示/隐藏注记图层
110
+ * @param visible 是否可见
111
+ */
112
+ setAnnotationVisible(visible: boolean): void;
113
+ /**
114
+ * 检查注记图层是否可见
115
+ * @returns 是否可见
116
+ */
117
+ isAnnotationVisible(): boolean;
118
+ /**
119
+ * 切换底图图层
120
+ * @param type 图层类型
121
+ */
122
+ switchBaseLayer(type: TiandituType | string): void;
123
+ /**
124
+ * 获取当前底图类型
125
+ * @returns 当前底图类型
126
+ */
127
+ getCurrentBaseLayerType(): string | null;
128
+ /**
129
+ * 获取可用的图层类型列表
130
+ * @returns 图层类型数组
131
+ */
132
+ getAvailableLayerTypes(): string[];
133
+ /**
134
+ * 检查指定图层类型是否存在
135
+ * @param type 图层类型
136
+ * @returns 是否存在
137
+ */
138
+ hasLayerType(type: string): boolean;
139
+ /**
140
+ * 添加注记图层(实例方法)
141
+ * @param options 注记图层选项(不包含token)
142
+ * @returns 创建的图层
143
+ */
144
+ addAnnotationLayer(options: Omit<AnnotationLayerOptions, 'token'>): TileLayer<XYZ>;
145
+ /**
146
+ * 添加注记图层(静态方法)
147
+ * @param map 地图实例
148
+ * @param options 注记图层选项
149
+ * @returns 创建的图层
150
+ */
151
+ static addAnnotationLayer(map: Map, options: AnnotationLayerOptions): TileLayer<XYZ>;
152
+ /**
153
+ * 将所有图层添加到地图
154
+ * @private
155
+ */
156
+ private addMapLayer;
157
+ /**
158
+ * 处理图层(应用裁剪等)
159
+ * @param layer 原始图层
160
+ * @returns 处理后的图层
161
+ * @private
162
+ */
163
+ private processLayer;
164
+ /**
165
+ * 添加GeoServer图层
166
+ * @param url GeoServer服务URL
167
+ * @param layerName 图层名称
168
+ * @param options 图层选项
169
+ * @returns 创建的WMS图层
170
+ */
171
+ addGeoServerLayer(url: string, layerName: string, options?: GeoServerLayerOptions): TileLayer<TileWMS>;
172
+ /**
173
+ * 创建天地图图层(实例方法)
174
+ * @param options 天地图图层选项
175
+ * @returns 创建的图层
176
+ * @private
177
+ */
178
+ private createTiandituLayer;
179
+ /**
180
+ * 创建注记图层(实例方法)
181
+ * @param options 注记图层选项
182
+ * @returns 创建的图层
183
+ * @private
184
+ */
185
+ private createAnnotationLayer;
186
+ /**
187
+ * 创建天地图底图图层(静态方法)
188
+ * @param options 天地图图层选项
189
+ * @returns 创建的图层
190
+ */
191
+ static getTiandiTuLayer(options: TiandituLayerOptions): TileLayer<XYZ>;
192
+ /**
193
+ * 创建天地图注记图层(静态方法)
194
+ * @param options 注记图层选项
195
+ * @returns 创建的图层
196
+ */
197
+ static createAnnotationLayer(options: AnnotationLayerOptions): TileLayer<XYZ>;
198
+ /**
199
+ * 获取天地图注记图层(向后兼容的静态方法)
200
+ * @param options 注记图层选项
201
+ * @returns 创建的图层
202
+ * @deprecated 使用 createAnnotationLayer 替代
203
+ */
204
+ static getAnnotationLayer(options: AnnotationLayerOptions): TileLayer<XYZ>;
205
+ /**
206
+ * 创建WMTS瓦片网格
207
+ * @param length 层级数量
208
+ * @returns WMTS瓦片网格
209
+ */
210
+ static getTileGrid(length: number): WMTSTileGrid;
211
+ /**
212
+ * 移除指定类型的图层
213
+ * @param type 图层类型
214
+ */
215
+ removeLayersByType(type: string): void;
216
+ /**
217
+ * 清除所有图层
218
+ */
219
+ clearAllLayers(): void;
220
+ /**
221
+ * 获取图层数量统计
222
+ * @returns 图层统计信息
223
+ */
224
+ getLayerStats(): {
225
+ totalTypes: number;
226
+ totalLayers: number;
227
+ layersByType: Record<string, number>;
228
+ };
229
+ /**
230
+ * 销毁实例,清理资源
231
+ */
232
+ destroy(): void;
233
+ }
234
+ export {};