Skip to content

Commit

Permalink
feat: initial release (#3)
Browse files Browse the repository at this point in the history
* chore: port of mgrs-java 2.1 (#1)

* chore: port of GridLine.java and GridType.java

* chore: port of Grid.java

* chore: port of GridLabel.java

* chore: port of GridLabeler.java

* chore: port of Grids.java

* chore: port of MGRSLabeler.java

* chore: port of ZoomGrids.java

* chore: port of BandLetterRange.java

* chore: port of GridRange.java minus the iterator

* chore: port of GridZone.java

* chore: port of GridZones.java

* chore: port of GZDLabeler.java

* chore: port of LatitudeBand.java

* chore: port of LongitudinalString.java

* chore: port of ZoneNumberRange.java

* chore: port of MGRSProperties.java

* chore: port of UTM.java

* chore: port of MGRS.java

* chore: port of MGRSConstants.ts

* chore: port of MGRSUtils.java

* fix: correct majority of build errors

* chore: port of mgrs.properties

* fix: dropping decimal parts

* fix: dropping decimal part

* fix: using toFixed(2) in place of javas decimalformatter

* fix: fixing compile error on longest line of code known to ever exist

* fix: fixing more simple compile errors

* revert: removing temp changes to tsconfig.json

* fix: more compiler fixes

* fix: handling case where no easting intersection

* fix: fixing compile errors for regexp

* fix: removing locale from getEastingAndNorthing (need to resolve)

* refactor: results of npm run format

* test: adding mocha config and 1 test

* chore: port of GridTypeTest.java

* fix: correcting enum ordinal calculation

* refactor: fixing lint errors

* chore: port of BandLetterRangeTest.java

* chore: port of testZoneNumbers in GridZonesTest.java

* chore: port of testBandLetters from GridZonesTest.java

* fix: fixing char math

* chore: port of MGRSTest.java.  not compiling.

* fix: adding checks for null/not null, and fails

* fix: fixing all compile errors. still failing.

* fix: fixing passing row for column value in constructor

* fix: properly removing all spaces from a string in MGRS

* fix: fixing toString to passing METER GridType

* feat: using decimal-format to more closely mirror java

* fix: correcting string equality with case ignored

* fix:  removing decimal from easting and northing

* feat: bump of grid-js

* fix: Correct null check on a number and fixing tests

* lint: fixing all lint errors

* chore: adding exports to index

* chore: code formatting

* feat: bump to rc.0 of grid

* ci: moving prettier to a lint action

* feat: bump to version 1.1.0 of grid-js

* doc: updating README

* test: skipping test draw tile of Readme.spec.ts due to timeout.  Need to fix

* feat: bump to version 1.2.0 of grid-js

* test: add GridLine test

* lint: fixing lint errors

* test: adding Grid test

* test: adding Grids test

* chore: implementing iterator of GridRange

* test: adding GridRange test

* test: add ZoneNumberRange test

* lint: fixing lint errors

* test: adding UTM test

* lint: fixing lint errors

* ci: Removing prettier, which is captured in lint run

* test: adding MGRSUtils test

* test: adding MGRSUtils test

* fix: adding comparable interface to Grid for proper sorting

* lint: fixing linter

* lint: fix lint errors

* test: adding compare tests

* doc: adding remote dependencies

* doc: replacing java with javascript

* doc: fixing spelling error

* doc: renaming color to mgrs

* test: adding isUTM test

* lint: fixing lint which I constantly forget to do

* test: adding final tests

* doc: removing @author

* feat: bump to 2.0.0 grid-js

* fix: correcting issues with newer version of grid

* doc: moving build status to top of readme

* chore: cleaning up bad comments

* test: adding more grid tests

* feat: bump to 2.1 of grid-js

* lint: fixing lint errors

* 1.0.0
  • Loading branch information
gillandk authored Oct 27, 2022
1 parent b3e0ed0 commit bfe1eb8
Show file tree
Hide file tree
Showing 42 changed files with 990 additions and 497 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Please fill out as much known and relevant information as possible.

#### Version Information:

* Color Javascript Version:
* Color Javascript Source: (e.g. Central Repository, Release, Source Code Build)
* MGRS Javascript Version:
* MGRS Javascript Source: (e.g. Central Repository, Release, Source Code Build)
* IDE Name & Version:
* NPM Version: (npm --version)
* Node Version: (node --version)
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
blank_issues_enabled: false
contact_links:
- name: Discussions
url: https://github.com/ngageoint/color-js/discussions
url: https://github.com/ngageoint/mgrs-js/discussions
about: Questions, Feature Requests, Feedback, Conversations
14 changes: 3 additions & 11 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v1

- name: Install
- name: Install Dependencies
run: npm ci

- name: Build
Expand All @@ -26,17 +26,9 @@ jobs:
- name: Coverage
run: npm run coverage

- name: Coveralls
- name: Upload Coverage
uses: coverallsapp/github-action@master
if: github.ref_name == 'master'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./docs/coverage/lcov.info

- name: Prettify code
uses: creyD/[email protected]
if: github.ref_name == 'master'
with:
prettier_options: --write \"lib/**/*.ts\" \"test/**/*.ts\""
only_changed: True
github_token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./docs/coverage/lcov.info
87 changes: 80 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# MGRS Java
# MGRS Javascript

![Build & Test](https://github.com/ngageoint/mgrs-js/actions/workflows/build-test.yml/badge.svg)
[![NPM](https://img.shields.io/npm/v/@ngageoint/mgrs-js.svg)](https://www.npmjs.com/package/@ngageoint/mgrs-js)
[![Coverage Status](https://coveralls.io/repos/github/ngageoint/mgrs-js/badge.svg)](https://coveralls.io/github/ngageoint/mgrs-js)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

#### Military Grid Reference System Lib ####

Expand All @@ -11,11 +16,79 @@ Software source code previously released under an open source license and then m

### About ###

[MGRS](http://ngageoint.github.io/mgrs-js/) is a Java library providing Military Grid Reference System functionality, a geocoordinate standard used by NATO militaries for locating points on Earth.
[MGRS](http://ngageoint.github.io/mgrs-js/) is a Javascript library providing Military Grid Reference System functionality, a geocoordinate standard used by NATO militaries for locating points on Earth.

### Build and Installation ###
#### Coordinates ####

![Build & Test](https://github.com/ngageoint/mgrs-js/actions/workflows/build-test.yml/badge.svg)
[![NPM](https://img.shields.io/npm/v/@ngageoint/mgrs-js.svg)](https://www.npmjs.com/package/@ngageoint/mgrs-js)
[![Coverage Status](https://coveralls.io/repos/github/ngageoint/mgrs-js/badge.svg)](https://coveralls.io/github/ngageoint/mgrs-js)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
```javascript
const mgrs = MGRS.parse('33XVG74594359');
const point = mgrs.toPoint();
const pointMeters = point.toMeters();
const utm = mgrs.toUTM();
const utmCoordinate = utm.toString();
const point2 = utm.toPoint();

const mgrs2 = MGRS.parse('33X VG 74596 43594');

const latitude = 63.98862388;
const longitude = 29.06755082;
const point3 = Point.point(longitude, latitude);
const mgrs3 = MGRS.from(point3);
const mgrsCoordinate = mgrs3.toString();
const mgrsGZD = mgrs3.coordinate(GridType.GZD);
const mgrs100k = mgrs3.coordinate(GridType.HUNDRED_KILOMETER);
const mgrs10k = mgrs3.coordinate(GridType.TEN_KILOMETER);
const mgrs1k = mgrs3.coordinate(GridType.KILOMETER);
const mgrs100m = mgrs3.coordinate(GridType.HUNDRED_METER);
const mgrs10m = mgrs3.coordinate(GridType.TEN_METER);
const mgrs1m = mgrs3.coordinate(GridType.METER);

const utm2 = UTM.from(point3);
const mgrs4 = utm2.toMGRS();

const utm3 = UTM.parse('18 N 585628 4511322');
const mgrs5 = utm3.toMGRS();
```

#### Draw Tile Template ####

See [mgrs-android](https://github.com/ngageoint/mgrs-android) for a concrete example

```javascript
// GridTile tile = ...;

const grids = Grids.create();

const zoomGrids = grids.getGrids(tile.getZoom());
if (zoomGrids && zoomGrids.hasGrids()) {
const gridRange = GridZones.getGridRange(tile.getBounds()!);

for (const grid of zoomGrids) {
// draw this grid for each zone
for (const zone of gridRange) {
const lines = grid.getLinesFromGridTile(tile, zone);
if (lines) {
const pixelRange = zone.getBounds().getPixelRangeFromTile(tile);
for (const line of lines) {
const pixel1 = line.getPoint1().getPixelFromTile(tile);
const pixel2 = line.getPoint2().getPixelFromTile(tile);
// Draw line
}
}

const labels = grid.getLabelsFromGridTile(tile, zone);
if (labels) {
for (const label of labels) {
const pixelRange = label.getBounds()?.getPixelRangeFromTile(tile);
const centerPixel = label.getCenter()?.getPixelFromTile(tile);
// Draw label
}
}
}
}
}
```
### Remote Dependencies ###
* [Grid Javascript](https://github.com/ngageoint/grid-js) (The MIT License (MIT)) - Grid Library
3 changes: 0 additions & 3 deletions lib/MGRS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { MGRSUtils } from './MGRSUtils';

/**
* Military Grid Reference System Coordinate
*
* @author wnewman
* @author osbornb
*/
export class MGRS {
/**
Expand Down
2 changes: 0 additions & 2 deletions lib/MGRSConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { GridConstants } from '@ngageoint/grid-js';

/**
* Military Grid Reference System Constants
*
* @author osbornb
*/
export class MGRSConstants {
/**
Expand Down
7 changes: 2 additions & 5 deletions lib/MGRSUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { MGRSConstants } from './MGRSConstants';

/**
* Military Grid Reference System utilities
*
* @author wnewman
* @author osbornb
*/
export class MGRSUtils {
/**
Expand Down Expand Up @@ -35,8 +32,8 @@ export class MGRSUtils {
*/
public static validateBandLetter(letter: string): void {
if (
letter < MGRSConstants.MIN_BAND_LETTER ||
letter > MGRSConstants.MAX_BAND_LETTER ||
letter.charCodeAt(0) < MGRSConstants.MIN_BAND_LETTER.charCodeAt(0) ||
letter.charCodeAt(0) > MGRSConstants.MAX_BAND_LETTER.charCodeAt(0) ||
GridUtils.isOmittedBandLetter(letter)
) {
throw new Error('Illegal band letter (CDEFGHJKLMNPQRSTUVWX): ' + letter);
Expand Down
3 changes: 0 additions & 3 deletions lib/features/GridLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { GridType } from '../grid/GridType';

/**
* Line between two points
*
* @author wnewman
* @author osbornb
*/
export class GridLine extends Line {
/**
Expand Down
82 changes: 55 additions & 27 deletions lib/grid/Grid.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Color } from '@ngageoint/color-js';
import { BaseGrid, Bounds, GridStyle, GridTile, PropertyConstants } from '@ngageoint/grid-js';
import { IComparable } from 'tstl';
import { GridLine } from '../features/GridLine';
import { GridZone } from '../gzd/GridZone';
import { MGRSProperties } from '../property/MGRSProperties';
import { GridLabel } from './GridLabel';
import { GridLabeler } from './GridLabeler';
import { GridType } from './GridType';
import { GridTypeUtils } from './GridTypeUtils';

/**
* Grid
*
* @author wnewman
* @author osbornb
*/
export class Grid extends BaseGrid {
export class Grid extends BaseGrid implements IComparable<Grid> {
/**
* Default line width
*/
Expand Down Expand Up @@ -80,14 +79,19 @@ export class Grid extends BaseGrid {
* grid type
* @return grid type line style
*/
public getStyleFromGridType(gridType: GridType): GridStyle {
let style: GridStyle | undefined;
if (gridType === this.type) {
style = this.getStyle();
public getStyle(gridType?: GridType): GridStyle {
let style: GridStyle;
if (gridType !== null && gridType !== undefined) {
if (gridType === this.type) {
style = super.getStyle();
} else {
style = this.styles.get(gridType)!;
}
} else {
style = this.styles.get(gridType);
style = super.getStyle();
}
return style!;

return style;
}

/**
Expand All @@ -98,12 +102,12 @@ export class Grid extends BaseGrid {
* @return grid type line style
*/
private getOrCreateStyle(gridType: GridType): GridStyle {
let style = this.getStyleFromGridType(gridType);
let style = this.getStyle(gridType);
if (!style) {
style = new GridStyle(undefined, 0);
this.setStyleWithGridType(gridType, style);
this.setStyle(style, gridType);
}
return style;
return style!;
}

/**
Expand All @@ -114,7 +118,11 @@ export class Grid extends BaseGrid {
* @param style
* grid line style
*/
public setStyleWithGridType(gridType: GridType, style: GridStyle): void {
public setStyle(style?: GridStyle, gridType?: GridType): void {
if (gridType === null || gridType === undefined) {
gridType = this.type;
}

if (gridType < this.getPrecision()) {
throw new Error(
'Grid can not define a style for a higher precision grid type. Type: ' +
Expand All @@ -124,9 +132,9 @@ export class Grid extends BaseGrid {
);
}
if (gridType === this.type) {
this.setStyle(style);
super.setStyle(style);
} else {
this.styles.set(gridType, style != null ? style : new GridStyle(undefined, 0));
this.styles.set(gridType, style ? style : new GridStyle(undefined, 0));
}
}

Expand All @@ -144,16 +152,19 @@ export class Grid extends BaseGrid {
* grid type
* @return grid type line color
*/
public getColorFromGridType(gridType: GridType): Color {
public getColor(gridType?: GridType): Color | undefined {
let color: Color | undefined;
const style = this.getStyleFromGridType(gridType);
if (style) {
color = style.getColor();
if (gridType !== null && gridType !== undefined) {
const style = this.getStyle(gridType);
if (style) {
color = style.getColor();
}
}
if (!color) {
color = this.getColor();
color = super.getColor();
}
return color!;

return color;
}

/**
Expand All @@ -164,7 +175,10 @@ export class Grid extends BaseGrid {
* @param color
* grid line color
*/
public setColorWithGridType(gridType: GridType, color: Color): void {
public setColor(color?: Color, gridType?: GridType): void {
if (gridType === null || gridType === undefined) {
gridType = this.type;
}
this.getOrCreateStyle(gridType).setColor(color);
}

Expand All @@ -175,14 +189,14 @@ export class Grid extends BaseGrid {
* grid type
* @return grid type line width
*/
public getWidthFromGridType(gridType: GridType): number {
public getWidth(gridType?: GridType): number {
let width = 0;
const style = this.getStyleFromGridType(gridType);
const style = this.getStyle(gridType);
if (style) {
width = style.getWidth();
}
if (width === 0) {
width = this.getWidth();
width = super.getWidth();
}
return width;
}
Expand All @@ -195,7 +209,10 @@ export class Grid extends BaseGrid {
* @param width
* grid line width
*/
public setWidthWithGridType(gridType: GridType, width: number): void {
public setWidth(width: number, gridType?: GridType): void {
if (gridType === null || gridType === undefined) {
gridType = this.type;
}
this.getOrCreateStyle(gridType).setWidth(width);
}

Expand Down Expand Up @@ -315,6 +332,13 @@ export class Grid extends BaseGrid {
return precision;
}

public hashCode(): number {
const prime = 31;
let result = 1;
result = prime * result + (!this.type ? 0 : GridTypeUtils.hashCode(this.type));
return result;
}

/**
* {@inheritDoc}
*/
Expand All @@ -326,4 +350,8 @@ export class Grid extends BaseGrid {
if (this.type !== other.type) return false;
return true;
}

public less(other: Grid): boolean {
return this.hashCode() < other.hashCode();
}
}
3 changes: 0 additions & 3 deletions lib/grid/GridLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { GridType } from './GridType';

/**
* MGRS Grid Label
*
* @author wnewman
* @author osbornb
*/
export class GridLabel extends Label {
/**
Expand Down
2 changes: 0 additions & 2 deletions lib/grid/GridLabeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { GridType } from './GridType';

/**
* Grid Labeler
*
* @author osbornb
*/
export abstract class GridLabeler extends Labeler {
/**
Expand Down
Loading

0 comments on commit bfe1eb8

Please sign in to comment.