Skip to content

Commit

Permalink
feat: Support 3d point/location
Browse files Browse the repository at this point in the history
Add support for z for point and location
  • Loading branch information
DKaminari committed Mar 13, 2019
1 parent dc667ab commit 6673102
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/arcgis-rest-common-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ export type SpatialRelationship =
export interface IExtent {
xmin: number;
ymin: number;
zmin?: number;
xmax: number;
ymax: number;
zmax?: number;
spatialReference?: ISpatialReference;
}

Expand Down Expand Up @@ -272,6 +274,7 @@ export interface IPictureMarkerSymbol extends IMarkerSymbol, IPictureSourced {
export interface IPoint extends IHasZM, IGeometry {
x: number;
y: number;
z?: number;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/arcgis-rest-common/src/types/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IGeometry {
export interface IPoint extends IHasZM, IGeometry {
x: number;
y: number;
z?: number;
}

/**
Expand All @@ -44,4 +45,5 @@ export interface ILocation {
longitude?: number;
lat?: number;
long?: number;
z?: number;
}
11 changes: 7 additions & 4 deletions packages/arcgis-rest-common/src/util/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import { IPoint, ILocation } from "../types/geometry";

export function isLocationArray(
coords: ILocation | IPoint | [number, number]
): coords is [number, number] {
return (coords as [number, number]).length === 2;
coords: ILocation | IPoint | [number, number] | [number, number, number]
): coords is [number, number] | [number, number, number] {
return (
(coords as [number, number]).length === 2 ||
(coords as [number, number, number]).length === 3
);
}

export function isLocation(
coords: ILocation | IPoint | [number, number]
coords: ILocation | IPoint | [number, number] | [number, number, number]
): coords is ILocation {
return (
(coords as ILocation).latitude !== undefined ||
Expand Down
70 changes: 70 additions & 0 deletions packages/arcgis-rest-common/test/location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const stops: Array<[number, number]> = [
[-117.918976, 33.812092]
];

const stops3: Array<[number, number, number]> = [
[-117.195677, 34.056383, 10.11],
[-117.918976, 33.812092, 8.43]
];

const stopsObjectsLatLong: ILocation[] = [
{
lat: 34.056383,
Expand All @@ -22,6 +27,19 @@ const stopsObjectsLatLong: ILocation[] = [
}
];

const stopsObjectsLatLong3: ILocation[] = [
{
lat: 34.056383,
long: -117.195677,
z: 10.11
},
{
lat: 33.812092,
long: -117.918976,
z: 8.43
}
];

const stopsObjectsLatitudeLongitude: ILocation[] = [
{
latitude: 34.056383,
Expand All @@ -33,6 +51,19 @@ const stopsObjectsLatitudeLongitude: ILocation[] = [
}
];

const stopsObjectsLatitudeLongitude3: ILocation[] = [
{
latitude: 34.056383,
longitude: -117.195677,
z: 10.11
},
{
latitude: 33.812092,
longitude: -117.918976,
z: 8.43
}
];

const stopsObjectsPoint: IPoint[] = [
{
x: 34.056383,
Expand All @@ -44,30 +75,69 @@ const stopsObjectsPoint: IPoint[] = [
}
];

const stopsObjectsPoint3: IPoint[] = [
{
x: 34.056383,
y: -117.195677,
z: 10.11
},
{
x: 33.812092,
y: -117.918976,
z: 8.43
}
];

describe("location helpers", () => {
it("should recognize a shorthand location", done => {
expect(isLocation(stopsObjectsLatLong[0])).toEqual(true);
done();
});

it("should recognize a shorthand 3d location", done => {
expect(isLocation(stopsObjectsLatLong3[0])).toEqual(true);
done();
});

it("should recognize a spelled out location", done => {
expect(isLocation(stopsObjectsLatitudeLongitude[0])).toEqual(true);
done();
});

it("should recognize a spelled out 3d location", done => {
expect(isLocation(stopsObjectsLatitudeLongitude[0])).toEqual(true);
done();
});

it("should recognize that a point is not a location", done => {
expect(isLocation(stopsObjectsPoint[0])).toEqual(false);
done();
});

it("should recognize that a 3d point is not a location", done => {
expect(isLocation(stopsObjectsPoint3[0])).toEqual(false);
done();
});

it("should recognize that raw coordinates are not a location", done => {
expect(isLocation(stops[0])).toEqual(false);
done();
});

it("should recognize that raw 3d coordinates are not a location", done => {
expect(isLocation(stops3[0])).toEqual(false);
done();
});

it("should recognize a location array", done => {
expect(isLocationArray(stops[0])).toEqual(true);
expect(isLocationArray(stops[1])).toEqual(true);
done();
});

it("should recognize a 3d location array", done => {
expect(isLocationArray(stops3[0])).toEqual(true);
expect(isLocationArray(stops3[1])).toEqual(true);
done();
});
});

0 comments on commit 6673102

Please sign in to comment.