-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmapcontrol.js
More file actions
293 lines (264 loc) · 7.1 KB
/
mapcontrol.js
File metadata and controls
293 lines (264 loc) · 7.1 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
var mapControl;
function initMap() {
mapControl = createMapControl();
}
function createMapControl() {
var taskfeatures = [];
var sectorfeatures=[];
var trackline;
var airspacePolygons=[];
var polygonBases = [];
var airspaceCircles=[];
var circleBases = [];
var engineLines=[];
var gliderMarker = new google.maps.Marker({
icon: 'glidericon.png'
});
var myStyles =[
{
"featureType": "poi",
"elementType": "labels",
"stylers": [
{ "visibility": "off" }
]
},
{
"featureType": "transit",
"elementType": "labels",
"stylers": [
{ "visibility": "off" }
] } ];
var mapOpt = {
center: new google.maps.LatLng(0, 0),
zoom: 2,
mapTypeId: google.maps.MapTypeId.TERRAIN,
streetViewControl: false,
styles: myStyles
};
var pinicon = {
url: 'pin.png',
anchor: new google.maps.Point(0, 53)
};
var pin = new google.maps.Marker({
icon: pinicon
});
function zapAirspace() {
var i;
var j;
for (i = 0; i < airspacePolygons.length; i++) {
airspacePolygons[i].setMap(null);
airspacePolygons[i] = null;
}
airspacePolygons.length = 0;
polygonBases.length = 0;
for (j = 0; j < airspaceCircles.length; j++) {
airspaceCircles[j].setMap(null);
airspaceCircles[j] = null;
}
airspaceCircles.length = 0;
circleBases.length = 0;
}
function getLineBounds(line) {
var bounds = new google.maps.LatLngBounds();
line.getPath().forEach(function(latLng) {
bounds.extend(latLng);
});
return bounds;
}
function getTargetLine(start, end) {
var targetLine = new google.maps.Polyline({
path: [start, end],
strokeColor: 'black',
strokeOpacity: 1.0,
strokeWeight: 2
});
return targetLine;
}
function getCircle(centre,radius) {
var tpCircle = new google.maps.Circle({
strokeColor: 'black',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: 'green',
fillOpacity: 0.1,
center: centre,
radius: radius * 1000
});
return tpCircle;
}
function getPolygon(coordlist) {
var sectorPoly = new google.maps.Polygon({
paths: coordlist,
strokeColor: 'black',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: 'green',
fillOpacity: 0.1
});
return sectorPoly;
}
function zapSectors() {
var i;
for(i=0;i < sectorfeatures.length; i++) {
sectorfeatures[i].setMap(null);
}
sectorfeatures=[];
}
function zapTask() {
var i;
zapSectors();
for(i=0;i < taskfeatures.length; i++) {
taskfeatures[i].setMap(null);
}
taskfeatures=[];
}
function deleteEnl () {
var i;
for(i=0;i < engineLines.length;i++) {
engineLines[i].setMap(null);
}
engineLines=[];
}
map = new google.maps.Map($('#map').get(0), mapOpt);
return {
addTask: function(task) {
var j;
var route = new google.maps.Polyline({
path: task.coords,
strokeColor: 'dimgray',
strokeOpacity: 1.0,
strokeWeight: 3
});
route.setMap(map);
taskfeatures.push(route);
for (j = 0; j < task.coords.length - 1; j++) {
var taskmarker = new google.maps.Marker({
position: task.coords[j],
map: map,
title: task.labels[j]
});
taskfeatures.push(taskmarker);
}
var taskbounds=getLineBounds(route);
map.fitBounds(taskbounds);
},
drawSectors: function(sectorList) {
var i;
var feature;
zapSectors();
for(i=0;i< sectorList.length;i++) {
switch(sectorList[i].type) {
case "line":
feature=getTargetLine(sectorList[i].start,sectorList[i].end);
break;
case "circle":
feature=getCircle(sectorList[i].centre,sectorList[i].radius);
break;
case "segment":
feature=getPolygon(sectorList[i].outline);
break;
}
feature.setMap(map);
sectorfeatures.push(feature);
}
},
clearTask: function() {
zapTask();
},
setBounds: function(bounds) {
map.fitBounds(bounds);
},
showTP: function(tpoint) {
map.panTo(tpoint);
map.setZoom(13);
},
addTrack: function(coords) {
pin.setMap(null);
if (trackline) {
trackline.setMap(null);
}
trackline = new google.maps.Polyline({
path: coords,
strokeColor: 'blue',
strokeOpacity: 1.0,
clickable: false,
strokeWeight: 4
});
trackline.setMap(map);
gliderMarker.setPosition(coords[0]);
gliderMarker.setMap(map);
},
updateAirspace: function(clipalt) {
var i;
var j;
for (i = 0; i < airspacePolygons.length; i++) {
if (polygonBases[i] < clipalt) {
airspacePolygons[i].setMap(map);
} else {
airspacePolygons[i].setMap(null);
}
}
for (j = 0; j < airspaceCircles.length; j++) {
if (circleBases[j] < clipalt) {
airspaceCircles[j].setMap(map);
} else {
airspaceCircles[j].setMap(null);
}
}
},
setAirspace: function(airdata) {
var i;
var j;
zapAirspace();
var airDrawOptions = {
strokeColor: 'black',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: '#FF0000',
fillOpacity: 0.2,
clickable: false
};
for (i = 0; i < airdata.polygons.length; i++) {
airspacePolygons[i] = new google.maps.Polygon(airDrawOptions);
airspacePolygons[i].setPaths(airdata.polygons[i].coords);
polygonBases[i] = airdata.polygons[i].base;
}
for (j = 0; j < airdata.circles.length; j++) {
airspaceCircles[j] = new google.maps.Circle(airDrawOptions);
airspaceCircles[j].setRadius(1000 * airdata.circles[j].radius);
airspaceCircles[j].setCenter(airdata.circles[j].centre);
circleBases[j] = airdata.circles[j].base;
}
},
zapEngineRuns: function() {
deleteEnl();
},
showEngineRuns: function(runList) {
var i;
var lineOpt={
strokeColor: 'yellow',
strokeOpacity: 1.0,
clickable: false,
zIndex: google.maps.Marker.MAX_ZINDEX +1,
strokeWeight: 4
};
deleteEnl();
for(i=0;i < runList.length; i++) {
engineLines[i]= new google.maps.Polyline(lineOpt);
engineLines[i].setPath(runList[i]);
engineLines[i].setMap(map);
}
},
setTimeMarker: function(position) {
gliderMarker.setPosition(position);
var gliderpos = new google.maps.LatLng(position);
if (!(map.getBounds().contains(gliderpos))) {
map.panTo(gliderpos);
}
},
pushPin: function(coords) {
pin.setPosition(coords);
pin.setMap(map);
}
};
}