my-openlayer 2.0.0 → 2.1.0
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/MyOl.d.ts +135 -128
- package/MyOl.js +401 -381
- package/README.md +0 -21
- package/core/ConfigManager.d.ts +88 -88
- package/core/ConfigManager.js +112 -112
- package/core/EventManager.d.ts +141 -141
- package/core/EventManager.js +316 -316
- package/core/Line.d.ts +130 -109
- package/core/Line.js +512 -288
- package/core/MapBaseLayers.d.ts +234 -234
- package/core/MapBaseLayers.js +573 -573
- package/core/MapTools.d.ts +68 -68
- package/core/MapTools.js +202 -201
- package/core/MeasureHandler.d.ts +65 -65
- package/core/MeasureHandler.js +312 -312
- package/core/Point.d.ts +94 -94
- package/core/Point.js +348 -348
- package/core/Polygon.d.ts +157 -139
- package/core/Polygon.js +605 -529
- package/core/SelectHandler.d.ts +138 -0
- package/core/SelectHandler.js +395 -0
- package/core/VueTemplatePoint.d.ts +51 -51
- package/core/VueTemplatePoint.js +529 -529
- package/index.d.ts +19 -18
- package/index.js +18 -17
- package/package.json +1 -1
- package/types.d.ts +340 -302
- package/types.js +11 -11
- package/utils/ErrorHandler.d.ts +102 -102
- package/utils/ErrorHandler.js +191 -191
- package/utils/ValidationUtils.d.ts +163 -163
- package/utils/ValidationUtils.js +312 -312
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import Map from "ol/Map";
|
|
2
|
+
import { FeatureLike } from "ol/Feature";
|
|
3
|
+
import { SelectOptions, SelectMode } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* 要素选择处理器类
|
|
6
|
+
* 用于在地图上选择和高亮显示要素,支持单选、多选等多种选择模式
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const selectHandler = new SelectHandler(map);
|
|
11
|
+
*
|
|
12
|
+
* // 启用点击选择
|
|
13
|
+
* selectHandler.enableSelect('click', {
|
|
14
|
+
* layerFilter: ['pointLayer', 'polygonLayer'],
|
|
15
|
+
* multi: false,
|
|
16
|
+
* onSelect: (event) => {
|
|
17
|
+
* console.log('选中要素:', event.selected);
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // 获取当前选中的要素
|
|
22
|
+
* const selected = selectHandler.getSelectedFeatures();
|
|
23
|
+
*
|
|
24
|
+
* // 清除选择
|
|
25
|
+
* selectHandler.clearSelection();
|
|
26
|
+
*
|
|
27
|
+
* // 禁用选择
|
|
28
|
+
* selectHandler.disableSelect();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export default class SelectHandler {
|
|
32
|
+
/** OpenLayers 地图实例 */
|
|
33
|
+
private readonly map;
|
|
34
|
+
/** 事件管理器实例 */
|
|
35
|
+
private readonly eventManager;
|
|
36
|
+
/** 错误处理器实例 */
|
|
37
|
+
private readonly errorHandler;
|
|
38
|
+
/** Select 交互实例 */
|
|
39
|
+
private selectInteraction?;
|
|
40
|
+
/** 当前选择模式 */
|
|
41
|
+
private currentMode?;
|
|
42
|
+
/** 当前配置选项 */
|
|
43
|
+
private currentOptions?;
|
|
44
|
+
/** 是否已启用选择 */
|
|
45
|
+
private isEnabled;
|
|
46
|
+
/** 默认选中样式 - 点要素 */
|
|
47
|
+
private readonly defaultPointStyle;
|
|
48
|
+
/** 默认选中样式 - 线要素 */
|
|
49
|
+
private readonly defaultLineStyle;
|
|
50
|
+
/** 默认选中样式 - 面要素 */
|
|
51
|
+
private readonly defaultPolygonStyle;
|
|
52
|
+
/**
|
|
53
|
+
* 构造函数
|
|
54
|
+
* @param map OpenLayers地图实例
|
|
55
|
+
*/
|
|
56
|
+
constructor(map: Map);
|
|
57
|
+
/**
|
|
58
|
+
* 启用要素选择
|
|
59
|
+
* @param mode 选择模式:'click'(点击)、'hover'(悬停)、'box'(框选)、'ctrl'(Ctrl+点击)
|
|
60
|
+
* @param options 选择配置选项
|
|
61
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
62
|
+
*/
|
|
63
|
+
enableSelect(mode?: SelectMode, options?: SelectOptions): this;
|
|
64
|
+
/**
|
|
65
|
+
* 禁用要素选择
|
|
66
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
67
|
+
*/
|
|
68
|
+
disableSelect(): this;
|
|
69
|
+
/**
|
|
70
|
+
* 获取当前选中的要素
|
|
71
|
+
* @returns 选中的要素数组
|
|
72
|
+
*/
|
|
73
|
+
getSelectedFeatures(): FeatureLike[];
|
|
74
|
+
/**
|
|
75
|
+
* 清除所有选择
|
|
76
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
77
|
+
*/
|
|
78
|
+
clearSelection(): this;
|
|
79
|
+
/**
|
|
80
|
+
* 通过要素ID选择要素
|
|
81
|
+
* @param featureIds 要素ID数组
|
|
82
|
+
* @param layerName 图层名称(可选)
|
|
83
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
84
|
+
*/
|
|
85
|
+
selectByIds(featureIds: string[], layerName?: string): this;
|
|
86
|
+
/**
|
|
87
|
+
* 通过属性选择要素
|
|
88
|
+
* @param propertyName 属性名称
|
|
89
|
+
* @param propertyValue 属性值
|
|
90
|
+
* @param layerName 图层名称(可选)
|
|
91
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
92
|
+
*/
|
|
93
|
+
selectByProperty(propertyName: string, propertyValue: any, layerName?: string): this;
|
|
94
|
+
/**
|
|
95
|
+
* 判断选择是否已启用
|
|
96
|
+
* @returns 是否已启用
|
|
97
|
+
*/
|
|
98
|
+
isSelectEnabled(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* 获取当前选择模式
|
|
101
|
+
* @returns 当前选择模式
|
|
102
|
+
*/
|
|
103
|
+
getCurrentMode(): SelectMode | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* 销毁选择处理器,清理所有资源
|
|
106
|
+
*/
|
|
107
|
+
destroy(): void;
|
|
108
|
+
/**
|
|
109
|
+
* 合并选项配置
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
private mergeOptions;
|
|
113
|
+
/**
|
|
114
|
+
* 创建 Select 交互
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
private createSelectInteraction;
|
|
118
|
+
/**
|
|
119
|
+
* 获取选择条件
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
private getSelectCondition;
|
|
123
|
+
/**
|
|
124
|
+
* 创建图层过滤器
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
private createLayerFilter;
|
|
128
|
+
/**
|
|
129
|
+
* 创建选择样式
|
|
130
|
+
* @private
|
|
131
|
+
*/
|
|
132
|
+
private createSelectStyle;
|
|
133
|
+
/**
|
|
134
|
+
* 附加事件监听器
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
private attachEventListeners;
|
|
138
|
+
}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { Select } from "ol/interaction";
|
|
2
|
+
import { click, pointerMove, platformModifierKeyOnly } from "ol/events/condition";
|
|
3
|
+
import VectorLayer from "ol/layer/Vector";
|
|
4
|
+
import { Style, Fill, Stroke, Circle as CircleStyle } from "ol/style";
|
|
5
|
+
import { EventManager } from "./EventManager";
|
|
6
|
+
import { ValidationUtils } from "../utils/ValidationUtils";
|
|
7
|
+
import { ErrorHandler, MyOpenLayersError, ErrorType } from "../utils/ErrorHandler";
|
|
8
|
+
/**
|
|
9
|
+
* 要素选择处理器类
|
|
10
|
+
* 用于在地图上选择和高亮显示要素,支持单选、多选等多种选择模式
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const selectHandler = new SelectHandler(map);
|
|
15
|
+
*
|
|
16
|
+
* // 启用点击选择
|
|
17
|
+
* selectHandler.enableSelect('click', {
|
|
18
|
+
* layerFilter: ['pointLayer', 'polygonLayer'],
|
|
19
|
+
* multi: false,
|
|
20
|
+
* onSelect: (event) => {
|
|
21
|
+
* console.log('选中要素:', event.selected);
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // 获取当前选中的要素
|
|
26
|
+
* const selected = selectHandler.getSelectedFeatures();
|
|
27
|
+
*
|
|
28
|
+
* // 清除选择
|
|
29
|
+
* selectHandler.clearSelection();
|
|
30
|
+
*
|
|
31
|
+
* // 禁用选择
|
|
32
|
+
* selectHandler.disableSelect();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export default class SelectHandler {
|
|
36
|
+
/**
|
|
37
|
+
* 构造函数
|
|
38
|
+
* @param map OpenLayers地图实例
|
|
39
|
+
*/
|
|
40
|
+
constructor(map) {
|
|
41
|
+
/** 是否已启用选择 */
|
|
42
|
+
this.isEnabled = false;
|
|
43
|
+
/** 默认选中样式 - 点要素 */
|
|
44
|
+
this.defaultPointStyle = new Style({
|
|
45
|
+
image: new CircleStyle({
|
|
46
|
+
radius: 7,
|
|
47
|
+
fill: new Fill({ color: 'rgba(255, 0, 0, 0.6)' }),
|
|
48
|
+
stroke: new Stroke({ color: '#ff0000', width: 2 })
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
/** 默认选中样式 - 线要素 */
|
|
52
|
+
this.defaultLineStyle = new Style({
|
|
53
|
+
stroke: new Stroke({
|
|
54
|
+
color: '#ff0000',
|
|
55
|
+
width: 3
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
/** 默认选中样式 - 面要素 */
|
|
59
|
+
this.defaultPolygonStyle = new Style({
|
|
60
|
+
stroke: new Stroke({
|
|
61
|
+
color: '#ff0000',
|
|
62
|
+
width: 2
|
|
63
|
+
}),
|
|
64
|
+
fill: new Fill({
|
|
65
|
+
color: 'rgba(255, 0, 0, 0.2)'
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
ValidationUtils.validateMapInstance(map);
|
|
69
|
+
this.map = map;
|
|
70
|
+
this.eventManager = new EventManager(map);
|
|
71
|
+
this.errorHandler = ErrorHandler.getInstance();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 启用要素选择
|
|
75
|
+
* @param mode 选择模式:'click'(点击)、'hover'(悬停)、'box'(框选)、'ctrl'(Ctrl+点击)
|
|
76
|
+
* @param options 选择配置选项
|
|
77
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
78
|
+
*/
|
|
79
|
+
enableSelect(mode = 'click', options) {
|
|
80
|
+
try {
|
|
81
|
+
// 如果已启用,先禁用
|
|
82
|
+
if (this.isEnabled) {
|
|
83
|
+
this.disableSelect();
|
|
84
|
+
}
|
|
85
|
+
const mergedOptions = this.mergeOptions(options);
|
|
86
|
+
this.currentMode = mode;
|
|
87
|
+
this.currentOptions = mergedOptions;
|
|
88
|
+
// 创建 Select 交互
|
|
89
|
+
this.selectInteraction = this.createSelectInteraction(mode, mergedOptions);
|
|
90
|
+
// 添加事件监听器
|
|
91
|
+
this.attachEventListeners(mergedOptions);
|
|
92
|
+
// 添加到地图
|
|
93
|
+
this.map.addInteraction(this.selectInteraction);
|
|
94
|
+
this.isEnabled = true;
|
|
95
|
+
console.debug('要素选择已启用', { mode, options: mergedOptions });
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
this.errorHandler.handleError(new MyOpenLayersError(`启用要素选择失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.COMPONENT_ERROR, { mode, options }));
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 禁用要素选择
|
|
105
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
106
|
+
*/
|
|
107
|
+
disableSelect() {
|
|
108
|
+
try {
|
|
109
|
+
if (this.selectInteraction) {
|
|
110
|
+
this.map.removeInteraction(this.selectInteraction);
|
|
111
|
+
this.selectInteraction = undefined;
|
|
112
|
+
}
|
|
113
|
+
this.isEnabled = false;
|
|
114
|
+
this.currentMode = undefined;
|
|
115
|
+
console.debug('要素选择已禁用');
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
this.errorHandler.handleError(new MyOpenLayersError(`禁用要素选择失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.COMPONENT_ERROR));
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 获取当前选中的要素
|
|
125
|
+
* @returns 选中的要素数组
|
|
126
|
+
*/
|
|
127
|
+
getSelectedFeatures() {
|
|
128
|
+
if (!this.selectInteraction) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const features = this.selectInteraction.getFeatures();
|
|
132
|
+
return features.getArray();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 清除所有选择
|
|
136
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
137
|
+
*/
|
|
138
|
+
clearSelection() {
|
|
139
|
+
if (this.selectInteraction) {
|
|
140
|
+
this.selectInteraction.getFeatures().clear();
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 通过要素ID选择要素
|
|
146
|
+
* @param featureIds 要素ID数组
|
|
147
|
+
* @param layerName 图层名称(可选)
|
|
148
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
149
|
+
*/
|
|
150
|
+
selectByIds(featureIds, layerName) {
|
|
151
|
+
try {
|
|
152
|
+
if (!this.selectInteraction) {
|
|
153
|
+
console.warn('选择交互未启用,无法选择要素');
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
if (!featureIds || featureIds.length === 0) {
|
|
157
|
+
console.warn('要素ID列表为空');
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
// 清除当前选择
|
|
161
|
+
this.clearSelection();
|
|
162
|
+
// 获取所有图层
|
|
163
|
+
const layers = this.map.getLayers().getArray();
|
|
164
|
+
for (const layer of layers) {
|
|
165
|
+
// 过滤图层
|
|
166
|
+
if (layerName && layer.get('layerName') !== layerName) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (layer instanceof VectorLayer) {
|
|
170
|
+
const source = layer.getSource();
|
|
171
|
+
if (!source)
|
|
172
|
+
continue;
|
|
173
|
+
// 查找并选择要素
|
|
174
|
+
for (const featureId of featureIds) {
|
|
175
|
+
const feature = source.getFeatureById(featureId);
|
|
176
|
+
if (feature) {
|
|
177
|
+
this.selectInteraction.getFeatures().push(feature);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
this.errorHandler.handleError(new MyOpenLayersError(`通过ID选择要素失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.COMPONENT_ERROR, { featureIds, layerName }));
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 通过属性选择要素
|
|
191
|
+
* @param propertyName 属性名称
|
|
192
|
+
* @param propertyValue 属性值
|
|
193
|
+
* @param layerName 图层名称(可选)
|
|
194
|
+
* @returns SelectHandler 实例(支持链式调用)
|
|
195
|
+
*/
|
|
196
|
+
selectByProperty(propertyName, propertyValue, layerName) {
|
|
197
|
+
try {
|
|
198
|
+
if (!this.selectInteraction) {
|
|
199
|
+
console.warn('选择交互未启用,无法选择要素');
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
if (!propertyName) {
|
|
203
|
+
throw new Error('属性名称不能为空');
|
|
204
|
+
}
|
|
205
|
+
// 清除当前选择
|
|
206
|
+
this.clearSelection();
|
|
207
|
+
// 获取所有图层
|
|
208
|
+
const layers = this.map.getLayers().getArray();
|
|
209
|
+
for (const layer of layers) {
|
|
210
|
+
// 过滤图层
|
|
211
|
+
if (layerName && layer.get('layerName') !== layerName) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (layer instanceof VectorLayer) {
|
|
215
|
+
const source = layer.getSource();
|
|
216
|
+
if (!source)
|
|
217
|
+
continue;
|
|
218
|
+
// 查找并选择要素
|
|
219
|
+
const features = source.getFeatures();
|
|
220
|
+
for (const feature of features) {
|
|
221
|
+
if (feature.get(propertyName) === propertyValue) {
|
|
222
|
+
this.selectInteraction.getFeatures().push(feature);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
this.errorHandler.handleError(new MyOpenLayersError(`通过属性选择要素失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.COMPONENT_ERROR, { propertyName, propertyValue, layerName }));
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 判断选择是否已启用
|
|
236
|
+
* @returns 是否已启用
|
|
237
|
+
*/
|
|
238
|
+
isSelectEnabled() {
|
|
239
|
+
return this.isEnabled;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 获取当前选择模式
|
|
243
|
+
* @returns 当前选择模式
|
|
244
|
+
*/
|
|
245
|
+
getCurrentMode() {
|
|
246
|
+
return this.currentMode;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 销毁选择处理器,清理所有资源
|
|
250
|
+
*/
|
|
251
|
+
destroy() {
|
|
252
|
+
try {
|
|
253
|
+
this.disableSelect();
|
|
254
|
+
console.debug('选择处理器已销毁');
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
this.errorHandler.handleError(new MyOpenLayersError(`销毁选择处理器失败: ${error instanceof Error ? error.message : '未知错误'}`, ErrorType.COMPONENT_ERROR));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 合并选项配置
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
mergeOptions(options) {
|
|
265
|
+
return {
|
|
266
|
+
multi: false,
|
|
267
|
+
layerFilter: undefined,
|
|
268
|
+
featureFilter: undefined,
|
|
269
|
+
hitTolerance: 0,
|
|
270
|
+
selectStyle: undefined,
|
|
271
|
+
onSelect: undefined,
|
|
272
|
+
onDeselect: undefined,
|
|
273
|
+
...options
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* 创建 Select 交互
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
280
|
+
createSelectInteraction(mode, options) {
|
|
281
|
+
// 确定选择条件
|
|
282
|
+
const condition = this.getSelectCondition(mode);
|
|
283
|
+
// 创建图层过滤器
|
|
284
|
+
const layerFilter = this.createLayerFilter(options.layerFilter);
|
|
285
|
+
// 创建要素过滤器
|
|
286
|
+
const filter = options.featureFilter;
|
|
287
|
+
// 创建选择样式
|
|
288
|
+
const style = this.createSelectStyle(options.selectStyle);
|
|
289
|
+
return new Select({
|
|
290
|
+
condition,
|
|
291
|
+
layers: layerFilter,
|
|
292
|
+
filter,
|
|
293
|
+
style,
|
|
294
|
+
multi: options.multi,
|
|
295
|
+
hitTolerance: options.hitTolerance
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* 获取选择条件
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
302
|
+
getSelectCondition(mode) {
|
|
303
|
+
switch (mode) {
|
|
304
|
+
case 'click':
|
|
305
|
+
return click;
|
|
306
|
+
case 'hover':
|
|
307
|
+
return pointerMove;
|
|
308
|
+
case 'ctrl':
|
|
309
|
+
return platformModifierKeyOnly;
|
|
310
|
+
case 'box':
|
|
311
|
+
// 框选需要额外的 DragBox 交互,这里暂不实现
|
|
312
|
+
return click;
|
|
313
|
+
default:
|
|
314
|
+
return click;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* 创建图层过滤器
|
|
319
|
+
* @private
|
|
320
|
+
*/
|
|
321
|
+
createLayerFilter(layerNames) {
|
|
322
|
+
if (!layerNames || layerNames.length === 0) {
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
return (layer) => {
|
|
326
|
+
const layerName = layer.get('layerName') || layer.get('name');
|
|
327
|
+
return layerNames.includes(layerName);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* 创建选择样式
|
|
332
|
+
* @private
|
|
333
|
+
*/
|
|
334
|
+
createSelectStyle(customStyle) {
|
|
335
|
+
if (customStyle) {
|
|
336
|
+
return customStyle;
|
|
337
|
+
}
|
|
338
|
+
// 返回根据几何类型的默认样式
|
|
339
|
+
return (feature) => {
|
|
340
|
+
const geometry = feature.getGeometry();
|
|
341
|
+
if (!geometry) {
|
|
342
|
+
return this.defaultPointStyle;
|
|
343
|
+
}
|
|
344
|
+
const geometryType = geometry.getType();
|
|
345
|
+
switch (geometryType) {
|
|
346
|
+
case 'Point':
|
|
347
|
+
case 'MultiPoint':
|
|
348
|
+
return this.defaultPointStyle;
|
|
349
|
+
case 'LineString':
|
|
350
|
+
case 'MultiLineString':
|
|
351
|
+
return this.defaultLineStyle;
|
|
352
|
+
case 'Polygon':
|
|
353
|
+
case 'MultiPolygon':
|
|
354
|
+
return this.defaultPolygonStyle;
|
|
355
|
+
default:
|
|
356
|
+
return this.defaultPointStyle;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* 附加事件监听器
|
|
362
|
+
* @private
|
|
363
|
+
*/
|
|
364
|
+
attachEventListeners(options) {
|
|
365
|
+
if (!this.selectInteraction) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
// 监听选择事件
|
|
369
|
+
this.selectInteraction.on('select', (event) => {
|
|
370
|
+
const callbackEvent = {
|
|
371
|
+
selected: event.selected,
|
|
372
|
+
deselected: event.deselected,
|
|
373
|
+
mapBrowserEvent: event.mapBrowserEvent
|
|
374
|
+
};
|
|
375
|
+
// 触发选择回调
|
|
376
|
+
if (options.onSelect && event.selected.length > 0) {
|
|
377
|
+
try {
|
|
378
|
+
options.onSelect(callbackEvent);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
console.error('选择回调执行失败:', error);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
// 触发取消选择回调
|
|
385
|
+
if (options.onDeselect && event.deselected.length > 0) {
|
|
386
|
+
try {
|
|
387
|
+
options.onDeselect(callbackEvent);
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
console.error('取消选择回调执行失败:', error);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { Map as OLMap } from 'ol';
|
|
2
|
-
import { VueTemplatePointInstance } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Vue模板点位管理类
|
|
5
|
-
* 用于在地图上添加和管理Vue组件覆盖物
|
|
6
|
-
*/
|
|
7
|
-
export default class VueTemplatePoint {
|
|
8
|
-
private readonly map;
|
|
9
|
-
private readonly errorHandler;
|
|
10
|
-
private vuePoints;
|
|
11
|
-
/**
|
|
12
|
-
* 构造函数
|
|
13
|
-
* @param map OpenLayers地图实例
|
|
14
|
-
*/
|
|
15
|
-
constructor(map: OLMap);
|
|
16
|
-
/**
|
|
17
|
-
* 添加Vue模板点位
|
|
18
|
-
* @param pointDataList 点位数据列表
|
|
19
|
-
* @param template Vue模板
|
|
20
|
-
* @param options 可选配置项
|
|
21
|
-
* @returns 点位控制器
|
|
22
|
-
*/
|
|
23
|
-
addVueTemplatePoint(pointDataList: any[], template: any, options?: {
|
|
24
|
-
positioning?: 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-center' | 'center-right' | 'top-left' | 'top-center' | 'top-right';
|
|
25
|
-
stopEvent?: boolean;
|
|
26
|
-
}): {
|
|
27
|
-
setVisible: (visible: boolean) => void;
|
|
28
|
-
remove: () => void;
|
|
29
|
-
getPoints: () => VueTemplatePointInstance[];
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* 根据ID获取点位实例
|
|
33
|
-
* @param id 点位ID
|
|
34
|
-
* @returns 点位实例或undefined
|
|
35
|
-
*/
|
|
36
|
-
getPointById(id: string): VueTemplatePointInstance | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* 获取所有点位实例
|
|
39
|
-
* @returns 所有点位实例数组
|
|
40
|
-
*/
|
|
41
|
-
getAllPoints(): VueTemplatePointInstance[];
|
|
42
|
-
/**
|
|
43
|
-
* 移除所有点位
|
|
44
|
-
*/
|
|
45
|
-
removeAllPoints(): void;
|
|
46
|
-
/**
|
|
47
|
-
* 获取点位数量
|
|
48
|
-
* @returns 点位数量
|
|
49
|
-
*/
|
|
50
|
-
getPointCount(): number;
|
|
51
|
-
}
|
|
1
|
+
import { Map as OLMap } from 'ol';
|
|
2
|
+
import { VueTemplatePointInstance } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Vue模板点位管理类
|
|
5
|
+
* 用于在地图上添加和管理Vue组件覆盖物
|
|
6
|
+
*/
|
|
7
|
+
export default class VueTemplatePoint {
|
|
8
|
+
private readonly map;
|
|
9
|
+
private readonly errorHandler;
|
|
10
|
+
private vuePoints;
|
|
11
|
+
/**
|
|
12
|
+
* 构造函数
|
|
13
|
+
* @param map OpenLayers地图实例
|
|
14
|
+
*/
|
|
15
|
+
constructor(map: OLMap);
|
|
16
|
+
/**
|
|
17
|
+
* 添加Vue模板点位
|
|
18
|
+
* @param pointDataList 点位数据列表
|
|
19
|
+
* @param template Vue模板
|
|
20
|
+
* @param options 可选配置项
|
|
21
|
+
* @returns 点位控制器
|
|
22
|
+
*/
|
|
23
|
+
addVueTemplatePoint(pointDataList: any[], template: any, options?: {
|
|
24
|
+
positioning?: 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-center' | 'center-right' | 'top-left' | 'top-center' | 'top-right';
|
|
25
|
+
stopEvent?: boolean;
|
|
26
|
+
}): {
|
|
27
|
+
setVisible: (visible: boolean) => void;
|
|
28
|
+
remove: () => void;
|
|
29
|
+
getPoints: () => VueTemplatePointInstance[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 根据ID获取点位实例
|
|
33
|
+
* @param id 点位ID
|
|
34
|
+
* @returns 点位实例或undefined
|
|
35
|
+
*/
|
|
36
|
+
getPointById(id: string): VueTemplatePointInstance | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* 获取所有点位实例
|
|
39
|
+
* @returns 所有点位实例数组
|
|
40
|
+
*/
|
|
41
|
+
getAllPoints(): VueTemplatePointInstance[];
|
|
42
|
+
/**
|
|
43
|
+
* 移除所有点位
|
|
44
|
+
*/
|
|
45
|
+
removeAllPoints(): void;
|
|
46
|
+
/**
|
|
47
|
+
* 获取点位数量
|
|
48
|
+
* @returns 点位数量
|
|
49
|
+
*/
|
|
50
|
+
getPointCount(): number;
|
|
51
|
+
}
|