bbox-dateline
Advanced tools
Comparing version 1.0.3 to 1.1.0
# Changelog | ||
## 0.1.0 - 2017-03-17 | ||
## 1.1.0 - 2017-03-20 | ||
- Support bbox that overlaps the entire world | ||
## 1.0.0 - 2017-03-17 | ||
- Initialize `bbox-dateline` library | ||
- Add methods `bbox()`, `center()`, `latitude()` & `longitude()` |
@@ -1180,7 +1180,22 @@ (function (global, factory) { | ||
var west = longitude(bbox[0]); | ||
var south = latitude(bbox[1]); | ||
var east = longitude(bbox[2]); | ||
var north = latitude(bbox[3]); | ||
var west = bbox[0]; | ||
var south = bbox[1]; | ||
var east = bbox[2]; | ||
var north = bbox[3]; | ||
// Support bbox that overlaps the entire world | ||
if (west < -180 && east > 180) { | ||
west = -180; | ||
east = 180; | ||
} | ||
if (south < -90 && north > 90) { | ||
south = -90; | ||
north = 90; | ||
} | ||
// Convert Lat & Lng within dateline | ||
west = longitude(bbox[0]); | ||
south = latitude(bbox[1]); | ||
east = longitude(bbox[2]); | ||
north = latitude(bbox[3]); | ||
return [west, south, east, north] | ||
@@ -1187,0 +1202,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.dateline=r()}(this,function(){function e(r,t,o){var n,i,u,a,s,f,l,c,y,d,g=0,p=0,h="FeatureCollection"===r.type,m="Feature"===r.type,w=h?r.features.length:1;for(n=0;w>n;n++)for(y=h?r.features[n].geometry:m?r.geometry:r,d="GeometryCollection"===y.type,l=d?y.geometries.length:1,a=0;l>a;a++)if(f=d?y.geometries[a]:y,c=f.coordinates,g=!o||"Polygon"!==f.type&&"MultiPolygon"!==f.type?0:1,"Point"===f.type)t(c,p),p++;else if("LineString"===f.type||"MultiPoint"===f.type)for(i=0;i<c.length;i++)t(c[i],p),p++;else if("Polygon"===f.type||"MultiLineString"===f.type)for(i=0;i<c.length;i++)for(u=0;u<c[i].length-g;u++)t(c[i][u],p),p++;else if("MultiPolygon"===f.type)for(i=0;i<c.length;i++)for(u=0;u<c[i].length;u++)for(s=0;s<c[i][u].length-g;s++)t(c[i][u][s],p),p++;else{if("GeometryCollection"!==f.type)throw new Error("Unknown Geometry Type");for(i=0;i<f.geometries.length;i++)e(f.geometries[i],t,o)}}function r(r,t,o,n){var i=o;return e(r,function(e,r){i=0===r&&void 0===o?e:t(i,e,r)},n),i}function t(e,r){var t;switch(e.type){case"FeatureCollection":for(t=0;t<e.features.length;t++)r(e.features[t].properties,t);break;case"Feature":r(e.properties,0)}}function o(e,r,o){var n=o;return t(e,function(e,t){n=0===t&&void 0===o?e:r(n,e,t)}),n}function n(e,r){if("Feature"===e.type)r(e,0);else if("FeatureCollection"===e.type)for(var t=0;t<e.features.length;t++)r(e.features[t],t)}function i(e,r,t){var o=t;return n(e,function(e,n){o=0===n&&void 0===t?e:r(o,e,n)}),o}function u(r){var t=[];return e(r,function(e){t.push(e)}),t}function a(e,r){var t,o,n,i,u,a,s,f=0,l="FeatureCollection"===e.type,c="Feature"===e.type,y=l?e.features.length:1;for(t=0;y>t;t++)for(a=l?e.features[t].geometry:c?e.geometry:e,s="GeometryCollection"===a.type,u=s?a.geometries.length:1,n=0;u>n;n++)if(i=s?a.geometries[n]:a,"Point"===i.type||"LineString"===i.type||"MultiPoint"===i.type||"Polygon"===i.type||"MultiLineString"===i.type||"MultiPolygon"===i.type)r(i,f),f++;else{if("GeometryCollection"!==i.type)throw new Error("Unknown Geometry Type");for(o=0;o<i.geometries.length;o++)r(i.geometries[o],f),f++}}function s(e,r,t){var o=t;return a(e,function(e,n){o=0===n&&void 0===t?e:r(o,e,n)}),o}function f(e,r){if(!e)throw new Error("No geometry passed");return{type:"Feature",properties:r||{},geometry:e}}function l(e){if(!e)throw new Error("bbox is required");if(Array.isArray(e)||(e=M(e)),4!==e.length)throw new Error("bbox must have 4 numbers");var r=d(e[0]),t=y(e[1]),o=d(e[2]),n=y(e[3]);return[r,t,o,n]}function c(e){var r;if(!e)throw new Error("center is required");if(Array.isArray(e))if(4===e.length){var t=e,o=t[0],n=t[1],i=t[2],u=t[3];r=[(o+i)/2,(n+u)/2]}else r=[e[0],e[1]];else r=B(e).geometry.coordinates;if(2!==r.length)throw new Error("center must have 2 numbers");var a=d(r[0]),s=y(r[1]);return[a,s]}function y(e){if(void 0===e||null===e)throw new Error("lat is required");return(e>90||-90>e)&&(e%=180,e>90&&(e=-180+e),-90>e&&(e=180+e),e===-0&&(e=0)),e}function d(e){if(void 0===e||void 0===e)throw new Error("lng is required");return(e>180||-180>e)&&(e%=360,e>180&&(e=-360+e),-180>e&&(e=360+e),e===-0&&(e=0)),e}var g=e,p=r,h=t,m=o,w=n,v=i,E=u,P=a,b=s,C={coordEach:g,coordReduce:p,propEach:h,propReduce:m,featureEach:w,featureReduce:v,coordAll:E,geomEach:P,geomReduce:b},F=C.coordEach,M=function(e){var r=[1/0,1/0,-(1/0),-(1/0)];return F(e,function(e){r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r},N=f,k=function(e,r){if(!e)throw new Error("No coordinates passed");if(void 0===e.length)throw new Error("Coordinates must be an array");if(e.length<2)throw new Error("Coordinates must be at least 2 numbers long");if("number"!=typeof e[0]||"number"!=typeof e[1])throw new Error("Coordinates must numbers");return f({type:"Point",coordinates:e},r)},L=function(e,r){if(!e)throw new Error("No coordinates passed");for(var t=0;t<e.length;t++){var o=e[t];if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var n=0;n<o[o.length-1].length;n++)if(o[o.length-1][n]!==o[0][n])throw new Error("First and last Position are not equivalent.")}return f({type:"Polygon",coordinates:e},r)},S=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"LineString",coordinates:e},r)},G=function(e){if(!e)throw new Error("No features passed");return{type:"FeatureCollection",features:e}},R=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"MultiLineString",coordinates:e},r)},q=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"MultiPoint",coordinates:e},r)},x=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"MultiPolygon",coordinates:e},r)},A=function(e,r){if(!e)throw new Error("No geometries passed");return f({type:"GeometryCollection",geometries:e},r)},T={miles:3960,nauticalmiles:3441.145,degrees:57.2957795,radians:1,inches:250905600,yards:6969600,meters:6373e3,metres:6373e3,kilometers:6373,kilometres:6373,feet:20908792.65},I=function(e,r){var t=T[r||"kilometers"];if(void 0===t)throw new Error("Invalid unit");return e*t},D=function(e,r){var t=T[r||"kilometers"];if(void 0===t)throw new Error("Invalid unit");return e/t},U=function(e,r){var t=T[r||"kilometers"];if(void 0===t)throw new Error("Invalid unit");return e/t*57.2958},j={feature:N,point:k,polygon:L,lineString:S,featureCollection:G,multiLineString:R,multiPoint:q,multiPolygon:x,geometryCollection:A,radiansToDistance:I,distanceToRadians:D,distanceToDegrees:U},z=j.point,B=function(e){var r=M(e),t=(r[0]+r[2])/2,o=(r[1]+r[3])/2;return z([t,o])},H={bbox:l,longitude:d,latitude:y,center:c};return H}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.dateline=r()}(this,function(){function e(r,t,o){var n,i,u,a,s,f,l,c,y,d,g=0,p=0,h="FeatureCollection"===r.type,m="Feature"===r.type,w=h?r.features.length:1;for(n=0;w>n;n++)for(y=h?r.features[n].geometry:m?r.geometry:r,d="GeometryCollection"===y.type,l=d?y.geometries.length:1,a=0;l>a;a++)if(f=d?y.geometries[a]:y,c=f.coordinates,g=!o||"Polygon"!==f.type&&"MultiPolygon"!==f.type?0:1,"Point"===f.type)t(c,p),p++;else if("LineString"===f.type||"MultiPoint"===f.type)for(i=0;i<c.length;i++)t(c[i],p),p++;else if("Polygon"===f.type||"MultiLineString"===f.type)for(i=0;i<c.length;i++)for(u=0;u<c[i].length-g;u++)t(c[i][u],p),p++;else if("MultiPolygon"===f.type)for(i=0;i<c.length;i++)for(u=0;u<c[i].length;u++)for(s=0;s<c[i][u].length-g;s++)t(c[i][u][s],p),p++;else{if("GeometryCollection"!==f.type)throw new Error("Unknown Geometry Type");for(i=0;i<f.geometries.length;i++)e(f.geometries[i],t,o)}}function r(r,t,o,n){var i=o;return e(r,function(e,r){i=0===r&&void 0===o?e:t(i,e,r)},n),i}function t(e,r){var t;switch(e.type){case"FeatureCollection":for(t=0;t<e.features.length;t++)r(e.features[t].properties,t);break;case"Feature":r(e.properties,0)}}function o(e,r,o){var n=o;return t(e,function(e,t){n=0===t&&void 0===o?e:r(n,e,t)}),n}function n(e,r){if("Feature"===e.type)r(e,0);else if("FeatureCollection"===e.type)for(var t=0;t<e.features.length;t++)r(e.features[t],t)}function i(e,r,t){var o=t;return n(e,function(e,n){o=0===n&&void 0===t?e:r(o,e,n)}),o}function u(r){var t=[];return e(r,function(e){t.push(e)}),t}function a(e,r){var t,o,n,i,u,a,s,f=0,l="FeatureCollection"===e.type,c="Feature"===e.type,y=l?e.features.length:1;for(t=0;y>t;t++)for(a=l?e.features[t].geometry:c?e.geometry:e,s="GeometryCollection"===a.type,u=s?a.geometries.length:1,n=0;u>n;n++)if(i=s?a.geometries[n]:a,"Point"===i.type||"LineString"===i.type||"MultiPoint"===i.type||"Polygon"===i.type||"MultiLineString"===i.type||"MultiPolygon"===i.type)r(i,f),f++;else{if("GeometryCollection"!==i.type)throw new Error("Unknown Geometry Type");for(o=0;o<i.geometries.length;o++)r(i.geometries[o],f),f++}}function s(e,r,t){var o=t;return a(e,function(e,n){o=0===n&&void 0===t?e:r(o,e,n)}),o}function f(e,r){if(!e)throw new Error("No geometry passed");return{type:"Feature",properties:r||{},geometry:e}}function l(e){if(!e)throw new Error("bbox is required");if(Array.isArray(e)||(e=M(e)),4!==e.length)throw new Error("bbox must have 4 numbers");var r=e[0],t=e[1],o=e[2],n=e[3];return-180>r&&o>180&&(r=-180,o=180),-90>t&&n>90&&(t=-90,n=90),r=d(e[0]),t=y(e[1]),o=d(e[2]),n=y(e[3]),[r,t,o,n]}function c(e){var r;if(!e)throw new Error("center is required");if(Array.isArray(e))if(4===e.length){var t=e,o=t[0],n=t[1],i=t[2],u=t[3];r=[(o+i)/2,(n+u)/2]}else r=[e[0],e[1]];else r=B(e).geometry.coordinates;if(2!==r.length)throw new Error("center must have 2 numbers");var a=d(r[0]),s=y(r[1]);return[a,s]}function y(e){if(void 0===e||null===e)throw new Error("lat is required");return(e>90||-90>e)&&(e%=180,e>90&&(e=-180+e),-90>e&&(e=180+e),e===-0&&(e=0)),e}function d(e){if(void 0===e||void 0===e)throw new Error("lng is required");return(e>180||-180>e)&&(e%=360,e>180&&(e=-360+e),-180>e&&(e=360+e),e===-0&&(e=0)),e}var g=e,p=r,h=t,m=o,w=n,v=i,E=u,P=a,b=s,C={coordEach:g,coordReduce:p,propEach:h,propReduce:m,featureEach:w,featureReduce:v,coordAll:E,geomEach:P,geomReduce:b},F=C.coordEach,M=function(e){var r=[1/0,1/0,-(1/0),-(1/0)];return F(e,function(e){r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r},N=f,k=function(e,r){if(!e)throw new Error("No coordinates passed");if(void 0===e.length)throw new Error("Coordinates must be an array");if(e.length<2)throw new Error("Coordinates must be at least 2 numbers long");if("number"!=typeof e[0]||"number"!=typeof e[1])throw new Error("Coordinates must numbers");return f({type:"Point",coordinates:e},r)},L=function(e,r){if(!e)throw new Error("No coordinates passed");for(var t=0;t<e.length;t++){var o=e[t];if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var n=0;n<o[o.length-1].length;n++)if(o[o.length-1][n]!==o[0][n])throw new Error("First and last Position are not equivalent.")}return f({type:"Polygon",coordinates:e},r)},S=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"LineString",coordinates:e},r)},G=function(e){if(!e)throw new Error("No features passed");return{type:"FeatureCollection",features:e}},R=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"MultiLineString",coordinates:e},r)},q=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"MultiPoint",coordinates:e},r)},x=function(e,r){if(!e)throw new Error("No coordinates passed");return f({type:"MultiPolygon",coordinates:e},r)},A=function(e,r){if(!e)throw new Error("No geometries passed");return f({type:"GeometryCollection",geometries:e},r)},T={miles:3960,nauticalmiles:3441.145,degrees:57.2957795,radians:1,inches:250905600,yards:6969600,meters:6373e3,metres:6373e3,kilometers:6373,kilometres:6373,feet:20908792.65},I=function(e,r){var t=T[r||"kilometers"];if(void 0===t)throw new Error("Invalid unit");return e*t},D=function(e,r){var t=T[r||"kilometers"];if(void 0===t)throw new Error("Invalid unit");return e/t},U=function(e,r){var t=T[r||"kilometers"];if(void 0===t)throw new Error("Invalid unit");return e/t*57.2958},j={feature:N,point:k,polygon:L,lineString:S,featureCollection:G,multiLineString:R,multiPoint:q,multiPolygon:x,geometryCollection:A,radiansToDistance:I,distanceToRadians:D,distanceToDegrees:U},z=j.point,B=function(e){var r=M(e),t=(r[0]+r[2])/2,o=(r[1]+r[3])/2;return z([t,o])},H={bbox:l,longitude:d,latitude:y,center:c};return H}); |
23
index.js
@@ -19,7 +19,22 @@ var turfBBox = require('@turf/bbox') | ||
var west = longitude(bbox[0]) | ||
var south = latitude(bbox[1]) | ||
var east = longitude(bbox[2]) | ||
var north = latitude(bbox[3]) | ||
var west = bbox[0] | ||
var south = bbox[1] | ||
var east = bbox[2] | ||
var north = bbox[3] | ||
// Support bbox that overlaps the entire world | ||
if (west < -180 && east > 180) { | ||
west = -180 | ||
east = 180 | ||
} | ||
if (south < -90 && north > 90) { | ||
south = -90 | ||
north = 90 | ||
} | ||
// Convert Lat & Lng within dateline | ||
west = longitude(bbox[0]) | ||
south = latitude(bbox[1]) | ||
east = longitude(bbox[2]) | ||
north = latitude(bbox[3]) | ||
return [west, south, east, north] | ||
@@ -26,0 +41,0 @@ } |
{ | ||
"name": "bbox-dateline", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Modifies a BBox to fit within the bounds of the International Date Line", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55738
1336