小编all*_*ces的帖子

在Google Maps Angular2中添加按钮

我是Angular的新手,并且有一个可显示全屏Google地图的网络应用。我想在Google地图布局中添加一个“注销”按钮(而不是标题)。

我知道使用javascript Google Maps Api,这可能像:

var Logout = document.getElementById('Logout');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(Logout);
Run Code Online (Sandbox Code Playgroud)

但是,使用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>
Run Code Online (Sandbox Code Playgroud)

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 …
Run Code Online (Sandbox Code Playgroud)

google-maps typescript angular2-google-maps angular

3
推荐指数
1
解决办法
4377
查看次数