Skip to content

Commit

Permalink
#54 added show bus functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-red-baron committed Jun 19, 2016
1 parent e7f3f4c commit b502836
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions CitizenApplication/app/components/native-map/native-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import {GoogleMap, GoogleMapsEvent, GoogleMapsMarker, GoogleMapsLatLng, GoogleMa
This is Map component for the CitizenApplication.
*/
@Component({
selector: 'native-map',
templateUrl: 'build/components/native-map/map.html'
selector: 'native-map',
templateUrl: 'build/components/native-map/map.html'
})
export class NativeMap implements OnDestroy {
private map;
private mapElement;
private logger: Logger;
private mapElementId;
private map;
private mapElement;
private logger: Logger;
private mapElementId;

constructor(private element: ElementRef, private config: ConfigurationService) {
this.logger = new LoggerFactory().getLogger(this.config.misc.log_level, 'MapComponent', this.config.misc.log_pretty_print);
}
constructor(private element: ElementRef, private config: ConfigurationService) {
this.logger = new LoggerFactory().getLogger(this.config.misc.log_level, 'MapComponent', this.config.misc.log_pretty_print);
}

render() {
// Generate pseudorandom ID of the div, as the Ionic native plugin does not accept the element object,
// but just the div id.
this.mapElementId = 'map' + new Date().getTime();
this.mapElement = this.element.nativeElement.children[0];
this.mapElement.setAttribute('id', this.mapElementId);
let map = new GoogleMap(this.mapElementId);
this.map = map;
this.map.setOptions({
render() {
// Generate pseudorandom ID of the div, as the Ionic native plugin does not accept the element object,
// but just the div id.
this.mapElementId = 'map' + new Date().getTime();
this.mapElement = this.element.nativeElement.children[0];
this.mapElement.setAttribute('id', this.mapElementId);
let map = new GoogleMap(this.mapElementId);
this.map = map;
this.map.setOptions({
'backgroundColor': 'white',
'controls': {
'compass': true,
Expand All @@ -47,9 +47,9 @@ export class NativeMap implements OnDestroy {
});
this.centerCamera();
console.log('successfully loaded map');
}
}

centerCamera() {
centerCamera() {
let options = { timeout: 10000, enableHighAccuracy: true };
Geolocation.getCurrentPosition(options).then((resp) => {
let latitude = resp.coords.latitude;
Expand Down Expand Up @@ -78,12 +78,27 @@ export class NativeMap implements OnDestroy {
};
}

ngOnDestroy() {
this.logger.debug('Removing the map element along with all the children.');
while (this.mapElement.firstChild) {
this.mapElement.removeChild(this.mapElement.firstChild);
/**
* shows the bus position
* @param busX current x-coord of the bus
* @param busY current y-ccord of the bus
*/
showBus(busX, busY ) {
let busLatLng = new GoogleMapsLatLng(busX, busY);
this.map.addMarker({
'position': busLatLng,
'title': 'busposition'
}, function (marker) {
marker.showInfoWindow();
});
}

ngOnDestroy() {
this.logger.debug('Removing the map element along with all the children.');
while (this.mapElement.firstChild) {
this.mapElement.removeChild(this.mapElement.firstChild);
}
}
}

}

0 comments on commit b502836

Please sign in to comment.