Comparing version 0.1.0 to 0.1.1
@@ -249,3 +249,3 @@ 'use strict'; | ||
if (typeof window === 'undefined') { | ||
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { | ||
// nodejs | ||
@@ -252,0 +252,0 @@ module.exports.Coord = Coord; |
# v0.1.1 | ||
- Support browserify (https://github.com/springmeyer/arc.js/pull/26) | ||
# v0.1.0 | ||
@@ -7,2 +10,2 @@ | ||
- Added mocha tests | ||
- Fixed jshint strict errors | ||
- Fixed jshint strict errors |
{ | ||
"name": "arc", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "draw great circle arcs", | ||
@@ -31,7 +31,15 @@ "url": "https://github.com/springmeyer/arc.js", | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "tape test/*.js" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.17.1" | ||
"tape": "~2.12.1" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"chrome/22..latest", | ||
"firefox/16..latest", | ||
"safari/latest" | ||
] | ||
} | ||
} |
# arc.js | ||
> Calculate great circles routes as lines in GeoJSON or WKT format. | ||
Calculate great circles routes as lines in GeoJSON or WKT format. | ||
Algorithms from http://williams.best.vwh.net/avform.htm#Intermediate | ||
@@ -10,16 +9,30 @@ | ||
## Install | ||
# Usage | ||
```bash | ||
$ npm install --save arc | ||
``` | ||
Require the library in node.js like: | ||
```bash | ||
$ bower install --save arc.js | ||
``` | ||
var arc = require('arc'); | ||
## License | ||
Use in the browser like: | ||
BSD | ||
<script src="./arc.js"></script> | ||
## Usage | ||
Require the library in node.js like: | ||
```js | ||
var arc = require('arc'); | ||
``` | ||
# API | ||
Use in the browser like: | ||
```html | ||
<script src="./arc.js"></script> | ||
``` | ||
## API | ||
**1)** Create start and end coordinates | ||
@@ -29,4 +42,6 @@ | ||
var start = { x: -122, y: 48 }; | ||
var end = { x: -77, y: 39 }; | ||
```js | ||
var start = { x: -122, y: 48 }; | ||
var end = { x: -77, y: 39 }; | ||
``` | ||
@@ -39,3 +54,5 @@ Note that `x` here is longitude in degrees and `y` is latitude in degrees. | ||
var generator = new arc.GreatCircle(start, end, {'name': 'Seattle to DC'}); | ||
```js | ||
var generator = new arc.GreatCircle(start, end, {'name': 'Seattle to DC'}); | ||
``` | ||
@@ -46,3 +63,5 @@ **3)** Generate a line arc | ||
var line = generator.Arc(100,{offset:10}); | ||
```js | ||
var line = generator.Arc(100,{offset:10}); | ||
``` | ||
@@ -52,12 +71,14 @@ The `line` will be a raw sequence of the start and end coordinates plus an arc of | ||
> line | ||
{ properties: { name: 'Seattle to DC' }, | ||
coords: | ||
[ [ -122, 48.00000000000001 ], | ||
[ -112.06161978373486, 47.7241672604096 ], | ||
[ -102.38404317022653, 46.60813199882492 ], | ||
[ -93.22718895342909, 44.716217302635705 ], | ||
[ -84.74823988299501, 42.14415510795357 ], | ||
[ -77, 38.99999999999999 ] ], | ||
length: 6 } | ||
```js | ||
> line | ||
{ properties: { name: 'Seattle to DC' }, | ||
coords: | ||
[ [ -122, 48.00000000000001 ], | ||
[ -112.06161978373486, 47.7241672604096 ], | ||
[ -102.38404317022653, 46.60813199882492 ], | ||
[ -93.22718895342909, 44.716217302635705 ], | ||
[ -84.74823988299501, 42.14415510795357 ], | ||
[ -77, 38.99999999999999 ] ], | ||
length: 6 } | ||
``` | ||
@@ -74,14 +95,18 @@ #### Arc options | ||
> line.json(); | ||
{ geometry: | ||
{ type: 'LineString', | ||
coordinates: [ [Object], [Object], [Object], [Object], [Object], [Object] ] }, | ||
type: 'Feature', | ||
properties: { name: 'Seattle to DC' } } | ||
```js | ||
> line.json(); | ||
{ geometry: | ||
{ type: 'LineString', | ||
coordinates: [ [Object], [Object], [Object], [Object], [Object], [Object] ] }, | ||
type: 'Feature', | ||
properties: { name: 'Seattle to DC' } } | ||
``` | ||
Or to WKT (Well known text): | ||
> line.wkt(); | ||
'LINESTRING(-122 48.00000000000001,-112.06161978373486 47.7241672604096,-102.38404317022653 46.60813199882492,-93.22718895342909 44.716217302635705,-84.74823988299501 42.14415510795357,-77 38.99999999999999)' | ||
```js | ||
> line.wkt(); | ||
'LINESTRING(-122 48.00000000000001,-112.06161978373486 47.7241672604096,-102.38404317022653 46.60813199882492,-93.22718895342909 44.716217302635705,-84.74823988299501 42.14415510795357,-77 38.99999999999999)' | ||
``` | ||
It is then up to you to add up these features to create fully fledged geodata. See the examples/ directory for sample code to create GeoJSON feature collection from multiple routes. |
'use strict'; | ||
var test = require('tape').test; | ||
var arc = require('../'); | ||
var assert = require('assert'); | ||
describe('Coord', function() { | ||
it('#constructor', function() { | ||
var coord = new arc.Coord(0,0); | ||
assert.equal(coord.lon,0); | ||
assert.equal(coord.lat,0); | ||
assert.equal(coord.x,0); | ||
assert.equal(coord.y,0); | ||
}); | ||
it('#view', function() { | ||
var coord = new arc.Coord(0,0); | ||
assert.equal(coord.view(),'0,0'); | ||
}); | ||
it('#antipode', function() { | ||
var coord = new arc.Coord(0,0); | ||
assert.equal(coord.antipode().view(),'-180,0'); | ||
}); | ||
test('Coord', function(t) { | ||
var coord = new arc.Coord(0,0); | ||
t.equal(coord.lon,0); | ||
t.equal(coord.lat,0); | ||
t.equal(coord.x,0); | ||
t.equal(coord.y,0); | ||
t.equal(coord.view(),'0,0'); | ||
t.equal(coord.antipode().view(),'-180,0'); | ||
t.end(); | ||
}); | ||
describe('Arc', function() { | ||
it('#constructor', function() { | ||
var a = new arc.Arc(); | ||
assert.deepEqual(a.properties, {}); | ||
test('Arc', function(t) { | ||
var a = new arc.Arc(); | ||
t.deepEqual(a.properties, {}); | ||
t.equal(a.wkt(), ''); | ||
t.deepEqual(a.json(),{ | ||
'geometry': { 'type': 'LineString', 'coordinates': null }, | ||
'type': 'Feature', 'properties': {} | ||
}); | ||
it('#wkt', function() { | ||
var a = new arc.Arc(); | ||
assert.equal(a.wkt(), ''); | ||
}); | ||
it('#json', function() { | ||
var a = new arc.Arc(); | ||
assert.deepEqual(a.json(),{ | ||
'geometry': { 'type': 'LineString', 'coordinates': null }, | ||
'type': 'Feature', 'properties': {} | ||
}); | ||
}); | ||
t.end(); | ||
}); | ||
describe('GreatCircle', function() { | ||
it('#constructor', function() { | ||
var a = new arc.GreatCircle({ | ||
x: 0, y: 0 | ||
}, { | ||
x: 10, y: 0 | ||
}); | ||
assert.ok(a); | ||
test('GreatCircle', function(t) { | ||
var a = new arc.GreatCircle({ | ||
x: 0, y: 0 | ||
}, { | ||
x: 10, y: 0 | ||
}); | ||
it('#interpolate', function() { | ||
var a = new arc.GreatCircle({ | ||
x: 0, y: 0 | ||
}, { | ||
x: 10, y: 0 | ||
}); | ||
assert.deepEqual(a.interpolate(0), [0, 0]); | ||
assert.deepEqual(a.interpolate(1), [10, 0]); | ||
}); | ||
t.ok(a); | ||
t.deepEqual(a.interpolate(0), [0, 0]); | ||
t.deepEqual(a.interpolate(1), [10, 0]); | ||
t.end(); | ||
}); | ||
@@ -83,13 +61,12 @@ | ||
describe('Routes', function() { | ||
test('Routes', function(t) { | ||
routes.forEach(function(route,idx) { | ||
it(route[2].name, function() { | ||
var gc = new arc.GreatCircle(route[0], route[1], route[2]); | ||
var line = gc.Arc(3); | ||
//console.log(JSON.stringify(line)) | ||
assert.deepEqual(line,arcs[idx]); | ||
}); | ||
var gc = new arc.GreatCircle(route[0], route[1], route[2]); | ||
var line = gc.Arc(3); | ||
//console.log(JSON.stringify(line)) | ||
t.deepEqual(line,arcs[idx]); | ||
}); | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18851
10
329
107
0