11import { ChangeDetectionStrategy , Component , DestroyRef , OnInit , inject , signal } from '@angular/core' ;
22import {
33 selectCopiedFeatures ,
4- selectEditActive , selectEditCopyOtherLayerFeaturesActive , selectEditCreateNewFeatureActive ,
4+ selectEditActive , selectEditCopyOtherLayerFeaturesActive , selectEditCreateNewFeatureActive , selectSelectedCopyLayer ,
55 selectSelectedEditLayer ,
66} from '../state/edit.selectors' ;
77import { Store } from '@ngrx/store' ;
88import { combineLatest , map , of , take } from 'rxjs' ;
99import {
10- setEditActive , setEditCopyOtherLayerFeaturesActive , setEditCreateNewFeatureActive , setSelectedEditLayer ,
10+ setEditActive , setEditCopyOtherLayerFeaturesActive , setEditCopyOtherLayerFeaturesDisabled , setEditCreateNewFeatureActive ,
11+ setSelectedEditLayer ,
1112} from '../state/edit.actions' ;
1213import { FormControl } from '@angular/forms' ;
1314import { 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}
0 commit comments