Skip to content

Commit

Permalink
Show laylines only when heading upwind (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Jun 2, 2024
1 parent a3527ff commit 419221e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app/modules/map/ol/lib/navigation/layer-layline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { Layer } from 'ol/layer';
import { Feature } from 'ol';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { Style, Stroke, Fill, Circle } from 'ol/style';
import { Style } from 'ol/style';
import { LineString } from 'ol/geom';
import { MapComponent } from '../map.component';
import { Extent, Coordinate } from '../models';
import { fromLonLatArray, mapifyCoords } from '../util';
import { AsyncSubject } from 'rxjs';
import { Convert } from 'src/app/lib/convert';

// ** Freeboard Layline component **
@Component({
Expand All @@ -41,6 +42,8 @@ export class LaylineComponent implements OnInit, OnDestroy, OnChanges {
@Input() mapZoom = 10;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@Input() laylineStyles: { [key: string]: any };
@Input() heading: number;
@Input() awa: number;
@Input() opacity: number;
@Input() visible: boolean;
@Input() extent: Extent;
Expand Down Expand Up @@ -81,7 +84,12 @@ export class LaylineComponent implements OnInit, OnDestroy, OnChanges {
const properties: { [index: string]: any } = {};

for (const key in changes) {
if (key === 'lines') {
if (
key === 'lines' ||
key === 'heading' ||
key === 'bearing' ||
key === 'awa'
) {
this.parseValues();
if (this.source) {
this.source.clear();
Expand Down Expand Up @@ -111,6 +119,15 @@ export class LaylineComponent implements OnInit, OnDestroy, OnChanges {
parseValues() {
const fa: Feature[] = [];
let idx = 0;
// is upwind
if (
typeof this.heading !== 'number' ||
Math.abs(Convert.radiansToDegrees(this.awa)) >= 90
) {
this.features = [];
return;
}

if (this.lines) {
if (this.lines.port && Array.isArray(this.lines.port)) {
this.lines.port.forEach((l: Coordinate[]) => {
Expand Down

0 comments on commit 419221e

Please sign in to comment.