File

packages/core/src/lib/services/managers/marker-manager.ts

Index

Properties
Methods

Constructor

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

Methods

addMarker
addMarker(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : void
Async convertAnimation
convertAnimation(uiAnim: | null)
Parameters :
Name Type Optional
uiAnim | null No
Returns : {}
createEventObservable
createEventObservable(eventName: google.maps.MarkerMouseEventNames | google.maps.MarkerChangeOptionEventNames, marker: AgmMarker)
Type parameters :
  • T
Parameters :
Name Type Optional
eventName google.maps.MarkerMouseEventNames | google.maps.MarkerChangeOptionEventNames No
marker AgmMarker No
Returns : Observable<T>
deleteMarker
deleteMarker(markerDirective: AgmMarker)
Parameters :
Name Type Optional
markerDirective AgmMarker No
Returns : Promise<void>
getNativeMarker
getNativeMarker(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<google.maps.Marker>
Async updateAnimation
updateAnimation(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : any
updateClickable
updateClickable(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateDraggable
updateDraggable(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateIcon
updateIcon(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateLabel
updateLabel(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateMarkerPosition
updateMarkerPosition(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateOpacity
updateOpacity(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateTitle
updateTitle(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateVisible
updateVisible(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>
updateZIndex
updateZIndex(marker: AgmMarker)
Parameters :
Name Type Optional
marker AgmMarker No
Returns : Promise<void>

Properties

Protected _markers
Type : Map<AgmMarker | Promise<google.maps.Marker>>
Default value : new Map<AgmMarker, Promise<google.maps.Marker>>()
import { Injectable, NgZone } from '@angular/core';
import { Observable } from 'rxjs';

import { AgmMarker } from './../../directives/marker';

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

@Injectable()
export class MarkerManager {
  protected _markers: Map<AgmMarker, Promise<google.maps.Marker>> =
      new Map<AgmMarker, Promise<google.maps.Marker>>();

  constructor(protected _mapsWrapper: GoogleMapsAPIWrapper, protected _zone: NgZone) {}

  async convertAnimation(uiAnim: keyof typeof google.maps.Animation | null) {
    if (uiAnim === null) {
      return null;
    } else {
      return this._mapsWrapper.getNativeMap().then(() => google.maps.Animation[uiAnim]);
    }
  }

  deleteMarker(markerDirective: AgmMarker): Promise<void> {
    const markerPromise = this._markers.get(markerDirective);
    if (markerPromise == null) {
      // marker already deleted
      return Promise.resolve();
    }
    return markerPromise.then((marker: google.maps.Marker) => {
      return this._zone.run(() => {
        marker.setMap(null);
        this._markers.delete(markerDirective);
      });
    });
  }

  updateMarkerPosition(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then(
        (m: google.maps.Marker) => m.setPosition({lat: marker.latitude, lng: marker.longitude}));
  }

  updateTitle(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setTitle(marker.title));
  }

  updateLabel(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => { m.setLabel(marker.label); });
  }

  updateDraggable(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setDraggable(marker.draggable));
  }

  updateIcon(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setIcon(marker.iconUrl));
  }

  updateOpacity(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setOpacity(marker.opacity));
  }

  updateVisible(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setVisible(marker.visible));
  }

  updateZIndex(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setZIndex(marker.zIndex));
  }

  updateClickable(marker: AgmMarker): Promise<void> {
    return this._markers.get(marker).then((m: google.maps.Marker) => m.setClickable(marker.clickable));
  }

  async updateAnimation(marker: AgmMarker) {
    const m = await this._markers.get(marker);
    m.setAnimation(await this.convertAnimation(marker.animation));
  }

  addMarker(marker: AgmMarker) {
    const markerPromise = new Promise<google.maps.Marker>(async (resolve) =>
     this._mapsWrapper.createMarker({
        position: {lat: marker.latitude, lng: marker.longitude},
        label: marker.label,
        draggable: marker.draggable,
        icon: marker.iconUrl,
        opacity: marker.opacity,
        visible: marker.visible,
        zIndex: marker.zIndex,
        title: marker.title,
        clickable: marker.clickable,
        animation: await this.convertAnimation(marker.animation),
      }).then(resolve));
    this._markers.set(marker, markerPromise);
  }

  getNativeMarker(marker: AgmMarker): Promise<google.maps.Marker> {
    return this._markers.get(marker);
  }

  createEventObservable<T extends (google.maps.MouseEvent | void)>(
      eventName: google.maps.MarkerMouseEventNames | google.maps.MarkerChangeOptionEventNames,
      marker: AgmMarker): Observable<T> {
    return new Observable(observer => {
      this._markers.get(marker).then(m =>
        m.addListener(eventName, e => this._zone.run(() => observer.next(e)))
      );
    });
  }
}

result-matching ""

    No results matching ""