我是Angular中的新成員,並且有一個顯示全屏Google地圖的Web應用程序。 我想添加一個「註銷」按鈕到谷歌地圖佈局(不是標題)。將按鈕添加到Google地圖中Angular2
我知道使用JavaScript谷歌地圖API,可以像:
var Logout = document.getElementById('Logout');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(Logout);
但隨着AGM - Angular Google Maps,我怎麼沒發現。
現在我有:
map.component.html
<button id="Logout" [(ngModel)]="logoutButton" class="toggle-button controls button" (click)="logout()">Logout</button>
<agm-map [latitude]="lat" [longitude]="lng" [zoom]=12 [mapTypeControl]="true" (boundsChange)="centerChanged($event)" (idle)="loadParkings()" >
<agm-marker *ngFor="let park of parkings" [latitude]="park.location[0]" [longitude]="park.location[1]"></agm-marker>
</agm-map>
map.component.ts
import {GoogleMapsAPIWrapper} from '@agm/core';
declare var google: any;
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
lat: number;
lng: number;
map: any;
logoutButton: any;
constructor(
public mapApi: GoogleMapsAPIWrapper) {}
ngOnInit(): void {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
});
} else {
this.lat = 47.2275654;
this.lng = -1.3849729;
}
}
logout() {
this.authenficationService.logout();
this.router.navigate(['/login']);
}
}