File

src/directives/map-marker.ts

Description

Holds instance of the heremap marker. Please note that directive must be placed inside map component, otherwise it will never be rendered.

Implements

OnDestroy

Metadata

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

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

delay

Type : number

icon

Icon for the foreground. If a string is provided, it is treated as though it were an Icon with the string as url.

opacity

The marker's opacity between 0.0 and 1.0.

Type : number

position

Marker position

title

Rollover text

Type : string

visible

If true, the marker is visible

Type : boolean

zIndex

Set marker zIndex for displayed on the map

Type : number

Outputs

click

This event is fired when the marker icon was clicked.

$event Type: EventEmitter<any>
dblclick

This event is fired when the marker icon was double clicked.

$event Type: EventEmitter<any>
icon_changed

This event is fired when the marker icon property changes.

$event Type: EventEmitter<any>
position_changed

This event is fired when the marker position property changes.

$event Type: EventEmitter<any>
rightclick

This event is fired for a rightclick on the marker.

$event Type: EventEmitter<any>
title_changed

This event is fired when the marker title property changes.

$event Type: EventEmitter<any>
visible_changed

This event is fired when the marker visible property changes.

$event Type: EventEmitter<any>

Methods

Private bindEvents
bindEvents(marker: H.map.Marker)
Parameters :
Name Type Optional
marker H.map.Marker No
Returns : void
Public hasMapComponent
hasMapComponent()
Returns : boolean
ngOnDestroy
ngOnDestroy()
Returns : void
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)

Marker 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
icon
seticon(value)

Icon for the foreground. If a string is provided, it is treated as though it were an Icon with the string as url.

Parameters :
Name Optional
value No
Returns : void
opacity
setopacity(value: number)

The marker's opacity between 0.0 and 1.0.

Parameters :
Name Type Optional
value number No
Returns : void
title
settitle(value: string)

Rollover text

Parameters :
Name Type Optional
value string No
Returns : void
visible
setvisible(mode: boolean)

If true, the marker is visible

Parameters :
Name Type Optional
mode boolean No
Returns : void
zIndex
setzIndex(value: number)

Set marker zIndex for displayed on the map

Parameters :
Name Type Optional
value number No
Returns : void
setDelay
setsetDelay(value: number)
Parameters :
Name Type Optional
value number No
Returns : void
import {
  Directive,
  Input,
  Output,
  EventEmitter,
  forwardRef,
  OnDestroy
} 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';

/**
 * Holds instance of the heremap marker. Please note that directive must be placed inside
 * map component, otherwise it will never be rendered.
 */
@Directive({
  selector: 'map-marker',
  providers: [
    {
      provide: BaseMapComponent,
      useExisting: forwardRef(() => MapMakerDirective)
    }
  ]
})
export class MapMakerDirective extends BaseMapComponent<H.map.Marker> implements OnDestroy {
  /*
   * Outputs events
   * **********************************************************
   */

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

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

  /**
   * This event is fired for a rightclick on the marker.
   */
  @Output()
  rightclick: EventEmitter<any> = new EventEmitter<any>();

  /**
   * This event is fired when the marker position property changes.
   */
  @Output()
  position_changed: EventEmitter<any> = new EventEmitter<any>();

  /**
   * This event is fired when the marker icon property changes.
   */
  @Output()
  icon_changed: EventEmitter<any> = new EventEmitter<any>();

  /**
   * This event is fired when the marker title property changes.
   */
  @Output()
  title_changed: EventEmitter<any> = new EventEmitter<any>();

  /**
   * This event is fired when the marker visible property changes.
   */
  @Output()
  visible_changed: EventEmitter<any> = new EventEmitter<any>();

  /*
   * Inputs options
   * **********************************************************
   */

  /**
   * Marker position
   */
  @Input()
  set position(point: GeoPoint) {
    const position = toLatLng(point);
    this._mapsManager
      .createMarker({ position })
      .then((marker: H.map.Marker) => {
        this.bindEvents(marker);
        this.proxyResolver(marker);
      });

    this.proxy.then(marker => {
      marker.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;
  }

  /**
   * Icon for the foreground. If a string is provided,
   * it is treated as though it were an Icon with the string as url.
   */
  @Input()
  set icon(value: string | H.map.Icon) {
    this.proxy.then(marker => {
      if (typeof value === 'string') {
        value = new H.map.Icon(value, {
          size: { w: 20, h: 20 },
          crossOrigin: false
        });
      }
      marker.setIcon(value);
    });
  }

  /**
   * The marker's opacity between 0.0 and 1.0.
   */
  @Input()
  set opacity(value: number) {
    // this.proxy.then(marker => marker.setOpacity(value));
  }

  /**
   * Rollover text
   */
  @Input()
  set title(value: string) {
    // this.proxy.then(marker => marker.setTitle(value));
  }

  /**
   * If true, the marker is visible
   */
  @Input()
  set visible(mode: boolean) {
    this.proxy.then(marker => marker.setVisibility(mode));
  }

  /**
   * Set marker zIndex for displayed on the map
   */
  @Input()
  set zIndex(value: number) {
    this.proxy.then(marker => marker.setZIndex(value));
  }

  // @Input()
  // set animation(value: google.maps.Animation) {
  //     //this.proxy.then(marker => marker.setAnimation(<google.maps.Animation>value));
  // }

  @Input('delay')
  set setDelay(value: number) {
    this.delay = value;
  }

  protected mapComponent: MapComponent;

  private _clickable = true;

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

  ngOnDestroy() {
    this.proxy.then(marker => {
      marker.dispose();
      this.mapComponent.getMap().then(map => {
        if (map.getObjects().indexOf(marker) >= 0) {
          map.removeObject(marker);
        }
      });
    });
  }


  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.map.Marker) =>
      setTimeout(() => {
        if (mapObject instanceof H.map.Object) {
          map.addObject(mapObject);
        }
      }, this.delay || 0)
    );
  }

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

  private bindEvents(marker: H.map.Marker) {
    marker.addEventListener('tap', e => {
      if (this._clickable) {
        this.click.emit(e);
      }
    });
    marker.addEventListener('dbltap', e => {
      if (this._clickable) {
        this.dblclick.emit(e);
      }
    });
    // marker.addEventListener('position_changed', e => this.position_changed.emit(e));
    // marker.addEventListener('title_changed', e => this.title_changed.emit(e));
    // marker.addEventListener('icon_changed', e => this.icon_changed.emit(e));
    marker.addEventListener('visibilitychange', e =>
      this.visible_changed.emit(e)
    );
  }
}

result-matching ""

    No results matching ""