import { GoogleMapsAPIWrapper } from '@agm/core'; import { Component,Input } from '@angular/core'; @Component({ selector: 'core-map',styleUrls: [ './map.component.scss' ],templateUrl: './map.component.html',}) export class MapComponent { constructor( public gMaps: GoogleMapsAPIWrapper ) {} public markerClicked = (markerObj) => { this.gMaps.setCenter({ lat: markerObj.latitude,lng: markerObj.longitude }); console.log('clicked',markerObj,{ lat: markerObj.latitude,lng: markerObj.longitude }); } } console output: Object {lat: 42.31277,lng: -91.24892}
也试过panTo同样的结果.
也许它是在Christopher发布他的解决方案后添加的,但是agm-map有一个mapReady事件,它返回可用于访问setCenter()的原始地图对象.
原文链接:https://www.f2er.com/angularjs/143892.htmlimport { Component,}) export class MapComponent { protected map: any; constructor() {} protected mapReady(map) { this.map = map; } public markerClicked = (markerObj) => { if (this.map) this.map.setCenter({ lat: markerObj.latitude,lng: markerObj.longitude }); } }
<agm-map (mapReady)="mapReady($event)"></agm-map>