From 66731024e8688ef47536280c558ee9c08799b698 Mon Sep 17 00:00:00 2001 From: Daramora Kaminari Date: Wed, 13 Mar 2019 08:22:22 +0300 Subject: [PATCH] feat: Support 3d point/location Add support for z for point and location --- .../arcgis-rest-common-types/src/index.ts | 3 + .../arcgis-rest-common/src/types/geometry.ts | 2 + .../arcgis-rest-common/src/util/location.ts | 11 +-- .../arcgis-rest-common/test/location.test.ts | 70 +++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/packages/arcgis-rest-common-types/src/index.ts b/packages/arcgis-rest-common-types/src/index.ts index ce1d5409ff..de9c017a3b 100644 --- a/packages/arcgis-rest-common-types/src/index.ts +++ b/packages/arcgis-rest-common-types/src/index.ts @@ -149,8 +149,10 @@ export type SpatialRelationship = export interface IExtent { xmin: number; ymin: number; + zmin?: number; xmax: number; ymax: number; + zmax?: number; spatialReference?: ISpatialReference; } @@ -272,6 +274,7 @@ export interface IPictureMarkerSymbol extends IMarkerSymbol, IPictureSourced { export interface IPoint extends IHasZM, IGeometry { x: number; y: number; + z?: number; } /** diff --git a/packages/arcgis-rest-common/src/types/geometry.ts b/packages/arcgis-rest-common/src/types/geometry.ts index 9a6b5b3758..9e1830a4a2 100644 --- a/packages/arcgis-rest-common/src/types/geometry.ts +++ b/packages/arcgis-rest-common/src/types/geometry.ts @@ -34,6 +34,7 @@ export interface IGeometry { export interface IPoint extends IHasZM, IGeometry { x: number; y: number; + z?: number; } /** @@ -44,4 +45,5 @@ export interface ILocation { longitude?: number; lat?: number; long?: number; + z?: number; } diff --git a/packages/arcgis-rest-common/src/util/location.ts b/packages/arcgis-rest-common/src/util/location.ts index 6869b6c585..7356d57b1c 100644 --- a/packages/arcgis-rest-common/src/util/location.ts +++ b/packages/arcgis-rest-common/src/util/location.ts @@ -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 || diff --git a/packages/arcgis-rest-common/test/location.test.ts b/packages/arcgis-rest-common/test/location.test.ts index 8bc1379b92..cce7320bb3 100644 --- a/packages/arcgis-rest-common/test/location.test.ts +++ b/packages/arcgis-rest-common/test/location.test.ts @@ -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, @@ -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, @@ -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, @@ -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(); + }); });