From 67cca39c0beffe006dfb950431ee26c5a025a04c Mon Sep 17 00:00:00 2001 From: portree_kid Date: Fri, 10 Jan 2020 14:35:39 +0100 Subject: [PATCH] Loading on startup --- package-lock.json | 5 ++++ package.json | 1 + src/renderer/components/FlightgearMap.vue | 9 +++++- src/renderer/loaders/pavement_loader.js | 35 +++++++++++------------ 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 43909ee..a25edfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9173,6 +9173,11 @@ "resolved": "https://registry.npmjs.org/geo-coordinates-parser/-/geo-coordinates-parser-1.2.3.tgz", "integrity": "sha512-d5yj0zfkN4K2tIE877cg0lWofCo+JnWIjX2JMtBOMVgU76DrqEWgKuxZnp0L+hbSkmi1bot22M7a7Go5TNEVJg==" }, + "geodesy": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/geodesy/-/geodesy-2.2.0.tgz", + "integrity": "sha512-pNCjfcmU9Q27SJpSLIN0deidCEhGtQvxA7cH28bJKn2lV1xFA4fxfHeYAmGAXqJBQvPIqZsWWvytkJNkL+k2Ug==" + }, "geojson-equality": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/geojson-equality/-/geojson-equality-0.1.6.tgz", diff --git a/package.json b/package.json index 3dc5797..0c009a4 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "file-url": "^3.0.0", "fs": "0.0.1-security", "geo-coordinates-parser": "^1.2.3", + "geodesy": "^2.2.0", "idb": "^4.0.5", "jquery": "^3.4.1", "leaflet": "^1.5.1", diff --git a/src/renderer/components/FlightgearMap.vue b/src/renderer/components/FlightgearMap.vue index e8fb646..23a3a26 100644 --- a/src/renderer/components/FlightgearMap.vue +++ b/src/renderer/components/FlightgearMap.vue @@ -54,7 +54,7 @@ mounted () { this.$store.dispatch('getAirports') this.$store.subscribe((mutation, state) => { - if (mutation.type === 'BOUNDS') { + if (mutation.type === 'BOUNDS' || mutation.type === 'SET_AIRPORTS') { // console.log(this.$parent) // console.log(this.$store.state.Settings.bounds) let airportsToLoad = this.$store.state.Airports.airports @@ -65,6 +65,8 @@ this.$refs.pavementLayer.load(airportsToLoad[0]) this.editingAirport = airportsToLoad[0] } + this.$refs.airportLayer.setVisible(this.zoom < 12) + // console.log(this.groundnet) } }) @@ -81,6 +83,9 @@ methods: { visible (feature) { let bounds = this.$store.state.Settings.bounds + if (!bounds.hasOwnProperty('getNorthEast')) { + bounds = this.$refs.map.mapObject.getBounds() + } let coordinates = feature.geometry.coordinates let ret = bounds.getNorthEast().lat > Number(coordinates[1]) && bounds.getNorthEast().lng > Number(coordinates[0]) @@ -110,11 +115,13 @@ centerUpdated (center) { if (center !== this.$store.state.Settings.center) { this.$store.dispatch('setCenter', center) + this.$refs.airportLayer.setVisible(this.zoom < 12) } }, boundsUpdated (bounds) { if (bounds !== this.$store.state.Settings.bounds) { this.$store.dispatch('setBounds', bounds) + this.$refs.airportLayer.setVisible(this.zoom < 12) } } }, diff --git a/src/renderer/loaders/pavement_loader.js b/src/renderer/loaders/pavement_loader.js index 68bc3fb..433e8bf 100644 --- a/src/renderer/loaders/pavement_loader.js +++ b/src/renderer/loaders/pavement_loader.js @@ -1,7 +1,8 @@ /* eslint-disable */ const lineReader = require('readline'); const zlib = require('zlib'); -const turf = require('@turf/turf'); +// const geodesy = require('geodesy'); +const LatLonEllipsoidal = require( 'geodesy/latlon-ellipsoidal-vincenty.js').default; const fs = require('fs'); module.exports.readPavement = function (f, icao, cb) { @@ -52,34 +53,32 @@ var scanMethods = { 100: (line, icao, layerGroup) => { if (module.exports.isScanning) { console.log('Runway ', line ); - var point1 = turf.point([line[9], line[10]]); - var point2 = turf.point([line[18], line[19]]); + var point1 = new LatLonEllipsoidal(Number(line[9]), Number(line[10])); + var point2 = new LatLonEllipsoidal(Number(line[18]), Number(line[19])); var runwayPoints = []; - var bearing = turf.bearing(point1, point2); - var runwayEnd1 = [line[9], line[10]]; - var runwayEnd2 = [line[18], line[19]]; - var runwayWidth = Number(line[1])/1000; - var destination = turf.destination(point1, runwayWidth/2, bearing, {}); + var bearing = point1.initialBearingTo(point2); + var runwayWidth = Number(line[1]); + var destination = point1.destinationPoint( 1000, bearing); - runwayPoints.push(turf.destination(point1, runwayWidth/2, bearing+90, {})); - runwayPoints.push(turf.destination(point2, runwayWidth/2, bearing+90, {})); - runwayPoints.push(turf.destination(point2, runwayWidth/2, bearing-90, {})); - runwayPoints.push(turf.destination(point1, runwayWidth/2, bearing-90, {})); + runwayPoints.push(point1.destinationPoint( runwayWidth/2, (bearing+90))); + runwayPoints.push(point2.destinationPoint( runwayWidth/2, (bearing+90))); + runwayPoints.push(point2.destinationPoint( runwayWidth/2, (bearing-90))); + runwayPoints.push(point1.destinationPoint( runwayWidth/2, (bearing-90))); - runwayPoints = runwayPoints.map(p => p.geometry.coordinates); var runwayPoly = new L.Polygon(runwayPoints); runwayPoly.setStyle({color: 'grey'}); runwayPoly.addTo(layerGroup); - console.log(turf.bearing(point1, point2), turf.bearing(point2, point1)); - console.log(runwayEnd1, runwayEnd2); - - - // var end = turf.destination([start.lat, start.lng], this.attributes.radius / 1000, this.attributes.heading - 180, options); + var runwayLine = new L.Polyline([point1,point2]); + runwayLine.setStyle({color: 'red'}); + // runwayLine.addTo(layerGroup); + var runwayLine1 = new L.Polyline([point1 ,destination]); + runwayLine1.setStyle({color: 'red'}); + // runwayLine1.addTo(layerGroup); } }, // Pavement