From d50b504e5e36173c078217ee3960c61e138533d6 Mon Sep 17 00:00:00 2001 From: Jake Bruun Date: Tue, 13 May 2014 23:14:42 -0700 Subject: [PATCH 1/4] Create declaration file for GeoJSON spec. --- geojson/geojson-tests.ts | 129 +++++++++++++++++++++++++++++++++++++++ geojson/geojson.d.ts | 127 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 256 insertions(+) create mode 100644 geojson/geojson-tests.ts create mode 100644 geojson/geojson.d.ts diff --git a/geojson/geojson-tests.ts b/geojson/geojson-tests.ts new file mode 100644 index 000000000..ed953520b --- /dev/null +++ b/geojson/geojson-tests.ts @@ -0,0 +1,129 @@ +/// + +var featureCollection: GeoJSON.FeatureCollection = { + type: "FeatureCollection", + features: [ + { + type: "Feature", + geometry: { + type: "Point", + coordinates: [102.0, 0.5] + }, + properties: { + prop0: "value0" + } + }, + { + type: "Feature", + geometry: { + type: "LineString", + coordinates: [ + [102.0, 0.0], + [103.0, 1.0], + [104.0, 0.0], + [105.0, 1.0] + ] + }, + properties: { + prop0: "value0", + prop1: 0.0 + } + }, + { + type: "Feature", + geometry: { + type: "Polygon", + coordinates: [ + [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] + ] + }, + properties: { + prop0: "value0", + prop1: { + that: "this" + } + } + } + ], + crs: { + type: "link", + properties: { + href: "http://example.com/crs/42", + type: "proj4" + } + } +} + +var feature: GeoJSON.Feature = { + type: "Feature", + bbox: [-180.0, -90.0, 180.0, 90.0], + geometry: { + type: "Polygon", + coordinates: [ + [[-180.0, 10.0], [20.0, 90.0], [180.0, -5.0], [-30.0, -90.0]] + ] + }, + properties: null +}; + + +var point: GeoJSON.Point = { + type: "Point", + coordinates: [100.0, 0.0] +}; + +var lineString: GeoJSON.LineString = { + type: "LineString", + coordinates: [ [100.0, 0.0], [101.0, 1.0] ] +}; + +var polygon: GeoJSON.Polygon = { + type: "Polygon", + coordinates: [ + [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] + ] +}; + +var polygonWithHole: GeoJSON.Polygon = { + type: "Polygon", + coordinates: [ + [ [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] ] + ] +}; + +var multiPoint: GeoJSON.MultiPoint = { + type: "MultiPoint", + coordinates: [ [100.0, 0.0], [101.0, 1.0] ] +}; + +var multiLineString: GeoJSON.MultiLineString = { + type: "MultiLineString", + coordinates: [ + [ [100.0, 0.0], [101.0, 1.0] ], + [ [102.0, 2.0], [103.0, 3.0] ] + ] +}; + +var multiPolygon: GeoJSON.MultiPolygon = { + type: "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]]] + ] +} + +var geometryCollection: GeoJSON.GeometryCollection = { + type: "GeometryCollection", + "geometries": [ + { + type: "Point", + coordinates: [100.0, 0.0] + }, + { + type: "LineString", + coordinates: [ [101.0, 0.0], [102.0, 1.0] ] + } + ] +} \ No newline at end of file diff --git a/geojson/geojson.d.ts b/geojson/geojson.d.ts new file mode 100644 index 000000000..54ee3cb90 --- /dev/null +++ b/geojson/geojson.d.ts @@ -0,0 +1,127 @@ +// Type definitions for GeoJSON Format Specification +// Project: http://geojson.org/ +// Definitions by: Jacob Bruun +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module GeoJSON { + + /*** + * http://geojson.org/geojson-spec.html#geojson-objects + */ + export interface GeoJsonObject + { + type: string; + bbox?: number[]; + crs?: CoordinateReferenceSystem; + } + + /*** + * http://geojson.org/geojson-spec.html#positions + */ + export interface Position + { + [index: number]: number; + } + + /*** + * http://geojson.org/geojson-spec.html#geometry-objects + */ + export interface GeometryObject extends GeoJsonObject + { + coordinates: any + } + + /*** + * http://geojson.org/geojson-spec.html#point + */ + export interface Point extends GeometryObject + { + coordinates: Position + } + + /*** + * http://geojson.org/geojson-spec.html#multipoint + */ + export interface MultiPoint extends GeometryObject + { + + coordinates: Position[] + } + + /*** + * http://geojson.org/geojson-spec.html#linestring + */ + export interface LineString extends GeometryObject + { + coordinates: Position[] + } + + /*** + * http://geojson.org/geojson-spec.html#multilinestring + */ + export interface MultiLineString extends GeometryObject + { + coordinates: Position[][] + } + + /*** + * http://geojson.org/geojson-spec.html#polygon + */ + export interface Polygon extends GeometryObject + { + coordinates: Position[][] + } + + /*** + * http://geojson.org/geojson-spec.html#multipolygon + */ + export interface MultiPolygon extends GeometryObject + { + coordinates: Position[][][] + } + + /*** + * http://geojson.org/geojson-spec.html#geometry-collection + */ + export interface GeometryCollection extends GeoJsonObject + { + geometries: GeometryObject[]; + } + + /*** + * http://geojson.org/geojson-spec.html#feature-objects + */ + export interface Feature extends GeoJsonObject + { + geometry: GeometryObject; + properties: any; + id?: string; + } + + /*** + * http://geojson.org/geojson-spec.html#feature-collection-objects + */ + export interface FeatureCollection extends GeoJsonObject + { + features: Feature[]; + } + + /*** + * http://geojson.org/geojson-spec.html#coordinate-reference-system-objects + */ + export interface CoordinateReferenceSystem + { + type: string; + properties: any; + } + + export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem + { + properties: { name: string } + } + + export interface LinkedCoordinateReferenceSystem extends CoordinateReferenceSystem + { + properties: { href: string; type: string } + } +} \ No newline at end of file From 44c5608942b63662cb26d992580988a68f640120 Mon Sep 17 00:00:00 2001 From: Jake Bruun Date: Tue, 13 May 2014 23:18:57 -0700 Subject: [PATCH 2/4] Fixed formatting --- geojson/geojson.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geojson/geojson.d.ts b/geojson/geojson.d.ts index 54ee3cb90..8414ecd03 100644 --- a/geojson/geojson.d.ts +++ b/geojson/geojson.d.ts @@ -5,7 +5,7 @@ declare module GeoJSON { - /*** + /*** * http://geojson.org/geojson-spec.html#geojson-objects */ export interface GeoJsonObject From 63cd88fcf3eed82b166afe52fe86aca876a3d6ff Mon Sep 17 00:00:00 2001 From: Jake Bruun Date: Tue, 13 May 2014 23:20:07 -0700 Subject: [PATCH 3/4] Fixed formatting --- geojson/geojson.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geojson/geojson.d.ts b/geojson/geojson.d.ts index 8414ecd03..1f8a23db5 100644 --- a/geojson/geojson.d.ts +++ b/geojson/geojson.d.ts @@ -115,7 +115,7 @@ declare module GeoJSON { properties: any; } - export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem + export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem { properties: { name: string } } From f8935ebdcadbda5993157914a86c9c49189e1731 Mon Sep 17 00:00:00 2001 From: Jake Bruun Date: Tue, 13 May 2014 23:24:19 -0700 Subject: [PATCH 4/4] Updated contributors.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f39e1f53d..a204feb3c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -84,6 +84,7 @@ All definitions files include a header with the author and editors, so at some p * [fs-extra](https://github.com/jprichardson/node-fs-extra) (by [midknight41](https://github.com/midknight41)) * [FullCalendar](http://arshaw.com/fullcalendar/) (by [Neil Stalker](https://github.com/nestalk)) * [Gamepad](http://www.w3.org/TR/gamepad/) (by [Kon](http://phyzkit.net/)) +* [GeoJSON](http://geojson.org/) (by [Jake Bruun](https://github.com/cobster)) * [Giraffe](https://github.com/barc/backbone.giraffe) (by [Matt McCray](https://github.com/darthapo)) * [glDatePicker](http://glad.github.com/glDatePicker/) (by [Dániel Tar](https://github.com/qcz)) * [Glob](https://github.com/isaacs/node-glob) (by [vvakame](https://github.com/vvakame))