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/README.md
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
# my-openlayer
|
|
2
|
-
|
|
3
|
-
my-openlayer 是一个基于 [OpenLayers](https://openlayers.org/) 的现代地图组件库,专为 Web GIS 应用开发者设计。提供完整的 TypeScript 支持、模块化的类型定义、强大的错误处理和事件管理系统,支持天地图底图加载、要素绘制、图层管理、事件监听等丰富功能,极大提升地图开发效率。
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/my-openlayer)
|
|
6
|
-
[](https://www.typescriptlang.org/)
|
|
7
|
-
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## 项目概述
|
|
12
|
-
|
|
13
|
-
- **项目名称**:`my-openlayer`
|
|
14
|
-
- **用途**:基于 OpenLayers 的 TypeScript 地图组件库,提供点/线/面要素、底图切换、热力图、事件与配置管理等能力。
|
|
15
|
-
- **目标用户**:Web GIS 开发者、可视化工程师、前端开发者
|
|
16
|
-
|
|
17
|
-
## 功能亮点
|
|
18
|
-
|
|
19
|
-
- **🗺️ 底图管理 (MapBaseLayers)**
|
|
20
|
-
- 支持天地图矢量、影像、地形底图切换
|
|
21
|
-
- 动态切换底图与注记图层管理
|
|
22
|
-
- 地图裁剪与自定义范围显示
|
|
23
|
-
- 支持 GeoServer WMS 图层
|
|
24
|
-
|
|
1
|
+
# my-openlayer
|
|
2
|
+
|
|
3
|
+
my-openlayer 是一个基于 [OpenLayers](https://openlayers.org/) 的现代地图组件库,专为 Web GIS 应用开发者设计。提供完整的 TypeScript 支持、模块化的类型定义、强大的错误处理和事件管理系统,支持天地图底图加载、要素绘制、图层管理、事件监听等丰富功能,极大提升地图开发效率。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/my-openlayer)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 项目概述
|
|
12
|
+
|
|
13
|
+
- **项目名称**:`my-openlayer`
|
|
14
|
+
- **用途**:基于 OpenLayers 的 TypeScript 地图组件库,提供点/线/面要素、底图切换、热力图、事件与配置管理等能力。
|
|
15
|
+
- **目标用户**:Web GIS 开发者、可视化工程师、前端开发者
|
|
16
|
+
|
|
17
|
+
## 功能亮点
|
|
18
|
+
|
|
19
|
+
- **🗺️ 底图管理 (MapBaseLayers)**
|
|
20
|
+
- 支持天地图矢量、影像、地形底图切换
|
|
21
|
+
- 动态切换底图与注记图层管理
|
|
22
|
+
- 地图裁剪与自定义范围显示
|
|
23
|
+
- 支持 GeoServer WMS 图层
|
|
24
|
+
|
|
25
25
|
- **📍 要素操作**
|
|
26
26
|
- **点位管理 (Point)**:点位标注(自定义图标、聚合、DOM 闪烁、高性能矢量闪烁)
|
|
27
|
-
- **线要素绘制 (Line)
|
|
28
|
-
- **面要素 (Polygon)**:面要素绘制、分区高亮、遮罩层
|
|
29
|
-
- **Vue组件支持 (VueTemplatePoint)**:支持将 Vue 组件作为地图点位渲染
|
|
30
|
-
- **河流图层 (RiverLayerManager)**:支持分级显示的河流图层管理
|
|
31
|
-
|
|
32
|
-
- **🛠️ 地图工具**
|
|
33
|
-
- **测量工具 (MeasureHandler)**:距离和面积测量
|
|
34
|
-
- **要素选择 (SelectHandler)**:支持点击、悬停、多选等交互选择
|
|
35
|
-
- **地图工具 (MapTools)**:图层管理、定位、视图自适应
|
|
36
|
-
- **事件管理 (EventManager)**:统一的地图事件监听与管理
|
|
37
|
-
|
|
38
|
-
- **⚡ 高级特性**
|
|
39
|
-
- **TypeScript 完全支持**:提供完整的类型定义
|
|
40
|
-
- **错误处理 (ErrorHandler)**:统一的错误捕获与日志
|
|
41
|
-
- **配置管理 (ConfigManager)**:集中管理默认配置
|
|
42
|
-
- **坐标系支持**:内置 CGCS2000 坐标系支持
|
|
43
|
-
|
|
44
|
-
## 安装
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
npm install my-openlayer
|
|
48
|
-
# 或
|
|
49
|
-
yarn add my-openlayer
|
|
50
|
-
# 或
|
|
51
|
-
pnpm add my-openlayer
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 依赖要求
|
|
55
|
-
|
|
56
|
-
- **Node.js**: >= 18
|
|
57
|
-
- **OpenLayers**: ^10.6.1
|
|
58
|
-
- **proj4**: ^2.7.5
|
|
59
|
-
- **@turf/turf**: ^7.2.0
|
|
60
|
-
|
|
61
|
-
## 快速上手
|
|
62
|
-
|
|
63
|
-
### 1. 初始化地图
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
import MyOl, { MapInitType } from 'my-openlayer';
|
|
67
|
-
|
|
68
|
-
const mapConfig: MapInitType = {
|
|
69
|
-
center: [119.81, 29.969],
|
|
70
|
-
zoom: 10,
|
|
71
|
-
token: import.meta.env.VITE_TIANDITU_TOKEN, // 天地图 Token
|
|
72
|
-
annotation: true
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const map = new MyOl('map-container', mapConfig);
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### 2. 使用功能模块
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
// 获取模块实例
|
|
82
|
-
const point = map.getPoint();
|
|
83
|
-
const line = map.getLine();
|
|
84
|
-
const polygon = map.getPolygon();
|
|
85
|
-
|
|
86
|
-
// 添加点位
|
|
27
|
+
- **线要素绘制 (Line)**:支持静态线、流光线、流动线图标动画,详见 [Line 动画文档](docs/Line.md#流动线--动态图标线)
|
|
28
|
+
- **面要素 (Polygon)**:面要素绘制、分区高亮、遮罩层
|
|
29
|
+
- **Vue组件支持 (VueTemplatePoint)**:支持将 Vue 组件作为地图点位渲染
|
|
30
|
+
- **河流图层 (RiverLayerManager)**:支持分级显示的河流图层管理
|
|
31
|
+
|
|
32
|
+
- **🛠️ 地图工具**
|
|
33
|
+
- **测量工具 (MeasureHandler)**:距离和面积测量
|
|
34
|
+
- **要素选择 (SelectHandler)**:支持点击、悬停、多选等交互选择
|
|
35
|
+
- **地图工具 (MapTools)**:图层管理、定位、视图自适应
|
|
36
|
+
- **事件管理 (EventManager)**:统一的地图事件监听与管理
|
|
37
|
+
|
|
38
|
+
- **⚡ 高级特性**
|
|
39
|
+
- **TypeScript 完全支持**:提供完整的类型定义
|
|
40
|
+
- **错误处理 (ErrorHandler)**:统一的错误捕获与日志
|
|
41
|
+
- **配置管理 (ConfigManager)**:集中管理默认配置
|
|
42
|
+
- **坐标系支持**:内置 CGCS2000 坐标系支持
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install my-openlayer
|
|
48
|
+
# 或
|
|
49
|
+
yarn add my-openlayer
|
|
50
|
+
# 或
|
|
51
|
+
pnpm add my-openlayer
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 依赖要求
|
|
55
|
+
|
|
56
|
+
- **Node.js**: >= 18
|
|
57
|
+
- **OpenLayers**: ^10.6.1
|
|
58
|
+
- **proj4**: ^2.7.5
|
|
59
|
+
- **@turf/turf**: ^7.2.0
|
|
60
|
+
|
|
61
|
+
## 快速上手
|
|
62
|
+
|
|
63
|
+
### 1. 初始化地图
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import MyOl, { MapInitType } from 'my-openlayer';
|
|
67
|
+
|
|
68
|
+
const mapConfig: MapInitType = {
|
|
69
|
+
center: [119.81, 29.969],
|
|
70
|
+
zoom: 10,
|
|
71
|
+
token: import.meta.env.VITE_TIANDITU_TOKEN, // 天地图 Token
|
|
72
|
+
annotation: true
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const map = new MyOl('map-container', mapConfig);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. 使用功能模块
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// 获取模块实例
|
|
82
|
+
const point = map.getPoint();
|
|
83
|
+
const line = map.getLine();
|
|
84
|
+
const polygon = map.getPolygon();
|
|
85
|
+
|
|
86
|
+
// 添加点位
|
|
87
87
|
point.addPoint([{ lgtd: 119.81, lttd: 29.969, name: '示例点' }], {
|
|
88
88
|
layerName: 'example-point',
|
|
89
89
|
img: 'marker.png'
|
|
@@ -124,68 +124,94 @@ pulseLayer?.stop();
|
|
|
124
124
|
pulseLayer?.start();
|
|
125
125
|
pulseLayer?.remove();
|
|
126
126
|
```
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
|
|
128
|
+
### 4. 添加流动线
|
|
129
|
+
|
|
130
|
+
`Line` 模块现在支持流光线与流动线图标动画,调用方式与 `Point.addPulsePointLayer()` 保持一致,返回可控 handle。
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const flow = map.getLine().addFlowLine(lineData, {
|
|
134
|
+
layerName: 'river-flow',
|
|
135
|
+
animationMode: 'icon+dash',
|
|
136
|
+
strokeColor: '#19b1ff',
|
|
137
|
+
strokeWidth: 3,
|
|
138
|
+
lineDash: [18, 12],
|
|
139
|
+
flowSymbol: {
|
|
140
|
+
src: '/symbols/boat.svg',
|
|
141
|
+
scale: 0.9,
|
|
142
|
+
color: '#19b1ff',
|
|
143
|
+
rotateWithView: true,
|
|
144
|
+
count: 2,
|
|
145
|
+
spacing: 0.2
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
flow?.pause();
|
|
150
|
+
flow?.resume();
|
|
151
|
+
flow?.remove();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 文档索引
|
|
155
|
+
|
|
156
|
+
为了提供更详细的说明,我们将文档拆分为独立的模块文件:
|
|
157
|
+
|
|
158
|
+
### 核心类库
|
|
159
|
+
- **[MyOl](docs/MyOl.md)**: 地图入口类,负责初始化和模块访问。
|
|
160
|
+
- **[MapBaseLayers](docs/MapBaseLayers.md)**: 底图与注记管理。
|
|
161
|
+
- **[ConfigManager](docs/ConfigManager.md)**: 配置管理。
|
|
162
|
+
- **[EventManager](docs/EventManager.md)**: 事件管理。
|
|
163
|
+
- **[ErrorHandler](docs/ErrorHandler.md)**: 错误处理。
|
|
164
|
+
|
|
165
|
+
### 要素操作
|
|
140
166
|
- **[Point](docs/Point.md)**: 点要素(含聚合、DOM 点位、高性能闪烁点)。
|
|
141
|
-
- **[Line](docs/Line.md)**: 线要素。
|
|
142
|
-
- **[Polygon](docs/Polygon.md)**: 面要素(含热力图、图片层)。
|
|
143
|
-
- **[VueTemplatePoint](docs/VueTemplatePoint.md)**: Vue 组件点位。
|
|
144
|
-
- **[RiverLayerManager](docs/RiverLayerManager.md)**: 河流图层管理。
|
|
145
|
-
|
|
146
|
-
### 交互与工具
|
|
147
|
-
- **[SelectHandler](docs/SelectHandler.md)**: 要素选择交互(支持独立样式渲染、多选隔离)。
|
|
148
|
-
- **[MeasureHandler](docs/MeasureHandler.md)**: 测量工具。
|
|
149
|
-
- **[MapTools](docs/MapTools.md)**: 通用地图工具。
|
|
150
|
-
- **[ValidationUtils](docs/ValidationUtils.md)**: 验证工具。
|
|
151
|
-
|
|
152
|
-
## 详细用法示例
|
|
153
|
-
|
|
154
|
-
### 底图切换
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const baseLayers = map.getMapBaseLayers();
|
|
158
|
-
baseLayers.switchBaseLayer('img_c'); // 切换到影像底图
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### 测量工具
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
import { MeasureHandler } from 'my-openlayer';
|
|
165
|
-
|
|
166
|
-
// 需要传入原生的 OpenLayers map 实例
|
|
167
|
-
const measure = new MeasureHandler(map.map);
|
|
168
|
-
|
|
169
|
-
measure.start('LineString'); // 开始测距
|
|
170
|
-
measure.end(); // 结束测量
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
> 注意:部分高级功能(如 SelectHandler)可以通过 `map.getSelectHandler()` 访问。
|
|
174
|
-
|
|
175
|
-
## 贡献指南
|
|
176
|
-
|
|
177
|
-
欢迎提交 Issue 或 Pull Request!
|
|
178
|
-
|
|
179
|
-
1. Fork 本仓库
|
|
180
|
-
2. 新建分支:`git checkout -b feature/your-feature`
|
|
181
|
-
3. 提交更改:`git commit -m 'feat: 新功能描述'`
|
|
182
|
-
4. 推送分支:`git push origin feature/your-feature`
|
|
183
|
-
5. 提交 Pull Request
|
|
184
|
-
|
|
185
|
-
## 许可证
|
|
186
|
-
|
|
187
|
-
[MIT](LICENSE)
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
**联系方式**: 2364184627@qq.com | [GitHub Issues](https://github.com/cuteyuchen/my-openlayer/issues)
|
|
167
|
+
- **[Line](docs/Line.md)**: 线要素。
|
|
168
|
+
- **[Polygon](docs/Polygon.md)**: 面要素(含热力图、图片层)。
|
|
169
|
+
- **[VueTemplatePoint](docs/VueTemplatePoint.md)**: Vue 组件点位。
|
|
170
|
+
- **[RiverLayerManager](docs/RiverLayerManager.md)**: 河流图层管理。
|
|
171
|
+
|
|
172
|
+
### 交互与工具
|
|
173
|
+
- **[SelectHandler](docs/SelectHandler.md)**: 要素选择交互(支持独立样式渲染、多选隔离)。
|
|
174
|
+
- **[MeasureHandler](docs/MeasureHandler.md)**: 测量工具。
|
|
175
|
+
- **[MapTools](docs/MapTools.md)**: 通用地图工具。
|
|
176
|
+
- **[ValidationUtils](docs/ValidationUtils.md)**: 验证工具。
|
|
177
|
+
|
|
178
|
+
## 详细用法示例
|
|
179
|
+
|
|
180
|
+
### 底图切换
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const baseLayers = map.getMapBaseLayers();
|
|
184
|
+
baseLayers.switchBaseLayer('img_c'); // 切换到影像底图
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 测量工具
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { MeasureHandler } from 'my-openlayer';
|
|
191
|
+
|
|
192
|
+
// 需要传入原生的 OpenLayers map 实例
|
|
193
|
+
const measure = new MeasureHandler(map.map);
|
|
194
|
+
|
|
195
|
+
measure.start('LineString'); // 开始测距
|
|
196
|
+
measure.end(); // 结束测量
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
> 注意:部分高级功能(如 SelectHandler)可以通过 `map.getSelectHandler()` 访问。
|
|
200
|
+
|
|
201
|
+
## 贡献指南
|
|
202
|
+
|
|
203
|
+
欢迎提交 Issue 或 Pull Request!
|
|
204
|
+
|
|
205
|
+
1. Fork 本仓库
|
|
206
|
+
2. 新建分支:`git checkout -b feature/your-feature`
|
|
207
|
+
3. 提交更改:`git commit -m 'feat: 新功能描述'`
|
|
208
|
+
4. 推送分支:`git push origin feature/your-feature`
|
|
209
|
+
5. 提交 Pull Request
|
|
210
|
+
|
|
211
|
+
## 许可证
|
|
212
|
+
|
|
213
|
+
[MIT](LICENSE)
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
**联系方式**: 2364184627@qq.com | [GitHub Issues](https://github.com/cuteyuchen/my-openlayer/issues)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Map from "ol/Map";
|
|
2
|
+
import VectorLayer from "ol/layer/Vector";
|
|
3
|
+
import VectorSource from "ol/source/Vector";
|
|
4
|
+
import type { FlowLineLayerHandle, FlowLineOptions, LineOptions, MapJSONData } from "../../types";
|
|
5
|
+
/**
|
|
6
|
+
* 线要素管理类
|
|
7
|
+
* 用于在地图上添加和管理静态线与流动线要素。
|
|
8
|
+
*/
|
|
9
|
+
export default class Line {
|
|
10
|
+
private readonly map;
|
|
11
|
+
private readonly flowLineRegistry;
|
|
12
|
+
private readonly styleFactory;
|
|
13
|
+
constructor(map: Map);
|
|
14
|
+
/**
|
|
15
|
+
* 合并静态线默认配置。
|
|
16
|
+
*/
|
|
17
|
+
private mergeDefaultOptions;
|
|
18
|
+
/**
|
|
19
|
+
* 合并流动线默认配置。
|
|
20
|
+
*/
|
|
21
|
+
private mergeFlowLineOptions;
|
|
22
|
+
/**
|
|
23
|
+
* 创建静态线图层。
|
|
24
|
+
*/
|
|
25
|
+
private createStaticLayer;
|
|
26
|
+
/**
|
|
27
|
+
* 注册流动线句柄。
|
|
28
|
+
*/
|
|
29
|
+
private registerFlowLineHandle;
|
|
30
|
+
/**
|
|
31
|
+
* 注销流动线句柄。
|
|
32
|
+
*/
|
|
33
|
+
private unregisterFlowLineHandle;
|
|
34
|
+
addLine(data: MapJSONData, options?: LineOptions): VectorLayer<VectorSource>;
|
|
35
|
+
addLineByUrl(url: string, options?: LineOptions): VectorLayer<VectorSource>;
|
|
36
|
+
removeLineLayer(layerName: string): void;
|
|
37
|
+
addFlowLine(data: MapJSONData, options?: FlowLineOptions): FlowLineLayerHandle | null;
|
|
38
|
+
addFlowLineByUrl(url: string, options?: FlowLineOptions): Promise<FlowLineLayerHandle | null>;
|
|
39
|
+
removeFlowLineLayer(layerName: string): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import GeoJSON from "ol/format/GeoJSON";
|
|
2
|
+
import VectorLayer from "ol/layer/Vector";
|
|
3
|
+
import VectorSource from "ol/source/Vector";
|
|
4
|
+
import { ErrorHandler } from "../../utils/ErrorHandler";
|
|
5
|
+
import ProjectionUtils from "../../utils/ProjectionUtils";
|
|
6
|
+
import ValidationUtils from "../../utils/ValidationUtils";
|
|
7
|
+
import { ConfigManager, MapTools } from "../map";
|
|
8
|
+
import LineFlowAnimator from "./LineFlowAnimator";
|
|
9
|
+
import LineStyleFactory from "./LineStyleFactory";
|
|
10
|
+
/**
|
|
11
|
+
* 线要素管理类
|
|
12
|
+
* 用于在地图上添加和管理静态线与流动线要素。
|
|
13
|
+
*/
|
|
14
|
+
export default class Line {
|
|
15
|
+
constructor(map) {
|
|
16
|
+
this.flowLineRegistry = new globalThis.Map();
|
|
17
|
+
this.styleFactory = new LineStyleFactory();
|
|
18
|
+
ValidationUtils.validateMapInstance(map);
|
|
19
|
+
this.map = map;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 合并静态线默认配置。
|
|
23
|
+
*/
|
|
24
|
+
mergeDefaultOptions(options) {
|
|
25
|
+
const layerName = options?.layerName || ConfigManager.DEFAULT_LINE_OPTIONS.layerName;
|
|
26
|
+
return {
|
|
27
|
+
...ConfigManager.DEFAULT_LINE_OPTIONS,
|
|
28
|
+
...options,
|
|
29
|
+
layerName
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 合并流动线默认配置。
|
|
34
|
+
*/
|
|
35
|
+
mergeFlowLineOptions(options) {
|
|
36
|
+
const layerName = options?.layerName || ConfigManager.DEFAULT_LINE_OPTIONS.layerName;
|
|
37
|
+
return {
|
|
38
|
+
...ConfigManager.DEFAULT_FLOW_LINE_OPTIONS,
|
|
39
|
+
...options,
|
|
40
|
+
flowSymbol: {
|
|
41
|
+
...ConfigManager.DEFAULT_FLOW_LINE_OPTIONS.flowSymbol,
|
|
42
|
+
...options?.flowSymbol
|
|
43
|
+
},
|
|
44
|
+
layerName
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 创建静态线图层。
|
|
49
|
+
*/
|
|
50
|
+
createStaticLayer(source, options) {
|
|
51
|
+
const layer = new VectorLayer({
|
|
52
|
+
properties: {
|
|
53
|
+
name: options.layerName,
|
|
54
|
+
layerName: options.layerName
|
|
55
|
+
},
|
|
56
|
+
source,
|
|
57
|
+
style: this.styleFactory.createBaseLineStyleResolver(options),
|
|
58
|
+
zIndex: options.zIndex
|
|
59
|
+
});
|
|
60
|
+
layer.setVisible(options.visible ?? true);
|
|
61
|
+
this.map.addLayer(layer);
|
|
62
|
+
return layer;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 注册流动线句柄。
|
|
66
|
+
*/
|
|
67
|
+
registerFlowLineHandle(layerName, handle) {
|
|
68
|
+
this.flowLineRegistry.set(layerName, handle);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 注销流动线句柄。
|
|
72
|
+
*/
|
|
73
|
+
unregisterFlowLineHandle(layerName) {
|
|
74
|
+
this.flowLineRegistry.delete(layerName);
|
|
75
|
+
}
|
|
76
|
+
addLine(data, options) {
|
|
77
|
+
ValidationUtils.validateRequired(data, 'GeoJSON data is required');
|
|
78
|
+
const mergedOptions = this.mergeDefaultOptions(options);
|
|
79
|
+
const features = new GeoJSON().readFeatures(data, ProjectionUtils.getGeoJSONReadOptions(mergedOptions));
|
|
80
|
+
return this.createStaticLayer(new VectorSource({ features }), mergedOptions);
|
|
81
|
+
}
|
|
82
|
+
addLineByUrl(url, options = {}) {
|
|
83
|
+
ValidationUtils.validateNonEmptyString(url, 'Line url is required');
|
|
84
|
+
const mergedOptions = this.mergeDefaultOptions(options);
|
|
85
|
+
const source = new VectorSource({
|
|
86
|
+
url,
|
|
87
|
+
format: new GeoJSON(ProjectionUtils.getGeoJSONReadOptions(mergedOptions))
|
|
88
|
+
});
|
|
89
|
+
return this.createStaticLayer(source, mergedOptions);
|
|
90
|
+
}
|
|
91
|
+
removeLineLayer(layerName) {
|
|
92
|
+
ValidationUtils.validateLayerName(layerName);
|
|
93
|
+
MapTools.removeLayer(this.map, layerName);
|
|
94
|
+
}
|
|
95
|
+
addFlowLine(data, options = {}) {
|
|
96
|
+
const mergedOptions = this.mergeFlowLineOptions(options);
|
|
97
|
+
const layerName = mergedOptions.layerName;
|
|
98
|
+
try {
|
|
99
|
+
ValidationUtils.validateLayerName(layerName);
|
|
100
|
+
this.flowLineRegistry.get(layerName)?.remove();
|
|
101
|
+
const animator = new LineFlowAnimator(this.map, data, mergedOptions, name => {
|
|
102
|
+
this.unregisterFlowLineHandle(name);
|
|
103
|
+
});
|
|
104
|
+
const handle = animator.createHandle();
|
|
105
|
+
if (!handle) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
this.registerFlowLineHandle(layerName, handle);
|
|
109
|
+
return handle;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
ErrorHandler.getInstance().error('[Line] 添加流动线失败:', error);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async addFlowLineByUrl(url, options = {}) {
|
|
117
|
+
const mergedOptions = this.mergeFlowLineOptions(options);
|
|
118
|
+
try {
|
|
119
|
+
ValidationUtils.validateNonEmptyString(url, 'Flow line url is required');
|
|
120
|
+
const response = await fetch(url);
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
throw new Error(`Failed to fetch flow line data: ${response.status}`);
|
|
123
|
+
}
|
|
124
|
+
const jsonData = await response.json();
|
|
125
|
+
if (!jsonData || typeof jsonData !== 'object') {
|
|
126
|
+
throw new Error('Flow line JSON data is invalid');
|
|
127
|
+
}
|
|
128
|
+
return this.addFlowLine(jsonData, mergedOptions);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
ErrorHandler.getInstance().error('[Line] 从 URL 添加流动线失败:', error);
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
removeFlowLineLayer(layerName) {
|
|
136
|
+
ValidationUtils.validateLayerName(layerName);
|
|
137
|
+
const handle = this.flowLineRegistry.get(layerName);
|
|
138
|
+
if (handle) {
|
|
139
|
+
handle.remove();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
MapTools.removeLayer(this.map, [layerName, `${layerName}__flow-animation`]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Feature from 'ol/Feature';
|
|
2
|
+
import { LineString } from 'ol/geom';
|
|
3
|
+
import type { FlowLineOptions } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* 线要素工厂
|
|
6
|
+
* 负责流动线数据标准化、过滤与克隆。
|
|
7
|
+
*/
|
|
8
|
+
export default class LineFeatureFactory {
|
|
9
|
+
/**
|
|
10
|
+
* 标准化线要素,兼容 FeatureCollection / Feature / LineString / MultiLineString。
|
|
11
|
+
*/
|
|
12
|
+
static normalizeLineFeatures(data: unknown, options: FlowLineOptions): Feature<LineString>[];
|
|
13
|
+
/**
|
|
14
|
+
* 克隆线要素,用于基础线与动画线共用独立 source。
|
|
15
|
+
*/
|
|
16
|
+
static cloneLineFeatures(features: Feature<LineString>[]): Feature<LineString>[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import Feature from 'ol/Feature';
|
|
2
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
3
|
+
import { LineString, MultiLineString } from 'ol/geom';
|
|
4
|
+
import { ErrorHandler } from '../../utils/ErrorHandler';
|
|
5
|
+
import ProjectionUtils from '../../utils/ProjectionUtils';
|
|
6
|
+
/**
|
|
7
|
+
* 线要素工厂
|
|
8
|
+
* 负责流动线数据标准化、过滤与克隆。
|
|
9
|
+
*/
|
|
10
|
+
export default class LineFeatureFactory {
|
|
11
|
+
/**
|
|
12
|
+
* 标准化线要素,兼容 FeatureCollection / Feature / LineString / MultiLineString。
|
|
13
|
+
*/
|
|
14
|
+
static normalizeLineFeatures(data, options) {
|
|
15
|
+
if (!data) {
|
|
16
|
+
ErrorHandler.getInstance().error('[LineFeatureFactory] 流动线数据不能为空');
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const readOptions = ProjectionUtils.getGeoJSONReadOptions(options);
|
|
21
|
+
const features = new GeoJSON().readFeatures(data, readOptions);
|
|
22
|
+
const normalizedFeatures = [];
|
|
23
|
+
features.forEach(feature => {
|
|
24
|
+
const geometry = feature.getGeometry();
|
|
25
|
+
if (!geometry) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const properties = { ...feature.getProperties() };
|
|
29
|
+
delete properties.geometry;
|
|
30
|
+
if (geometry instanceof LineString) {
|
|
31
|
+
if (geometry.getCoordinates().length >= 2) {
|
|
32
|
+
normalizedFeatures.push(new Feature({
|
|
33
|
+
...properties,
|
|
34
|
+
geometry: geometry.clone()
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (geometry instanceof MultiLineString) {
|
|
40
|
+
geometry.getLineStrings().forEach((lineString, index) => {
|
|
41
|
+
if (lineString.getCoordinates().length < 2) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
normalizedFeatures.push(new Feature({
|
|
45
|
+
...properties,
|
|
46
|
+
__segmentIndex: index,
|
|
47
|
+
geometry: lineString.clone()
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (normalizedFeatures.length === 0) {
|
|
53
|
+
ErrorHandler.getInstance().error('[LineFeatureFactory] 未找到可用于流动线动画的线要素');
|
|
54
|
+
}
|
|
55
|
+
return normalizedFeatures;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
ErrorHandler.getInstance().error('[LineFeatureFactory] 标准化流动线数据失败:', error);
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 克隆线要素,用于基础线与动画线共用独立 source。
|
|
64
|
+
*/
|
|
65
|
+
static cloneLineFeatures(features) {
|
|
66
|
+
return features.map(feature => {
|
|
67
|
+
const properties = { ...feature.getProperties() };
|
|
68
|
+
delete properties.geometry;
|
|
69
|
+
return new Feature({
|
|
70
|
+
...properties,
|
|
71
|
+
geometry: feature.getGeometry()?.clone()
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Map from 'ol/Map';
|
|
2
|
+
import { LineString } from 'ol/geom';
|
|
3
|
+
import type { FlowLineLayerHandle, FlowLineOptions } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* 流动线动画器
|
|
6
|
+
* 负责动画生命周期、postrender 与 RAF 驱动。
|
|
7
|
+
*/
|
|
8
|
+
export default class LineFlowAnimator {
|
|
9
|
+
private readonly map;
|
|
10
|
+
private readonly onRemove?;
|
|
11
|
+
private readonly maxSymbolCount;
|
|
12
|
+
private readonly styleFactory;
|
|
13
|
+
private readonly animationPointGeometry;
|
|
14
|
+
private readonly animationPointFeature;
|
|
15
|
+
private options;
|
|
16
|
+
private normalizedFeatures;
|
|
17
|
+
private baseSource;
|
|
18
|
+
private animationSource;
|
|
19
|
+
private baseLayer;
|
|
20
|
+
private animationLayer;
|
|
21
|
+
private dashStyle;
|
|
22
|
+
private state;
|
|
23
|
+
private startTime;
|
|
24
|
+
private pausedAt;
|
|
25
|
+
private pausedDuration;
|
|
26
|
+
private frozenProgress;
|
|
27
|
+
private rafId;
|
|
28
|
+
private postrenderKey;
|
|
29
|
+
constructor(map: Map, data: unknown, options?: FlowLineOptions, onRemove?: (layerName: string) => void);
|
|
30
|
+
createHandle(): FlowLineLayerHandle | null;
|
|
31
|
+
getProgressByTime(now: number, startTime: number, duration: number, speed: number, loop: boolean): number;
|
|
32
|
+
getCoordinateAndRotation(line: LineString, progress: number): {
|
|
33
|
+
coordinate: number[];
|
|
34
|
+
rotation: number;
|
|
35
|
+
};
|
|
36
|
+
start(): void;
|
|
37
|
+
pause(): void;
|
|
38
|
+
resume(): void;
|
|
39
|
+
stop(): void;
|
|
40
|
+
setVisible(visible: boolean): void;
|
|
41
|
+
updateData(data: unknown): void;
|
|
42
|
+
remove(): void;
|
|
43
|
+
private createBaseLayer;
|
|
44
|
+
private createAnimationLayer;
|
|
45
|
+
private normalizeOptions;
|
|
46
|
+
private updateSources;
|
|
47
|
+
private bindPostrender;
|
|
48
|
+
private unbindPostrender;
|
|
49
|
+
private startRafLoop;
|
|
50
|
+
private stopRafLoop;
|
|
51
|
+
private getCurrentProgress;
|
|
52
|
+
private getNow;
|
|
53
|
+
}
|