Check if infowindow is opened Google Maps v3

前端 未结 5 902
小鲜肉
小鲜肉 2020-12-28 12:16

Please, I need a help.

I want to check if my infowindow is opened.

For example:

if (infowindow.isOpened)
{
   doSomething()
}
5条回答
  •  北海茫月
    2020-12-28 12:58

    You can simply set key and value for infoWindow: infoWindow.set('closed', true);

    example:

    const infoWindow = new google.maps.InfoWindow({
        content: 'foo',
        position: {
            lat: some_number,
            lng: some_number
        }
    });
    
    infoWindow.set('closed', true);
    
    // Clicking on polyline for this example
    // Can be marker too
    polyline.addListener(
        'click',
        () => {
            if (infoWindow.get('closed')) {
                infoWindow.open(map);
                infoWindow.set('closed', false);
            } else {
                infoWindow.close();
                infoWindow.set('closed', true);
            }
        }
    );
    

提交回复
热议问题