my-openlayer 0.1.0 → 0.1.2
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/LICENSE +17 -17
- package/README.md +339 -0
- package/dist/MyOl.d.ts +2 -1
- package/dist/core/MapBaseLayers.d.ts +1 -1
- package/dist/core/MapBaseLayers.js +6 -3
- package/dist/types.d.ts +2 -2
- package/package.json +11 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2025 cuteyuchen
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# my-openlayer
|
|
2
|
+
|
|
3
|
+
基于 OpenLayers 的地图组件库,提供了一系列便捷的地图操作功能,支持天地图底图加载、要素绘制、图层管理等功能。
|
|
4
|
+
|
|
5
|
+
## 功能特点
|
|
6
|
+
|
|
7
|
+
- **底图管理**
|
|
8
|
+
- 支持天地图矢量图、影像图、地形图
|
|
9
|
+
- 支持底图动态切换
|
|
10
|
+
- 支持注记图层控制
|
|
11
|
+
- 支持地图裁剪
|
|
12
|
+
|
|
13
|
+
- **要素操作**
|
|
14
|
+
- 点位标注(支持图标、文字)
|
|
15
|
+
- 线要素绘制(支持样式自定义)
|
|
16
|
+
- 面要素绘制
|
|
17
|
+
- DOM点位(支持Vue组件)
|
|
18
|
+
- 点位聚合展示
|
|
19
|
+
- 闪烁点位效果
|
|
20
|
+
|
|
21
|
+
- **地图工具**
|
|
22
|
+
- 图层管理
|
|
23
|
+
- 事件监听
|
|
24
|
+
- 坐标转换
|
|
25
|
+
- 视图控制
|
|
26
|
+
|
|
27
|
+
## 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install my-openlayer
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 使用方法
|
|
34
|
+
|
|
35
|
+
### 基础初始化
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
import MyOl from 'my-openlayer';
|
|
39
|
+
|
|
40
|
+
const map = new MyOl('map-container', {
|
|
41
|
+
// 中心点坐标
|
|
42
|
+
center: [119.81, 29.969],
|
|
43
|
+
// 缩放级别
|
|
44
|
+
zoom: 10,
|
|
45
|
+
// 最小缩放级别
|
|
46
|
+
minZoom: 8,
|
|
47
|
+
// 最大缩放级别
|
|
48
|
+
maxZoom: 20,
|
|
49
|
+
// 天地图token
|
|
50
|
+
token: 'your-tianditu-token',
|
|
51
|
+
// 是否显示注记
|
|
52
|
+
annotation: true,
|
|
53
|
+
// 地图裁剪
|
|
54
|
+
mapClip: false,
|
|
55
|
+
mapClipData: undefined,
|
|
56
|
+
// 图层配置
|
|
57
|
+
layers: {
|
|
58
|
+
vec_c: [], // 矢量图层
|
|
59
|
+
img_c: [], // 影像图层
|
|
60
|
+
ter_c: [] // 地形图层
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 底图操作
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// 获取底图管理实例
|
|
69
|
+
const baseLayers = map.getMapBaseLayers();
|
|
70
|
+
|
|
71
|
+
// 切换底图
|
|
72
|
+
baseLayers.switchBaseLayer('vec_c'); // 切换到矢量图
|
|
73
|
+
baseLayers.switchBaseLayer('img_c'); // 切换到影像图
|
|
74
|
+
baseLayers.switchBaseLayer('ter_c'); // 切换到地形图
|
|
75
|
+
|
|
76
|
+
// 添加注记图层
|
|
77
|
+
baseLayers.addAnnotationLayer({
|
|
78
|
+
type: 'cva_c', // 注记类型
|
|
79
|
+
zIndex: 11, // 图层层级
|
|
80
|
+
visible: true // 是否可见
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 点位操作
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// 获取点位操作实例
|
|
88
|
+
const point = map.getPoint();
|
|
89
|
+
|
|
90
|
+
// 添加普通点位
|
|
91
|
+
point.addPoint([
|
|
92
|
+
{
|
|
93
|
+
lgtd: 119.81,
|
|
94
|
+
lttd: 29.969,
|
|
95
|
+
name: '测试点位'
|
|
96
|
+
}
|
|
97
|
+
], 'test-point', {
|
|
98
|
+
nameKey: 'name', // 名称字段
|
|
99
|
+
img: 'marker.png', // 图标路径
|
|
100
|
+
hasImg: true, // 是否显示图标
|
|
101
|
+
textFont: '12px sans-serif', // 文字样式
|
|
102
|
+
textFillColor: '#FFF', // 文字颜色
|
|
103
|
+
textStrokeColor: '#000', // 文字描边颜色
|
|
104
|
+
textStrokeWidth: 3, // 文字描边宽度
|
|
105
|
+
textOffsetY: 20, // 文字Y轴偏移
|
|
106
|
+
zIndex: 4, // 图层层级
|
|
107
|
+
visible: true // 是否可见
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// 添加聚合点位
|
|
111
|
+
point.addClusterPoint(pointData, 'cluster-point', {
|
|
112
|
+
nameKey: 'name',
|
|
113
|
+
img: 'cluster.png',
|
|
114
|
+
zIndex: 4
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// 添加Vue组件点位
|
|
118
|
+
const domPoints = point.setDomPointVue(
|
|
119
|
+
[{ lgtd: 119.81, lttd: 29.969 }],
|
|
120
|
+
YourVueComponent,
|
|
121
|
+
Vue
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// 控制组件点位显隐
|
|
125
|
+
domPoints.setVisible(true);
|
|
126
|
+
|
|
127
|
+
// 移除组件点位
|
|
128
|
+
domPoints.remove();
|
|
129
|
+
|
|
130
|
+
// 地图定位
|
|
131
|
+
point.locationAction(119.81, 29.969, 15, 1000);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 线要素操作
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// 获取线要素操作实例
|
|
138
|
+
const line = map.getLine();
|
|
139
|
+
|
|
140
|
+
// 添加普通线要素
|
|
141
|
+
line.addLineCommon(lineGeoJSON, {
|
|
142
|
+
type: 'test-line', // 线要素类型
|
|
143
|
+
strokeColor: '#037AFF', // 线条颜色
|
|
144
|
+
strokeWidth: 3, // 线条宽度
|
|
145
|
+
zIndex: 3 // 图层层级
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// 添加河流要素(支持分级显示)
|
|
149
|
+
line.addRiverLayersByZoom(riverGeoJSON, {
|
|
150
|
+
type: 'river',
|
|
151
|
+
strokeColor: '#0071FF',
|
|
152
|
+
strokeWidth: 3,
|
|
153
|
+
zIndex: 6,
|
|
154
|
+
visible: true
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 地图工具
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
// 获取工具实例
|
|
162
|
+
const tools = map.getTools();
|
|
163
|
+
|
|
164
|
+
// 获取图层
|
|
165
|
+
const layer = tools.getLayerByLayerName('layerName');
|
|
166
|
+
|
|
167
|
+
// 移除图层
|
|
168
|
+
tools.removeLayer('layerName');
|
|
169
|
+
|
|
170
|
+
// 事件监听
|
|
171
|
+
MapTools.mapOnEvent(map, 'click', (feature, event) => {
|
|
172
|
+
console.log('点击要素:', feature);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// 支持的事件类型
|
|
176
|
+
// - click: 点击事件
|
|
177
|
+
// - moveend: 地图移动结束事件
|
|
178
|
+
// - hover: 鼠标悬停事件
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## API文档
|
|
182
|
+
|
|
183
|
+
### MyOl
|
|
184
|
+
|
|
185
|
+
主类,用于创建和管理地图实例。
|
|
186
|
+
|
|
187
|
+
#### 构造函数
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
constructor(id: string, options: MapInitType)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
参数:
|
|
194
|
+
- `id`: 地图容器ID
|
|
195
|
+
- `options`: 地图初始化配置
|
|
196
|
+
- `center`: 中心点坐标 [经度, 纬度]
|
|
197
|
+
- `zoom`: 缩放级别
|
|
198
|
+
- `minZoom`: 最小缩放级别
|
|
199
|
+
- `maxZoom`: 最大缩放级别
|
|
200
|
+
- `token`: 天地图token
|
|
201
|
+
- `annotation`: 是否显示注记
|
|
202
|
+
- `mapClip`: 是否启用地图裁剪
|
|
203
|
+
- `mapClipData`: 裁剪数据
|
|
204
|
+
- `layers`: 图层配置
|
|
205
|
+
|
|
206
|
+
#### 方法
|
|
207
|
+
|
|
208
|
+
- `getPoint()`: 获取点位操作实例
|
|
209
|
+
- `getLine()`: 获取线要素操作实例
|
|
210
|
+
- `getPolygon()`: 获取面要素操作实例
|
|
211
|
+
- `getTools()`: 获取地图工具实例
|
|
212
|
+
- `getMapBaseLayers()`: 获取底图图层管理实例
|
|
213
|
+
- `restPosition(duration?: number)`: 重置地图位置
|
|
214
|
+
- `locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number)`: 地图定位
|
|
215
|
+
- `mapOnEvent(eventType: string, callback: Function, clickType?: string)`: 地图事件监听
|
|
216
|
+
- `showMapLayer(layerName: string, show: boolean)`: 控制图层显隐
|
|
217
|
+
|
|
218
|
+
### MapBaseLayers
|
|
219
|
+
|
|
220
|
+
底图图层管理类。
|
|
221
|
+
|
|
222
|
+
#### 方法
|
|
223
|
+
|
|
224
|
+
- `switchBaseLayer(type: TiandituType)`: 切换底图
|
|
225
|
+
- `addAnnotationLayer(options: AnnotationLayerOptions)`: 添加注记图层
|
|
226
|
+
- `initLayer()`: 初始化图层
|
|
227
|
+
|
|
228
|
+
### Point
|
|
229
|
+
|
|
230
|
+
点位操作类。
|
|
231
|
+
|
|
232
|
+
#### 方法
|
|
233
|
+
|
|
234
|
+
- `addPoint(pointData: PointData[], type: string, options: OptionsType)`: 添加点位
|
|
235
|
+
- `addClusterPoint(pointData: any[], type: string, options: OptionsType)`: 添加聚合点位
|
|
236
|
+
- `setDomPointVue(pointInfoList: any[], template: any, Vue: any)`: 添加Vue组件点位
|
|
237
|
+
- `locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number)`: 地图定位
|
|
238
|
+
|
|
239
|
+
### Line
|
|
240
|
+
|
|
241
|
+
线要素操作类。
|
|
242
|
+
|
|
243
|
+
#### 方法
|
|
244
|
+
|
|
245
|
+
- `addLineCommon(data: MapJSONData, options: OptionsType)`: 添加普通线要素
|
|
246
|
+
- `addRiverLayersByZoom(data: MapJSONData, options: OptionsType)`: 添加河流要素
|
|
247
|
+
- `showRiverLayer(show: boolean)`: 控制河流图层显隐
|
|
248
|
+
|
|
249
|
+
### MapTools
|
|
250
|
+
|
|
251
|
+
地图工具类。
|
|
252
|
+
|
|
253
|
+
#### 方法
|
|
254
|
+
|
|
255
|
+
- `getLayerByLayerName(layerName: string)`: 获取图层
|
|
256
|
+
- `removeLayer(layerName: string)`: 移除图层
|
|
257
|
+
- `static mapOnEvent(map: Map, eventType: string, callback: Function, clickType?: string)`: 事件监听
|
|
258
|
+
- `static setMapClip(baseLayer: any, data: MapJSONData)`: 设置地图裁剪
|
|
259
|
+
|
|
260
|
+
## 类型定义
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
interface MapInitType {
|
|
264
|
+
layers?: undefined;
|
|
265
|
+
zoom?: number;
|
|
266
|
+
center?: number[];
|
|
267
|
+
minZoom?: number;
|
|
268
|
+
maxZoom?: number;
|
|
269
|
+
extent?: undefined;
|
|
270
|
+
token?: string;
|
|
271
|
+
annotation?: boolean;
|
|
272
|
+
mapClip?: boolean;
|
|
273
|
+
mapClipData?: any;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
type TiandituType = 'vec_c' | 'img_c' | 'ter_c';
|
|
277
|
+
|
|
278
|
+
interface AnnotationLayerOptions {
|
|
279
|
+
type: string;
|
|
280
|
+
token: string;
|
|
281
|
+
zIndex?: number;
|
|
282
|
+
visible?: boolean;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
interface OptionsType {
|
|
286
|
+
type?: string;
|
|
287
|
+
nameKey?: string;
|
|
288
|
+
img?: string;
|
|
289
|
+
hasImg?: boolean;
|
|
290
|
+
textFont?: string;
|
|
291
|
+
textFillColor?: string;
|
|
292
|
+
textStrokeColor?: string;
|
|
293
|
+
textStrokeWidth?: number;
|
|
294
|
+
textOffsetY?: number;
|
|
295
|
+
zIndex?: number;
|
|
296
|
+
visible?: boolean;
|
|
297
|
+
strokeColor?: string;
|
|
298
|
+
strokeWidth?: number;
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## 依赖
|
|
303
|
+
|
|
304
|
+
- ol ^6.15.1
|
|
305
|
+
- proj4 ^2.7.5
|
|
306
|
+
- turf ^3.0.14
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
## 许可证
|
|
310
|
+
|
|
311
|
+
[MIT](LICENSE)
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
## 更新日志
|
|
315
|
+
|
|
316
|
+
### 0.1.1
|
|
317
|
+
- 初始版本发布
|
|
318
|
+
- 支持基础地图功能
|
|
319
|
+
- 支持点线面要素操作
|
|
320
|
+
- 支持天地图底图
|
|
321
|
+
|
|
322
|
+
## 常见问题
|
|
323
|
+
|
|
324
|
+
1. **如何获取天地图token?**
|
|
325
|
+
- 访问天地图开发者平台注册账号
|
|
326
|
+
- 申请密钥(token)
|
|
327
|
+
|
|
328
|
+
2. **为什么地图无法加载?**
|
|
329
|
+
- 检查token是否正确
|
|
330
|
+
- 检查网络连接
|
|
331
|
+
- 确认坐标系是否正确
|
|
332
|
+
|
|
333
|
+
3. **如何自定义点位样式?**
|
|
334
|
+
- 通过options参数配置样式
|
|
335
|
+
- 支持自定义图标和文字样式
|
|
336
|
+
|
|
337
|
+
## 联系方式
|
|
338
|
+
|
|
339
|
+
如有问题或建议,请提交 [Issue](https://github.com/cuteyuchen/my-openlayer/issues)
|
package/dist/MyOl.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Map from "ol/Map";
|
|
|
3
3
|
import Polygon from "./core/Polygon";
|
|
4
4
|
import Point from "./core/Point";
|
|
5
5
|
import Line from "./core/Line";
|
|
6
|
+
import MapBaseLayers from "./core/MapBaseLayers";
|
|
6
7
|
import MapTools from "./core/MapTools";
|
|
7
8
|
import { MapInitType } from './types';
|
|
8
9
|
export default class MyOl {
|
|
@@ -31,7 +32,7 @@ export default class MyOl {
|
|
|
31
32
|
* @returns Polygon
|
|
32
33
|
*/
|
|
33
34
|
getPolygon(): Polygon;
|
|
34
|
-
getMapBaseLayers():
|
|
35
|
+
getMapBaseLayers(): MapBaseLayers;
|
|
35
36
|
/**
|
|
36
37
|
* 获取 地图 点 操作
|
|
37
38
|
* @returns Point
|
|
@@ -14,7 +14,7 @@ export default class MapBaseLayers {
|
|
|
14
14
|
constructor(map: Map, options: MapLayersOptions);
|
|
15
15
|
switchBaseLayer(type: TiandituType): void;
|
|
16
16
|
initLayer(): void;
|
|
17
|
-
addAnnotationLayer(options: AnnotationLayerOptions): void;
|
|
17
|
+
addAnnotationLayer(options: Omit<AnnotationLayerOptions, 'token'>): void;
|
|
18
18
|
static addAnnotationLayer(map: Map, options: AnnotationLayerOptions): TileLayer<XYZ>;
|
|
19
19
|
addMapLayer(): void;
|
|
20
20
|
createLayer(layer: any): any;
|
|
@@ -76,15 +76,18 @@ export default class MapBaseLayers {
|
|
|
76
76
|
}
|
|
77
77
|
//添加注记图层
|
|
78
78
|
addAnnotationLayer(options) {
|
|
79
|
-
MapBaseLayers.addAnnotationLayer(this.map,
|
|
79
|
+
MapBaseLayers.addAnnotationLayer(this.map, {
|
|
80
|
+
...options,
|
|
81
|
+
token: this.options.token || ''
|
|
82
|
+
});
|
|
80
83
|
}
|
|
81
84
|
//添加注记图层
|
|
82
85
|
static addAnnotationLayer(map, options) {
|
|
83
86
|
const layer = MapBaseLayers.getAnnotationLayer({
|
|
84
87
|
type: options.type,
|
|
85
88
|
token: options.token,
|
|
86
|
-
zIndex: options.zIndex,
|
|
87
|
-
visible: options.visible
|
|
89
|
+
zIndex: options.zIndex ?? 10,
|
|
90
|
+
visible: options.visible ?? true
|
|
88
91
|
});
|
|
89
92
|
map.addLayer(layer);
|
|
90
93
|
return layer;
|
package/dist/types.d.ts
CHANGED
|
@@ -45,8 +45,8 @@ export interface MapLayersOptions {
|
|
|
45
45
|
export interface AnnotationLayerOptions {
|
|
46
46
|
type: AnnotationType;
|
|
47
47
|
token: string;
|
|
48
|
-
zIndex
|
|
49
|
-
visible
|
|
48
|
+
zIndex?: number;
|
|
49
|
+
visible?: boolean;
|
|
50
50
|
}
|
|
51
51
|
export interface OptionsType {
|
|
52
52
|
type?: string;
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-openlayer",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"openlayers",
|
|
10
|
+
"ol",
|
|
11
|
+
"gis",
|
|
12
|
+
"map",
|
|
13
|
+
"vue"
|
|
14
|
+
],
|
|
8
15
|
"files": [
|
|
9
|
-
"dist/*"
|
|
16
|
+
"dist/*",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
10
19
|
],
|
|
11
20
|
"scripts": {
|
|
12
21
|
"dev": "vite",
|