Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Dec 6, 2024
1 parent f483e0d commit edbda5d
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 106 deletions.
5 changes: 2 additions & 3 deletions helper/autopilot/pypilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const initApiRoutes = () => {
return;
}

let deg = req.body.value * (180 / Math.PI);
let deg = req.body.value;
if (deg > 359) {
deg = 359;
} else if (deg < -179) {
Expand All @@ -181,8 +181,7 @@ const initApiRoutes = () => {
return;
}

const v = req.body.value * (180 / Math.PI);
let deg = apData.target + v;
let deg = apData.target + req.body.value;
if (deg > 360) {
deg = 360;
} else if (deg < -180) {
Expand Down
8 changes: 7 additions & 1 deletion src/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mat-nav-list {
position: absolute;
z-index: 4901;
bottom: 30px;
left: 50px;
left: 10px;
max-width: calc(100% - 55px);
max-height: 100px;
text-align: center;
Expand Down Expand Up @@ -193,3 +193,9 @@ mat-nav-list {
display: none;
}
}

@media only screen and (max-height: 600px) {
.navdataPanel {
left: 50px;
}
}
26 changes: 14 additions & 12 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,20 @@ export class AppComponent {
}) => {
// detect apis
this.app.data.weather.hasApi = res.apis.includes('weather');
this.app.data.autopilot.hasApi = res.apis.includes('autopilot');

// prefer FB Autopilot API if enabled
this.signalk.api
.get(this.app.skApiVersion, 'vessels/self/steering/autopilot')
.subscribe(
() => {
this.app.data.autopilot.hasApi = true;
this.app.data.autopilot.isLocal = true;
},
() => {
this.app.debug('No local AP API found.');
}
);

// detect plugins
const hasPlugin = {
Expand Down Expand Up @@ -627,18 +641,6 @@ export class AppComponent {
this.app.data.anchor.hasApi = true;
}
);

// check for Autopilot API
this.signalk.api
.get(this.app.skApiVersion, 'vessels/self/steering/autopilot')
.subscribe(
() => {
this.app.data.autopilot.hasApi = true;
},
() => {
this.app.data.autopilot.hasApi = false;
}
);
}

// ** start trail / AIS timers
Expand Down
5 changes: 3 additions & 2 deletions src/app/app.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class AppInfo extends Info {
this.name = 'Freeboard-SK';
this.shortName = 'Freeboard';
this.description = `Signal K Chart Plotter.`;
this.version = '2.12.2';
this.version = '2.12.3';
this.url = 'https://github.com/signalk/freeboard-sk';
this.logo = './assets/img/app_logo.png';

Expand Down Expand Up @@ -269,7 +269,8 @@ export class AppInfo extends Info {
},
autopilot: {
console: false, // display Autopilot console
hasApi: false // Server implements Autopilot API
hasApi: false, // Server implements Autopilot API
isLocal: false // FB AP API
},
buildRoute: {
show: false
Expand Down
68 changes: 56 additions & 12 deletions src/app/app.settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Position } from './types';
import { Convert } from './lib/convert';

// validate supplied settings against base config
export function validateConfig(settings: IAppConfig): boolean {
Expand Down Expand Up @@ -211,6 +212,9 @@ export function cleanConfig(

if (typeof settings.resources === 'undefined') {
settings.resources = {
fetchFilter:
'?position=[%map:longitude%,%map:latitude%]&distance=%fetch:radius%',
fetchRadius: 0,
notes: {
rootFilter:
'?position=[%map:longitude%,%map:latitude%]&distance=%note:radius%',
Expand All @@ -231,16 +235,13 @@ export function cleanConfig(
if (typeof settings.resources.paths === 'undefined') {
settings.resources.paths = [];
}
}
// update rootFilter params
if (typeof settings.resources.notes.rootFilter !== 'undefined') {
settings.resources.notes.rootFilter =
settings.resources.notes.rootFilter.replace('dist=', 'distance=');
settings.resources.notes.rootFilter =
settings.resources.notes.rootFilter.replace(
`position=%map:latitude%,%map:longitude%`,
`position=[%map:longitude%,%map:latitude%]`
);
if (typeof settings.resources.fetchFilter === 'undefined') {
settings.resources.fetchFilter =
'?position=[%map:longitude%,%map:latitude%]&distance=%fetch:radius%';
}
if (typeof settings.resources.fetchRadius === 'undefined') {
settings.resources.fetchRadius = 0;
}
}

// apply url params
Expand Down Expand Up @@ -325,7 +326,7 @@ export const DefaultConfig: IAppConfig = {
windVectors: true, // display vessel TWD, AWD vectors
laylines: false,
cogLine: 10, // self COG line time (mins)
aisCogLine: 10, // self COG line time (mins)
aisCogLine: 10, // ais COG line time (mins)
headingLineSize: -1 // mode for display of heading line -1 = default
},
positionFormat: 'XY',
Expand Down Expand Up @@ -378,8 +379,12 @@ export const DefaultConfig: IAppConfig = {
},
resources: {
// ** resource options
fetchFilter:
'?position=[%map:longitude%,%map:latitude%]&distance=%fetch:radius%',
fetchRadius: 0, // radius (NM/km) within which to return resources
notes: {
rootFilter: '?position=%map:latitude%,%map:longitude%&dist=%note:radius%', // param string to provide record filtering
rootFilter:
'?position=[%map:longitude%,%map:latitude%]&distance=%note:radius%', // param string to provide record filtering
getRadius: 20, // radius (NM/km) within which to return notes
groupNameEdit: false,
groupRequiresPosition: true
Expand Down Expand Up @@ -506,6 +511,8 @@ export interface IAppConfig {
};
resources: {
// ** resource options
fetchFilter: string; // param string to provide record filtering
fetchRadius: number; // radius (NM/km) within which to return resources
notes: {
rootFilter: string; // param string to provide record filtering
getRadius: number; // radius (NM/km) within which to return notes
Expand All @@ -519,3 +526,40 @@ export interface IAppConfig {
paths: string[];
};
}

// ** process url tokens
export const processUrlTokens = (s: string, config: IAppConfig): string => {
if (!s) {
return s;
}
const ts = s.split('%');
if (ts.length > 1) {
const uts = ts.map((i) => {
if (i === 'map:latitude') {
return config.map.center[1];
} else if (i === 'map:longitude') {
return config.map.center[0];
} else if (i === 'note:radius') {
const dist =
config.units.distance === 'm'
? config.resources.notes.getRadius
: Math.floor(
Convert.nauticalMilesToKm(config.resources.notes.getRadius)
);
return dist * 1000;
} else if (i === 'fetch:radius') {
const dist =
config.units.distance === 'm'
? config.resources.notes.getRadius
: Math.floor(
Convert.nauticalMilesToKm(config.resources.fetchRadius)
);
return dist * 1000;
} else {
return i;
}
});
s = uts.join('');
}
return s;
};
15 changes: 9 additions & 6 deletions src/app/modules/autopilot/autopilot.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,18 @@ import { SKStreamFacade } from 'src/app/modules';
export class AutopilotComponent {
protected autopilotOptions = { modes: [], states: [] };
private deltaSub: Subscription;
private autopilotApiPath = 'vessels/self/steering/autopilot/default';
private autopilotApiPath: string;

constructor(
protected app: AppInfo,
private signalk: SignalKClient,
private stream: SKStreamFacade,
private cdr: ChangeDetectorRef
) {}
) {
this.autopilotApiPath = this.app.data.autopilot.isLocal
? 'vessels/self/steering/autopilot/default'
: 'vessels/self/autopilots/_default';
}

ngOnInit() {
this.deltaSub = this.stream.delta$().subscribe((e: UpdateMessage) => {
Expand Down Expand Up @@ -192,16 +196,15 @@ export class AutopilotComponent {
}

targetAdjust(value: number) {
const rad = value ? Convert.degreesToRadians(value) : 0;
if (!rad) {
if (typeof value !== 'number') {
return;
}
this.signalk.api
.put(this.app.skApiVersion, `${this.autopilotApiPath}/target/adjust`, {
value: rad
value: value,
units: 'deg'
})
.subscribe(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
() => {
this.app.debug(`Target adjusted: ${value} deg.`);
},
Expand Down
59 changes: 43 additions & 16 deletions src/app/modules/map/fb-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,23 +1755,18 @@ export class FBMapComponent implements OnInit, OnDestroy {

// ** called by onMapMove() to render features within map extent
private renderMapContents() {
if (this.fetchNotes()) {
if (this.shouldFetchNotes()) {
this.skres.getNotes();
this.app.debug(`fetching Notes...`);
}
if (this.shouldFetchResourceSets()) {
this.app.debug(`fetching ResourceSets...`);
this.skresOther.getItemsInBounds();
}
}

// ** returns true if skres.getNotes() should be called
private fetchNotes() {
this.display.layer.notes =
this.app.config.notes &&
this.app.config.map.zoomLevel >= this.app.config.selections.notesMinZoom;

this.app.debug(`lastGet: ${this.app.data.lastGet}`);
this.app.debug(`getRadius: ${this.app.config.resources.notes.getRadius}`);
if (this.fbMap.zoomLevel < this.app.config.selections.notesMinZoom) {
return false;
}
// returns true when map center has moved a distance > (threshold / 2)
private mapMoveThresholdExceeded(threshold: number): boolean {
if (!this.app.data.lastGet) {
this.app.data.lastGet = this.app.config.map.center;
return true;
Expand All @@ -1785,14 +1780,46 @@ export class FBMapComponent implements OnInit, OnDestroy {
// ** if d is more than half the getRadius
const cr =
this.app.config.units.distance === 'ft'
? Convert.nauticalMilesToKm(this.app.config.resources.notes.getRadius) *
1000
: this.app.config.resources.notes.getRadius * 1000;
? Convert.nauticalMilesToKm(threshold) * 1000
: threshold * 1000;

this.app.debug(`mapMoveThresholdExceeded: ${d >= cr / 2}`);
if (d >= cr / 2) {
this.app.data.lastGet = this.app.config.map.center;
return true;
} else {
return false;
}
}

// ** returns true if skresOther.getItemsInBounds() should be called
private shouldFetchResourceSets() {
if (
this.app.config.resources.fetchRadius &&
this.app.config.resources.fetchFilter
) {
if (!this.skresOther.hasSelections()) {
return false;
}
return this.mapMoveThresholdExceeded(50);
} else {
return false;
}
return false;
}

// ** returns true if skres.getNotes() should be called
private shouldFetchNotes() {
this.display.layer.notes =
this.app.config.notes &&
this.app.config.map.zoomLevel >= this.app.config.selections.notesMinZoom;

this.app.debug(`lastGet: ${this.app.data.lastGet}`);
this.app.debug(`getRadius: ${this.app.config.resources.notes.getRadius}`);
if (this.fbMap.zoomLevel < this.app.config.selections.notesMinZoom) {
return false;
}
return this.mapMoveThresholdExceeded(
this.app.config.resources.notes.getRadius
);
}
}
9 changes: 8 additions & 1 deletion src/app/modules/map/popovers/resource-popover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ id: string - resource id
(click)="emitModify()"
matTooltip="Modify / Move"
matTooltipPosition="after"
[disabled]="this.ctrl.isReadOnly"
>
<mat-icon>touch_app</mat-icon>
MOVE
Expand All @@ -97,6 +98,7 @@ id: string - resource id
(click)="emitDelete()"
matTooltip="Delete"
matTooltipPosition="after"
[disabled]="this.ctrl.isReadOnly"
>
<mat-icon>delete</mat-icon>
DELETE
Expand Down Expand Up @@ -220,7 +222,8 @@ export class ResourcePopoverComponent {
showNotesButton: false,
canActivate: false,
isActive: false,
activeText: 'ACTIVE'
activeText: 'ACTIVE',
isReadOnly: false
};

constructor(public app: AppInfo) {}
Expand Down Expand Up @@ -293,6 +296,7 @@ export class ResourcePopoverComponent {
this.ctrl.showAddNoteButton = false;
this.ctrl.showPointsButton = false;
this.ctrl.showRelatedButton = false;
this.ctrl.isReadOnly = this.resource[1].feature.properties?.readOnly;
this.properties = [];
if (this.resource[1].name) {
this.properties.push(['Name', this.resource[1].name]);
Expand Down Expand Up @@ -334,6 +338,7 @@ export class ResourcePopoverComponent {
this.ctrl.showAddNoteButton = false;
this.ctrl.showRelatedButton = false;
this.ctrl.showDeleteButton = this.ctrl.isActive ? false : true;
this.ctrl.isReadOnly = this.resource[1].feature.properties?.readOnly;
}
this.properties = [];
this.properties.push(['Name', this.resource[1].name]);
Expand Down Expand Up @@ -366,6 +371,7 @@ export class ResourcePopoverComponent {
: false;
this.properties = [];
this.properties.push(['Name', this.resource[1].name]);
this.ctrl.isReadOnly = this.resource[1].properties?.readOnly;
}

parseRegion() {
Expand All @@ -380,6 +386,7 @@ export class ResourcePopoverComponent {
this.ctrl.showNotesButton = true;
this.ctrl.showPointsButton = false;
this.ctrl.showRelatedButton = false;
this.ctrl.isReadOnly = this.resource[1].feature.properties?.readOnly;
this.properties = [];
this.properties.push(['Name', this.resource[1].name]);
this.properties.push(['Description', this.resource[1].description]);
Expand Down
Loading

0 comments on commit edbda5d

Please sign in to comment.