Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ATC-144 #146

Merged
merged 5 commits into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


### Minor
- Refactors `canvasController.canvas_draw_sids` method to use `airport.sidCollection` instead of `airport.sid` [#144](https://github.com/n8rzz/atc/issues/144)


### Bugfixes
Expand Down
21 changes: 2 additions & 19 deletions src/assets/scripts/airport/AirportModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import _has from 'lodash/has';
import _head from 'lodash/head';
import _map from 'lodash/map';
import _isEmpty from 'lodash/isEmpty';
import _isNil from 'lodash/isNil';
import AirspaceModel from './AirspaceModel';
import PositionModel from '../base/PositionModel';
import RunwayModel from './RunwayModel';
Expand Down Expand Up @@ -407,7 +408,7 @@ export default class AirportModel {
prop.canvas.draw_labels = true;
$(SELECTORS.DOM_SELECTORS.TOGGLE_LABELS).toggle(!_isEmpty(this.maps));
$(SELECTORS.DOM_SELECTORS.TOGGLE_RESTRICTED_AREAS).toggle((this.restricted_areas || []).length > 0);
$(SELECTORS.DOM_SELECTORS.TOGGLE_SIDS).toggle(!_isEmpty(this.sids));
$(SELECTORS.DOM_SELECTORS.TOGGLE_SIDS).toggle(!_isNil(this.sidCollection));

prop.canvas.dirty = true;
$(SELECTORS.DOM_SELECTORS.TOGGLE_TERRAIN).toggle(!_isEmpty(this.terrain));
Expand Down Expand Up @@ -683,24 +684,6 @@ export default class AirportModel {
return this.sidCollection.findRandomExitPointForSIDIcao(icao);
}

// FIXME: possibly unused
// getSIDName(id, rwy) {
// if (_has(this.sids[id], 'suffix')) {
// return `${this.sids[id].name} ${this.sids[id].suffix[rwy]}`;
// }
//
// return this.sids[id].name;
// }

// FIXME: possibly unused
// getSIDid(id, rwy) {
// if (_has(this.sids[id], 'suffix')) {
// return this.sids[id].icao + this.sids[id].suffix[rwy];
// }
//
// return this.sids[id].icao;
// }

/**
* Return an array of [Waypoint, fixRestrictions] for a given STAR
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import _find from 'lodash/find';
import _forEach from 'lodash/forEach';
import _isEmpty from 'lodash/isEmpty';
import _map from 'lodash/map';
import _random from 'lodash/random';
import BaseCollection from '../../base/BaseCollection';
import StandardRouteModel from './StandardRouteModel';
Expand Down Expand Up @@ -27,6 +29,28 @@ export default class StandardRouteCollection extends BaseCollection {
return this._init(standardRouteEnum);
}

// TODO: refactor into a reusable class that can be fed an `item` and will be consumed by the `CanvasController`
/**
* Return an idwntifier and a list of fixes in the order in which they should be drawn.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identifier

*
* Pulled directly from an airport json `draw` definition per route.
*
* @property draw
* @return {array}
*/
get draw() {
return _map(this._items, (item) => {
const sidForCanvas = {};
sidForCanvas.identifier = item.icao;

if (!_isEmpty(item.draw)) {
sidForCanvas.draw = item.draw;
}

return sidForCanvas;
});
}

/**
* Lifecycle method. Should be run only once on instantiation.
*
Expand Down
88 changes: 44 additions & 44 deletions src/assets/scripts/canvas/CanvasController.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ export default class ConvasController {
});
}

// TODO: break this method up into smaller chunks
/**
* @for CanvasController
* @method canvas_draw_sids
Expand All @@ -647,69 +648,68 @@ export default class ConvasController {

// Store the count of sid text drawn for a specific transition
const text_at_point = [];
const airport = window.airportController.airport_get();

cc.strokeStyle = COLORS.DEPARTURE_COLOR;
cc.fillStyle = COLORS.DEPARTURE_COLOR;
cc.setLineDash([1, 10]);
cc.font = 'italic 14px monoOne, monospace';

const airport = window.airportController.airport_get();

_forEach(airport.sids, (sid, s) => {
_forEach(airport.sidCollection.draw, (sid) => {
let write_sid_name = true;
let fx = null;
let fy = null;

// TODO: this if should be reversed to check for the opposite condition and return early.
if (_has(sid, 'draw')) {
_forEach(sid.draw, (fixList, i) => {
// const fixList = airport.sids[s].draw[i];
let exit_name = null;

for (let j = 0; j < fixList.length; j++) {
// write exitPoint name
if (fixList[j].indexOf('*') !== -1) {
exit_name = fixList[j].replace('*', '');
write_sid_name = false;
}
let fixX = null;
let fixY = null;

let fix = airport.getFixPosition(fixList[j].replace('*', ''));
if (!_has(sid, 'draw')) {
return;
}

if (!fix) {
log(`Unable to draw line to '${fixList[j]}' because its position is not defined!`, LOG.WARNING);
}
_forEach(sid.draw, (fixList, i) => {
let exit_name = null;

fx = window.uiController.km_to_px(fix[0]) + this.canvas.panX;
fy = -window.uiController.km_to_px(fix[1]) + this.canvas.panY;
for (let j = 0; j < fixList.length; j++) {
// write exitPoint name
if (fixList[j].indexOf('*') !== -1) {
exit_name = fixList[j].replace('*', '');
write_sid_name = false;
}

if (j === 0) {
cc.beginPath();
cc.moveTo(fx, fy);
} else {
cc.lineTo(fx, fy);
}
let fix = airport.getFixPosition(fixList[j].replace('*', ''));

if (!fix) {
log(`Unable to draw line to '${fixList[j]}' because its position is not defined!`, LOG.WARNING);
}

cc.stroke();
fixX = window.uiController.km_to_px(fix[0]) + this.canvas.panX;
fixY = -window.uiController.km_to_px(fix[1]) + this.canvas.panY;

if (exit_name) {
// Initialize count for this transition
if (isNaN(text_at_point[exit_name])) {
text_at_point[exit_name] = 0;
}
if (j === 0) {
cc.beginPath();
cc.moveTo(fixX, fixY);
} else {
cc.lineTo(fixX, fixY);
}
}

// Move the y point for drawing depending on how many sids we have drawn text for
// at this point already
const y_point = fy + (15 * text_at_point[exit_name]);
cc.fillText(`${s}.${exit_name}`, fx + 10, y_point);
cc.stroke();

text_at_point[exit_name] += 1; // Increment the count for this transition
if (exit_name) {
// Initialize count for this transition
if (isNaN(text_at_point[exit_name])) {
text_at_point[exit_name] = 0;
}
});

if (write_sid_name) {
cc.fillText(s, fx + 10, fy);
// Move the y point for drawing depending on how many sids we have drawn text for
// at this point already
const y_point = fixY + (15 * text_at_point[exit_name]);
cc.fillText(`${sid.identifier}.${exit_name}`, fixX + 10, y_point);

text_at_point[exit_name] += 1; // Increment the count for this transition
}
});

if (write_sid_name) {
cc.fillText(sid.identifier, fixX + 10, fixY);
}
});
}
Expand Down