Move config init to config class

This commit is contained in:
Bartek Fabiszewski 2019-10-09 18:10:43 +02:00
parent d51e02d5af
commit 982c0dde78
3 changed files with 48 additions and 71 deletions

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,31 @@ import uEvent from './event.js';
export default class uConfig { export default class uConfig {
constructor() {
this.inititialize();
}
inititialize() {
this.interval = 10;
this.units = 'metric';
this.mapapi = 'openlayers';
this.gkey = null;
this.ol_layers = {};
this.init_latitude = 52.23;
this.init_longitude = 21.01;
this.pass_regex = new RegExp('(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{12,})');
this.strokeWeight = 2;
this.strokeColor = '#ff0000';
this.strokeOpacity = 1;
this.showLatest = false;
// marker colors
this.colorNormal = '#fff';
this.colorStart = '#55b500';
this.colorStop = '#ff6a00';
this.colorExtra = '#ccc';
this.colorHilite = '#feff6a';
}
/** /**
* *
* @param {uBinder} binder * @param {uBinder} binder
@ -65,6 +90,28 @@ export default class uConfig {
*/ */
set units(value) { set units(value) {
this._units = value; this._units = value;
if (this._units === 'imperial') {
this._factor_kmh = 0.62; // to mph
this._unit_kmh = 'mph';
this._factor_m = 3.28; // to feet
this._unit_m = 'ft';
this._factor_km = 0.62; // to miles
this._unit_km = 'mi';
} else if (this._units === 'nautical') {
this._factor_kmh = 0.54; // to knots
this._unit_kmh = 'kt';
this._factor_m = 1; // meters
this._unit_m = 'm';
this._factor_km = 0.54; // to nautical miles
this._unit_km = 'nm';
} else {
this._factor_kmh = 1;
this._unit_kmh = 'km/h';
this._factor_m = 1;
this._unit_m = 'm';
this._factor_km = 1;
this._unit_km = 'km';
}
} }
/** /**
@ -200,13 +247,6 @@ export default class uConfig {
return this._factor_kmh; return this._factor_kmh;
} }
/**
* @param {number} value
*/
set factor_kmh(value) {
this._factor_kmh = value;
}
/** /**
* @return {string} * @return {string}
*/ */
@ -214,13 +254,6 @@ export default class uConfig {
return this._unit_kmh; return this._unit_kmh;
} }
/**
* @param {string} value
*/
set unit_kmh(value) {
this._unit_kmh = value;
}
/** /**
* @return {number} * @return {number}
*/ */
@ -228,13 +261,6 @@ export default class uConfig {
return this._factor_m; return this._factor_m;
} }
/**
* @param {number} value
*/
set factor_m(value) {
this._factor_m = value;
}
/** /**
* @return {string} * @return {string}
*/ */
@ -242,13 +268,6 @@ export default class uConfig {
return this._unit_m; return this._unit_m;
} }
/**
* @param {string} value
*/
set unit_m(value) {
this._unit_m = value;
}
/** /**
* @return {number} * @return {number}
*/ */
@ -256,13 +275,6 @@ export default class uConfig {
return this._factor_km; return this._factor_km;
} }
/**
* @param {number} value
*/
set factor_km(value) {
this._factor_km = value;
}
/** /**
* @return {string} * @return {string}
*/ */
@ -270,13 +282,6 @@ export default class uConfig {
return this._unit_km; return this._unit_km;
} }
/**
* @param {string} value
*/
set unit_km(value) {
this._unit_km = value;
}
/** /**
* @return {boolean} * @return {boolean}
*/ */

View File

@ -104,34 +104,6 @@ class uConstants {
this.config.strokeWeight = uUtils.getNodeAsInt(configNode[0], 'strokeWeight'); this.config.strokeWeight = uUtils.getNodeAsInt(configNode[0], 'strokeWeight');
this.config.strokeColor = uUtils.getNode(configNode[0], 'strokeColor'); this.config.strokeColor = uUtils.getNode(configNode[0], 'strokeColor');
this.config.strokeOpacity = uUtils.getNodeAsInt(configNode[0], 'strokeOpacity'); this.config.strokeOpacity = uUtils.getNodeAsInt(configNode[0], 'strokeOpacity');
this.config.factor_kmh = 1;
this.config.unit_kmh = 'km/h';
this.config.factor_m = 1;
this.config.unit_m = 'm';
this.config.factor_km = 1;
this.config.unit_km = 'km';
if (this.config.units === 'imperial') {
this.config.factor_kmh = 0.62; // to mph
this.config.unit_kmh = 'mph';
this.config.factor_m = 3.28; // to feet
this.config.unit_m = 'ft';
this.config.factor_km = 0.62; // to miles
this.config.unit_km = 'mi';
} else if (this.config.units === 'nautical') {
this.config.factor_kmh = 0.54; // to knots
this.config.unit_kmh = 'kt';
this.config.factor_m = 1; // meters
this.config.unit_m = 'm';
this.config.factor_km = 0.54; // to nautical miles
this.config.unit_km = 'nm';
}
this.config.showLatest = false;
// marker colors
this.config.colorNormal = '#fff';
this.config.colorStart = '#55b500';
this.config.colorStop = '#ff6a00';
this.config.colorExtra = '#ccc';
this.config.colorHilite = '#feff6a';
} }
} }
} }