Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(messages): message at the layer level, config to allow the message to be shown each time the layer is set to be visible. #943

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/lib/message/shared/message.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface MessageOptions extends Notification {
from?: Date | string;
to?: Date | string;
id?: string;
showOnEachLayerVisibility?: boolean;
}
22 changes: 18 additions & 4 deletions packages/geo/src/lib/layer/shared/layers/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ export abstract class Layer {
set visible(value: boolean) {
this.ol.setVisible(value);
this.visible$.next(value);
if (!this.hasBeenVisible$.value && value && this.messageService){
if (!this.hasBeenVisible$.value && value){
this.hasBeenVisible$.next(value);
}
if (this.options?.messages && value) {
this.options?.messages
.filter(m => m.options?.showOnEachLayerVisibility)
.map(message =>
this.showMessage(message)
);
}
}
get visible(): boolean {
return this.visible$.value;
Expand Down Expand Up @@ -178,9 +185,7 @@ export abstract class Layer {
this.hasBeenVisible$$ = this.hasBeenVisible$.subscribe(() => {
if (this.options.messages && this.visible) {
this.options.messages.map(message => {
message.title = message.title;
message.text = message.text;
this.messageService.message(message as Message);
this.showMessage(message);
});
}
});
Expand All @@ -189,6 +194,15 @@ export abstract class Layer {
}
}

private showMessage(message: Message) {
if (!this.messageService) {
return;
}
message.title = message.title;
message.text = message.text;
this.messageService.message(message as Message);
}

private observeResolution() {
this.resolution$$ = this.map.viewController.resolution$.subscribe(() =>
this.updateInResolutionsRange()
Expand Down