-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrid.js
88 lines (67 loc) · 3 KB
/
grid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function Grid() {
this.p1_latitude = 0;
this.p1_longitude = 0;
this.p2_latitude = 0;
this.p2_longitude = 0;
this.visible = true;
// Graphic object
this.gDraw = new createjs.Container();
this.gLabel1 = new createjs.Text("", "normal 10px Courier", RWY_TEXT_COLOR);
this.gLabel1.x = -20;
this.gLabel1.y = -10;
this.gLabel1.lineHeight = 9;
this.gLine = new createjs.Shape();
this.gLine.x = 0;
this.gLine.y = 0;
this.gLine.graphics.setStrokeStyle(1).beginStroke(GRID_COLOR).moveTo(0,0).lineTo(1,1).endStroke();
this.gDraw.addChild(this.gLine, this.gLabel1);
}
Grid.prototype.setScreenPosition = function() {
// var length_miles = Math.feetToMiles(this.length);
// var width_miles = Math.feetToMiles(this.width);
// var threshold1 = Math.coordsFromCoarseDistance(this.latitude, this.longitude, (180 + this.heading) % 360, length_miles / 2);
var gridP1 = Math.coordsToScreen( this.p1_latitude, this.p1_longitude);
// var th1Y = (SCREEN_CENTER_Y - ((LATITUDE_CENTER - this.p1_latitude) * MILESFACT ));
// var th1X = (SCREEN_CENTER_X - ((LONGITUDE_CENTER - this.p1_longitude) * MILESFACT ));
this.gDraw.x = gridP1.x;
this.gDraw.y = gridP1.y;
// var threshold2 = Math.coordsFromCoarseDistance(this.latitude, this.longitude, this.heading, length_miles / 2);
// var th2Y = (SCREEN_CENTER_Y - ((LATITUDE_CENTER - this.p2_latitude) * MILESFACT ));
// var th2X = (SCREEN_CENTER_X - ((LONGITUDE_CENTER - this.p2_longitude) * MILESFACT ));
gridP2 = Math.coordsToScreen( this.p2_latitude, this.p2_longitude);
// console.log(this.latitude, this.longitude, threshold1.lat, threshold1.lon);
this.gLine.graphics.clear();
this.gLine.graphics.setStrokeStyle(3).beginStroke(GRID_COLOR).moveTo(0,0).lineTo(gridP2.x - gridP1.x, gridP2.y - gridP1.y).endStroke();
this.gLabel1.text = this.p1_latitude + ' - ' + this.p1_longitude;
}
Grid.prototype.show = function(visible) {
this.visible = visible;
this.gDraw.visible = visible;
}
/** GLOBAL FUNCTIONS **/
function createGrid() {
var ngrid = 0;
var step = 0.5;
for(lat=LATITUDE_CENTER-5; lat<LATITUDE_CENTER+5; lat+=step) {
for(lon=LONGITUDE_CENTER-5; lon<LONGITUDE_CENTER+5; lon+=step) {
lat = Math.floor(lat * 10)/10;
lon = Math.floor(lon * 10)/10;
grid[ngrid] = new Grid();
grid[ngrid].p1_latitude = lat;
grid[ngrid].p1_longitude = lon;
grid[ngrid].p2_latitude = lat+step;
grid[ngrid].p2_longitude = lon;
grid[ngrid].setScreenPosition();
mainContainer.addChild(grid[ngrid].gDraw);
ngrid++;
grid[ngrid] = new Grid();
grid[ngrid].p1_latitude = lat;
grid[ngrid].p1_longitude = lon;
grid[ngrid].p2_latitude = lat;
grid[ngrid].p2_longitude = lon+step;
grid[ngrid].setScreenPosition();
mainContainer.addChild(grid[ngrid].gDraw);
ngrid++;
}
}
}