Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/directives/directions-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Input, Directive, SimpleChanges, OnChanges, OnDestroy } from '@angular/core';
import { Input, Directive, SimpleChanges, OnChanges, OnDestroy, Output, EventEmitter } from '@angular/core';

import { BaseMapDirective } from './base-map-directive';
import { NguiMapComponent } from '../components/ngui-map.component';
Expand All @@ -9,7 +9,7 @@ const INPUTS = [
'polylineOptions', 'preserveViewport', 'routeIndex', 'suppressBicyclingLayer',
'suppressInfoWindows', 'suppressMarkers', 'suppressPolylines'
];
const OUTPUTS = ['directions_changed'];
const OUTPUTS = ['directions_changed', 'directions_result'];

@Directive({
selector: 'ngui-map > directions-renderer',
Expand All @@ -19,6 +19,8 @@ const OUTPUTS = ['directions_changed'];
export class DirectionsRenderer extends BaseMapDirective implements OnChanges, OnDestroy {
// tslint:disable-next-line
@Input('directions-request') directionsRequest: google.maps.DirectionsRequest;
@Output('directionsFailed') directionsFailed: EventEmitter<string> = new EventEmitter();
@Output('directions_result') directionsResult: EventEmitter<string> = new EventEmitter();

directionsService: google.maps.DirectionsService;
directionsRenderer: google.maps.DirectionsRenderer;
Expand All @@ -44,7 +46,7 @@ export class DirectionsRenderer extends BaseMapDirective implements OnChanges, O

this.directionsRenderer.setMap(this.nguiMapComponent.map);

// set google events listeners and emidirectionsRenderer to this outputs listeners
// set google events listeners and emit directionsRenderer to this outputs listeners
this.showDirections(this.directionsRequest);

this.nguiMap.setObjectEvents(this.outputs, this, 'directionsRenderer');
Expand All @@ -53,7 +55,6 @@ export class DirectionsRenderer extends BaseMapDirective implements OnChanges, O
this.initialized$.emit(this.directionsRenderer);
}


ngOnChanges(changes: SimpleChanges) {
let newOptions = {};
for (let key in changes) {
Expand All @@ -77,7 +78,9 @@ export class DirectionsRenderer extends BaseMapDirective implements OnChanges, O

if (status === google.maps.DirectionsStatus.OK) {
this.directionsRenderer.setDirections(response);
this.directionsResult.emit(response);
} else {
this.directionsFailed.emit(status);
console.error('Directions request failed due to ' + status);
}
}
Expand Down