Compare commits

...
3 changed files with 90 additions and 25 deletions
+14 -2
View File
@@ -58,12 +58,17 @@ class SearchController extends Controller
{ {
$q = request('q', ''); $q = request('q', '');
$len = strlen($q); $len = strlen($q);
$includeInactive = request()->boolean('include_inactive'); $showClosed = request()->boolean('show_closed');
$showNoCode = request()->boolean('show_no_code');
if ($len < 3) return []; if ($len < 3) return [];
return Airport::with('region.country') return Airport::with('region.country')
->when(!$includeInactive, fn($query) => $query->where('active', true)) ->when(!$showClosed, fn($query) => $query->where('active', true))
->when(!$showNoCode, fn($query) => $query->where(function ($sub) {
$sub->whereNotNull('iata_code')
->orWhereNotNull('icao_code');
}))
->when($len === 3, fn($query) => $query->where('iata_code', 'ilike', $q)) ->when($len === 3, fn($query) => $query->where('iata_code', 'ilike', $q))
->when($len >= 4, fn($query) => $query->where(function ($sub) use ($q, $len) { ->when($len >= 4, fn($query) => $query->where(function ($sub) use ($q, $len) {
$sub->when($len === 4, fn($s) => $s->where('icao_code', 'ilike', $q)) $sub->when($len === 4, fn($s) => $s->where('icao_code', 'ilike', $q))
@@ -75,6 +80,13 @@ class SearchController extends Controller
WHEN active THEN 0 WHEN active THEN 0
ELSE 1 ELSE 1
END END
")
->orderByRaw("
CASE
WHEN iata_code IS NOT NULL AND icao_code IS NOT NULL THEN 0
WHEN iata_code IS NOT NULL OR icao_code IS NOT NULL THEN 1
ELSE 2
END
") ")
->orderByRaw(" ->orderByRaw("
CASE CASE
@@ -12,10 +12,14 @@ const model = defineModel<{ value: number, title: string, country_code: string }
const airportOptions = ref(props.prefilledOptions ?? []) const airportOptions = ref(props.prefilledOptions ?? [])
const autocompleteRef = ref<any>(null) const autocompleteRef = ref<any>(null)
const includeInactive = ref(true) const showClosed = ref(false)
const showNoCode = ref(false)
const lastQuery = ref('') const lastQuery = ref('')
const menuOpen = ref(false)
const onFocus = () => { const onFocus = () => {
menuOpen.value = true
nextTick(() => { nextTick(() => {
const input = autocompleteRef.value?.$el?.querySelector('input') const input = autocompleteRef.value?.$el?.querySelector('input')
input?.select() input?.select()
@@ -35,14 +39,15 @@ const searchAirports = async (query: string) => {
const { data } = await axios.get('/search/airports', { const { data } = await axios.get('/search/airports', {
params: { params: {
q: query, q: query,
include_inactive: includeInactive.value ? 1 : undefined, show_closed: showClosed.value ? 1 : undefined,
show_no_code: showNoCode.value ? 1 : undefined,
}, },
}) })
airportOptions.value = data airportOptions.value = data
} }
// Re-run the last search when the checkbox is toggled, so results update immediately // Re-run the last search when either checkbox is toggled, so results update immediately
watch(includeInactive, () => { watch([showClosed, showNoCode], () => {
if (lastQuery.value) searchAirports(lastQuery.value) if (lastQuery.value) searchAirports(lastQuery.value)
}) })
</script> </script>
@@ -51,6 +56,7 @@ watch(includeInactive, () => {
<v-autocomplete <v-autocomplete
ref="autocompleteRef" ref="autocompleteRef"
v-model="model" v-model="model"
v-model:menu="menuOpen"
:label="label ?? 'Airport'" :label="label ?? 'Airport'"
:items="airportOptions" :items="airportOptions"
:error-messages="errorMessages" :error-messages="errorMessages"
@@ -62,6 +68,7 @@ watch(includeInactive, () => {
clearable clearable
hide-no-data hide-no-data
return-object return-object
autocomplete="off"
:custom-filter="() => true" :custom-filter="() => true"
> >
<template #prepend-inner> <template #prepend-inner>
@@ -69,6 +76,27 @@ watch(includeInactive, () => {
<span v-if="model" :class="`fi fi-${model.country_code}`"></span> <span v-if="model" :class="`fi fi-${model.country_code}`"></span>
</span> </span>
</template> </template>
<template #prepend-item>
<div class="px-4 py-1 d-flex align-center" style="gap: 16px;" @mousedown.prevent>
<v-checkbox
v-model="showClosed"
label="Show Closed Airports"
density="compact"
hide-details
style="flex: none; transform: scale(0.65); transform-origin: left center;"
/>
<v-checkbox
v-model="showNoCode"
label="Show Airports with No Code"
density="compact"
hide-details
style="flex: none; transform: scale(0.65); transform-origin: left center;"
/>
</div>
<v-divider class="mt-1" />
</template>
<template #item="{ item, props: itemProps }"> <template #item="{ item, props: itemProps }">
<v-list-item v-bind="itemProps"> <v-list-item v-bind="itemProps">
<template #prepend> <template #prepend>
@@ -370,10 +370,34 @@ export default defineComponent({
link.click() link.click()
} }
function loopPoints(origin: LngLat, radiusDeg = 0.2, steps = 48): LngLat[] {
const [lng, lat] = origin
// Widen the longitude radius to compensate for mercator distortion at this latitude
const lngRadius = radiusDeg / Math.max(Math.cos(lat * Math.PI / 180), 0.15)
// Center the loop above the origin so the airport point sits at the bottom of the loop
const centerLat = lat + radiusDeg
const points: LngLat[] = []
for (let i = 0; i <= steps; i++) {
const theta = (i / steps) * Math.PI * 2
points.push([
lng + Math.sin(theta) * lngRadius,
centerLat - radiusDeg * Math.cos(theta),
])
}
return points // first and last point === origin, at the bottom of the loop
}
const getArc = (flight: Flight): LngLat[] => { const getArc = (flight: Flight): LngLat[] => {
const key = routeKey(flight.departure_airport, flight.arrival_airport) const key = routeKey(flight.departure_airport, flight.arrival_airport)
if (!arcCache.has(key)) { if (!arcCache.has(key)) {
arcCache.set(key, greatCirclePoints( const isSameAirport = flight.departure_airport.id === flight.arrival_airport.id
arcCache.set(key, isSameAirport
? loopPoints([flight.departure_airport.longitude_deg, flight.departure_airport.latitude_deg])
: greatCirclePoints(
[flight.departure_airport.longitude_deg, flight.departure_airport.latitude_deg], [flight.departure_airport.longitude_deg, flight.departure_airport.latitude_deg],
[flight.arrival_airport.longitude_deg, flight.arrival_airport.latitude_deg], [flight.arrival_airport.longitude_deg, flight.arrival_airport.latitude_deg],
)) ))
@@ -666,8 +690,10 @@ export default defineComponent({
? { top: 20, bottom: 20, left: 55, right: 55 } ? { top: 20, bottom: 20, left: 55, right: 55 }
: { top: 60, bottom: 60, left: 60, right: 60 } : { top: 60, bottom: 60, left: 60, right: 60 }
const lngs = props.flights.flatMap(f => [f.departure_airport.longitude_deg, f.arrival_airport.longitude_deg]) // Use full arc/loop geometry, not just endpoints, so loops aren't clipped
const lats = props.flights.flatMap(f => [f.departure_airport.latitude_deg, f.arrival_airport.latitude_deg]) const allPoints = props.flights.flatMap(getArc)
const lngs = allPoints.map(p => p[0])
const lats = allPoints.map(p => p[1])
const minLat = Math.min(...lats) const minLat = Math.min(...lats)
const maxLat = Math.max(...lats) const maxLat = Math.max(...lats)
@@ -689,7 +715,6 @@ export default defineComponent({
} }
map!.fitBounds([[minLng, minLat], [maxLng, maxLat]], { padding, duration: 0 }) map!.fitBounds([[minLng, minLat], [maxLng, maxLat]], { padding, duration: 0 })
} }
// ── Map init ────────────────────────────────────────────────────────── // ── Map init ──────────────────────────────────────────────────────────
const initMap = (): void => { const initMap = (): void => {