3.0 Infowindows – Just one please…

As you may have noticed, in most project sites, you can open as many infowindows at the same time. While at times, this might be a desired behavior, in general, we usually only want to have one infowindow open at a time.

Let’s look at the code that allows you to open multiple windows at the same time. ┬áThe infowindow code is part of the “createMarker” function:

Since the infowindow declaration (line 9 above) is made within the function, a new infowindow instance is created every time a new marker is created. In order to create just “one” infowindow that the function accesses, we need to move the variable declaration outside of this function and into the global space. Then, you can define the content of the infowindow as shown in line 14 below.

Leave a Reply