boundingbox
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,6 +0,16 @@ | ||
function BoundingBox(bounds) { | ||
if(bounds instanceof BoundingBox) { | ||
'use strict' | ||
// define L, if Leaflet is not available (not not confuse Linter) | ||
if (typeof L === 'undefined') { | ||
var L | ||
} | ||
function BoundingBox (bounds) { | ||
var k | ||
if (bounds instanceof BoundingBox) { | ||
this.bounds = {} | ||
for(var k in bounds.bounds) | ||
for (k in bounds.bounds) { | ||
this.bounds[k] = bounds.bounds[k] | ||
} | ||
@@ -11,3 +21,3 @@ return | ||
// Leaflet.latLngBounds detected! | ||
if(typeof bounds.getSouthWest == 'function') { | ||
if (typeof bounds.getSouthWest === 'function') { | ||
var sw = bounds.getSouthWest() | ||
@@ -24,52 +34,60 @@ var ne = bounds.getNorthEast() | ||
if('bounds' in bounds) | ||
if ('bounds' in bounds) { | ||
bounds = bounds.bounds | ||
} | ||
this.bounds = {} | ||
for(var k in bounds) | ||
for (k in bounds) { | ||
this.bounds[k] = bounds[k] | ||
} | ||
if(this.bounds.lat) { | ||
if (this.bounds.lat) { | ||
this.bounds.minlat = this.bounds.lat | ||
this.bounds.maxlat = this.bounds.lat | ||
delete(this.bounds.lat) | ||
delete this.bounds.lat | ||
} | ||
if(this.bounds.lon) { | ||
if (this.bounds.lon) { | ||
this.bounds.minlon = this.bounds.lon | ||
this.bounds.maxlon = this.bounds.lon | ||
delete(this.bounds.lon) | ||
delete this.bounds.lon | ||
} | ||
// e.g. L.latLng object | ||
if(this.bounds.lng) { | ||
if (this.bounds.lng) { | ||
this.bounds.minlon = this.bounds.lng | ||
this.bounds.maxlon = this.bounds.lng | ||
delete(this.bounds.lng) | ||
delete this.bounds.lng | ||
} | ||
for(var k in this.bounds) | ||
if(['minlon', 'minlat', 'maxlon', 'maxlat'].indexOf(k) == -1) | ||
delete(this.bounds[k]) | ||
for (k in this.bounds) { | ||
if (['minlon', 'minlat', 'maxlon', 'maxlat'].indexOf(k) === -1) { | ||
delete this.bounds[k] | ||
} | ||
} | ||
} | ||
BoundingBox.prototype.intersects = function(other) { | ||
other = new BoundingBox(other); | ||
BoundingBox.prototype.intersects = function (other) { | ||
other = new BoundingBox(other) | ||
if(other.bounds.maxlat < this.bounds.minlat) | ||
return false; | ||
if (other.bounds.maxlat < this.bounds.minlat) { | ||
return false | ||
} | ||
if(other.bounds.minlat > this.bounds.maxlat) | ||
return false; | ||
if (other.bounds.minlat > this.bounds.maxlat) { | ||
return false | ||
} | ||
if(other.bounds.maxlon < this.bounds.minlon) | ||
return false; | ||
if (other.bounds.maxlon < this.bounds.minlon) { | ||
return false | ||
} | ||
if(other.bounds.minlon > this.bounds.maxlon) | ||
return false; | ||
if (other.bounds.minlon > this.bounds.maxlon) { | ||
return false | ||
} | ||
return true; | ||
return true | ||
} | ||
BoundingBox.prototype.toTile = function() { | ||
BoundingBox.prototype.toTile = function () { | ||
return new BoundingBox({ | ||
@@ -83,3 +101,3 @@ minlat: Math.floor(this.bounds.minlat * 10) / 10, | ||
BoundingBox.prototype.toBBoxString = function() { | ||
BoundingBox.prototype.toBBoxString = function () { | ||
return this.bounds.minlon + ',' + | ||
@@ -91,10 +109,10 @@ this.bounds.minlat + ',' + | ||
BoundingBox.prototype.diagonalLength = function() { | ||
BoundingBox.prototype.diagonalLength = function () { | ||
var dlat = this.bounds.maxlat - this.bounds.minlat | ||
var dlon = this.bounds.maxlon - this.bounds.minlon | ||
return d = Math.sqrt(dlat * dlat + dlon * dlon) | ||
return Math.sqrt(dlat * dlat + dlon * dlon) | ||
} | ||
BoundingBox.prototype.getCenter = function() { | ||
BoundingBox.prototype.getCenter = function () { | ||
var dlat = this.bounds.maxlat - this.bounds.minlat | ||
@@ -109,3 +127,3 @@ var dlon = this.bounds.maxlon - this.bounds.minlon | ||
BoundingBox.prototype.toLeaflet = function() { | ||
BoundingBox.prototype.toLeaflet = function () { | ||
return L.latLngBounds( | ||
@@ -117,5 +135,7 @@ L.latLng(this.bounds.minlat, this.bounds.minlon), | ||
if(typeof module != 'undefined' && module.exports) | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = BoundingBox | ||
if(typeof window != 'undefined') | ||
} | ||
if (typeof window !== 'undefined') { | ||
window.BoundingBox = BoundingBox | ||
} |
{ | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"name": "boundingbox", | ||
"description": "Implements bounding boxes with usual functions like intersects. Can convert from/to Leaflet bounds and GeoJSON.", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "BoundingBox.js", | ||
@@ -12,10 +11,15 @@ "directories": { | ||
"devDependencies": { | ||
"mocha": "*", | ||
"browserify": "*", | ||
"leaflet": "*" | ||
"eslint": "*", | ||
"eslint-config-standard": "^6.1.0", | ||
"eslint-plugin-promise": "^2.0.1", | ||
"eslint-plugin-standard": "^2.0.1", | ||
"leaflet": "*", | ||
"mocha": "*" | ||
}, | ||
"scripts": { | ||
"test": "./run_tests", | ||
"build": "browserify BoundingBox.js -o dist/boundingbox.js", | ||
"prepublish": "npm run build" | ||
"build": "mkdir -p dist; browserify BoundingBox.js -o dist/boundingbox.js", | ||
"prepublish": "npm run build; npm run lint", | ||
"lint": "eslint BoundingBox.js" | ||
}, | ||
@@ -22,0 +26,0 @@ "repository": { |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
87124
11
1498
7
4