diff --git a/turf/turf-test.ts b/turf/turf-test.ts index e69de29bb..1cf6be9b0 100644 --- a/turf/turf-test.ts +++ b/turf/turf-test.ts @@ -0,0 +1,94 @@ +/// + +////////////////////////////////////////////////////////////////////////// +// Tests Aggregation +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +// Tests Measurement +////////////////////////////////////////////////////////////////////////// + +var point1 = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [-75.343, 39.984] + } +}; +var point2 = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [-75.534, 39.123] + } +}; +var units = "miles"; + +var points = { + "type": "FeatureCollection", + "features": [point1, point2] +}; + +var distance = turf.distance(point1, point2, units); + +////////////////////////////////////////////////////////////////////////// +// Tests Transformation +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +// Tests Misc +////////////////////////////////////////////////////////////////////////// + +var line = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [-77.031669, 38.878605], + [-77.029609, 38.881946], + [-77.020339, 38.884084], + [-77.025661, 38.885821], + [-77.021884, 38.889563], + [-77.019824, 38.892368] + ] + } +}; +var pt = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [-77.037076, 38.884017] + } +}; + +var snapped = turf.pointOnLine(line, pt); +snapped.properties['marker-color'] = '#00f' + +var result = { + "type": "FeatureCollection", + "features": [line, pt, snapped] +}; + +////////////////////////////////////////////////////////////////////////// +// Tests Helper +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +// Tests Data +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +// Tests Interpolation +//////////////////////////////////////////////////////////////////////////; + +////////////////////////////////////////////////////////////////////////// +// Tests Joins +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +// Tests Classification +////////////////////////////////////////////////////////////////////////// diff --git a/turf/turf.d.ts b/turf/turf.d.ts index e69de29bb..cde4b59d3 100644 --- a/turf/turf.d.ts +++ b/turf/turf.d.ts @@ -0,0 +1,65 @@ +// Type definitions for Turf 2.0 +// Project: http://turfjs.org/ +// Definitions by: Guillaume Croteau +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module turf { + ////////////////////////////////////////////////////////////////////////// + // Aggregation + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Measurement + ////////////////////////////////////////////////////////////////////////// + + /** + * Calculates the distance between two points in degress, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature. + * @param from Origin point + * @param to Destination point + * @param units Can be degrees, radians, miles, or kilometers. Default is kilometers. + * @returns Distance between the two points + */ + function distance(from: GeoJSON.Feature, to: GeoJSON.Feature, units?: string): number; + + ////////////////////////////////////////////////////////////////////////// + // Transformation + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Misc + ////////////////////////////////////////////////////////////////////////// + + /** + * Takes a Point and a LineString and calculates the closest Point on the LineString. + * @param line Line to snap to + * @param point Point to snap from + * @returns Closest point on the line to point + */ + function pointOnLine(line: GeoJSON.Feature, point: GeoJSON.Feature): GeoJSON.Feature; + + ////////////////////////////////////////////////////////////////////////// + // Helper + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Data + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Interpolation + //////////////////////////////////////////////////////////////////////////; + + ////////////////////////////////////////////////////////////////////////// + // Joins + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Classification + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // Types + ////////////////////////////////////////////////////////////////////////// +}