Socket
Socket
Sign inDemoInstall

polyline

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyline - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

.idea/.name

11

package.json

@@ -5,9 +5,10 @@ {

"description": "Polyline encoding and decoding",
"version": "0.0.0",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "git://github.com/tmcw/polyline.git"
"url": "git://github.com/mapbox/polyline.git"
},
"dependencies": {},
"devDependencies": {
"jshint": "2.3.0",
"mocha": "1.2.x"

@@ -17,3 +18,3 @@ },

"scripts": {
"test": "mocha -R spec"
"test": "jshint src && mocha -R spec"
},

@@ -23,3 +24,7 @@ "main": "src/polyline.js",

"node": "*"
},
"jshintConfig": {
"undef": true,
"node": true
}
}

@@ -1,2 +0,2 @@

[![Build Status](https://secure.travis-ci.org/tmcw/polyline.png?branch=master)](http://travis-ci.org/tmcw/polyline)
[![Build Status](https://secure.travis-ci.org/mapbox/polyline.png?branch=master)](http://travis-ci.org/mapbox/polyline)

@@ -6,4 +6,8 @@ # polyline

A simple [google-esque polyline](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)
implementation in Javascript
implementation in Javascript. Compatible with nodejs (`npm install polyline` and the browser (copy `src/polyline.js`)).
Encodes/decodes into lat/lng coordinate pairs. Flip the pairs to be compatible with GeoJSON.
# [Documentation](https://github.com/mapbox/polyline/blob/master/API.md)
## See Also

@@ -10,0 +14,0 @@

@@ -8,3 +8,3 @@ var polyline = {};

polyline.encodeCoordinate = function(coordinate) {
function encode(coordinate) {
coordinate = Math.round(coordinate * 1e5);

@@ -22,16 +22,7 @@ coordinate <<= 1;

return output;
};
}
// See http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.js
polyline.decodeCoordinate = function(str) {
for (var i = 0; i < str.length; i++) {
var binary = str.charCodeAt(i) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
}
};
// This is adapted from the implementation in Project-OSRM
// https://github.com/DennisOSRM/Project-OSRM-Web/blob/master/WebContent/routing/OSRM.RoutingGeometry.js
polyline.decodeLine = function(str) {
polyline.decode = function(str) {

@@ -87,29 +78,13 @@ var index = 0,

// Simple encoding of a point, simply encoding two coordinates
polyline.encodePoint = function(x, y) {
return this.encodeCoordinate(x) + this.encodeCoordinate(y);
};
polyline.encode = function(coordinates) {
if (!coordinates.length) return '';
polyline.encodeLine = function(coordinates) {
var previous_point,
output = '',
longitude = 0,
latitude = 0;
var output = encode(coordinates[0][0]) + encode(coordinates[0][1]);
for (var i = 0; i < coordinates.length; i++) {
var pt = [
coordinates[i][0],
coordinates[i][1]];
for (var i = 1; i < coordinates.length; i++) {
var a = coordinates[i], b = coordinates[i - 1];
output += encode(a[0] - b[0]);
output += encode(a[1] - b[1]);
}
if (latitude || longitude) {
pt = [
pt[0] - latitude,
pt[1] - longitude];
}
output += this.encodePoint(pt[0], pt[1]);
latitude = pt[0];
longitude = pt[1];
}
return output;

@@ -116,0 +91,0 @@ };

var assert = require('assert'),
polyline = require('../');
polyline = require('../');
describe('polyline', function() {
function compare(coords, against) {

@@ -14,17 +13,9 @@ function a(x) { return Math.round(x * 100) / 100; }

describe('#encodeCoordinate()', function() {
it('should encode one of the google reference coords', function() {
assert.equal(polyline.encodeCoordinate(-179.9832104), '`~oia@');
describe('#decode()', function() {
it('decodes an empty Array', function() {
assert.deepEqual(polyline.decode(''), []);
});
});
describe('#encodePoint()', function() {
it('should encode one of the google reference points', function() {
assert.equal(polyline.encodePoint(38.5, -120.2), '_p~iF~ps|U');
});
});
describe('#decodeLine()', function() {
it('should decode a google reference line', function() {
var coords = polyline.decodeLine('_p~iF~ps|U_ulLnnqC_mqNvxq`@');
it('decodes a String into an Array of lat/lon pairs', function() {
var coords = polyline.decode('_p~iF~ps|U_ulLnnqC_mqNvxq`@');
var against = [

@@ -39,15 +30,11 @@ [38.5, -120.2],

describe('#encodeLine()', function() {
it('should encode two points', function() {
assert.equal(polyline.encodeLine([[38.5, -120.2], [40.7, -120.95]]), '_p~iF~ps|U_ulLnnqC');
describe('#encode()', function() {
it('encodes an empty Array', function() {
assert.equal(polyline.encode([]), '');
});
});
describe('back and forth', function() {
it('should encode two points', function() {
assert.equal(polyline.encodeLine([[38.5, -120.2], [40.7, -120.95]]), '_p~iF~ps|U_ulLnnqC');
compare(polyline.decodeLine('_p~iF~ps|U_ulLnnqC'), [[38.5, -120.2], [40.7, -120.95]]);
it('encodes an Array of lat/lon pairs into a String', function() {
assert.equal(polyline.encode([[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]), '_p~iF~ps|U_ulLnnqC_mqNvxq`@');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc