File

packages/core/src/lib/services/managers/kml-layer-manager.ts

Description

Manages all KML Layers for a Google Map instance.

Index

Properties
Methods

Constructor

constructor(_wrapper: GoogleMapsAPIWrapper, _zone: NgZone)
Parameters :
Name Type Optional
_wrapper GoogleMapsAPIWrapper No
_zone NgZone No

Methods

addKmlLayer
addKmlLayer(layer: AgmKmlLayer)

Adds a new KML Layer to the map.

Parameters :
Name Type Optional
layer AgmKmlLayer No
Returns : void
createEventObservable
createEventObservable(eventName: string, layer: AgmKmlLayer)
Type parameters :
  • T

Creates a Google Maps event listener for the given KmlLayer as an Observable

Parameters :
Name Type Optional
eventName string No
layer AgmKmlLayer No
Returns : Observable<T>
deleteKmlLayer
deleteKmlLayer(layer: AgmKmlLayer)
Parameters :
Name Type Optional
layer AgmKmlLayer No
Returns : void
setOptions
setOptions(layer: AgmKmlLayer, options: google.maps.KmlLayerOptions)
Parameters :
Name Type Optional
layer AgmKmlLayer No
options google.maps.KmlLayerOptions No
Returns : void

Properties

Private _layers
Type : Map<AgmKmlLayer | Promise<google.maps.KmlLayer>>
Default value : new Map<AgmKmlLayer, Promise<google.maps.KmlLayer>>()
import { Injectable, NgZone } from '@angular/core';
import { Observable, Observer } from 'rxjs';

import { AgmKmlLayer } from './../../directives/kml-layer';
import { GoogleMapsAPIWrapper } from './../google-maps-api-wrapper';

/**
 * Manages all KML Layers for a Google Map instance.
 */
@Injectable()
export class KmlLayerManager {
  private _layers: Map<AgmKmlLayer, Promise<google.maps.KmlLayer>> =
      new Map<AgmKmlLayer, Promise<google.maps.KmlLayer>>();

  constructor(private _wrapper: GoogleMapsAPIWrapper, private _zone: NgZone) {}

  /**
   * Adds a new KML Layer to the map.
   */
  addKmlLayer(layer: AgmKmlLayer) {
    const newLayer = this._wrapper.getNativeMap().then(m => {
      return new google.maps.KmlLayer({
        clickable: layer.clickable,
        map: m,
        preserveViewport: layer.preserveViewport,
        screenOverlays: layer.screenOverlays,
        suppressInfoWindows: layer.suppressInfoWindows,
        url: layer.url,
        zIndex: layer.zIndex,
      });
    });
    this._layers.set(layer, newLayer);
  }

  setOptions(layer: AgmKmlLayer, options: google.maps.KmlLayerOptions) {
    this._layers.get(layer).then(l => l.setOptions(options));
  }

  deleteKmlLayer(layer: AgmKmlLayer) {
    this._layers.get(layer).then(l => {
      l.setMap(null);
      this._layers.delete(layer);
    });
  }

  /**
   * Creates a Google Maps event listener for the given KmlLayer as an Observable
   */
  createEventObservable<T>(eventName: string, layer: AgmKmlLayer): Observable<T> {
    return new Observable((observer: Observer<T>) => {
      this._layers.get(layer).then((m: google.maps.KmlLayer) => {
        m.addListener(eventName, (e: T) => this._zone.run(() => observer.next(e)));
      });
    });
  }
}

result-matching ""

    No results matching ""