Saving
This commit is contained in:
parent
b9d3908416
commit
756791206a
@ -5,12 +5,15 @@
|
||||
</template>
|
||||
|
||||
<script lang="js">
|
||||
/* eslint-disable */
|
||||
import {LMap, LMarker} from 'vue2-leaflet'
|
||||
import L from 'leaflet'
|
||||
import LEdit from 'leaflet-editable/src/Leaflet.Editable.js'
|
||||
import {readGroundnetXML, addFeature} from '../loaders/groundnet_loader'
|
||||
import {extendTaxiSegment} from '../loaders/TaxiwaySegmentExtender'
|
||||
import {writeGroundnetXML} from '../loaders/groundnet_writer'
|
||||
import L2 from 'leaflet-textpath'
|
||||
|
||||
// import {LSymbol} from 'leaflet-polylinedecorator'
|
||||
|
||||
export default {
|
||||
@ -40,11 +43,16 @@
|
||||
this.groundnetLayerGroup.removeFrom(this.$parent.mapObject)
|
||||
}
|
||||
this.icao = icao
|
||||
this.groundnetLayerGroup = readGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, icao)
|
||||
this.groundnetLayerGroup = readGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, icao, false)
|
||||
if (this.groundnetLayerGroup === undefined) {
|
||||
console.console.error('ICAO not loaded ' + icao)
|
||||
return
|
||||
}
|
||||
this.groundnetLayerGroup.eachLayer(l => {
|
||||
if (l instanceof L.TaxiwaySegment) {
|
||||
l.addListeners()
|
||||
}
|
||||
})
|
||||
/*
|
||||
this.groundnetLayerGroup.eachLayer(l => {
|
||||
if (l instanceof L.TaxiwaySegment) {
|
||||
@ -89,8 +97,11 @@
|
||||
},
|
||||
enableEdit () {
|
||||
this.editable = true
|
||||
this.featureLookup = [];
|
||||
this.groundnetLayerGroup.eachLayer(l => {
|
||||
l.enableEdit()
|
||||
|
||||
l.featureLookup = this.featureLookup;
|
||||
if (typeof l.extensions === 'function') {
|
||||
l.extensions()
|
||||
}
|
||||
@ -98,6 +109,7 @@
|
||||
l.bringToFront()
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
disableEdit () {
|
||||
this.editable = false
|
||||
@ -113,9 +125,48 @@
|
||||
drawPolyline () {
|
||||
var polyLine = this.$parent.mapObject.editTools.startPolyline()
|
||||
polyLine.addTo(this.groundnetLayerGroup)
|
||||
polyLine.on('editable:drawing:end', event => {
|
||||
polyLine.groundnetLayerGroup = this.groundnetLayerGroup;
|
||||
|
||||
polyLine.on('editable:vertex:new', event => {
|
||||
console.log(event)
|
||||
let closest = this.closestLayerSnap(event.latlng, 10)
|
||||
if (closest) {
|
||||
event.latlng.__vertex.glueindex = closest.vertex.glueindex;
|
||||
event.latlng.__vertex.setLatLng(closest.vertex.latlng);
|
||||
console.log(closest)
|
||||
}
|
||||
else{
|
||||
event.latlng.__vertex.glueindex = ++this.groundnetLayerGroup.maxId;
|
||||
this.featureLookup[event.latlng.__vertex.glueindex] = [];
|
||||
}
|
||||
})
|
||||
polyLine.on('editable:drawing:end', event => {
|
||||
event.target.featureLookup = this.featureLookup;
|
||||
extendTaxiSegment(event.target);
|
||||
event.target.addListeners()
|
||||
console.log(event)
|
||||
event.target.addTo(this.groundnetLayerGroup)
|
||||
})
|
||||
},
|
||||
closestLayerSnap (eventLatlng, snap) {
|
||||
var layers = []
|
||||
this.groundnetLayerGroup.eachLayer((layer) => {
|
||||
if (layer instanceof L.Polyline) {
|
||||
console.log(layer._latlngs)
|
||||
layer._latlngs.forEach(latlng => {
|
||||
if (latlng.__vertex) {
|
||||
let distance = latlng.distanceTo(eventLatlng)
|
||||
if (distance > 0 && distance < snap) {
|
||||
layers.push({d: latlng.distanceTo(eventLatlng), l: layer, vertex: latlng.__vertex})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
layers.sort((l1, l2) => l1.d - l2.d)
|
||||
if (layers.length > 0) {
|
||||
return layers[0]
|
||||
}
|
||||
},
|
||||
drawParking () {
|
||||
this.$parent.mapObject.on('click', this.addParking)
|
||||
@ -148,7 +199,7 @@
|
||||
xml.push(l)
|
||||
})
|
||||
writeGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, this.icao, xml)
|
||||
}
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
edit: function () {
|
||||
|
@ -88,7 +88,7 @@ L.ParkingSpot = L.Circle.extend({
|
||||
console.log("Move : ", event);
|
||||
// Is it the edit vertex (Middle) moving?
|
||||
if(event.target.editor._resizeLatLng.__vertex._icon !== event.sourceTarget._element){
|
||||
follow(event.target.id, event);
|
||||
this.follow(event.target.id, event);
|
||||
event.target.updateVertexFromDirection();
|
||||
}
|
||||
else if(event.target.editor._resizeLatLng.__vertex._icon === event.sourceTarget._element) {
|
||||
@ -114,6 +114,45 @@ L.ParkingSpot = L.Circle.extend({
|
||||
},
|
||||
extensions: function () {
|
||||
this.createDirection();
|
||||
if (typeof this.featureLookup[this.id] === 'undefined') {
|
||||
this.featureLookup[this.id] = [];
|
||||
}
|
||||
this.featureLookup[this.id].push(this);
|
||||
},
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
follow (dragIndex, event) {
|
||||
this.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
_getLatRadius: function () {
|
||||
|
@ -28,7 +28,7 @@ var runwayNode = function (n, layerGroup) {
|
||||
iconAnchor: [15, 42]
|
||||
});
|
||||
const node = new L.RunwayNode([latlon.decimalLatitude, latlon.decimalLongitude], { icon: icon });
|
||||
node.id = n.attr('index');
|
||||
node.glueindex = n.attr('index');
|
||||
node.addTo(layerGroup);
|
||||
node.addListeners();
|
||||
return node;
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* eslint-disable */
|
||||
var L = require('leaflet');
|
||||
|
||||
|
||||
L.TaxiwaySegment = L.Polyline.extend({
|
||||
options: {
|
||||
id: 'Custom data!',
|
||||
@ -29,6 +30,86 @@ L.TaxiwaySegment = L.Polyline.extend({
|
||||
}
|
||||
});
|
||||
},
|
||||
extensions: function () {
|
||||
this._latlngs[0].__vertex.glueindex = this.begin;
|
||||
this._latlngs.slice(-1)[0].__vertex.glueindex = this.end;
|
||||
if (typeof this.featureLookup[this.begin] === 'undefined') {
|
||||
this.featureLookup[this.begin] = new Array();
|
||||
}
|
||||
if (typeof this.featureLookup[this.end] === 'undefined') {
|
||||
this.featureLookup[this.end] = new Array();
|
||||
}
|
||||
this.featureLookup[this.begin].push(this);
|
||||
this.featureLookup[this.end].push(this);
|
||||
},
|
||||
addListeners: function () {
|
||||
this.on('click', function (event) {
|
||||
console.log("Click : " + event.target);
|
||||
store.default.dispatch('setArc', event.target.options.attributes);
|
||||
});
|
||||
this.on('editable:drawing:move', function (event) {
|
||||
console.log(event.target);
|
||||
if (dragIndex >= 0) {
|
||||
this.follow(dragIndex, event);
|
||||
}
|
||||
});
|
||||
var dragIndex = -1;
|
||||
this.on('editable:vertex:dragstart', function (event) {
|
||||
console.log("Event Target : ", event.target);
|
||||
console.log("Middle Marker : ", event.vertex == event.vertex.middleMarker);
|
||||
console.log("Middle Marker : ", event.vertex.glueindex == undefined);
|
||||
if(event.vertex.glueindex == undefined)
|
||||
return;
|
||||
dragIndex = event.vertex.glueindex;
|
||||
});
|
||||
this.on('editable:vertex:dragend', function (event) {
|
||||
console.log("Dragend : ", event.vertex);
|
||||
if (dragIndex > 0) {
|
||||
this.featureLookup[dragIndex].forEach(element => {
|
||||
if (element instanceof L.ParkingSpot) {
|
||||
//element.setLatLng(event);
|
||||
console.log(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
dragIndex = -1;
|
||||
});
|
||||
},
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
follow (dragIndex, event) {
|
||||
this.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
updateStyle() {
|
||||
var style = {};
|
||||
|
117
src/renderer/loaders/TaxiwaySegmentExtender.js
Normal file
117
src/renderer/loaders/TaxiwaySegmentExtender.js
Normal file
@ -0,0 +1,117 @@
|
||||
/* eslint-disable */
|
||||
var L = require('leaflet');
|
||||
|
||||
exports.extendTaxiSegment = function (taxiwaySegment) {
|
||||
taxiwaySegment.__proto__.begin;
|
||||
taxiwaySegment.__proto__.end;
|
||||
taxiwaySegment.__proto__.bidirectional;
|
||||
taxiwaySegment.__proto__.updateBeginVertex = function (latlng) {
|
||||
if (this._latlngs[0].__vertex) {
|
||||
this._latlngs[0].__vertex.setLatLng(latlng);
|
||||
}
|
||||
};
|
||||
taxiwaySegment.__proto__.updateEndVertex = function (latlng) {
|
||||
if(this._latlngs[1].__vertex){
|
||||
this._latlngs[1].__vertex.setLatLng(latlng);
|
||||
}
|
||||
};
|
||||
|
||||
taxiwaySegment.__proto__.updateMiddle = function () {
|
||||
this._latlngs.forEach(element => {
|
||||
if(element.__vertex.middleMarker){
|
||||
element.__vertex.middleMarker.updateLatLng();
|
||||
}
|
||||
});
|
||||
};
|
||||
taxiwaySegment.__proto__.extensions = function () {
|
||||
this._latlngs[0].__vertex.glueindex = this.begin;
|
||||
this._latlngs.slice(-1)[0].__vertex.glueindex = this.end;
|
||||
if (typeof this.featureLookup[this.begin] === 'undefined') {
|
||||
this.featureLookup[this.begin] = new Array();
|
||||
}
|
||||
if (typeof this.featureLookup[this.end] === 'undefined') {
|
||||
this.featureLookup[this.end] = new Array();
|
||||
}
|
||||
this.featureLookup[this.begin].push(this);
|
||||
this.featureLookup[this.end].push(this);
|
||||
};
|
||||
taxiwaySegment.__proto__.addListeners = function () {
|
||||
this.on('click', function (event) {
|
||||
console.log("Click : " + event.target);
|
||||
store.default.dispatch('setArc', event.target.options.attributes);
|
||||
});
|
||||
this.on('editable:drawing:move', function (event) {
|
||||
console.log(event.target);
|
||||
if (dragIndex >= 0) {
|
||||
this.follow(dragIndex, event);
|
||||
}
|
||||
});
|
||||
var dragIndex = -1;
|
||||
this.on('editable:vertex:dragstart', function (event) {
|
||||
console.log("Event Target : ", event.target);
|
||||
console.log("Middle Marker : ", event.vertex == event.vertex.middleMarker);
|
||||
console.log("Middle Marker : ", event.vertex.glueindex == undefined);
|
||||
if(event.vertex.glueindex == undefined)
|
||||
return;
|
||||
dragIndex = event.vertex.glueindex;
|
||||
});
|
||||
this.on('editable:vertex:dragend', function (event) {
|
||||
console.log("Dragend : ", event.vertex);
|
||||
if (dragIndex > 0) {
|
||||
this.featureLookup[dragIndex].forEach(element => {
|
||||
if (element instanceof L.ParkingSpot) {
|
||||
//element.setLatLng(event);
|
||||
console.log(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
dragIndex = -1;
|
||||
});
|
||||
};
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
taxiwaySegment.__proto__.follow = function (dragIndex, event) {
|
||||
this.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
taxiwaySegment.__proto__.updateStyle = function() {
|
||||
var style = {};
|
||||
if (this.options.attributes.isPushBackRoute) {
|
||||
style.color = 'magenta';
|
||||
}
|
||||
this.setStyle(style);
|
||||
if (!this.bidirectional) {
|
||||
this.setText(' ► ', {repeat: true, attributes: {fill: 'red', size: 20}})
|
||||
}
|
||||
};
|
||||
};
|
@ -22,14 +22,18 @@ exports.addFeature = function (feature) {
|
||||
featureLookup[feature.id] = new Array();
|
||||
}
|
||||
|
||||
exports.readGroundnetXML = function (fDir, icao) {
|
||||
exports.readGroundnetXML = function (fDir, icao, force) {
|
||||
try {
|
||||
layerGroup = L.layerGroup();
|
||||
layerGroup.maxId = 0;
|
||||
var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.xml');
|
||||
layerGroup.maxId = 0;
|
||||
var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.xml');
|
||||
var fNew = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.new.xml');
|
||||
|
||||
if (f == null || !fs.existsSync(f))
|
||||
return;
|
||||
if(fNew != null && fs.existsSync(fNew) && !force) {
|
||||
f = fNew;
|
||||
}
|
||||
|
||||
var features = new Array();
|
||||
|
||||
@ -120,66 +124,16 @@ exports.readGroundnetXML = function (fDir, icao) {
|
||||
// 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;
|
||||
});
|
||||
|
||||
|
||||
if(featureLookup[n.attr('begin')] == undefined) {
|
||||
featureLookup[n.attr('begin')] = [];
|
||||
}
|
||||
if(featureLookup[n.attr('end')] == undefined) {
|
||||
featureLookup[n.attr('end')] = [];
|
||||
}
|
||||
featureLookup[n.attr('begin')].push(polyline);
|
||||
featureLookup[n.attr('end')].push(polyline);
|
||||
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();
|
||||
@ -193,41 +147,4 @@ exports.readGroundnetXML = function (fDir, icao) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
@ -14,10 +14,10 @@ const util = require('util');
|
||||
const mathjs = require('mathjs');
|
||||
|
||||
var builder = require('xmlbuilder');
|
||||
|
||||
|
||||
|
||||
exports.writeGroundnetXML = function (fDir, icao, featureList) {
|
||||
try {
|
||||
try {
|
||||
var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.new.xml');
|
||||
|
||||
if (f == null)
|
||||
@ -26,109 +26,163 @@ exports.writeGroundnetXML = function (fDir, icao, featureList) {
|
||||
console.log(featureList);
|
||||
|
||||
var parkings = featureList.map(mapParkings).filter(n => n);
|
||||
|
||||
var runwayNodes = featureList.map(mapRunwayNodes).filter(n => n);
|
||||
|
||||
var nodes = [];
|
||||
var arcList = [];
|
||||
|
||||
var featureLookup = [];
|
||||
// Loaded segments
|
||||
featureList.filter(o => o instanceof L.TaxiwaySegment).filter(n => n).forEach(element => {
|
||||
var begin = mapBeginNode(element);
|
||||
nodes[begin['@index']] = begin;
|
||||
var end = mapEndNode(element);
|
||||
nodes[end['@index']] = end;
|
||||
});
|
||||
runwayNodes.forEach(element => {
|
||||
if (nodes[element['@index']] != undefined) {
|
||||
nodes[element['@index']]['@isOnRunway'] = "1";
|
||||
} else {
|
||||
nodes[element['@index']] = element;
|
||||
}
|
||||
});
|
||||
// New segments
|
||||
featureList.filter(o => o instanceof L.Polyline).filter(n => n).forEach(element => {
|
||||
// element._latlngs.forEach(latlng => { nodes[latlng.__vertex.glueindex] = mapVertexNode(latlng) });
|
||||
var startIndex = -1;
|
||||
element._latlngs.forEach(latlng => {
|
||||
if (latlng.__vertex !== undefined && latlng.__vertex.glueindex !== undefined) {
|
||||
nodes[latlng.__vertex.glueindex] = mapVertexNode(latlng);
|
||||
if (startIndex > 0) {
|
||||
if (featureLookup[startIndex] == undefined) {
|
||||
featureLookup[startIndex] = [];
|
||||
}
|
||||
if (featureLookup[latlng.__vertex.glueindex] == undefined) {
|
||||
featureLookup[latlng.__vertex.glueindex] = [];
|
||||
}
|
||||
arc = { '@begin': startIndex, '@end': String(latlng.__vertex.glueindex) };
|
||||
arcList.push(arc);
|
||||
featureLookup[startIndex][latlng.__vertex.glueindex] = arc;
|
||||
arc = { '@begin': String(latlng.__vertex.glueindex), '@end': startIndex };
|
||||
arcList.push(arc);
|
||||
featureLookup[latlng.__vertex.glueindex][startIndex] = arc;
|
||||
}
|
||||
startIndex = latlng.__vertex.glueindex;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// delete the parkings
|
||||
parkings.forEach( n => {
|
||||
parkings.forEach(n => {
|
||||
nodes[n['@index']] = null;
|
||||
} );
|
||||
});
|
||||
nodes = nodes.filter(n => n);
|
||||
|
||||
nodes.sort((p, p2) => {return p['@index']- p2['@index'] });
|
||||
var uniqueNodes = nodes.filter( (v, i, a) => a.indexOf(v) === i );
|
||||
nodes.sort((p, p2) => { return p['@index'] - p2['@index'] });
|
||||
var uniqueNodes = nodes.filter((v, i, a) => a.indexOf(v) === i);
|
||||
|
||||
var maxId = uniqueNodes.slice(-1)[0]['@index'];
|
||||
|
||||
var arcList = [];
|
||||
/*
|
||||
featureList.filter(o => o instanceof L.TaxiwaySegment).filter(n => n).forEach(element => {
|
||||
|
||||
if (element.getLatLngs().length > 2) {
|
||||
let middlePoints = element.getLatLngs().slice(1,-1);
|
||||
let middlePoints = element.getLatLngs().slice(1, -1);
|
||||
let startIndex = element.begin;
|
||||
middlePoints.forEach(latlng => {
|
||||
uniqueNodes.push({'@index': String(++maxId), '@lat': convertLat(latlng), '@lon': convertLon(latlng)});
|
||||
arc = {'@begin': startIndex, '@end': String(maxId)};
|
||||
uniqueNodes.push({ '@index': String(++maxId), '@lat': convertLat(latlng), '@lon': convertLon(latlng) });
|
||||
arc = { '@begin': startIndex, '@end': String(maxId) };
|
||||
arcList.push(arc);
|
||||
arc = {'@begin': String(maxId), '@end': startIndex};
|
||||
arc = { '@begin': String(maxId), '@end': startIndex };
|
||||
arcList.push(arc);
|
||||
startIndex = maxId;
|
||||
});
|
||||
arc = {'@begin': String(startIndex), '@end': element.end};
|
||||
arc = { '@begin': String(startIndex), '@end': element.end };
|
||||
arcList.push(arc);
|
||||
arc = {'@begin': element.end, '@end': String(startIndex)};
|
||||
arc = { '@begin': element.end, '@end': String(startIndex) };
|
||||
arcList.push(arc);
|
||||
console.log('We have a edited line');
|
||||
console.log('We have a edited line');
|
||||
}
|
||||
else {
|
||||
arc = {'@begin': element.begin, '@end': element.end };
|
||||
arc = { '@begin': element.begin, '@end': element.end };
|
||||
arcList.push(arc);
|
||||
if (element.bidirectional) {
|
||||
arc = {'@begin': element.end, '@end': element.begin };
|
||||
arcList.push(arc);
|
||||
}
|
||||
arc = { '@begin': element.end, '@end': element.begin };
|
||||
arcList.push(arc);
|
||||
}
|
||||
}
|
||||
// <arc begin="0" end="161" isPushBackRoute="1" name="" />
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
var xmlObj = {groundnet: {version:1, parkingList:{ Parking: parkings }, TaxiNodes: { node: uniqueNodes}, TaxiWaySegments: { arc: arcList}}};
|
||||
var xmlObj = { groundnet: { version: 1, parkingList: { Parking: parkings }, TaxiNodes: { node: uniqueNodes }, TaxiWaySegments: { arc: arcList } } };
|
||||
|
||||
xmlString = builder.create(xmlObj).end({ pretty: true});
|
||||
fs.writeFileSync(f,xmlString);
|
||||
xmlString = builder.create(xmlObj).end({ pretty: true });
|
||||
fs.writeFileSync(f, xmlString);
|
||||
console.log(xmlString);
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
return layerGroup;
|
||||
}
|
||||
|
||||
var mapParkings = function( o ) {
|
||||
var mapParkings = function (o) {
|
||||
console.log(o);
|
||||
if (o instanceof L.ParkingSpot) {
|
||||
var lat = convertLat(o.getLatLng());
|
||||
var lon = convertLon(o.getLatLng());
|
||||
// <Parking index="0" type="gate" name="GA_Parking" lat="S9 25.739923" lon="E160 2.927602" heading="67" radius="44" airlineCodes="" />
|
||||
return {'@index': String(o['id']), '@type': o.options.attributes.type, '@name': o.options.attributes.name, '@lat': lat, '@lon': lon, '@heading': Number(o.options.attributes.heading), '@radius': String(o.options.radius)};
|
||||
return { '@index': String(o['id']), '@type': o.options.attributes.type, '@name': o.options.attributes.name, '@lat': lat, '@lon': lon, '@heading': Number(o.options.attributes.heading), '@radius': String(o.options.radius) };
|
||||
}
|
||||
}
|
||||
|
||||
var mapBeginNode = function( o ) {
|
||||
if (o instanceof L.TaxiwaySegment) {
|
||||
var mapRunwayNodes = function (o) {
|
||||
console.log(o);
|
||||
if (o instanceof L.RunwayNode) {
|
||||
return { '@index': String(o['glueindex']), '@lat': convertLat(o._latlng), '@lon': convertLon(o._latlng), '@isOnRunway': '1' };
|
||||
}
|
||||
}
|
||||
|
||||
var mapBeginNode = function (o) {
|
||||
if (o instanceof L.TaxiwaySegment) {
|
||||
console.log(o);
|
||||
// <Parking index="0" type="gate" name="GA_Parking" lat="S9 25.739923" lon="E160 2.927602" heading="67" radius="44" airlineCodes="" />
|
||||
return {'@index': String(o['begin']), '@lat': convertLat(o._latlngs[0]), '@lon': convertLon(o._latlngs[0])};
|
||||
return { '@index': String(o['begin']), '@lat': convertLat(o._latlngs[0]), '@lon': convertLon(o._latlngs[0]), '@isOnRunway': '0' };
|
||||
}
|
||||
}
|
||||
|
||||
var mapEndNode = function( o ) {
|
||||
if (o instanceof L.TaxiwaySegment) {
|
||||
var mapEndNode = function (o) {
|
||||
if (o instanceof L.TaxiwaySegment) {
|
||||
console.log(o);
|
||||
// <Parking index="0" type="gate" name="GA_Parking" lat="S9 25.739923" lon="E160 2.927602" heading="67" radius="44" airlineCodes="" />
|
||||
return {'@index': String(o['end']), '@lat': convertLat(o._latlngs[1]), '@lon': convertLon(o._latlngs[1])};
|
||||
return { '@index': String(o['end']), '@lat': convertLat(o._latlngs[1]), '@lon': convertLon(o._latlngs[1]), '@isOnRunway': '0' };
|
||||
}
|
||||
}
|
||||
|
||||
var convertLat = function( latlng ) {
|
||||
var mapVertexNode = function (l) {
|
||||
if (l instanceof L.LatLng) {
|
||||
console.log(l);
|
||||
// <Parking index="0" type="gate" name="GA_Parking" lat="S9 25.739923" lon="E160 2.927602" heading="67" radius="44" airlineCodes="" />
|
||||
return { '@index': String(l.__vertex.glueindex), '@lat': convertLat(l), '@lon': convertLon(l) };
|
||||
}
|
||||
}
|
||||
|
||||
var convertLat = function (latlng) {
|
||||
console.log(latlng.lat);
|
||||
var NS = latlng.lat>0?'N':'S';
|
||||
var deg = mathjs.abs(mathjs.floor(latlng.lat));
|
||||
var NS = latlng.lat > 0 ? 'N' : 'S';
|
||||
var deg = mathjs.floor(mathjs.abs(latlng.lat));
|
||||
var min = (mathjs.abs(latlng.lat) - deg) * 60;
|
||||
// console.log(NS + deg + " " + min);
|
||||
return NS + String(deg).padStart(2, '0') + " " + mathjs.round( min, 3 );
|
||||
return NS + String(deg).padStart(2, '0') + " " + mathjs.round(min, 3);
|
||||
}
|
||||
|
||||
var convertLon = function( latlng ) {
|
||||
var convertLon = function (latlng) {
|
||||
console.log(latlng.lng);
|
||||
var NS = latlng.lat<0?'E':'W';
|
||||
var NS = latlng.lat < 0 ? 'E' : 'W';
|
||||
var deg = mathjs.floor(mathjs.abs(latlng.lng));
|
||||
var min = (mathjs.abs(latlng.lng) - deg) * 60;
|
||||
// console.log(NS + deg + " " + min);
|
||||
return NS + String(deg).padStart(2, '0') + " " + mathjs.round( min, 3 );
|
||||
return NS + String(deg).padStart(2, '0') + " " + mathjs.round(min, 3);
|
||||
}
|
Loading…
Reference in New Issue
Block a user