Merge pull request #21526 from dhritzkiv/patch-4

haversine: add format support
This commit is contained in:
Nathan Shively-Sanders
2017-11-17 15:08:17 -08:00
committed by GitHub
2 changed files with 71 additions and 4 deletions
+50 -2
View File
@@ -1,11 +1,11 @@
import haversine = require('haversine');
const start: haversine.Coordinate = {
const start: haversine.CoordinateLongitudeLatitude = {
longitude: 48.1548256,
latitude: 11.4017529
};
const end: haversine.Coordinate = {
const end: haversine.CoordinateLongitudeLatitude = {
longitude: 52.5065133,
latitude: 13.1445551
};
@@ -16,3 +16,51 @@ const options: haversine.Options = {
};
haversine(start, end, options);
const startShort: haversine.CoordinateLonLat = {
lon: 48.1548256,
lat: 11.4017529
};
const endShort: haversine.CoordinateLonLat = {
lon: 52.5065133,
lat: 13.1445551
};
const optionsShort: haversine.Options = {
format: '{lon,lat}'
};
haversine(startShort, endShort, optionsShort);
const startLatLon: haversine.LatLonTuple = [11.4017529, 48.1548256];
const endLatLon: haversine.LatLonTuple = [13.1445551, 52.5065133];
const optionsLatLon: haversine.Options = {
format: '[lat,lon]'
};
haversine(startLatLon, endLatLon, optionsLatLon);
const startGeoJSON = {
type: "Feature",
geometry: {
type: "LineString",
coordinates: startLatLon
}
};
const endGeoJSON = {
type: "Feature",
geometry: {
type: "LineString",
coordinates: endLatLon
}
};
const optionsGeoJSON: haversine.Options = {
format: 'geojson'
};
haversine(startGeoJSON, endGeoJSON, optionsGeoJSON);
+21 -2
View File
@@ -1,14 +1,29 @@
// Type definitions for haversine 1.0
// Type definitions for haversine 1.1
// Project: https://github.com/njj/haversine
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace haversine {
interface Coordinate {
interface CoordinateLongitudeLatitude {
longitude: number;
latitude: number;
}
interface CoordinateLonLat {
lon: number;
lat: number;
}
type LatLonTuple = [number, number];
interface GeoJSON {
geometry: {
coordinates: LatLonTuple
};
}
type Coordinate = (CoordinateLongitudeLatitude | CoordinateLonLat | LatLonTuple | GeoJSON);
interface Options {
/**
* Unit of measurement applied to result. Default: "km".
@@ -18,6 +33,10 @@ declare namespace haversine {
* If passed, will result in library returning boolean value of whether or not the start and end points are within that supplied threshold. Default: null.
*/
threshold?: number;
/**
* Format of coordinate arguments.
*/
format?: '[lat,lon]' | '[lon,lat]' | '{lon,lat}' | 'geojson';
}
}