mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 14:59:37 +08:00
GeoJSON: Enhance with generic properties (#20932)
* Make properties optional generic * Write tests for generic usage of gGeoJSON feature properties * Apply layout like recommend in the tslint default rule-set. * double quotes * 4 spaces indent (no tabs!) * Remove jsdoc typings and force typescript version 2.3 for sub type-definitions of geojson * apply change of andy-ms in PR #20933 * remove empty comments and set typescript version to 2.3 to fix linting errors * Add myself to the list of authors * Set TypeScript version to 2.3 for packages depending on geojson
This commit is contained in:
1013
types/botvs/index.d.ts
vendored
1013
types/botvs/index.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1
types/d3-geo/index.d.ts
vendored
1
types/d3-geo/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-geo/
|
||||
// Definitions by: Hugues Stefanski <https://github.com/Ledragon>, Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.9.0
|
||||
|
||||
|
||||
@@ -67,16 +67,16 @@ let featureWithPolygon: GeoJSON.Feature<GeoJSON.Polygon> = {
|
||||
};
|
||||
|
||||
let point: GeoJSON.Point = {
|
||||
type: "Point",
|
||||
coordinates: [100.0, 0.0]
|
||||
type: "Point",
|
||||
coordinates: [100.0, 0.0]
|
||||
};
|
||||
|
||||
// This type is commonly used in the turf package
|
||||
let pointCoordinates: number[] = point.coordinates;
|
||||
|
||||
let lineString: GeoJSON.LineString = {
|
||||
type: "LineString",
|
||||
coordinates: [ [100.0, 0.0], [101.0, 1.0] ]
|
||||
type: "LineString",
|
||||
coordinates: [ [100.0, 0.0], [101.0, 1.0] ]
|
||||
};
|
||||
|
||||
let polygon: GeoJSON.Polygon = {
|
||||
@@ -112,7 +112,7 @@ let multiPolygon: GeoJSON.MultiPolygon = {
|
||||
coordinates: [
|
||||
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
|
||||
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
|
||||
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
|
||||
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
|
||||
]
|
||||
};
|
||||
|
||||
@@ -172,31 +172,31 @@ featureCollection = {
|
||||
{
|
||||
type: "Feature",
|
||||
geometry: lineString,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}, {
|
||||
type: "Feature",
|
||||
geometry: polygon,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}, {
|
||||
type: "Feature",
|
||||
geometry: polygonWithHole,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}, {
|
||||
type: "Feature",
|
||||
geometry: multiPoint,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}, {
|
||||
type: "Feature",
|
||||
geometry: multiLineString,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}, {
|
||||
type: "Feature",
|
||||
geometry: multiPolygon,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}, {
|
||||
type: "Feature",
|
||||
geometry: geometryCollection,
|
||||
properties: {test: 'OK'}
|
||||
properties: {test: "OK"}
|
||||
}
|
||||
],
|
||||
crs: {
|
||||
@@ -210,17 +210,41 @@ featureCollection = {
|
||||
|
||||
// Allow access to custom properties
|
||||
const pt: GeoJSON.Feature<GeoJSON.Point> = {
|
||||
type: 'Feature',
|
||||
type: "Feature",
|
||||
properties: {
|
||||
foo: 'bar',
|
||||
hello: 'world',
|
||||
foo: "bar",
|
||||
hello: "world",
|
||||
1: 2
|
||||
},
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
type: "Point",
|
||||
coordinates: [0, 0]
|
||||
}
|
||||
};
|
||||
pt.properties.foo;
|
||||
pt.properties.hello;
|
||||
pt.properties[1];
|
||||
|
||||
// Optional generic for properties
|
||||
|
||||
interface TestProperty {
|
||||
foo: "bar" | "baz";
|
||||
hello: string;
|
||||
}
|
||||
|
||||
const typedPropertiesFeature: GeoJSON.Feature<GeoJSON.Point, TestProperty> = {
|
||||
type: "Feature",
|
||||
properties: {
|
||||
foo: "bar",
|
||||
hello: "world",
|
||||
},
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [0, 0]
|
||||
}
|
||||
};
|
||||
|
||||
const typedPropertiesFeatureCollection: GeoJSON.FeatureCollection<GeoJSON.Point, TestProperty> = {
|
||||
type: "FeatureCollection",
|
||||
features: [typedPropertiesFeature]
|
||||
};
|
||||
|
||||
82
types/geojson/index.d.ts
vendored
82
types/geojson/index.d.ts
vendored
@@ -1,13 +1,15 @@
|
||||
// Type definitions for GeoJSON Format Specification Revision 1.0
|
||||
// Project: http://geojson.org/
|
||||
// Definitions by: Jacob Bruun <https://github.com/cobster>
|
||||
// Arne Schubert <https://github.com/atd-schubert>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
export as namespace GeoJSON;
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#geojson-objects
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#geojson-objects
|
||||
*/
|
||||
export interface GeoJsonObject {
|
||||
type: string;
|
||||
bbox?: number[];
|
||||
@@ -15,13 +17,13 @@ export interface GeoJsonObject {
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#positions
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#positions
|
||||
*/
|
||||
export type Position = number[];
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#geometry-objects
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#geometry-objects
|
||||
*/
|
||||
export interface DirectGeometryObject extends GeoJsonObject {
|
||||
coordinates: Position[][][] | Position[][] | Position[] | Position;
|
||||
}
|
||||
@@ -31,82 +33,82 @@ export interface DirectGeometryObject extends GeoJsonObject {
|
||||
export type GeometryObject = DirectGeometryObject | GeometryCollection;
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#point
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#point
|
||||
*/
|
||||
export interface Point extends DirectGeometryObject {
|
||||
type: 'Point';
|
||||
type: "Point";
|
||||
coordinates: Position;
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#multipoint
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#multipoint
|
||||
*/
|
||||
export interface MultiPoint extends DirectGeometryObject {
|
||||
type: 'MultiPoint';
|
||||
type: "MultiPoint";
|
||||
coordinates: Position[];
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#linestring
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#linestring
|
||||
*/
|
||||
export interface LineString extends DirectGeometryObject {
|
||||
type: 'LineString';
|
||||
type: "LineString";
|
||||
coordinates: Position[];
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#multilinestring
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#multilinestring
|
||||
*/
|
||||
export interface MultiLineString extends DirectGeometryObject {
|
||||
type: 'MultiLineString';
|
||||
type: "MultiLineString";
|
||||
coordinates: Position[][];
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#polygon
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#polygon
|
||||
*/
|
||||
export interface Polygon extends DirectGeometryObject {
|
||||
type: 'Polygon';
|
||||
type: "Polygon";
|
||||
coordinates: Position[][];
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#multipolygon
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#multipolygon
|
||||
*/
|
||||
export interface MultiPolygon extends DirectGeometryObject {
|
||||
type: 'MultiPolygon';
|
||||
type: "MultiPolygon";
|
||||
coordinates: Position[][][];
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#geometry-collection
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#geometry-collection
|
||||
*/
|
||||
export interface GeometryCollection extends GeoJsonObject {
|
||||
type: 'GeometryCollection';
|
||||
type: "GeometryCollection";
|
||||
geometries: GeometryObject[];
|
||||
}
|
||||
|
||||
/***
|
||||
* https://tools.ietf.org/html/rfc7946#section-3.2
|
||||
*/
|
||||
export interface Feature<T extends GeometryObject> extends GeoJsonObject {
|
||||
type: 'Feature';
|
||||
geometry: T;
|
||||
properties: any;
|
||||
* https://tools.ietf.org/html/rfc7946#section-3.2
|
||||
*/
|
||||
export interface Feature<G extends GeometryObject, P = any> extends GeoJsonObject {
|
||||
type: "Feature";
|
||||
geometry: G;
|
||||
properties: P;
|
||||
id?: string | number;
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#feature-collection-objects
|
||||
*/
|
||||
export interface FeatureCollection<T extends GeometryObject> extends GeoJsonObject {
|
||||
type: 'FeatureCollection';
|
||||
features: Array<Feature<T>>;
|
||||
* http://geojson.org/geojson-spec.html#feature-collection-objects
|
||||
*/
|
||||
export interface FeatureCollection<G extends GeometryObject, P = any> extends GeoJsonObject {
|
||||
type: "FeatureCollection";
|
||||
features: Array<Feature<G, P>>;
|
||||
}
|
||||
|
||||
/***
|
||||
* http://geojson.org/geojson-spec.html#coordinate-reference-system-objects
|
||||
*/
|
||||
* http://geojson.org/geojson-spec.html#coordinate-reference-system-objects
|
||||
*/
|
||||
export interface CoordinateReferenceSystem {
|
||||
type: string;
|
||||
properties: any;
|
||||
|
||||
1
types/geojson2osm/index.d.ts
vendored
1
types/geojson2osm/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/Rub21/geojson2osm
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="geojson"/>
|
||||
|
||||
|
||||
1
types/leaflet/v0/index.d.ts
vendored
1
types/leaflet/v0/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/Leaflet/Leaflet
|
||||
// Definitions by: Vladimir Zotov <https://github.com/rgripper>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="geojson" />
|
||||
|
||||
|
||||
1
types/polyline/index.d.ts
vendored
1
types/polyline/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/mapbox/polyline
|
||||
// Definitions by: Arseniy Maximov <https://github.com/Kern0>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="geojson" />
|
||||
|
||||
|
||||
1
types/shapefile/index.d.ts
vendored
1
types/shapefile/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/mbostock/shapefile
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="geojson"/>
|
||||
|
||||
|
||||
1
types/supercluster/index.d.ts
vendored
1
types/supercluster/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/mapbox/supercluster
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import * as GeoJSON from 'geojson';
|
||||
|
||||
|
||||
1
types/tilebelt/index.d.ts
vendored
1
types/tilebelt/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/mapbox/tilebelt
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="geojson" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user