@smartnet360/svelte-components 0.0.78 → 0.0.80
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/dist/map-v2/shared/controls/FeatureSelectionControl.svelte +31 -1
- package/dist/map-v2/shared/controls/FeatureSelectionControl.svelte.d.ts +4 -0
- package/dist/map-v2/shared/controls/featureSelectionStore.svelte.d.ts +9 -2
- package/dist/map-v2/shared/controls/featureSelectionStore.svelte.js +19 -8
- package/package.json +1 -1
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
actionButtonLabel?: string;
|
|
34
34
|
/** Feature icon (default: geo-alt-fill) */
|
|
35
35
|
featureIcon?: string;
|
|
36
|
+
/** Available property names to use as ID (default: ['id', 'siteId', 'cellName']) */
|
|
37
|
+
idPropertyOptions?: string[];
|
|
38
|
+
/** Default property to use as ID (default: 'id') */
|
|
39
|
+
defaultIdProperty?: string;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
let {
|
|
@@ -42,7 +46,9 @@
|
|
|
42
46
|
iconOnlyWhenCollapsed = true,
|
|
43
47
|
onAction,
|
|
44
48
|
actionButtonLabel = 'Process',
|
|
45
|
-
featureIcon = 'geo-alt-fill'
|
|
49
|
+
featureIcon = 'geo-alt-fill',
|
|
50
|
+
idPropertyOptions = ['siteId', 'cellName','id'],
|
|
51
|
+
defaultIdProperty = 'siteId'
|
|
46
52
|
}: Props = $props();
|
|
47
53
|
|
|
48
54
|
// Get map from context
|
|
@@ -53,6 +59,9 @@
|
|
|
53
59
|
const store = createFeatureSelectionStore();
|
|
54
60
|
console.log('[FeatureSelectionControl] Store created:', store);
|
|
55
61
|
|
|
62
|
+
// Set the ID property to use
|
|
63
|
+
store.setIdProperty(defaultIdProperty);
|
|
64
|
+
|
|
56
65
|
let selectedFeatures = $derived(store.getSelectedFeatures());
|
|
57
66
|
let selectionCount = $derived(store.count);
|
|
58
67
|
let hasSelection = $derived(selectionCount > 0);
|
|
@@ -86,6 +95,12 @@
|
|
|
86
95
|
store.toggleSelectionMode();
|
|
87
96
|
}
|
|
88
97
|
|
|
98
|
+
function handleIdPropertyChange(event: Event) {
|
|
99
|
+
const target = event.target as HTMLSelectElement;
|
|
100
|
+
store.setIdProperty(target.value);
|
|
101
|
+
console.log('[FeatureSelectionControl] ID property changed to:', target.value);
|
|
102
|
+
}
|
|
103
|
+
|
|
89
104
|
function handleRemoveFeature(featureId: string) {
|
|
90
105
|
store.removeFeatureSelection(featureId);
|
|
91
106
|
}
|
|
@@ -138,6 +153,21 @@
|
|
|
138
153
|
{/if}
|
|
139
154
|
</div>
|
|
140
155
|
|
|
156
|
+
<!-- ID Property Selector -->
|
|
157
|
+
<div class="mb-3">
|
|
158
|
+
<label for="id-property-select" class="form-label small">Select By</label>
|
|
159
|
+
<select
|
|
160
|
+
id="id-property-select"
|
|
161
|
+
class="form-select form-select-sm"
|
|
162
|
+
value={store.idProperty}
|
|
163
|
+
onchange={handleIdPropertyChange}
|
|
164
|
+
>
|
|
165
|
+
{#each idPropertyOptions as option}
|
|
166
|
+
<option value={option}>{option}</option>
|
|
167
|
+
{/each}
|
|
168
|
+
</select>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
141
171
|
<!-- Selection Stats -->
|
|
142
172
|
<div class="selection-stats mb-2">
|
|
143
173
|
<strong>{selectionCount}</strong>
|
|
@@ -13,6 +13,10 @@ interface Props {
|
|
|
13
13
|
actionButtonLabel?: string;
|
|
14
14
|
/** Feature icon (default: geo-alt-fill) */
|
|
15
15
|
featureIcon?: string;
|
|
16
|
+
/** Available property names to use as ID (default: ['id', 'siteId', 'cellName']) */
|
|
17
|
+
idPropertyOptions?: string[];
|
|
18
|
+
/** Default property to use as ID (default: 'id') */
|
|
19
|
+
defaultIdProperty?: string;
|
|
16
20
|
}
|
|
17
21
|
declare const FeatureSelectionControl: import("svelte").Component<Props, {}, "">;
|
|
18
22
|
type FeatureSelectionControl = ReturnType<typeof FeatureSelectionControl>;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import type { Map as MapboxMap } from 'mapbox-gl';
|
|
8
8
|
export interface SelectedFeature {
|
|
9
9
|
id: string;
|
|
10
|
+
siteId?: string;
|
|
11
|
+
cellName?: string;
|
|
10
12
|
layerId?: string;
|
|
11
13
|
properties?: Record<string, any>;
|
|
12
14
|
}
|
|
@@ -14,12 +16,17 @@ export declare class FeatureSelectionStore {
|
|
|
14
16
|
private selectedFeatures;
|
|
15
17
|
private map;
|
|
16
18
|
selectionMode: boolean;
|
|
19
|
+
idProperty: string;
|
|
17
20
|
private clickHandler;
|
|
18
21
|
constructor();
|
|
19
22
|
/**
|
|
20
23
|
* Initialize the store with a map instance
|
|
21
24
|
*/
|
|
22
25
|
setMap(mapInstance: MapboxMap): void;
|
|
26
|
+
/**
|
|
27
|
+
* Set which property to use as the ID
|
|
28
|
+
*/
|
|
29
|
+
setIdProperty(property: string): void;
|
|
23
30
|
/**
|
|
24
31
|
* Setup global click handler for any feature
|
|
25
32
|
*/
|
|
@@ -39,11 +46,11 @@ export declare class FeatureSelectionStore {
|
|
|
39
46
|
/**
|
|
40
47
|
* Toggle a feature in the selection
|
|
41
48
|
*/
|
|
42
|
-
toggleFeatureSelection(id: string, layerId?: string, properties?: Record<string, any
|
|
49
|
+
toggleFeatureSelection(id: string, layerId?: string, properties?: Record<string, any>, siteId?: string, cellName?: string): void;
|
|
43
50
|
/**
|
|
44
51
|
* Add a feature to the selection
|
|
45
52
|
*/
|
|
46
|
-
addFeatureSelection(id: string, layerId?: string, properties?: Record<string, any
|
|
53
|
+
addFeatureSelection(id: string, layerId?: string, properties?: Record<string, any>, siteId?: string, cellName?: string): void;
|
|
47
54
|
/**
|
|
48
55
|
* Remove a feature from the selection
|
|
49
56
|
*/
|
|
@@ -8,6 +8,7 @@ export class FeatureSelectionStore {
|
|
|
8
8
|
selectedFeatures = $state([]);
|
|
9
9
|
map = $state(null);
|
|
10
10
|
selectionMode = $state(false);
|
|
11
|
+
idProperty = $state('siteId'); // Default property to use as ID
|
|
11
12
|
clickHandler = null;
|
|
12
13
|
constructor() { }
|
|
13
14
|
/**
|
|
@@ -18,6 +19,13 @@ export class FeatureSelectionStore {
|
|
|
18
19
|
this.map = mapInstance;
|
|
19
20
|
this.setupClickHandler();
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Set which property to use as the ID
|
|
24
|
+
*/
|
|
25
|
+
setIdProperty(property) {
|
|
26
|
+
this.idProperty = property;
|
|
27
|
+
console.log('[FeatureSelection] ID property set to:', property);
|
|
28
|
+
}
|
|
21
29
|
/**
|
|
22
30
|
* Setup global click handler for any feature
|
|
23
31
|
*/
|
|
@@ -39,14 +47,17 @@ export class FeatureSelectionStore {
|
|
|
39
47
|
properties: feature.properties,
|
|
40
48
|
id: feature.id
|
|
41
49
|
});
|
|
42
|
-
|
|
50
|
+
// Use the configured property as the ID
|
|
51
|
+
const featureId = feature.properties?.[this.idProperty] || feature.id;
|
|
52
|
+
const siteId = feature.properties?.siteId;
|
|
53
|
+
const cellName = feature.properties?.cellName;
|
|
43
54
|
if (featureId) {
|
|
44
|
-
console.log('[FeatureSelection] Found feature with ID:', featureId);
|
|
45
|
-
this.toggleFeatureSelection(String(featureId), feature.layer?.id, feature.properties || undefined);
|
|
55
|
+
console.log('[FeatureSelection] Found feature with ID (using', this.idProperty + '):', featureId, 'siteId:', siteId, 'cellName:', cellName);
|
|
56
|
+
this.toggleFeatureSelection(String(featureId), feature.layer?.id, feature.properties || undefined, siteId, cellName);
|
|
46
57
|
break; // Only select the topmost feature
|
|
47
58
|
}
|
|
48
59
|
else {
|
|
49
|
-
console.log('[FeatureSelection] Feature has no
|
|
60
|
+
console.log('[FeatureSelection] Feature has no', this.idProperty, 'property');
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
}
|
|
@@ -76,7 +87,7 @@ export class FeatureSelectionStore {
|
|
|
76
87
|
/**
|
|
77
88
|
* Toggle a feature in the selection
|
|
78
89
|
*/
|
|
79
|
-
toggleFeatureSelection(id, layerId, properties) {
|
|
90
|
+
toggleFeatureSelection(id, layerId, properties, siteId, cellName) {
|
|
80
91
|
const index = this.selectedFeatures.findIndex(f => f.id === id);
|
|
81
92
|
if (index >= 0) {
|
|
82
93
|
// Remove if already selected
|
|
@@ -84,16 +95,16 @@ export class FeatureSelectionStore {
|
|
|
84
95
|
}
|
|
85
96
|
else {
|
|
86
97
|
// Add if not selected
|
|
87
|
-
this.selectedFeatures.push({ id, layerId, properties });
|
|
98
|
+
this.selectedFeatures.push({ id, layerId, properties, siteId, cellName });
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
/**
|
|
91
102
|
* Add a feature to the selection
|
|
92
103
|
*/
|
|
93
|
-
addFeatureSelection(id, layerId, properties) {
|
|
104
|
+
addFeatureSelection(id, layerId, properties, siteId, cellName) {
|
|
94
105
|
const exists = this.selectedFeatures.some(f => f.id === id);
|
|
95
106
|
if (!exists) {
|
|
96
|
-
this.selectedFeatures.push({ id, layerId, properties });
|
|
107
|
+
this.selectedFeatures.push({ id, layerId, properties, siteId, cellName });
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
/**
|