// const geolib = require('geolib'); const leaflet = require('leaflet'); const rivets = require('rivets'); import draw_base_map from './base_map' import { ACTUAL_ROUTE_COLOR } from './config' /** * Render the live map * @param opts * @private */ export default (opts) => { opts = Object.assign({ center: [29.98139, -95.33374], zoom: 5, update_uri: '/api/acars', pirep_uri: '/api/pireps/{id}', pirep_link_uri: '/pireps/{id}', positions: null, render_elem: 'map', aircraft_icon: '/assets/img/acars/aircraft.png', units: 'nmi', }, opts); const map = draw_base_map(opts); const aircraftIcon = leaflet.icon({ iconUrl: opts.aircraft_icon, iconSize: [42, 42], iconAnchor: [21, 21], }); /** * Hold the markers * @type {{}} */ let markers_list = {}; let pannedToCenter = false; let layerFlights = null; let layerSelFlight = null; let layerSelFlightFeature = null; let layerSelFlightLayer = null; let layerSelArr = null; let layerSelDep = null; /** * Controller for two-way bindings * @type {{focusMarker: focusMarker}} */ const mapController = { /** * Focus on a specific marker * @param e * @param model */ focusMarker: (e, model) => { if(!(model.pirep.id in markers_list)) { console.log('marker not found in list'); return; } const marker = markers_list[model.pirep.id]; onFlightClick(marker[0], marker[1]); }, }; const r_map_view = rivets.bind($('#map-info-box'), {pirep: {}, controller: mapController}); const r_table_view = rivets.bind($('#live_flights'), {pireps: [], controller: mapController}); /** * When a flight is clicked on, show the path, etc for that flight * @param feature * @param layer */ const onFlightClick = (feature, layer) => { const pirep_uri = opts.pirep_uri.replace('{id}', feature.properties.pirep_id); const geojson_uri = opts.pirep_uri.replace('{id}', feature.properties.pirep_id) + "/acars/geojson"; const pirep_info = $.ajax({ url: pirep_uri, dataType: 'json', error: console.log }); const flight_route = $.ajax({ url: geojson_uri, dataType: 'json', error: console.log }); // Load up the PIREP info $.when(flight_route).done((rte) => { if (layerSelFlight !== null) { map.removeLayer(layerSelFlight); //map.removeLayer(layerSelArr); //map.removeLayer(layerSelDep); } layerSelFlight = leaflet.geodesic([], { weight: 5, opacity: 0.9, color: ACTUAL_ROUTE_COLOR, wrap: false, }).addTo(map); layerSelFlight.geoJson(rte.line); layerSelFlightFeature = feature; layerSelFlightLayer = layer; /*const dptIcon = leaflet.divIcon({ html: '