mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #46380 [polygon-lookup] Add types for polygon-lookup by @ffflorian
This commit is contained in:
parent
202a040f62
commit
92aab27ecd
50
types/polygon-lookup/index.d.ts
vendored
Normal file
50
types/polygon-lookup/index.d.ts
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
// Type definitions for polygon-lookup 2.6
|
||||
// Project: https://github.com/pelias/polygon-lookup
|
||||
// Definitions by: Florian Keller <https://github.com/ffflorian>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { FeatureCollection, Polygon } from 'geojson';
|
||||
import RBush from 'rbush';
|
||||
|
||||
declare namespace PolygonLookup {
|
||||
interface BBox {
|
||||
maxX: number;
|
||||
maxY: number;
|
||||
minX: number;
|
||||
minY: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare class PolygonLookup {
|
||||
constructor(featureCollection?: FeatureCollection);
|
||||
|
||||
/** A spatial index for `this.polygons`. */
|
||||
rtree: RBush<PolygonLookup.BBox[]>;
|
||||
polygons: FeatureCollection;
|
||||
|
||||
/**
|
||||
* Find polygon(s) that a point intersects. Execute a bounding-box search to
|
||||
* narrow down the candidate polygons to a small subset, and then perform
|
||||
* additional point-in-polygon intersections to resolve any ambiguities.
|
||||
*
|
||||
* @param x The x-coordinate of the point.
|
||||
* @param y The y-coordinate of the point.
|
||||
* @param limit Number of results to return (`-1` to return all the results).
|
||||
* @return If one or more bounding box intersections are
|
||||
* found and limit is `undefined`, return the first polygon that intersects
|
||||
* (`x`, `y`); otherwise, `undefined`. If a limit is passed in, return
|
||||
* intersecting polygons as a GeoJSON `FeatureCollection`.
|
||||
*/
|
||||
search(x: number, y: number): Polygon | undefined;
|
||||
search(x: number, y: number, limit: number): FeatureCollection | undefined;
|
||||
|
||||
/**
|
||||
* Build a spatial index for a set of polygons, and store both the polygons and
|
||||
* the index in this `PolygonLookup`.
|
||||
*
|
||||
* @param collection A GeoJSON-formatted `FeatureCollection`.
|
||||
*/
|
||||
loadFeatureCollection(collection: FeatureCollection): void;
|
||||
}
|
||||
|
||||
export = PolygonLookup;
|
||||
27
types/polygon-lookup/polygon-lookup-tests.ts
Normal file
27
types/polygon-lookup/polygon-lookup-tests.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import PolygonLookup = require('polygon-lookup');
|
||||
import { FeatureCollection } from 'geojson';
|
||||
|
||||
const featureCollection: FeatureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{
|
||||
type: 'Feature',
|
||||
properties: { id: 'bar' },
|
||||
geometry: {
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
[
|
||||
[0, 1],
|
||||
[2, 1],
|
||||
[3, 4],
|
||||
[1, 5],
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const lookup = new PolygonLookup(featureCollection);
|
||||
lookup.search(1, 2);
|
||||
lookup.search(1, 2, 1);
|
||||
23
types/polygon-lookup/tsconfig.json
Normal file
23
types/polygon-lookup/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"polygon-lookup-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/polygon-lookup/tslint.json
Normal file
1
types/polygon-lookup/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user