ng2-heremaps
Version:
Here Maps for Angular 6
384 lines • 12.5 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
import * as tslib_1 from "tslib";
import { Directive, Input, Output, EventEmitter, forwardRef } from '@angular/core';
import { HereMapsManager } from '../services/maps-manager';
import { BaseMapComponent } from './base-map-component';
import { toLatLng } from '../utils/position';
/**
* Renders directions on heremap. Please note that directive must be placed inside
* map component, otherwise it will never be rendered.
*/
var MapDirectionsDirective = /** @class */ (function (_super) {
tslib_1.__extends(MapDirectionsDirective, _super);
function MapDirectionsDirective(_mapsManager) {
var _this = _super.call(this) || this;
_this._mapsManager = _mapsManager;
/**
* This event is fired when the directions route changes.
*/
_this.directions_changed = new EventEmitter();
/**
* By default, the input map is centered and zoomed to the bounding box of this set of directions.
* If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.
*/
_this.preserveViewport = true;
_this._intermediatePoints = [];
_this._mapsManager.onApiLoad().then(function () {
var /** @type {?} */ lineString = new H.geo.LineString([
44.09,
-116.9,
3000,
44.082305,
-116.776059,
2000
]);
var /** @type {?} */ route = new H.map.Polyline(lineString);
_this.proxyResolver(route);
});
return _this;
}
Object.defineProperty(MapDirectionsDirective.prototype, "route", {
get: /**
* @return {?}
*/
function () {
return this._route;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (this._route !== value) {
this._route = value;
this.tryShowRoute();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MapDirectionsDirective.prototype, "origin", {
get: /**
* @return {?}
*/
function () {
return this._origin;
},
set: /**
* Origin of directions
* @param {?} value can be google.maps.LatLngLiteral or Coordinates or {latitude: number, longitude: number}
* @return {?}
*/
function (value) {
if (this._origin !== value) {
this._origin = value;
this.tryShowRoute();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MapDirectionsDirective.prototype, "destination", {
get: /**
* @return {?}
*/
function () {
return this._destination;
},
set: /**
* Destination of directions
* @param {?} value can be google.maps.LatLngLiteral or Coordinates or {latitude: number, longitude: number}
* @return {?}
*/
function (value) {
if (this._destination !== value) {
this._destination = value;
this.tryShowRoute();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MapDirectionsDirective.prototype, "intermediatePoints", {
get: /**
* @return {?}
*/
function () {
return this._intermediatePoints;
},
set: /**
* Destination of directions
* @param {?} value can be google.maps.LatLngLiteral or Coordinates or {latitude: number, longitude: number}
* @return {?}
*/
function (value) {
if (this._intermediatePoints !== value) {
this._intermediatePoints = value;
this.tryShowRoute();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MapDirectionsDirective.prototype, "lineWidth", {
get: /**
* @return {?}
*/
function () {
return this._lineWidth;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
var _this = this;
if (this._lineWidth !== value) {
this._lineWidth = value;
this.proxy.then(function (route) {
var /** @type {?} */ style = route.getStyle();
style = new H.map.SpatialStyle();
style.lineWidth = _this._lineWidth;
route.setStyle(style);
});
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MapDirectionsDirective.prototype, "strokeColor", {
get: /**
* @return {?}
*/
function () {
return this._strokeColor;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (this._strokeColor !== value) {
this._strokeColor = value;
this.proxy.then(function (route) {
var /** @type {?} */ style = route.getStyle();
style = new H.map.SpatialStyle();
style.strokeColor = value;
route.setStyle(style);
});
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MapDirectionsDirective.prototype, "fillColor", {
get: /**
* @return {?}
*/
function () {
return this._fillColor;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (this._fillColor !== value) {
this._fillColor = value;
this.proxy.then(function (route) {
var /** @type {?} */ style = route.getStyle();
style = new H.map.SpatialStyle();
style.fillColor = value;
route.setStyle(style);
});
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
MapDirectionsDirective.prototype.hasMapComponent = /**
* @return {?}
*/
function () {
return !!this.mapComponent;
};
/**
* @param {?} component
* @param {?} map
* @param {?} ui
* @return {?}
*/
MapDirectionsDirective.prototype.setMapComponent = /**
* @param {?} component
* @param {?} map
* @param {?} ui
* @return {?}
*/
function (component, map, ui) {
var _this = this;
this.mapComponent = component;
this.proxy.then(function (mapObject) {
return setTimeout(function () {
if (mapObject instanceof H.map.Object) {
map.addObject(mapObject);
}
}, _this.delay || 0);
});
};
/**
* @return {?}
*/
MapDirectionsDirective.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
var _this = this;
this.mapComponent.getMap().then(function (map) {
_this.proxy.then(function (polyline) {
polyline.dispose();
});
});
};
/**
* @return {?}
*/
MapDirectionsDirective.prototype.tryShowRoute = /**
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ route = this._route || [];
if (route instanceof Array && route.length > 0) {
this.renderRoute(route);
}
else if (this.origin && this.destination) {
this.renderRoute([]);
this._mapsManager
.getDirections(toLatLng(this.origin), toLatLng(this.destination), this.intermediatePoints || [])
.then(function (r) {
if (r && r.response && r.response.route) {
var /** @type {?} */ newRoute = r.response.route[0].shape.map(function (str) {
var /** @type {?} */ parts = str.split(',');
return { lat: parseFloat(parts[0]), lng: parseFloat(parts[1]) };
});
_this.renderRoute(newRoute || []);
}
else {
_this.renderRoute([]);
}
})
.catch(function (e) {
_this.renderRoute([]);
});
}
else {
this.renderRoute([]);
}
};
/**
* @param {?} route
* @return {?}
*/
MapDirectionsDirective.prototype.renderRoute = /**
* @param {?} route
* @return {?}
*/
function (route) {
this.proxy.then(function (polyline) {
if (route instanceof Array && route.length > 0) {
var /** @type {?} */ lineString_1 = new H.geo.LineString([]);
route.forEach(function (point) {
lineString_1.pushPoint(toLatLng(point));
});
polyline.setGeometry(lineString_1);
polyline.setVisibility(route.length > 0);
}
else {
polyline.setVisibility(false);
return;
}
});
};
/**
* @return {?}
*/
MapDirectionsDirective.prototype.bindEvents = /**
* @return {?}
*/
function () {
// this.proxy.then()
// directions.addListener('directions_changed', (e) => this.directions_changed.emit(e));
};
MapDirectionsDirective.decorators = [
{ type: Directive, args: [{
selector: 'map-directions',
providers: [
{
provide: BaseMapComponent,
useExisting: forwardRef(function () { return MapDirectionsDirective; })
}
]
},] }
];
/** @nocollapse */
MapDirectionsDirective.ctorParameters = function () { return [
{ type: HereMapsManager, },
]; };
MapDirectionsDirective.propDecorators = {
"route": [{ type: Input },],
"origin": [{ type: Input },],
"destination": [{ type: Input },],
"intermediatePoints": [{ type: Input },],
"directions_changed": [{ type: Output },],
"preserveViewport": [{ type: Input },],
};
return MapDirectionsDirective;
}(BaseMapComponent));
export { MapDirectionsDirective };
function MapDirectionsDirective_tsickle_Closure_declarations() {
/** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */
MapDirectionsDirective.decorators;
/**
* @nocollapse
* @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>}
*/
MapDirectionsDirective.ctorParameters;
/** @type {!Object<string,!Array<{type: !Function, args: (undefined|!Array<?>)}>>} */
MapDirectionsDirective.propDecorators;
/** @type {?} */
MapDirectionsDirective.prototype.mapComponent;
/**
* This event is fired when the directions route changes.
* @type {?}
*/
MapDirectionsDirective.prototype.directions_changed;
/**
* By default, the input map is centered and zoomed to the bounding box of this set of directions.
* If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.
* @type {?}
*/
MapDirectionsDirective.prototype.preserveViewport;
/** @type {?} */
MapDirectionsDirective.prototype._origin;
/** @type {?} */
MapDirectionsDirective.prototype._destination;
/** @type {?} */
MapDirectionsDirective.prototype._intermediatePoints;
/** @type {?} */
MapDirectionsDirective.prototype._lineWidth;
/** @type {?} */
MapDirectionsDirective.prototype._strokeColor;
/** @type {?} */
MapDirectionsDirective.prototype._fillColor;
/** @type {?} */
MapDirectionsDirective.prototype._route;
/** @type {?} */
MapDirectionsDirective.prototype._mapsManager;
}
//# sourceMappingURL=map-directions.js.map