libs/open-layers/src/lib/services/map.service.ts
Service which holds all generated maps and their ids
Properties |
|
Methods |
Public getMap | ||||||
getMap(mapId: string)
|
||||||
Delivers the corresponding map as observable to the id
Parameters :
Returns :
Observable<Map>
the map as observable |
Public removeMap | ||||||
removeMap(id: string)
|
||||||
Removes the map to the given map id
Parameters :
Returns :
void
|
Public setMap | |||||||||
setMap(mapId: string, map: Map)
|
|||||||||
Saves id and corresponding map
Parameters :
Returns :
void
|
Private map |
Type : object
|
Default value : {}
|
import { Injectable } from '@angular/core';
import { Map } from 'ol';
import { Observable, of, Subject } from 'rxjs';
/**
* Service which holds all generated maps and their ids
*/
@Injectable({
providedIn: 'root'
})
export class OlMapService {
private map = {};
/**
* Saves id and corresponding map
*
* @param mapId
* @param map
*/
public setMap(mapId: string, map: Map) {
if (this.map[mapId] instanceof Subject) {
const subject = this.map[mapId] as Subject<Map>;
subject.next(map);
subject.complete();
}
this.map[mapId] = map;
}
/**
* Delivers the corresponding map as observable to the id
*
* @param mapId
* @returns the map as observable
*/
public getMap(mapId: string): Observable<Map> {
if (this.map[mapId]) {
if (this.map[mapId] instanceof Subject) {
return this.map[mapId];
} else {
return of(this.map[mapId]);
}
} else {
this.map[mapId] = new Subject<Map>();
return this.map[mapId];
}
}
/**
* Removes the map to the given map id
*
* @param id
*/
public removeMap(id: string): void {
if (this.map[id]) {
delete this.map[id];
}
}
}