src/directives/map-polyline.ts
Directive that will render plyline to map. Please note that directive must be placed inside map component, otherwise it will never render polyline.
Providers |
{ provide: BaseMapComponent, useExisting: forwardRef(() => MapPolylineDirective) }
|
Selector | map-polyline |
Properties |
|
Methods |
|
Inputs |
Accessors |
constructor(mapsManager: HereMapsManager)
|
||||||
Defined in src/directives/map-polyline.ts:104
|
||||||
Parameters :
|
fillColor
|
Type : |
Defined in src/directives/map-polyline.ts:35
|
lineWidth
|
Type : |
Defined in src/directives/map-polyline.ts:73
|
options
|
|
Defined in src/directives/map-polyline.ts:85
|
strokeColor
|
Type : |
Defined in src/directives/map-polyline.ts:54
|
Public hasMapComponent |
hasMapComponent()
|
Defined in src/directives/map-polyline.ts:120
|
Checks if map is set to directive
Returns :
boolean
|
Public ngOnDestroy |
ngOnDestroy()
|
Defined in src/directives/map-polyline.ts:140
|
Returns :
void
|
Public setMapComponent | ||||||||||||
setMapComponent(component: MapComponent, map: H.Map)
|
||||||||||||
Defined in src/directives/map-polyline.ts:129
|
||||||||||||
Sets heremap to polyline. This is called by map component so you don't need to call it manually.
Parameters :
Returns :
void
|
Private _fillColor |
_fillColor:
|
Type : string
|
Defined in src/directives/map-polyline.ts:23
|
Private _lineWidth |
_lineWidth:
|
Type : number
|
Default value : 4
|
Defined in src/directives/map-polyline.ts:25
|
Private _strokeColor |
_strokeColor:
|
Type : string
|
Defined in src/directives/map-polyline.ts:24
|
Protected mapComponent |
mapComponent:
|
Type : MapComponent
|
Defined in src/directives/map-polyline.ts:21
|
Private polyline |
polyline:
|
Type : H.map.Polyline
|
Defined in src/directives/map-polyline.ts:22
|
fillColor | ||||||
getfillColor()
|
||||||
Defined in src/directives/map-polyline.ts:30
|
||||||
Fill color that should be used when polyline is rendered on map
Returns :
string
|
||||||
setfillColor(color: string)
|
||||||
Defined in src/directives/map-polyline.ts:35
|
||||||
Parameters :
Returns :
void
|
strokeColor | ||||||
getstrokeColor()
|
||||||
Defined in src/directives/map-polyline.ts:49
|
||||||
Stroke color that should be used when polyline is rendered on map
Returns :
string
|
||||||
setstrokeColor(color: string)
|
||||||
Defined in src/directives/map-polyline.ts:54
|
||||||
Parameters :
Returns :
void
|
lineWidth | ||||||
getlineWidth()
|
||||||
Defined in src/directives/map-polyline.ts:68
|
||||||
Gives plyline with
Returns :
number
|
||||||
setlineWidth(lineWidth: number)
|
||||||
Defined in src/directives/map-polyline.ts:73
|
||||||
Parameters :
Returns :
void
|
options | ||||
setoptions(opts)
|
||||
Defined in src/directives/map-polyline.ts:85
|
||||
Parameters :
Returns :
void
|
import {Directive, Input, OnDestroy, forwardRef} from '@angular/core';
import {BaseMapComponent} from './base-map-component';
import {HereMapsManager} from '../services/maps-manager';
import {PolylineOptions} from '../interface/polyline-options';
import { MapComponent } from './map';
/**
* Directive that will render plyline to map. Please note that directive must be placed inside
* map component, otherwise it will never render polyline.
*/
@Directive({
selector: 'map-polyline',
providers: [{provide: BaseMapComponent, useExisting: forwardRef(() => MapPolylineDirective)}]
})
export class MapPolylineDirective extends BaseMapComponent<H.map.Polyline> implements OnDestroy {
protected mapComponent: MapComponent;
private polyline: H.map.Polyline;
private _fillColor: string;
private _strokeColor: string;
private _lineWidth = 4;
/**
* Fill color that should be used when polyline is rendered on map
*/
get fillColor(): string {
return this._fillColor;
}
@Input()
set fillColor(color: string) {
if (this._fillColor !== color) {
this._fillColor = color;
this.proxy.then(p => {
const style = Object.assign({}, p.getStyle());
style.fillColor = color;
p.setStyle(style);
});
}
}
/**
* Stroke color that should be used when polyline is rendered on map
*/
get strokeColor(): string {
return this._strokeColor;
}
@Input()
set strokeColor(color: string) {
if (this._strokeColor !== color) {
this._strokeColor = color;
this.proxy.then(p => {
const style = Object.assign({}, p.getStyle());
style.strokeColor = color;
p.setStyle(style);
});
}
}
/**
* Gives plyline with
*/
get lineWidth(): number {
return this._lineWidth;
}
@Input()
set lineWidth(lineWidth: number) {
if (this._lineWidth !== lineWidth) {
this._lineWidth = lineWidth;
this.proxy.then(p => {
const style = Object.assign({}, p.getStyle());
style.lineWidth = lineWidth;
p.setStyle(style);
});
}
}
@Input()
set options(opts: PolylineOptions) {
this.proxy.then((polyline: H.map.Polyline) => {
const style = {
strokeColor: opts.strokeColor || this.strokeColor,
fillColor: opts.fillColor || this.fillColor,
lineWidth: opts.lineWidth || this.lineWidth
},
strip = new H.geo.Strip();
(opts.path || [])
.forEach(point => {
strip.pushPoint({
lat: point.lat,
lng: point.lng
});
});
polyline.setStrip(strip);
polyline.setStyle(style);
});
}
constructor(mapsManager: HereMapsManager) {
super();
mapsManager
.onApiLoad()
.then(() => {
const strip = new H.geo.Strip();
this.polyline = new H.map.Polyline(strip);
this.proxyResolver(this.polyline);
});
}
/**
* Checks if map is set to directive
*/
public hasMapComponent(): boolean {
return !!this.mapComponent;
}
/**
* Sets heremap to polyline. This is called by map component so you don't need to call it manually.
* @param component map component
* @param map here map instance
*/
public setMapComponent(component: MapComponent, map: H.Map): void {
this.mapComponent = component;
this.proxy
.then((mapObject: H.map.Polyline) =>
setTimeout(() => {
if (mapObject instanceof H.map.Object) {
map.addObject(mapObject);
}
}, this.delay || 0));
}
public ngOnDestroy(): void {
this.proxy
.then(p => {
this.mapComponent
.getMap()
.then((map) => {
map.removeObject(this.polyline);
this.polyline.dispose();
delete this.polyline;
});
});
}
}