my-openlayer 2.4.6 → 2.4.8
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 +101 -0
- package/MyOl.js +1 -1
- package/core/Point.js +10 -2
- package/docs/.vitepress/cache/deps/@theme_index.js +275 -0
- package/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
- package/docs/.vitepress/cache/deps/_metadata.json +40 -0
- package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js +12542 -0
- package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js.map +7 -0
- package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js +9719 -0
- package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js.map +7 -0
- package/docs/.vitepress/cache/deps/package.json +3 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/docs/.vitepress/cache/deps/vue.js +343 -0
- package/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/docs/.vitepress/config.mts +57 -0
- package/docs/ConfigManager.md +57 -26
- package/docs/ErrorHandler.md +88 -27
- package/docs/EventManager.md +120 -30
- package/docs/Line.md +153 -18
- package/docs/MapBaseLayers.md +171 -21
- package/docs/MapTools.md +139 -15
- package/docs/MeasureHandler.md +71 -31
- package/docs/MyOl.md +220 -35
- package/docs/Point.md +141 -34
- package/docs/Polygon.md +204 -28
- package/docs/RiverLayerManager.md +156 -28
- package/docs/SelectHandler.md +110 -89
- package/docs/ValidationUtils.md +65 -20
- package/docs/VueTemplatePoint.md +155 -26
- package/docs/index.md +78 -0
- package/package.json +7 -3
package/docs/SelectHandler.md
CHANGED
|
@@ -1,126 +1,147 @@
|
|
|
1
|
-
# SelectHandler
|
|
1
|
+
# SelectHandler 类
|
|
2
2
|
|
|
3
|
-
`SelectHandler`
|
|
3
|
+
`SelectHandler` 类用于处理地图上的要素选择交互,支持点击、悬停、Ctrl+点击等多种模式,并支持编程式选择。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 构造函数
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
```typescript
|
|
8
|
+
constructor(map: Map)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **map**: OpenLayers 地图实例。
|
|
12
|
+
|
|
13
|
+
## 接口定义
|
|
14
|
+
|
|
15
|
+
### SelectOptions
|
|
16
|
+
|
|
17
|
+
| 属性名 | 类型 | 说明 |
|
|
18
|
+
| :--- | :--- | :--- |
|
|
19
|
+
| multi | `boolean` | 是否支持多选,默认 `false` |
|
|
20
|
+
| layerFilter | `string[]` | 图层过滤器,指定可选择的图层名称列表 |
|
|
21
|
+
| featureFilter | `(feature: FeatureLike) => boolean` | 要素过滤器函数 |
|
|
22
|
+
| hitTolerance | `number` | 点击容差(像素),默认为 0 |
|
|
23
|
+
| selectStyle | `Style \| Style[] \| ((feature: FeatureLike) => Style \| Style[])` | 选中要素的样式 |
|
|
24
|
+
| onSelect | `(event: SelectCallbackEvent) => void` | 选中要素时的回调函数 |
|
|
25
|
+
| onDeselect | `(event: SelectCallbackEvent) => void` | 取消选中要素时的回调函数 |
|
|
26
|
+
|
|
27
|
+
### ProgrammaticSelectOptions
|
|
28
|
+
|
|
29
|
+
| 属性名 | 类型 | 说明 |
|
|
30
|
+
| :--- | :--- | :--- |
|
|
31
|
+
| layerName | `string` | 图层名称,指定在哪个图层中选择要素 |
|
|
32
|
+
| selectStyle | `Style \| Style[] \| ((feature: FeatureLike) => Style \| Style[])` | 自定义选中样式(仅作用于此次选择) |
|
|
33
|
+
| fitView | `boolean` | 是否定位至选中要素,默认 `false` |
|
|
34
|
+
| fitDuration | `number` | 定位动画持续时间(毫秒),默认 500 |
|
|
35
|
+
| fitPadding | `number` | 定位时的边距(像素),默认 100 |
|
|
36
|
+
|
|
37
|
+
### SelectMode
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
type SelectMode = 'click' | 'hover' | 'ctrl';
|
|
41
|
+
```
|
|
11
42
|
|
|
12
43
|
## 方法
|
|
13
44
|
|
|
14
|
-
###
|
|
45
|
+
### enableSelect
|
|
46
|
+
|
|
47
|
+
启用要素选择。
|
|
15
48
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
49
|
+
```typescript
|
|
50
|
+
enableSelect(mode: SelectMode = 'click', options?: SelectOptions): this
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- **mode**: 选择模式。
|
|
54
|
+
- **options**: 配置选项。
|
|
55
|
+
- **返回值**: `SelectHandler` 实例,支持链式调用。
|
|
56
|
+
|
|
57
|
+
### disableSelect
|
|
24
58
|
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
禁用要素选择。
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
disableSelect(): this
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- **返回值**: `SelectHandler` 实例。
|
|
66
|
+
|
|
67
|
+
### clearSelection
|
|
68
|
+
|
|
69
|
+
清除所有选择(包括交互式和编程式)。
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
clearSelection(): this
|
|
73
|
+
```
|
|
27
74
|
|
|
28
|
-
|
|
75
|
+
- **返回值**: `SelectHandler` 实例。
|
|
29
76
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
77
|
+
### selectByIds
|
|
78
|
+
|
|
79
|
+
通过要素 ID 编程式选择要素。
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
selectByIds(featureIds: string[], options?: ProgrammaticSelectOptions): this
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- **featureIds**: 要素 ID 数组。
|
|
86
|
+
- **options**: 编程式选择选项。
|
|
87
|
+
- **返回值**: `SelectHandler` 实例。
|
|
88
|
+
|
|
89
|
+
### selectByProperty
|
|
90
|
+
|
|
91
|
+
通过属性编程式选择要素。
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
selectByProperty(propertyName: string, propertyValue: any, options?: ProgrammaticSelectOptions): this
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- **propertyName**: 属性名。
|
|
98
|
+
- **propertyValue**: 属性值。
|
|
99
|
+
- **options**: 编程式选择选项。
|
|
100
|
+
- **返回值**: `SelectHandler` 实例。
|
|
34
101
|
|
|
35
102
|
## 使用示例
|
|
36
103
|
|
|
37
|
-
###
|
|
104
|
+
### 启用点击选择
|
|
38
105
|
|
|
39
106
|
```typescript
|
|
40
|
-
|
|
107
|
+
import { SelectHandler } from 'my-openlayers';
|
|
108
|
+
|
|
109
|
+
const selectHandler = new SelectHandler(map);
|
|
41
110
|
|
|
42
|
-
//
|
|
111
|
+
// 启用点击选择,仅针对 'cities' 图层
|
|
43
112
|
selectHandler.enableSelect('click', {
|
|
44
|
-
|
|
45
|
-
layerFilter: ['target-layer'], // 仅选择特定图层的要素
|
|
113
|
+
layerFilter: ['cities'],
|
|
46
114
|
onSelect: (event) => {
|
|
47
|
-
|
|
48
|
-
console.log('选中要素:', feature.getProperties());
|
|
115
|
+
console.log('Selected:', event.selected);
|
|
49
116
|
},
|
|
50
117
|
onDeselect: (event) => {
|
|
51
|
-
console.log('
|
|
52
|
-
}
|
|
53
|
-
// 自定义选中样式(简单对象)
|
|
54
|
-
selectStyle: new Style({
|
|
55
|
-
image: new Circle({
|
|
56
|
-
radius: 8,
|
|
57
|
-
fill: new Fill({ color: 'red' }),
|
|
58
|
-
stroke: new Stroke({ color: 'white', width: 2 })
|
|
59
|
-
})
|
|
60
|
-
})
|
|
118
|
+
console.log('Deselected:', event.deselected);
|
|
119
|
+
}
|
|
61
120
|
});
|
|
62
121
|
```
|
|
63
122
|
|
|
64
|
-
###
|
|
65
|
-
|
|
66
|
-
利用函数式 `selectStyle`,可以在选中时动态获取要素的原始样式,并在此基础上修改(例如只改边框颜色,保留填充)。由于采用了**样式固化**机制,这种写法是安全的。
|
|
123
|
+
### 启用悬停高亮
|
|
67
124
|
|
|
68
125
|
```typescript
|
|
69
|
-
selectHandler.enableSelect('
|
|
70
|
-
selectStyle: (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const originStyleLike = feature.getStyle();
|
|
74
|
-
let originStyle = originStyleLike;
|
|
75
|
-
|
|
76
|
-
// 如果原始样式是函数,执行它获取 Style 对象
|
|
77
|
-
if (typeof originStyleLike === 'function') {
|
|
78
|
-
originStyle = originStyleLike(feature, resolution);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 归一化为数组
|
|
82
|
-
const styles = Array.isArray(originStyle) ? originStyle : [originStyle];
|
|
83
|
-
|
|
84
|
-
// 克隆并修改样式(例如:将边框改为青色)
|
|
85
|
-
return styles.map(s => {
|
|
86
|
-
const clone = s.clone();
|
|
87
|
-
const stroke = clone.getStroke();
|
|
88
|
-
if (stroke) {
|
|
89
|
-
stroke.setColor('#00FFFF');
|
|
90
|
-
stroke.setWidth(3);
|
|
91
|
-
} else {
|
|
92
|
-
// 如果没有边框,添加一个
|
|
93
|
-
clone.setStroke(new Stroke({ color: '#00FFFF', width: 3 }));
|
|
94
|
-
}
|
|
95
|
-
return clone;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
126
|
+
selectHandler.enableSelect('hover', {
|
|
127
|
+
selectStyle: new Style({
|
|
128
|
+
stroke: new Stroke({ color: 'yellow', width: 4 })
|
|
129
|
+
})
|
|
98
130
|
});
|
|
99
131
|
```
|
|
100
132
|
|
|
101
|
-
###
|
|
102
|
-
|
|
103
|
-
编程式选择支持传入特定的样式,该样式将独立于主交互样式生效,且支持多要素使用不同样式。
|
|
133
|
+
### 编程式选择并定位
|
|
104
134
|
|
|
105
135
|
```typescript
|
|
106
|
-
//
|
|
107
|
-
selectHandler.selectByIds(['
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// 同时选中 ID 为 'feature-2' 的要素,但用蓝色高亮(互不冲突)
|
|
113
|
-
selectHandler.selectByIds(['feature-2'], {
|
|
114
|
-
selectStyle: new Style({ stroke: new Stroke({ color: 'blue', width: 4 }) })
|
|
136
|
+
// 选择 ID 为 'beijing' 的要素并自动定位
|
|
137
|
+
selectHandler.selectByIds(['beijing'], {
|
|
138
|
+
fitView: true,
|
|
139
|
+
fitPadding: 50
|
|
115
140
|
});
|
|
116
141
|
```
|
|
117
142
|
|
|
118
|
-
###
|
|
143
|
+
### 清除选择
|
|
119
144
|
|
|
120
145
|
```typescript
|
|
121
|
-
// 禁用用户交互(停止响应点击,但保留编程式高亮)
|
|
122
|
-
selectHandler.disableSelect();
|
|
123
|
-
|
|
124
|
-
// 清除所有选择(包括交互式和编程式的高亮)
|
|
125
146
|
selectHandler.clearSelection();
|
|
126
147
|
```
|
package/docs/ValidationUtils.md
CHANGED
|
@@ -1,38 +1,83 @@
|
|
|
1
|
-
# ValidationUtils
|
|
1
|
+
# ValidationUtils 验证工具
|
|
2
2
|
|
|
3
|
-
`ValidationUtils`
|
|
3
|
+
`ValidationUtils` 提供了一系列静态方法,用于验证地图操作中的各种参数和数据,确保数据的完整性和类型正确性。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 导入
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
```typescript
|
|
8
|
+
import { ValidationUtils } from 'my-openlayer';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 静态方法
|
|
12
|
+
|
|
13
|
+
### 坐标验证
|
|
14
|
+
|
|
15
|
+
| 方法名 | 参数 | 返回值 | 描述 |
|
|
16
|
+
| :--- | :--- | :--- | :--- |
|
|
17
|
+
| `isValidCoordinate(longitude, latitude)` | `longitude: number`<br>`latitude: number` | `boolean` | 验证经纬度坐标是否有效(数字且在合法范围内) |
|
|
18
|
+
| `validateCoordinate(longitude, latitude)` | `longitude: number`<br>`latitude: number` | `void` | 验证经纬度,无效时抛出异常 |
|
|
19
|
+
|
|
20
|
+
### 数据验证
|
|
21
|
+
|
|
22
|
+
| 方法名 | 参数 | 返回值 | 描述 |
|
|
23
|
+
| :--- | :--- | :--- | :--- |
|
|
24
|
+
| `validatePointData(pointData)` | `pointData: any[]` | `boolean` | 验证点位数据数组是否有效 |
|
|
25
|
+
| `validateOptions(options)` | `options: any` | `boolean` | 验证配置选项是否为对象 |
|
|
26
|
+
| `validateMaskData(data)` | `data: any` | `void` | 验证遮罩数据,无效时抛出异常 |
|
|
27
|
+
|
|
28
|
+
### 对象/实例验证
|
|
29
|
+
|
|
30
|
+
| 方法名 | 参数 | 返回值 | 描述 |
|
|
31
|
+
| :--- | :--- | :--- | :--- |
|
|
32
|
+
| `validateMapInstance(map)` | `map: any` | `void` | 验证 OpenLayers 地图实例是否存在 |
|
|
33
|
+
| `validateElementId(id)` | `id: string` | `boolean` | 验证 DOM 元素 ID 是否存在 |
|
|
34
|
+
| `validateVueParams(pointInfoList, template, Vue)` | `pointInfoList: any[]`<br>`template: any`<br>`Vue: any` | `boolean` | 验证 Vue 组件相关参数 |
|
|
35
|
+
|
|
36
|
+
### 通用验证
|
|
37
|
+
|
|
38
|
+
| 方法名 | 参数 | 返回值 | 描述 |
|
|
39
|
+
| :--- | :--- | :--- | :--- |
|
|
40
|
+
| `validateRequired(value, message)` | `value: any`<br>`message: string` | `void` | 验证值是否存在,否则抛出带消息的异常 |
|
|
41
|
+
| `validateType(value, expectedType, message)` | `value: any`<br>`expectedType: string`<br>`message: string` | `void` | 验证值类型,否则抛出带消息的异常 |
|
|
13
42
|
|
|
14
43
|
## 使用示例
|
|
15
44
|
|
|
45
|
+
### 验证坐标
|
|
46
|
+
|
|
16
47
|
```typescript
|
|
17
48
|
import { ValidationUtils } from 'my-openlayer';
|
|
18
49
|
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const lat = 30.2;
|
|
50
|
+
const lng = 120.5;
|
|
51
|
+
const lat = 30.5;
|
|
22
52
|
|
|
23
53
|
if (ValidationUtils.isValidCoordinate(lng, lat)) {
|
|
24
|
-
|
|
54
|
+
// 坐标有效,执行操作
|
|
55
|
+
map.getView().setCenter([lng, lat]);
|
|
25
56
|
} else {
|
|
26
|
-
console.error('
|
|
57
|
+
console.error('Invalid coordinates');
|
|
27
58
|
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 验证必填参数
|
|
28
62
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
63
|
+
```typescript
|
|
64
|
+
function initLayer(map, options) {
|
|
65
|
+
try {
|
|
66
|
+
ValidationUtils.validateMapInstance(map);
|
|
67
|
+
ValidationUtils.validateRequired(options, 'Options are required');
|
|
68
|
+
|
|
69
|
+
// 初始化图层
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Initialization failed:', error.message);
|
|
72
|
+
}
|
|
32
73
|
}
|
|
74
|
+
```
|
|
33
75
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
76
|
+
### 验证 Vue 组件参数
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
if (ValidationUtils.validateVueParams(points, MyComponent, Vue)) {
|
|
80
|
+
// 创建 Vue 覆盖物
|
|
81
|
+
new VueTemplatePoint(map).addVueTemplatePoint(points, MyComponent);
|
|
37
82
|
}
|
|
38
83
|
```
|
package/docs/VueTemplatePoint.md
CHANGED
|
@@ -1,24 +1,121 @@
|
|
|
1
1
|
# VueTemplatePoint Vue 组件点位类
|
|
2
2
|
|
|
3
|
-
`VueTemplatePoint` 允许将 Vue 组件直接渲染为地图上的点位覆盖物(Overlay),支持 Vue 2 和 Vue 3
|
|
3
|
+
`VueTemplatePoint` 允许将 Vue 组件直接渲染为地图上的点位覆盖物(Overlay),支持 Vue 2 和 Vue 3。它通过创建 Overlay 并将 Vue 组件挂载到 Overlay 的 DOM 元素中来实现。
|
|
4
|
+
|
|
5
|
+
## 构造函数
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
constructor(map: Map)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **参数**:
|
|
12
|
+
- `map` (Map): OpenLayers 地图实例。
|
|
13
|
+
|
|
14
|
+
## 接口定义
|
|
15
|
+
|
|
16
|
+
### VueTemplatePointOptions
|
|
17
|
+
|
|
18
|
+
配置 Vue 模版点位的选项接口。
|
|
19
|
+
|
|
20
|
+
| 属性 | 类型 | 必填 | 默认值 | 描述 |
|
|
21
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
22
|
+
| Template | `any` | 是 | - | Vue 组件模版对象。 |
|
|
23
|
+
| lgtd | `number` | 是 | - | 经度。 |
|
|
24
|
+
| lttd | `number` | 是 | - | 纬度。 |
|
|
25
|
+
| props | `Record<string, any>` | 否 | - | 传递给组件的 props。 |
|
|
26
|
+
| positioning | `string` | 否 | `'center-center'` | 覆盖物相对于位置的锚点。可选值见 OpenLayers Overlay positioning。 |
|
|
27
|
+
| stopEvent | `boolean` | 否 | `false` | 是否阻止地图事件冒泡。 |
|
|
28
|
+
| zIndex | `number` | 否 | - | DOM 元素的 z-index。 |
|
|
29
|
+
| className | `string` | 否 | - | DOM 元素的 CSS 类名。 |
|
|
30
|
+
| visible | `boolean` | 否 | `true` | 初始可见性。 |
|
|
4
31
|
|
|
5
32
|
## 方法
|
|
6
33
|
|
|
7
|
-
|
|
8
|
-
- `pointDataList`: 点位数据列表。
|
|
9
|
-
- `template`: Vue 组件对象。
|
|
10
|
-
- `options`:
|
|
11
|
-
- `positioning`: 覆盖物定位点(如 `'center-center'`)。
|
|
12
|
-
- `stopEvent`: 是否阻止事件冒泡。
|
|
34
|
+
### addVueTemplatePoint
|
|
13
35
|
|
|
14
|
-
|
|
36
|
+
添加一组 Vue 组件点位。
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
addVueTemplatePoint(
|
|
40
|
+
pointDataList: any[],
|
|
41
|
+
template: any,
|
|
42
|
+
options?: {
|
|
43
|
+
positioning?: string,
|
|
44
|
+
stopEvent?: boolean
|
|
45
|
+
}
|
|
46
|
+
): VueTemplatePointController
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **参数**:
|
|
50
|
+
- `pointDataList` (any[]): 点位数据列表。列表中的每个对象都必须包含 `lgtd` (经度) 和 `lttd` (纬度) 属性。
|
|
51
|
+
- `template` (any): Vue 组件对象。
|
|
52
|
+
- `options` (Object): 可选配置。
|
|
53
|
+
- `positioning`: 覆盖物定位点(如 `'center-center'`, `'bottom-center'` 等)。
|
|
54
|
+
- `stopEvent`: 是否阻止事件冒泡(默认 `false`)。
|
|
55
|
+
|
|
56
|
+
- **返回值**:
|
|
57
|
+
返回一个控制对象 `VueTemplatePointController`,用于批量管理这组点位。
|
|
58
|
+
|
|
59
|
+
### VueTemplatePointController 接口
|
|
60
|
+
|
|
61
|
+
`addVueTemplatePoint` 返回的对象包含以下方法:
|
|
62
|
+
|
|
63
|
+
| 方法 | 描述 |
|
|
64
|
+
| :--- | :--- |
|
|
65
|
+
| `setVisible(visible: boolean): void` | 设置该组所有点位的可见性。 |
|
|
66
|
+
| `setOneVisibleByProp(propName: string, propValue: any, visible: boolean): void` | 根据点位数据中的属性值控制特定点位的可见性。 |
|
|
67
|
+
| `remove(): void` | 移除该组所有点位并销毁组件实例。 |
|
|
68
|
+
| `getPoints(): VueTemplatePointInstance[]` | 获取该组创建的所有底层点位实例列表。 |
|
|
69
|
+
|
|
70
|
+
### getPointById
|
|
71
|
+
|
|
72
|
+
根据 ID 获取单个点位实例。
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
getPointById(id: string): VueTemplatePointInstance | undefined
|
|
76
|
+
```
|
|
15
77
|
|
|
16
|
-
|
|
78
|
+
### getAllPoints
|
|
17
79
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
80
|
+
获取所有管理的点位实例。
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
getAllPoints(): VueTemplatePointInstance[]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### removeAllPoints
|
|
87
|
+
|
|
88
|
+
移除并销毁所有点位。
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
removeAllPoints(): void
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### getPointCount
|
|
95
|
+
|
|
96
|
+
获取当前管理的点位数量。
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
getPointCount(): number
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## VueTemplatePointInstance 实例方法
|
|
103
|
+
|
|
104
|
+
单个点位实例 (`VueTemplatePointInstance`) 提供的操作方法:
|
|
105
|
+
|
|
106
|
+
| 方法 | 描述 |
|
|
107
|
+
| :--- | :--- |
|
|
108
|
+
| `setVisible(visible: boolean): void` | 设置当前点位可见性。 |
|
|
109
|
+
| `isVisible(): boolean` | 获取当前可见性状态。 |
|
|
110
|
+
| `updatePosition(lgtd: number, lttd: number): void` | 更新点位经纬度位置。 |
|
|
111
|
+
| `getPosition(): number[]` | 获取当前位置 `[lgtd, lttd]`。 |
|
|
112
|
+
| `updateProps(newProps: Record<string, any>): void` | 更新传递给组件的 props。 |
|
|
113
|
+
| `setStyle(styles: Partial<CSSStyleDeclaration>): void` | 设置 DOM 元素的 CSS 样式。 |
|
|
114
|
+
| `addClass(className: string): void` | 添加 CSS 类名。 |
|
|
115
|
+
| `removeClass(className: string): void` | 移除 CSS 类名。 |
|
|
116
|
+
| `remove(): void` | 移除并销毁当前点位。 |
|
|
117
|
+
| `getId(): string` | 获取点位唯一 ID。 |
|
|
118
|
+
| `getDomElement(): HTMLElement` | 获取点位对应的 DOM 元素。 |
|
|
22
119
|
|
|
23
120
|
## 使用示例
|
|
24
121
|
|
|
@@ -28,50 +125,77 @@
|
|
|
28
125
|
import { MyOl } from 'my-openlayer';
|
|
29
126
|
import MyPopup from './MyPopup.vue'; // 你的 Vue 组件
|
|
30
127
|
|
|
128
|
+
const map = new MyOl('map-container');
|
|
129
|
+
const vuePointManager = map.getPoint();
|
|
130
|
+
|
|
31
131
|
const pointData = [
|
|
32
132
|
{ lgtd: 120.1, lttd: 30.2, title: '位置1', status: 'normal' },
|
|
33
133
|
{ lgtd: 120.2, lttd: 30.3, title: '位置2', status: 'warning' }
|
|
34
134
|
];
|
|
35
135
|
|
|
36
|
-
// 添加组件点位
|
|
37
|
-
const
|
|
136
|
+
// 1. 添加组件点位
|
|
137
|
+
const pointsController = vuePointManager.addVueTemplatePoint(
|
|
38
138
|
pointData,
|
|
39
139
|
MyPopup,
|
|
40
140
|
{
|
|
41
141
|
positioning: 'bottom-center',
|
|
42
|
-
stopEvent: true //
|
|
142
|
+
stopEvent: true // 允许点击组件交互,阻止地图点击事件
|
|
43
143
|
}
|
|
44
144
|
);
|
|
45
145
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
|
|
146
|
+
// 2. 批量控制显示隐藏
|
|
147
|
+
pointsController.setVisible(false);
|
|
148
|
+
|
|
149
|
+
// 3. 根据属性控制特定点位
|
|
150
|
+
pointsController.setOneVisibleByProp('status', 'warning', true);
|
|
151
|
+
|
|
152
|
+
// 4. 获取单个实例进行精细控制
|
|
153
|
+
const instances = pointsController.getPoints();
|
|
154
|
+
if (instances.length > 0) {
|
|
155
|
+
const firstPoint = instances[0];
|
|
156
|
+
|
|
157
|
+
// 更新位置
|
|
158
|
+
firstPoint.updatePosition(120.15, 30.25);
|
|
159
|
+
|
|
160
|
+
// 更新 Props
|
|
161
|
+
firstPoint.updateProps({
|
|
162
|
+
pointData: { ...pointData[0], title: '更新后的标题' }
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// 添加样式类
|
|
166
|
+
firstPoint.addClass('highlight-point');
|
|
167
|
+
}
|
|
51
168
|
|
|
52
|
-
//
|
|
53
|
-
//
|
|
169
|
+
// 5. 移除这组点位
|
|
170
|
+
// pointsController.remove();
|
|
54
171
|
```
|
|
55
172
|
|
|
56
173
|
### Vue 组件编写规范 (MyPopup.vue)
|
|
57
174
|
|
|
58
|
-
组件会接收 `pointData` 作为 props
|
|
175
|
+
组件会接收 `pointData` 作为 props,内容为传入 `pointDataList` 中的对应数据项。
|
|
59
176
|
|
|
60
177
|
```vue
|
|
61
178
|
<template>
|
|
62
|
-
<div class="popup">
|
|
179
|
+
<div class="popup" :class="pointData.status">
|
|
63
180
|
<h3>{{ pointData.title }}</h3>
|
|
64
181
|
<p>状态: {{ pointData.status }}</p>
|
|
182
|
+
<button @click="handleClick">详情</button>
|
|
65
183
|
</div>
|
|
66
184
|
</template>
|
|
67
185
|
|
|
68
186
|
<script setup>
|
|
69
|
-
defineProps
|
|
187
|
+
import { defineProps } from 'vue';
|
|
188
|
+
|
|
189
|
+
const props = defineProps({
|
|
70
190
|
pointData: {
|
|
71
191
|
type: Object,
|
|
72
192
|
required: true
|
|
73
193
|
}
|
|
74
194
|
});
|
|
195
|
+
|
|
196
|
+
const handleClick = () => {
|
|
197
|
+
console.log('Clicked point:', props.pointData.title);
|
|
198
|
+
};
|
|
75
199
|
</script>
|
|
76
200
|
|
|
77
201
|
<style scoped>
|
|
@@ -80,6 +204,11 @@ defineProps({
|
|
|
80
204
|
padding: 10px;
|
|
81
205
|
border-radius: 4px;
|
|
82
206
|
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
|
|
207
|
+
min-width: 150px;
|
|
208
|
+
transform: translate(-50%, -100%); /* 配合 bottom-center 定位 */
|
|
209
|
+
}
|
|
210
|
+
.popup.warning {
|
|
211
|
+
border: 2px solid orange;
|
|
83
212
|
}
|
|
84
213
|
</style>
|
|
85
214
|
```
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# My OpenLayers
|
|
2
|
+
|
|
3
|
+
My OpenLayers 是一个基于 OpenLayers 的轻量级地图封装库,旨在简化地图开发流程,提供开箱即用的常用功能。它集成了点、线、面绘制,测量工具,选择交互,Vue 组件覆盖物等功能,特别优化了 Vue 项目的集成体验。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- **开箱即用**: 封装了常用的地图功能,减少样板代码。
|
|
8
|
+
- **Vue 集成**: 支持使用 Vue 组件作为地图覆盖物,轻松创建复杂的交互式标记。
|
|
9
|
+
- **TypeScript**: 完全使用 TypeScript 编写,提供完整的类型定义。
|
|
10
|
+
- **工具丰富**: 内置测量、选择、裁剪、遮罩等实用工具。
|
|
11
|
+
- **扩展性强**: 提供基础类和接口,方便二次封装和扩展。
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install my-openlayer
|
|
17
|
+
# 或者
|
|
18
|
+
yarn add my-openlayer
|
|
19
|
+
# 或者
|
|
20
|
+
pnpm add my-openlayer
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { MyOl } from 'my-openlayer';
|
|
27
|
+
import 'ol/ol.css'; // 引入 OpenLayers 样式
|
|
28
|
+
|
|
29
|
+
// 初始化地图
|
|
30
|
+
const map = new MyOl('map-container', {
|
|
31
|
+
center: [120.2, 30.3],
|
|
32
|
+
zoom: 12,
|
|
33
|
+
projection: 'EPSG:4326'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 获取原生 Map 实例
|
|
37
|
+
const olMap = map.map;
|
|
38
|
+
|
|
39
|
+
// 添加一个点
|
|
40
|
+
const point = map.getPoint();
|
|
41
|
+
point.addPoint([{
|
|
42
|
+
lgtd: 120.2,
|
|
43
|
+
lttd: 30.3,
|
|
44
|
+
style: {
|
|
45
|
+
icon: 'path/to/icon.png'
|
|
46
|
+
}
|
|
47
|
+
}]);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 核心模块
|
|
51
|
+
|
|
52
|
+
- **[MyOl](./MyOl.md)**: 核心入口类,负责地图初始化和模块管理。
|
|
53
|
+
- **[Point](./Point.md)**: 点位管理,支持图标、文本、聚合等。
|
|
54
|
+
- **[Line](./Line.md)**: 线条绘制,支持不同样式和动画。
|
|
55
|
+
- **[Polygon](./Polygon.md)**: 多边形绘制,支持遮罩、热力图等。
|
|
56
|
+
- **[VueTemplatePoint](./VueTemplatePoint.md)**: 使用 Vue 组件作为地图点位覆盖物。
|
|
57
|
+
|
|
58
|
+
## 工具模块
|
|
59
|
+
|
|
60
|
+
- **[MapTools](./MapTools.md)**: 通用地图工具,如裁剪、定位、导出图片等。
|
|
61
|
+
- **[MeasureHandler](./MeasureHandler.md)**: 距离和面积测量工具。
|
|
62
|
+
- **[SelectHandler](./SelectHandler.md)**: 要素选择交互工具。
|
|
63
|
+
- **[MapBaseLayers](./MapBaseLayers.md)**: 底图切换和管理。
|
|
64
|
+
|
|
65
|
+
## 基础设施
|
|
66
|
+
|
|
67
|
+
- **[ConfigManager](./ConfigManager.md)**: 全局配置管理。
|
|
68
|
+
- **[EventManager](./EventManager.md)**: 统一事件管理系统。
|
|
69
|
+
- **[ErrorHandler](./ErrorHandler.md)**: 错误处理和日志系统。
|
|
70
|
+
- **[ValidationUtils](./ValidationUtils.md)**: 参数验证工具。
|
|
71
|
+
|
|
72
|
+
## 贡献
|
|
73
|
+
|
|
74
|
+
欢迎提交 Issue 和 Pull Request!
|
|
75
|
+
|
|
76
|
+
## 许可证
|
|
77
|
+
|
|
78
|
+
MIT License
|