File

libs/open-layers/src/lib/services/map.service.ts

Description

Service which holds all generated maps and their ids

Index

Properties
Methods

Methods

Public getMap
getMap(mapId: string)

Delivers the corresponding map as observable to the id

Parameters :
Name Type Optional
mapId string No
Returns : Observable<Map>

the map as observable

Public removeMap
removeMap(id: string)

Removes the map to the given map id

Parameters :
Name Type Optional
id string No
Returns : void
Public setMap
setMap(mapId: string, map: Map)

Saves id and corresponding map

Parameters :
Name Type Optional
mapId string No
map Map No
Returns : void

Properties

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];
    }
  }

}

result-matching ""

    No results matching ""