Skip to content

Commit

Permalink
fix: Adding drawing layer fails when auth change
Browse files Browse the repository at this point in the history
Tmp drawing layer workspace property needs to be upadted on authchange
  • Loading branch information
FilipLeitner authored and raitisbe committed Jul 12, 2021
1 parent 1b6d735 commit eae03ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Expand Up @@ -86,23 +86,24 @@ export class HsDrawLayerMetadataDialogComponent

this.data.addDrawLayer(this.layer);
this.data.fillDrawableLayers();
if (this.data.tmpDrawLayer) {
this.tmpFeatures = this.layer.getSource().getFeatures();
//Dispatch add feature event in order to trigger sync
this.awaitLayerSync(this.layer).then(() => {
const event =
this.layer.getSource().getFeatures().length > this.tmpFeatures.length
? //Existing layer
{type: 'addfeature', feature: this.tmpFeatures}
: //New layer
'addfeature';
this.layer.getSource().dispatchEvent(event);
});
}
this.tmpFeatures = this.layer.getSource().getFeatures();
//Dispatch add feature event in order to trigger sync
this.awaitLayerSync(this.layer).then(() => {
const event = this.tmpFeatures ? this.getEventType() : 'addfeature';
this.layer.getSource().dispatchEvent(event);
});
this.data.tmpDrawLayer = false;
this.HsDialogContainerService.destroy(this);
}

getEventType() {
return this.layer.getSource().getFeatures().length > this.tmpFeatures.length
? //Existing layer
{type: 'addfeature', feature: this.tmpFeatures}
: //New layer
'addfeature';
}

cancel(): void {
this.data.selectedLayer = this.data.previouslySelected;
this.HsDialogContainerService.destroy(this);
Expand Down
5 changes: 5 additions & 0 deletions projects/hslayers/src/components/draw/draw.service.ts
Expand Up @@ -29,6 +29,7 @@ import {
getEditor,
getName,
getTitle,
setWorkspace,
} from '../../common/layer-extensions';

type activateParams = {
Expand Down Expand Up @@ -185,6 +186,9 @@ export class HsDrawService {
this.fillDrawableLayers();
this.isAuthorized =
endpoint.user !== 'anonymous' && endpoint.user !== 'browser';
if (this.selectedLayer && this.tmpDrawLayer){
setWorkspace(this.selectedLayer, endpoint.user)
}
});

this.HsEventBusService.LayerManagerLayerVisibilityChanges.subscribe(
Expand Down Expand Up @@ -265,6 +269,7 @@ export class HsDrawService {
},
workspace: this.HsLaymanService.getLaymanEndpoint()?.user,
});
this.tmpDrawLayer = true;
this.selectedLayer = drawLayer;
this.HsDialogContainerService.create(
HsDrawLayerMetadataDialogComponent,
Expand Down
Expand Up @@ -21,7 +21,7 @@ <h4 class="modal-title">
<hs-layman-current-user [endpoint]="endpoint"></hs-layman-current-user>
</div>
<div class="d-flex w-75 m-auto p-4 justify-content-around" style="white-space: nowrap;"
*ngIf="data.drawableLaymanLayers.length > 0 && data.isAuthorized && !data.tmpDrawLayer">
*ngIf="data.drawableLaymanLayers.length > 0 && data.isAuthorized">
<button type="button" class="btn btn-sm rounded hs-toolbar-button" (click)="type = 'draw'"
[ngClass]="type == 'draw' ? 'btn-primary' : 'btn-secondary'">
{{'DRAW.drawToolbar.addDrawLayer' | translate}}
Expand Down

0 comments on commit eae03ad

Please sign in to comment.