From 53afd1ee779611682fba7b326038cda9a55ef4e1 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 19 Apr 2024 13:32:17 +0200 Subject: [PATCH] adds dots for navigation flights too --- index.html | 107 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/index.html b/index.html index c0a65f5..e5fc7c7 100644 --- a/index.html +++ b/index.html @@ -82,7 +82,10 @@ function _updateMap(csvData, airportsData) { const lines = csvData.split('\n'); - const features = lines.map(line => { + + const features_nav = new Array(); + const features_local = new Array(); + for(const line of lines) { const [from, to] = line.split(','); const fromAirport = airportsData[from]; @@ -97,45 +100,80 @@ const toLatitude = parseFloat(toAirport.latitude); // if from == to, draw a point - var geometry; if(fromAirport == toAirport) { - geometry = { - type: 'Point', - coordinates: [fromLongitude, fromLatitude] - }; + features_local.push( { + type: 'Feature', + properties: { + from, + to + }, + geometry: { + type: 'Point', + coordinates: [fromLongitude, fromLatitude] + } + } ); } else { - geometry = { - type: 'LineString', - coordinates: [ - [fromLongitude, fromLatitude], - [toLongitude, toLatitude] - ] - }; + features_nav.push( { + type: 'Feature', + properties: { + from, + to + }, + geometry: { + type: 'LineString', + coordinates: [ + [fromLongitude, fromLatitude], + [toLongitude, toLatitude] + ] + } + } ); + + // Add a point for each airport + features_nav.push( { + type: 'Feature', + properties: { + name: fromAirport.name + }, + geometry: { + type: 'Point', + coordinates: [fromLongitude, fromLatitude] + } + } ); + + features_nav.push( { + type: 'Feature', + properties: { + name: toAirport.name + }, + geometry: { + type: 'Point', + coordinates: [toLongitude, toLatitude] + } + } ); } + } - return { - type: 'Feature', - properties: { - from, - to - }, - geometry: geometry - }; - }); - - map.addSource('routes', { + map.addSource('nav', { type: 'geojson', data: { type: 'FeatureCollection', - features + features: features_nav + } + }); + + map.addSource('local', { + type: 'geojson', + data: { + type: 'FeatureCollection', + features: features_local } }); map.addLayer({ - id: 'routes', + id: 'nav_lines', type: 'line', - source: 'routes', + source: 'nav', layout: { 'line-join': 'round', 'line-cap': 'round' @@ -147,9 +185,20 @@ }); map.addLayer({ - id: 'points', + id: 'nav_points', type: 'circle', - source: 'routes', + source: 'nav', + paint: { + 'circle-radius': 5, + 'circle-color': '#ce42f5' + }, + filter: ['==', '$type', 'Point'] + }); + + map.addLayer({ + id: 'local_points', + type: 'circle', + source: 'local', paint: { 'circle-radius': 5, 'circle-color': '#f00'