my-openlayer 1.0.12 → 1.0.13

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.
@@ -8,7 +8,7 @@ import { Tile as TileLayer } from "ol/layer";
8
8
  import { TileWMS } from "ol/source";
9
9
  import WMTSTileGrid from "ol/tilegrid/WMTS";
10
10
  import XYZ from "ol/source/XYZ";
11
- import { MapLayersOptions, TiandituType, AnnotationLayerOptions } from "../types";
11
+ import { MapLayersOptions, TiandituType, AnnotationLayerOptions, AnnotationType } from "../types";
12
12
  /**
13
13
  * GeoServer图层选项接口
14
14
  */
@@ -31,7 +31,7 @@ interface GeoServerLayerOptions {
31
31
  */
32
32
  interface TiandituLayerOptions {
33
33
  /** 图层类型 */
34
- type: TiandituType;
34
+ type: TiandituType | string;
35
35
  /** 天地图token */
36
36
  token: string;
37
37
  /** 图层层级 */
@@ -91,7 +91,7 @@ export default class MapBaseLayers {
91
91
  * 切换注记类别
92
92
  * @param annotationType 注记类型 ('cva_c' | 'cia_c' | 'cta_c')
93
93
  */
94
- switchAnnotationLayer(annotationType: 'cva_c' | 'cia_c' | 'cta_c'): void;
94
+ switchAnnotationLayer(annotationType: AnnotationType): void;
95
95
  /**
96
96
  * 设置注记图层(私有方法,用于消除代码重复)
97
97
  * @param annotationType 注记类型
@@ -119,7 +119,7 @@ export default class MapBaseLayers {
119
119
  * 切换底图图层
120
120
  * @param type 图层类型
121
121
  */
122
- switchBaseLayer(type: TiandituType): void;
122
+ switchBaseLayer(type: TiandituType | string): void;
123
123
  /**
124
124
  * 获取当前底图类型
125
125
  * @returns 当前底图类型
@@ -21,6 +21,7 @@ const TIANDITU_CONFIG = {
21
21
  DEFAULT_ZINDEX: 9,
22
22
  ANNOTATION_ZINDEX_OFFSET: 10
23
23
  };
24
+ const TIANDITU_TYPES = ['vec_c', 'img_c', 'ter_c'];
24
25
  /**
25
26
  * 地图底图图层管理类
26
27
  */
@@ -42,7 +43,14 @@ export default class MapBaseLayers {
42
43
  this.map = map;
43
44
  this.options = this.mergeDefaultOptions(options);
44
45
  // 初始化图层
45
- this.initializeLayers();
46
+ if (this.options?.token) {
47
+ this.initializeLayers();
48
+ }
49
+ if (this.layers && Object.keys(this.layers).length > 0) {
50
+ this.addMapLayer();
51
+ const firstLayerType = Object.keys(this.layers)[0];
52
+ this.switchBaseLayer(firstLayerType);
53
+ }
46
54
  }
47
55
  catch (error) {
48
56
  this.errorHandler.createAndHandleError(`Failed to initialize MapBaseLayers: ${error}`, ErrorType.MAP_ERROR, { map, options, error });
@@ -86,11 +94,6 @@ export default class MapBaseLayers {
86
94
  throw new Error('请配置token后才能使用天地图底图');
87
95
  }
88
96
  this.initTiandituLayers();
89
- if (this.layers && Object.keys(this.layers).length > 0) {
90
- this.addMapLayer();
91
- const firstLayerType = Object.keys(this.layers)[0];
92
- this.switchBaseLayer(firstLayerType);
93
- }
94
97
  }
95
98
  // 添加注记图层
96
99
  if (this.options.annotation) {
@@ -208,6 +211,10 @@ export default class MapBaseLayers {
208
211
  this.errorHandler.createAndHandleError('需要按照键值对的方式配置底图才可使用切换底图功能', ErrorType.LAYER_ERROR, { layersType: 'array', requestedType: type });
209
212
  return;
210
213
  }
214
+ if (TIANDITU_TYPES.includes(type) && !this.options.token) {
215
+ this.errorHandler.createAndHandleError('请配置token后才能使用天地图底图', ErrorType.LAYER_ERROR, { requestedType: type });
216
+ return;
217
+ }
211
218
  if (!this.layers[type]) {
212
219
  this.errorHandler.createAndHandleError(`图层类型 '${type}' 不存在`, ErrorType.LAYER_ERROR, { availableTypes: Object.keys(this.layers), requestedType: type });
213
220
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "1.0.12",
4
+ "version": "1.0.13",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
package/types.d.ts CHANGED
@@ -32,7 +32,7 @@ export interface MapInitType {
32
32
  annotation?: boolean;
33
33
  }
34
34
  export type AnnotationType = 'cva_c' | 'cia_c' | 'cta_c';
35
- export type TiandituType = 'vec_c' | 'img_c' | 'ter_c' | string;
35
+ export type TiandituType = 'vec_c' | 'img_c' | 'ter_c';
36
36
  export interface MapLayers {
37
37
  vec_c?: BaseLayer[];
38
38
  img_c?: BaseLayer[];