Skip to content

Commit da18bf8

Browse files
committed
Show the selected copy layer in different style, deactivate copy layer when clicking selected copy layer again
1 parent 541757a commit da18bf8

File tree

5 files changed

+59
-33
lines changed

5 files changed

+59
-33
lines changed

projects/core/src/lib/components/edit/edit/edit.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
padding-top: 6px;
3838
}
3939

40+
.mat-mdc-menu-item.selected {
41+
color: var(--primary-color);
42+
}
43+
4044
@media screen and (max-width: 730px) {
4145
.edit-container--is-active {
4246
padding: 0;

projects/core/src/lib/components/edit/edit/edit.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@
7575
<mat-icon svgIcon="split"></mat-icon>
7676
</button>
7777
<mat-menu #layerToCreateNewFeaturesFromMenu="matMenu" xPosition="after" yPosition="below">
78+
@let selectedCopyLayerId = selectedCopyLayer$ | async;
7879
@for (layer of layersToCreateNewFeaturesFrom(); track layer) {
79-
<button mat-menu-item (click)="createFeatureFromLayer(layer.id)">{{layer.title || layer.layerName}}</button>
80+
@let selected = layer.id === selectedCopyLayerId;
81+
<button mat-menu-item [class.selected]="selected" (click)="createFeatureFromLayer(layer.id)">
82+
<mat-icon [svgIcon]="selected ? 'check' : ''" color="primary"/>
83+
<span>{{layer.title || layer.layerName}}</span>
84+
</button>
8085
}
8186
</mat-menu>
8287
}

projects/core/src/lib/components/edit/edit/edit.component.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
22
import {
33
selectCopiedFeatures,
4-
selectEditActive, selectEditCopyOtherLayerFeaturesActive, selectEditCreateNewFeatureActive,
4+
selectEditActive, selectEditCopyOtherLayerFeaturesActive, selectEditCreateNewFeatureActive, selectSelectedCopyLayer,
55
selectSelectedEditLayer,
66
} from '../state/edit.selectors';
77
import { Store } from '@ngrx/store';
88
import { combineLatest, map, of, take } from 'rxjs';
99
import {
10-
setEditActive, setEditCopyOtherLayerFeaturesActive, setEditCreateNewFeatureActive, setSelectedEditLayer,
10+
setEditActive, setEditCopyOtherLayerFeaturesActive, setEditCopyOtherLayerFeaturesDisabled, setEditCreateNewFeatureActive,
11+
setSelectedEditLayer,
1112
} from '../state/edit.actions';
1213
import { FormControl } from '@angular/forms';
1314
import { selectEditableLayers, selectOrderedVisibleLayersWithServices } from '../../../map/state/map.selectors';
@@ -38,6 +39,7 @@ export class EditComponent implements OnInit {
3839
public createNewFeatureActive$ = this.store$.select(selectEditCreateNewFeatureActive);
3940
public copyActive$ = this.store$.select(selectEditCopyOtherLayerFeaturesActive);
4041
public copiedFeaturesCount$ = this.store$.select(selectCopiedFeatures).pipe(map(features => features.length));
42+
public selectedCopyLayer$ = this.store$.select(selectSelectedCopyLayer);
4143
public editableLayers$ = this.store$.select(selectEditableLayers);
4244
public layer = new FormControl();
4345
public editGeometryType: GeometryType | null = null;
@@ -144,25 +146,22 @@ export class EditComponent implements OnInit {
144146
if (!this.layer.value) {
145147
return;
146148
}
147-
// get layer attribute details for edit form
148-
this.applicationLayerService.getLayerDetails$(this.layer.value)
149-
.pipe(take(1))
150-
.subscribe(layerDetails => {
151-
// show edit dialog
152-
this.store$.dispatch(setEditCreateNewFeatureActive({
153-
active: true,
154-
geometryType,
155-
columnMetadata: layerDetails.details.attributes.map(attribute => {
156-
return {
157-
layerId: layerDetails.details.id,
158-
name: attribute.name,
159-
type: attribute.type as unknown as AttributeType,
160-
alias: attribute.editAlias,
161-
};
162-
},
163-
),
164-
}));
165-
});
149+
150+
this.applicationLayerService.getLayerDetails$(this.layer.value).pipe(take(1)).subscribe(layerDetails => {
151+
this.store$.dispatch(setEditCreateNewFeatureActive({
152+
active: true,
153+
geometryType,
154+
columnMetadata: layerDetails.details.attributes.map(attribute => {
155+
return {
156+
layerId: layerDetails.details.id,
157+
name: attribute.name,
158+
type: attribute.type as unknown as AttributeType,
159+
alias: attribute.editAlias,
160+
};
161+
},
162+
),
163+
}));
164+
});
166165
}
167166

168167
public createFeatureIfSingleGeometryType() {
@@ -175,13 +174,15 @@ export class EditComponent implements OnInit {
175174
}
176175

177176
public createFeatureFromLayer(id: string) {
178-
// get layer attribute details for edit form
179-
this.applicationLayerService.getLayerDetails$(this.layer.value)
180-
.pipe(take(1))
181-
.subscribe(layerDetails => {
182-
// show edit dialog
177+
178+
this.selectedCopyLayer$.pipe(take(1)).subscribe(selectedCopyLayer => {
179+
if (id == selectedCopyLayer) {
180+
this.store$.dispatch(setEditCopyOtherLayerFeaturesDisabled());
181+
return;
182+
}
183+
184+
this.applicationLayerService.getLayerDetails$(this.layer.value).pipe(take(1)).subscribe(layerDetails => {
183185
this.store$.dispatch(setEditCopyOtherLayerFeaturesActive({
184-
active: true,
185186
layerId: id,
186187
columnMetadata: layerDetails.details.attributes.map(attribute => {
187188
return {
@@ -194,5 +195,6 @@ export class EditComponent implements OnInit {
194195
),
195196
}));
196197
});
198+
});
197199
}
198200
}

projects/core/src/lib/components/edit/state/edit.actions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ export const setEditCreateNewFeatureActive = createAction(
1919

2020
export const setEditCopyOtherLayerFeaturesActive = createAction(
2121
`${editActionsPrefix} Set Copy Other Layer Features Active`,
22-
props<{ active: boolean; layerId: string; columnMetadata: FeatureInfoColumnMetadataModel[] }>(),
22+
props<{ layerId: string; columnMetadata: FeatureInfoColumnMetadataModel[] }>(),
2323
);
2424

25+
export const setEditCopyOtherLayerFeaturesDisabled = createAction(
26+
`${editActionsPrefix} Set Copy Other Layer Features Disabled`);
27+
2528
export const setSelectedEditLayer = createAction(
2629
`${editActionsPrefix} Set Selected Layer`,
2730
props<{ layer: string | null }>(),

projects/core/src/lib/components/edit/state/edit.reducer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,30 @@ const onSetCopyOtherLayerFeaturesActive = (
101101
payload: ReturnType<typeof EditActions.setEditCopyOtherLayerFeaturesActive>,
102102
): EditState => ({
103103
...state,
104-
isCopyOtherLayerFeaturesActive: payload.active,
104+
isCopyOtherLayerFeaturesActive: true,
105105
isCreateNewFeatureActive: false,
106+
dialogVisible: true,
107+
dialogCollapsed: false,
106108
selectedCopyLayer: payload.layerId,
107-
dialogVisible: payload.active,
109+
columnMetadata: payload.columnMetadata,
110+
// Do not reset copiedFeatures, so features from different layers can be copied
108111
selectedFeature: 'new',
109112
features: [{
110113
layerId: payload.columnMetadata[0].layerId,
111114
__fid: 'new',
112115
attributes: {},
113116
}],
114-
columnMetadata: payload.columnMetadata,
115117
loadStatus: LoadingStateEnum.INITIAL,
116-
dialogCollapsed: false,
118+
});
119+
120+
const onSetCopyOtherLayerFeaturesDisabled = (
121+
state: EditState,
122+
): EditState => ({
123+
...state,
124+
isCreateNewFeatureActive: false,
125+
dialogVisible: false,
126+
dialogCollapsed: true,
127+
...initialEditCopyState,
117128
});
118129

119130
const onSetCreateNewFeatureActive = (
@@ -248,6 +259,7 @@ const editReducerImpl = createReducer<EditState>(
248259
initialEditState,
249260
on(EditActions.setEditActive, onSetIsActive),
250261
on(EditActions.setEditCopyOtherLayerFeaturesActive, onSetCopyOtherLayerFeaturesActive),
262+
on(EditActions.setEditCopyOtherLayerFeaturesDisabled, onSetCopyOtherLayerFeaturesDisabled),
251263
on(EditActions.setEditCreateNewFeatureActive, onSetCreateNewFeatureActive),
252264
on(EditActions.setSelectedEditLayer, onSetSelectedLayer),
253265
on(EditActions.loadEditFeatures, onLoadFeatureInfo),

0 commit comments

Comments
 (0)