compute-distance
Advanced tools
+27
-5
@@ -0,7 +1,26 @@ | ||
| // Get the Google API object, if it exists | ||
| var getGoogleAPI = function (options) { | ||
| if (options && options.google) { | ||
| return options.google; | ||
| } | ||
| else if (global && global.google) { | ||
| return global.google; | ||
| } | ||
| else if (window && window.google) { | ||
| return window.google; | ||
| } | ||
| else { | ||
| console.log("Google API object does not exist"); | ||
| console.trace(); | ||
| } | ||
| return undefined; | ||
| }; | ||
| // Smooth the run (e.g. ignore bouncing GPS tracks) | ||
| var defaultFilter = function (data) { | ||
| var defaultFilter = function (data, options) { | ||
| var accurate = [], | ||
| filtered = [], | ||
| maxDistance = 20; // Meters | ||
| maxDistance = 20, // Meters | ||
| google = getGoogleAPI(options); | ||
@@ -46,4 +65,5 @@ // Filter out inaccurate points | ||
| // Get an array of coordinates | ||
| var getCoordinates = function (data) { | ||
| var coords = []; | ||
| var getCoordinates = function (data, options) { | ||
| var coords = [], | ||
| google = getGoogleAPI(options); | ||
@@ -61,3 +81,5 @@ for (var i in data) { | ||
| // Get the distance represented by a set of coordinates (meters) | ||
| var computeDistance = function (coords) { | ||
| var computeDistance = function (coords, options) { | ||
| var google = getGoogleAPI(options); | ||
| var distance = 0; | ||
@@ -64,0 +86,0 @@ for (var i = 0; i < coords.length - 1; ++i) { |
+4
-1
| { | ||
| "name": "compute-distance", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "author": "Daniel Sauble", | ||
@@ -23,3 +23,6 @@ "description": "Find the distance represented by a set of points, filter if necessary", | ||
| "url": "git+ssh://git@github.com/djsauble/compute-distance.git" | ||
| }, | ||
| "dependencies": { | ||
| "google-maps": "^3.2.1" | ||
| } | ||
| } |
+19
-15
| Find the distance associated with an array of geospatial coordinates. | ||
| There are three methods associated with this library. | ||
| There are three methods associated with this library. Each takes an `options` | ||
| param, where you can pass your Google Maps API object (using [this | ||
| library](https://www.npmjs.com/package/google-maps), for example). | ||
| *`filter(data)`* | ||
| **filter(data, options)** | ||
@@ -19,3 +21,3 @@ A filter designed to smooth abberations from a GPS trace. It discards | ||
| *`mapToGoogle(data)`* | ||
| **mapToGoogle(data, options)** | ||
@@ -31,5 +33,5 @@ Take an array of coordinates and convert them to google.maps.LatLng objects. | ||
| *`computeDistance(data)`* | ||
| **computeDistance(data, options)** | ||
| Take an array of google.maps.LatLng objects and compute the distance they | ||
| Take an array of `google.maps.LatLng` objects and compute the distance they | ||
| represent in meters. | ||
@@ -44,13 +46,15 @@ | ||
| var Distance = require(`compute-distance`); | ||
| var Distance = require('compute-distance'); | ||
| var GoogleMapsLoader = require('google-maps'); | ||
| GoogleMapsLoader.KEY = 'your-api-key'; | ||
| GoogleMapsLoader.LIBRARIES = ['geometry']; | ||
| var filtered = Distance.filter(data); // data is an array of coordinates | ||
| var points = Distance.mapToGoogle(filtered); | ||
| var distance = Distance.computeDistance(points); | ||
| GoogleMapsLoader.load(function(google) { | ||
| var options = { google: google }; | ||
| var filtered = Distance.filter(data, options); // data is an array of coordinates | ||
| var points = Distance.mapToGoogle(filtered, options); | ||
| var distance = Distance.computeDistance(points, options); | ||
| }; | ||
| To compute distance on a raw dataset, without filtering, do the following: | ||
| var Distance = require(`compute-distance`); | ||
| var points = Distance.mapToGoogle(data); | ||
| var distance = Distance.computeDistance(points); | ||
| To compute distance on a raw dataset, without filtering, pass your raw data to | ||
| `mapToGoogle` directly, instead of passing it through `filter` first. |
+269
-13
| (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
| (function (global){ | ||
| // Get the Google API object, if it exists | ||
| var getGoogleAPI = function (options) { | ||
| if (options && options.google) { | ||
| return options.google; | ||
| } | ||
| else if (global && global.google) { | ||
| return global.google; | ||
| } | ||
| else if (window && window.google) { | ||
| return window.google; | ||
| } | ||
| else { | ||
| console.log("Google API object does not exist"); | ||
| console.trace(); | ||
| } | ||
| return undefined; | ||
| }; | ||
| // Smooth the run (e.g. ignore bouncing GPS tracks) | ||
| var defaultFilter = function (data) { | ||
| var defaultFilter = function (data, options) { | ||
| var accurate = [], | ||
| filtered = [], | ||
| maxDistance = 20; // Meters | ||
| maxDistance = 20, // Meters | ||
| google = getGoogleAPI(options); | ||
@@ -47,4 +67,5 @@ // Filter out inaccurate points | ||
| // Get an array of coordinates | ||
| var getCoordinates = function (data) { | ||
| var coords = []; | ||
| var getCoordinates = function (data, options) { | ||
| var coords = [], | ||
| google = getGoogleAPI(options); | ||
@@ -62,3 +83,5 @@ for (var i in data) { | ||
| // Get the distance represented by a set of coordinates (meters) | ||
| var computeDistance = function (coords) { | ||
| var computeDistance = function (coords, options) { | ||
| var google = getGoogleAPI(options); | ||
| var distance = 0; | ||
@@ -77,16 +100,249 @@ for (var i = 0; i < coords.length - 1; ++i) { | ||
| }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
| },{}],2:[function(require,module,exports){ | ||
| (function(root, factory) { | ||
| if (root === null) { | ||
| throw new Error('Google-maps package can be used only in browser'); | ||
| } | ||
| if (typeof define === 'function' && define.amd) { | ||
| define(factory); | ||
| } else if (typeof exports === 'object') { | ||
| module.exports = factory(); | ||
| } else { | ||
| root.GoogleMapsLoader = factory(); | ||
| } | ||
| })(typeof window !== 'undefined' ? window : null, function() { | ||
| 'use strict'; | ||
| var googleVersion = '3.18'; | ||
| var script = null; | ||
| var google = null; | ||
| var loading = false; | ||
| var callbacks = []; | ||
| var onLoadEvents = []; | ||
| var originalCreateLoaderMethod = null; | ||
| var GoogleMapsLoader = {}; | ||
| GoogleMapsLoader.URL = 'https://maps.googleapis.com/maps/api/js'; | ||
| GoogleMapsLoader.KEY = null; | ||
| GoogleMapsLoader.LIBRARIES = []; | ||
| GoogleMapsLoader.CLIENT = null; | ||
| GoogleMapsLoader.CHANNEL = null; | ||
| GoogleMapsLoader.LANGUAGE = null; | ||
| GoogleMapsLoader.REGION = null; | ||
| GoogleMapsLoader.VERSION = googleVersion; | ||
| GoogleMapsLoader.WINDOW_CALLBACK_NAME = '__google_maps_api_provider_initializator__'; | ||
| GoogleMapsLoader._googleMockApiObject = {}; | ||
| GoogleMapsLoader.load = function(fn) { | ||
| if (google === null) { | ||
| if (loading === true) { | ||
| if (fn) { | ||
| callbacks.push(fn); | ||
| } | ||
| } else { | ||
| loading = true; | ||
| window[GoogleMapsLoader.WINDOW_CALLBACK_NAME] = function() { | ||
| ready(fn); | ||
| }; | ||
| GoogleMapsLoader.createLoader(); | ||
| } | ||
| } else if (fn) { | ||
| fn(google); | ||
| } | ||
| }; | ||
| GoogleMapsLoader.createLoader = function() { | ||
| script = document.createElement('script'); | ||
| script.type = 'text/javascript'; | ||
| script.src = GoogleMapsLoader.createUrl(); | ||
| document.body.appendChild(script); | ||
| }; | ||
| GoogleMapsLoader.isLoaded = function() { | ||
| return google !== null; | ||
| }; | ||
| GoogleMapsLoader.createUrl = function() { | ||
| var url = GoogleMapsLoader.URL; | ||
| url += '?callback=' + GoogleMapsLoader.WINDOW_CALLBACK_NAME; | ||
| if (GoogleMapsLoader.KEY) { | ||
| url += '&key=' + GoogleMapsLoader.KEY; | ||
| } | ||
| if (GoogleMapsLoader.LIBRARIES.length > 0) { | ||
| url += '&libraries=' + GoogleMapsLoader.LIBRARIES.join(','); | ||
| } | ||
| if (GoogleMapsLoader.CLIENT) { | ||
| url += '&client=' + GoogleMapsLoader.CLIENT + '&v=' + GoogleMapsLoader.VERSION; | ||
| } | ||
| if (GoogleMapsLoader.CHANNEL) { | ||
| url += '&channel=' + GoogleMapsLoader.CHANNEL; | ||
| } | ||
| if (GoogleMapsLoader.LANGUAGE) { | ||
| url += '&language=' + GoogleMapsLoader.LANGUAGE; | ||
| } | ||
| if (GoogleMapsLoader.REGION) { | ||
| url += '®ion=' + GoogleMapsLoader.REGION; | ||
| } | ||
| return url; | ||
| }; | ||
| GoogleMapsLoader.release = function(fn) { | ||
| var release = function() { | ||
| GoogleMapsLoader.KEY = null; | ||
| GoogleMapsLoader.LIBRARIES = []; | ||
| GoogleMapsLoader.CLIENT = null; | ||
| GoogleMapsLoader.CHANNEL = null; | ||
| GoogleMapsLoader.LANGUAGE = null; | ||
| GoogleMapsLoader.REGION = null; | ||
| GoogleMapsLoader.VERSION = googleVersion; | ||
| google = null; | ||
| loading = false; | ||
| callbacks = []; | ||
| onLoadEvents = []; | ||
| if (typeof window.google !== 'undefined') { | ||
| delete window.google; | ||
| } | ||
| if (typeof window[GoogleMapsLoader.WINDOW_CALLBACK_NAME] !== 'undefined') { | ||
| delete window[GoogleMapsLoader.WINDOW_CALLBACK_NAME]; | ||
| } | ||
| if (originalCreateLoaderMethod !== null) { | ||
| GoogleMapsLoader.createLoader = originalCreateLoaderMethod; | ||
| originalCreateLoaderMethod = null; | ||
| } | ||
| if (script !== null) { | ||
| script.parentElement.removeChild(script); | ||
| script = null; | ||
| } | ||
| if (fn) { | ||
| fn(); | ||
| } | ||
| }; | ||
| if (loading) { | ||
| GoogleMapsLoader.load(function() { | ||
| release(); | ||
| }); | ||
| } else { | ||
| release(); | ||
| } | ||
| }; | ||
| GoogleMapsLoader.onLoad = function(fn) { | ||
| onLoadEvents.push(fn); | ||
| }; | ||
| GoogleMapsLoader.makeMock = function() { | ||
| originalCreateLoaderMethod = GoogleMapsLoader.createLoader; | ||
| GoogleMapsLoader.createLoader = function() { | ||
| window.google = GoogleMapsLoader._googleMockApiObject; | ||
| window[GoogleMapsLoader.WINDOW_CALLBACK_NAME](); | ||
| }; | ||
| }; | ||
| var ready = function(fn) { | ||
| var i; | ||
| loading = false; | ||
| if (google === null) { | ||
| google = window.google; | ||
| } | ||
| for (i = 0; i < onLoadEvents.length; i++) { | ||
| onLoadEvents[i](google); | ||
| } | ||
| if (fn) { | ||
| fn(google); | ||
| } | ||
| for (i = 0; i < callbacks.length; i++) { | ||
| callbacks[i](google); | ||
| } | ||
| callbacks = []; | ||
| }; | ||
| return GoogleMapsLoader; | ||
| }); | ||
| },{}],3:[function(require,module,exports){ | ||
| var Distance = require('../index'); | ||
| var GoogleMapsLoader = require('google-maps'); | ||
| GoogleMapsLoader.KEY = 'AIzaSyDrMrHDCL33b4PkB0p5SZlCR7mwc7Yp7SA'; | ||
| GoogleMapsLoader.LIBRARIES = ['geometry']; | ||
| QUnit.test( 'Filter a GPS track to ensure the filter works', function(assert) { | ||
| var filtered = Distance.filter(data); | ||
| var done = assert.async(); | ||
| var raw = Distance.mapToGoogle(data); | ||
| var civilized = Distance.mapToGoogle(filtered); | ||
| GoogleMapsLoader.load(function(google) { | ||
| var options = { google: google }; | ||
| var rawDistance = Distance.computeDistance(raw); | ||
| var filteredDistance = Distance.computeDistance(civilized); | ||
| var filtered = Distance.filter(data, options); | ||
| assert.equal(104.01168761662434, rawDistance, 'Passed!'); | ||
| assert.equal(97.55330283703395, filteredDistance, 'Passed!'); | ||
| var raw = Distance.mapToGoogle(data, options); | ||
| var civilized = Distance.mapToGoogle(filtered, options); | ||
| var rawDistance = Distance.computeDistance(raw, options); | ||
| var filteredDistance = Distance.computeDistance(civilized, options); | ||
| assert.equal(104.01168761662434, rawDistance, 'Passed!'); | ||
| assert.equal(97.55330283703395, filteredDistance, 'Passed!'); | ||
| done(); | ||
| }); | ||
| }); | ||
@@ -321,2 +577,2 @@ | ||
| },{"../index":1}]},{},[2]); | ||
| },{"../index":1,"google-maps":2}]},{},[3]); |
+0
-1
@@ -12,3 +12,2 @@ <!DOCTYPE html> | ||
| <div id='qunit-fixture'></div> | ||
| <script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyDrMrHDCL33b4PkB0p5SZlCR7mwc7Yp7SA&libraries=geometry' type='text/javascript'></script> | ||
| <script src='https://code.jquery.com/qunit/qunit-2.0.1.js'></script> | ||
@@ -15,0 +14,0 @@ <script src='bundle.js'></script> |
+18
-7
| var Distance = require('../index'); | ||
| var GoogleMapsLoader = require('google-maps'); | ||
| GoogleMapsLoader.KEY = 'AIzaSyDrMrHDCL33b4PkB0p5SZlCR7mwc7Yp7SA'; | ||
| GoogleMapsLoader.LIBRARIES = ['geometry']; | ||
| QUnit.test( 'Filter a GPS track to ensure the filter works', function(assert) { | ||
| var filtered = Distance.filter(data); | ||
| var done = assert.async(); | ||
| var raw = Distance.mapToGoogle(data); | ||
| var civilized = Distance.mapToGoogle(filtered); | ||
| GoogleMapsLoader.load(function(google) { | ||
| var options = { google: google }; | ||
| var rawDistance = Distance.computeDistance(raw); | ||
| var filteredDistance = Distance.computeDistance(civilized); | ||
| var filtered = Distance.filter(data, options); | ||
| assert.equal(104.01168761662434, rawDistance, 'Passed!'); | ||
| assert.equal(97.55330283703395, filteredDistance, 'Passed!'); | ||
| var raw = Distance.mapToGoogle(data, options); | ||
| var civilized = Distance.mapToGoogle(filtered, options); | ||
| var rawDistance = Distance.computeDistance(raw, options); | ||
| var filteredDistance = Distance.computeDistance(civilized, options); | ||
| assert.equal(104.01168761662434, rawDistance, 'Passed!'); | ||
| assert.equal(97.55330283703395, filteredDistance, 'Passed!'); | ||
| done(); | ||
| }); | ||
| }); | ||
@@ -15,0 +26,0 @@ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
28024
29.81%838
32.81%58
7.41%1
Infinity%2
100%+ Added
+ Added