Skip to content

Commit

Permalink
fix: Modification and removal of features in uneditable layer
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner authored and jmacura committed May 22, 2024
1 parent feb7753 commit 1ba816a
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 60 deletions.
2 changes: 1 addition & 1 deletion projects/hslayers/assets/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@
},
"reallyDelete": "Opravdu smazat tento prvek?",
"reallyDeleteAllFeaturesFrom": "Opravdu odstranit všechny prvky z vrstvy {0}?",
"reallyDeleteAllSelectedLayers": "Opravdu odstranit všechny vybrané prvky?",
"reallyDeleteAllSelectedLayers": "Opravdu chcete odstranit všechny odstranitelné vybrané prvky?",
"untitledFeature": "Prvek bez názvu"
},
"SAVECOMPOSITION": {
Expand Down
4 changes: 2 additions & 2 deletions projects/hslayers/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
"confirmClear": "Confirm clear",
"confirmDelete": "Confirm delete",
"coordinates": "Coordinates",
"deleteAllSelected": "Delete all selected features",
"deleteAllSelected": "Delete all selected removable features",
"downloadAs": "Download as",
"feature": {
"attributeName": "Attribute name",
Expand Down Expand Up @@ -831,7 +831,7 @@
},
"reallyDelete": "Really delete this feature?",
"reallyDeleteAllFeaturesFrom": "Really delete all features from layer {0}?",
"reallyDeleteAllSelectedLayers": "Really delete all selected features?",
"reallyDeleteAllSelectedLayers": "Do you really want to delete all selected removable features?",
"untitledFeature": "Untitled feature"
},
"SAVECOMPOSITION": {
Expand Down
2 changes: 1 addition & 1 deletion projects/hslayers/assets/locales/lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@
},
"reallyDelete": "Vai tiešām vēlaties dzēst šo objektu?",
"reallyDeleteAllFeaturesFrom": "Vai tiešām vēlaties izdzēst visus objektus no slāņa {0}?",
"reallyDeleteAllSelectedLayers": "Vai tiešām dzēst visus atlasītos grafiskos objektus?",
"reallyDeleteAllSelectedLayers": "Vai tiešām vēlaties dzēst visas atlasītās noņemamās funkcijas?",
"untitledFeature": "Objekts bez nosaukuma"
},
"SAVECOMPOSITION": {
Expand Down
2 changes: 1 addition & 1 deletion projects/hslayers/assets/locales/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@
},
"reallyDelete": "Naozaj zmazať tento prvok?",
"reallyDeleteAllFeaturesFrom": "Naozaj odstrániť všetky prvky z vrstvy {0}?",
"reallyDeleteAllSelectedLayers": "Naozaj odstrániť všetky vybrané prvky?",
"reallyDeleteAllSelectedLayers": "Naozaj chcete odstrániť všetky odstrániteľné vybrané funkcie?",
"untitledFeature": "Prvok bez názvu"
},
"SAVECOMPOSITION": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ChangeDetectionStrategy, Component, Input, OnInit} from '@angular/core';

import {HsLayerDescriptor} from 'hslayers-ng/types';
import {HsLayerUtilsService} from 'hslayers-ng/services/utils';
import {HsQueryPopupWidgetBaseComponent} from '../query-popup-widget-base.component';

@Component({
Expand All @@ -20,20 +19,11 @@ export class HsLayerNameComponent
layerDescriptor: HsLayerDescriptor;
};

constructor(private hsLayerUtilsService: HsLayerUtilsService) {
constructor() {
super();
}

ngOnInit(): void {
this.layerDescriptor = this.data.layerDescriptor;
}

/**
* Get title translation
* @param title - Title to translate
* @returns Translated title
*/
translateTitle(title: string): string {
return this.hsLayerUtilsService.translateTitle(title);
}
}
28 changes: 22 additions & 6 deletions projects/hslayers/components/print/print-legend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Observable, Subject, Subscription} from 'rxjs';
import {Vector as VectorLayer} from 'ol/layer';
import {Vector as VectorSource} from 'ol/source';

import {HsLayerUtilsService} from 'hslayers-ng/services/utils';
import {HsLanguageService} from 'hslayers-ng/services/language';
import {HsLegendDescriptor} from 'hslayers-ng/components/legend';
import {HsLegendLayerStaticService} from 'hslayers-ng/components/legend';
import {HsLegendService} from 'hslayers-ng/components/legend';
Expand All @@ -28,7 +28,7 @@ export class HsPrintLegendService extends PrintLegendParams {
private hsMapService: HsMapService,
private hsLegendService: HsLegendService,
private hsLegendLayerStaticService: HsLegendLayerStaticService,
private hsLayerUtilsService: HsLayerUtilsService,
private hsLanguageService: HsLanguageService,
private hsShareThumbnailService: HsShareThumbnailService,
) {
super();
Expand Down Expand Up @@ -148,7 +148,11 @@ export class HsPrintLegendService extends PrintLegendParams {
for (const sublayer of desc.subLayerLegends) {
const wmsSvg = await this.legendImageToSvg(
sublayer,
this.hsLayerUtilsService.translateTitle(desc.title),
this.hsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
desc.title,
undefined,
),
);
if (wmsSvg) {
svgSources.push(wmsSvg);
Expand Down Expand Up @@ -198,7 +202,11 @@ export class HsPrintLegendService extends PrintLegendParams {
}
svgSource = this.legendToSvg(
legendSource,
this.hsLayerUtilsService.translateTitle(desc.title),
this.hsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
desc.title,
undefined,
),
);
} else {
for (const category of (desc.lyr.getSource() as SparqlJson)
Expand All @@ -220,13 +228,21 @@ export class HsPrintLegendService extends PrintLegendParams {
case 'image':
svgSource = await this.legendImageToSvg(
layerLegend.lastLegendImage,
this.hsLayerUtilsService.translateTitle(desc.title),
this.hsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
desc.title,
undefined,
),
);
break;
case 'svg':
svgSource = this.legendToSvg(
layerLegend.lastLegendImage,
this.hsLayerUtilsService.translateTitle(desc.title),
this.hsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
desc.title,
undefined,
),
);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div class="input-group m-1">
<span class="input-group-text">{{attribute.name}}</span>
<input class="form-control" *ngIf="!isObject" [(ngModel)]="attribute.value" (change)="change()"
[readonly]="readonly" [ngModelOptions]="{standalone: true}">
[readonly]="readonly" name="hs-query-attribute-row-input">
<textarea class="form-control" *ngIf="isObject" name="attributeValue" [(ngModel)]="tmpObjectValue"
[readonly]="readonly" (change)="change()" [ngModelOptions]="{standalone: true}">
[readonly]="readonly" (change)="change()" name="hs-query-attribute-row-textarea">
</textarea>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions projects/hslayers/components/query/feature-common.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class HsFeatureCommonService {
map.getLayers().on('change:length', () => {
this.updateLayerList();
});

this.updateLayerList();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
[feature]="item">
</hs-query-feature>
</div>
</ng-container>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ export class HsQueryFeatureListComponent {
);
const confirmed = await dialog.waitResult();
if (confirmed == 'yes') {
for (const feature of this.hsQueryBaseService.features) {
for (const feature of this.hsQueryBaseService.features.filter((f) =>
this.hsQueryVectorService.isFeatureRemovable(f.feature),
)) {
//Give HsQueryVectorService.featureRemovals time to splice QueryBase.data.features
setTimeout(() => {
this.hsQueryVectorService.removeFeature(feature.feature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{feature.layer}}</strong></div>
</div>
<hs-query-attribute-row *ngFor="let attribute of feature.attributes" [template]="feature.hstemplate"
[feature]="feature" [attribute]="attribute" [readonly]="false">
[feature]="feature" [attribute]="attribute" [readonly]="readonly">
</hs-query-attribute-row>
<hs-query-attribute-row *ngFor="let stat of feature.stats" [feature]="feature" [attribute]="stat" [readonly]="true">
</hs-query-attribute-row>
Expand Down Expand Up @@ -38,7 +38,7 @@
[(ngModel)]="selectedLayer" name="selectedLayer">
<option [ngValue]="null" [disabled]="true" selected hidden> {{'ADDLAYERS.Vector.chooseLayer' |
translateHs }}</option>
<option *ngFor="let layer of availableLayers" [ngValue]="layer">
<option *ngFor="let layer of availableLayers | async" [ngValue]="layer">
{{getTitle(layer) | translateHs : {module: 'LAYERS'} }}</option>
</select>
<button class="btn btn-primary btn-sm" (click)="moveOrCopyFeature()" [disabled]="!selectedLayer"><i
Expand All @@ -49,8 +49,8 @@
<div class="justify-content-end" style="padding-left: 10px" *ngIf="olFeature() !== undefined">
<div class="mx-1 mb-2 text-end">
<div class="btn-group">
<button class="btn btn-secondary btn-sm" (click)="newAttribVisible = !newAttribVisible"><i
class="icon-calcplus"></i></button>
<button [disabled]="readonly" class="btn btn-secondary btn-sm"
(click)="newAttribVisible = !newAttribVisible"><i class="icon-calcplus"></i></button>
<button class="btn btn-secondary btn-sm" (click)="zoomToFeature()"><i class="icon-search"></i></button>
<div class="btn-group" ngbDropdown placement="bottom" display="dynamic">
<button ngbDropdownToggle class="btn btn-secondary btn-sm" type="button" (click)="toggleEditMenu()"><i
Expand Down
32 changes: 19 additions & 13 deletions projects/hslayers/components/query/feature/feature.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {Component, DestroyRef, Input, OnInit} from '@angular/core';
import {Observable, map} from 'rxjs';

import {Feature} from 'ol';
import {Geometry} from 'ol/geom';
import {Layer} from 'ol/layer';

import {HsFeatureCommonService} from '../feature-common.service';
import {HsLayerUtilsService} from 'hslayers-ng/services/utils';
import {HsMapService} from 'hslayers-ng/services/map';
import {HsQueryVectorService} from 'hslayers-ng/services/query';
import {exportFormats} from '../feature-common.service';
import {getTitle} from 'hslayers-ng/common/extensions';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';

@Component({
selector: 'hs-query-feature',
templateUrl: './feature.component.html',
})
export class HsQueryFeatureComponent implements OnDestroy, OnInit {
export class HsQueryFeatureComponent implements OnInit {
@Input() feature;

attributeName = '';
Expand All @@ -33,31 +37,33 @@ export class HsQueryFeatureComponent implements OnDestroy, OnInit {
selectedLayer = null;
editType: 'move' | 'copy';
getTitle = getTitle;
availableLayers = [];
availableLayersSubscription: any;
availableLayers: Observable<Layer[]>;

readonly: boolean;

constructor(
private hsMapService: HsMapService,
private hsQueryVectorService: HsQueryVectorService,
private hsFeatureCommonService: HsFeatureCommonService,
private hsLayerUtilsService: HsLayerUtilsService,
private DestroyRef: DestroyRef,
) {}

ngOnInit(): void {
this.availableLayersSubscription =
this.hsFeatureCommonService.availableLayer$.subscribe((layers) => {
this.availableLayers = this.hsFeatureCommonService.availableLayer$.pipe(
takeUntilDestroyed(this.DestroyRef),
map((layers) => {
if (!this.olFeature()) {
//Feature from WMS getFeatureInfo
return;
return [];
}
const featureLayer = this.hsMapService.getLayerForFeature(
this.olFeature(),
);
this.availableLayers = layers.filter((layer) => layer != featureLayer);
});
}

ngOnDestroy(): void {
this.availableLayersSubscription?.unsubscribe();
this.readonly = !this.hsLayerUtilsService.isLayerEditable(featureLayer);
return layers.filter((layer) => layer != featureLayer);
}),
);
}

/**
Expand Down
20 changes: 14 additions & 6 deletions projects/hslayers/services/draw/draw.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ export class HsDrawService extends HsDrawServiceParams {
if (this.onSelected) {
this.onSelected(e);
}
this.modify.setActive(true);
});

this.selectedFeatures.on('remove', (e) => {
if (this.selectedFeatures.length == 0) {
if (this.selectedFeatures.getLength() == 0) {
this.modify.setActive(false);
}
});

this.hsEventBusService.vectorQueryFeatureSelection.subscribe((event) => {
this.selectedFeatures.push(event.feature);
if (getEditor(event.selector.getLayer(event.feature)).editable) {
this.modify.setActive(true);
}
});

this.hsEventBusService.vectorQueryFeatureDeselection.subscribe(
Expand Down Expand Up @@ -168,8 +170,11 @@ export class HsDrawService extends HsDrawServiceParams {
const title = getTitle(this.selectedLayer);
return title == TMP_LAYER_TITLE
? this.translate('DRAW.unsavedDrawing')
: this.hsLayerUtilsService.translateTitle(title) ||
getName(this.selectedLayer);
: this.hsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
title,
undefined,
) || getName(this.selectedLayer);
} else {
return this.translate('DRAW.Select layer');
}
Expand All @@ -182,8 +187,11 @@ export class HsDrawService extends HsDrawServiceParams {
if (this.snapLayer) {
const title = getTitle(this.snapLayer);
return (
this.hsLayerUtilsService.translateTitle(title) ||
getName(this.snapLayer)
this.hsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
title,
undefined,
) || getName(this.snapLayer)
);
}
}
Expand Down
10 changes: 0 additions & 10 deletions projects/hslayers/services/utils/layer-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {METERS_PER_UNIT} from 'ol/proj';
import {Tile as TileLayer} from 'ol/layer';
import {isEmpty} from 'ol/extent';

import {HsLanguageService} from 'hslayers-ng/services/language';
import {HsLayerDescriptor} from 'hslayers-ng/types';
import {HsUtilsService} from './utils.service';
import {HsWmsLayer} from 'hslayers-ng/types';
Expand All @@ -38,7 +37,6 @@ import {
export class HsLayerUtilsService {
constructor(
public HsUtilsService: HsUtilsService,
public HsLanguageService: HsLanguageService,
private zone: NgZone,
) {}

Expand Down Expand Up @@ -452,14 +450,6 @@ export class HsLayerUtilsService {
: false;
}

translateTitle(title: string): string {
return this.HsLanguageService.getTranslationIgnoreNonExisting(
'LAYERS',
title,
undefined,
);
}

/**
* Test if layers source is loaded
* @param layer - Selected layer descriptor
Expand Down

0 comments on commit 1ba816a

Please sign in to comment.