Skip to content

Commit

Permalink
Hide airports the more you zoom out
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Dec 24, 2017
1 parent 56bceff commit eeb7a92
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const aircraftIndex = {}
const airlineICAOIndex = {}
const airportMarkers = []
const infoPanel = document.getElementById('info')
let map, selectedMarker, planeIcon, currentPosition, openInfoWindow

Expand Down Expand Up @@ -38,6 +39,8 @@ function initMap () {
: new google.maps.LatLng(48.9062802, 2.3598659) // eslint-disable-line no-undef
})

map.addListener('zoom_changed', zoomLevelChanged)

onJQuery(function () {
// eslint-disable-next-line no-undef
$.getJSON('airports', plotAirports)
Expand All @@ -61,6 +64,19 @@ function initMap () {
})
}

function zoomLevelChanged () {
const level = map.getZoom()
airportMarkers.forEach(function (marker) {
let visible = true
if (level >= 6 && level <= 7) {
visible = !!marker.airport.IATA
} else if (level < 6) {
visible = false
}
marker.setVisible(visible)
})
}

function parseAirlines (airlines) {
airlines.forEach(function (airline) {
airlineICAOIndex[airline.ICAO] = airline
Expand All @@ -84,6 +100,7 @@ function plotAirports (airports) {
title: airport.name,
icon: airportIcon
})
marker.airport = airport
// eslint-disable-next-line no-undef
const infoWindow = new google.maps.InfoWindow({
content: `
Expand All @@ -96,6 +113,7 @@ function plotAirports (airports) {
`
})
marker.addListener('click', airportClick.bind(infoWindow, marker))
airportMarkers.push(marker)
})

function airportClick (marker) {
Expand Down

0 comments on commit eeb7a92

Please sign in to comment.