turf-nearest
Advanced tools
Comparing version 0.1.3 to 1.0.0
26
index.js
@@ -1,23 +0,23 @@ | ||
distance = require('turf-distance') | ||
distance = require('turf-distance'); | ||
module.exports = function(targetPoint, points){ | ||
var nearestPoint | ||
var count = 0 | ||
var dist = Infinity | ||
var nearestPoint; | ||
var count = 0; | ||
var dist = Infinity; | ||
points.features.forEach(function(pt){ | ||
if(!nearestPoint){ | ||
nearestPoint = pt | ||
var dist = distance(targetPoint, pt, 'miles') | ||
nearestPoint.properties.distance = dist | ||
nearestPoint = pt; | ||
var dist = distance(targetPoint, pt, 'miles'); | ||
nearestPoint.properties.distance = dist; | ||
} | ||
else{ | ||
var dist = distance(targetPoint, pt, 'miles') | ||
var dist = distance(targetPoint, pt, 'miles'); | ||
if(dist < nearestPoint.properties.distance){ | ||
nearestPoint = pt | ||
nearestPoint.properties.distance = dist | ||
nearestPoint = pt; | ||
nearestPoint.properties.distance = dist; | ||
} | ||
} | ||
}) | ||
delete nearestPoint.properties.distance | ||
return nearestPoint | ||
}); | ||
delete nearestPoint.properties.distance; | ||
return nearestPoint; | ||
} |
{ | ||
"name": "turf-nearest", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"description": "turf nearest module", | ||
@@ -26,7 +26,8 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tape": "^2.13.3" | ||
"benchmark": "^1.0.0", | ||
"tape": "^3.0.3" | ||
}, | ||
"dependencies": { | ||
"turf-distance": "^0.1.4" | ||
"turf-distance": "^1.0.0" | ||
} | ||
} |
24
test.js
@@ -1,16 +0,16 @@ | ||
var test = require('tape') | ||
var nearest = require('./') | ||
var fs = require('fs') | ||
var test = require('tape'); | ||
var nearest = require('./'); | ||
var fs = require('fs'); | ||
test('distance', function(t){ | ||
var pt = JSON.parse(fs.readFileSync(__dirname+'/geojson/pt.geojson')) | ||
var pts = JSON.parse(fs.readFileSync(__dirname+'/geojson/pts.geojson')) | ||
var pt = JSON.parse(fs.readFileSync(__dirname+'/geojson/pt.geojson')); | ||
var pts = JSON.parse(fs.readFileSync(__dirname+'/geojson/pts.geojson')); | ||
var closestPt = nearest(pt, pts) | ||
var closestPt = nearest(pt, pts); | ||
t.ok(closestPt, 'should return a point') | ||
t.equal(closestPt.geometry.type, 'Point', 'should be a point') | ||
t.equal(closestPt.geometry.coordinates[0], -75.33, 'lon -75.33') | ||
t.equal(closestPt.geometry.coordinates[1], 39.44, 'lat 39.44') | ||
t.end() | ||
}) | ||
t.ok(closestPt, 'should return a point'); | ||
t.equal(closestPt.geometry.type, 'Point', 'should be a point'); | ||
t.equal(closestPt.geometry.coordinates[0], -75.33, 'lon -75.33'); | ||
t.equal(closestPt.geometry.coordinates[1], 39.44, 'lat 39.44'); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9040
10
48
0
2
2
+ Addedturf-distance@1.1.0(transitive)
+ Addedturf-invariant@1.0.3(transitive)
- Removedturf-distance@0.1.5(transitive)
Updatedturf-distance@^1.0.0