agm-marker onMouseOver打开agm-info-window

时间:2017-10-03 09:44:03

标签: angular google-maps-api-3

我使用Angular Google Maps(AGM)组件。 我需要在标记鼠标悬停上打开信息窗口。 如何在我的函数infowindow中检索onMouseOver实例以打开它?

<agm-map [fitBounds]="latlngBounds" [zoom]="15">
    <agm-marker *ngFor="let m of markers; let i = index"
                [latitude]="m.geoCode.latitude"
                [longitude]="m.geoCode.longitude"
                (mouseOver)="onMouseOver(m)"
                >

        <agm-info-window [disableAutoPan]="false">

            <div>
                <a (click)="onClickInfoView({id:m.id})" class="btn btn-attention pull-right">test<i class="fa fa-angle-double-right"></i></a>
            </div>

        </agm-info-window>


    </agm-marker>

</agm-map>



onMouseOver(data) {
        ???? /* how to open here the info window?
    }

3 个答案:

答案 0 :(得分:9)

最后我找到了解决方案:

select2

答案 1 :(得分:1)

您可以添加mouseOut事件并创建一个函数来关闭InfoWindow onMouseOut

    <agm-map #gm [fitBounds]="latlngBounds" [zoom]="15">
    <agm-marker *ngFor="let m of markers; let i = index"
                [latitude]="m.geoCode.latitude"
                [longitude]="m.geoCode.longitude"
                (mouseOver)="onMouseOver(infoWindow, $event)" 
                (mouseOut)="onMouseOut(infoWindow, $event)"
                >

        <agm-info-window [disableAutoPan]="false" #infoWindow>

            <div>
                {{m.name}}
                {{m.rating}}
            </div>
            <div>
                <a (click)="onClickInfoView({id:m.id})" class="btn btn-attention pull-right">Daje <i class="fa fa-angle-double-right"></i></a>
            </div>

        </agm-info-window>


    </agm-marker>

</agm-map>


onMouseOver(infoWindow, $event: MouseEvent) {
        infoWindow.open();
    }

onMouseOut(infoWindow, $event: MouseEvent) {
        infoWindow.close();
    }

答案 2 :(得分:0)

在我的情况下,onMouseover()只有在我将其设置为

时才有效
onMouseOver(infoWindow, gm) {

  if (gm.lastOpen && gm.lastOpen.isOpen) {
    gm.lastOpen.close();
  }

  gm.lastOpen = infoWindow;

  infoWindow.open();
}