my-openlayer 2.1.3 → 2.1.4

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/MyOl.js CHANGED
@@ -40,7 +40,7 @@ class MyOl {
40
40
  // 参数验证
41
41
  this.validateConstructorParams(id, this.options);
42
42
  // 初始化坐标系
43
- MyOl.initializeProjections();
43
+ MyOl.initializeProjections(this.options);
44
44
  // 准备图层
45
45
  const layers = Array.isArray(this.options.layers) ? this.options.layers : [];
46
46
  // 创建地图实例
@@ -85,7 +85,7 @@ class MyOl {
85
85
  * 初始化坐标系
86
86
  * @private
87
87
  */
88
- static initializeProjections() {
88
+ static initializeProjections(options) {
89
89
  // 定义 CGCS2000 坐标系
90
90
  proj4.defs(MyOl.PROJECTIONS.CGCS2000, "+proj=longlat +ellps=GRS80 +no_defs");
91
91
  proj4.defs(MyOl.PROJECTIONS.CGCS2000_3_DEGREE, "+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");
@@ -99,6 +99,19 @@ class MyOl {
99
99
  units: "degrees"
100
100
  });
101
101
  olProjAddProjection(cgsc2000);
102
+ if (options.projection?.code) {
103
+ const code = options.projection.code;
104
+ if (options.projection.def) {
105
+ proj4.defs(code, options.projection.def);
106
+ }
107
+ const customProj = new olProjProjection({
108
+ code,
109
+ extent: options.projection.extent ?? cgsc2000.getExtent(),
110
+ worldExtent: options.projection.worldExtent ?? cgsc2000.getWorldExtent(),
111
+ units: options.projection.units ?? cgsc2000.getUnits()
112
+ });
113
+ olProjAddProjection(customProj);
114
+ }
102
115
  }
103
116
  /**
104
117
  * 创建地图控件
@@ -133,11 +146,12 @@ class MyOl {
133
146
  */
134
147
  static createView(options = MyOl.DefaultOptions) {
135
148
  try {
149
+ const code = options.projection?.code ?? MyOl.PROJECTIONS.CGCS2000;
136
150
  const projection = new olProjProjection({
137
- code: MyOl.PROJECTIONS.CGCS2000,
138
- extent: [-180, -90, 180, 90],
139
- worldExtent: [-180, -90, 180, 90],
140
- units: "degrees"
151
+ code,
152
+ extent: options.projection?.extent ?? [-180, -90, 180, 90],
153
+ worldExtent: options.projection?.worldExtent ?? [-180, -90, 180, 90],
154
+ units: options.projection?.units ?? "degrees"
141
155
  });
142
156
  const viewOptions = {
143
157
  projection,
package/core/Line.js CHANGED
@@ -6,7 +6,7 @@ import { Feature } from "ol";
6
6
  import MapTools from "./MapTools";
7
7
  import { ValidationUtils } from "../utils/ValidationUtils";
8
8
  import { EventManager } from "./EventManager";
9
- import { ErrorHandler } from "src/utils/ErrorHandler";
9
+ import { ErrorHandler } from "../utils/ErrorHandler";
10
10
  /**
11
11
  * 线要素管理类
12
12
  * 用于在地图上添加和管理线要素,包括普通线要素、河流图层等
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "2.1.3",
4
+ "version": "2.1.4",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
package/types.d.ts CHANGED
@@ -5,6 +5,7 @@ import View from "ol/View";
5
5
  import Feature, { FeatureLike } from "ol/Feature";
6
6
  import { Style } from "ol/style";
7
7
  import MapBrowserEvent from "ol/MapBrowserEvent";
8
+ import { Units } from "ol/proj/Units";
8
9
  export interface FeatureData {
9
10
  type: string;
10
11
  properties: any;
@@ -34,6 +35,13 @@ export interface MapInitType {
34
35
  annotation?: boolean;
35
36
  enableLog?: boolean;
36
37
  logLevel?: 'debug' | 'info' | 'warn' | 'error';
38
+ projection?: {
39
+ code: string;
40
+ def?: string;
41
+ extent?: number[];
42
+ worldExtent?: number[];
43
+ units?: Units;
44
+ };
37
45
  }
38
46
  export type AnnotationType = 'cva_c' | 'cia_c' | 'cta_c';
39
47
  export type TiandituType = 'vec_c' | 'img_c' | 'ter_c';