【发布时间】:2022-06-17 17:30:28
【问题描述】:
我正在使用 Angular 的 Google 地图库 (@angular/google-maps: 13.3.4),并且希望在添加标记时以与标记相同的方式为集群设置动画。到目前为止,这是我的代码:
<google-map height="400px"
width="750px"
[center]="center"
[zoom]="zoom"
>
<map-marker-clusterer [zoomOnClick]="true" [imagePath]="markerClustererImagePath">
<map-marker *ngFor="let markerPosition of markerPositions"
[options]="markerOptions"
[position]="markerPosition"
></map-marker>
</map-marker-clusterer>
</google-map>
<button (click)="addSingleMarker($event)">Add new Marker</button>
<button (click)="addMarkerToCluster($event)">Add new Cluster</button>
组件.ts:
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
center = { lat: 24, lng: 12 };
zoom = 4;
markerPositions = [
{ lat: 24, lng: 12 },
{ lat: 24, lng: 12 },
{ lat: 15, lng: 6 },
];
markerOptions: google.maps.MarkerOptions = {
animation: google.maps.Animation.DROP
};
markerClustererImagePath =
'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m';
public addMarkerToCluster($event: google.maps.MapMouseEvent) {
if ($event.latLng !== null) {
this.markerPositions.push({ lat: 24, lng: 12 });
}
}
public addSingleMarker($event: google.maps.MapMouseEvent) {
if ($event.latLng !== null) {
this.markerPositions.push({ lat: 21, lng: 2 });
}
}
}
如果有人可以帮助我,我会很高兴。
【问题讨论】:
标签: google-maps-markers angular-google-maps