From 618346d1b1ae7c56536684506f23a382e50fec28 Mon Sep 17 00:00:00 2001 From: Keith Paterson Date: Mon, 11 Jan 2021 13:25:06 +0100 Subject: [PATCH] #115 Better edit of NoseWheel position --- src/renderer/components/ParkingEdit.vue | 67 ++++++++++++++++--------- src/renderer/store/modules/Editable.js | 6 +++ 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/renderer/components/ParkingEdit.vue b/src/renderer/components/ParkingEdit.vue index 17069bf..37fd87d 100644 --- a/src/renderer/components/ParkingEdit.vue +++ b/src/renderer/components/ParkingEdit.vue @@ -210,9 +210,33 @@ }, turfToLatLng: function (turfPoint) { return '' + turfPoint.geometry.coordinates[1].toFixed(6) + ',' + turfPoint.geometry.coordinates[0].toFixed(6); + }, + calcWheel () { + var centerCoords = convert(this.$store.state.Editable.data.parking.coords); + if(this.calculate === 'Nose Wheel') { + // we change center + const centerLatLng = convert(newValue); + const parkingSize = this.validRadii.indexOf(this.$store.state.Editable.data.parking.radius); + if (parkingSize>=0) { + var newNoseWheel = turf.destination(this.latToTurf(centerLatLng), this.validN2M[parkingSize]/1000, this.$store.state.Editable.data.parking.heading - 180, turfOptions); + this.$store.commit('SET_EDIT_PARKING_NOSE_COORDS', this.turfToLatLng(newNoseWheel)); + } + } + }, + calcCenter () { + var centerCoords = convert(this.$store.state.Editable.data.parking.coords); + if (this.calculate === 'Center') { + // we change center + const noseWheelLatLng = convert(this.noseWheel); + const parkingSize = this.validRadii.indexOf(this.$store.state.Editable.data.parking.radius); + if (parkingSize>=0) { + var newCenter = turf.destination(this.latToTurf(noseWheelLatLng), this.validN2M[parkingSize]/1000, this.$store.state.Editable.data.parking.heading, turfOptions); + this.$store.commit('SET_EDIT_PARKING_COORDS', this.turfToLatLng(newCenter)); + } + } } }, - data () { return {calculate:'Nose Wheel', noseWheel: '', validRadii: [7.5, 10, 14, 18, 26, 33, 40], validN2M: [5, 5, 6, 10, 15, 24, 24] } }, + data () { return {_calculate: 'Center', noseWheel: '', validRadii: [7.5, 10, 14, 18, 26, 33, 40], validN2M: [5, 5, 6, 10, 15, 24, 24] } }, computed: { editing: { get: function () { @@ -274,6 +298,19 @@ this.$store.commit('SET_EDIT_PARKING_NUMBER', newValue) } }, + calculate: { + get: function () { + return this._calculate; + }, + set: function (newValue) { + this._calculate = newValue; + if (newValue==='Center') { + this.calcWheel(); + } else { + this.calcCenter(); + } + } + }, coordinates: { // getter get: function () { @@ -290,23 +327,14 @@ newValue = newValue.replace(', ', ' ').replace(/,/g, '.').replace(' ', ', '); } this.$store.commit('SET_EDIT_PARKING_COORDS', newValue) + this.calcWheel(); } }, noseCoordinates: { // getter get: function () { - if(this.$store.state.Editable.index!==undefined) { - const center = convert(this.$store.state.Editable.data.parking.coords); - const parkingSize = this.validRadii.indexOf(this.$store.state.Editable.data.parking.radius); - if (parkingSize>=0) { - var newWheel = turf.destination(this.latToTurf(center), this.validN2M[parkingSize]/1000, this.normalizeAngle(this.$store.state.Editable.data.parking.heading), turfOptions); - var newValue = this.turfToLatLng(newWheel); - if( newValue.match(/,/g) !== null && newValue.match(/,/g).length === 1) { - newValue = newValue.replace(',', ' '); - } - this.noseWheel = newValue; - return newValue; - } + if(this.$store.state.Editable.index!==undefined) { + return this.$store.state.Editable.data.parking.nosecoords; } }, // setter @@ -317,17 +345,8 @@ if( newValue.match(/,/g) !== null && newValue.match(/,/g).length === 3) { newValue = newValue.replace(', ', ' ').replace(/,/g, '.').replace(' ', ', '); } - this.noseWheel = newValue; - var centerCoords = convert(this.$store.state.Editable.data.parking.coords); - if(this.calculate === 'Center') { - // we change center - const noseWheelLatLng = convert(this.noseWheel); - const parkingSize = this.validRadii.indexOf(this.$store.state.Editable.data.parking.radius); - if (parkingSize>=0) { - var newCenter = turf.destination(this.latToTurf(noseWheelLatLng), this.validN2M[parkingSize]/1000, this.$store.state.Editable.data.parking.heading, turfOptions); - this.$store.commit('SET_EDIT_PARKING_COORDS', this.turfToLatLng(newCenter)); - } - } + this.$store.commit('SET_EDIT_PARKING_NOSE_COORDS', newValue); + this.calcCenter(); } }, heading: { diff --git a/src/renderer/store/modules/Editable.js b/src/renderer/store/modules/Editable.js index e1aaead..8622a44 100644 --- a/src/renderer/store/modules/Editable.js +++ b/src/renderer/store/modules/Editable.js @@ -131,6 +131,9 @@ const mutations = { 'SET_EDIT_PARKING_COORDS' (state, coords) { Vue.set(state.data.parking, 'coords', coords) }, + 'SET_EDIT_PARKING_NOSE_COORDS' (state, coords) { + Vue.set(state.data.parking, 'nosecoords', coords) + }, 'SET_EDIT_ARC_NAME' (state, arcName) { if (state.type === 'arc') { Vue.set(state.data.arc, 'name', arcName) @@ -197,6 +200,9 @@ const actions = { async setParkingCoords (context, coords) { context.commit('SET_EDIT_PARKING_COORDS', coords) }, + async setParkingNoseCoords (context, coords) { + context.commit('SET_EDIT_PARKING_NOSE_COORDS', coords) + }, async setArc (context, arc) { context.commit(SET_EDIT_ARC, arc) },