我是 Angular 的新手,并且有一个显示全屏谷歌地图的网络应用程序。我想在谷歌地图布局中添加一个“注销”按钮(而不是作为标题)。
我知道使用 javascript Google Maps 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']);
}
}