Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Sensor CoT Link #430

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions api/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions api/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@turf/boolean-within": "^7.1.0",
"@turf/envelope": "^7.1.0",
"@turf/point-on-feature": "^7.0.0",
"@turf/sector": "^7.1.0",
"apexcharts": "^3.0.0",
"core-js": "^3.6.4",
"cronstrue": "^2.19.0",
Expand Down Expand Up @@ -54,12 +55,12 @@
"eslint": "^9.0.0",
"eslint-plugin-vue": "^9.0.0",
"openapi-typescript": "^7.0.0",
"typescript": "5.6.2",
"typescript-eslint": "^8.3.0",
"vite": "^5.0.0",
"vite-plugin-babel": "^1.2.0",
"vite-plugin-pwa": "^0.21.0",
"vue-tsc": "2.0.29",
"typescript": "5.6.2"
"vue-tsc": "2.0.29"
},
"browserslist": [
"> 1%",
Expand Down
73 changes: 69 additions & 4 deletions api/web/src/stores/base/cot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { std } from '../../std.ts';
import { sector } from '@turf/sector';
import { bbox } from '@turf/bbox'
import { useCOTStore } from '../cots.ts'
import { useMapStore } from '../map.ts';
Expand Down Expand Up @@ -45,7 +46,9 @@ export default class COT {
_geometry: Feature["geometry"];

_store: ReturnType<typeof useCOTStore>;
origin: Origin
origin: Origin;

links: Set<string>;

constructor(feat: Feature, origin?: Origin) {
feat.properties = COT.style(feat.geometry.type, feat.properties);
Expand All @@ -58,6 +61,8 @@ export default class COT {
this._store = useCOTStore();
this.origin = origin || { mode: OriginMode.CONNECTION };

this.links = new Set();

if (!this._properties.archived) {
this._properties.archived = false
}
Expand All @@ -69,6 +74,10 @@ export default class COT {
if (this.origin.mode === OriginMode.CONNECTION) {
this._store.pending.set(this.id, this);
}

if (this._properties.sensor) {
this.link();
}
}

set properties(properties: Feature["properties"]) {
Expand All @@ -82,18 +91,66 @@ export default class COT {
set geometry(geometry: Feature["geometry"]) {
this.update({ geometry })
}

get geometry() {
return this._geometry;
}

link(): void {
if (this._properties.sensor) {
const id = `${this.id}-sensor`

let updated = false;

console.error('SENSOR RANGE', this._properties.sensor.range)

if (this.links.has(id)) {
const cot = this._store.get(id);
if (cot) {
updated = true;

cot.geometry = sector(
this._properties.center,
(this._properties.sensor.range || 10) / 1000,
this._properties.sensor.azimuth,
this._properties.sensor.azimuth + this._properties.sensor.fov,
).geometry
}
}

if (!updated) {
// TODO Use NodeCoT & Respect Sensor Style if present
new COT({
id,
type: 'Feature',
properties: {
callsign: '',
type: 'u-d-p',
stroke: '#ffffff',
'stroke-width': 1,
'stroke-opacity': 1,
fill: '#ffffff',
'fill-opacity': 0.2
},
geometry: sector(
this._properties.center,
(this._properties.sensor.range || 10) / 1000,
this._properties.sensor.azimuth,
this._properties.sensor.azimuth + this._properties.sensor.fov,
).geometry
});

this.links.add(id)
}
}
}

/**
* Update the COT and return a boolean as to whether the COT needs to be re-rendered
*/
async update(update: {
update(update: {
properties?: Feature["properties"],
geometry?: Feature["geometry"]
}): Promise<boolean> {
}): boolean {
let changed = false;
if (update.geometry) {
//TODO Detect Geometry changes, use centroid?!
Expand All @@ -110,6 +167,14 @@ export default class COT {
break;
}
}

if (update.properties.sensor) {
this.link();
} else if (this._properties.sensor && !update.properties.sensor) {
// TODO Unlink & cleanup
}

this._properties = update.properties;
}

if (!this._properties.center) {
Expand Down
Loading