22import { featureCollection } from '@turf/helpers' ;
33import within from '@turf/within' ;
44import buffer from '@turf/buffer' ;
5+ import bbox from '@turf/bbox' ;
56
67/**
78 * Create an array filled with a range of numbers starting at {start} and ending
@@ -13,7 +14,7 @@ import buffer from '@turf/buffer';
1314 */
1415export function range ( start , end ) {
1516 let res = [ ] ;
16- for ( var i = start ; i < end ; i ++ ) { res . push ( i ) ; }
17+ for ( let i = start ; i < end ; i ++ ) { res . push ( i ) ; }
1718 return res ;
1819}
1920
@@ -25,7 +26,7 @@ export function range (start, end) {
2526 * Origins in the given area
2627 */
2728export function originsInRegion ( area , origins ) {
28- let result = within ( origins , featureCollection ( [ area ] ) ) ;
29+ const result = within ( origins , featureCollection ( [ area ] ) ) ;
2930 return result ;
3031}
3132
@@ -37,12 +38,21 @@ export function originsInRegion (area, origins) {
3738 * @param {number } time Value in seconds
3839 * @param {number } speed Value in km/h
3940 * @param {FeatureCollection } poi Points of Interest
41+ *
42+ * @throws RangeError
43+ *
4044 * @return {FeatureCollection }
4145 * The Points of Interest in the buffered area.
4246 */
4347export function poisInBuffer ( area , poi , time , speed ) {
44- let distance = ( time / 3600 ) * speed ;
45- let bufferedArea = buffer ( area , distance , 'kilometers' ) ;
46- var result = within ( poi , featureCollection ( [ bufferedArea ] ) ) ;
48+ const distance = ( time / 3600 ) * speed ;
49+ const bufferedArea = buffer ( area , distance , 'kilometers' ) ;
50+ const [ e , s , w , n ] = bbox ( bufferedArea ) ;
51+
52+ if ( e < - 180 && w > 180 && s < - 85 && n > 85 ) {
53+ throw new RangeError ( 'World buffer overflow' ) ;
54+ }
55+
56+ const result = within ( poi , featureCollection ( [ bufferedArea ] ) ) ;
4757 return result ;
4858}
0 commit comments