Updated bower dependencies for client.

This commit is contained in:
baldo 2022-08-02 15:24:19 +02:00
commit fe5b68e1c4
136 changed files with 7596 additions and 9284 deletions

View file

@ -1,7 +1,7 @@
{
"name": "Geolib",
"main": "dist/geolib.js",
"version": "2.0.22",
"main": "geolib.js",
"version": "1.3.5",
"homepage": "https://github.com/manuelbieh/Geolib",
"authors": [
"Manuel Bieh <github@manuelbieh.de>"
@ -20,13 +20,13 @@
"test",
"tests"
],
"_release": "2.0.22",
"_release": "1.3.5",
"_resolution": {
"type": "version",
"tag": "v2.0.22",
"commit": "cfa4d4f1a887a3327507f7dde452953c7497db33"
"tag": "1.3.5",
"commit": "2189417c87a6a56d28f30cd4d021e58a066798bc"
},
"_source": "https://github.com/manuelbieh/Geolib.git",
"_target": "2.0.22",
"_target": "1.3.5",
"_originalSource": "geolib"
}

View file

@ -1,133 +1,115 @@
/*global module:false*/
module.exports = function(grunt) {
require('time-grunt')(grunt);
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-text-replace');
require('load-grunt-tasks')(grunt);
var fs = require('fs');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.name %> <%= pkg.version %> by <%= pkg.author.name %>\n'+
'* Library to provide geo functions like distance calculation,\n' +
'* conversion of decimal coordinates to sexagesimal and vice versa, etc.\n' +
'* WGS 84 (World Geodetic System 1984)\n' +
'* \n' +
'* @author <%= pkg.author.name %>\n' +
'* @url <%= pkg.author.url %>\n' +
'* @version <%= pkg.version %>\n' +
'* @license <%= _.pluck(pkg.licenses, "type").join(", ") %> \n**/',
lint: {
files: ['src/geolib.js']
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.name %> <%= pkg.version %> by <%= pkg.author.name %>\n'+
'* A growing library to provide some basic geo functions like distance calculation,\n' +
'* conversion of decimal coordinates to sexagesimal and vice versa, etc.\n' +
'* WGS 84 (World Geodetic System 1984)\n' +
'* \n' +
'* @author <%= pkg.author.name %>\n' +
'* @url <%= pkg.author.url %>\n' +
'* @version <%= pkg.version %>\n' +
'* @license <%= _.pluck(pkg.licenses, "type").join(", ") %> \n**/',
lint: {
files: ['src/geolib.js']
},
qunit: {
files: ['tests/*.html']
},
concat: {
options: {
banner: '<%= banner %>',
report: false
},
qunit: {
files: ['tests/*.html']
},
concat: {
main: {
options: {
banner: '<%= banner %>',
report: false
},
src: ['src/geolib.js'],
dest: 'dist/geolib.js'
}
},
copy: {
component: {
files: [{
src: "package.json",
dest: "component.json"
}]
},
elev: {
files: [{
src: ['src/geolib.elevation.js'],
dest: 'dist/geolib.elevation.js'
}]
},
pointInside: {
files: [{
src: ['src/geolib.isPointInsideRobust.js'],
dest: 'dist/geolib.isPointInsideRobust.js'
}]
},
},
replace: {
version: {
src: ['dist/*.js', 'bower.json', 'README.md'],
overwrite: true,
replacements: [
{
from: '$version$',
to: '<%= pkg.version %>'
}, {
from: /"version": "([0-9a-zA-Z\-\.\+]*)",/,
to: '"version": "<%= pkg.version %>",'
}, {
from: /v[0-9]+\.[0-9]{1,2}\.[0-9]{1,}/,
to: 'v<%= pkg.version %>'
}
]
}
},
uglify: {
options: {
preserveComments: 'some'
},
main: {
files: {
'dist/geolib.min.js': ['dist/geolib.js']
}
},
elev: {
files: {
'dist/geolib.elevation.min.js': ['dist/geolib.elevation.js']
}
},
pointInside: {
files: {
'dist/geolib.isPointInsideRobust.min.js': ['dist/geolib.isPointInsideRobust.js']
}
},
},
watch: {
all: {
files: '<%= jshint.all %>',
tasks: ['default']
}
},
jshint: {
all: [
'src/geolib.js',
'src/geolib.elevation.js',
'src/geolib.isPointInsideRobust.js',
],
options: {
curly: true,
eqeqeq: false,
immed: true,
latedef: true,
newcap: false,
noarg: true,
sub: true,
undef: true,
evil: true,
boss: true,
eqnull: true,
globals: {
module: true,
define: true,
require: true,
elevationResult: true
}
}
full: {
src: ['src/geolib.js'],
dest: 'geolib.js'
}
});
},
copy: {
component: {
files: [{
src: "package.json",
dest: "component.json"
}]
}
},
replace: {
noelevation: {
src: 'geolib.js',
dest: 'geolib.js',
replacements: [{
from: '/* %ELEVATION% */',
to: ''
}]
},
full: {
src: 'geolib.js',
dest: 'geolib.js',
replacements: [{
from: '/* %ELEVATION% */',
to: fs.readFileSync('src/geolib.elevation.js', 'utf-8')
}]
}
},
uglify: {
options: {
banner: "<%= banner %>"
},
full: {
files: {
'geolib.min.js': ['geolib.js']
}
}
},
watch: {
files: '<config:lint.files>',
tasks: 'lint test'
},
jshint: {
all: [
'src/geolib.js'
],
options: {
curly: true,
eqeqeq: false,
immed: true,
latedef: true,
newcap: false,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
globals: {
module: true,
define: true
}
}
}
});
// Default task.
grunt.registerTask('default', ['concat:main', 'copy', 'replace', 'uglify']);
grunt.registerTask('travis', ['jshint','qunit']);
grunt.registerTask('test', ['qunit']);
// Default task.
//grunt.registerTask('default', 'lint test concat min');
//grunt.registerTask('default', 'lint qunit clean concat:full min copy');
grunt.registerTask('default', ['concat:full', 'copy', 'replace:full', 'uglify']);
grunt.registerTask('travis', ['jshint','qunit']);
grunt.registerTask('test', ['qunit']);
//grunt.registerTask('no-elevation', 'lint qunit concat:noelevation min');
grunt.registerTask('no-elevation', ['concat:full', 'replace:noelevation', 'uglify']);
};

View file

@ -1,21 +0,0 @@
The MIT License
Copyright (c) 2011-2014 Manuel Bieh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -1,133 +1,79 @@
# Geolib v2.0.21
# Geolib
[![Build Status](https://secure.travis-ci.org/manuelbieh/Geolib.png?branch=master)](http://travis-ci.org/manuelbieh/Geolib)
Library to provide basic geospatial operations like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc.
A small library to provide some basic geo functions like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc.
[View demo](http://www.manuel-bieh.de/publikationen/scripts/geolib/demo.html)
<h2>Methods</h2>
<h3>geolib.getDistance(object start, object end[, int accuracy, int precision])</h3>
<h3>geolib.getDistance(object start, object end[, int accuracy])</h3>
Calculates the distance between two geo coordinates
Takes 2 or 4 arguments. First 2 arguments must be objects that each have latitude and longitude properties (e.g. `{latitude: 52.518611, longitude: 13.408056}`)Works with:. Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distaWorks with:nce of 1248 meters with an accuracy of 100 is returned as `1200` (accuracy 10 = `1250` etc.). 4th argument is precision in sub-meters (1 is meter presicion, 2 is decimeters, 3 is centimeters, etc).
Takes 2 or 3. First 2 arguments must be an object with a latitude and a longitude property (e.g. {latitude: 52.518611, longitude: 13.408056}). Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distance of 1248 meters with an accuracy of 100 is returned as 1200.
Return value is always float and represents the distance in meters.
Return value is always an integer and represents the distance in meters.
<h4>Examples</h4>
<pre>geolib.getDistance(
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}
);
geolib.getDistance(
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}
);
// Working with W3C Geolocation API
navigator.geolocation.getCurrentPosition(
function(position) {
alert('You are ' + geolib.getDistance(position.coords, {
latitude: 51.525,
longitude: 7.4575
}) + ' meters away from 51.525, 7.4575');
},
function() {
alert('Position could not be determined.')
},
{
enableHighAccuracy: true
}
function(position) {
alert('You are ' + geolib.getDistance(position.coords, {
latitude: 51.525,
longitude: 7.4575
}) + ' meters away from 51.525, 7.4575');
},
function() {
alert('Position could not be determined.')
},
{
enableHighAccuracy: true
}
);
</pre>
<h3>geolib.getDistanceSimple(object start, object end[, int accuracy])</h3>
Calculates the distance between two geo coordinates but this method is far more inaccurate as compared to getDistance.
It can take up 2 to 3 arguments. start, end and accuracy can be defined in the same as in getDistance.
Return value is always float that represents the distance in meters.
<h4>Examples</h4>
<pre>geolib.getDistanceSimple(
{latitude: 51.5103, longitude: 7.49347},
{latitude: "51° 31' N", longitude: "7° 28' E"}
);</pre>
<h3>geolib.getCenter(array coords)</h3>
Calculates the geographical center of all points in a collection of geo coordinates
Takes an object or array of coordinates and calculates the center of it.
Returns an object: `{"latitude": centerLat, "longitude": centerLng}`
Returns an object: `{"latitude": centerLat, "longitude": centerLng, "distance": diagonalDistance}`
<h4>Examples</h4>
<pre>var spots = {
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
"London Eye": {latitude: 51.503333, longitude: -0.119722},
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
"London Eye": {latitude: 51.503333, longitude: -0.119722},
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
}
geolib.getCenter(spots);
geolib.getCenter([
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.515, longitude: 7.453619},
{latitude: 51.503333, longitude: -0.119722}
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.515, longitude: 7.453619},
{latitude: 51.503333, longitude: -0.119722}
]);
</pre>
<h3>geolib.getCenterOfBounds(array coords)</h3>
<h3>geolib.isPointInside(object latlng, array coords)</h3>
Calculates the center of the bounds of geo coordinates.
Takes an array of coordinates, calculate the border of those, and gives back
the center of that rectangle.
On polygons like political borders (eg. states), this may gives a closer
result to human expectation, than `getCenter`, because that function can be
disturbed by uneven distribution of point in different sides.
Imagine the US state Oklahoma: `getCenter` on that gives a southern
point, because the southern border contains a lot more nodes, than the others.
Returns an object: `{"latitude": centerLat, "longitude": centerLng}`
<h3>geolib.getBounds(array coords)</h3>
Calculates the bounds of geo coordinates.
It returns maximum and minimum, latitude, longitude, and elevation (if provided) in form of an object of form:
<pre>{
"minLat": minimumLatitude,
"maxLat": maximumLatitude,
"minLng": minimumLongitude,
"maxLng": maximumLongitude,
"minElev": minimumElevation,
"maxElev": maximumElevation
}</pre>
<h4>Example</h4>
<pre>geolib.getCenter([
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.515, longitude: 7.453619},
{latitude: 51.503333, longitude: -0.119722}
]);</pre>
<h3>geolib.isPointInside(object latlng, array polygon)</h3>
Checks whether a point is inside of a polygon or not.
Checks whether a point is inside of a polygon or not.
Note: the polygon coords must be in correct order!
Returns true or false
@ -136,18 +82,18 @@ Returns true or false
<pre>
geolib.isPointInside(
{latitude: 51.5125, longitude: 7.485},
[
{latitude: 51.50, longitude: 7.40},
{latitude: 51.555, longitude: 7.40},
{latitude: 51.555, longitude: 7.625},
{latitude: 51.5125, longitude: 7.625}
]
{latitude: 51.5125, longitude: 7.485},
[
{latitude: 51.50, longitude: 7.40},
{latitude: 51.555, longitude: 7.40},
{latitude: 51.555, longitude: 7.625},
{latitude: 51.5125, longitude: 7.625}
]
); // -> true</pre>
<h3>geolib.isPointInCircle(object latlng, object center, integer radius)</h3>
Similar to is point inside: checks whether a point is inside of a circle or not.
Similar to is point inside: checks whether a point is inside of a circle or not.
Returns true or false
@ -155,60 +101,11 @@ Returns true or false
<pre>// checks if 51.525, 7.4575 is within a radius of 5km from 51.5175, 7.4678
geolib.isPointInCircle(
{latitude: 51.525, longitude: 7.4575},
{latitude: 51.5175, longitude: 7.4678},
5000
{latitude: 51.525, longitude: 7.4575},
{latitude: 51.5175, longitude: 7.4678},
5000
);</pre>
<h3>geolib.getRhumbLineBearing(object originLL, object destLL)</h3>
Gets rhumb line bearing of two points. Find out about the difference between rhumb line and
great circle bearing on Wikipedia. Rhumb line should be fine in most cases:
http://en.wikipedia.org/wiki/Rhumb_line#General_and_mathematical_description
Function is heavily based on Doug Vanderweide's great PHP version (licensed under GPL 3.0)
http://www.dougv.com/2009/07/13/calculating-the-bearing-and-compass-rose-direction-between-two-latitude-longitude-coordinates-in-php/
Returns calculated bearing as integer.
<h4>Example</h4>
<pre>geolib.getRhumbLineBearing(
{latitude: 52.518611, longitude: 13.408056},
{latitude: 51.519475, longitude: 7.46694444}
);</pre>
<h3>geolib.getBearing(object originLL, object destLL)</h3>
Gets great circle bearing of two points. See description of getRhumbLineBearing for more information.
Returns calculated bearing as integer.
<h4>Example</h4>
<pre>geolib.getBearing(
{latitude: 52.518611, longitude: 13.408056},
{latitude: 51.519475, longitude: 7.46694444}
);</pre>
<h3>geolib.getCompassDirection(object originLL, object destLL, string bearingMode (optional))</h3>
Gets the compass direction from an origin coordinate (originLL) to a destination coordinate (destLL).
Bearing mode. Can be either circle or rhumbline (default).
Returns an object with a rough (NESW) and an exact direction (NNE, NE, ENE, E, ESE, etc).
<h4>Example</h4>
<pre>geolib.getCompassDirection(
{latitude: 52.518611, longitude: 13.408056},
{latitude: 51.519475, longitude: 7.46694444}
);
//Output
{
rough: 'W',
exact: 'WSW'
}</pre>
<h3>geolib.orderByDistance(object latlng, mixed coords)</h3>
Sorts an object or array of coords by distance from a reference coordinate
@ -220,58 +117,59 @@ Returns a sorted array [{latitude: x, longitude: y, distance: z, key: property}]
<pre>
// coords array
geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, [
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.518, longitude: 7.45425},
{latitude: 51.503333, longitude: -0.119722}
{latitude: 52.516272, longitude: 13.377722},
{latitude: 51.518, longitude: 7.45425},
{latitude: 51.503333, longitude: -0.119722}
]);
// coords object
geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, {
a: {latitude: 52.516272, longitude: 13.377722},
b: {latitude: 51.518, longitude: 7.45425},
c: {latitude: 51.503333, longitude: -0.119722}
a: {latitude: 52.516272, longitude: 13.377722},
b: {latitude: 51.518, longitude: 7.45425},
c: {latitude: 51.503333, longitude: -0.119722}
});
</pre>
<h3>geolib.findNearest(object latlng, mixed coords[[, int offset], int limit])</h3>
<h3>geolib.findNearest(object latlng, mixed coords[, int offset])</h3>
Finds the nearest coordinate to a reference coordinate.
<h4>Examples</h4>
<pre>var spots = {
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
"London Eye": {latitude: 51.503333, longitude: -0.119722},
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
"London Eye": {latitude: 51.503333, longitude: -0.119722},
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
}
// in this case set offset to 1 otherwise the nearest point will always be your reference point
geolib.findNearest(spots['Dortmund U-Tower'], spots, 1)
geolib.findNearest(spots['Dortmund U-Tower'], spots, 1)
</pre>
<h3>geolib.getPathLength(mixed coords)</h3>
Calculates the length of a collection of coordinates
Returns the length of the path in meters
Returns the length of the path in kilometers
<h4>Example</h4>
<pre>
// Calculate distance from Berlin via Dortmund to London
geolib.getPathLength([
{latitude: 52.516272, longitude: 13.377722}, // Berlin
{latitude: 51.515, longitude: 7.453619}, // Dortmund
{latitude: 51.503333, longitude: -0.119722} // London
{latitude: 52.516272, longitude: 13.377722}, // Berlin
{latitude: 51.515, longitude: 7.453619}, // Dortmund
{latitude: 51.503333, longitude: -0.119722} // London
]); // -> 945235</pre>
<h3>geolib.getSpeed(coords, coords[, options])</h3>
Calculates the speed between two points within a given time span.
Calculates the speed between to points within a given time span.
Returns the speed in <em>options.unit</em> (default is km/h).
@ -279,29 +177,12 @@ Returns the speed in <em>options.unit</em> (default is km/h).
<pre>
geolib.getSpeed(
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
{lat: 52.54944, lng: 13.468509, time: 1360245600880},
{unit: 'mph'}
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
{lat: 52.54944, lng: 13.468509, time: 1360245600880},
{unit: 'mph'}
); // -> 66.9408 (mph)</pre>
<h3>geolib.isPointInLine(object point, object start, object end</h3>
Calculates if given point lies in a line formed by start and end.
Returns true or false
<h4>Examples</h4>
<pre>var point1 = {latitude: 0.5, longitude: 0};
var point2 = {latitude: 0, longitude: 10};
var point3 = {latitude: 0, longitude: 15.5};
var start = {latitude: 0, longitude: 0};
var end = {latitude: 0, longitude: 15};
var isInLine1 = geolib.isPointInLine(point1, start, end) //-> false;
var isInLine2 = geolib.isPointInLine(point2, start, end) //-> true;
var isInLine3 = geolib.isPointInLine(point3, start, end) //-> false;
</pre>
<h3>geolib.convertUnit(string unit, float distance[, int round])</h3>
@ -341,63 +222,16 @@ Converts a sexagesimal coordinate to decimal format
Converts a decimal coordinate to sexagesimal format
<h4>Example</h4>
`geolib.decimal2sexagesimal(51.49611111); // -> 51° 29' 46.00`
<h3>geolib.latitude(object latlng)</h3>
<h3>geolib.longitude(object latlng)</h3>
<h3>geolib.elevation(object latlng)</h3>
Returns the latitude/longitude/elevation for a given point and converts it to decimal.
Works with:
- longitude: `longitude`, `lng`, `lon`, 0 (GeoJSON array)
- latitude: `latitude`, `lat`, 1 (GeoJSON array)
- elevation: `elevation`, `elev`, `alt`, `altitude`, 2 (GeoJSON array)
<h4>Examples</h4>
`geolib.latitude({lat: 51.49611, lng: 7.38896}); // -> 51.49611`
`geolib.longitude({lat: 51.49611, lng: 7.38896}); // -> 7.38896`
<h3>geolib.useDecimal(mixed latlng)</h3>
<h3>geolib.useDecimal(mixed coordinate)</h3>
Checks if a coordinate is already in decimal format and, if not, converts it to
<h4>Example</h4>
<pre>geolib.useDecimal("51° 29' 46\" N"); // -> 51.59611111
geolib.useDecimal(51.59611111) // -> 51.59611111</pre>
<h3>geolib.computeDestinationPoint(start, distance, bearing, radius(optional))</h3>
Computes the destination point given an initial point, a distance and a bearing
If no radius is given it defaults to the mean earth radius of 6371000 meter.
Returns an object: `{"latitude": destLat, "longitude": destLng}`
(Attention: this formula is not *100%* accurate (but very close though))
<h4>Example</h4>
<pre>var initialPoint = {lat: 51.516272, lon: 0.45425}
var dist = 1234;
var bearing = 45;
geolib.computeDestinationPoint(initialPoint, dist, bearing);
// -> {"latitude":51.52411853234181,"longitude":0.4668623365950795}
</pre>
<h2>Changelog</h2>
<h3>v2.0.0+beta1</h3>
- Dropped support for IE6, IE7, IE8
- Added new methods `geolib.latitude()`, `geolib.longitude()`, `geolib.elevation()` to get latitude, longitude or elevation of points. Will be converted to decimal format automatically
- Added new method `geolib.extend()` to extend geolib object
- Added support for GeoJSON format (`[lon, lat, elev]`)
- Added property `geolib.version` to query the currently used version
- Moved `geolib.elevation` to an optional module (`geolib.elevation.js`)
- Using `Object.create(Geolib.prototype)` instead of object literal `{}`
- New folder structure: compiled `geolib.js` can now be found in `dist/` instead of root dir
- Improved Grunt build task

View file

@ -1,10 +1,10 @@
{
"name": "Geolib",
"main": "dist/geolib.js",
"version": "2.0.21",
"main": "geolib.js",
"version": "1.3.5",
"homepage": "https://github.com/manuelbieh/Geolib",
"authors": [
"Manuel Bieh <github@manuelbieh.de>"
"Manuel Bieh <github@manuelbieh.de>"
],
"description": "Library to perform geo specific tasks",
"keywords": [

View file

@ -1,52 +0,0 @@
{
"name": "geolib",
"homepage": "http://github.com/manuelbieh/Geolib",
"author": {
"name": "Manuel Bieh",
"url": "http://www.manuelbieh.com/"
},
"repository": {
"type": "git",
"url": "http://github.com/manuelbieh/geolib.git"
},
"devDependencies": {
"grunt": "~0.4",
"grunt-cli": "*",
"grunt-contrib-uglify": "~0.2",
"grunt-contrib-concat": "~0.3",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-copy": "~0.4",
"grunt-contrib-qunit": "~0.2.0",
"grunt-text-replace": "~0.3.6",
"grunt-contrib-jshint": "~0.6.2",
"phantomjs": ">=1.8.0",
"grunt-jslint": "~1.0.0",
"time-grunt": "~0.3.1",
"load-grunt-tasks": "~0.4.0"
},
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
],
"files": [
"dist/geolib.js",
"dist/geolib.elevation.js"
],
"description": "Library to perform geo specific tasks",
"keywords": [
"geolocation",
"geo",
"distance",
"geojson",
"geospatial",
"lbs",
"location"
],
"scripts": {
"test": "grunt travis --verbose"
},
"version": "2.0.21",
"main": "dist/geolib.js"
}

View file

@ -1,190 +0,0 @@
/*! geolib.elevation 2.0.21 by Manuel Bieh
*
* Elevation Addon for Geolib.js
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
* @version 2.0.21
* @license MIT
*/
;(function(global, geolib, undefined) {
var elevation = {
/*global google:true geolib:true require:true module:true elevationResult:true */
/**
* @param Array Collection of coords [{latitude: 51.510, longitude: 7.1321}, {latitude: 49.1238, longitude: "8° 30' W"}, ...]
* @return Array [{lat:#lat, lng:#lng, elev:#elev},....]}
*/
getElevation: function() {
if (typeof global.navigator !== 'undefined') {
this.getElevationClient.apply(this, arguments);
} else {
this.getElevationServer.apply(this, arguments);
}
},
/* Optional elevation addon requires Googlemaps API JS */
getElevationClient: function(coords, cb) {
if (!global.google) {
throw new Error("Google maps api not loaded");
}
if (coords.length === 0) {
return cb(null, null);
}
if (coords.length === 1) {
return cb(new Error("getElevation requires at least 2 points."));
}
var path = [];
for(var i = 0; i < coords.length; i++) {
path.push(new google.maps.LatLng(
this.latitude(coords[i]),
this.longitude(coords[i])
));
}
var positionalRequest = {
'path': path,
'samples': path.length
};
var elevationService = new google.maps.ElevationService();
var geolib = this;
elevationService.getElevationAlongPath(positionalRequest, function (results, status) {
geolib.elevationHandler(results, status, coords, cb);
});
},
getElevationServer: function(coords, cb) {
if (coords.length === 0) {
return cb(null, null);
}
if (coords.length === 1) {
return cb(new Error("getElevation requires at least 2 points."));
}
var gm = require('googlemaps');
var path = [];
for(var i = 0; i < coords.length; i++) {
path.push(
this.latitude(coords[i]) + ',' + this.longitude(coords[i])
);
}
var geolib = this;
gm.elevationFromPath(path.join('|'), path.length, function(err, results) {
geolib.elevationHandler(results.results, results.status, coords, cb);
});
},
elevationHandler: function(results, status, coords, cb) {
var latsLngsElevs = [];
if (status == "OK" ) {
for (var i = 0; i < results.length; i++) {
latsLngsElevs.push({
"lat": this.latitude(coords[i]),
"lng": this.longitude(coords[i]),
"elev":results[i].elevation
});
}
cb(null, latsLngsElevs);
} else {
cb(new Error("Could not get elevation using Google's API"), elevationResult.status);
}
},
/**
* @param Array [{lat:#lat, lng:#lng, elev:#elev},....]}
* @return Number % grade
*/
getGrade: function(coords) {
var rise = Math.abs(
this.elevation(coords[coords.length-1]) - this.elevation(coords[0])
);
var run = this.getPathLength(coords);
return Math.floor((rise/run)*100);
},
/**
* @param Array [{lat:#lat, lng:#lng, elev:#elev},....]}
* @return Object {gain:#gain, loss:#loss}
*/
getTotalElevationGainAndLoss: function(coords) {
var gain = 0;
var loss = 0;
for(var i = 0; i < coords.length - 1; i++) {
var deltaElev = this.elevation(coords[i]) - this.elevation(coords[i + 1]);
if (deltaElev > 0) {
loss += deltaElev;
} else {
gain += Math.abs(deltaElev);
}
}
return {
"gain": gain,
"loss": loss
};
}
};
// Node module
if (typeof module !== 'undefined' &&
typeof module.exports !== 'undefined') {
geolib = require('geolib');
geolib.extend(elevation);
// AMD module
} else if (typeof define === "function" && define.amd) {
define(["geolib"], function (geolib) {
geolib.extend(elevation);
return geolib;
});
// we're in a browser
} else {
geolib.extend(elevation);
}
}(this, this.geolib));

View file

@ -1,10 +0,0 @@
/*! geolib.elevation 2.0.21 by Manuel Bieh
*
* Elevation Addon for Geolib.js
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
* @version 2.0.21
* @license MIT
*/
!function(a,b,c){var d={getElevation:function(){"undefined"!=typeof a.navigator?this.getElevationClient.apply(this,arguments):this.getElevationServer.apply(this,arguments)},getElevationClient:function(b,c){if(!a.google)throw new Error("Google maps api not loaded");if(0===b.length)return c(null,null);if(1===b.length)return c(new Error("getElevation requires at least 2 points."));for(var d=[],e=0;e<b.length;e++)d.push(new google.maps.LatLng(this.latitude(b[e]),this.longitude(b[e])));var f={path:d,samples:d.length},g=new google.maps.ElevationService,h=this;g.getElevationAlongPath(f,function(a,d){h.elevationHandler(a,d,b,c)})},getElevationServer:function(a,b){if(0===a.length)return b(null,null);if(1===a.length)return b(new Error("getElevation requires at least 2 points."));for(var c=require("googlemaps"),d=[],e=0;e<a.length;e++)d.push(this.latitude(a[e])+","+this.longitude(a[e]));var f=this;c.elevationFromPath(d.join("|"),d.length,function(c,d){f.elevationHandler(d.results,d.status,a,b)})},elevationHandler:function(a,b,c,d){var e=[];if("OK"==b){for(var f=0;f<a.length;f++)e.push({lat:this.latitude(c[f]),lng:this.longitude(c[f]),elev:a[f].elevation});d(null,e)}else d(new Error("Could not get elevation using Google's API"),elevationResult.status)},getGrade:function(a){var b=Math.abs(this.elevation(a[a.length-1])-this.elevation(a[0])),c=this.getPathLength(a);return Math.floor(b/c*100)},getTotalElevationGainAndLoss:function(a){for(var b=0,c=0,d=0;d<a.length-1;d++){var e=this.elevation(a[d])-this.elevation(a[d+1]);e>0?c+=e:b+=Math.abs(e)}return{gain:b,loss:c}}};"undefined"!=typeof module&&"undefined"!=typeof module.exports?(b=require("geolib"),b.extend(d)):"function"==typeof define&&define.amd?define(["geolib"],function(a){return a.extend(d),a}):b.extend(d)}(this,this.geolib);

View file

@ -1,744 +0,0 @@
/*! geolib.isPointInsideRobust 2.0.21
* !!EXPERIMENTAL!!
*
* Robust version of isPointInside for Geolib.js
*
* Based on https://github.com/mikolalysenko/robust-point-in-polygon
* by Mikola Lysenko, licensed under MIT
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
* @version 2.0.21
* @license MIT
*
*/
;(function(global, geolib, undefined) {
var addOn = function(geolib) {
var SPLITTER = +(Math.pow(2, 27) + 1.0);
var NUM_EXPAND = 5;
var EPSILON = 1.1102230246251565e-16;
var ERRBOUND3 = (3.0 + 16.0 * EPSILON) * EPSILON;
var ERRBOUND4 = (7.0 + 56.0 * EPSILON) * EPSILON;
var twoProduct = function(a, b, result) {
var x = a * b;
var c = SPLITTER * a;
var abig = c - a;
var ahi = c - abig;
var alo = a - ahi;
var d = SPLITTER * b;
var bbig = d - b;
var bhi = d - bbig;
var blo = b - bhi;
var err1 = x - (ahi * bhi);
var err2 = err1 - (alo * bhi);
var err3 = err2 - (ahi * blo);
var y = alo * blo - err3;
if(result) {
result[0] = y;
result[1] = x;
return result;
}
return [ y, x ];
};
var fastTwoSum = function(a, b, result) {
var x = a + b;
var bv = x - a;
var av = x - bv;
var br = b - bv;
var ar = a - av;
if(result) {
result[0] = ar + br;
result[1] = x;
return result;
}
return [ar+br, x];
};
var twoSum = fastTwoSum;
var linearExpansionSum = function(e, f) {
var ne = e.length|0;
var nf = f.length|0;
if(ne === 1 && nf === 1) {
return scalarScalar(e[0], f[0]);
}
var n = ne + nf;
var g = new Array(n);
var count = 0;
var eptr = 0;
var fptr = 0;
var abs = Math.abs;
var ei = e[eptr];
var ea = abs(ei);
var fi = f[fptr];
var fa = abs(fi);
var a, b;
if(ea < fa) {
b = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
b = fi;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
fa = abs(fi);
}
}
if((eptr < ne && ea < fa) || (fptr >= nf)) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
fa = abs(fi);
}
}
var x = a + b;
var bv = x - a;
var y = b - bv;
var q0 = y;
var q1 = x;
var _x, _bv, _av, _br, _ar;
while(eptr < ne && fptr < nf) {
if(ea < fa) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
fa = abs(fi);
}
}
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
}
while(eptr < ne) {
a = ei;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
}
}
while(fptr < nf) {
a = fi;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
}
}
if(q0) {
g[count++] = q0;
}
if(q1) {
g[count++] = q1;
}
if(!count) {
g[count++] = 0.0;
}
g.length = count;
return g;
};
var robustSum = linearExpansionSum;
var scaleLinearExpansion = function(e, scale) {
var n = e.length;
if(n === 1) {
var ts = twoProduct(e[0], scale);
if(ts[0]) {
return ts;
}
return [ ts[1] ];
}
var g = new Array(2 * n);
var q = [0.1, 0.1];
var t = [0.1, 0.1];
var count = 0;
twoProduct(e[0], scale, q);
if(q[0]) {
g[count++] = q[0];
}
for(var i=1; i<n; ++i) {
twoProduct(e[i], scale, t);
var pq = q[1];
twoSum(pq, t[0], q);
if(q[0]) {
g[count++] = q[0];
}
var a = t[1];
var b = q[1];
var x = a + b;
var bv = x - a;
var y = b - bv;
q[1] = x;
if(y) {
g[count++] = y;
}
}
if(q[1]) {
g[count++] = q[1];
}
if(count === 0) {
g[count++] = 0.0;
}
g.length = count;
return g;
};
var robustScale = scaleLinearExpansion;
var scalarScalar = function(a, b) {
var x = a + b;
var bv = x - a;
var av = x - bv;
var br = b - bv;
var ar = a - av;
var y = ar + br;
if(y) {
return [y, x];
}
return [x];
};
var robustSubtract = function(e, f) {
var ne = e.length|0;
var nf = f.length|0;
if(ne === 1 && nf === 1) {
return scalarScalar(e[0], -f[0]);
}
var n = ne + nf;
var g = new Array(n);
var count = 0;
var eptr = 0;
var fptr = 0;
var abs = Math.abs;
var ei = e[eptr];
var ea = abs(ei);
var fi = -f[fptr];
var fa = abs(fi);
var a, b;
if(ea < fa) {
b = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
b = fi;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
fa = abs(fi);
}
}
if((eptr < ne && ea < fa) || (fptr >= nf)) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
fa = abs(fi);
}
}
var x = a + b;
var bv = x - a;
var y = b - bv;
var q0 = y;
var q1 = x;
var _x, _bv, _av, _br, _ar;
while(eptr < ne && fptr < nf) {
if(ea < fa) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
fa = abs(fi);
}
}
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
}
while(eptr < ne) {
a = ei;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
}
}
while(fptr < nf) {
a = fi;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
}
}
if(q0) {
g[count++] = q0;
}
if(q1) {
g[count++] = q1;
}
if(!count) {
g[count++] = 0.0;
}
g.length = count;
return g;
};
var cofactor = function(m, c) {
var result = new Array(m.length-1);
for(var i=1; i<m.length; ++i) {
var r = result[i-1] = new Array(m.length-1);
for(var j=0,k=0; j<m.length; ++j) {
if(j === c) {
continue;
}
r[k++] = m[i][j];
}
}
return result;
};
var matrix = function(n) {
var result = new Array(n);
for(var i=0; i<n; ++i) {
result[i] = new Array(n);
for(var j=0; j<n; ++j) {
result[i][j] = ["m", j, "[", (n-i-1), "]"].join("");
}
}
return result;
};
var sign = function(n) {
if(n & 1) {
return "-";
}
return "";
};
var generateSum = function(expr) {
if(expr.length === 1) {
return expr[0];
} else if(expr.length === 2) {
return ["sum(", expr[0], ",", expr[1], ")"].join("");
} else {
var m = expr.length>>1;
return ["sum(", generateSum(expr.slice(0, m)), ",", generateSum(expr.slice(m)), ")"].join("");
}
};
var determinant = function(m) {
if(m.length === 2) {
return [["sum(prod(", m[0][0], ",", m[1][1], "),prod(-", m[0][1], ",", m[1][0], "))"].join("")];
} else {
var expr = [];
for(var i=0; i<m.length; ++i) {
expr.push(["scale(", generateSum(determinant(cofactor(m, i))), ",", sign(i), m[0][i], ")"].join(""));
}
return expr;
}
};
var orientation = function(n) {
var pos = [];
var neg = [];
var m = matrix(n);
var args = [];
for(var i=0; i<n; ++i) {
if((i&1)===0) {
pos.push.apply(pos, determinant(cofactor(m, i)));
} else {
neg.push.apply(neg, determinant(cofactor(m, i)));
}
args.push("m" + i);
}
var posExpr = generateSum(pos);
var negExpr = generateSum(neg);
var funcName = "orientation" + n + "Exact";
var code = [
"function ",
funcName,
"(", args.join(), "){var p=",
posExpr,
",n=",
negExpr,
",d=sub(p,n);return d[d.length-1];};return ",
funcName
].join("");
var proc = new Function("sum", "prod", "scale", "sub", code);
return proc(robustSum, twoProduct, robustScale, robustSubtract);
};
var orient;
var orientation3Exact = orientation(3);
var orientation4Exact = orientation(4);
var CACHED = [
function orientation0() { return 0; },
function orientation1() { return 0; },
function orientation2(a, b) {
return b[0] - a[0];
},
function orientation3(a, b, c) {
var l = (a[1] - c[1]) * (b[0] - c[0]);
var r = (a[0] - c[0]) * (b[1] - c[1]);
var det = l - r;
var s;
if(l > 0) {
if(r <= 0) {
return det;
} else {
s = l + r;
}
} else if(l < 0) {
if(r >= 0) {
return det;
} else {
s = -(l + r);
}
} else {
return det;
}
var tol = ERRBOUND3 * s;
if(det >= tol || det <= -tol) {
return det;
}
return orientation3Exact(a, b, c);
},
function orientation4(a,b,c,d) {
var adx = a[0] - d[0];
var bdx = b[0] - d[0];
var cdx = c[0] - d[0];
var ady = a[1] - d[1];
var bdy = b[1] - d[1];
var cdy = c[1] - d[1];
var adz = a[2] - d[2];
var bdz = b[2] - d[2];
var cdz = c[2] - d[2];
var bdxcdy = bdx * cdy;
var cdxbdy = cdx * bdy;
var cdxady = cdx * ady;
var adxcdy = adx * cdy;
var adxbdy = adx * bdy;
var bdxady = bdx * ady;
var det = adz * (bdxcdy - cdxbdy) +
bdz * (cdxady - adxcdy) +
cdz * (adxbdy - bdxady);
var permanent = (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
(Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
(Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
var tol = ERRBOUND4 * permanent;
if ((det > tol) || (-det > tol)) {
return det;
}
return orientation4Exact(a,b,c,d);
}
];
var slowOrient = function(args) {
var proc = CACHED[args.length];
if(!proc) {
proc = CACHED[args.length] = orientation(args.length);
}
return proc.apply(undefined, args);
};
var generateOrientationProc = function() {
while(CACHED.length <= NUM_EXPAND) {
CACHED.push(orientation(CACHED.length));
}
var args = [];
var procArgs = ["slow"];
for(var i=0; i<=NUM_EXPAND; ++i) {
args.push("a" + i);
procArgs.push("o" + i);
}
var code = [
"function getOrientation(",
args.join(),
"){switch(arguments.length){case 0:case 1:return 0;"
];
for(i=2; i<=NUM_EXPAND; ++i) {
code.push("case ", i, ":return o", i, "(", args.slice(0, i).join(), ");");
}
code.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation");
procArgs.push(code.join(""));
var proc = Function.apply(undefined, procArgs);
orient = proc.apply(undefined, [slowOrient].concat(CACHED));
for(i=0; i<=NUM_EXPAND; ++i) {
orient[i] = CACHED[i];
}
};
generateOrientationProc();
var robustPointInPolygon = function(vs, point) {
// transform from geolib format to array syntax
var x = geolib.longitude(point);
var y = geolib.latitude(point);
var coords = vs.map(function(coords) {
return [geolib.longitude(coords), geolib.latitude(coords)];
});
vs = coords;
point = [x,y];
var n = vs.length;
var inside = 1;
var lim = n;
var s, c, yk, px, p;
for(var i = 0, j = n-1; i<lim; j=i++) {
var a = vs[i];
var b = vs[j];
var yi = a[1];
var yj = b[1];
if(yj < yi) {
if(yj < y && y < yi) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (0 < s)|0;
}
} else if(y === yi) {
c = vs[(i+1)%n];
yk = c[1];
if(yi < yk) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (0 < s)|0;
}
}
}
} else if(yi < yj) {
if(yi < y && y < yj) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (s < 0)|0;
}
} else if(y === yi) {
c = vs[(i+1)%n];
yk = c[1];
if(yk < yi) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (s < 0)|0;
}
}
}
} else if(y === yi) {
var x0 = Math.min(a[0], b[0]);
var x1 = Math.max(a[0], b[0]);
if(i === 0) {
while(j>0) {
var k = (j+n-1)%n;
p = vs[k];
if(p[1] !== y) {
break;
}
px = p[0];
x0 = Math.min(x0, px);
x1 = Math.max(x1, px);
j = k;
}
if(j === 0) {
if(x0 <= x && x <= x1) {
return 0;
}
return 1;
}
lim = j+1;
}
var y0 = vs[(j+n-1)%n][1];
while(i+1<lim) {
p = vs[i+1];
if(p[1] !== y) {
break;
}
px = p[0];
x0 = Math.min(x0, px);
x1 = Math.max(x1, px);
i += 1;
}
if(x0 <= x && x <= x1) {
return 0;
}
var y1 = vs[(i+1)%n][1];
if(x < x0 && (y0 < y !== y1 < y)) {
inside ^= 1;
}
}
}
return 2 * inside - 1;
};
return {
/**
* @param object coordinate to check e.g. {latitude: 51.5023, longitude: 7.3815}
* @param array array with coords e.g. [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
* @return integer -1 if point is inside, 0 if point is on boundaries, 1 if point is outside
*/
isPointInsideRobust: function(latlng, coords) {
return robustPointInPolygon(coords, latlng);
},
isInside: function() {
return this.isPointInsideRobust.apply(this, arguments);
}
};
};
// Node module
if (typeof module !== 'undefined' &&
typeof module.exports !== 'undefined') {
module.exports = function(geolib) {
geolib.extend(addOn(geolib), true);
return geolib;
};
// AMD module
} else if (typeof define === "function" && define.amd) {
define(["geolib"], function (geolib) {
geolib.extend(addOn(geolib), true);
return geolib;
});
// we're in a browser
} else {
geolib.extend(addOn(geolib), true);
}
}(this, this.geolib));

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

1069
app/bower_components/geolib/geolib.js vendored Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,25 +0,0 @@
Packaging [Geolib](http://github.com/manuelbieh/Geolib) for [Meteor.js](http://meteor.com).
# Meteor
If you're new to Meteor, here's what the excitement is all about -
[watch the first two minutes](https://www.youtube.com/watch?v=fsi0aJ9yr2o); you'll be hooked by 1:28.
That screencast is from 2012. In the meantime, Meteor has become a mature JavaScript-everywhere web
development framework. Read more at [Why Meteor](http://www.meteorpedia.com/read/Why_Meteor).
# Issues
If you encounter an issue while using this package, please CC @dandv when you file it in this repo.
# DONE
* Simple test. Should be enough.
# TODO
* Add other tests; however, that is overkill, and the responsibiity of Moment, not of the Meteor integration.

View file

@ -1,3 +0,0 @@
// Geolib makes `geolib` global on the window (or global) object, while Meteor expects a file-scoped global variable
geolib = this.geolib;
delete this.geolib;

View file

@ -1,30 +0,0 @@
// package metadata file for Meteor.js
'use strict';
var packageName = 'outatime:geolib'; // https://atmospherejs.com/outatime/geolib
var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));
Package.describe({
name: packageName,
summary: 'Geolib - Library to perform geo specific tasks',
version: packageJson.version,
documentation: 'meteor/README.md',
git: 'https://github.com/manuelbieh/geolib.git'
});
Package.onUse(function (api) {
api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']);
api.export('geolib');
api.addFiles([
'dist/geolib.js',
'meteor/export.js'
]);
});
Package.onTest(function (api) {
api.use(packageName);
api.use('tinytest');
api.addFiles('meteor/test.js');
});

View file

@ -1,5 +0,0 @@
'use strict';
Tinytest.add('Geolib.is', function (test) {
test.equal(geolib.radius, 6378137, {message: 'simple geolib object'});
});

View file

@ -5,6 +5,9 @@
"name": "Manuel Bieh",
"url": "http://www.manuelbieh.com/"
},
"bin": {
"geolib": "./geolib.js"
},
"repository": {
"type": "git",
"url": "http://github.com/manuelbieh/geolib.git"
@ -19,34 +22,27 @@
"grunt-contrib-qunit": "~0.2.0",
"grunt-text-replace": "~0.3.6",
"grunt-contrib-jshint": "~0.6.2",
"phantomjs": ">=1.8.0",
"grunt-jslint": "~1.0.0",
"time-grunt": "~0.3.1",
"load-grunt-tasks": "~0.4.0"
"phantomjs": "~1.8.0",
"grunt-jslint": "~1.0.0"
},
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
"type": "LGPL",
"url": "http://www.gnu.org/licenses/lgpl-3.0.txt"
}
],
"files": [
"dist/geolib.js",
"dist/geolib.elevation.js"
"geolib.js"
],
"description": "Library to perform geo specific tasks",
"keywords": [
"geolocation",
"geo",
"distance",
"geojson",
"geospatial",
"lbs",
"location"
"distance"
],
"scripts": {
"test": "grunt travis --verbose"
},
"version": "2.0.22",
"main": "dist/geolib.js"
"version": "1.3.5",
"main": "./geolib"
}

View file

@ -1,190 +1,135 @@
/*! geolib.elevation $version$ by Manuel Bieh
*
* Elevation Addon for Geolib.js
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
* @version $version$
* @license MIT
*/
;(function(global, geolib, undefined) {
var elevation = {
/*global google:true geolib:true require:true module:true elevationResult:true */
/**
* @param Array Collection of coords [{latitude: 51.510, longitude: 7.1321}, {latitude: 49.1238, longitude: "8° 30' W"}, ...]
* @return Array [{lat:#lat, lng:#lng, elev:#elev},....]}
*/
getElevation: function() {
if (typeof global.navigator !== 'undefined') {
this.getElevationClient.apply(this, arguments);
} else {
this.getElevationServer.apply(this, arguments);
}
},
/* Optional elevation addon requires Googlemaps API JS */
getElevationClient: function(coords, cb) {
if (!global.google) {
throw new Error("Google maps api not loaded");
}
if (coords.length === 0) {
return cb(null, null);
}
if (coords.length === 1) {
return cb(new Error("getElevation requires at least 2 points."));
}
var path = [];
for(var i = 0; i < coords.length; i++) {
path.push(new google.maps.LatLng(
this.latitude(coords[i]),
this.longitude(coords[i])
));
}
var positionalRequest = {
'path': path,
'samples': path.length
};
var elevationService = new google.maps.ElevationService();
var geolib = this;
elevationService.getElevationAlongPath(positionalRequest, function (results, status) {
geolib.elevationHandler(results, status, coords, cb);
});
},
getElevationServer: function(coords, cb) {
if (coords.length === 0) {
return cb(null, null);
}
if (coords.length === 1) {
return cb(new Error("getElevation requires at least 2 points."));
}
var gm = require('googlemaps');
var path = [];
for(var i = 0; i < coords.length; i++) {
path.push(
this.latitude(coords[i]) + ',' + this.longitude(coords[i])
);
}
var geolib = this;
gm.elevationFromPath(path.join('|'), path.length, function(err, results) {
geolib.elevationHandler(results.results, results.status, coords, cb);
});
},
elevationHandler: function(results, status, coords, cb) {
var latsLngsElevs = [];
if (status == "OK" ) {
for (var i = 0; i < results.length; i++) {
latsLngsElevs.push({
"lat": this.latitude(coords[i]),
"lng": this.longitude(coords[i]),
"elev":results[i].elevation
});
}
cb(null, latsLngsElevs);
} else {
cb(new Error("Could not get elevation using Google's API"), elevationResult.status);
}
},
/**
* @param Array [{lat:#lat, lng:#lng, elev:#elev},....]}
* @return Number % grade
*/
getGrade: function(coords) {
var rise = Math.abs(
this.elevation(coords[coords.length-1]) - this.elevation(coords[0])
);
var run = this.getPathLength(coords);
return Math.floor((rise/run)*100);
},
/**
* @param Array [{lat:#lat, lng:#lng, elev:#elev},....]}
* @return Object {gain:#gain, loss:#loss}
*/
getTotalElevationGainAndLoss: function(coords) {
var gain = 0;
var loss = 0;
for(var i = 0; i < coords.length - 1; i++) {
var deltaElev = this.elevation(coords[i]) - this.elevation(coords[i + 1]);
if (deltaElev > 0) {
loss += deltaElev;
} else {
gain += Math.abs(deltaElev);
}
}
return {
"gain": gain,
"loss": loss
};
/* Optional elevation addon requires Googlemaps API JS */
/*global google:true geolib:true require:true module:true elevationResult*/
/**
* @param Array Collection of coords [{latitude: 51.510, longitude: 7.1321}, {latitude: 49.1238, longitude: "8° 30' W"}, ...]
*
* @return Array [{lat:#lat, lng:#lng, elev:#elev},....]}
*/
geolib.getElevation = function() {
if (typeof window.navigator !== 'undefined') {
geolib.getElevationClient.apply(this, arguments);
} else {
geolib.getElevationServer.apply(this, arguments);
}
};
geolib.getElevationClient = function(coords, cb) {
if (!window.google) {
throw new Error("Google maps api not loaded");
}
if (coords.length === 0) {
return cb(null, null);
}
if (coords.length === 1) {
return cb(new Error("getElevation requires at least 2 points."));
}
var path = [];
var keys = geolib.getKeys(coords[0]);
var latitude = keys.latitude;
var longitude = keys.longitude;
for(var i = 0; i < coords.length; i++) {
path.push(new google.maps.LatLng(
geolib.useDecimal(coords[i][latitude]),
geolib.useDecimal(coords[i][longitude])
));
}
var positionalRequest = {
'path': path,
'samples': path.length
};
var elevationService = new google.maps.ElevationService();
elevationService.getElevationAlongPath(positionalRequest,function (results, status) {
geolib.elevationHandler(results, status, coords, keys, cb);
});
};
// Node module
if (typeof module !== 'undefined' &&
typeof module.exports !== 'undefined') {
geolib.getElevationServer = function(coords, cb) {
geolib = require('geolib');
geolib.extend(elevation);
if (coords.length === 0) {
return cb(null, null);
}
// AMD module
} else if (typeof define === "function" && define.amd) {
if (coords.length === 1) {
return cb(new Error("getElevation requires at least 2 points."));
}
define(["geolib"], function (geolib) {
geolib.extend(elevation);
return geolib;
var gm = require('googlemaps');
var path = [];
var keys = geolib.getKeys(coords[0]);
//coords[0]
var latitude = keys.latitude;
var longitude = keys.longitude;
for(var i = 0; i < coords.length; i++) {
path.push(geolib.useDecimal(coords[i][latitude]) + ',' +
geolib.useDecimal(coords[i][longitude]));
}
gm.elevationFromPath(path.join('|'), path.length, function(err, results) {
geolib.elevationHandler(results.results, results.status, coords, keys, cb);
});
// we're in a browser
} else {
},
geolib.extend(elevation);
geolib.elevationHandler = function(results, status, coords, keys, cb){
var latsLngsElevs = [];
var latitude = keys.latitude;
var longitude = keys.longitude;
if (status == "OK" ) {
for (var i = 0; i < results.length; i++) {
latsLngsElevs.push({
"lat":coords[i][latitude],
"lng":coords[i][longitude],
"elev":results[i].elevation
});
}
cb(null, latsLngsElevs);
} else {
cb(new Error("Could not get elevation using Google's API"), elevationResult.status);
}
};
}
/**
* @param Array [{lat:#lat, lng:#lng, elev:#elev},....]}
*
* @return Number % grade
*/
geolib.getGrade = function(coords){
var keys = geolib.getKeys(coords[0]);
var elevation = keys.elevation;
var rise = Math.abs(coords[coords.length-1][elevation] - coords[0][elevation]);
var run = geolib.getPathLength(coords);
return Math.floor((rise/run)*100);
};
}(this, this.geolib));
/**
* @param Array [{lat:#lat, lng:#lng, elev:#elev},....]}
*
* @return Object {gain:#gain, loss:#loss}
*/
geolib.getTotalElevationGainAndLoss = function(coords){
var keys = geolib.getKeys(coords[0]);
var elevation = keys.elevation;
var gain = 0;
var loss = 0;
for(var i = 0; i < coords.length - 1; i++){
var deltaElev = coords[i][elevation] - coords[i + 1][elevation];
if (deltaElev > 0) {
loss += deltaElev;
} else {
gain += Math.abs(deltaElev);
}
}
return {
"gain": gain,
"loss": loss
};
};

View file

@ -1,744 +0,0 @@
/*! geolib.isPointInsideRobust $version$
* !!EXPERIMENTAL!!
*
* Robust version of isPointInside for Geolib.js
*
* Based on https://github.com/mikolalysenko/robust-point-in-polygon
* by Mikola Lysenko, licensed under MIT
*
* @author Manuel Bieh
* @url http://www.manuelbieh.com/
* @version $version$
* @license MIT
*
*/
;(function(global, geolib, undefined) {
var addOn = function(geolib) {
var SPLITTER = +(Math.pow(2, 27) + 1.0);
var NUM_EXPAND = 5;
var EPSILON = 1.1102230246251565e-16;
var ERRBOUND3 = (3.0 + 16.0 * EPSILON) * EPSILON;
var ERRBOUND4 = (7.0 + 56.0 * EPSILON) * EPSILON;
var twoProduct = function(a, b, result) {
var x = a * b;
var c = SPLITTER * a;
var abig = c - a;
var ahi = c - abig;
var alo = a - ahi;
var d = SPLITTER * b;
var bbig = d - b;
var bhi = d - bbig;
var blo = b - bhi;
var err1 = x - (ahi * bhi);
var err2 = err1 - (alo * bhi);
var err3 = err2 - (ahi * blo);
var y = alo * blo - err3;
if(result) {
result[0] = y;
result[1] = x;
return result;
}
return [ y, x ];
};
var fastTwoSum = function(a, b, result) {
var x = a + b;
var bv = x - a;
var av = x - bv;
var br = b - bv;
var ar = a - av;
if(result) {
result[0] = ar + br;
result[1] = x;
return result;
}
return [ar+br, x];
};
var twoSum = fastTwoSum;
var linearExpansionSum = function(e, f) {
var ne = e.length|0;
var nf = f.length|0;
if(ne === 1 && nf === 1) {
return scalarScalar(e[0], f[0]);
}
var n = ne + nf;
var g = new Array(n);
var count = 0;
var eptr = 0;
var fptr = 0;
var abs = Math.abs;
var ei = e[eptr];
var ea = abs(ei);
var fi = f[fptr];
var fa = abs(fi);
var a, b;
if(ea < fa) {
b = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
b = fi;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
fa = abs(fi);
}
}
if((eptr < ne && ea < fa) || (fptr >= nf)) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
fa = abs(fi);
}
}
var x = a + b;
var bv = x - a;
var y = b - bv;
var q0 = y;
var q1 = x;
var _x, _bv, _av, _br, _ar;
while(eptr < ne && fptr < nf) {
if(ea < fa) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
fa = abs(fi);
}
}
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
}
while(eptr < ne) {
a = ei;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
}
}
while(fptr < nf) {
a = fi;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
fptr += 1;
if(fptr < nf) {
fi = f[fptr];
}
}
if(q0) {
g[count++] = q0;
}
if(q1) {
g[count++] = q1;
}
if(!count) {
g[count++] = 0.0;
}
g.length = count;
return g;
};
var robustSum = linearExpansionSum;
var scaleLinearExpansion = function(e, scale) {
var n = e.length;
if(n === 1) {
var ts = twoProduct(e[0], scale);
if(ts[0]) {
return ts;
}
return [ ts[1] ];
}
var g = new Array(2 * n);
var q = [0.1, 0.1];
var t = [0.1, 0.1];
var count = 0;
twoProduct(e[0], scale, q);
if(q[0]) {
g[count++] = q[0];
}
for(var i=1; i<n; ++i) {
twoProduct(e[i], scale, t);
var pq = q[1];
twoSum(pq, t[0], q);
if(q[0]) {
g[count++] = q[0];
}
var a = t[1];
var b = q[1];
var x = a + b;
var bv = x - a;
var y = b - bv;
q[1] = x;
if(y) {
g[count++] = y;
}
}
if(q[1]) {
g[count++] = q[1];
}
if(count === 0) {
g[count++] = 0.0;
}
g.length = count;
return g;
};
var robustScale = scaleLinearExpansion;
var scalarScalar = function(a, b) {
var x = a + b;
var bv = x - a;
var av = x - bv;
var br = b - bv;
var ar = a - av;
var y = ar + br;
if(y) {
return [y, x];
}
return [x];
};
var robustSubtract = function(e, f) {
var ne = e.length|0;
var nf = f.length|0;
if(ne === 1 && nf === 1) {
return scalarScalar(e[0], -f[0]);
}
var n = ne + nf;
var g = new Array(n);
var count = 0;
var eptr = 0;
var fptr = 0;
var abs = Math.abs;
var ei = e[eptr];
var ea = abs(ei);
var fi = -f[fptr];
var fa = abs(fi);
var a, b;
if(ea < fa) {
b = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
b = fi;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
fa = abs(fi);
}
}
if((eptr < ne && ea < fa) || (fptr >= nf)) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
fa = abs(fi);
}
}
var x = a + b;
var bv = x - a;
var y = b - bv;
var q0 = y;
var q1 = x;
var _x, _bv, _av, _br, _ar;
while(eptr < ne && fptr < nf) {
if(ea < fa) {
a = ei;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
ea = abs(ei);
}
} else {
a = fi;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
fa = abs(fi);
}
}
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
}
while(eptr < ne) {
a = ei;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
eptr += 1;
if(eptr < ne) {
ei = e[eptr];
}
}
while(fptr < nf) {
a = fi;
b = q0;
x = a + b;
bv = x - a;
y = b - bv;
if(y) {
g[count++] = y;
}
_x = q1 + x;
_bv = _x - q1;
_av = _x - _bv;
_br = x - _bv;
_ar = q1 - _av;
q0 = _ar + _br;
q1 = _x;
fptr += 1;
if(fptr < nf) {
fi = -f[fptr];
}
}
if(q0) {
g[count++] = q0;
}
if(q1) {
g[count++] = q1;
}
if(!count) {
g[count++] = 0.0;
}
g.length = count;
return g;
};
var cofactor = function(m, c) {
var result = new Array(m.length-1);
for(var i=1; i<m.length; ++i) {
var r = result[i-1] = new Array(m.length-1);
for(var j=0,k=0; j<m.length; ++j) {
if(j === c) {
continue;
}
r[k++] = m[i][j];
}
}
return result;
};
var matrix = function(n) {
var result = new Array(n);
for(var i=0; i<n; ++i) {
result[i] = new Array(n);
for(var j=0; j<n; ++j) {
result[i][j] = ["m", j, "[", (n-i-1), "]"].join("");
}
}
return result;
};
var sign = function(n) {
if(n & 1) {
return "-";
}
return "";
};
var generateSum = function(expr) {
if(expr.length === 1) {
return expr[0];
} else if(expr.length === 2) {
return ["sum(", expr[0], ",", expr[1], ")"].join("");
} else {
var m = expr.length>>1;
return ["sum(", generateSum(expr.slice(0, m)), ",", generateSum(expr.slice(m)), ")"].join("");
}
};
var determinant = function(m) {
if(m.length === 2) {
return [["sum(prod(", m[0][0], ",", m[1][1], "),prod(-", m[0][1], ",", m[1][0], "))"].join("")];
} else {
var expr = [];
for(var i=0; i<m.length; ++i) {
expr.push(["scale(", generateSum(determinant(cofactor(m, i))), ",", sign(i), m[0][i], ")"].join(""));
}
return expr;
}
};
var orientation = function(n) {
var pos = [];
var neg = [];
var m = matrix(n);
var args = [];
for(var i=0; i<n; ++i) {
if((i&1)===0) {
pos.push.apply(pos, determinant(cofactor(m, i)));
} else {
neg.push.apply(neg, determinant(cofactor(m, i)));
}
args.push("m" + i);
}
var posExpr = generateSum(pos);
var negExpr = generateSum(neg);
var funcName = "orientation" + n + "Exact";
var code = [
"function ",
funcName,
"(", args.join(), "){var p=",
posExpr,
",n=",
negExpr,
",d=sub(p,n);return d[d.length-1];};return ",
funcName
].join("");
var proc = new Function("sum", "prod", "scale", "sub", code);
return proc(robustSum, twoProduct, robustScale, robustSubtract);
};
var orient;
var orientation3Exact = orientation(3);
var orientation4Exact = orientation(4);
var CACHED = [
function orientation0() { return 0; },
function orientation1() { return 0; },
function orientation2(a, b) {
return b[0] - a[0];
},
function orientation3(a, b, c) {
var l = (a[1] - c[1]) * (b[0] - c[0]);
var r = (a[0] - c[0]) * (b[1] - c[1]);
var det = l - r;
var s;
if(l > 0) {
if(r <= 0) {
return det;
} else {
s = l + r;
}
} else if(l < 0) {
if(r >= 0) {
return det;
} else {
s = -(l + r);
}
} else {
return det;
}
var tol = ERRBOUND3 * s;
if(det >= tol || det <= -tol) {
return det;
}
return orientation3Exact(a, b, c);
},
function orientation4(a,b,c,d) {
var adx = a[0] - d[0];
var bdx = b[0] - d[0];
var cdx = c[0] - d[0];
var ady = a[1] - d[1];
var bdy = b[1] - d[1];
var cdy = c[1] - d[1];
var adz = a[2] - d[2];
var bdz = b[2] - d[2];
var cdz = c[2] - d[2];
var bdxcdy = bdx * cdy;
var cdxbdy = cdx * bdy;
var cdxady = cdx * ady;
var adxcdy = adx * cdy;
var adxbdy = adx * bdy;
var bdxady = bdx * ady;
var det = adz * (bdxcdy - cdxbdy) +
bdz * (cdxady - adxcdy) +
cdz * (adxbdy - bdxady);
var permanent = (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
(Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
(Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
var tol = ERRBOUND4 * permanent;
if ((det > tol) || (-det > tol)) {
return det;
}
return orientation4Exact(a,b,c,d);
}
];
var slowOrient = function(args) {
var proc = CACHED[args.length];
if(!proc) {
proc = CACHED[args.length] = orientation(args.length);
}
return proc.apply(undefined, args);
};
var generateOrientationProc = function() {
while(CACHED.length <= NUM_EXPAND) {
CACHED.push(orientation(CACHED.length));
}
var args = [];
var procArgs = ["slow"];
for(var i=0; i<=NUM_EXPAND; ++i) {
args.push("a" + i);
procArgs.push("o" + i);
}
var code = [
"function getOrientation(",
args.join(),
"){switch(arguments.length){case 0:case 1:return 0;"
];
for(i=2; i<=NUM_EXPAND; ++i) {
code.push("case ", i, ":return o", i, "(", args.slice(0, i).join(), ");");
}
code.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation");
procArgs.push(code.join(""));
var proc = Function.apply(undefined, procArgs);
orient = proc.apply(undefined, [slowOrient].concat(CACHED));
for(i=0; i<=NUM_EXPAND; ++i) {
orient[i] = CACHED[i];
}
};
generateOrientationProc();
var robustPointInPolygon = function(vs, point) {
// transform from geolib format to array syntax
var x = geolib.longitude(point);
var y = geolib.latitude(point);
var coords = vs.map(function(coords) {
return [geolib.longitude(coords), geolib.latitude(coords)];
});
vs = coords;
point = [x,y];
var n = vs.length;
var inside = 1;
var lim = n;
var s, c, yk, px, p;
for(var i = 0, j = n-1; i<lim; j=i++) {
var a = vs[i];
var b = vs[j];
var yi = a[1];
var yj = b[1];
if(yj < yi) {
if(yj < y && y < yi) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (0 < s)|0;
}
} else if(y === yi) {
c = vs[(i+1)%n];
yk = c[1];
if(yi < yk) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (0 < s)|0;
}
}
}
} else if(yi < yj) {
if(yi < y && y < yj) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (s < 0)|0;
}
} else if(y === yi) {
c = vs[(i+1)%n];
yk = c[1];
if(yk < yi) {
s = orient(a, b, point);
if(s === 0) {
return 0;
} else {
inside ^= (s < 0)|0;
}
}
}
} else if(y === yi) {
var x0 = Math.min(a[0], b[0]);
var x1 = Math.max(a[0], b[0]);
if(i === 0) {
while(j>0) {
var k = (j+n-1)%n;
p = vs[k];
if(p[1] !== y) {
break;
}
px = p[0];
x0 = Math.min(x0, px);
x1 = Math.max(x1, px);
j = k;
}
if(j === 0) {
if(x0 <= x && x <= x1) {
return 0;
}
return 1;
}
lim = j+1;
}
var y0 = vs[(j+n-1)%n][1];
while(i+1<lim) {
p = vs[i+1];
if(p[1] !== y) {
break;
}
px = p[0];
x0 = Math.min(x0, px);
x1 = Math.max(x1, px);
i += 1;
}
if(x0 <= x && x <= x1) {
return 0;
}
var y1 = vs[(i+1)%n][1];
if(x < x0 && (y0 < y !== y1 < y)) {
inside ^= 1;
}
}
}
return 2 * inside - 1;
};
return {
/**
* @param object coordinate to check e.g. {latitude: 51.5023, longitude: 7.3815}
* @param array array with coords e.g. [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
* @return integer -1 if point is inside, 0 if point is on boundaries, 1 if point is outside
*/
isPointInsideRobust: function(latlng, coords) {
return robustPointInPolygon(coords, latlng);
},
isInside: function() {
return this.isPointInsideRobust.apply(this, arguments);
}
};
};
// Node module
if (typeof module !== 'undefined' &&
typeof module.exports !== 'undefined') {
module.exports = function(geolib) {
geolib.extend(addOn(geolib), true);
return geolib;
};
// AMD module
} else if (typeof define === "function" && define.amd) {
define(["geolib"], function (geolib) {
geolib.extend(addOn(geolib), true);
return geolib;
});
// we're in a browser
} else {
geolib.extend(addOn(geolib), true);
}
}(this, this.geolib));

File diff suppressed because it is too large Load diff