@@ -30,7 +30,13 @@ import {
30
30
import { FreeboardOpenlayersModule } from 'src/app/modules/map/ol' ;
31
31
import { PipesModule } from 'src/app/lib/pipes' ;
32
32
33
- import { computeDestinationPoint , getGreatCircleBearing } from 'geolib' ;
33
+ import {
34
+ computeDestinationPoint ,
35
+ getGreatCircleBearing ,
36
+ getDistanceFromLine ,
37
+ getDistance ,
38
+ getPreciseDistance
39
+ } from 'geolib' ;
34
40
import { toLonLat } from 'ol/proj' ;
35
41
import { Style , Stroke , Fill } from 'ol/style' ;
36
42
import { Collection , Feature } from 'ol' ;
@@ -709,8 +715,10 @@ export class FBMapComponent implements OnInit, OnDestroy {
709
715
}
710
716
711
717
public onMapPointerDrag ( ) {
712
- this . fbMap . movingMap = false ;
713
- this . exitedMovingMap . emit ( true ) ;
718
+ if ( ! this . app . config . map . lockMoveMap ) {
719
+ this . fbMap . movingMap = false ;
720
+ this . exitedMovingMap . emit ( true ) ;
721
+ }
714
722
}
715
723
716
724
// toggle display of resource feature
@@ -1215,107 +1223,119 @@ export class FBMapComponent implements OnInit, OnDestroy {
1215
1223
typeof this . app . data . vessels . active . heading === 'number'
1216
1224
) {
1217
1225
const twd_deg = Convert . radiansToDegrees (
1218
- this . app . data . vessels . self . wind . twd
1226
+ this . app . data . vessels . self . wind . direction
1219
1227
) ;
1228
+
1229
+ const twd_inv = Angle . add ( twd_deg , 180 ) ;
1230
+
1220
1231
const destUpwind =
1221
1232
Math . abs (
1222
1233
Angle . difference ( this . app . data . navData . bearing . value , twd_deg )
1223
1234
) < 90 ;
1235
+
1224
1236
const ba_deg = Convert . radiansToDegrees (
1225
1237
this . app . data . vessels . self . performance . beatAngle ?? Math . PI / 4
1226
1238
) ;
1227
- const destInTarget =
1228
- Math . abs (
1229
- Angle . difference ( this . app . data . navData . bearing . value , twd_deg )
1230
- ) < ba_deg ;
1239
+
1240
+ const ga_deg = Convert . radiansToDegrees (
1241
+ this . app . data . vessels . self . performance . gybeAngle ?? Math . PI / 6
1242
+ ) ;
1243
+
1244
+ const destInTarget = destUpwind
1245
+ ? Math . abs (
1246
+ Angle . difference ( this . app . data . navData . bearing . value , twd_deg )
1247
+ ) < ba_deg
1248
+ : Math . abs (
1249
+ Angle . difference ( this . app . data . navData . bearing . value , twd_deg )
1250
+ ) > ga_deg ;
1251
+
1231
1252
const dtg =
1232
1253
this . app . config . units . distance === 'm'
1233
1254
? this . app . data . navData . dtg * 1000
1234
1255
: Convert . nauticalMilesToKm ( this . app . data . navData . dtg * 1000 ) ;
1235
1256
1236
- if ( destInTarget ) {
1237
- const bta = Angle . add ( twd_deg , 90 ) ; // tack angle = 90
1238
-
1239
- const hbd_rad = Convert . degreesToRadians (
1240
- Angle . difference ( twd_deg , this . app . data . navData . bearing . value )
1241
- ) ;
1242
- const dist1 = Math . sin ( hbd_rad ) * dtg ;
1243
- const dist2 = Math . cos ( hbd_rad ) * dtg ;
1244
- const pt1 = computeDestinationPoint (
1245
- this . app . data . vessels . active . position ,
1246
- dist1 ,
1247
- bta
1248
- ) ;
1249
- const pt2 = computeDestinationPoint (
1250
- this . app . data . vessels . active . position ,
1251
- dist2 ,
1252
- twd_deg
1253
- ) ;
1254
- const p1a = [
1255
- this . app . data . vessels . active . position ,
1256
- [ pt1 . longitude , pt1 . latitude ]
1257
- ] ;
1258
- const p1b = [
1259
- [ pt1 . longitude , pt1 . latitude ] ,
1260
- this . dfeat . navData . position
1261
- ] ;
1262
- const l1 = hbd_rad < 0 ? [ p1a , p1b ] : [ p1b , p1a ] ;
1263
-
1264
- const p2a = [
1265
- [ pt2 . longitude , pt2 . latitude ] ,
1266
- this . dfeat . navData . position
1267
- ] ;
1268
- const p2b = [
1269
- this . app . data . vessels . active . position ,
1270
- [ pt2 . longitude , pt2 . latitude ]
1271
- ] ;
1272
- const l2 = hbd_rad < 0 ? [ p2a , p2b ] : [ p2b , p2a ] ;
1273
-
1274
- vl . laylines = {
1275
- port : hbd_rad < 0 ? l2 : l1 ,
1276
- starboard : hbd_rad < 0 ? l1 : l2
1277
- } ;
1278
- }
1279
- // target angle lines
1280
- if ( destUpwind && destInTarget ) {
1257
+ // mark laylines
1258
+ let markLines = [ ] ;
1259
+ if ( destUpwind ) {
1281
1260
const bapt1 = computeDestinationPoint (
1282
- this . app . data . vessels . active . position ,
1261
+ this . dfeat . navData . position ,
1283
1262
dtg ,
1284
- Angle . add ( twd_deg , ba_deg )
1263
+ Angle . add ( twd_inv , ba_deg )
1285
1264
) ;
1286
1265
const bapt2 = computeDestinationPoint (
1287
- this . app . data . vessels . active . position ,
1266
+ this . dfeat . navData . position ,
1288
1267
dtg ,
1289
- Angle . add ( twd_deg , 0 - ba_deg )
1268
+ Angle . add ( twd_inv , 0 - ba_deg )
1290
1269
) ;
1291
- vl . targetAngle = [
1270
+
1271
+ markLines = [
1292
1272
[ bapt1 . longitude , bapt1 . latitude ] ,
1293
- this . app . data . vessels . active . position ,
1273
+ this . dfeat . navData . position ,
1294
1274
[ bapt2 . longitude , bapt2 . latitude ]
1295
1275
] ;
1296
- } else if (
1297
- ! destUpwind &&
1298
- typeof this . app . data . vessels . self . performance . gybeAngle === 'number'
1299
- ) {
1300
- const ga_deg = Convert . radiansToDegrees (
1301
- this . app . data . vessels . self . performance . gybeAngle
1302
- ) ;
1276
+ } else {
1303
1277
const gapt1 = computeDestinationPoint (
1304
- this . app . data . vessels . active . position ,
1278
+ this . dfeat . navData . position ,
1305
1279
dtg ,
1306
- Angle . add ( this . app . data . navData . bearing . value , ga_deg )
1280
+ Angle . add ( twd_deg , ga_deg )
1307
1281
) ;
1308
1282
const gapt2 = computeDestinationPoint (
1309
- this . app . data . vessels . active . position ,
1283
+ this . dfeat . navData . position ,
1310
1284
dtg ,
1311
- Angle . add ( this . app . data . navData . bearing . value , 0 - ga_deg )
1285
+ Angle . add ( twd_deg , 0 - ga_deg )
1312
1286
) ;
1313
- vl . targetAngle = [
1287
+
1288
+ markLines = [
1314
1289
[ gapt1 . longitude , gapt1 . latitude ] ,
1315
- this . app . data . vessels . active . position ,
1290
+ this . dfeat . navData . position ,
1316
1291
[ gapt2 . longitude , gapt2 . latitude ]
1317
1292
] ;
1318
1293
}
1294
+
1295
+ vl . targetAngle = markLines ;
1296
+
1297
+ // vessel laylines
1298
+ if ( destInTarget && destUpwind ) {
1299
+ // Vector angles
1300
+ const hbd_deg = Angle . difference (
1301
+ twd_deg ,
1302
+ this . app . data . navData . bearing . value
1303
+ ) ;
1304
+ const C_RAD = Convert . degreesToRadians ( ba_deg - hbd_deg ) ;
1305
+ const B_RAD = Convert . degreesToRadians ( ba_deg + hbd_deg ) ;
1306
+ const A_RAD = Math . PI - ( B_RAD + C_RAD ) ;
1307
+ // Vector lengths
1308
+ const b = ( dtg * Math . sin ( B_RAD ) ) / Math . sin ( A_RAD ) ;
1309
+ const c = ( dtg * Math . sin ( C_RAD ) ) / Math . sin ( A_RAD ) ;
1310
+ // intersection points
1311
+ const ipts = computeDestinationPoint (
1312
+ this . app . data . vessels . active . position ,
1313
+ b ,
1314
+ Angle . add ( twd_deg , ba_deg )
1315
+ ) ;
1316
+ const iptp = computeDestinationPoint (
1317
+ this . app . data . vessels . active . position ,
1318
+ c ,
1319
+ Angle . add ( twd_deg , 0 - ba_deg )
1320
+ ) ;
1321
+
1322
+ vl . laylines = {
1323
+ port : [
1324
+ [
1325
+ [ iptp . longitude , iptp . latitude ] ,
1326
+ this . app . data . vessels . active . position
1327
+ ] ,
1328
+ [
1329
+ [ ipts . longitude , ipts . latitude ] ,
1330
+ this . app . data . vessels . active . position
1331
+ ]
1332
+ ] ,
1333
+ starboard : [
1334
+ [ [ ipts . longitude , ipts . latitude ] , markLines [ 1 ] ] ,
1335
+ [ markLines [ 1 ] , [ iptp . longitude , iptp . latitude ] ]
1336
+ ]
1337
+ } ;
1338
+ }
1319
1339
}
1320
1340
1321
1341
// AWA (focused)
0 commit comments