my-openlayer 2.4.8 → 2.4.9

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/docs/Line.md CHANGED
@@ -1,187 +1,187 @@
1
- # Line 线要素类
2
-
3
- `Line` 类用于在地图上绘制线要素,支持 GeoJSON 数据加载、自定义样式和图层管理。
4
-
5
- ## 构造函数
6
-
7
- ```typescript
8
- const line = new Line(map: Map);
9
- ```
10
-
11
- - **map**: OpenLayers 地图实例。
12
-
13
- ## 接口定义
14
-
15
- ### LineOptions
16
-
17
- 配置线图层的样式、属性和行为。继承自 `BaseOptions`, `StyleOptions`, `TextOptions`。
18
-
19
- | 属性 | 类型 | 说明 |
20
- | :--- | :--- | :--- |
21
- | **基础配置** | | |
22
- | `layerName` | `string` | 图层名称,用于唯一标识和管理图层 |
23
- | `zIndex` | `number` | 图层层级,默认自动处理 |
24
- | `visible` | `boolean` | 图层是否可见,默认 `true` |
25
- | `opacity` | `number` | 图层透明度 (0-1) |
26
- | `fitView` | `boolean` | 添加要素后是否自动缩放视图以适应要素范围 |
27
- | **样式配置** | | |
28
- | `strokeColor` | `string` \| `number[]` | 线条颜色,如 `'#ff0000'` 或 `[255, 0, 0, 1]` |
29
- | `strokeWidth` | `number` | 线条宽度(像素) |
30
- | `lineDash` | `number[]` | 虚线模式,如 `[10, 10]` 表示 10px 实线 10px 间隔 |
31
- | `lineDashOffset` | `number` | 虚线偏移量 |
32
- | `style` | `Style` \| `Function` | 自定义 OpenLayers 样式或样式函数 |
33
- | **文本标注** | | |
34
- | `textVisible` | `boolean` | 是否显示文本标注 |
35
- | `textCallBack` | `(feature) => string` | 获取文本内容的回调函数 |
36
- | `textFont` | `string` | 字体样式,默认 `'12px sans-serif'` |
37
- | `textFillColor` | `string` | 文本填充颜色 |
38
- | `textStrokeColor` | `string` | 文本描边颜色 |
39
- | `textStrokeWidth` | `number` | 文本描边宽度 |
40
- | `textOffsetY` | `number` | 文本 Y 轴偏移量 |
41
- | **其他** | | |
42
- | `type` | `string` | 线条类型标识,会写入 Feature 的属性中 |
43
-
44
- ### MapJSONData (GeoJSON)
45
-
46
- 标准的 GeoJSON 格式数据结构。
47
-
48
- ```typescript
49
- interface MapJSONData {
50
- type: string; // 通常为 "FeatureCollection"
51
- name?: string; // 数据集名称
52
- features: FeatureData[]; // 要素数组
53
- }
54
-
55
- interface FeatureData {
56
- type: string; // "Feature"
57
- properties: any; // 属性对象
58
- geometry: {
59
- type: "LineString" | "MultiLineString";
60
- coordinates: number[][] | number[][][];
61
- };
62
- }
63
- ```
64
-
65
- ## 方法
66
-
67
- ### addLine
68
-
69
- 添加线要素图层。
70
-
71
- ```typescript
72
- addLine(data: MapJSONData, options?: LineOptions): VectorLayer<VectorSource>
73
- ```
74
-
75
- | 参数 | 类型 | 说明 |
76
- | :--- | :--- | :--- |
77
- | `data` | `MapJSONData` | GeoJSON 格式的线数据 |
78
- | `options` | `LineOptions` | 图层配置项 |
79
-
80
- **返回**: 创建的 `VectorLayer` 实例。
81
-
82
- ### addLineByUrl
83
-
84
- 从 URL 加载并添加线要素图层。
85
-
86
- ```typescript
87
- addLineByUrl(url: string, options?: LineOptions): VectorLayer<VectorSource>
88
- ```
89
-
90
- | 参数 | 类型 | 说明 |
91
- | :--- | :--- | :--- |
92
- | `url` | `string` | GeoJSON 数据的 URL 地址 |
93
- | `options` | `LineOptions` | 图层配置项 |
94
-
95
- **返回**: 创建的 `VectorLayer` 实例。
96
-
97
- ### removeLineLayer
98
-
99
- 根据图层名称移除线图层。
100
-
101
- ```typescript
102
- removeLineLayer(layerName: string): void
103
- ```
104
-
105
- | 参数 | 类型 | 说明 |
106
- | :--- | :--- | :--- |
107
- | `layerName` | `string` | 要移除的图层名称 |
108
-
109
- ## 使用示例
110
-
111
- ### 基础用法
112
-
113
- ```typescript
114
- const lineModule = map.getLine();
115
-
116
- // GeoJSON 数据
117
- const lineData = {
118
- type: 'FeatureCollection',
119
- features: [
120
- {
121
- type: 'Feature',
122
- geometry: {
123
- type: 'LineString',
124
- coordinates: [[119.8, 29.9], [119.9, 30.0]]
125
- },
126
- properties: { name: '线路1', status: 'active' }
127
- }
128
- ]
129
- };
130
-
131
- // 添加红色实线
132
- lineModule.addLine(lineData, {
133
- layerName: 'base-line',
134
- strokeColor: '#ff0000',
135
- strokeWidth: 3,
136
- fitView: true
137
- });
138
- ```
139
-
140
- ### 虚线与标注
141
-
142
- ```typescript
143
- lineModule.addLine(lineData, {
144
- layerName: 'dash-line',
145
- strokeColor: '#0000ff',
146
- strokeWidth: 2,
147
- lineDash: [10, 5], // 10px实线,5px间隔
148
- textVisible: true,
149
- textFillColor: '#000',
150
- textStrokeColor: '#fff',
151
- textStrokeWidth: 2,
152
- // 动态获取显示的文本
153
- textCallBack: (feature) => feature.get('name')
154
- });
155
- ```
156
-
157
- ### 自定义样式函数
158
-
159
- ```typescript
160
- import { Style, Stroke } from 'ol/style';
161
-
162
- lineModule.addLine(lineData, {
163
- layerName: 'custom-style-line',
164
- // 根据属性动态设置颜色
165
- style: (feature) => {
166
- const status = feature.get('properties').status;
167
- const color = status === 'active' ? 'green' : 'gray';
168
-
169
- return new Style({
170
- stroke: new Stroke({
171
- color: color,
172
- width: 4
173
- })
174
- });
175
- }
176
- });
177
- ```
178
-
179
- ### 从接口加载
180
-
181
- ```typescript
182
- lineModule.addLineByUrl('/api/lines/all.json', {
183
- layerName: 'api-lines',
184
- strokeColor: 'orange',
185
- strokeWidth: 2
186
- });
187
- ```
1
+ # Line 线要素类
2
+
3
+ `Line` 类用于在地图上绘制线要素,支持 GeoJSON 数据加载、自定义样式和图层管理。
4
+
5
+ ## 构造函数
6
+
7
+ ```typescript
8
+ const line = new Line(map: Map);
9
+ ```
10
+
11
+ - **map**: OpenLayers 地图实例。
12
+
13
+ ## 接口定义
14
+
15
+ ### LineOptions
16
+
17
+ 配置线图层的样式、属性和行为。继承自 `BaseOptions`, `StyleOptions`, `TextOptions`。
18
+
19
+ | 属性 | 类型 | 说明 |
20
+ | :--- | :--- | :--- |
21
+ | **基础配置** | | |
22
+ | `layerName` | `string` | 图层名称,用于唯一标识和管理图层 |
23
+ | `zIndex` | `number` | 图层层级,默认自动处理 |
24
+ | `visible` | `boolean` | 图层是否可见,默认 `true` |
25
+ | `opacity` | `number` | 图层透明度 (0-1) |
26
+ | `fitView` | `boolean` | 添加要素后是否自动缩放视图以适应要素范围 |
27
+ | **样式配置** | | |
28
+ | `strokeColor` | `string` \| `number[]` | 线条颜色,如 `'#ff0000'` 或 `[255, 0, 0, 1]` |
29
+ | `strokeWidth` | `number` | 线条宽度(像素) |
30
+ | `lineDash` | `number[]` | 虚线模式,如 `[10, 10]` 表示 10px 实线 10px 间隔 |
31
+ | `lineDashOffset` | `number` | 虚线偏移量 |
32
+ | `style` | `Style` \| `Function` | 自定义 OpenLayers 样式或样式函数 |
33
+ | **文本标注** | | |
34
+ | `textVisible` | `boolean` | 是否显示文本标注 |
35
+ | `textCallBack` | `(feature) => string` | 获取文本内容的回调函数 |
36
+ | `textFont` | `string` | 字体样式,默认 `'12px sans-serif'` |
37
+ | `textFillColor` | `string` | 文本填充颜色 |
38
+ | `textStrokeColor` | `string` | 文本描边颜色 |
39
+ | `textStrokeWidth` | `number` | 文本描边宽度 |
40
+ | `textOffsetY` | `number` | 文本 Y 轴偏移量 |
41
+ | **其他** | | |
42
+ | `type` | `string` | 线条类型标识,会写入 Feature 的属性中 |
43
+
44
+ ### MapJSONData (GeoJSON)
45
+
46
+ 标准的 GeoJSON 格式数据结构。
47
+
48
+ ```typescript
49
+ interface MapJSONData {
50
+ type: string; // 通常为 "FeatureCollection"
51
+ name?: string; // 数据集名称
52
+ features: FeatureData[]; // 要素数组
53
+ }
54
+
55
+ interface FeatureData {
56
+ type: string; // "Feature"
57
+ properties: any; // 属性对象
58
+ geometry: {
59
+ type: "LineString" | "MultiLineString";
60
+ coordinates: number[][] | number[][][];
61
+ };
62
+ }
63
+ ```
64
+
65
+ ## 方法
66
+
67
+ ### addLine
68
+
69
+ 添加线要素图层。
70
+
71
+ ```typescript
72
+ addLine(data: MapJSONData, options?: LineOptions): VectorLayer<VectorSource>
73
+ ```
74
+
75
+ | 参数 | 类型 | 说明 |
76
+ | :--- | :--- | :--- |
77
+ | `data` | `MapJSONData` | GeoJSON 格式的线数据 |
78
+ | `options` | `LineOptions` | 图层配置项 |
79
+
80
+ **返回**: 创建的 `VectorLayer` 实例。
81
+
82
+ ### addLineByUrl
83
+
84
+ 从 URL 加载并添加线要素图层。
85
+
86
+ ```typescript
87
+ addLineByUrl(url: string, options?: LineOptions): VectorLayer<VectorSource>
88
+ ```
89
+
90
+ | 参数 | 类型 | 说明 |
91
+ | :--- | :--- | :--- |
92
+ | `url` | `string` | GeoJSON 数据的 URL 地址 |
93
+ | `options` | `LineOptions` | 图层配置项 |
94
+
95
+ **返回**: 创建的 `VectorLayer` 实例。
96
+
97
+ ### removeLineLayer
98
+
99
+ 根据图层名称移除线图层。
100
+
101
+ ```typescript
102
+ removeLineLayer(layerName: string): void
103
+ ```
104
+
105
+ | 参数 | 类型 | 说明 |
106
+ | :--- | :--- | :--- |
107
+ | `layerName` | `string` | 要移除的图层名称 |
108
+
109
+ ## 使用示例
110
+
111
+ ### 基础用法
112
+
113
+ ```typescript
114
+ const lineModule = map.getLine();
115
+
116
+ // GeoJSON 数据
117
+ const lineData = {
118
+ type: 'FeatureCollection',
119
+ features: [
120
+ {
121
+ type: 'Feature',
122
+ geometry: {
123
+ type: 'LineString',
124
+ coordinates: [[119.8, 29.9], [119.9, 30.0]]
125
+ },
126
+ properties: { name: '线路1', status: 'active' }
127
+ }
128
+ ]
129
+ };
130
+
131
+ // 添加红色实线
132
+ lineModule.addLine(lineData, {
133
+ layerName: 'base-line',
134
+ strokeColor: '#ff0000',
135
+ strokeWidth: 3,
136
+ fitView: true
137
+ });
138
+ ```
139
+
140
+ ### 虚线与标注
141
+
142
+ ```typescript
143
+ lineModule.addLine(lineData, {
144
+ layerName: 'dash-line',
145
+ strokeColor: '#0000ff',
146
+ strokeWidth: 2,
147
+ lineDash: [10, 5], // 10px实线,5px间隔
148
+ textVisible: true,
149
+ textFillColor: '#000',
150
+ textStrokeColor: '#fff',
151
+ textStrokeWidth: 2,
152
+ // 动态获取显示的文本
153
+ textCallBack: (feature) => feature.get('name')
154
+ });
155
+ ```
156
+
157
+ ### 自定义样式函数
158
+
159
+ ```typescript
160
+ import { Style, Stroke } from 'ol/style';
161
+
162
+ lineModule.addLine(lineData, {
163
+ layerName: 'custom-style-line',
164
+ // 根据属性动态设置颜色
165
+ style: (feature) => {
166
+ const status = feature.get('properties').status;
167
+ const color = status === 'active' ? 'green' : 'gray';
168
+
169
+ return new Style({
170
+ stroke: new Stroke({
171
+ color: color,
172
+ width: 4
173
+ })
174
+ });
175
+ }
176
+ });
177
+ ```
178
+
179
+ ### 从接口加载
180
+
181
+ ```typescript
182
+ lineModule.addLineByUrl('/api/lines/all.json', {
183
+ layerName: 'api-lines',
184
+ strokeColor: 'orange',
185
+ strokeWidth: 2
186
+ });
187
+ ```