-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fully implement functionality for show/hide of layers
- Loading branch information
1 parent
04cfc67
commit 69bd5f9
Showing
8 changed files
with
208 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<div leaflet | ||
[leafletOptions]="options" | ||
[leafletLayers]="layers" | ||
(leafletMapReady)="onMapReady($event)" | ||
(leafletMapZoomStart)="onMapZoomStart()" | ||
(leafletMapZoomEnd)="onMapZoomEnd($event)" | ||
class="map"> | ||
<div *ngFor="let value of layers | async" [leafletLayer]="value"></div> | ||
</div> | ||
<div class="loader" *ngIf="showLoader"> | ||
<span>{{ showLoader }}</span> | ||
</div> | ||
<div class="loader" *ngIf="showLoader"><span>{{ showLoader }}</span></div> |
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 |
---|---|---|
@@ -1,44 +1,78 @@ | ||
import { EventEmitter, Injectable, Output } from '@angular/core'; | ||
import { geoJson, Layer } from 'leaflet'; | ||
import { EventEmitter, Injectable } from '@angular/core'; | ||
import { GeoJSON, geoJson, Layer } from 'leaflet'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { NGXLogger } from 'ngx-logger'; | ||
import { GeoJsonObject } from 'geojson'; | ||
import { capitols, centerOfEurope, darkMatterNoLabelsLayer, euBorderStyle } from './map.constants'; | ||
import { firstValueFrom } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class MapService { | ||
@Output() resetMap = new EventEmitter<string>(); | ||
@Output() toMyLocation = new EventEmitter<string>(); | ||
resetMap$ = new EventEmitter<string>(); | ||
toMyLocation$ = new EventEmitter<string>(); | ||
showEuBorders$ = new EventEmitter<boolean>(); | ||
showCapitols$ = new EventEmitter<boolean>(); | ||
|
||
private readonly euBordersLayer: Promise<GeoJSON>; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private log: NGXLogger | ||
) {} | ||
) { | ||
this.euBordersLayer = this.initEuBordersLayer(); | ||
} | ||
|
||
getBaseLayer() { | ||
return darkMatterNoLabelsLayer; | ||
private async initEuBordersLayer() { | ||
return firstValueFrom(this.http.get<GeoJsonObject>('./assets/geo-data/european-borders.json')) | ||
.then(jsonResponse => { | ||
this.log.debug('Loaded borders json', jsonResponse); | ||
return geoJson(jsonResponse, { style: euBorderStyle }); | ||
}) | ||
.catch(err => { | ||
this.log.error('Error loading EU borders geo json', err); | ||
// TODO error notification | ||
return geoJson(); | ||
}); | ||
} | ||
|
||
getCenterOfEurope() { | ||
return centerOfEurope; | ||
} | ||
|
||
load(layers: Layer[]) { | ||
this.http.get<GeoJsonObject>('./assets/geo-data/european-borders.json').subscribe((json: GeoJsonObject) => { | ||
this.log.info('Loaded borders json', json); | ||
async loadAllLayers(): Promise<Layer[]> { | ||
return Promise.all([this.getBaseLayer(), this.getEuBordersLayer(), this.getCapitolsLayer()]); | ||
} | ||
|
||
private async getBaseLayer() { | ||
return darkMatterNoLabelsLayer; | ||
} | ||
|
||
layers.push(geoJson(json, { style: euBorderStyle })); | ||
layers.push(capitols); | ||
}); | ||
private async getEuBordersLayer() { | ||
return this.euBordersLayer; | ||
} | ||
|
||
resetMapToEuropeanCenter() { | ||
// TODO load capitols via HTTP | ||
private async getCapitolsLayer() { | ||
return capitols; | ||
} | ||
|
||
async resetMapToEuropeanCenter() { | ||
this.log.info('Reset map'); | ||
this.resetMap.emit(); | ||
this.resetMap$.emit(); | ||
} | ||
|
||
moveMapToMyLocation() { | ||
async moveMapToMyLocation() { | ||
this.log.info('Move map to my location'); | ||
this.toMyLocation.emit(); | ||
this.toMyLocation$.emit(); | ||
} | ||
|
||
async doShowEuBorders(value: boolean) { | ||
this.log.trace('Show EU borders', value); | ||
this.showEuBorders$.emit(value); | ||
} | ||
|
||
async doShowCapitols(value: boolean) { | ||
this.log.trace('Show capitols', value); | ||
this.showCapitols$.emit(value); | ||
} | ||
} |
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
Oops, something went wrong.