233 lines
10 KiB
JavaScript
233 lines
10 KiB
JavaScript
/* eslint-disable */
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
var xamel = require('xamel');
|
|
const convert = require('geo-coordinates-parser');
|
|
|
|
const markers = require('./MagneticVertex');
|
|
const TaxiwaySegment = require('./TaxiwaySegment');
|
|
|
|
const parkingSpot = require('./ParkingSpot.js');
|
|
const runwayNode = require('./RunwayNode.js');
|
|
|
|
const store = require('../store');
|
|
|
|
const util = require('util');
|
|
|
|
var $ = require('jquery');
|
|
|
|
var featureLookup = {};
|
|
|
|
exports.addFeature = function (feature) {
|
|
featureLookup[feature.id] = new Array();
|
|
}
|
|
|
|
exports.readGroundnetXML = function (fDir, icao) {
|
|
try {
|
|
layerGroup = L.layerGroup();
|
|
layerGroup.maxId = 0;
|
|
var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.xml');
|
|
|
|
if (f == null || !fs.existsSync(f))
|
|
return;
|
|
|
|
var features = new Array();
|
|
|
|
// map.on("editable:vertex:new", function (event) {
|
|
// log.console("Add vertex " + event);
|
|
// });
|
|
|
|
var xmlGroundnet = fs.readFileSync(f, 'utf8').toString();
|
|
xamel.parse(xmlGroundnet, function (err, xml) {
|
|
console.debug("parsed " + path.basename(f));
|
|
if (err !== null) {
|
|
console.error("Error in " + airline);
|
|
throw err;
|
|
}
|
|
var parkingNodes = xml.find('groundnet/parkingList/Parking');
|
|
console.log("Parking Nodes" + parkingNodes.length);
|
|
|
|
var merged = new Array();
|
|
|
|
var nodesLookup = {};
|
|
|
|
parkingNodes.map(n => {
|
|
var circle = parkingSpot(n, layerGroup);
|
|
nodesLookup[n.attr('index')] = n;
|
|
featureLookup[n.attr('index')] = new Array();
|
|
featureLookup[n.attr('index')].push(circle);
|
|
layerGroup.maxId = Math.max(layerGroup.maxId, Number(n.attr('index')))
|
|
features.push(circle);
|
|
}).sort();
|
|
// Get all nodes into the lookup
|
|
var taxiNodes = xml.find('groundnet/TaxiNodes/node');
|
|
taxiNodes.map(n => {
|
|
//attrs.lat
|
|
//console.log(n.attr('lat') + " " + n.attr('lon'));
|
|
var latlon = convert(n.attr('lat') + " " + n.attr('lon'));
|
|
//console.log(latlon.decimalLatitude);
|
|
|
|
layerGroup.maxId = Math.max(layerGroup.maxId, Number(n.attr('index')))
|
|
nodesLookup[n.attr('index')] = n;
|
|
if (n.attr('isOnRunway') === '1') {
|
|
var rNode = runwayNode(n, layerGroup);
|
|
if(featureLookup[rNode.id] === undefined) {
|
|
featureLookup[rNode.id] = [];
|
|
}
|
|
featureLookup[rNode.id].push(rNode);
|
|
}
|
|
}).sort();
|
|
|
|
|
|
var taxiArcs = xml.find('groundnet/TaxiWaySegments/arc');
|
|
taxiArcs.map(n => {
|
|
var begin = nodesLookup[n.attr('begin')];
|
|
var end = nodesLookup[n.attr('end')];
|
|
if (typeof begin !== 'undefined' && typeof end !== 'undefined') {
|
|
var bidirectional = false;
|
|
if (typeof featureLookup[n.attr('begin')] !== 'undefined') {
|
|
featureLookup[n.attr('begin')].forEach(element => {
|
|
if (element instanceof L.TaxiwaySegment && element.end === n.attr('begin') && element.begin === n.attr('end')) {
|
|
element.bidirectional = true;
|
|
bidirectional = true;
|
|
}
|
|
});
|
|
}
|
|
if (typeof featureLookup[n.attr('end')] !== 'undefined') {
|
|
featureLookup[n.attr('end')].forEach(element => {
|
|
if (element instanceof L.TaxiwaySegment && element.end === n.attr('begin') && element.begin === n.attr('end')) {
|
|
element.bidirectional = true;
|
|
bidirectional = true;
|
|
}
|
|
});
|
|
}
|
|
if (!bidirectional) {
|
|
var beginlatlon = convert(begin.attr('lat') + " " + begin.attr('lon'));
|
|
var endlatlon = convert(end.attr('lat') + " " + end.attr('lon'));
|
|
const polyline = new L.TaxiwaySegment([[beginlatlon.decimalLatitude, beginlatlon.decimalLongitude], [endlatlon.decimalLatitude, endlatlon.decimalLongitude]], {}).addTo(layerGroup);
|
|
$.each( n.attrs, function( key, value ) {
|
|
console.log( key + "\t" + value);
|
|
|
|
if(isNaN(value))
|
|
polyline.options.attributes[ key ] = value;
|
|
else
|
|
polyline.options.attributes[ key ] = Number( value);
|
|
});
|
|
polyline.updateStyle();
|
|
|
|
polyline.begin = begin.attr('index');
|
|
polyline.end = end.attr('index');
|
|
// polyline.enableEdit();
|
|
|
|
// polyline.on('dblclick', function (event) { L.DomEvent.stop; polyline.toggleEdit; });
|
|
polyline.on('click', function (event) {
|
|
console.log("Click : " + event.target);
|
|
store.default.dispatch('setArc', event.target.options.attributes);
|
|
});
|
|
polyline.on('editable:drawing:move', function (event) {
|
|
console.log(event.target);
|
|
if (dragIndex >= 0) {
|
|
follow(dragIndex, event);
|
|
}
|
|
});
|
|
var dragIndex = -1;
|
|
polyline.on('editable:vertex:dragstart', function (event) {
|
|
console.log(event.vertex);
|
|
console.log(event.target);
|
|
if (typeof featureLookup[event.target.begin] !== 'undefined') {
|
|
featureLookup[event.target.begin].forEach(element => {
|
|
if (element instanceof L.ParkingSpot) {
|
|
dragIndex = event.target.begin;
|
|
}
|
|
else if (element instanceof L.TaxiwaySegment) {
|
|
if (element.getLatLngs()[0].equals(event.vertex.getLatLng())) {
|
|
dragIndex = element.begin;
|
|
}
|
|
if (element.getLatLngs()[element.getLatLngs().length - 1].equals(event.vertex.getLatLng())) {
|
|
dragIndex = element.end;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
if (typeof featureLookup[event.target.end] !== 'undefined') {
|
|
featureLookup[event.target.end].forEach(element => {
|
|
if (element instanceof L.ParkingSpot) {
|
|
dragIndex = event.target.end;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
polyline.on('editable:vertex:dragend', function (event) {
|
|
console.log("Dragend : ", event.vertex);
|
|
if (dragIndex > 0) {
|
|
featureLookup[dragIndex].forEach(element => {
|
|
if (element instanceof L.ParkingSpot) {
|
|
//element.setLatLng(event);
|
|
console.log(element);
|
|
}
|
|
});
|
|
}
|
|
dragIndex = -1;
|
|
});
|
|
|
|
|
|
polyline.addTo(layerGroup);
|
|
if (typeof featureLookup[polyline.begin] === 'undefined') {
|
|
featureLookup[polyline.begin] = new Array();
|
|
}
|
|
if (typeof featureLookup[polyline.end] === 'undefined') {
|
|
featureLookup[polyline.end] = new Array();
|
|
}
|
|
featureLookup[polyline.begin].push(polyline);
|
|
featureLookup[polyline.end].push(polyline);
|
|
}
|
|
}
|
|
}).sort();
|
|
|
|
|
|
return layerGroup;
|
|
});
|
|
// var jsonAirports = JSON.parse(geoJSON);
|
|
// return jsonAirports;
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
return layerGroup;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
|
|
follow = function (dragIndex, event) {
|
|
featureLookup[dragIndex].forEach(element => {
|
|
if(element !== event.target){
|
|
if (element instanceof L.RunwayNode) {
|
|
element.setLatLng(event.latlng);
|
|
}
|
|
else if (element instanceof L.ParkingSpot) {
|
|
// element.disableEdit();
|
|
element.setLatLng(event.latlng);
|
|
// element.enableEdit();
|
|
// element.extensions();
|
|
element.updateMiddleMarker();
|
|
element.updateVertexFromDirection();
|
|
}
|
|
else if (element instanceof L.TaxiwaySegment) {
|
|
if (element.begin === dragIndex) {
|
|
element.getLatLngs()[0].update(event.latlng);
|
|
element.setLatLngs(element.getLatLngs());
|
|
element.updateBeginVertex(event.latlng);
|
|
element.updateMiddle();
|
|
}
|
|
if (element.end === dragIndex) {
|
|
element.getLatLngs()[element.getLatLngs().length - 1].update(event.latlng);
|
|
element.setLatLngs(element.getLatLngs());
|
|
element.updateEndVertex(event.latlng);
|
|
element.updateMiddle();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
} |