ng2-heremaps
Version:
Here Maps for Angular 6
188 lines • 5.67 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
import { Directive, Input, forwardRef } from '@angular/core';
import { BaseMapComponent } from './base-map-component';
import { HereMapsManager } from '../services/maps-manager';
/**
* Directive that will render plyline to map. Please note that directive must be placed inside
* map component, otherwise it will never render polyline.
*/
export class MapPolylineDirective extends BaseMapComponent {
/**
* @param {?} mapsManager
*/
constructor(mapsManager) {
super();
this._lineWidth = 4;
mapsManager
.onApiLoad()
.then(() => {
const /** @type {?} */ strip = new H.geo.Strip();
this.polyline = new H.map.Polyline(strip);
this.proxyResolver(this.polyline);
});
}
/**
* Fill color that should be used when polyline is rendered on map
* @return {?}
*/
get fillColor() {
return this._fillColor;
}
/**
* @param {?} color
* @return {?}
*/
set fillColor(color) {
if (this._fillColor !== color) {
this._fillColor = color;
this.proxy.then(p => {
const /** @type {?} */ style = Object.assign({}, p.getStyle());
style.fillColor = color;
p.setStyle(style);
});
}
}
/**
* Stroke color that should be used when polyline is rendered on map
* @return {?}
*/
get strokeColor() {
return this._strokeColor;
}
/**
* @param {?} color
* @return {?}
*/
set strokeColor(color) {
if (this._strokeColor !== color) {
this._strokeColor = color;
this.proxy.then(p => {
const /** @type {?} */ style = Object.assign({}, p.getStyle());
style.strokeColor = color;
p.setStyle(style);
});
}
}
/**
* Gives plyline with
* @return {?}
*/
get lineWidth() {
return this._lineWidth;
}
/**
* @param {?} lineWidth
* @return {?}
*/
set lineWidth(lineWidth) {
if (this._lineWidth !== lineWidth) {
this._lineWidth = lineWidth;
this.proxy.then(p => {
const /** @type {?} */ style = Object.assign({}, p.getStyle());
style.lineWidth = lineWidth;
p.setStyle(style);
});
}
}
/**
* @param {?} opts
* @return {?}
*/
set options(opts) {
this.proxy.then((polyline) => {
const /** @type {?} */ style = {
strokeColor: opts.strokeColor || this.strokeColor,
fillColor: opts.fillColor || this.fillColor,
lineWidth: opts.lineWidth || this.lineWidth
}, /** @type {?} */
strip = new H.geo.Strip();
(opts.path || [])
.forEach(point => {
strip.pushPoint({
lat: point.lat,
lng: point.lng
});
});
polyline.setStrip(strip);
polyline.setStyle(style);
});
}
/**
* Checks if map is set to directive
* @return {?}
*/
hasMapComponent() {
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
* @return {?}
*/
setMapComponent(component, map) {
this.mapComponent = component;
this.proxy
.then((mapObject) => setTimeout(() => {
if (mapObject instanceof H.map.Object) {
map.addObject(mapObject);
}
}, this.delay || 0));
}
/**
* @return {?}
*/
ngOnDestroy() {
this.proxy
.then(p => {
this.mapComponent
.getMap()
.then((map) => {
map.removeObject(this.polyline);
this.polyline.dispose();
delete this.polyline;
});
});
}
}
MapPolylineDirective.decorators = [
{ type: Directive, args: [{
selector: 'map-polyline',
providers: [{ provide: BaseMapComponent, useExisting: forwardRef(() => MapPolylineDirective) }]
},] }
];
/** @nocollapse */
MapPolylineDirective.ctorParameters = () => [
{ type: HereMapsManager, },
];
MapPolylineDirective.propDecorators = {
"fillColor": [{ type: Input },],
"strokeColor": [{ type: Input },],
"lineWidth": [{ type: Input },],
"options": [{ type: Input },],
};
function MapPolylineDirective_tsickle_Closure_declarations() {
/** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */
MapPolylineDirective.decorators;
/**
* @nocollapse
* @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>}
*/
MapPolylineDirective.ctorParameters;
/** @type {!Object<string,!Array<{type: !Function, args: (undefined|!Array<?>)}>>} */
MapPolylineDirective.propDecorators;
/** @type {?} */
MapPolylineDirective.prototype.mapComponent;
/** @type {?} */
MapPolylineDirective.prototype.polyline;
/** @type {?} */
MapPolylineDirective.prototype._fillColor;
/** @type {?} */
MapPolylineDirective.prototype._strokeColor;
/** @type {?} */
MapPolylineDirective.prototype._lineWidth;
}
//# sourceMappingURL=map-polyline.js.map