cheap-ruler
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -11,3 +11,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.cheapRuler = f()}})(function(){var define,module,exports;return (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){ | ||
// unit multipliers for conversion from kilometers | ||
var factors = { | ||
var factors = cheapRuler.units = { | ||
kilometers: 1, | ||
miles: 1000 / 1609.344, | ||
@@ -30,2 +31,3 @@ nauticalmiles: 1000 / 1852, | ||
if (lat === undefined) throw new Error('No latitude given.'); | ||
if (units && !factors[units]) throw new Error('Unknown unit ' + units + '. Use one of: ' + Object.keys(factors)); | ||
@@ -32,0 +34,0 @@ var f = lat * Math.PI / 180; |
@@ -10,3 +10,4 @@ 'use strict'; /* @flow */ | ||
// unit multipliers for conversion from kilometers | ||
var factors = { | ||
var factors = cheapRuler.units = { | ||
kilometers: 1, | ||
miles: 1000 / 1609.344, | ||
@@ -29,2 +30,3 @@ nauticalmiles: 1000 / 1852, | ||
if (lat === undefined) throw new Error('No latitude given.'); | ||
if (units && !factors[units]) throw new Error('Unknown unit ' + units + '. Use one of: ' + Object.keys(factors)); | ||
@@ -31,0 +33,0 @@ var f = lat * Math.PI / 180; |
{ | ||
"name": "cheap-ruler", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A collection of fast approximations to common geographic measurements.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -169,2 +169,23 @@ # cheap-ruler [![Build Status](https://travis-ci.org/mapbox/cheap-ruler.svg?branch=master)](https://travis-ci.org/mapbox/cheap-ruler) [![](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects) | ||
### Units conversion | ||
Multipliers for converting between units are also exposed in `cheapRuler.units`: | ||
```js | ||
// convert 50 meters to yards | ||
50 * cheapRuler.units.yards / cheapRuler.units.meters; | ||
``` | ||
If you don't specify units when creating a ruler object, | ||
you can use these constants to convert return values (using multiplication) | ||
and input arguments (using division) to any units: | ||
```js | ||
// get distance between points in feet | ||
var distanceInFeet = ruler.distance(a, b) * cheapRuler.units.feet; | ||
// make a bbox from a point with a 200 inch buffer | ||
var box = ruler.bufferPoint(p, 200 / cheapRuler.units.inches); | ||
``` | ||
## Install | ||
@@ -171,0 +192,0 @@ |
88081
24
846
208