2020-09-04 23:50:05 +08:00
|
|
|
/**
|
|
|
|
* Before you edit these, read the documentation on how these files are compiled:
|
|
|
|
* https://docs.phpvms.net/customize/building-assets
|
|
|
|
*
|
|
|
|
* Edits here don't take place until you compile these assets and then upload them.
|
|
|
|
*/
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
import draw_base_map from './base_map';
|
|
|
|
import { addWMSLayer } from './helpers';
|
|
|
|
import request from '../request';
|
|
|
|
|
|
|
|
import { ACTUAL_ROUTE_COLOR, CIRCLE_COLOR, PLAN_ROUTE_COLOR } from './config';
|
2018-04-07 06:10:45 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
const leaflet = require('leaflet');
|
2018-03-13 06:30:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show some popup text when a feature is clicked on
|
|
|
|
* @param feature
|
|
|
|
* @param layer
|
|
|
|
*/
|
|
|
|
export const onFeaturePointClick = (feature, layer) => {
|
2019-08-30 20:08:00 +08:00
|
|
|
let popup_html = '';
|
|
|
|
if (feature.properties && feature.properties.popup) {
|
|
|
|
popup_html += feature.properties.popup;
|
|
|
|
}
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
layer.bindPopup(popup_html);
|
2018-03-28 07:18:25 +08:00
|
|
|
};
|
2018-03-13 06:30:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show each point as a marker
|
|
|
|
* @param feature
|
|
|
|
* @param latlng
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
export const pointToLayer = (feature, latlng) => leaflet.circleMarker(latlng, {
|
|
|
|
radius: 5,
|
|
|
|
fillColor: CIRCLE_COLOR,
|
|
|
|
color: '#000',
|
|
|
|
weight: 1,
|
|
|
|
opacity: 1,
|
|
|
|
fillOpacity: 0.8,
|
|
|
|
});
|
2018-03-13 06:30:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2019-08-30 20:08:00 +08:00
|
|
|
* @param _opts
|
2018-03-13 06:30:52 +08:00
|
|
|
* @private
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
export default (_opts) => {
|
|
|
|
const opts = Object.assign({
|
|
|
|
route_points: null,
|
|
|
|
planned_route_line: null,
|
|
|
|
actual_route_points: null,
|
|
|
|
actual_route_line: null,
|
|
|
|
render_elem: 'map',
|
|
|
|
live_map: false,
|
|
|
|
aircraft_icon: '/assets/img/acars/aircraft.png',
|
|
|
|
refresh_interval: 10,
|
|
|
|
metar_wms: {
|
|
|
|
url: '',
|
|
|
|
params: {},
|
|
|
|
},
|
|
|
|
}, _opts);
|
|
|
|
|
|
|
|
const aircraftIcon = leaflet.icon({
|
|
|
|
iconUrl: opts.aircraft_icon,
|
|
|
|
iconSize: [42, 42],
|
|
|
|
iconAnchor: [21, 21],
|
|
|
|
});
|
|
|
|
|
|
|
|
const map = draw_base_map(opts);
|
|
|
|
let layerLiveFlight;
|
|
|
|
|
|
|
|
if (opts.metar_wms.url !== '') {
|
|
|
|
addWMSLayer(map, opts.metar_wms);
|
|
|
|
}
|
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
const plannedRouteLayer = new L.Geodesic([], {
|
2019-08-30 20:08:00 +08:00
|
|
|
weight: 4,
|
|
|
|
opacity: 0.9,
|
|
|
|
color: PLAN_ROUTE_COLOR,
|
|
|
|
steps: 50,
|
|
|
|
wrap: false,
|
|
|
|
}).addTo(map);
|
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
plannedRouteLayer.fromGeoJson(opts.planned_route_line);
|
2019-08-30 20:08:00 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
map.fitBounds(plannedRouteLayer.getBounds());
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the route points after
|
|
|
|
if (opts.route_points !== null) {
|
|
|
|
const route_points = leaflet.geoJSON(opts.route_points, {
|
|
|
|
onEachFeature: onFeaturePointClick,
|
|
|
|
pointToLayer,
|
|
|
|
style: {
|
|
|
|
color: PLAN_ROUTE_COLOR,
|
|
|
|
weight: 3,
|
|
|
|
opacity: 0.65,
|
|
|
|
},
|
2018-04-07 06:10:45 +08:00
|
|
|
});
|
2018-03-14 22:07:41 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
route_points.addTo(map);
|
|
|
|
}
|
2018-03-14 22:07:41 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
/**
|
|
|
|
* draw the actual route
|
|
|
|
*/
|
2018-03-14 22:07:41 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
if (opts.actual_route_line !== null && opts.actual_route_line.features.length > 0) {
|
2020-02-09 02:29:34 +08:00
|
|
|
const actualRouteLayer = new L.Geodesic([], {
|
2019-08-30 20:08:00 +08:00
|
|
|
weight: 3,
|
|
|
|
opacity: 0.9,
|
|
|
|
color: ACTUAL_ROUTE_COLOR,
|
|
|
|
steps: 50,
|
|
|
|
wrap: false,
|
2018-04-07 06:10:45 +08:00
|
|
|
}).addTo(map);
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2020-02-09 02:29:34 +08:00
|
|
|
actualRouteLayer.fromGeoJson(opts.actual_route_line);
|
2018-03-13 06:30:52 +08:00
|
|
|
|
|
|
|
try {
|
2019-08-30 20:08:00 +08:00
|
|
|
map.fitBounds(actualRouteLayer.getBounds());
|
2018-03-13 06:30:52 +08:00
|
|
|
} catch (e) {
|
2019-08-30 20:08:00 +08:00
|
|
|
console.log(e);
|
2018-05-02 09:58:05 +08:00
|
|
|
}
|
2019-08-30 20:08:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.actual_route_points !== null && opts.actual_route_points.features.length > 0) {
|
|
|
|
const route_points = leaflet.geoJSON(opts.actual_route_points, {
|
|
|
|
onEachFeature: onFeaturePointClick,
|
|
|
|
pointToLayer,
|
|
|
|
style: {
|
|
|
|
color: ACTUAL_ROUTE_COLOR,
|
|
|
|
weight: 3,
|
|
|
|
opacity: 0.65,
|
|
|
|
},
|
|
|
|
});
|
2018-05-02 09:58:05 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
route_points.addTo(map);
|
|
|
|
}
|
2018-05-02 09:58:05 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
/**
|
2020-02-09 02:29:34 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
2019-08-30 20:08:00 +08:00
|
|
|
const liveFlight = () => {
|
|
|
|
request({ url: opts.pirep_uri }).then((response) => {
|
|
|
|
const routeJson = response.data.data;
|
2020-02-09 02:29:34 +08:00
|
|
|
console.log(routeJson);
|
2019-08-30 20:08:00 +08:00
|
|
|
layerLiveFlight = leaflet.geoJSON(routeJson, {
|
|
|
|
pointToLayer(feature, latlon) {
|
|
|
|
return leaflet.marker(latlon, {
|
|
|
|
icon: aircraftIcon,
|
|
|
|
rotationAngle: feature.properties.heading,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2018-05-02 09:58:05 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
layerLiveFlight.addTo(map);
|
|
|
|
});
|
|
|
|
};
|
2018-03-14 22:07:41 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
setInterval(liveFlight, opts.refresh_interval * 1000);
|
2020-02-09 02:29:34 +08:00
|
|
|
*/
|
2018-03-13 06:30:52 +08:00
|
|
|
};
|