@angular-helpers/openlayers 0.1.1 → 0.3.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.
@@ -1,6 +1,12 @@
1
- import { Observable } from 'rxjs';
2
- import { Feature, OlFeature } from '@angular-helpers/openlayers/core';
1
+ import * as rxjs from 'rxjs';
2
+ import * as _angular_helpers_openlayers_interactions from '@angular-helpers/openlayers/interactions';
3
3
  import * as i0 from '@angular/core';
4
+ import { Provider } from '@angular/core';
5
+ import * as _angular_helpers_openlayers_core from '@angular-helpers/openlayers/core';
6
+ import { Feature, OlFeature } from '@angular-helpers/openlayers/core';
7
+ import Interaction from 'ol/interaction/Interaction';
8
+ import OLMap from 'ol/Map';
9
+ import { Feature as Feature$1 } from 'ol';
4
10
 
5
11
  type InteractionType = 'select' | 'draw' | 'modify' | 'dragAndDrop';
6
12
  interface InteractionConfig {
@@ -9,27 +15,330 @@ interface InteractionConfig {
9
15
  interface SelectConfig extends InteractionConfig {
10
16
  layers?: string[];
11
17
  multi?: boolean;
18
+ hitTolerance?: number;
12
19
  }
13
20
  interface DrawConfig extends InteractionConfig {
14
21
  type: 'Point' | 'LineString' | 'Polygon' | 'Circle';
15
22
  source?: string;
16
23
  freehand?: boolean;
24
+ snapTolerance?: number;
25
+ }
26
+ interface ModifyConfig extends InteractionConfig {
27
+ source?: string;
28
+ snapTolerance?: number;
29
+ }
30
+ interface DragAndDropConfig extends InteractionConfig {
31
+ format?: 'GeoJSON' | 'KML' | 'GPX';
32
+ projection?: string;
17
33
  }
18
34
  interface SelectEvent {
19
35
  feature: Feature;
20
36
  selected: boolean;
21
37
  }
38
+ interface DrawEndEvent {
39
+ feature: Feature;
40
+ type: string;
41
+ }
42
+ interface DrawStartEvent {
43
+ feature: Feature;
44
+ }
45
+ interface ModifyEvent {
46
+ features: Feature[];
47
+ type: 'modifystart' | 'modifyend';
48
+ }
49
+ interface InteractionState {
50
+ id: string;
51
+ type: InteractionType;
52
+ active: boolean;
53
+ }
22
54
 
55
+ /**
56
+ * Main service for managing OpenLayers map interactions.
57
+ * Orchestrates specialized interaction services and exposes unified API.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const interactionService = inject(OlInteractionService);
62
+ *
63
+ * // Enable select interaction
64
+ * interactionService.enableSelect('select-1', { layers: ['cities'], multi: true });
65
+ *
66
+ * // React to selection changes
67
+ * effect(() => {
68
+ * const selected = interactionService.selectedFeatures();
69
+ * console.log('Selected:', selected);
70
+ * });
71
+ * ```
72
+ */
23
73
  declare class OlInteractionService {
24
- enableInteraction(type: InteractionType, config: unknown): unknown;
74
+ private mapService;
75
+ private stateService;
76
+ private zoneHelper;
77
+ private selectService;
78
+ private drawService;
79
+ private modifyService;
80
+ readonly selectedFeatures: i0.Signal<_angular_helpers_openlayers_core.Feature[]>;
81
+ readonly selectionCount: i0.Signal<number>;
82
+ readonly hasSelection: i0.Signal<boolean>;
83
+ readonly activeInteractions: i0.Signal<_angular_helpers_openlayers_interactions.ManagedInteraction[]>;
84
+ readonly drawStart$: rxjs.Observable<_angular_helpers_openlayers_interactions.DrawStartEvent>;
85
+ readonly drawEnd$: rxjs.Observable<_angular_helpers_openlayers_interactions.DrawEndEvent>;
86
+ readonly modify$: rxjs.Observable<_angular_helpers_openlayers_interactions.ModifyEvent>;
87
+ /**
88
+ * Enable a select interaction on the map.
89
+ * @param id - Unique identifier for this interaction
90
+ * @param config - Selection configuration
91
+ * @returns Object with cleanup method
92
+ */
93
+ enableSelect(id: string, config?: SelectConfig): {
94
+ cleanup: () => void;
95
+ };
96
+ /**
97
+ * Enable a draw interaction on the map.
98
+ * @param id - Unique identifier for this interaction
99
+ * @param config - Draw configuration
100
+ * @returns Object with cleanup method and isActive signal
101
+ */
102
+ enableDraw(id: string, config: DrawConfig): {
103
+ cleanup: () => void;
104
+ isActive: () => boolean;
105
+ };
106
+ /**
107
+ * Enable a modify interaction on the map.
108
+ * @param id - Unique identifier for this interaction
109
+ * @param config - Modify configuration
110
+ * @returns Object with cleanup method
111
+ */
112
+ enableModify(id: string, config?: ModifyConfig): {
113
+ cleanup: () => void;
114
+ };
115
+ /**
116
+ * Disable and remove an interaction by id.
117
+ * @param id - The interaction identifier
118
+ */
25
119
  disableInteraction(id: string): void;
26
- startDrawing(type: string, options?: DrawConfig): Observable<Feature>;
120
+ /**
121
+ * Disable all active interactions.
122
+ */
123
+ disableAll(): void;
124
+ /**
125
+ * Clear the current selection.
126
+ * Also clears the OL Select interaction's internal feature collection so the
127
+ * visual selection is removed from the map.
128
+ */
129
+ clearSelection(): void;
130
+ /**
131
+ * Check if an interaction is currently active.
132
+ * @param id - The interaction identifier
133
+ * @returns True if active, false otherwise
134
+ */
135
+ isActive(id: string): boolean;
136
+ /**
137
+ * Get current interaction state.
138
+ * @returns Array of interaction state summaries
139
+ */
140
+ getInteractionState(): _angular_helpers_openlayers_interactions.InteractionState[];
27
141
  static ɵfac: i0.ɵɵFactoryDeclaration<OlInteractionService, never>;
28
142
  static ɵprov: i0.ɵɵInjectableDeclaration<OlInteractionService>;
29
143
  }
30
144
 
145
+ /**
146
+ * Internal representation of a managed OpenLayers interaction.
147
+ * Tracks the interaction instance, its configuration, and cleanup function.
148
+ */
149
+ interface ManagedInteraction {
150
+ /** Unique identifier for this interaction instance */
151
+ id: string;
152
+ /** Type of interaction (select, draw, modify, etc.) */
153
+ type: InteractionType;
154
+ /** The OpenLayers interaction instance */
155
+ olInteraction: Interaction;
156
+ /** Configuration used when creating the interaction */
157
+ config: InteractionConfig;
158
+ /** Function to clean up and remove the interaction from the map */
159
+ cleanup: () => void;
160
+ }
161
+
162
+ /**
163
+ * Service responsible for managing the reactive state of interactions.
164
+ * Provides signals for interaction state and observables for events.
165
+ */
166
+ declare class InteractionStateService {
167
+ private interactions;
168
+ private selectedFeaturesInternal;
169
+ private drawStartSubject;
170
+ private drawEndSubject;
171
+ private modifySubject;
172
+ readonly selectedFeatures: i0.Signal<Feature[]>;
173
+ readonly selectionCount: i0.Signal<number>;
174
+ readonly hasSelection: i0.Signal<boolean>;
175
+ readonly activeInteractions: i0.Signal<ManagedInteraction[]>;
176
+ readonly drawStart$: rxjs.Observable<DrawStartEvent>;
177
+ readonly drawEnd$: rxjs.Observable<DrawEndEvent>;
178
+ readonly modify$: rxjs.Observable<ModifyEvent>;
179
+ /**
180
+ * Adds a managed interaction to the state.
181
+ * @param interaction - The interaction to add
182
+ */
183
+ addInteraction(interaction: ManagedInteraction): void;
184
+ /**
185
+ * Removes an interaction by id.
186
+ * @param id - The interaction identifier to remove
187
+ */
188
+ removeInteraction(id: string): void;
189
+ /**
190
+ * Gets all managed interactions.
191
+ * @returns Array of managed interactions
192
+ */
193
+ getInteractions(): ManagedInteraction[];
194
+ /**
195
+ * Finds an interaction by id.
196
+ * @param id - The interaction identifier
197
+ * @returns The managed interaction or undefined
198
+ */
199
+ findInteraction(id: string): ManagedInteraction | undefined;
200
+ /**
201
+ * Sets the currently selected features.
202
+ * @param features - Array of selected features
203
+ */
204
+ setSelectedFeatures(features: Feature[]): void;
205
+ /**
206
+ * Clears the current selection.
207
+ */
208
+ clearSelection(): void;
209
+ /**
210
+ * Emits a draw start event.
211
+ * @param event - The draw start event data
212
+ */
213
+ emitDrawStart(event: DrawStartEvent): void;
214
+ /**
215
+ * Emits a draw end event.
216
+ * @param event - The draw end event data
217
+ */
218
+ emitDrawEnd(event: DrawEndEvent): void;
219
+ /**
220
+ * Emits a modify event.
221
+ * @param event - The modify event data
222
+ */
223
+ emitModify(event: ModifyEvent): void;
224
+ /**
225
+ * Gets the current interaction state summary.
226
+ * @returns Array of interaction state objects
227
+ */
228
+ getInteractionState(): InteractionState[];
229
+ /**
230
+ * Checks if an interaction is currently active.
231
+ * @param id - The interaction identifier
232
+ * @returns True if the interaction exists and is active
233
+ */
234
+ isActive(id: string): boolean;
235
+ /**
236
+ * Clears all interactions from state.
237
+ * Note: This only clears the state tracking, not the actual OL interactions.
238
+ */
239
+ clearAll(): void;
240
+ static ɵfac: i0.ɵɵFactoryDeclaration<InteractionStateService, never>;
241
+ static ɵprov: i0.ɵɵInjectableDeclaration<InteractionStateService>;
242
+ }
243
+
244
+ /**
245
+ * Service responsible for creating and managing Select interactions.
246
+ */
247
+ declare class SelectInteractionService {
248
+ private mapService;
249
+ private stateService;
250
+ private zoneHelper;
251
+ /**
252
+ * Creates and configures a Select interaction.
253
+ * @param id - Unique identifier for the interaction
254
+ * @param config - Select interaction configuration
255
+ * @param map - OpenLayers map instance
256
+ * @returns Promise that resolves when the interaction is created
257
+ */
258
+ createSelectInteraction(id: string, config: SelectConfig, map: OLMap): void;
259
+ static ɵfac: i0.ɵɵFactoryDeclaration<SelectInteractionService, never>;
260
+ static ɵprov: i0.ɵɵInjectableDeclaration<SelectInteractionService>;
261
+ }
262
+
263
+ /**
264
+ * Service responsible for creating and managing Draw interactions.
265
+ */
266
+ declare class DrawInteractionService {
267
+ private mapService;
268
+ private layerService;
269
+ private stateService;
270
+ private zoneHelper;
271
+ /**
272
+ * Creates and configures a Draw interaction.
273
+ * @param id - Unique identifier for the interaction
274
+ * @param config - Draw interaction configuration
275
+ * @param map - OpenLayers map instance
276
+ * @returns True if the interaction was created successfully
277
+ */
278
+ createDrawInteraction(id: string, config: DrawConfig, map: OLMap): boolean;
279
+ static ɵfac: i0.ɵɵFactoryDeclaration<DrawInteractionService, never>;
280
+ static ɵprov: i0.ɵɵInjectableDeclaration<DrawInteractionService>;
281
+ }
282
+
283
+ /**
284
+ * Service responsible for creating and managing Modify interactions.
285
+ */
286
+ declare class ModifyInteractionService {
287
+ private layerService;
288
+ private stateService;
289
+ private zoneHelper;
290
+ /**
291
+ * Creates and configures a Modify interaction.
292
+ * @param id - Unique identifier for the interaction
293
+ * @param config - Modify interaction configuration
294
+ * @param map - OpenLayers map instance
295
+ */
296
+ createModifyInteraction(id: string, config: ModifyConfig, map: OLMap): void;
297
+ static ɵfac: i0.ɵɵFactoryDeclaration<ModifyInteractionService, never>;
298
+ static ɵprov: i0.ɵɵInjectableDeclaration<ModifyInteractionService>;
299
+ }
300
+
301
+ /**
302
+ * Converts an OpenLayers feature to the internal Feature format.
303
+ * Handles coordinate extraction and geometry type mapping.
304
+ *
305
+ * @param olFeature - The OpenLayers feature to convert
306
+ * @returns The converted Feature with normalized structure
307
+ */
308
+ declare function olFeatureToFeature(olFeature: Feature$1): Feature;
309
+
310
+ /**
311
+ * Provide the interactions feature with OlInteractionService and all specialized services.
312
+ * Note: ZoneHelper is inherited from core's provideOpenLayers.
313
+ * @returns OlFeature configuration for interactions
314
+ */
31
315
  declare function withInteractions(): OlFeature<'interactions'>;
316
+ /**
317
+ * Alias for withInteractions().
318
+ * @returns OlFeature configuration for interactions
319
+ */
32
320
  declare function provideInteractions(): OlFeature<'interactions'>;
321
+ /**
322
+ * Enable select interaction when providing the interactions feature.
323
+ * @param id Unique identifier for this interaction
324
+ * @param config Select interaction configuration
325
+ * @returns Provider function that enables select interaction
326
+ */
327
+ declare function withSelectInteraction(id: string, config?: SelectConfig): Provider;
328
+ /**
329
+ * Enable draw interaction when providing the interactions feature.
330
+ * @param id Unique identifier for this interaction
331
+ * @param config Draw interaction configuration
332
+ * @returns Provider function that enables draw interaction
333
+ */
334
+ declare function withDrawInteraction(id: string, config: DrawConfig): Provider;
335
+ /**
336
+ * Enable modify interaction when providing the interactions feature.
337
+ * @param id Unique identifier for this interaction
338
+ * @param config Modify interaction configuration
339
+ * @returns Provider function that enables modify interaction
340
+ */
341
+ declare function withModifyInteraction(id: string, config?: ModifyConfig): Provider;
33
342
 
34
- export { OlInteractionService, provideInteractions, withInteractions };
35
- export type { DrawConfig, InteractionConfig, InteractionType, SelectConfig, SelectEvent };
343
+ export { DrawInteractionService, InteractionStateService, ModifyInteractionService, OlInteractionService, SelectInteractionService, olFeatureToFeature, provideInteractions, withDrawInteraction, withInteractions, withModifyInteraction, withSelectInteraction };
344
+ export type { DragAndDropConfig, DrawConfig, DrawEndEvent, DrawStartEvent, InteractionConfig, InteractionState, InteractionType, ManagedInteraction, ModifyConfig, ModifyEvent, SelectConfig, SelectEvent };
@@ -1,23 +1,24 @@
1
1
  import * as _angular_core from '@angular/core';
2
- import { OnInit, OnDestroy } from '@angular/core';
3
2
  import { Feature, Style, Layer, Extent, OlFeature } from '@angular-helpers/openlayers/core';
3
+ import BaseLayer from 'ol/layer/Base';
4
4
 
5
- declare class OlVectorLayerComponent implements OnInit, OnDestroy {
5
+ declare class OlVectorLayerComponent {
6
6
  private layerService;
7
+ private destroyRef;
7
8
  id: _angular_core.InputSignal<string>;
8
9
  features: _angular_core.InputSignal<Feature[]>;
9
10
  zIndex: _angular_core.InputSignal<number>;
10
11
  opacity: _angular_core.InputSignal<number>;
11
12
  visible: _angular_core.InputSignal<boolean>;
12
13
  style: _angular_core.InputSignal<Style | ((feature: Feature) => Style)>;
13
- ngOnInit(): void;
14
- ngOnDestroy(): void;
14
+ constructor();
15
15
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<OlVectorLayerComponent, never>;
16
16
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<OlVectorLayerComponent, "ol-vector-layer", never, { "id": { "alias": "id"; "required": true; "isSignal": true; }; "features": { "alias": "features"; "required": false; "isSignal": true; }; "zIndex": { "alias": "zIndex"; "required": false; "isSignal": true; }; "opacity": { "alias": "opacity"; "required": false; "isSignal": true; }; "visible": { "alias": "visible"; "required": false; "isSignal": true; }; "style": { "alias": "style"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
17
17
  }
18
18
 
19
- declare class OlTileLayerComponent implements OnInit, OnDestroy {
19
+ declare class OlTileLayerComponent {
20
20
  private layerService;
21
+ private destroyRef;
21
22
  id: _angular_core.InputSignal<string>;
22
23
  source: _angular_core.InputSignal<"osm" | "xyz" | "wms">;
23
24
  url: _angular_core.InputSignal<string>;
@@ -26,13 +27,27 @@ declare class OlTileLayerComponent implements OnInit, OnDestroy {
26
27
  zIndex: _angular_core.InputSignal<number>;
27
28
  opacity: _angular_core.InputSignal<number>;
28
29
  visible: _angular_core.InputSignal<boolean>;
29
- ngOnInit(): void;
30
- private tryAddLayer;
31
- ngOnDestroy(): void;
30
+ constructor();
32
31
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<OlTileLayerComponent, never>;
33
32
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<OlTileLayerComponent, "ol-tile-layer", never, { "id": { "alias": "id"; "required": true; "isSignal": true; }; "source": { "alias": "source"; "required": true; "isSignal": true; }; "url": { "alias": "url"; "required": false; "isSignal": true; }; "attributions": { "alias": "attributions"; "required": false; "isSignal": true; }; "params": { "alias": "params"; "required": false; "isSignal": true; }; "zIndex": { "alias": "zIndex"; "required": false; "isSignal": true; }; "opacity": { "alias": "opacity"; "required": false; "isSignal": true; }; "visible": { "alias": "visible"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
34
33
  }
35
34
 
35
+ declare class OlImageLayerComponent {
36
+ private layerService;
37
+ private destroyRef;
38
+ id: _angular_core.InputSignal<string>;
39
+ sourceType: _angular_core.InputSignal<"wms" | "static">;
40
+ url: _angular_core.InputSignal<string>;
41
+ params: _angular_core.InputSignal<Record<string, unknown>>;
42
+ imageExtent: _angular_core.InputSignal<[number, number, number, number]>;
43
+ zIndex: _angular_core.InputSignal<number>;
44
+ opacity: _angular_core.InputSignal<number>;
45
+ visible: _angular_core.InputSignal<boolean>;
46
+ constructor();
47
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<OlImageLayerComponent, never>;
48
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<OlImageLayerComponent, "ol-image-layer", never, { "id": { "alias": "id"; "required": true; "isSignal": true; }; "sourceType": { "alias": "sourceType"; "required": true; "isSignal": true; }; "url": { "alias": "url"; "required": true; "isSignal": true; }; "params": { "alias": "params"; "required": false; "isSignal": true; }; "imageExtent": { "alias": "imageExtent"; "required": false; "isSignal": true; }; "zIndex": { "alias": "zIndex"; "required": false; "isSignal": true; }; "opacity": { "alias": "opacity"; "required": false; "isSignal": true; }; "visible": { "alias": "visible"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
49
+ }
50
+
36
51
  interface LayerConfig extends Layer {
37
52
  type: 'vector' | 'tile' | 'image';
38
53
  extent?: Extent;
@@ -65,15 +80,51 @@ interface ImageSourceConfig {
65
80
  imageExtent?: Extent;
66
81
  }
67
82
 
83
+ interface LayerInfo {
84
+ id: string;
85
+ type: 'vector' | 'tile' | 'image';
86
+ visible: boolean;
87
+ opacity: number;
88
+ zIndex: number;
89
+ }
68
90
  declare class OlLayerService {
69
91
  private mapService;
70
92
  private layerCache;
93
+ private pendingConfigs;
94
+ private layerState;
95
+ readonly layers: _angular_core.Signal<LayerInfo[]>;
96
+ readonly visibleLayers: _angular_core.Signal<LayerInfo[]>;
97
+ readonly tileLayers: _angular_core.Signal<LayerInfo[]>;
98
+ readonly vectorLayers: _angular_core.Signal<LayerInfo[]>;
71
99
  addLayer(config: LayerConfig): {
72
100
  id: string;
73
101
  };
102
+ private flushPending;
103
+ private createLayer;
104
+ getLayer(id: string): BaseLayer | undefined;
105
+ hasLayer(id: string): boolean;
74
106
  removeLayer(id: string): void;
75
107
  setVisibility(id: string, visible: boolean): void;
108
+ toggleVisibility(id: string): boolean;
76
109
  setOpacity(id: string, opacity: number): void;
110
+ setZIndex(id: string, zIndex: number): void;
111
+ isVisible(id: string): boolean;
112
+ getOpacity(id: string): number;
113
+ getZIndex(id: string): number;
114
+ /**
115
+ * Clears all features from a vector layer's source.
116
+ * Does not remove the layer itself.
117
+ * @param id - Layer identifier
118
+ */
119
+ clearFeatures(id: string): void;
120
+ /**
121
+ * Updates the features of a vector layer.
122
+ * Syncs new features without clearing existing ones (preserves OL modifications).
123
+ * @param id - Layer identifier
124
+ * @param features - New features to sync
125
+ */
126
+ updateFeatures(id: string, features: VectorLayerConfig['features']): void;
127
+ private updateLayerState;
77
128
  private createVectorLayer;
78
129
  private createTileLayer;
79
130
  private createImageLayer;
@@ -84,5 +135,5 @@ declare class OlLayerService {
84
135
  declare function withLayers(): OlFeature<'layers'>;
85
136
  declare function provideLayers(): OlFeature<'layers'>;
86
137
 
87
- export { OlLayerService, OlTileLayerComponent, OlVectorLayerComponent, provideLayers, withLayers };
88
- export type { ImageLayerConfig, ImageSourceConfig, LayerConfig, SourceConfig, TileLayerConfig, VectorLayerConfig };
138
+ export { OlImageLayerComponent, OlLayerService, OlTileLayerComponent, OlVectorLayerComponent, provideLayers, withLayers };
139
+ export type { ImageLayerConfig, ImageSourceConfig, LayerConfig, LayerInfo, SourceConfig, TileLayerConfig, VectorLayerConfig };