agm-marker onMouseOver open agm-info-window

后端 未结 3 407
小蘑菇
小蘑菇 2020-12-19 03:36

I using Angular Google Maps(AGM) componet. I need to open info window on marker mouse hover. How can I retreive the infowindow instance in my function onM

相关标签:
3条回答
  • 2020-12-19 04:25

    At the end I found a solution:

    <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,gm)"
                    >
    
            <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, gm) {
    
            if (gm.lastOpen != null) {
                gm.lastOpen.close();
            }
    
            gm.lastOpen = infoWindow;
    
            infoWindow.open();
        }
    
    0 讨论(0)
  • 2020-12-19 04:25

    In my case, onMouseover() only worked if I set it to

    onMouseOver(infoWindow, gm) {
    
      if (gm.lastOpen && gm.lastOpen.isOpen) {
        gm.lastOpen.close();
      }
    
      gm.lastOpen = infoWindow;
    
      infoWindow.open();
    }
    
    0 讨论(0)
  • 2020-12-19 04:26

    You can add a mouseOut event and create a function to close the 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();
        }
    
    0 讨论(0)
提交回复
热议问题