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/CHANGELOG.md +207 -151
- package/README.md +156 -156
- package/core/Point.js +21 -3
- 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 +187 -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 +165 -165
- 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 +78 -78
- package/package.json +1 -2
- package/types.d.ts +2 -0
- package/AI_CONTEXT.md +0 -147
package/docs/ValidationUtils.md
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
# ValidationUtils 验证工具
|
|
2
|
-
|
|
3
|
-
`ValidationUtils` 提供了一系列静态方法,用于验证地图操作中的各种参数和数据,确保数据的完整性和类型正确性。
|
|
4
|
-
|
|
5
|
-
## 导入
|
|
6
|
-
|
|
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` | 验证值类型,否则抛出带消息的异常 |
|
|
42
|
-
|
|
43
|
-
## 使用示例
|
|
44
|
-
|
|
45
|
-
### 验证坐标
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { ValidationUtils } from 'my-openlayer';
|
|
49
|
-
|
|
50
|
-
const lng = 120.5;
|
|
51
|
-
const lat = 30.5;
|
|
52
|
-
|
|
53
|
-
if (ValidationUtils.isValidCoordinate(lng, lat)) {
|
|
54
|
-
// 坐标有效,执行操作
|
|
55
|
-
map.getView().setCenter([lng, lat]);
|
|
56
|
-
} else {
|
|
57
|
-
console.error('Invalid coordinates');
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### 验证必填参数
|
|
62
|
-
|
|
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
|
-
}
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### 验证 Vue 组件参数
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
if (ValidationUtils.validateVueParams(points, MyComponent, Vue)) {
|
|
80
|
-
// 创建 Vue 覆盖物
|
|
81
|
-
new VueTemplatePoint(map).addVueTemplatePoint(points, MyComponent);
|
|
82
|
-
}
|
|
83
|
-
```
|
|
1
|
+
# ValidationUtils 验证工具
|
|
2
|
+
|
|
3
|
+
`ValidationUtils` 提供了一系列静态方法,用于验证地图操作中的各种参数和数据,确保数据的完整性和类型正确性。
|
|
4
|
+
|
|
5
|
+
## 导入
|
|
6
|
+
|
|
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` | 验证值类型,否则抛出带消息的异常 |
|
|
42
|
+
|
|
43
|
+
## 使用示例
|
|
44
|
+
|
|
45
|
+
### 验证坐标
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { ValidationUtils } from 'my-openlayer';
|
|
49
|
+
|
|
50
|
+
const lng = 120.5;
|
|
51
|
+
const lat = 30.5;
|
|
52
|
+
|
|
53
|
+
if (ValidationUtils.isValidCoordinate(lng, lat)) {
|
|
54
|
+
// 坐标有效,执行操作
|
|
55
|
+
map.getView().setCenter([lng, lat]);
|
|
56
|
+
} else {
|
|
57
|
+
console.error('Invalid coordinates');
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 验证必填参数
|
|
62
|
+
|
|
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
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 验证 Vue 组件参数
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
if (ValidationUtils.validateVueParams(points, MyComponent, Vue)) {
|
|
80
|
+
// 创建 Vue 覆盖物
|
|
81
|
+
new VueTemplatePoint(map).addVueTemplatePoint(points, MyComponent);
|
|
82
|
+
}
|
|
83
|
+
```
|
package/docs/VueTemplatePoint.md
CHANGED
|
@@ -1,214 +1,214 @@
|
|
|
1
|
-
# VueTemplatePoint Vue 组件点位类
|
|
2
|
-
|
|
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` | 初始可见性。 |
|
|
31
|
-
|
|
32
|
-
## 方法
|
|
33
|
-
|
|
34
|
-
### addVueTemplatePoint
|
|
35
|
-
|
|
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
|
-
```
|
|
77
|
-
|
|
78
|
-
### getAllPoints
|
|
79
|
-
|
|
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 元素。 |
|
|
119
|
-
|
|
120
|
-
## 使用示例
|
|
121
|
-
|
|
122
|
-
### Vue 3 示例
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
import { MyOl } from 'my-openlayer';
|
|
126
|
-
import MyPopup from './MyPopup.vue'; // 你的 Vue 组件
|
|
127
|
-
|
|
128
|
-
const map = new MyOl('map-container');
|
|
129
|
-
const vuePointManager = map.getPoint();
|
|
130
|
-
|
|
131
|
-
const pointData = [
|
|
132
|
-
{ lgtd: 120.1, lttd: 30.2, title: '位置1', status: 'normal' },
|
|
133
|
-
{ lgtd: 120.2, lttd: 30.3, title: '位置2', status: 'warning' }
|
|
134
|
-
];
|
|
135
|
-
|
|
136
|
-
// 1. 添加组件点位
|
|
137
|
-
const pointsController = vuePointManager.addVueTemplatePoint(
|
|
138
|
-
pointData,
|
|
139
|
-
MyPopup,
|
|
140
|
-
{
|
|
141
|
-
positioning: 'bottom-center',
|
|
142
|
-
stopEvent: true // 允许点击组件交互,阻止地图点击事件
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
|
|
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
|
-
}
|
|
168
|
-
|
|
169
|
-
// 5. 移除这组点位
|
|
170
|
-
// pointsController.remove();
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Vue 组件编写规范 (MyPopup.vue)
|
|
174
|
-
|
|
175
|
-
组件会接收 `pointData` 作为 props,内容为传入 `pointDataList` 中的对应数据项。
|
|
176
|
-
|
|
177
|
-
```vue
|
|
178
|
-
<template>
|
|
179
|
-
<div class="popup" :class="pointData.status">
|
|
180
|
-
<h3>{{ pointData.title }}</h3>
|
|
181
|
-
<p>状态: {{ pointData.status }}</p>
|
|
182
|
-
<button @click="handleClick">详情</button>
|
|
183
|
-
</div>
|
|
184
|
-
</template>
|
|
185
|
-
|
|
186
|
-
<script setup>
|
|
187
|
-
import { defineProps } from 'vue';
|
|
188
|
-
|
|
189
|
-
const props = defineProps({
|
|
190
|
-
pointData: {
|
|
191
|
-
type: Object,
|
|
192
|
-
required: true
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const handleClick = () => {
|
|
197
|
-
console.log('Clicked point:', props.pointData.title);
|
|
198
|
-
};
|
|
199
|
-
</script>
|
|
200
|
-
|
|
201
|
-
<style scoped>
|
|
202
|
-
.popup {
|
|
203
|
-
background: white;
|
|
204
|
-
padding: 10px;
|
|
205
|
-
border-radius: 4px;
|
|
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;
|
|
212
|
-
}
|
|
213
|
-
</style>
|
|
214
|
-
```
|
|
1
|
+
# VueTemplatePoint Vue 组件点位类
|
|
2
|
+
|
|
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` | 初始可见性。 |
|
|
31
|
+
|
|
32
|
+
## 方法
|
|
33
|
+
|
|
34
|
+
### addVueTemplatePoint
|
|
35
|
+
|
|
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
|
+
```
|
|
77
|
+
|
|
78
|
+
### getAllPoints
|
|
79
|
+
|
|
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 元素。 |
|
|
119
|
+
|
|
120
|
+
## 使用示例
|
|
121
|
+
|
|
122
|
+
### Vue 3 示例
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { MyOl } from 'my-openlayer';
|
|
126
|
+
import MyPopup from './MyPopup.vue'; // 你的 Vue 组件
|
|
127
|
+
|
|
128
|
+
const map = new MyOl('map-container');
|
|
129
|
+
const vuePointManager = map.getPoint();
|
|
130
|
+
|
|
131
|
+
const pointData = [
|
|
132
|
+
{ lgtd: 120.1, lttd: 30.2, title: '位置1', status: 'normal' },
|
|
133
|
+
{ lgtd: 120.2, lttd: 30.3, title: '位置2', status: 'warning' }
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
// 1. 添加组件点位
|
|
137
|
+
const pointsController = vuePointManager.addVueTemplatePoint(
|
|
138
|
+
pointData,
|
|
139
|
+
MyPopup,
|
|
140
|
+
{
|
|
141
|
+
positioning: 'bottom-center',
|
|
142
|
+
stopEvent: true // 允许点击组件交互,阻止地图点击事件
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
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
|
+
}
|
|
168
|
+
|
|
169
|
+
// 5. 移除这组点位
|
|
170
|
+
// pointsController.remove();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Vue 组件编写规范 (MyPopup.vue)
|
|
174
|
+
|
|
175
|
+
组件会接收 `pointData` 作为 props,内容为传入 `pointDataList` 中的对应数据项。
|
|
176
|
+
|
|
177
|
+
```vue
|
|
178
|
+
<template>
|
|
179
|
+
<div class="popup" :class="pointData.status">
|
|
180
|
+
<h3>{{ pointData.title }}</h3>
|
|
181
|
+
<p>状态: {{ pointData.status }}</p>
|
|
182
|
+
<button @click="handleClick">详情</button>
|
|
183
|
+
</div>
|
|
184
|
+
</template>
|
|
185
|
+
|
|
186
|
+
<script setup>
|
|
187
|
+
import { defineProps } from 'vue';
|
|
188
|
+
|
|
189
|
+
const props = defineProps({
|
|
190
|
+
pointData: {
|
|
191
|
+
type: Object,
|
|
192
|
+
required: true
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const handleClick = () => {
|
|
197
|
+
console.log('Clicked point:', props.pointData.title);
|
|
198
|
+
};
|
|
199
|
+
</script>
|
|
200
|
+
|
|
201
|
+
<style scoped>
|
|
202
|
+
.popup {
|
|
203
|
+
background: white;
|
|
204
|
+
padding: 10px;
|
|
205
|
+
border-radius: 4px;
|
|
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;
|
|
212
|
+
}
|
|
213
|
+
</style>
|
|
214
|
+
```
|