Skip to content

Commit

Permalink
Merge 2560ed8 into ab8fef0
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinr committed Nov 9, 2018
2 parents ab8fef0 + 2560ed8 commit dd5a2c8
Show file tree
Hide file tree
Showing 23 changed files with 1,785 additions and 114 deletions.
206 changes: 103 additions & 103 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/arcgis-rest-common-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"include": [
"src/**/*.ts"
]
}
}
57 changes: 57 additions & 0 deletions packages/arcgis-rest-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[![npm version][npm-img]][npm-url]
[![build status][travis-img]][travis-url]
[![Coverage Status][coverage-img]][coverage-url]
[![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE)

[npm-img]: https://img.shields.io/npm/v/@esri/arcgis-rest-common.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-common
[travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js
[coverage-img]: https://coveralls.io/repos/github/Esri/arcgis-rest-js/badge.svg
[coverage-url]: https://coveralls.io/github/Esri/arcgis-rest-js

# @esri/arcgis-rest-common

> Shared utility methods for [`@esri/arcgis-rest-js`](https://github.com/Esri/arcgis-rest-js).
### Example

```bash
npm install @esri/arcgis-rest-common
```

### [API Reference](https://esri.github.io/arcgis-rest-js/api/common/)

### Issues

If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you.

If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss).

### Versioning

For transparency into the release cycle and in striving to maintain backward compatibility, @esri/arcgis-rest-js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible.

For more information on SemVer, please visit <http://semver.org/>.

### Contributing

Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md).

### License

Copyright &copy; 2018 Esri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

> http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

A copy of the license is available in the repository's [LICENSE](../../LICENSE) file.
11 changes: 11 additions & 0 deletions packages/arcgis-rest-common/package-lock.json

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

43 changes: 43 additions & 0 deletions packages/arcgis-rest-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@esri/arcgis-rest-common",
"version": "1.13.2",
"description": "Shared utility methods for @esri/arcgis-rest-js",
"main": "dist/node/index.js",
"browser": "dist/umd/common.umd.js",
"module": "dist/esm/index.js",
"js:next": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"license": "Apache-2.0",
"files": [
"dist/**"
],
"dependencies": {
"tslib": "^1.9.3"
},
"devDependencies": {},
"peerDependencies": {},
"scripts": {
"prepare": "npm run build",
"build": "npm run build:node && npm run build:umd && npm run build:esm",
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node",
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration",
"dev:umd": "rollup -w -c ../../umd-base-profile.js",
"dev:node": "tsc -w --module commonjs --outDir ./dist/node"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Esri/arcgis-rest-js.git"
},
"contributors": [
"John Gravois <john@esri.com>"
],
"bugs": {
"url": "https://github.com/Esri/arcgis-rest-js/issues"
},
"homepage": "https://github.com/Esri/arcgis-rest-js#readme"
}
10 changes: 10 additions & 0 deletions packages/arcgis-rest-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

// utility methods
export * from "./util/location";

// types
export * from "./types/feature";
export * from "./types/geometry";
export * from "./types/symbol";
14 changes: 14 additions & 0 deletions packages/arcgis-rest-common/src/types/feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { IGeometry } from "./geometry";
import { ISymbol } from "./symbol";

/**
* a spatial entity and its corresponding properties
*/
export interface IFeature {
geometry?: IGeometry;
attributes: { [key: string]: any };
symbol?: ISymbol;
}
47 changes: 47 additions & 0 deletions packages/arcgis-rest-common/src/types/geometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

/**
*
*/
export interface IHasZM {
hasZ?: boolean;
hasM?: boolean;
}

/**
* Spatial reference systems define mathematical transformations and coordinate systems for displaying spatial information in 2D and 3D.
*/
export interface ISpatialReference {
wkid?: number;
latestWkid?: number;
vcsWkid?: number;
latestVcsWkid?: number;
wkt?: string;
latestWkt?: string;
}

/**
* a building block for discrete geometries
*/
export interface IGeometry {
spatialReference?: ISpatialReference;
}

/**
* A simple point geometry, with spatial reference defined.
*/
export interface IPoint extends IHasZM, IGeometry {
x: number;
y: number;
}

/**
*
*/
export interface ILocation {
latitude?: number;
longitude?: number;
lat?: number;
long?: number;
}
21 changes: 21 additions & 0 deletions packages/arcgis-rest-common/src/types/symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

/**
*
*/
export type SymbolType =
| "esriSLS"
| "esriSMS"
| "esriSFS"
| "esriPMS"
| "esriPFS"
| "esriTS";

/**
*
*/
export interface ISymbol {
type: SymbolType;
style?: string;
}
19 changes: 19 additions & 0 deletions packages/arcgis-rest-common/src/util/location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

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;
}

export function isLocation(
coords: ILocation | IPoint | [number, number]
): coords is ILocation {
return (
(coords as ILocation).latitude !== undefined ||
(coords as ILocation).lat !== undefined
);
}
73 changes: 73 additions & 0 deletions packages/arcgis-rest-common/test/location.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { IPoint } from "../../arcgis-rest-common-types/src";
import { ILocation } from "../src/types/geometry";
import { isLocation, isLocationArray } from "../src/util/location";

// -117.195677,34.056383;-117.918976,33.812092
const stops: Array<[number, number]> = [
[-117.195677, 34.056383],
[-117.918976, 33.812092]
];

const stopsObjectsLatLong: ILocation[] = [
{
lat: 34.056383,
long: -117.195677
},
{
lat: 33.812092,
long: -117.918976
}
];

const stopsObjectsLatitudeLongitude: ILocation[] = [
{
latitude: 34.056383,
longitude: -117.195677
},
{
latitude: 33.812092,
longitude: -117.918976
}
];

const stopsObjectsPoint: IPoint[] = [
{
x: 34.056383,
y: -117.195677
},
{
x: 33.812092,
y: -117.918976
}
];

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

it("should recognize a spelled out 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 raw coordinates are not a location", done => {
expect(isLocation(stops[0])).toEqual(false);
done();
});

it("should recognize a location array", done => {
expect(isLocationArray(stops[0])).toEqual(true);
expect(isLocationArray(stops[1])).toEqual(true);
done();
});
});
6 changes: 6 additions & 0 deletions packages/arcgis-rest-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": [
"src/**/*.ts"
]
}
1 change: 1 addition & 0 deletions packages/arcgis-rest-geocoder/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { request, IRequestOptions, warn } from "@esri/arcgis-rest-request";
export const worldGeocoder =
"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";

// to do: remove at v2.0.0 (and import from arcgis-rest-common instead)
export interface ILocation {
latitude?: number;
longitude?: number;
Expand Down
19 changes: 9 additions & 10 deletions packages/arcgis-rest-geocoder/src/reverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
* Apache-2.0 */

import { request } from "@esri/arcgis-rest-request";

import { IPoint } from "@esri/arcgis-rest-common-types";

import { worldGeocoder, ILocation, IEndpointRequestOptions } from "./helpers";

export interface IReverseGeocodeResponse {
address: {
[key: string]: any;
};
location: IPoint;
}
import { ILocation, worldGeocoder, IEndpointRequestOptions } from "./helpers";

// to do: remove utility functions and import from arcgis-rest-common at v2
function isLocationArray(
coords: ILocation | IPoint | [number, number]
): coords is [number, number] {
return (coords as [number, number]).length === 2;
}

function isLocation(
coords: ILocation | IPoint | [number, number]
): coords is ILocation {
Expand All @@ -29,6 +21,13 @@ function isLocation(
);
}

export interface IReverseGeocodeResponse {
address: {
[key: string]: any;
};
location: IPoint;
}

/**
* Used to determine the address of a [location](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-reverse-geocode.htm).
*
Expand Down
Loading

0 comments on commit dd5a2c8

Please sign in to comment.