Ashley James Brown
Ashley James Brown

Reputation: 119

google maps API - how to NOT load/open infowindow on click if its already open to stop flickering

Simple simple question but cannot find anyway to not do this.

Open any of the google maps api demos that have infowindows. Click on the marker and it opens the infowindow. keep clicking again and again on it quickly and it reloads it which causes a flickering of the infowindow.

Any idea how to state watch or check if its already open to not actually do this. ? Cant find any code in the reference.

google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
});

so some kind of if statement or code that can tell if my window is already open to not

Upvotes: 0

Views: 402

Answers (1)

Ashley James Brown
Ashley James Brown

Reputation: 119

google.maps.InfoWindow.prototype.opened = false;
var infowindow ;
var marker;


google.maps.event.addListener(marker, 'click', function() {
  if (infowindow.opened){
    //do nothing its already open
  }else{
    infowindow.open(map,marker); //open it
    infowindow.opened=true;
  }
});


google.maps.event.addListener(infowindow, 'closeclick', function() {
  infowindow.opened=false; //reset so that when closed it can be reopened again
});

Upvotes: 1

Related Questions