-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from koopjs/f/handle-oob-coords
Handle out of bounds WGS84 coordinates
- Loading branch information
Showing
14 changed files
with
926 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { clipToEnvelope } from './clip-to-envelope'; | ||
|
||
describe('clipToBounds', () => { | ||
test('clipToBoundsOfSpatialReference', () => { | ||
const result = clipToEnvelope([[-190, 95], [-185, 45]], {ymin: -90, ymax: 90, xmin: -180, xmax: 180}) | ||
expect(result).toEqual([[-180, 90], [-180, 45]]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { transformCoordinates } from './traverse-coordinates'; | ||
import { Coordinates } from './common-types'; | ||
import { IEnvelope } from '@esri/arcgis-rest-types'; | ||
|
||
export function clipToEnvelope(coordinates: Coordinates , envelope: IEnvelope): Coordinates { | ||
const { xmin, xmax, ymin, ymax } = envelope; | ||
|
||
const repositionInvalidCoordinates = (coords): Coordinates => { | ||
const [lon, lat] = coords; | ||
return [constrainNumber(lon, xmax, xmin), constrainNumber(lat, ymax, ymin)]; | ||
}; | ||
|
||
return transformCoordinates(coordinates, repositionInvalidCoordinates); | ||
} | ||
|
||
function constrainNumber (num:number, max:number, min:number): number { | ||
if (num > max) { | ||
return max; | ||
} | ||
|
||
if (num < min) { | ||
return min; | ||
} | ||
|
||
return num; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
LineString, | ||
MultiLineString, | ||
MultiPoint, | ||
MultiPolygon, | ||
Point, | ||
Polygon, | ||
Position | ||
} from 'geojson'; | ||
import { | ||
IEnvelope, | ||
IPoint, | ||
IPolyline, | ||
IPolygon, | ||
ISpatialReference, | ||
} from '@esri/arcgis-rest-types'; | ||
|
||
export type Geometry = | ||
| Point | ||
| MultiPoint | ||
| LineString | ||
| MultiLineString | ||
| Polygon | ||
| MultiPolygon; | ||
|
||
export type GeometryFilter = IEnvelope | IPoint | IPolyline | IPolygon | number[]; | ||
|
||
export type Coordinates = Position | Position[] | Position[][] | Position[][][]; | ||
|
||
export type ArcgisSpatialReference = number | ISpatialReference; | ||
|
||
export type SpatialReference = { | ||
wkid?: number; | ||
latestWkid?: number; | ||
wkt?: string; | ||
vcsWkid?: number; | ||
latestVcsWkid?: number; | ||
}; | ||
|
||
export type SpatialReferenceInput = string | number | SpatialReference; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.