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

BREAKING CHANGE(OFFLINE): major refactor and some properties moved #1213

Merged
merged 6 commits into from
Mar 30, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class FeatureDetailsComponent implements OnInit, OnDestroy {
let offlineButtonState;

if (this.map) {
this.map.offlineButtonToggle$.pipe(takeUntil(this.unsubscribe$)).subscribe(state => {
this.map.forcedOffline$.pipe(takeUntil(this.unsubscribe$)).subscribe(state => {
offlineButtonState = state;
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/layer/shared/layers/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export abstract class Layer {
> = new BehaviorSubject(false);

set maxResolution(value: number) {
this.ol.setMaxResolution(value || Infinity);
this.ol.setMaxResolution(value === 0 ? 0 : value || Infinity);
this.updateInResolutionsRange();
}
get maxResolution(): number {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<div *ngIf="visible" class="igo-user-button-container">
<div>
<button
mat-icon-button
[matTooltip]="checked ? ('igo.geo.mapButtons.online' | translate): ('igo.geo.mapButtons.offline' | translate)"
matTooltipPosition="left"
[ngClass]="[btnStyle]"
[color]="checked ? color : [colorOff]"
(click)="onToggle()"
(click)="map.onOfflineToggle(check)">
<mat-icon svgIcon="wifi-strength-off"></mat-icon>
</button>
</div>
<div class="igo-user-button-container">
<button
mat-icon-button
[matTooltip]="enabled ? ('igo.geo.mapButtons.online' | translate): ('igo.geo.mapButtons.offline' | translate)"
matTooltipPosition="left"
[ngClass]="[btnStyle]"
[color]="enabled ? color : null"
(click)="onClick()">
<mat-icon svgIcon="wifi-strength-off"></mat-icon>
</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@import '../../../../../core/src/style/partial/media';
@import '../../../../../core/src/style/partial/core.variables';

.baseStyle {
.onlineStyle {
width: $igo-icon-size;
background-color: rgb(255, 255, 255);
&:hover {
background-color: #efefef;
}
}

.toggleStyle {
.offlineStyle {
width: $igo-icon-size;
background-color: #b9b9b9;
}
Expand Down
55 changes: 17 additions & 38 deletions packages/geo/src/lib/map/offline-button/offline-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,37 @@
import { Component, Input, EventEmitter, Output } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { IgoMap } from '../shared/map';
import { ConfigService } from '@igo2/core';

@Component({
selector: 'igo-offline-button',
templateUrl: './offline-button.component.html',
styleUrls: ['./offline-button.component.scss']
})

export class OfflineButtonComponent {
export class OfflineButtonComponent implements OnInit {

btnStyle: string = 'baseStyle';
colorOff: string = 'rgb(255,255,255)';
btnStyle: string = 'onlineStyle';

@Output() change = new EventEmitter<boolean>();
@Input() map: IgoMap;
@Input() color: IgoMap;
@Input() enabled: boolean = false;

@Input()
get map(): IgoMap {
return this._map;
}
set map(value: IgoMap) {
this._map = value;
}
private _map: IgoMap;
constructor() {}

@Input()
get color(): string {
return this._color;
ngOnInit(): void {
this.map.forcedOffline$.next(this.enabled);
}
set color(value: string) {
this._color = value;
}
private _color: string;

@Input() public check: boolean = false;

get checked(): boolean {
return this.check;
}

public visible = false;

constructor(
private config: ConfigService
) {
this.visible = this.config.getConfig('offlineButton') ? true : false;
onClick() {
this.enabled = !this.enabled;
this.handleButtonStyle();
this.map.forcedOffline$.next(this.enabled);
}

onToggle() {
this.check = !this.check;
if (this.check) {
this.btnStyle = 'toggleStyle';
private handleButtonStyle() {
if (this.enabled) {
this.btnStyle = 'offlineStyle';
} else {
this.btnStyle = 'baseStyle';
this.btnStyle = 'onlineStyle';
}
}
}
6 changes: 1 addition & 5 deletions packages/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
// Move some stuff into controllers.
export class IgoMap {
public ol: olMap;
public offlineButtonToggle$ = new BehaviorSubject<boolean>(false);
public forcedOffline$ = new BehaviorSubject<boolean>(false);
public layers$ = new BehaviorSubject<Layer[]>([]);
public status$: Subject<SubjectStatus>;
public propertyChange$: Subject<{event:ObjectEvent, layer: Layer}>;
Expand Down Expand Up @@ -514,8 +514,4 @@ export class IgoMap {
private getLayerIndex(layer: Layer) {
return this.layers.findIndex((_layer: Layer) => _layer === layer);
}

onOfflineToggle(offline: boolean) {
this.offlineButtonToggle$.next(offline);
}
}
Loading