my-openlayer 2.4.12 → 2.5.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.
- package/CHANGELOG.md +251 -251
- package/LICENSE +21 -21
- package/MyOl.d.ts +9 -9
- package/MyOl.js +17 -14
- package/README.md +174 -148
- package/core/line/Line.d.ts +40 -0
- package/core/line/Line.js +144 -0
- package/core/line/LineFeatureFactory.d.ts +17 -0
- package/core/line/LineFeatureFactory.js +75 -0
- package/core/line/LineFlowAnimator.d.ts +53 -0
- package/core/line/LineFlowAnimator.js +297 -0
- package/core/line/LineStyleFactory.d.ts +43 -0
- package/core/line/LineStyleFactory.js +135 -0
- package/core/{RiverLayerManager.d.ts → line/RiverLayerManager.d.ts} +2 -2
- package/core/{RiverLayerManager.js → line/RiverLayerManager.js} +3 -5
- package/core/line/index.d.ts +6 -0
- package/core/line/index.js +5 -0
- package/core/{ConfigManager.d.ts → map/ConfigManager.d.ts} +25 -1
- package/core/{ConfigManager.js → map/ConfigManager.js} +22 -1
- package/core/{EventManager.d.ts → map/EventManager.d.ts} +1 -1
- package/core/{EventManager.js → map/EventManager.js} +2 -2
- package/core/{MapBaseLayers.d.ts → map/MapBaseLayers.d.ts} +1 -1
- package/core/{MapBaseLayers.js → map/MapBaseLayers.js} +3 -3
- package/core/{MapTools.d.ts → map/MapTools.d.ts} +5 -2
- package/core/{MapTools.js → map/MapTools.js} +11 -5
- package/core/{MeasureHandler.d.ts → map/MeasureHandler.d.ts} +1 -1
- package/core/{MeasureHandler.js → map/MeasureHandler.js} +41 -41
- package/core/map/index.d.ts +5 -0
- package/core/map/index.js +5 -0
- package/core/{Point.d.ts → point/Point.d.ts} +6 -14
- package/core/point/Point.js +272 -0
- package/core/point/PointClusterLayer.d.ts +10 -0
- package/core/point/PointClusterLayer.js +52 -0
- package/core/point/PointOverlay.d.ts +13 -0
- package/core/point/PointOverlay.js +57 -0
- package/core/point/PointPulseLayer.d.ts +13 -0
- package/core/point/PointPulseLayer.js +207 -0
- package/core/point/index.d.ts +4 -0
- package/core/point/index.js +4 -0
- package/core/{Polygon.d.ts → polygon/Polygon.d.ts} +4 -50
- package/core/polygon/Polygon.js +248 -0
- package/core/polygon/PolygonHeatmapLayer.d.ts +11 -0
- package/core/polygon/PolygonHeatmapLayer.js +40 -0
- package/core/polygon/PolygonImageLayer.d.ts +9 -0
- package/core/polygon/PolygonImageLayer.js +61 -0
- package/core/polygon/PolygonMaskLayer.d.ts +20 -0
- package/core/polygon/PolygonMaskLayer.js +107 -0
- package/core/polygon/PolygonStyleFactory.d.ts +12 -0
- package/core/polygon/PolygonStyleFactory.js +100 -0
- package/core/polygon/index.d.ts +5 -0
- package/core/polygon/index.js +5 -0
- package/core/{SelectHandler.d.ts → select/SelectHandler.d.ts} +2 -3
- package/core/{SelectHandler.js → select/SelectHandler.js} +4 -4
- package/core/select/index.d.ts +1 -0
- package/core/select/index.js +1 -0
- package/core/{VueTemplatePoint.d.ts → vue-template-point/VueTemplatePoint.d.ts} +1 -1
- package/core/{VueTemplatePoint.js → vue-template-point/VueTemplatePoint.js} +4 -4
- package/core/vue-template-point/index.d.ts +1 -0
- package/core/vue-template-point/index.js +1 -0
- package/docs/.vitepress/config.mts +57 -57
- package/docs/ConfigManager.md +71 -71
- package/docs/ErrorHandler.md +106 -106
- package/docs/EventManager.md +142 -142
- package/docs/Line.md +215 -187
- package/docs/MapBaseLayers.md +198 -198
- package/docs/MapTools.md +172 -172
- package/docs/MeasureHandler.md +87 -87
- package/docs/MyOl.md +247 -247
- package/docs/Point.md +136 -136
- package/docs/Polygon.md +241 -241
- package/docs/RiverLayerManager.md +187 -187
- package/docs/SelectHandler.md +147 -147
- package/docs/ValidationUtils.md +83 -83
- package/docs/VueTemplatePoint.md +214 -214
- package/docs/index.md +73 -73
- package/index.d.ts +10 -15
- package/index.js +7 -13
- package/package.json +11 -1
- package/types/base.d.ts +47 -0
- package/types/base.js +1 -0
- package/types/common.d.ts +59 -0
- package/types/common.js +1 -0
- package/types/index.d.ts +9 -0
- package/types/index.js +1 -0
- package/types/line.d.ts +41 -0
- package/types/line.js +1 -0
- package/types/map.d.ts +77 -0
- package/types/map.js +1 -0
- package/types/point.d.ts +54 -0
- package/types/point.js +1 -0
- package/types/polygon.d.ts +8 -0
- package/types/polygon.js +1 -0
- package/types/select.d.ts +25 -0
- package/types/select.js +1 -0
- package/types/vue-template-point.d.ts +54 -0
- package/{types.js → types/vue-template-point.js} +0 -3
- package/utils/ProjectionUtils.d.ts +28 -0
- package/utils/ProjectionUtils.js +34 -0
- package/utils/ValidationUtils.d.ts +33 -86
- package/utils/ValidationUtils.js +60 -165
- package/core/Line.d.ts +0 -49
- package/core/Line.js +0 -114
- package/core/Point.js +0 -560
- package/core/Polygon.js +0 -646
- package/docs/.vitepress/dist/404.html +0 -22
- package/docs/.vitepress/dist/ConfigManager.html +0 -46
- package/docs/.vitepress/dist/ErrorHandler.html +0 -52
- package/docs/.vitepress/dist/EventManager.html +0 -58
- package/docs/.vitepress/dist/Line.html +0 -92
- package/docs/.vitepress/dist/MapBaseLayers.html +0 -52
- package/docs/.vitepress/dist/MapTools.html +0 -81
- package/docs/.vitepress/dist/MeasureHandler.html +0 -32
- package/docs/.vitepress/dist/MyOl.html +0 -62
- package/docs/.vitepress/dist/Point.html +0 -81
- package/docs/.vitepress/dist/Polygon.html +0 -102
- package/docs/.vitepress/dist/RiverLayerManager.html +0 -66
- package/docs/.vitepress/dist/SelectHandler.html +0 -46
- package/docs/.vitepress/dist/ValidationUtils.html +0 -47
- package/docs/.vitepress/dist/VueTemplatePoint.html +0 -112
- package/docs/.vitepress/dist/assets/ConfigManager.md.BOMdGTaa.js +0 -22
- package/docs/.vitepress/dist/assets/ConfigManager.md.BOMdGTaa.lean.js +0 -1
- package/docs/.vitepress/dist/assets/ErrorHandler.md.yUiuJ9w9.js +0 -28
- package/docs/.vitepress/dist/assets/ErrorHandler.md.yUiuJ9w9.lean.js +0 -1
- package/docs/.vitepress/dist/assets/EventManager.md.BhCUVy1f.js +0 -34
- package/docs/.vitepress/dist/assets/EventManager.md.BhCUVy1f.lean.js +0 -1
- package/docs/.vitepress/dist/assets/Line.md.BAQOzmSt.js +0 -68
- package/docs/.vitepress/dist/assets/Line.md.BAQOzmSt.lean.js +0 -1
- package/docs/.vitepress/dist/assets/MapBaseLayers.md.Bw0L_m0b.js +0 -28
- package/docs/.vitepress/dist/assets/MapBaseLayers.md.Bw0L_m0b.lean.js +0 -1
- package/docs/.vitepress/dist/assets/MapTools.md.DaYgiDPe.js +0 -57
- package/docs/.vitepress/dist/assets/MapTools.md.DaYgiDPe.lean.js +0 -1
- package/docs/.vitepress/dist/assets/MeasureHandler.md.7Sf4ymRv.js +0 -8
- package/docs/.vitepress/dist/assets/MeasureHandler.md.7Sf4ymRv.lean.js +0 -1
- package/docs/.vitepress/dist/assets/MyOl.md.D-14Gzjy.js +0 -38
- package/docs/.vitepress/dist/assets/MyOl.md.D-14Gzjy.lean.js +0 -1
- package/docs/.vitepress/dist/assets/Point.md.Bi9juuuv.js +0 -57
- package/docs/.vitepress/dist/assets/Point.md.Bi9juuuv.lean.js +0 -1
- package/docs/.vitepress/dist/assets/Polygon.md.-JIqEvzD.js +0 -78
- package/docs/.vitepress/dist/assets/Polygon.md.-JIqEvzD.lean.js +0 -1
- package/docs/.vitepress/dist/assets/RiverLayerManager.md.CfUu2RxH.js +0 -42
- package/docs/.vitepress/dist/assets/RiverLayerManager.md.CfUu2RxH.lean.js +0 -1
- package/docs/.vitepress/dist/assets/SelectHandler.md.COR4ez_p.js +0 -22
- package/docs/.vitepress/dist/assets/SelectHandler.md.COR4ez_p.lean.js +0 -1
- package/docs/.vitepress/dist/assets/ValidationUtils.md.ReTVWa73.js +0 -23
- package/docs/.vitepress/dist/assets/ValidationUtils.md.ReTVWa73.lean.js +0 -1
- package/docs/.vitepress/dist/assets/VueTemplatePoint.md.CtxSb5Pm.js +0 -88
- package/docs/.vitepress/dist/assets/VueTemplatePoint.md.CtxSb5Pm.lean.js +0 -1
- package/docs/.vitepress/dist/assets/app.YvjVuxaB.js +0 -1
- package/docs/.vitepress/dist/assets/chunks/framework.C_W0ODpn.js +0 -18
- package/docs/.vitepress/dist/assets/chunks/theme.Bf87fILP.js +0 -1
- package/docs/.vitepress/dist/assets/index.md.BJz6tHSr.js +0 -26
- package/docs/.vitepress/dist/assets/index.md.BJz6tHSr.lean.js +0 -1
- package/docs/.vitepress/dist/assets/inter-italic-cyrillic-ext.r48I6akx.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-cyrillic.By2_1cv3.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-greek-ext.1u6EdAuj.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-greek.DJ8dCoTZ.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-latin-ext.CN1xVJS-.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-latin.C2AdPX0b.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-vietnamese.BSbpV94h.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-cyrillic-ext.BBPuwvHQ.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-cyrillic.C5lxZ8CY.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-greek-ext.CqjqNYQ-.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-greek.BBVDIX6e.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-latin-ext.4ZJIpNVo.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-latin.Di8DUHzh.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-vietnamese.BjW4sHH5.woff2 +0 -0
- package/docs/.vitepress/dist/assets/style.C2pAQzDq.css +0 -1
- package/docs/.vitepress/dist/hashmap.json +0 -1
- package/docs/.vitepress/dist/index.html +0 -50
- package/docs/.vitepress/dist/vp-icons.css +0 -1
- package/types.d.ts +0 -431
package/docs/MyOl.md
CHANGED
|
@@ -1,247 +1,247 @@
|
|
|
1
|
-
# MyOl 类
|
|
2
|
-
|
|
3
|
-
`MyOl` 是地图的核心类,作为整个库的入口点,负责地图的初始化、配置管理、模块加载以及基础的地图操作(如定位、重置)。它采用了模块化设计,按需加载各个功能模块(如点、线、面要素管理)。
|
|
4
|
-
|
|
5
|
-
## 导入
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { MyOl } from 'my-openlayer';
|
|
9
|
-
// 或者
|
|
10
|
-
import MyOl from 'my-openlayer';
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## 构造函数
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
constructor(id: string | HTMLElement, options?: Partial<MapInitType>)
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
初始化一个新的地图实例。
|
|
20
|
-
|
|
21
|
-
### 参数说明
|
|
22
|
-
|
|
23
|
-
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|
|
24
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
25
|
-
| `id` | `string` \| `HTMLElement` | 是 | - | 地图容器的 DOM ID 字符串或 HTMLElement 对象。 |
|
|
26
|
-
| `options` | `Partial<MapInitType>` | 否 | `{}` | 地图初始化配置选项,详见下表。 |
|
|
27
|
-
|
|
28
|
-
### MapInitType 配置选项
|
|
29
|
-
|
|
30
|
-
| 属性名 | 类型 | 描述 |
|
|
31
|
-
| :--- | :--- | :--- |
|
|
32
|
-
| `center` | `number[]` | 地图初始中心点坐标 `[经度, 纬度]`,默认为 `[0, 0]`。 |
|
|
33
|
-
| `zoom` | `number` | 地图初始缩放级别,默认为 `2`。 |
|
|
34
|
-
| `minZoom` | `number` | 最小缩放级别。 |
|
|
35
|
-
| `maxZoom` | `number` | 最大缩放级别。 |
|
|
36
|
-
| `token` | `string` | 天地图 API Token,用于加载天地图底图。 |
|
|
37
|
-
| `annotation` | `boolean` | 是否显示注记图层(如地名标注),默认为 `false`。 |
|
|
38
|
-
| `layers` | `LayerItem[]` | 自定义初始图层数组。如果设置了此项,内置底图管理可能受到影响。 |
|
|
39
|
-
| `mapClipData` | `MapJSONData` | 地图裁剪数据(GeoJSON 格式),用于仅显示特定区域。 |
|
|
40
|
-
| `enableLog` | `boolean` | 是否启用内部日志输出,默认为 `false`。 |
|
|
41
|
-
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error'` | 日志级别,默认为 `'error'`。 |
|
|
42
|
-
| `projection` | `object` | 自定义投影坐标系配置。 |
|
|
43
|
-
| `projection.code` | `string` | 投影代码,如 `'EPSG:4549'`。 |
|
|
44
|
-
| `projection.def` | `string` | proj4 定义字符串。 |
|
|
45
|
-
| `projection.extent` | `number[]` | 投影范围。 |
|
|
46
|
-
|
|
47
|
-
## 静态方法
|
|
48
|
-
|
|
49
|
-
### createView
|
|
50
|
-
|
|
51
|
-
创建 OpenLayers 的 `View` 实例。
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
static createView(options: MapInitType): View
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
| 参数名 | 类型 | 描述 |
|
|
58
|
-
| :--- | :--- | :--- |
|
|
59
|
-
| `options` | `MapInitType` | 地图配置选项,主要使用其中的 `center`, `zoom`, `projection` 等属性。 |
|
|
60
|
-
|
|
61
|
-
## 实例方法
|
|
62
|
-
|
|
63
|
-
### 模块获取
|
|
64
|
-
|
|
65
|
-
`MyOl` 提供了懒加载的模块获取方法,只有在首次调用时才会初始化对应模块。
|
|
66
|
-
|
|
67
|
-
#### getPoint
|
|
68
|
-
|
|
69
|
-
获取点要素操作模块。
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
getPoint(): Point
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
**返回值**: `Point` 实例,用于添加、删除、管理点要素。
|
|
76
|
-
|
|
77
|
-
#### getLine
|
|
78
|
-
|
|
79
|
-
获取线要素操作模块。
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
getLine(): Line
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**返回值**: `Line` 实例,用于绘制线条。
|
|
86
|
-
|
|
87
|
-
#### getPolygon
|
|
88
|
-
|
|
89
|
-
获取面要素操作模块。
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
getPolygon(): Polygon
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**返回值**: `Polygon` 实例,用于绘制多边形。
|
|
96
|
-
|
|
97
|
-
#### getMapBaseLayers
|
|
98
|
-
|
|
99
|
-
获取底图管理模块。
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
getMapBaseLayers(): MapBaseLayers
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
**返回值**: `MapBaseLayers` 实例,用于切换底图类型(矢量、影像、地形)。
|
|
106
|
-
|
|
107
|
-
#### getTools
|
|
108
|
-
|
|
109
|
-
获取地图工具模块。
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
getTools(): MapTools
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**返回值**: `MapTools` 实例,包含地图截图、裁剪等工具。
|
|
116
|
-
|
|
117
|
-
#### getSelectHandler
|
|
118
|
-
|
|
119
|
-
获取要素选择处理器模块。
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
getSelectHandler(): SelectHandler
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**返回值**: `SelectHandler` 实例,用于处理地图要素的点击、悬停选择交互。
|
|
126
|
-
|
|
127
|
-
### 地图操作
|
|
128
|
-
|
|
129
|
-
#### locationAction
|
|
130
|
-
|
|
131
|
-
定位到指定坐标,支持动画过渡。
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
locationAction(longitude: number, latitude: number, zoom: number = 20, duration: number = 3000): void
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
| 参数名 | 类型 | 默认值 | 描述 |
|
|
138
|
-
| :--- | :--- | :--- | :--- |
|
|
139
|
-
| `longitude` | `number` | - | 目标经度。 |
|
|
140
|
-
| `latitude` | `number` | - | 目标纬度。 |
|
|
141
|
-
| `zoom` | `number` | `20` | 目标缩放级别。 |
|
|
142
|
-
| `duration` | `number` | `3000` | 动画持续时间(毫秒)。 |
|
|
143
|
-
|
|
144
|
-
#### resetPosition
|
|
145
|
-
|
|
146
|
-
重置地图位置到初始化时设置的中心点。
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
resetPosition(duration: number = 3000): void
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
| 参数名 | 类型 | 默认值 | 描述 |
|
|
153
|
-
| :--- | :--- | :--- | :--- |
|
|
154
|
-
| `duration` | `number` | `3000` | 动画持续时间(毫秒)。 |
|
|
155
|
-
|
|
156
|
-
### 管理器访问
|
|
157
|
-
|
|
158
|
-
#### getEventManager
|
|
159
|
-
|
|
160
|
-
获取事件管理器,用于监听地图事件。
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
getEventManager(): EventManager
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
#### getErrorHandler
|
|
167
|
-
|
|
168
|
-
获取错误处理器,用于自定义错误处理逻辑。
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
getErrorHandler(): ErrorHandler
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
#### getConfigManager
|
|
175
|
-
|
|
176
|
-
获取配置管理器。
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
getConfigManager(): ConfigManager
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
#### getMapOptions
|
|
183
|
-
|
|
184
|
-
获取当前地图的只读配置副本。
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
getMapOptions(): Readonly<MapInitType>
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### 销毁
|
|
191
|
-
|
|
192
|
-
#### destroy
|
|
193
|
-
|
|
194
|
-
销毁地图实例,清理所有事件监听和资源。
|
|
195
|
-
|
|
196
|
-
```typescript
|
|
197
|
-
destroy(): void
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## 使用示例
|
|
201
|
-
|
|
202
|
-
### 完整初始化
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
import { MyOl } from 'my-openlayer';
|
|
206
|
-
|
|
207
|
-
// 定义配置
|
|
208
|
-
const options = {
|
|
209
|
-
// 杭州市中心
|
|
210
|
-
center: [120.15507, 30.274085],
|
|
211
|
-
zoom: 12,
|
|
212
|
-
minZoom: 5,
|
|
213
|
-
maxZoom: 18,
|
|
214
|
-
|
|
215
|
-
// 天地图 Token
|
|
216
|
-
token: 'YOUR_TIANDITU_TOKEN',
|
|
217
|
-
|
|
218
|
-
// 开启注记
|
|
219
|
-
annotation: true,
|
|
220
|
-
|
|
221
|
-
// 开启调试日志
|
|
222
|
-
enableLog: true,
|
|
223
|
-
logLevel: 'debug'
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// 初始化地图
|
|
227
|
-
const map = new MyOl('map-container', options);
|
|
228
|
-
|
|
229
|
-
// 监听加载完成
|
|
230
|
-
map.getEventManager().on('rendercomplete', () => {
|
|
231
|
-
console.log('Map loaded!');
|
|
232
|
-
});
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
### 使用自定义投影
|
|
236
|
-
|
|
237
|
-
```typescript
|
|
238
|
-
import { MyOl } from 'my-openlayer';
|
|
239
|
-
|
|
240
|
-
const map = new MyOl('map', {
|
|
241
|
-
projection: {
|
|
242
|
-
code: 'EPSG:4549', // CGCS2000 3度带
|
|
243
|
-
def: '+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs',
|
|
244
|
-
extent: [...] // 可选
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
```
|
|
1
|
+
# MyOl 类
|
|
2
|
+
|
|
3
|
+
`MyOl` 是地图的核心类,作为整个库的入口点,负责地图的初始化、配置管理、模块加载以及基础的地图操作(如定位、重置)。它采用了模块化设计,按需加载各个功能模块(如点、线、面要素管理)。
|
|
4
|
+
|
|
5
|
+
## 导入
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { MyOl } from 'my-openlayer';
|
|
9
|
+
// 或者
|
|
10
|
+
import MyOl from 'my-openlayer';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 构造函数
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
constructor(id: string | HTMLElement, options?: Partial<MapInitType>)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
初始化一个新的地图实例。
|
|
20
|
+
|
|
21
|
+
### 参数说明
|
|
22
|
+
|
|
23
|
+
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|
|
24
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
25
|
+
| `id` | `string` \| `HTMLElement` | 是 | - | 地图容器的 DOM ID 字符串或 HTMLElement 对象。 |
|
|
26
|
+
| `options` | `Partial<MapInitType>` | 否 | `{}` | 地图初始化配置选项,详见下表。 |
|
|
27
|
+
|
|
28
|
+
### MapInitType 配置选项
|
|
29
|
+
|
|
30
|
+
| 属性名 | 类型 | 描述 |
|
|
31
|
+
| :--- | :--- | :--- |
|
|
32
|
+
| `center` | `number[]` | 地图初始中心点坐标 `[经度, 纬度]`,默认为 `[0, 0]`。 |
|
|
33
|
+
| `zoom` | `number` | 地图初始缩放级别,默认为 `2`。 |
|
|
34
|
+
| `minZoom` | `number` | 最小缩放级别。 |
|
|
35
|
+
| `maxZoom` | `number` | 最大缩放级别。 |
|
|
36
|
+
| `token` | `string` | 天地图 API Token,用于加载天地图底图。 |
|
|
37
|
+
| `annotation` | `boolean` | 是否显示注记图层(如地名标注),默认为 `false`。 |
|
|
38
|
+
| `layers` | `LayerItem[]` | 自定义初始图层数组。如果设置了此项,内置底图管理可能受到影响。 |
|
|
39
|
+
| `mapClipData` | `MapJSONData` | 地图裁剪数据(GeoJSON 格式),用于仅显示特定区域。 |
|
|
40
|
+
| `enableLog` | `boolean` | 是否启用内部日志输出,默认为 `false`。 |
|
|
41
|
+
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error'` | 日志级别,默认为 `'error'`。 |
|
|
42
|
+
| `projection` | `object` | 自定义投影坐标系配置。 |
|
|
43
|
+
| `projection.code` | `string` | 投影代码,如 `'EPSG:4549'`。 |
|
|
44
|
+
| `projection.def` | `string` | proj4 定义字符串。 |
|
|
45
|
+
| `projection.extent` | `number[]` | 投影范围。 |
|
|
46
|
+
|
|
47
|
+
## 静态方法
|
|
48
|
+
|
|
49
|
+
### createView
|
|
50
|
+
|
|
51
|
+
创建 OpenLayers 的 `View` 实例。
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
static createView(options: MapInitType): View
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| 参数名 | 类型 | 描述 |
|
|
58
|
+
| :--- | :--- | :--- |
|
|
59
|
+
| `options` | `MapInitType` | 地图配置选项,主要使用其中的 `center`, `zoom`, `projection` 等属性。 |
|
|
60
|
+
|
|
61
|
+
## 实例方法
|
|
62
|
+
|
|
63
|
+
### 模块获取
|
|
64
|
+
|
|
65
|
+
`MyOl` 提供了懒加载的模块获取方法,只有在首次调用时才会初始化对应模块。
|
|
66
|
+
|
|
67
|
+
#### getPoint
|
|
68
|
+
|
|
69
|
+
获取点要素操作模块。
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
getPoint(): Point
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**返回值**: `Point` 实例,用于添加、删除、管理点要素。
|
|
76
|
+
|
|
77
|
+
#### getLine
|
|
78
|
+
|
|
79
|
+
获取线要素操作模块。
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
getLine(): Line
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**返回值**: `Line` 实例,用于绘制线条。
|
|
86
|
+
|
|
87
|
+
#### getPolygon
|
|
88
|
+
|
|
89
|
+
获取面要素操作模块。
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
getPolygon(): Polygon
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**返回值**: `Polygon` 实例,用于绘制多边形。
|
|
96
|
+
|
|
97
|
+
#### getMapBaseLayers
|
|
98
|
+
|
|
99
|
+
获取底图管理模块。
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
getMapBaseLayers(): MapBaseLayers
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**返回值**: `MapBaseLayers` 实例,用于切换底图类型(矢量、影像、地形)。
|
|
106
|
+
|
|
107
|
+
#### getTools
|
|
108
|
+
|
|
109
|
+
获取地图工具模块。
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
getTools(): MapTools
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**返回值**: `MapTools` 实例,包含地图截图、裁剪等工具。
|
|
116
|
+
|
|
117
|
+
#### getSelectHandler
|
|
118
|
+
|
|
119
|
+
获取要素选择处理器模块。
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
getSelectHandler(): SelectHandler
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**返回值**: `SelectHandler` 实例,用于处理地图要素的点击、悬停选择交互。
|
|
126
|
+
|
|
127
|
+
### 地图操作
|
|
128
|
+
|
|
129
|
+
#### locationAction
|
|
130
|
+
|
|
131
|
+
定位到指定坐标,支持动画过渡。
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
locationAction(longitude: number, latitude: number, zoom: number = 20, duration: number = 3000): void
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
| 参数名 | 类型 | 默认值 | 描述 |
|
|
138
|
+
| :--- | :--- | :--- | :--- |
|
|
139
|
+
| `longitude` | `number` | - | 目标经度。 |
|
|
140
|
+
| `latitude` | `number` | - | 目标纬度。 |
|
|
141
|
+
| `zoom` | `number` | `20` | 目标缩放级别。 |
|
|
142
|
+
| `duration` | `number` | `3000` | 动画持续时间(毫秒)。 |
|
|
143
|
+
|
|
144
|
+
#### resetPosition
|
|
145
|
+
|
|
146
|
+
重置地图位置到初始化时设置的中心点。
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
resetPosition(duration: number = 3000): void
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
| 参数名 | 类型 | 默认值 | 描述 |
|
|
153
|
+
| :--- | :--- | :--- | :--- |
|
|
154
|
+
| `duration` | `number` | `3000` | 动画持续时间(毫秒)。 |
|
|
155
|
+
|
|
156
|
+
### 管理器访问
|
|
157
|
+
|
|
158
|
+
#### getEventManager
|
|
159
|
+
|
|
160
|
+
获取事件管理器,用于监听地图事件。
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
getEventManager(): EventManager
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### getErrorHandler
|
|
167
|
+
|
|
168
|
+
获取错误处理器,用于自定义错误处理逻辑。
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
getErrorHandler(): ErrorHandler
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### getConfigManager
|
|
175
|
+
|
|
176
|
+
获取配置管理器。
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
getConfigManager(): ConfigManager
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### getMapOptions
|
|
183
|
+
|
|
184
|
+
获取当前地图的只读配置副本。
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
getMapOptions(): Readonly<MapInitType>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 销毁
|
|
191
|
+
|
|
192
|
+
#### destroy
|
|
193
|
+
|
|
194
|
+
销毁地图实例,清理所有事件监听和资源。
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
destroy(): void
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## 使用示例
|
|
201
|
+
|
|
202
|
+
### 完整初始化
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { MyOl } from 'my-openlayer';
|
|
206
|
+
|
|
207
|
+
// 定义配置
|
|
208
|
+
const options = {
|
|
209
|
+
// 杭州市中心
|
|
210
|
+
center: [120.15507, 30.274085],
|
|
211
|
+
zoom: 12,
|
|
212
|
+
minZoom: 5,
|
|
213
|
+
maxZoom: 18,
|
|
214
|
+
|
|
215
|
+
// 天地图 Token
|
|
216
|
+
token: 'YOUR_TIANDITU_TOKEN',
|
|
217
|
+
|
|
218
|
+
// 开启注记
|
|
219
|
+
annotation: true,
|
|
220
|
+
|
|
221
|
+
// 开启调试日志
|
|
222
|
+
enableLog: true,
|
|
223
|
+
logLevel: 'debug'
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// 初始化地图
|
|
227
|
+
const map = new MyOl('map-container', options);
|
|
228
|
+
|
|
229
|
+
// 监听加载完成
|
|
230
|
+
map.getEventManager().on('rendercomplete', () => {
|
|
231
|
+
console.log('Map loaded!');
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### 使用自定义投影
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { MyOl } from 'my-openlayer';
|
|
239
|
+
|
|
240
|
+
const map = new MyOl('map', {
|
|
241
|
+
projection: {
|
|
242
|
+
code: 'EPSG:4549', // CGCS2000 3度带
|
|
243
|
+
def: '+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs',
|
|
244
|
+
extent: [...] // 可选
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
```
|