File

src/directives/map-bubble.ts

Description

Renders buble on map. Please note that directive must be placed inside map component, otherwise it will never be rendered.

Metadata

Providers { provide: BaseMapComponent, useExisting: forwardRef(() => MapBubbleDirective) }
Selector map-bubble

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor(_mapsManager: HereMapsManager)
Parameters :
Name Type Optional
_mapsManager HereMapsManager No

Inputs

clickable

If true, the marker receives mouse and touch events. Default value is true.

Type : boolean

contentElement

Rollover text

position

Bubble position

Outputs

click

This event is fired when the marker icon was clicked.

$event Type: EventEmitter<any>

Methods

Private bindEvents
bindEvents(marker: H.ui.InfoBubble)
Parameters :
Name Type Optional
marker H.ui.InfoBubble No
Returns : void
Public hasMapComponent
hasMapComponent()
Returns : boolean
Public setMapComponent
setMapComponent(component: MapComponent, map: H.Map, ui: H.ui.UI)
Parameters :
Name Type Optional
component MapComponent No
map H.Map No
ui H.ui.UI No
Returns : void

Properties

Private _clickable
_clickable:
Default value : true
Protected mapComponent
mapComponent: MapComponent
Type : MapComponent

Accessors

position
setposition(point)

Bubble position

Parameters :
Name Optional
point No
Returns : void
clickable
setclickable(mode: boolean)

If true, the marker receives mouse and touch events. Default value is true.

Parameters :
Name Type Optional
mode boolean No
Returns : void
contentElement
setcontentElement(value)

Rollover text

Parameters :
Name Optional
value No
Returns : void
import {
  Directive,
  Input,
  Output,
  EventEmitter,
  forwardRef
} from '@angular/core';
import { HereMapsManager } from '../services/maps-manager';
import { BaseMapComponent } from './base-map-component';
import { GeoPoint } from '../interface/lat-lng';
import { toLatLng } from '../utils/position';
import { MapComponent } from './map';

/**
 * Renders buble on map. Please note that directive must be placed inside
 * map component, otherwise it will never be rendered.
 */
@Directive({
  selector: 'map-bubble',
  providers: [
    {
      provide: BaseMapComponent,
      useExisting: forwardRef(() => MapBubbleDirective)
    }
  ]
})
export class MapBubbleDirective extends BaseMapComponent<H.ui.InfoBubble> {
  protected mapComponent: MapComponent;
  /*
   * Outputs events
   * **********************************************************
   */

  /**
   * This event is fired when the marker icon was clicked.
   */
  @Output()
  click: EventEmitter<any> = new EventEmitter<any>();

  /*
     * Inputs options
     * **********************************************************
     */
  /**
   * Bubble position
   */
  @Input()
  set position(point: GeoPoint) {
    const position = toLatLng(point);
    this._mapsManager
      .createBubble({ position })
      .then((bubble: H.ui.InfoBubble) => {
        this.bindEvents(bubble);
        this.proxyResolver(bubble);
      });

    this.proxy.then(bubble => {
      bubble.setPosition(toLatLng(point));
    });
  }

  /**
   * If true, the marker receives mouse and touch events.
   * Default value is true.
   */
  @Input()
  set clickable(mode: boolean) {
    // this.proxy.then(marker => marker.setClickable(mode));
    this._clickable = mode;
  }

  /**
   * Rollover text
   */
  @Input()
  set contentElement(value: HTMLElement) {
    this.proxy.then(bubble => bubble.setContent(value));
  }

  private _clickable = true;

  constructor(private _mapsManager: HereMapsManager) {
    super();
  }

  public hasMapComponent(): boolean {
    return !!this.mapComponent;
  }

  public setMapComponent(
    component: MapComponent,
    map: H.Map,
    ui: H.ui.UI
  ): void {
    this.mapComponent = component;
    this.proxy.then((mapObject: H.ui.InfoBubble) =>
      setTimeout(() => {
        if (mapObject instanceof H.ui.InfoBubble) {
          ui.addBubble(mapObject);
        }
      }, this.delay || 0)
    );
  }

  /*
     * Internal logic
     * **********************************************************
     */

  private bindEvents(marker: H.ui.InfoBubble) {
    marker.addEventListener('tap', e => {
      if (this._clickable) {
        this.click.emit(e);
      }
    });
  }
}

result-matching ""

    No results matching ""