-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(map): add a directive that change url to path depending on the n…
…etwork status (#384) * feat(network): new network service that return the network status * feat(map): * new feature that change the url to a path depending on the network status. * the query can now select features from layers. * feat(map): add a directive that change url to path depending on the network status * fix(datasource): remove useless attributes * Delete mapOffline.directive.spec.ts * Update datasource.ts * Update datasource.ts
- Loading branch information
Showing
7 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Directive, AfterViewInit } from '@angular/core'; | ||
import { IgoMap } from './map'; | ||
import { MapBrowserComponent } from '../map-browser/map-browser.component'; | ||
import { NetworkService, ConnectionState } from '@igo2/core'; | ||
import { Subscription } from 'rxjs'; | ||
import { Layer } from '../../layer/shared/layers/layer'; | ||
import { MVTDataSourceOptions, XYZDataSourceOptions, FeatureDataSourceOptions } from '../../datasource'; | ||
|
||
@Directive({ | ||
selector: '[igoMapOffline]' | ||
}) | ||
export class MapOfflineDirective implements AfterViewInit { | ||
|
||
private context$$: Subscription; | ||
private state: ConnectionState; | ||
private component: MapBrowserComponent; | ||
|
||
get map(): IgoMap { | ||
return this.component.map; | ||
} | ||
|
||
constructor( | ||
component: MapBrowserComponent, | ||
private networkService: NetworkService | ||
) { | ||
this.component = component; | ||
} | ||
|
||
ngAfterViewInit() { | ||
this.networkService.currentState().subscribe((state: ConnectionState) => { | ||
console.log(state); | ||
this.state = state; | ||
this.changeLayer(); | ||
}); | ||
|
||
this.map.layers$.subscribe((layers: Layer[]) => { | ||
this.changeLayer(); | ||
}); | ||
} | ||
|
||
private changeLayer() { | ||
let sourceOptions; | ||
const layerList = this.map.layers$.value; | ||
layerList.forEach(layer => { | ||
if (layer.options.sourceOptions.type === 'mvt') { | ||
sourceOptions = (layer.options.sourceOptions as MVTDataSourceOptions); | ||
} 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 { | ||
return; | ||
} | ||
if (sourceOptions.pathOffline && | ||
this.state.connection === false) { | ||
if (sourceOptions.excludeAttributeOffline) { | ||
sourceOptions.excludeAttributeBackUp = sourceOptions.excludeAttribute; | ||
sourceOptions.excludeAttribute = sourceOptions.excludeAttributeOffline; | ||
} | ||
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; | ||
} | ||
layer.ol.getSource().clear(); | ||
layer.ol.getSource().setUrl(sourceOptions.url); | ||
} | ||
}); | ||
} | ||
} |