File

packages/core/src/lib/services/managers/info-window-manager.ts

Index

Properties
Methods

Constructor

constructor(_mapsWrapper: GoogleMapsAPIWrapper, _zone: NgZone, _markerManager: MarkerManager)
Parameters :
Name Type Optional
_mapsWrapper GoogleMapsAPIWrapper No
_zone NgZone No
_markerManager MarkerManager No

Methods

addInfoWindow
addInfoWindow(infoWindow: AgmInfoWindow)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
Returns : void
close
close(infoWindow: AgmInfoWindow)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
Returns : Promise<void>
createEventObservable
createEventObservable(eventName: string, infoWindow: AgmInfoWindow)
Type parameters :
  • T

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

Parameters :
Name Type Optional
eventName string No
infoWindow AgmInfoWindow No
Returns : Observable<T>
deleteInfoWindow
deleteInfoWindow(infoWindow: AgmInfoWindow)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
Returns : Promise<void>
open
open(infoWindow: AgmInfoWindow)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
Returns : Promise<void>
setOptions
setOptions(infoWindow: AgmInfoWindow, options: google.maps.InfoWindowOptions)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
options google.maps.InfoWindowOptions No
Returns : any
setPosition
setPosition(infoWindow: AgmInfoWindow)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
Returns : Promise<void>
setZIndex
setZIndex(infoWindow: AgmInfoWindow)
Parameters :
Name Type Optional
infoWindow AgmInfoWindow No
Returns : Promise<void>

Properties

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

import { AgmInfoWindow } from '../../directives/info-window';

import { GoogleMapsAPIWrapper } from '../google-maps-api-wrapper';
import { MarkerManager } from './marker-manager';

@Injectable()
export class InfoWindowManager {
  private _infoWindows: Map<AgmInfoWindow, Promise<google.maps.InfoWindow>> =
      new Map<AgmInfoWindow, Promise<google.maps.InfoWindow>>();

  constructor(
      private _mapsWrapper: GoogleMapsAPIWrapper, private _zone: NgZone,
      private _markerManager: MarkerManager) {}

  deleteInfoWindow(infoWindow: AgmInfoWindow): Promise<void> {
    const iWindow = this._infoWindows.get(infoWindow);
    if (iWindow == null) {
      // info window already deleted
      return Promise.resolve();
    }
    return iWindow.then((i: google.maps.InfoWindow) => {
      return this._zone.run(() => {
        i.close();
        this._infoWindows.delete(infoWindow);
      });
    });
  }

  setPosition(infoWindow: AgmInfoWindow): Promise<void> {
    return this._infoWindows.get(infoWindow).then((i: google.maps.InfoWindow) => i.setPosition({
      lat: infoWindow.latitude,
      lng: infoWindow.longitude,
    }));
  }

  setZIndex(infoWindow: AgmInfoWindow): Promise<void> {
    return this._infoWindows.get(infoWindow)
        .then((i: google.maps.InfoWindow) => i.setZIndex(infoWindow.zIndex));
  }

  open(infoWindow: AgmInfoWindow): Promise<void> {
    return this._infoWindows.get(infoWindow).then((w) => {
      if (infoWindow.hostMarker != null) {
        return this._markerManager.getNativeMarker(infoWindow.hostMarker).then((marker) => {
          return this._mapsWrapper.getNativeMap().then((map) => w.open(map, marker));
        });
      }
      return this._mapsWrapper.getNativeMap().then((map) => w.open(map));
    });
  }

  close(infoWindow: AgmInfoWindow): Promise<void> {
    return this._infoWindows.get(infoWindow).then((w) => w.close());
  }

  setOptions(infoWindow: AgmInfoWindow, options: google.maps.InfoWindowOptions) {
    return this._infoWindows.get(infoWindow).then((i: google.maps.InfoWindow) => i.setOptions(options));
  }

  addInfoWindow(infoWindow: AgmInfoWindow) {
    const options: google.maps.InfoWindowOptions = {
      content: infoWindow.content,
      maxWidth: infoWindow.maxWidth,
      zIndex: infoWindow.zIndex,
      disableAutoPan: infoWindow.disableAutoPan,
    };
    if (typeof infoWindow.latitude === 'number' && typeof infoWindow.longitude === 'number') {
      options.position = {lat: infoWindow.latitude, lng: infoWindow.longitude};
    }
    const infoWindowPromise = this._mapsWrapper.createInfoWindow(options);
    this._infoWindows.set(infoWindow, infoWindowPromise);
  }

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

result-matching ""

    No results matching ""