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(layer-item): layer's resolution change depending of the network state #395

Merged
merged 4 commits into from
Sep 23, 2019
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 @@ -8,4 +8,5 @@ export interface ClusterDataSourceOptions extends FeatureDataSourceOptions {
distance?: number;
source?: FeatureDataSource;
ol?: olSourceVector;
pathOffline?: string;
}
12 changes: 11 additions & 1 deletion packages/geo/src/lib/layer/layer-item/layer-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Subscription, BehaviorSubject } from 'rxjs';
import { MetadataLayerOptions } from '../../metadata/shared/metadata.interface';
import { layerIsQueryable } from '../../query/shared/query.utils';
import { Layer, TooltipType } from '../shared/layers';
import { NetworkService, ConnectionState } from '@igo2/core';

@Component({
selector: 'igo-layer-item',
Expand All @@ -29,6 +30,8 @@ export class LayerItemComponent implements OnInit, OnDestroy {

private resolution$$: Subscription;

private state: ConnectionState;

@Input() layer: Layer;

@Input() toggleLegendOnVisibilityChange: boolean = false;
Expand All @@ -50,7 +53,9 @@ export class LayerItemComponent implements OnInit, OnDestroy {
get opacity() { return this.layer.opacity * 100; }
set opacity(opacity: number) { this.layer.opacity = opacity / 100; }

constructor() {}
constructor(
private networkService: NetworkService
) {}

ngOnInit() {
const legend = this.layer.dataSource.options.legend || {};
Expand All @@ -66,6 +71,11 @@ export class LayerItemComponent implements OnInit, OnDestroy {
this.onResolutionChange();
});
this.tooltipText = this.computeTooltip();

this.networkService.currentState().subscribe((state: ConnectionState) => {
this.state = state;
this.onResolutionChange();
});
}

ngOnDestroy() {
Expand Down
30 changes: 22 additions & 8 deletions packages/geo/src/lib/map/shared/mapOffline.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MapBrowserComponent } from '../map-browser/map-browser.component';
import { FeatureDataSourceOptions } from '../../datasource/shared/datasources/feature-datasource.interface';
import { XYZDataSourceOptions } from '../../datasource/shared/datasources/xyz-datasource.interface';
import { MVTDataSourceOptions } from '../../datasource/shared/datasources/mvt-datasource.interface';
import { ClusterDataSourceOptions } from '../../datasource/shared/datasources/cluster-datasource.interface';

@Directive({
selector: '[igoMapOffline]'
Expand Down Expand Up @@ -43,28 +44,41 @@ export class MapOfflineDirective implements AfterViewInit {
layerList.forEach(layer => {
if (layer.options.sourceOptions.type === 'mvt') {
sourceOptions = (layer.options.sourceOptions as MVTDataSourceOptions);
layer.ol.getSource().clear();
} else if (layer.options.sourceOptions.type === 'xyz') {
sourceOptions = (layer.options.sourceOptions as XYZDataSourceOptions);
} else if (layer.options.sourceOptions.type === 'vector') {
sourceOptions = (layer.options.sourceOptions as FeatureDataSourceOptions);
} else if (layer.options.sourceOptions.type === 'cluster') {
sourceOptions = (layer.options.sourceOptions as ClusterDataSourceOptions);
} else {
return;
if (this.state.connection === false) {
layer.ol.setMaxResolution(0);
return;
} else if (this.state.connection === true) {
layer.ol.setMaxResolution(Infinity);
return;
}
}

if (sourceOptions.pathOffline &&
this.state.connection === false) {
if (sourceOptions.excludeAttributeOffline) {
sourceOptions.excludeAttributeBackUp = sourceOptions.excludeAttribute;
sourceOptions.excludeAttribute = sourceOptions.excludeAttributeOffline;
if (sourceOptions.type === 'vector' || 'cluster') {
return;
}
layer.ol.getSource().clear();
layer.ol.getSource().setUrl(sourceOptions.pathOffline);
} else if (sourceOptions.pathOffline &&
this.state.connection === true) {
if (sourceOptions.excludeAttributeBackUp) {
sourceOptions.excludeAttribute = sourceOptions.excludeAttributeBackUp;
if (sourceOptions.type === 'vector' || 'cluster') {
return;
}
layer.ol.getSource().clear();
layer.ol.getSource().setUrl(sourceOptions.url);
} else {
if (this.state.connection === false) {
layer.ol.setMaxResolution(0);
} else if (this.state.connection === true) {
layer.ol.setMaxResolution(Infinity);
}
}
});
}
Expand Down