Skip to content

Commit

Permalink
Don't create airport infoWindow until user clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Dec 24, 2017
1 parent 8bdec61 commit a346f0c
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function onAjaxError (jqXHR, textStatus, err) {
function zoomLevelChanged () {
const level = map.getZoom()
airportMarkers.forEach(function (marker) {
const size = airportSize[marker.airport.IATA]
const size = airportSize[marker.IATA]
const threshold = AIRPORT_VISIBILITY_THRESHOLD[level]
marker.setVisible(threshold ? size > threshold : true)
})
Expand Down Expand Up @@ -119,27 +119,25 @@ function plotAirports (airports) {
icon: airportIcon,
visible: visibilityThreshold ? size > visibilityThreshold : true
})
marker.airport = airport
// 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>
`
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
})
marker.addListener('click', airportClick.bind(infoWindow, marker))
airportMarkers.push(marker)
})

function airportClick (marker) {
if (openInfoWindow) openInfoWindow.close()
this.open(map, marker)
openInfoWindow = this
}
}

function plotAircrafts (aircrafts) {
Expand Down

0 comments on commit a346f0c

Please sign in to comment.