diff --git a/src/renderer/loaders/groundnet_loader.js b/src/renderer/loaders/groundnet_loader.js index 45cd4ab..5a068c3 100644 --- a/src/renderer/loaders/groundnet_loader.js +++ b/src/renderer/loaders/groundnet_loader.js @@ -56,6 +56,7 @@ exports.readGroundnetXML = function (fDir, icao, f) { try { store.default.dispatch('setGroundnetLoaded', false); var layerGroup = L.layerGroup(); + layerGroup.minId = 9999999999; layerGroup.maxId = 0; if (f == null || (!fs.existsSync(f) )) @@ -113,6 +114,7 @@ exports.readGroundnetXML = function (fDir, icao, f) { nodesLookup[n.attr('index')] = n; featureLookup[n.attr('index')] = new Array(); featureLookup[n.attr('index')].push(circle); + layerGroup.minId = Math.min(layerGroup.minId, Number(n.attr('index'))) layerGroup.maxId = Math.max(layerGroup.maxId, Number(n.attr('index'))) features.push(circle); }).sort(); @@ -139,7 +141,9 @@ exports.readGroundnetXML = function (fDir, icao, f) { } //console.log(latlon.decimalLatitude); + layerGroup.minId = Math.min(layerGroup.minId, Number(n.attr('index'))) layerGroup.maxId = Math.max(layerGroup.maxId, Number(n.attr('index'))) + console.debug(`Min Id : ${layerGroup.minId} Max Id : ${layerGroup.maxId} `); nodesLookup[n.attr('index')] = n; if (n.attr('isOnRunway') === '1') { diff --git a/src/renderer/loaders/groundnet_writer.js b/src/renderer/loaders/groundnet_writer.js index bb8c9f2..5cb17fa 100644 --- a/src/renderer/loaders/groundnet_writer.js +++ b/src/renderer/loaders/groundnet_writer.js @@ -57,6 +57,12 @@ function walkPushbackRoute (index, walkedNodes, pushBackNodes) { }); } +/** + * + * @param {*} fDir The directory + * @param {*} icao + * @param {*} featureList + */ exports.writeGroundnetXML = function (fDir, icao, featureList) { try { @@ -91,6 +97,8 @@ exports.writeGroundnetXML = function (fDir, icao, featureList) { var parkings = featureList.map(mapParkings).filter(n => n); var runwayNodes = featureList.map(mapRunwayNodes).filter(n => n); var holdNodes = featureList.map(mapHoldPoint).filter(n => n); + + holdNodes.forEach(n => { pushBackNodeLookup[n['@index']] = n; }); @@ -189,6 +197,51 @@ exports.writeGroundnetXML = function (fDir, icao, featureList) { var unicomList = store.default.state.Frequencies.items.filter(f => f.type === 'UNICOM').map(mapFrequency); + + var gapStart = -1; + var gapEnd = -1; + + do { + gapStart = -1; + gapEnd = -1; + var allIds = parkings.map(n => Number(n['@index'])) + .concat(uniqueNodes.map(n => Number(n['@index']))) + .sort((a, b) => a - b); + + allIds.forEach((element, index, array) => { + if (index > 0 && array[index-1] + 1 != element && gapStart == -1 ) { + gapStart = array[index-1]; + gapEnd = element; + } + }); + var gap = gapEnd - gapStart -1; + + parkings = parkings.map(n => { + if (n['@index']>gapStart) { + n['@index'] = String(n['@index'] - gap); + } + if (n['@pushbackRoute']>gapStart) { + n['@pushbackRoute'] = String(n['@pushbackRoute'] - gap); + } + return n; + }); + uniqueNodes = uniqueNodes.map(n => { + if (n['@index']>gapStart) { + n['@index'] = String(n['@index'] - gap); + } + return n; + }); + arcList = arcList.map(n => { + if (n['@begin']>gapStart) { + n['@begin'] = String(n['@begin'] - gap); + } + if (n['@end']>gapStart) { + n['@end'] = String(n['@end'] - gap); + } + return n; + }); + } while( gapStart > 0 && gapEnd > 0); + var xmlObj = { groundnet: { version: 1, fgaversion: version, name: name, 'frequencies': { APPROACH: approachList, DEPARTURE: departureList, AWOS: awosList, CLEARANCE: clearanceList, GROUND: groundList, TOWER: towerList, UNICOM: unicomList }, parkingList: { Parking: parkings }, TaxiNodes: { node: uniqueNodes }, TaxiWaySegments: { arc: arcList } } };