Skip to content

Commit

Permalink
Merge pull request #39 from dfpc-coe/basemaps
Browse files Browse the repository at this point in the history
Basemap XML Parsing
  • Loading branch information
ingalls authored Sep 17, 2024
2 parents dd498e1 + 6369b8a commit 6140120
Show file tree
Hide file tree
Showing 27 changed files with 690 additions and 109 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<h1 align=center>Node-CoT</h1>

<p align=center>Javascript Cursor-On-Target Library</p>
<p align=center>Typescript/Javascript Cursor-On-Target Library</p>

Lightweight JavaScript library for parsing and manipulating TAK related messages, primarily [Cursor-on-Target (COT)](https://git.tak.gov/standards/takcot)
Lightweight Typescript library for parsing and manipulating TAK related messages, primarily [Cursor-on-Target (COT)](https://git.tak.gov/standards/takcot)

## About

`node-cot` converts between TAK message protocols and a Javascript object/JSON format.
`node-cot` converts between TAK message protocols (XML & Protobuf) and a Javascript object/JSON format.
It also can bidirectionally convert CoT messages into [GeoJSON](https://geojson.org/)

It also support creating and parsing the following TAK Data Types

- Data Packages (CoTs, Attachments, etc)
- Basemap XML Documents

## Installation

### NPM
Expand Down
7 changes: 4 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import CoT from './lib/cot.js';
export * as Feature from './lib/feature.js'
export * as Types from './lib/types.js'
export * as CoTTypes from './lib/cot-types.js'
export * as Feature from './lib/types/feature.js'
export * as Types from './lib/types/types.js'
export * as CoTTypes from './lib/types/cot-types.js'
export * from './lib/chat.js'
export * from './lib/fileshare.js'
export * from './lib/force-delete.js'
export * from './lib/data-package.js'
export * from './lib/basemap.js'

export default CoT;
36 changes: 36 additions & 0 deletions lib/basemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Static } from '@sinclair/typebox'
import Err from '@openaddresses/batch-error';
import BasemapType from './types/basemap.js';
import xmljs from 'xml-js';
import AJV from 'ajv';

const checkBasemap = (new AJV({
allErrors: true,
coerceTypes: true,
allowUnionTypes: true
}))
.compile(BasemapType);

/**
* Helper class for creating and parsing Basemap XML documents
*/
export class Basemap {
basemap: Static<typeof BasemapType>;

constructor(basemap: Static<typeof BasemapType>) {
this.basemap = basemap;
}

/**
* Return a Basemap from a string XML representation
*/
static async parse(input: string): Promise<Basemap> {
const xml = xmljs.xml2js(input, { compact: true })

checkBasemap(xml);
if (checkBasemap.errors) throw new Err(400, null, `${checkBasemap.errors[0].message} (${checkBasemap.errors[0].instancePath})`);
const basemap = xml as Static<typeof BasemapType>;

return new Basemap(basemap);
}
}
4 changes: 2 additions & 2 deletions lib/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Util from './util.js'
import Util from './utils/util.js'
import CoT from './cot.js';
import type JSONCoT from './types.js';
import type JSONCoT from './types/types.js';
import type { Static } from '@sinclair/typebox';
import { randomUUID } from 'node:crypto';

Expand Down
12 changes: 6 additions & 6 deletions lib/cot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import type {
Polygon,
FeaturePropertyMission,
FeaturePropertyMissionLayer,
} from './feature.js';
} from './types/feature.js';
import {
InputFeature,
} from './feature.js';
} from './types/feature.js';
import type { AllGeoJSON } from "@turf/helpers";
import PointOnFeature from '@turf/point-on-feature';
import Truncate from '@turf/truncate';
import Ellipse from '@turf/ellipse';
import Util from './util.js';
import Color from './color.js';
import JSONCoT, { Detail } from './types.js'
import type { MartiDest, MartiDestAttributes, Link, LinkAttributes } from './types.js'
import Util from './utils/util.js';
import Color from './utils/color.js';
import JSONCoT, { Detail } from './types/types.js'
import type { MartiDest, MartiDestAttributes, Link, LinkAttributes } from './types/types.js'
import AJV from 'ajv';
import fs from 'fs';

Expand Down
6 changes: 3 additions & 3 deletions lib/fileshare.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Util from './util.js'
import Util from './utils/util.js'
import CoT from './cot.js';
import type JSONCoT from './types.js';
import type { FileShareAttributes } from './types.js';
import type JSONCoT from './types/types.js';
import type { FileShareAttributes } from './types/types.js';
import type { Static } from '@sinclair/typebox';

export class FileShare extends CoT {
Expand Down
4 changes: 2 additions & 2 deletions lib/force-delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Util from './util.js'
import Util from './utils/util.js'
import CoT from './cot.js';
import type JSONCoT from './types.js';
import type JSONCoT from './types/types.js';
import type { Static } from '@sinclair/typebox';

export class ForceDelete extends CoT {
Expand Down
29 changes: 29 additions & 0 deletions lib/types/basemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Type } from '@sinclair/typebox';

export const BasemapMapSource = Type.Object({
name: Type.Object({
_text: Type.String()
}),
minZoom: Type.Object({
_text: Type.Integer()
}),
maxZoom: Type.Object({
_text: Type.Integer()
}),
tileType: Type.Object({
_text: Type.String()
}),
tileUpdate: Type.Optional(Type.Object({
_text: Type.String()
})),
url: Type.Optional(Type.Object({
_text: Type.String()
})),
backgroundColor: Type.Optional(Type.Object({
_text: Type.String()
})),
})

export default Type.Object({
customMapSource: BasemapMapSource
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/util.ts → lib/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
TrackAttributes,
Detail,
Point
} from './types.js';
} from '../types/types.js';

/**
* Helper functions for generating CoT data
Expand Down
Loading

0 comments on commit 6140120

Please sign in to comment.