From 1e43d973b2e70024584c8adc97e718ffa0a41189 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Sun, 29 Mar 2020 18:10:51 +0200 Subject: [PATCH] Thresholds --- src/renderer/components/FlightgearMap.vue | 5 +- src/renderer/components/ThresholdLayer.vue | 72 +++++++++++ src/renderer/loaders/Threshold.js | 141 +++++++++++++++++++++ src/renderer/loaders/threshold_loader.js | 65 ++++++++++ 4 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 src/renderer/components/ThresholdLayer.vue create mode 100644 src/renderer/loaders/Threshold.js create mode 100644 src/renderer/loaders/threshold_loader.js diff --git a/src/renderer/components/FlightgearMap.vue b/src/renderer/components/FlightgearMap.vue index a38dd8b..41afc20 100644 --- a/src/renderer/components/FlightgearMap.vue +++ b/src/renderer/components/FlightgearMap.vue @@ -17,6 +17,7 @@ + 0 && airportsToLoad[0] !== this.editingAirport && this.zoom > 12) { this.$refs.editLayer.load(airportsToLoad[0]) this.$refs.pavementLayer.load(airportsToLoad[0]) + this.$refs.thresholdLayer.load(airportsToLoad[0]) this.editingAirport = airportsToLoad[0] } this.$refs.editLayer.setVisible(this.zoom >= 12) diff --git a/src/renderer/components/ThresholdLayer.vue b/src/renderer/components/ThresholdLayer.vue new file mode 100644 index 0000000..a5931bb --- /dev/null +++ b/src/renderer/components/ThresholdLayer.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/src/renderer/loaders/Threshold.js b/src/renderer/loaders/Threshold.js new file mode 100644 index 0000000..0b9fec3 --- /dev/null +++ b/src/renderer/loaders/Threshold.js @@ -0,0 +1,141 @@ +/* eslint-disable */ +const convert = require('geo-coordinates-parser'); +const leaflet = require('leaflet'); +const turf = require('@turf/turf'); +const util = require('util'); +const store = require('../store'); + +var $ = require('jquery'); +L.Threshold = L.Circle.extend({ + highlight() { + var style = {}; + style['color'] = 'red'; + this.setStyle(style); + }, + addListeners: function () { + this.on('editable:drawing:move', function (event) { + console.log("Move : ", event); + console.log("Move : ", event.latlng); + // Is it the edit vertex (Middle) moving? + if(event.target.editor._resizeLatLng.__vertex._icon !== event.sourceTarget._element){ + event.target.setLatLng(event.latlng); + event.target.updateVertexFromDirection(); + this.follow(event.target.id, event); + } + else if(event.target.editor._resizeLatLng.__vertex._icon === event.sourceTarget._element) { + event.target.updateDirectionFromVertex(); + event.target.updateVertexFromDirection(); + } + }); + /* + this.on('editable:vertex:drag', function (event) { + console.log("Drag : ", event); + }); + */ + this.on('click', function (event) { + console.log("Click : " + event.target); + store.default.dispatch('setParking', event.target.options.attributes); + this.highlight(); + this.unwatch = store.default.watch( + function (state) { + return state.Editable.data.parking; + }, + () => { + if (event.target instanceof L.Threshold) { + event.target.setStyle({color : '#3388ff'}); + this.unwatch(); + } + } + , + { + deep: true //add this if u need to watch object properties change etc. + } + ); + }); + this.on('editable:vertex:clicked', function (event) { + console.log(this.featureLookup[event.vertex.glueindex]); + if(event.target.editor._resizeLatLng.__vertex._icon !== event.sourceTarget._element){ + event.vertex._icon.style['background-color'] = 'red'; + store.default.dispatch('setParking', event.target.options.attributes); + this.unwatch = store.default.watch( + function (state) { + return state.Editable.data.parking; + }, + () => { + event.target.setStyle({color : '#3388ff'}); + this.unwatch(); + } + , + { + deep: true //add this if u need to watch object properties change etc. + } + ); + + } + + }); + + this.on('editable:disable', function (event) { + event.target.removeDirection(); + }); + }, + updateStyle: function () { + + }, + turfToLatLng: function (turfPoint) { + return {lat: turfPoint.geometry.coordinates[1], lng: turfPoint.geometry.coordinates[0]}; + }, + extensions: function (editLayer) { + this.createDirection(); + if (typeof this.featureLookup[this.id] === 'undefined') { + this.featureLookup[this.id] = []; + } + this.featureLookup[this.id].push(this); + }, + + _getLatRadius: function () { + return this._mRadius; + }, + + _getLngRadius: function () { + return this._mRadius; + }, + +}); + +var threshold = function (n, layerGroup) { + //console.log(n.attr('lat') + " " + n.attr('lon')); + var latlon = convert(n.find('lat/text()').text() + " " + n.find('lon/text()').text()); + //console.log(latlon.decimalLatitude); + //console.log(convert(n.attr('lat') + " " + n.attr('lon')).decimalLongitude); + const circle = new L.Threshold([latlon.decimalLatitude, latlon.decimalLongitude], { radius: 10, attributes: {} }); + circle.on('editable:enable', function (event) { + // event.target.createDirection(); + }); + /* + +*/ + //circle.attributes = { type: n.attr('type'), name: n.attr('name'), radius: Number(n.attr('radius')), airlineCodes: n.attr('airlineCodes'), heading: Number(n.attr('heading')) }; + + $.each( n.attrs, function( key, value ) { + console.log( '$', circle.id, key , value); + + if(isNaN(value)) + circle.options.attributes[ key ] = value; + else + circle.options.attributes[ key ] = Number( value); + }); + circle.addTo(layerGroup); + return circle; +} + +module.exports = threshold; \ No newline at end of file diff --git a/src/renderer/loaders/threshold_loader.js b/src/renderer/loaders/threshold_loader.js new file mode 100644 index 0000000..332a851 --- /dev/null +++ b/src/renderer/loaders/threshold_loader.js @@ -0,0 +1,65 @@ +/* eslint-disable */ +const fs = require('fs'); +const path = require('path'); +var xamel = require('xamel'); +const convert = require('geo-coordinates-parser'); + +const store = require('../store'); + +const util = require('util'); + +const threshold = require('./Threshold.js'); + + +var $ = require('jquery'); + +exports.readThresholdXML = function (fDir, icao, force) { + try { + layerGroup = L.layerGroup(); + layerGroup.maxId = 0; + var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.threshold.xml'); + var fNew = path.join(fDir, icao[0], icao[1], icao[2], icao + '.threshold.new.xml'); + + if (f == null || !fs.existsSync(f)) + return; + if (fNew != null && fs.existsSync(fNew) && !force) { + f = fNew; + } + + 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 thresholdNodes = xml.find('PropertyList/runway/threshold'); + console.log("Threshold Nodes" + thresholdNodes.length); + + var merged = new Array(); + + var nodesLookup = {}; + featureLookup = []; + + + thresholdNodes.map(n => { + var circle = threshold(n, layerGroup); + features.push(circle); + }).sort(); + + return layerGroup; + }); + // var jsonAirports = JSON.parse(geoJSON); + // return jsonAirports; + } catch (error) { + console.error(error); + } + return layerGroup; +}; \ No newline at end of file