my-openlayer 2.4.2 → 2.4.4

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.
@@ -1,33 +1,10 @@
1
- import Map from "ol/Map";
1
+ import OlMap from "ol/Map";
2
2
  import { FeatureLike } from "ol/Feature";
3
3
  import { Style } from "ol/style";
4
4
  import { SelectOptions, SelectMode, ProgrammaticSelectOptions } from "../types";
5
5
  /**
6
6
  * 要素选择处理器类
7
7
  * 用于在地图上选择和高亮显示要素,支持单选、多选等多种选择模式
8
- *
9
- * @example
10
- * ```typescript
11
- * const selectHandler = new SelectHandler(map);
12
- *
13
- * // 启用点击选择
14
- * selectHandler.enableSelect('click', {
15
- * layerFilter: ['pointLayer', 'polygonLayer'],
16
- * multi: false,
17
- * onSelect: (event) => {
18
- * console.log('选中要素:', event.selected);
19
- * }
20
- * });
21
- *
22
- * // 获取当前选中的要素
23
- * const selected = selectHandler.getSelectedFeatures();
24
- *
25
- * // 清除选择
26
- * selectHandler.clearSelection();
27
- *
28
- * // 禁用选择
29
- * selectHandler.disableSelect();
30
- * ```
31
8
  */
32
9
  export default class SelectHandler {
33
10
  /** OpenLayers 地图实例 */
@@ -36,14 +13,18 @@ export default class SelectHandler {
36
13
  private readonly eventManager;
37
14
  /** 错误处理器实例 */
38
15
  private readonly errorHandler;
39
- /** Select 交互实例 */
40
- private selectInteraction?;
16
+ /** Select 交互实例(只负责交互,不负责渲染) */
17
+ private mainSelectInteraction?;
18
+ /** 额外的 Select 交互实例列表(用于编程式选择) */
19
+ private extraSelectInteractions;
20
+ /** 渲染用 Select 交互实例映射(用于交互式选择的高亮渲染) featureUID -> Select */
21
+ private renderInteractions;
41
22
  /** 当前选择模式 */
42
23
  private currentMode?;
43
- /** 当前配置选项 */
44
- private currentOptions?;
45
24
  /** 是否已启用选择 */
46
25
  private isEnabled;
26
+ /** 当前自定义样式函数(用于交互式选择) */
27
+ private currentSelectStyle?;
47
28
  /** 默认选中样式 - 点要素 */
48
29
  private readonly defaultPointStyle;
49
30
  /** 默认选中样式 - 线要素 */
@@ -54,7 +35,7 @@ export default class SelectHandler {
54
35
  * 构造函数
55
36
  * @param map OpenLayers地图实例
56
37
  */
57
- constructor(map: Map);
38
+ constructor(map: OlMap);
58
39
  /**
59
40
  * 启用要素选择
60
41
  * @param mode 选择模式:'click'(点击)、'hover'(悬停)、'ctrl'(Ctrl+点击)
@@ -68,7 +49,7 @@ export default class SelectHandler {
68
49
  */
69
50
  disableSelect(): this;
70
51
  /**
71
- * 获取当前选中的要素
52
+ * 获取当前选中的要素(仅返回主交互中的要素)
72
53
  * @returns 选中的要素数组
73
54
  */
74
55
  getSelectedFeatures(): FeatureLike[];
@@ -79,75 +60,45 @@ export default class SelectHandler {
79
60
  clearSelection(): this;
80
61
  /**
81
62
  * 通过要素ID选择要素
82
- * @param featureIds 要素ID数组
83
- * @param options 编程式选择配置选项
84
- * @returns SelectHandler 实例(支持链式调用)
85
63
  */
86
64
  selectByIds(featureIds: string[], options?: ProgrammaticSelectOptions): this;
87
65
  /**
88
66
  * 通过属性选择要素
89
- * @param propertyName 属性名称
90
- * @param propertyValue 属性值
91
- * @param options 编程式选择配置选项
92
- * @returns SelectHandler 实例(支持链式调用)
93
67
  */
94
68
  selectByProperty(propertyName: string, propertyValue: any, options?: ProgrammaticSelectOptions): this;
95
69
  /**
96
- * 判断选择是否已启用
97
- * @returns 是否已启用
70
+ * 应用选择(编程式)
98
71
  */
99
- isSelectEnabled(): boolean;
72
+ private applySelection;
100
73
  /**
101
- * 获取当前选择模式
102
- * @returns 当前选择模式
74
+ * 添加额外的交互实例(用于函数式样式结果)
103
75
  */
76
+ private addExtraInteraction;
77
+ private findFeaturesByIds;
78
+ private findFeaturesByProperty;
79
+ private ensureMainInteraction;
80
+ isSelectEnabled(): boolean;
104
81
  getCurrentMode(): SelectMode | undefined;
105
- /**
106
- * 定位至要素
107
- * @private
108
- * @param features 要素数组
109
- * @param duration 动画持续时间(毫秒),默认500
110
- * @param padding 边距(像素),默认100
111
- */
82
+ updateSelectStyle(selectStyle: Style | Style[] | ((feature: FeatureLike, resolution: number) => Style | Style[])): this;
112
83
  private fitToFeatures;
113
- /**
114
- * 销毁选择处理器,清理所有资源
115
- */
116
84
  destroy(): void;
117
- /**
118
- * 合并选项配置
119
- * @private
120
- */
121
- private mergeOptions;
122
- /**
123
- * 创建 Select 交互
124
- * @private
125
- */
126
- private createSelectInteraction;
127
- /**
128
- * 获取选择条件
129
- * @private
130
- */
131
85
  private getSelectCondition;
86
+ private createLayerFilter;
132
87
  /**
133
- * 创建图层过滤器
134
- * @private
88
+ * 计算样式(解析函数或返回默认)
135
89
  */
136
- private createLayerFilter;
90
+ private calculateStyle;
137
91
  /**
138
- * 创建选择样式
139
- * @private
92
+ * 为单个要素创建并添加渲染交互
140
93
  */
141
- private createSelectStyle;
94
+ private createRenderInteraction;
142
95
  /**
143
- * 更新选择样式
144
- * @param selectStyle 新的选择样式
145
- * @returns SelectHandler 实例(支持链式调用)
96
+ * 移除单个要素的渲染交互
146
97
  */
147
- updateSelectStyle(selectStyle: Style | Style[] | ((feature: FeatureLike) => Style | Style[])): this;
98
+ private removeRenderInteraction;
148
99
  /**
149
- * 附加事件监听器
150
- * @private
100
+ * 清理所有交互式渲染交互
151
101
  */
102
+ private clearRenderInteractions;
152
103
  private attachEventListeners;
153
104
  }