Skip to content

Commit

Permalink
Reuse airport intoWindow object
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Dec 24, 2017
1 parent a346f0c commit c850c72
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,16 @@ function plotAirports (airports) {
marker.IATA = airport.IATA
marker.addListener('click', function () {
if (openInfoWindow) openInfoWindow.close()
// eslint-disable-next-line no-undef
const infoWindow = new google.maps.InfoWindow({
content: `
<h3>${airport.name}</h3>
<table class="list">
<tr><th>IATA</th><td>${airport.IATA || 'n/a'}</td></tr>
<tr><th>ICAO</th><td>${airport.ICAO || 'n/a'}</td></tr>
<tr><th>Altitude</th><td>${airport.altitude === null ? 'n/a' : airport.altitude + ' ft'}</td></tr>
</table>
`
})
infoWindow.open(map, marker)
openInfoWindow = infoWindow
else openInfoWindow = new google.maps.InfoWindow() // eslint-disable-line no-undef
openInfoWindow.setContent(`
<h3>${airport.name}</h3>
<table class="list">
<tr><th>IATA</th><td>${airport.IATA || 'n/a'}</td></tr>
<tr><th>ICAO</th><td>${airport.ICAO || 'n/a'}</td></tr>
<tr><th>Altitude</th><td>${airport.altitude === null ? 'n/a' : airport.altitude + ' ft'}</td></tr>
</table>
`)
openInfoWindow.open(map, marker)
})
airportMarkers.push(marker)
})
Expand Down

0 comments on commit c850c72

Please sign in to comment.