@aws-amplify/geo 1.2.2-geo.3 → 1.2.2-geo.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aws-amplify-geo.js +1099 -97
- package/dist/aws-amplify-geo.js.map +1 -1
- package/dist/aws-amplify-geo.min.js +2 -2
- package/dist/aws-amplify-geo.min.js.map +1 -1
- package/lib/Geo.d.ts +2 -2
- package/lib/Geo.js +1 -18
- package/lib/Geo.js.map +1 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +16 -8
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/util.d.ts +3 -3
- package/lib/util.js +42 -61
- package/lib/util.js.map +1 -1
- package/lib-esm/Geo.d.ts +2 -2
- package/lib-esm/Geo.js +2 -19
- package/lib-esm/Geo.js.map +1 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +16 -8
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib-esm/util.d.ts +3 -3
- package/lib-esm/util.js +38 -60
- package/lib-esm/util.js.map +1 -1
- package/package.json +4 -3
- package/src/Geo.ts +1 -24
- package/src/Providers/AmazonLocationServiceProvider.ts +20 -6
- package/src/util.ts +74 -81
package/dist/aws-amplify-geo.js
CHANGED
|
@@ -24843,6 +24843,1035 @@ function locateWindow() {
|
|
|
24843
24843
|
}
|
|
24844
24844
|
|
|
24845
24845
|
|
|
24846
|
+
/***/ }),
|
|
24847
|
+
|
|
24848
|
+
/***/ "../../node_modules/@turf/boolean-clockwise/dist/es/index.js":
|
|
24849
|
+
/*!******************************************************************************!*\
|
|
24850
|
+
!*** /root/amplify-js/node_modules/@turf/boolean-clockwise/dist/es/index.js ***!
|
|
24851
|
+
\******************************************************************************/
|
|
24852
|
+
/*! exports provided: default */
|
|
24853
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
24854
|
+
|
|
24855
|
+
"use strict";
|
|
24856
|
+
__webpack_require__.r(__webpack_exports__);
|
|
24857
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return booleanClockwise; });
|
|
24858
|
+
/* harmony import */ var _turf_invariant__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @turf/invariant */ "../../node_modules/@turf/invariant/dist/es/index.js");
|
|
24859
|
+
|
|
24860
|
+
/**
|
|
24861
|
+
* Takes a ring and return true or false whether or not the ring is clockwise or counter-clockwise.
|
|
24862
|
+
*
|
|
24863
|
+
* @name booleanClockwise
|
|
24864
|
+
* @param {Feature<LineString>|LineString|Array<Array<number>>} line to be evaluated
|
|
24865
|
+
* @returns {boolean} true/false
|
|
24866
|
+
* @example
|
|
24867
|
+
* var clockwiseRing = turf.lineString([[0,0],[1,1],[1,0],[0,0]]);
|
|
24868
|
+
* var counterClockwiseRing = turf.lineString([[0,0],[1,0],[1,1],[0,0]]);
|
|
24869
|
+
*
|
|
24870
|
+
* turf.booleanClockwise(clockwiseRing)
|
|
24871
|
+
* //=true
|
|
24872
|
+
* turf.booleanClockwise(counterClockwiseRing)
|
|
24873
|
+
* //=false
|
|
24874
|
+
*/
|
|
24875
|
+
function booleanClockwise(line) {
|
|
24876
|
+
var ring = Object(_turf_invariant__WEBPACK_IMPORTED_MODULE_0__["getCoords"])(line);
|
|
24877
|
+
var sum = 0;
|
|
24878
|
+
var i = 1;
|
|
24879
|
+
var prev;
|
|
24880
|
+
var cur;
|
|
24881
|
+
while (i < ring.length) {
|
|
24882
|
+
prev = cur || ring[0];
|
|
24883
|
+
cur = ring[i];
|
|
24884
|
+
sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
|
|
24885
|
+
i++;
|
|
24886
|
+
}
|
|
24887
|
+
return sum > 0;
|
|
24888
|
+
}
|
|
24889
|
+
|
|
24890
|
+
|
|
24891
|
+
/***/ }),
|
|
24892
|
+
|
|
24893
|
+
/***/ "../../node_modules/@turf/helpers/dist/es/index.js":
|
|
24894
|
+
/*!********************************************************************!*\
|
|
24895
|
+
!*** /root/amplify-js/node_modules/@turf/helpers/dist/es/index.js ***!
|
|
24896
|
+
\********************************************************************/
|
|
24897
|
+
/*! exports provided: earthRadius, factors, unitsFactors, areaFactors, feature, geometry, point, points, polygon, polygons, lineString, lineStrings, featureCollection, multiLineString, multiPoint, multiPolygon, geometryCollection, round, radiansToLength, lengthToRadians, lengthToDegrees, bearingToAzimuth, radiansToDegrees, degreesToRadians, convertLength, convertArea, isNumber, isObject, validateBBox, validateId */
|
|
24898
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
24899
|
+
|
|
24900
|
+
"use strict";
|
|
24901
|
+
__webpack_require__.r(__webpack_exports__);
|
|
24902
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "earthRadius", function() { return earthRadius; });
|
|
24903
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "factors", function() { return factors; });
|
|
24904
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "unitsFactors", function() { return unitsFactors; });
|
|
24905
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "areaFactors", function() { return areaFactors; });
|
|
24906
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "feature", function() { return feature; });
|
|
24907
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "geometry", function() { return geometry; });
|
|
24908
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "point", function() { return point; });
|
|
24909
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "points", function() { return points; });
|
|
24910
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "polygon", function() { return polygon; });
|
|
24911
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "polygons", function() { return polygons; });
|
|
24912
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lineString", function() { return lineString; });
|
|
24913
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lineStrings", function() { return lineStrings; });
|
|
24914
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "featureCollection", function() { return featureCollection; });
|
|
24915
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "multiLineString", function() { return multiLineString; });
|
|
24916
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "multiPoint", function() { return multiPoint; });
|
|
24917
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "multiPolygon", function() { return multiPolygon; });
|
|
24918
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "geometryCollection", function() { return geometryCollection; });
|
|
24919
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "round", function() { return round; });
|
|
24920
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "radiansToLength", function() { return radiansToLength; });
|
|
24921
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lengthToRadians", function() { return lengthToRadians; });
|
|
24922
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lengthToDegrees", function() { return lengthToDegrees; });
|
|
24923
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "bearingToAzimuth", function() { return bearingToAzimuth; });
|
|
24924
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "radiansToDegrees", function() { return radiansToDegrees; });
|
|
24925
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "degreesToRadians", function() { return degreesToRadians; });
|
|
24926
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "convertLength", function() { return convertLength; });
|
|
24927
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "convertArea", function() { return convertArea; });
|
|
24928
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNumber", function() { return isNumber; });
|
|
24929
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isObject", function() { return isObject; });
|
|
24930
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateBBox", function() { return validateBBox; });
|
|
24931
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateId", function() { return validateId; });
|
|
24932
|
+
/**
|
|
24933
|
+
* @module helpers
|
|
24934
|
+
*/
|
|
24935
|
+
/**
|
|
24936
|
+
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
|
|
24937
|
+
*
|
|
24938
|
+
* @memberof helpers
|
|
24939
|
+
* @type {number}
|
|
24940
|
+
*/
|
|
24941
|
+
var earthRadius = 6371008.8;
|
|
24942
|
+
/**
|
|
24943
|
+
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
|
|
24944
|
+
*
|
|
24945
|
+
* @memberof helpers
|
|
24946
|
+
* @type {Object}
|
|
24947
|
+
*/
|
|
24948
|
+
var factors = {
|
|
24949
|
+
centimeters: earthRadius * 100,
|
|
24950
|
+
centimetres: earthRadius * 100,
|
|
24951
|
+
degrees: earthRadius / 111325,
|
|
24952
|
+
feet: earthRadius * 3.28084,
|
|
24953
|
+
inches: earthRadius * 39.37,
|
|
24954
|
+
kilometers: earthRadius / 1000,
|
|
24955
|
+
kilometres: earthRadius / 1000,
|
|
24956
|
+
meters: earthRadius,
|
|
24957
|
+
metres: earthRadius,
|
|
24958
|
+
miles: earthRadius / 1609.344,
|
|
24959
|
+
millimeters: earthRadius * 1000,
|
|
24960
|
+
millimetres: earthRadius * 1000,
|
|
24961
|
+
nauticalmiles: earthRadius / 1852,
|
|
24962
|
+
radians: 1,
|
|
24963
|
+
yards: earthRadius * 1.0936,
|
|
24964
|
+
};
|
|
24965
|
+
/**
|
|
24966
|
+
* Units of measurement factors based on 1 meter.
|
|
24967
|
+
*
|
|
24968
|
+
* @memberof helpers
|
|
24969
|
+
* @type {Object}
|
|
24970
|
+
*/
|
|
24971
|
+
var unitsFactors = {
|
|
24972
|
+
centimeters: 100,
|
|
24973
|
+
centimetres: 100,
|
|
24974
|
+
degrees: 1 / 111325,
|
|
24975
|
+
feet: 3.28084,
|
|
24976
|
+
inches: 39.37,
|
|
24977
|
+
kilometers: 1 / 1000,
|
|
24978
|
+
kilometres: 1 / 1000,
|
|
24979
|
+
meters: 1,
|
|
24980
|
+
metres: 1,
|
|
24981
|
+
miles: 1 / 1609.344,
|
|
24982
|
+
millimeters: 1000,
|
|
24983
|
+
millimetres: 1000,
|
|
24984
|
+
nauticalmiles: 1 / 1852,
|
|
24985
|
+
radians: 1 / earthRadius,
|
|
24986
|
+
yards: 1.0936133,
|
|
24987
|
+
};
|
|
24988
|
+
/**
|
|
24989
|
+
* Area of measurement factors based on 1 square meter.
|
|
24990
|
+
*
|
|
24991
|
+
* @memberof helpers
|
|
24992
|
+
* @type {Object}
|
|
24993
|
+
*/
|
|
24994
|
+
var areaFactors = {
|
|
24995
|
+
acres: 0.000247105,
|
|
24996
|
+
centimeters: 10000,
|
|
24997
|
+
centimetres: 10000,
|
|
24998
|
+
feet: 10.763910417,
|
|
24999
|
+
hectares: 0.0001,
|
|
25000
|
+
inches: 1550.003100006,
|
|
25001
|
+
kilometers: 0.000001,
|
|
25002
|
+
kilometres: 0.000001,
|
|
25003
|
+
meters: 1,
|
|
25004
|
+
metres: 1,
|
|
25005
|
+
miles: 3.86e-7,
|
|
25006
|
+
millimeters: 1000000,
|
|
25007
|
+
millimetres: 1000000,
|
|
25008
|
+
yards: 1.195990046,
|
|
25009
|
+
};
|
|
25010
|
+
/**
|
|
25011
|
+
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
|
|
25012
|
+
*
|
|
25013
|
+
* @name feature
|
|
25014
|
+
* @param {Geometry} geometry input geometry
|
|
25015
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25016
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25017
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25018
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25019
|
+
* @returns {Feature} a GeoJSON Feature
|
|
25020
|
+
* @example
|
|
25021
|
+
* var geometry = {
|
|
25022
|
+
* "type": "Point",
|
|
25023
|
+
* "coordinates": [110, 50]
|
|
25024
|
+
* };
|
|
25025
|
+
*
|
|
25026
|
+
* var feature = turf.feature(geometry);
|
|
25027
|
+
*
|
|
25028
|
+
* //=feature
|
|
25029
|
+
*/
|
|
25030
|
+
function feature(geom, properties, options) {
|
|
25031
|
+
if (options === void 0) { options = {}; }
|
|
25032
|
+
var feat = { type: "Feature" };
|
|
25033
|
+
if (options.id === 0 || options.id) {
|
|
25034
|
+
feat.id = options.id;
|
|
25035
|
+
}
|
|
25036
|
+
if (options.bbox) {
|
|
25037
|
+
feat.bbox = options.bbox;
|
|
25038
|
+
}
|
|
25039
|
+
feat.properties = properties || {};
|
|
25040
|
+
feat.geometry = geom;
|
|
25041
|
+
return feat;
|
|
25042
|
+
}
|
|
25043
|
+
/**
|
|
25044
|
+
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
|
|
25045
|
+
* For GeometryCollection type use `helpers.geometryCollection`
|
|
25046
|
+
*
|
|
25047
|
+
* @name geometry
|
|
25048
|
+
* @param {string} type Geometry Type
|
|
25049
|
+
* @param {Array<any>} coordinates Coordinates
|
|
25050
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25051
|
+
* @returns {Geometry} a GeoJSON Geometry
|
|
25052
|
+
* @example
|
|
25053
|
+
* var type = "Point";
|
|
25054
|
+
* var coordinates = [110, 50];
|
|
25055
|
+
* var geometry = turf.geometry(type, coordinates);
|
|
25056
|
+
* // => geometry
|
|
25057
|
+
*/
|
|
25058
|
+
function geometry(type, coordinates, _options) {
|
|
25059
|
+
if (_options === void 0) { _options = {}; }
|
|
25060
|
+
switch (type) {
|
|
25061
|
+
case "Point":
|
|
25062
|
+
return point(coordinates).geometry;
|
|
25063
|
+
case "LineString":
|
|
25064
|
+
return lineString(coordinates).geometry;
|
|
25065
|
+
case "Polygon":
|
|
25066
|
+
return polygon(coordinates).geometry;
|
|
25067
|
+
case "MultiPoint":
|
|
25068
|
+
return multiPoint(coordinates).geometry;
|
|
25069
|
+
case "MultiLineString":
|
|
25070
|
+
return multiLineString(coordinates).geometry;
|
|
25071
|
+
case "MultiPolygon":
|
|
25072
|
+
return multiPolygon(coordinates).geometry;
|
|
25073
|
+
default:
|
|
25074
|
+
throw new Error(type + " is invalid");
|
|
25075
|
+
}
|
|
25076
|
+
}
|
|
25077
|
+
/**
|
|
25078
|
+
* Creates a {@link Point} {@link Feature} from a Position.
|
|
25079
|
+
*
|
|
25080
|
+
* @name point
|
|
25081
|
+
* @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
|
|
25082
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25083
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25084
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25085
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25086
|
+
* @returns {Feature<Point>} a Point feature
|
|
25087
|
+
* @example
|
|
25088
|
+
* var point = turf.point([-75.343, 39.984]);
|
|
25089
|
+
*
|
|
25090
|
+
* //=point
|
|
25091
|
+
*/
|
|
25092
|
+
function point(coordinates, properties, options) {
|
|
25093
|
+
if (options === void 0) { options = {}; }
|
|
25094
|
+
if (!coordinates) {
|
|
25095
|
+
throw new Error("coordinates is required");
|
|
25096
|
+
}
|
|
25097
|
+
if (!Array.isArray(coordinates)) {
|
|
25098
|
+
throw new Error("coordinates must be an Array");
|
|
25099
|
+
}
|
|
25100
|
+
if (coordinates.length < 2) {
|
|
25101
|
+
throw new Error("coordinates must be at least 2 numbers long");
|
|
25102
|
+
}
|
|
25103
|
+
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
|
|
25104
|
+
throw new Error("coordinates must contain numbers");
|
|
25105
|
+
}
|
|
25106
|
+
var geom = {
|
|
25107
|
+
type: "Point",
|
|
25108
|
+
coordinates: coordinates,
|
|
25109
|
+
};
|
|
25110
|
+
return feature(geom, properties, options);
|
|
25111
|
+
}
|
|
25112
|
+
/**
|
|
25113
|
+
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
|
|
25114
|
+
*
|
|
25115
|
+
* @name points
|
|
25116
|
+
* @param {Array<Array<number>>} coordinates an array of Points
|
|
25117
|
+
* @param {Object} [properties={}] Translate these properties to each Feature
|
|
25118
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25119
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
|
|
25120
|
+
* associated with the FeatureCollection
|
|
25121
|
+
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
|
|
25122
|
+
* @returns {FeatureCollection<Point>} Point Feature
|
|
25123
|
+
* @example
|
|
25124
|
+
* var points = turf.points([
|
|
25125
|
+
* [-75, 39],
|
|
25126
|
+
* [-80, 45],
|
|
25127
|
+
* [-78, 50]
|
|
25128
|
+
* ]);
|
|
25129
|
+
*
|
|
25130
|
+
* //=points
|
|
25131
|
+
*/
|
|
25132
|
+
function points(coordinates, properties, options) {
|
|
25133
|
+
if (options === void 0) { options = {}; }
|
|
25134
|
+
return featureCollection(coordinates.map(function (coords) {
|
|
25135
|
+
return point(coords, properties);
|
|
25136
|
+
}), options);
|
|
25137
|
+
}
|
|
25138
|
+
/**
|
|
25139
|
+
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
|
|
25140
|
+
*
|
|
25141
|
+
* @name polygon
|
|
25142
|
+
* @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
|
|
25143
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25144
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25145
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25146
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25147
|
+
* @returns {Feature<Polygon>} Polygon Feature
|
|
25148
|
+
* @example
|
|
25149
|
+
* var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
|
|
25150
|
+
*
|
|
25151
|
+
* //=polygon
|
|
25152
|
+
*/
|
|
25153
|
+
function polygon(coordinates, properties, options) {
|
|
25154
|
+
if (options === void 0) { options = {}; }
|
|
25155
|
+
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
|
|
25156
|
+
var ring = coordinates_1[_i];
|
|
25157
|
+
if (ring.length < 4) {
|
|
25158
|
+
throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
|
|
25159
|
+
}
|
|
25160
|
+
for (var j = 0; j < ring[ring.length - 1].length; j++) {
|
|
25161
|
+
// Check if first point of Polygon contains two numbers
|
|
25162
|
+
if (ring[ring.length - 1][j] !== ring[0][j]) {
|
|
25163
|
+
throw new Error("First and last Position are not equivalent.");
|
|
25164
|
+
}
|
|
25165
|
+
}
|
|
25166
|
+
}
|
|
25167
|
+
var geom = {
|
|
25168
|
+
type: "Polygon",
|
|
25169
|
+
coordinates: coordinates,
|
|
25170
|
+
};
|
|
25171
|
+
return feature(geom, properties, options);
|
|
25172
|
+
}
|
|
25173
|
+
/**
|
|
25174
|
+
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
|
|
25175
|
+
*
|
|
25176
|
+
* @name polygons
|
|
25177
|
+
* @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates
|
|
25178
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25179
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25180
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25181
|
+
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
|
|
25182
|
+
* @returns {FeatureCollection<Polygon>} Polygon FeatureCollection
|
|
25183
|
+
* @example
|
|
25184
|
+
* var polygons = turf.polygons([
|
|
25185
|
+
* [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
|
|
25186
|
+
* [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
|
|
25187
|
+
* ]);
|
|
25188
|
+
*
|
|
25189
|
+
* //=polygons
|
|
25190
|
+
*/
|
|
25191
|
+
function polygons(coordinates, properties, options) {
|
|
25192
|
+
if (options === void 0) { options = {}; }
|
|
25193
|
+
return featureCollection(coordinates.map(function (coords) {
|
|
25194
|
+
return polygon(coords, properties);
|
|
25195
|
+
}), options);
|
|
25196
|
+
}
|
|
25197
|
+
/**
|
|
25198
|
+
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
|
|
25199
|
+
*
|
|
25200
|
+
* @name lineString
|
|
25201
|
+
* @param {Array<Array<number>>} coordinates an array of Positions
|
|
25202
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25203
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25204
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25205
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25206
|
+
* @returns {Feature<LineString>} LineString Feature
|
|
25207
|
+
* @example
|
|
25208
|
+
* var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
|
|
25209
|
+
* var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
|
|
25210
|
+
*
|
|
25211
|
+
* //=linestring1
|
|
25212
|
+
* //=linestring2
|
|
25213
|
+
*/
|
|
25214
|
+
function lineString(coordinates, properties, options) {
|
|
25215
|
+
if (options === void 0) { options = {}; }
|
|
25216
|
+
if (coordinates.length < 2) {
|
|
25217
|
+
throw new Error("coordinates must be an array of two or more positions");
|
|
25218
|
+
}
|
|
25219
|
+
var geom = {
|
|
25220
|
+
type: "LineString",
|
|
25221
|
+
coordinates: coordinates,
|
|
25222
|
+
};
|
|
25223
|
+
return feature(geom, properties, options);
|
|
25224
|
+
}
|
|
25225
|
+
/**
|
|
25226
|
+
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
|
|
25227
|
+
*
|
|
25228
|
+
* @name lineStrings
|
|
25229
|
+
* @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
|
|
25230
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25231
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25232
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
|
|
25233
|
+
* associated with the FeatureCollection
|
|
25234
|
+
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
|
|
25235
|
+
* @returns {FeatureCollection<LineString>} LineString FeatureCollection
|
|
25236
|
+
* @example
|
|
25237
|
+
* var linestrings = turf.lineStrings([
|
|
25238
|
+
* [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
|
|
25239
|
+
* [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
|
|
25240
|
+
* ]);
|
|
25241
|
+
*
|
|
25242
|
+
* //=linestrings
|
|
25243
|
+
*/
|
|
25244
|
+
function lineStrings(coordinates, properties, options) {
|
|
25245
|
+
if (options === void 0) { options = {}; }
|
|
25246
|
+
return featureCollection(coordinates.map(function (coords) {
|
|
25247
|
+
return lineString(coords, properties);
|
|
25248
|
+
}), options);
|
|
25249
|
+
}
|
|
25250
|
+
/**
|
|
25251
|
+
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
|
|
25252
|
+
*
|
|
25253
|
+
* @name featureCollection
|
|
25254
|
+
* @param {Feature[]} features input features
|
|
25255
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25256
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25257
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25258
|
+
* @returns {FeatureCollection} FeatureCollection of Features
|
|
25259
|
+
* @example
|
|
25260
|
+
* var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
|
|
25261
|
+
* var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
|
|
25262
|
+
* var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
|
|
25263
|
+
*
|
|
25264
|
+
* var collection = turf.featureCollection([
|
|
25265
|
+
* locationA,
|
|
25266
|
+
* locationB,
|
|
25267
|
+
* locationC
|
|
25268
|
+
* ]);
|
|
25269
|
+
*
|
|
25270
|
+
* //=collection
|
|
25271
|
+
*/
|
|
25272
|
+
function featureCollection(features, options) {
|
|
25273
|
+
if (options === void 0) { options = {}; }
|
|
25274
|
+
var fc = { type: "FeatureCollection" };
|
|
25275
|
+
if (options.id) {
|
|
25276
|
+
fc.id = options.id;
|
|
25277
|
+
}
|
|
25278
|
+
if (options.bbox) {
|
|
25279
|
+
fc.bbox = options.bbox;
|
|
25280
|
+
}
|
|
25281
|
+
fc.features = features;
|
|
25282
|
+
return fc;
|
|
25283
|
+
}
|
|
25284
|
+
/**
|
|
25285
|
+
* Creates a {@link Feature<MultiLineString>} based on a
|
|
25286
|
+
* coordinate array. Properties can be added optionally.
|
|
25287
|
+
*
|
|
25288
|
+
* @name multiLineString
|
|
25289
|
+
* @param {Array<Array<Array<number>>>} coordinates an array of LineStrings
|
|
25290
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25291
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25292
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25293
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25294
|
+
* @returns {Feature<MultiLineString>} a MultiLineString feature
|
|
25295
|
+
* @throws {Error} if no coordinates are passed
|
|
25296
|
+
* @example
|
|
25297
|
+
* var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
|
|
25298
|
+
*
|
|
25299
|
+
* //=multiLine
|
|
25300
|
+
*/
|
|
25301
|
+
function multiLineString(coordinates, properties, options) {
|
|
25302
|
+
if (options === void 0) { options = {}; }
|
|
25303
|
+
var geom = {
|
|
25304
|
+
type: "MultiLineString",
|
|
25305
|
+
coordinates: coordinates,
|
|
25306
|
+
};
|
|
25307
|
+
return feature(geom, properties, options);
|
|
25308
|
+
}
|
|
25309
|
+
/**
|
|
25310
|
+
* Creates a {@link Feature<MultiPoint>} based on a
|
|
25311
|
+
* coordinate array. Properties can be added optionally.
|
|
25312
|
+
*
|
|
25313
|
+
* @name multiPoint
|
|
25314
|
+
* @param {Array<Array<number>>} coordinates an array of Positions
|
|
25315
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25316
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25317
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25318
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25319
|
+
* @returns {Feature<MultiPoint>} a MultiPoint feature
|
|
25320
|
+
* @throws {Error} if no coordinates are passed
|
|
25321
|
+
* @example
|
|
25322
|
+
* var multiPt = turf.multiPoint([[0,0],[10,10]]);
|
|
25323
|
+
*
|
|
25324
|
+
* //=multiPt
|
|
25325
|
+
*/
|
|
25326
|
+
function multiPoint(coordinates, properties, options) {
|
|
25327
|
+
if (options === void 0) { options = {}; }
|
|
25328
|
+
var geom = {
|
|
25329
|
+
type: "MultiPoint",
|
|
25330
|
+
coordinates: coordinates,
|
|
25331
|
+
};
|
|
25332
|
+
return feature(geom, properties, options);
|
|
25333
|
+
}
|
|
25334
|
+
/**
|
|
25335
|
+
* Creates a {@link Feature<MultiPolygon>} based on a
|
|
25336
|
+
* coordinate array. Properties can be added optionally.
|
|
25337
|
+
*
|
|
25338
|
+
* @name multiPolygon
|
|
25339
|
+
* @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons
|
|
25340
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25341
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25342
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25343
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25344
|
+
* @returns {Feature<MultiPolygon>} a multipolygon feature
|
|
25345
|
+
* @throws {Error} if no coordinates are passed
|
|
25346
|
+
* @example
|
|
25347
|
+
* var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
|
|
25348
|
+
*
|
|
25349
|
+
* //=multiPoly
|
|
25350
|
+
*
|
|
25351
|
+
*/
|
|
25352
|
+
function multiPolygon(coordinates, properties, options) {
|
|
25353
|
+
if (options === void 0) { options = {}; }
|
|
25354
|
+
var geom = {
|
|
25355
|
+
type: "MultiPolygon",
|
|
25356
|
+
coordinates: coordinates,
|
|
25357
|
+
};
|
|
25358
|
+
return feature(geom, properties, options);
|
|
25359
|
+
}
|
|
25360
|
+
/**
|
|
25361
|
+
* Creates a {@link Feature<GeometryCollection>} based on a
|
|
25362
|
+
* coordinate array. Properties can be added optionally.
|
|
25363
|
+
*
|
|
25364
|
+
* @name geometryCollection
|
|
25365
|
+
* @param {Array<Geometry>} geometries an array of GeoJSON Geometries
|
|
25366
|
+
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
|
|
25367
|
+
* @param {Object} [options={}] Optional Parameters
|
|
25368
|
+
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
|
|
25369
|
+
* @param {string|number} [options.id] Identifier associated with the Feature
|
|
25370
|
+
* @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature
|
|
25371
|
+
* @example
|
|
25372
|
+
* var pt = turf.geometry("Point", [100, 0]);
|
|
25373
|
+
* var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
|
|
25374
|
+
* var collection = turf.geometryCollection([pt, line]);
|
|
25375
|
+
*
|
|
25376
|
+
* // => collection
|
|
25377
|
+
*/
|
|
25378
|
+
function geometryCollection(geometries, properties, options) {
|
|
25379
|
+
if (options === void 0) { options = {}; }
|
|
25380
|
+
var geom = {
|
|
25381
|
+
type: "GeometryCollection",
|
|
25382
|
+
geometries: geometries,
|
|
25383
|
+
};
|
|
25384
|
+
return feature(geom, properties, options);
|
|
25385
|
+
}
|
|
25386
|
+
/**
|
|
25387
|
+
* Round number to precision
|
|
25388
|
+
*
|
|
25389
|
+
* @param {number} num Number
|
|
25390
|
+
* @param {number} [precision=0] Precision
|
|
25391
|
+
* @returns {number} rounded number
|
|
25392
|
+
* @example
|
|
25393
|
+
* turf.round(120.4321)
|
|
25394
|
+
* //=120
|
|
25395
|
+
*
|
|
25396
|
+
* turf.round(120.4321, 2)
|
|
25397
|
+
* //=120.43
|
|
25398
|
+
*/
|
|
25399
|
+
function round(num, precision) {
|
|
25400
|
+
if (precision === void 0) { precision = 0; }
|
|
25401
|
+
if (precision && !(precision >= 0)) {
|
|
25402
|
+
throw new Error("precision must be a positive number");
|
|
25403
|
+
}
|
|
25404
|
+
var multiplier = Math.pow(10, precision || 0);
|
|
25405
|
+
return Math.round(num * multiplier) / multiplier;
|
|
25406
|
+
}
|
|
25407
|
+
/**
|
|
25408
|
+
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
|
|
25409
|
+
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
25410
|
+
*
|
|
25411
|
+
* @name radiansToLength
|
|
25412
|
+
* @param {number} radians in radians across the sphere
|
|
25413
|
+
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
|
|
25414
|
+
* meters, kilometres, kilometers.
|
|
25415
|
+
* @returns {number} distance
|
|
25416
|
+
*/
|
|
25417
|
+
function radiansToLength(radians, units) {
|
|
25418
|
+
if (units === void 0) { units = "kilometers"; }
|
|
25419
|
+
var factor = factors[units];
|
|
25420
|
+
if (!factor) {
|
|
25421
|
+
throw new Error(units + " units is invalid");
|
|
25422
|
+
}
|
|
25423
|
+
return radians * factor;
|
|
25424
|
+
}
|
|
25425
|
+
/**
|
|
25426
|
+
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
|
|
25427
|
+
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
25428
|
+
*
|
|
25429
|
+
* @name lengthToRadians
|
|
25430
|
+
* @param {number} distance in real units
|
|
25431
|
+
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
|
|
25432
|
+
* meters, kilometres, kilometers.
|
|
25433
|
+
* @returns {number} radians
|
|
25434
|
+
*/
|
|
25435
|
+
function lengthToRadians(distance, units) {
|
|
25436
|
+
if (units === void 0) { units = "kilometers"; }
|
|
25437
|
+
var factor = factors[units];
|
|
25438
|
+
if (!factor) {
|
|
25439
|
+
throw new Error(units + " units is invalid");
|
|
25440
|
+
}
|
|
25441
|
+
return distance / factor;
|
|
25442
|
+
}
|
|
25443
|
+
/**
|
|
25444
|
+
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
|
|
25445
|
+
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
|
|
25446
|
+
*
|
|
25447
|
+
* @name lengthToDegrees
|
|
25448
|
+
* @param {number} distance in real units
|
|
25449
|
+
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
|
|
25450
|
+
* meters, kilometres, kilometers.
|
|
25451
|
+
* @returns {number} degrees
|
|
25452
|
+
*/
|
|
25453
|
+
function lengthToDegrees(distance, units) {
|
|
25454
|
+
return radiansToDegrees(lengthToRadians(distance, units));
|
|
25455
|
+
}
|
|
25456
|
+
/**
|
|
25457
|
+
* Converts any bearing angle from the north line direction (positive clockwise)
|
|
25458
|
+
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
|
|
25459
|
+
*
|
|
25460
|
+
* @name bearingToAzimuth
|
|
25461
|
+
* @param {number} bearing angle, between -180 and +180 degrees
|
|
25462
|
+
* @returns {number} angle between 0 and 360 degrees
|
|
25463
|
+
*/
|
|
25464
|
+
function bearingToAzimuth(bearing) {
|
|
25465
|
+
var angle = bearing % 360;
|
|
25466
|
+
if (angle < 0) {
|
|
25467
|
+
angle += 360;
|
|
25468
|
+
}
|
|
25469
|
+
return angle;
|
|
25470
|
+
}
|
|
25471
|
+
/**
|
|
25472
|
+
* Converts an angle in radians to degrees
|
|
25473
|
+
*
|
|
25474
|
+
* @name radiansToDegrees
|
|
25475
|
+
* @param {number} radians angle in radians
|
|
25476
|
+
* @returns {number} degrees between 0 and 360 degrees
|
|
25477
|
+
*/
|
|
25478
|
+
function radiansToDegrees(radians) {
|
|
25479
|
+
var degrees = radians % (2 * Math.PI);
|
|
25480
|
+
return (degrees * 180) / Math.PI;
|
|
25481
|
+
}
|
|
25482
|
+
/**
|
|
25483
|
+
* Converts an angle in degrees to radians
|
|
25484
|
+
*
|
|
25485
|
+
* @name degreesToRadians
|
|
25486
|
+
* @param {number} degrees angle between 0 and 360 degrees
|
|
25487
|
+
* @returns {number} angle in radians
|
|
25488
|
+
*/
|
|
25489
|
+
function degreesToRadians(degrees) {
|
|
25490
|
+
var radians = degrees % 360;
|
|
25491
|
+
return (radians * Math.PI) / 180;
|
|
25492
|
+
}
|
|
25493
|
+
/**
|
|
25494
|
+
* Converts a length to the requested unit.
|
|
25495
|
+
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
25496
|
+
*
|
|
25497
|
+
* @param {number} length to be converted
|
|
25498
|
+
* @param {Units} [originalUnit="kilometers"] of the length
|
|
25499
|
+
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
25500
|
+
* @returns {number} the converted length
|
|
25501
|
+
*/
|
|
25502
|
+
function convertLength(length, originalUnit, finalUnit) {
|
|
25503
|
+
if (originalUnit === void 0) { originalUnit = "kilometers"; }
|
|
25504
|
+
if (finalUnit === void 0) { finalUnit = "kilometers"; }
|
|
25505
|
+
if (!(length >= 0)) {
|
|
25506
|
+
throw new Error("length must be a positive number");
|
|
25507
|
+
}
|
|
25508
|
+
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
|
|
25509
|
+
}
|
|
25510
|
+
/**
|
|
25511
|
+
* Converts a area to the requested unit.
|
|
25512
|
+
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
|
|
25513
|
+
* @param {number} area to be converted
|
|
25514
|
+
* @param {Units} [originalUnit="meters"] of the distance
|
|
25515
|
+
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
25516
|
+
* @returns {number} the converted area
|
|
25517
|
+
*/
|
|
25518
|
+
function convertArea(area, originalUnit, finalUnit) {
|
|
25519
|
+
if (originalUnit === void 0) { originalUnit = "meters"; }
|
|
25520
|
+
if (finalUnit === void 0) { finalUnit = "kilometers"; }
|
|
25521
|
+
if (!(area >= 0)) {
|
|
25522
|
+
throw new Error("area must be a positive number");
|
|
25523
|
+
}
|
|
25524
|
+
var startFactor = areaFactors[originalUnit];
|
|
25525
|
+
if (!startFactor) {
|
|
25526
|
+
throw new Error("invalid original units");
|
|
25527
|
+
}
|
|
25528
|
+
var finalFactor = areaFactors[finalUnit];
|
|
25529
|
+
if (!finalFactor) {
|
|
25530
|
+
throw new Error("invalid final units");
|
|
25531
|
+
}
|
|
25532
|
+
return (area / startFactor) * finalFactor;
|
|
25533
|
+
}
|
|
25534
|
+
/**
|
|
25535
|
+
* isNumber
|
|
25536
|
+
*
|
|
25537
|
+
* @param {*} num Number to validate
|
|
25538
|
+
* @returns {boolean} true/false
|
|
25539
|
+
* @example
|
|
25540
|
+
* turf.isNumber(123)
|
|
25541
|
+
* //=true
|
|
25542
|
+
* turf.isNumber('foo')
|
|
25543
|
+
* //=false
|
|
25544
|
+
*/
|
|
25545
|
+
function isNumber(num) {
|
|
25546
|
+
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
25547
|
+
}
|
|
25548
|
+
/**
|
|
25549
|
+
* isObject
|
|
25550
|
+
*
|
|
25551
|
+
* @param {*} input variable to validate
|
|
25552
|
+
* @returns {boolean} true/false
|
|
25553
|
+
* @example
|
|
25554
|
+
* turf.isObject({elevation: 10})
|
|
25555
|
+
* //=true
|
|
25556
|
+
* turf.isObject('foo')
|
|
25557
|
+
* //=false
|
|
25558
|
+
*/
|
|
25559
|
+
function isObject(input) {
|
|
25560
|
+
return !!input && input.constructor === Object;
|
|
25561
|
+
}
|
|
25562
|
+
/**
|
|
25563
|
+
* Validate BBox
|
|
25564
|
+
*
|
|
25565
|
+
* @private
|
|
25566
|
+
* @param {Array<number>} bbox BBox to validate
|
|
25567
|
+
* @returns {void}
|
|
25568
|
+
* @throws Error if BBox is not valid
|
|
25569
|
+
* @example
|
|
25570
|
+
* validateBBox([-180, -40, 110, 50])
|
|
25571
|
+
* //=OK
|
|
25572
|
+
* validateBBox([-180, -40])
|
|
25573
|
+
* //=Error
|
|
25574
|
+
* validateBBox('Foo')
|
|
25575
|
+
* //=Error
|
|
25576
|
+
* validateBBox(5)
|
|
25577
|
+
* //=Error
|
|
25578
|
+
* validateBBox(null)
|
|
25579
|
+
* //=Error
|
|
25580
|
+
* validateBBox(undefined)
|
|
25581
|
+
* //=Error
|
|
25582
|
+
*/
|
|
25583
|
+
function validateBBox(bbox) {
|
|
25584
|
+
if (!bbox) {
|
|
25585
|
+
throw new Error("bbox is required");
|
|
25586
|
+
}
|
|
25587
|
+
if (!Array.isArray(bbox)) {
|
|
25588
|
+
throw new Error("bbox must be an Array");
|
|
25589
|
+
}
|
|
25590
|
+
if (bbox.length !== 4 && bbox.length !== 6) {
|
|
25591
|
+
throw new Error("bbox must be an Array of 4 or 6 numbers");
|
|
25592
|
+
}
|
|
25593
|
+
bbox.forEach(function (num) {
|
|
25594
|
+
if (!isNumber(num)) {
|
|
25595
|
+
throw new Error("bbox must only contain numbers");
|
|
25596
|
+
}
|
|
25597
|
+
});
|
|
25598
|
+
}
|
|
25599
|
+
/**
|
|
25600
|
+
* Validate Id
|
|
25601
|
+
*
|
|
25602
|
+
* @private
|
|
25603
|
+
* @param {string|number} id Id to validate
|
|
25604
|
+
* @returns {void}
|
|
25605
|
+
* @throws Error if Id is not valid
|
|
25606
|
+
* @example
|
|
25607
|
+
* validateId([-180, -40, 110, 50])
|
|
25608
|
+
* //=Error
|
|
25609
|
+
* validateId([-180, -40])
|
|
25610
|
+
* //=Error
|
|
25611
|
+
* validateId('Foo')
|
|
25612
|
+
* //=OK
|
|
25613
|
+
* validateId(5)
|
|
25614
|
+
* //=OK
|
|
25615
|
+
* validateId(null)
|
|
25616
|
+
* //=Error
|
|
25617
|
+
* validateId(undefined)
|
|
25618
|
+
* //=Error
|
|
25619
|
+
*/
|
|
25620
|
+
function validateId(id) {
|
|
25621
|
+
if (!id) {
|
|
25622
|
+
throw new Error("id is required");
|
|
25623
|
+
}
|
|
25624
|
+
if (["string", "number"].indexOf(typeof id) === -1) {
|
|
25625
|
+
throw new Error("id must be a number or a string");
|
|
25626
|
+
}
|
|
25627
|
+
}
|
|
25628
|
+
|
|
25629
|
+
|
|
25630
|
+
/***/ }),
|
|
25631
|
+
|
|
25632
|
+
/***/ "../../node_modules/@turf/invariant/dist/es/index.js":
|
|
25633
|
+
/*!**********************************************************************!*\
|
|
25634
|
+
!*** /root/amplify-js/node_modules/@turf/invariant/dist/es/index.js ***!
|
|
25635
|
+
\**********************************************************************/
|
|
25636
|
+
/*! exports provided: getCoord, getCoords, containsNumber, geojsonType, featureOf, collectionOf, getGeom, getType */
|
|
25637
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
25638
|
+
|
|
25639
|
+
"use strict";
|
|
25640
|
+
__webpack_require__.r(__webpack_exports__);
|
|
25641
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getCoord", function() { return getCoord; });
|
|
25642
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getCoords", function() { return getCoords; });
|
|
25643
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "containsNumber", function() { return containsNumber; });
|
|
25644
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "geojsonType", function() { return geojsonType; });
|
|
25645
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "featureOf", function() { return featureOf; });
|
|
25646
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "collectionOf", function() { return collectionOf; });
|
|
25647
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getGeom", function() { return getGeom; });
|
|
25648
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getType", function() { return getType; });
|
|
25649
|
+
/* harmony import */ var _turf_helpers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @turf/helpers */ "../../node_modules/@turf/helpers/dist/es/index.js");
|
|
25650
|
+
|
|
25651
|
+
/**
|
|
25652
|
+
* Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
|
|
25653
|
+
*
|
|
25654
|
+
* @name getCoord
|
|
25655
|
+
* @param {Array<number>|Geometry<Point>|Feature<Point>} coord GeoJSON Point or an Array of numbers
|
|
25656
|
+
* @returns {Array<number>} coordinates
|
|
25657
|
+
* @example
|
|
25658
|
+
* var pt = turf.point([10, 10]);
|
|
25659
|
+
*
|
|
25660
|
+
* var coord = turf.getCoord(pt);
|
|
25661
|
+
* //= [10, 10]
|
|
25662
|
+
*/
|
|
25663
|
+
function getCoord(coord) {
|
|
25664
|
+
if (!coord) {
|
|
25665
|
+
throw new Error("coord is required");
|
|
25666
|
+
}
|
|
25667
|
+
if (!Array.isArray(coord)) {
|
|
25668
|
+
if (coord.type === "Feature" &&
|
|
25669
|
+
coord.geometry !== null &&
|
|
25670
|
+
coord.geometry.type === "Point") {
|
|
25671
|
+
return coord.geometry.coordinates;
|
|
25672
|
+
}
|
|
25673
|
+
if (coord.type === "Point") {
|
|
25674
|
+
return coord.coordinates;
|
|
25675
|
+
}
|
|
25676
|
+
}
|
|
25677
|
+
if (Array.isArray(coord) &&
|
|
25678
|
+
coord.length >= 2 &&
|
|
25679
|
+
!Array.isArray(coord[0]) &&
|
|
25680
|
+
!Array.isArray(coord[1])) {
|
|
25681
|
+
return coord;
|
|
25682
|
+
}
|
|
25683
|
+
throw new Error("coord must be GeoJSON Point or an Array of numbers");
|
|
25684
|
+
}
|
|
25685
|
+
/**
|
|
25686
|
+
* Unwrap coordinates from a Feature, Geometry Object or an Array
|
|
25687
|
+
*
|
|
25688
|
+
* @name getCoords
|
|
25689
|
+
* @param {Array<any>|Geometry|Feature} coords Feature, Geometry Object or an Array
|
|
25690
|
+
* @returns {Array<any>} coordinates
|
|
25691
|
+
* @example
|
|
25692
|
+
* var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
|
|
25693
|
+
*
|
|
25694
|
+
* var coords = turf.getCoords(poly);
|
|
25695
|
+
* //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
|
|
25696
|
+
*/
|
|
25697
|
+
function getCoords(coords) {
|
|
25698
|
+
if (Array.isArray(coords)) {
|
|
25699
|
+
return coords;
|
|
25700
|
+
}
|
|
25701
|
+
// Feature
|
|
25702
|
+
if (coords.type === "Feature") {
|
|
25703
|
+
if (coords.geometry !== null) {
|
|
25704
|
+
return coords.geometry.coordinates;
|
|
25705
|
+
}
|
|
25706
|
+
}
|
|
25707
|
+
else {
|
|
25708
|
+
// Geometry
|
|
25709
|
+
if (coords.coordinates) {
|
|
25710
|
+
return coords.coordinates;
|
|
25711
|
+
}
|
|
25712
|
+
}
|
|
25713
|
+
throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array");
|
|
25714
|
+
}
|
|
25715
|
+
/**
|
|
25716
|
+
* Checks if coordinates contains a number
|
|
25717
|
+
*
|
|
25718
|
+
* @name containsNumber
|
|
25719
|
+
* @param {Array<any>} coordinates GeoJSON Coordinates
|
|
25720
|
+
* @returns {boolean} true if Array contains a number
|
|
25721
|
+
*/
|
|
25722
|
+
function containsNumber(coordinates) {
|
|
25723
|
+
if (coordinates.length > 1 &&
|
|
25724
|
+
Object(_turf_helpers__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(coordinates[0]) &&
|
|
25725
|
+
Object(_turf_helpers__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(coordinates[1])) {
|
|
25726
|
+
return true;
|
|
25727
|
+
}
|
|
25728
|
+
if (Array.isArray(coordinates[0]) && coordinates[0].length) {
|
|
25729
|
+
return containsNumber(coordinates[0]);
|
|
25730
|
+
}
|
|
25731
|
+
throw new Error("coordinates must only contain numbers");
|
|
25732
|
+
}
|
|
25733
|
+
/**
|
|
25734
|
+
* Enforce expectations about types of GeoJSON objects for Turf.
|
|
25735
|
+
*
|
|
25736
|
+
* @name geojsonType
|
|
25737
|
+
* @param {GeoJSON} value any GeoJSON object
|
|
25738
|
+
* @param {string} type expected GeoJSON type
|
|
25739
|
+
* @param {string} name name of calling function
|
|
25740
|
+
* @throws {Error} if value is not the expected type.
|
|
25741
|
+
*/
|
|
25742
|
+
function geojsonType(value, type, name) {
|
|
25743
|
+
if (!type || !name) {
|
|
25744
|
+
throw new Error("type and name required");
|
|
25745
|
+
}
|
|
25746
|
+
if (!value || value.type !== type) {
|
|
25747
|
+
throw new Error("Invalid input to " +
|
|
25748
|
+
name +
|
|
25749
|
+
": must be a " +
|
|
25750
|
+
type +
|
|
25751
|
+
", given " +
|
|
25752
|
+
value.type);
|
|
25753
|
+
}
|
|
25754
|
+
}
|
|
25755
|
+
/**
|
|
25756
|
+
* Enforce expectations about types of {@link Feature} inputs for Turf.
|
|
25757
|
+
* Internally this uses {@link geojsonType} to judge geometry types.
|
|
25758
|
+
*
|
|
25759
|
+
* @name featureOf
|
|
25760
|
+
* @param {Feature} feature a feature with an expected geometry type
|
|
25761
|
+
* @param {string} type expected GeoJSON type
|
|
25762
|
+
* @param {string} name name of calling function
|
|
25763
|
+
* @throws {Error} error if value is not the expected type.
|
|
25764
|
+
*/
|
|
25765
|
+
function featureOf(feature, type, name) {
|
|
25766
|
+
if (!feature) {
|
|
25767
|
+
throw new Error("No feature passed");
|
|
25768
|
+
}
|
|
25769
|
+
if (!name) {
|
|
25770
|
+
throw new Error(".featureOf() requires a name");
|
|
25771
|
+
}
|
|
25772
|
+
if (!feature || feature.type !== "Feature" || !feature.geometry) {
|
|
25773
|
+
throw new Error("Invalid input to " + name + ", Feature with geometry required");
|
|
25774
|
+
}
|
|
25775
|
+
if (!feature.geometry || feature.geometry.type !== type) {
|
|
25776
|
+
throw new Error("Invalid input to " +
|
|
25777
|
+
name +
|
|
25778
|
+
": must be a " +
|
|
25779
|
+
type +
|
|
25780
|
+
", given " +
|
|
25781
|
+
feature.geometry.type);
|
|
25782
|
+
}
|
|
25783
|
+
}
|
|
25784
|
+
/**
|
|
25785
|
+
* Enforce expectations about types of {@link FeatureCollection} inputs for Turf.
|
|
25786
|
+
* Internally this uses {@link geojsonType} to judge geometry types.
|
|
25787
|
+
*
|
|
25788
|
+
* @name collectionOf
|
|
25789
|
+
* @param {FeatureCollection} featureCollection a FeatureCollection for which features will be judged
|
|
25790
|
+
* @param {string} type expected GeoJSON type
|
|
25791
|
+
* @param {string} name name of calling function
|
|
25792
|
+
* @throws {Error} if value is not the expected type.
|
|
25793
|
+
*/
|
|
25794
|
+
function collectionOf(featureCollection, type, name) {
|
|
25795
|
+
if (!featureCollection) {
|
|
25796
|
+
throw new Error("No featureCollection passed");
|
|
25797
|
+
}
|
|
25798
|
+
if (!name) {
|
|
25799
|
+
throw new Error(".collectionOf() requires a name");
|
|
25800
|
+
}
|
|
25801
|
+
if (!featureCollection || featureCollection.type !== "FeatureCollection") {
|
|
25802
|
+
throw new Error("Invalid input to " + name + ", FeatureCollection required");
|
|
25803
|
+
}
|
|
25804
|
+
for (var _i = 0, _a = featureCollection.features; _i < _a.length; _i++) {
|
|
25805
|
+
var feature = _a[_i];
|
|
25806
|
+
if (!feature || feature.type !== "Feature" || !feature.geometry) {
|
|
25807
|
+
throw new Error("Invalid input to " + name + ", Feature with geometry required");
|
|
25808
|
+
}
|
|
25809
|
+
if (!feature.geometry || feature.geometry.type !== type) {
|
|
25810
|
+
throw new Error("Invalid input to " +
|
|
25811
|
+
name +
|
|
25812
|
+
": must be a " +
|
|
25813
|
+
type +
|
|
25814
|
+
", given " +
|
|
25815
|
+
feature.geometry.type);
|
|
25816
|
+
}
|
|
25817
|
+
}
|
|
25818
|
+
}
|
|
25819
|
+
/**
|
|
25820
|
+
* Get Geometry from Feature or Geometry Object
|
|
25821
|
+
*
|
|
25822
|
+
* @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
|
|
25823
|
+
* @returns {Geometry|null} GeoJSON Geometry Object
|
|
25824
|
+
* @throws {Error} if geojson is not a Feature or Geometry Object
|
|
25825
|
+
* @example
|
|
25826
|
+
* var point = {
|
|
25827
|
+
* "type": "Feature",
|
|
25828
|
+
* "properties": {},
|
|
25829
|
+
* "geometry": {
|
|
25830
|
+
* "type": "Point",
|
|
25831
|
+
* "coordinates": [110, 40]
|
|
25832
|
+
* }
|
|
25833
|
+
* }
|
|
25834
|
+
* var geom = turf.getGeom(point)
|
|
25835
|
+
* //={"type": "Point", "coordinates": [110, 40]}
|
|
25836
|
+
*/
|
|
25837
|
+
function getGeom(geojson) {
|
|
25838
|
+
if (geojson.type === "Feature") {
|
|
25839
|
+
return geojson.geometry;
|
|
25840
|
+
}
|
|
25841
|
+
return geojson;
|
|
25842
|
+
}
|
|
25843
|
+
/**
|
|
25844
|
+
* Get GeoJSON object's type, Geometry type is prioritize.
|
|
25845
|
+
*
|
|
25846
|
+
* @param {GeoJSON} geojson GeoJSON object
|
|
25847
|
+
* @param {string} [name="geojson"] name of the variable to display in error message (unused)
|
|
25848
|
+
* @returns {string} GeoJSON type
|
|
25849
|
+
* @example
|
|
25850
|
+
* var point = {
|
|
25851
|
+
* "type": "Feature",
|
|
25852
|
+
* "properties": {},
|
|
25853
|
+
* "geometry": {
|
|
25854
|
+
* "type": "Point",
|
|
25855
|
+
* "coordinates": [110, 40]
|
|
25856
|
+
* }
|
|
25857
|
+
* }
|
|
25858
|
+
* var geom = turf.getType(point)
|
|
25859
|
+
* //="Point"
|
|
25860
|
+
*/
|
|
25861
|
+
function getType(geojson, _name) {
|
|
25862
|
+
if (geojson.type === "FeatureCollection") {
|
|
25863
|
+
return "FeatureCollection";
|
|
25864
|
+
}
|
|
25865
|
+
if (geojson.type === "GeometryCollection") {
|
|
25866
|
+
return "GeometryCollection";
|
|
25867
|
+
}
|
|
25868
|
+
if (geojson.type === "Feature" && geojson.geometry !== null) {
|
|
25869
|
+
return geojson.geometry.type;
|
|
25870
|
+
}
|
|
25871
|
+
return geojson.type;
|
|
25872
|
+
}
|
|
25873
|
+
|
|
25874
|
+
|
|
24846
25875
|
/***/ }),
|
|
24847
25876
|
|
|
24848
25877
|
/***/ "../../node_modules/base64-js/index.js":
|
|
@@ -28023,10 +29052,8 @@ function () {
|
|
|
28023
29052
|
_b.label = 1;
|
|
28024
29053
|
|
|
28025
29054
|
case 1:
|
|
28026
|
-
_b.trys.push([1, 3,, 4]);
|
|
28027
|
-
|
|
29055
|
+
_b.trys.push([1, 3,, 4]);
|
|
28028
29056
|
|
|
28029
|
-
Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateGeofences"])(geofenceInputArray);
|
|
28030
29057
|
return [4
|
|
28031
29058
|
/*yield*/
|
|
28032
29059
|
, prov.saveGeofences(geofenceInputArray, options)];
|
|
@@ -28069,10 +29096,8 @@ function () {
|
|
|
28069
29096
|
_b.label = 1;
|
|
28070
29097
|
|
|
28071
29098
|
case 1:
|
|
28072
|
-
_b.trys.push([1, 3,, 4]);
|
|
28073
|
-
|
|
29099
|
+
_b.trys.push([1, 3,, 4]);
|
|
28074
29100
|
|
|
28075
|
-
Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateGeofenceId"])(geofenceId);
|
|
28076
29101
|
return [4
|
|
28077
29102
|
/*yield*/
|
|
28078
29103
|
, prov.getGeofence(geofenceId, options)];
|
|
@@ -28152,7 +29177,7 @@ function () {
|
|
|
28152
29177
|
|
|
28153
29178
|
GeoClass.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
28154
29179
|
return __awaiter(this, void 0, void 0, function () {
|
|
28155
|
-
var _a, providerName, prov, geofenceIdsInputArray,
|
|
29180
|
+
var _a, providerName, prov, geofenceIdsInputArray, error_7;
|
|
28156
29181
|
|
|
28157
29182
|
return __generator(this, function (_b) {
|
|
28158
29183
|
switch (_b.label) {
|
|
@@ -28166,20 +29191,6 @@ function () {
|
|
|
28166
29191
|
geofenceIdsInputArray = geofenceIds;
|
|
28167
29192
|
}
|
|
28168
29193
|
|
|
28169
|
-
badGeofenceIds = geofenceIdsInputArray.filter(function (geofenceId) {
|
|
28170
|
-
try {
|
|
28171
|
-
Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateGeofenceId"])(geofenceId);
|
|
28172
|
-
} catch (error) {
|
|
28173
|
-
return false;
|
|
28174
|
-
}
|
|
28175
|
-
});
|
|
28176
|
-
|
|
28177
|
-
if (badGeofenceIds.length > 0) {
|
|
28178
|
-
errorString = "Invalid geofence ids: " + badGeofenceIds;
|
|
28179
|
-
logger.debug(errorString);
|
|
28180
|
-
throw new Error(errorString);
|
|
28181
|
-
}
|
|
28182
|
-
|
|
28183
29194
|
_b.label = 1;
|
|
28184
29195
|
|
|
28185
29196
|
case 1:
|
|
@@ -28233,6 +29244,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
28233
29244
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
|
|
28234
29245
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__);
|
|
28235
29246
|
/* harmony import */ var _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @aws-sdk/client-location */ "../../node_modules/@aws-sdk/client-location/dist-es/index.js");
|
|
29247
|
+
/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util */ "./lib-esm/util.js");
|
|
28236
29248
|
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
28237
29249
|
function adopt(value) {
|
|
28238
29250
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -28427,6 +29439,7 @@ var __spread = undefined && undefined.__spread || function () {
|
|
|
28427
29439
|
|
|
28428
29440
|
|
|
28429
29441
|
|
|
29442
|
+
|
|
28430
29443
|
var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AmazonLocationServiceProvider');
|
|
28431
29444
|
|
|
28432
29445
|
var AmazonLocationServiceProvider =
|
|
@@ -28810,7 +29823,8 @@ function () {
|
|
|
28810
29823
|
|
|
28811
29824
|
if (!credentialsOK) {
|
|
28812
29825
|
throw new Error('No credentials');
|
|
28813
|
-
}
|
|
29826
|
+
} // Verify geofence collection exists in aws-config.js
|
|
29827
|
+
|
|
28814
29828
|
|
|
28815
29829
|
try {
|
|
28816
29830
|
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
@@ -28819,6 +29833,7 @@ function () {
|
|
|
28819
29833
|
throw error;
|
|
28820
29834
|
}
|
|
28821
29835
|
|
|
29836
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofencesInput"])(geofences);
|
|
28822
29837
|
PascalGeofences = geofences.map(function (_a) {
|
|
28823
29838
|
var geofenceId = _a.geofenceId,
|
|
28824
29839
|
polygon = _a.geometry.polygon;
|
|
@@ -28953,6 +29968,7 @@ function () {
|
|
|
28953
29968
|
throw error;
|
|
28954
29969
|
}
|
|
28955
29970
|
|
|
29971
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofenceId"])(geofenceId);
|
|
28956
29972
|
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
28957
29973
|
credentials: this._config.credentials,
|
|
28958
29974
|
region: this._config.region,
|
|
@@ -29105,7 +30121,7 @@ function () {
|
|
|
29105
30121
|
|
|
29106
30122
|
AmazonLocationServiceProvider.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
29107
30123
|
return __awaiter(this, void 0, void 0, function () {
|
|
29108
|
-
var credentialsOK, results, batches, count;
|
|
30124
|
+
var credentialsOK, badGeofenceIds, results, batches, count;
|
|
29109
30125
|
|
|
29110
30126
|
var _this = this;
|
|
29111
30127
|
|
|
@@ -29121,14 +30137,20 @@ function () {
|
|
|
29121
30137
|
|
|
29122
30138
|
if (!credentialsOK) {
|
|
29123
30139
|
throw new Error('No credentials');
|
|
29124
|
-
}
|
|
30140
|
+
}
|
|
29125
30141
|
|
|
30142
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
29126
30143
|
|
|
29127
|
-
|
|
29128
|
-
|
|
29129
|
-
|
|
29130
|
-
|
|
29131
|
-
|
|
30144
|
+
badGeofenceIds = geofenceIds.filter(function (geofenceId) {
|
|
30145
|
+
try {
|
|
30146
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofenceId"])(geofenceId);
|
|
30147
|
+
} catch (error) {
|
|
30148
|
+
return true;
|
|
30149
|
+
}
|
|
30150
|
+
});
|
|
30151
|
+
|
|
30152
|
+
if (badGeofenceIds.length > 0) {
|
|
30153
|
+
throw new Error("Invalid geofence ids: " + badGeofenceIds.join(', '));
|
|
29132
30154
|
}
|
|
29133
30155
|
|
|
29134
30156
|
results = {
|
|
@@ -29402,7 +30424,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
29402
30424
|
/*!*************************!*\
|
|
29403
30425
|
!*** ./lib-esm/util.js ***!
|
|
29404
30426
|
\*************************/
|
|
29405
|
-
/*! exports provided: validateCoordinates, validateGeofenceId, validateLinearRing, validatePolygon,
|
|
30427
|
+
/*! exports provided: validateCoordinates, validateGeofenceId, validateLinearRing, validatePolygon, validateGeofencesInput */
|
|
29406
30428
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
29407
30429
|
|
|
29408
30430
|
"use strict";
|
|
@@ -29411,9 +30433,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
29411
30433
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofenceId", function() { return validateGeofenceId; });
|
|
29412
30434
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateLinearRing", function() { return validateLinearRing; });
|
|
29413
30435
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validatePolygon", function() { return validatePolygon; });
|
|
29414
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "
|
|
29415
|
-
/* harmony import */ var
|
|
29416
|
-
/* harmony import */ var
|
|
30436
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofencesInput", function() { return validateGeofencesInput; });
|
|
30437
|
+
/* harmony import */ var _turf_boolean_clockwise__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @turf/boolean-clockwise */ "../../node_modules/@turf/boolean-clockwise/dist/es/index.js");
|
|
30438
|
+
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
|
|
30439
|
+
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__);
|
|
29417
30440
|
var __read = undefined && undefined.__read || function (o, n) {
|
|
29418
30441
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29419
30442
|
if (!m) return o;
|
|
@@ -29455,37 +30478,30 @@ var __read = undefined && undefined.__read || function (o, n) {
|
|
|
29455
30478
|
|
|
29456
30479
|
|
|
29457
30480
|
|
|
29458
|
-
|
|
30481
|
+
|
|
30482
|
+
var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('Geo');
|
|
29459
30483
|
function validateCoordinates(lng, lat) {
|
|
29460
30484
|
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
29461
30485
|
throw new Error("Invalid coordinates: [" + lng + "," + lat + "]");
|
|
29462
30486
|
}
|
|
29463
30487
|
|
|
29464
30488
|
if (lat < -90 || lat > 90) {
|
|
29465
|
-
|
|
29466
|
-
logger.debug(errorString);
|
|
29467
|
-
throw new Error(errorString);
|
|
30489
|
+
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
29468
30490
|
} else if (lng < -180 || lng > 180) {
|
|
29469
|
-
|
|
29470
|
-
logger.debug(errorString);
|
|
29471
|
-
throw new Error(errorString);
|
|
30491
|
+
throw new Error('Longitude must be between -180 and 180 degrees inclusive.');
|
|
29472
30492
|
}
|
|
29473
30493
|
}
|
|
29474
30494
|
function validateGeofenceId(geofenceId) {
|
|
29475
30495
|
var geofenceIdRegex = /^(?:[\x2D\.0-9A-Z_a-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u0660-\u0669\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0966-\u096F\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09F9\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AE6-\u0AEF\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F\u0B71-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0BE6-\u0BF2\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C66-\u0C6F\u0C78-\u0C7E\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D58-\u0D61\u0D66-\u0D78\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DE6-\u0DEF\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F20-\u0F33\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F-\u1049\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u1090-\u1099\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u17E0-\u17E9\u17F0-\u17F9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A20-\u1A54\u1A80-\u1A89\u1A90-\u1A99\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B50-\u1B59\u1B83-\u1BA0\u1BAE-\u1BE5\u1C00-\u1C23\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA830-\uA835\uA840-\uA873\uA882-\uA8B3\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA900-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF-\uA9D9\uA9E0-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDE80-\uDE9C\uDEA0-\uDED0\uDEE1-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE40-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE4\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD23\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF27\uDF30-\uDF45\uDF51-\uDF54\uDF70-\uDF81\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC52-\uDC6F\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD03-\uDD26\uDD36-\uDD3F\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDD0-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDEF0-\uDEF9\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC50-\uDC59\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE50-\uDE59\uDE80-\uDEAA\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF30-\uDF3B\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF2\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDE70-\uDEBE\uDEC0-\uDEC9\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD834[\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD837[\uDF00-\uDF1E]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD40-\uDD49\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB\uDEF0-\uDEF9]|\uD839[\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCCF\uDD00-\uDD43\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF38\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A])+$/i; // Check if geofenceId is valid
|
|
29476
30496
|
|
|
29477
30497
|
if (!geofenceIdRegex.test(geofenceId)) {
|
|
29478
|
-
|
|
29479
|
-
logger.debug(errorString);
|
|
29480
|
-
throw new Error(errorString);
|
|
30498
|
+
throw new Error("Invalid geofenceId: '" + geofenceId + "' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.");
|
|
29481
30499
|
}
|
|
29482
30500
|
}
|
|
29483
|
-
function validateLinearRing(linearRing) {
|
|
30501
|
+
function validateLinearRing(linearRing, geofenceId) {
|
|
29484
30502
|
// Validate LinearRing size, must be at least 4 points
|
|
29485
30503
|
if (linearRing.length < 4) {
|
|
29486
|
-
|
|
29487
|
-
logger.debug(errorString);
|
|
29488
|
-
throw new Error(errorString);
|
|
30504
|
+
throw new Error(geofenceId + ": LinearRing must contain 4 or more coordinates.");
|
|
29489
30505
|
} // Validate all coordinates are valid, error with which ones are bad
|
|
29490
30506
|
|
|
29491
30507
|
|
|
@@ -29502,9 +30518,7 @@ function validateLinearRing(linearRing) {
|
|
|
29502
30518
|
});
|
|
29503
30519
|
|
|
29504
30520
|
if (badCoordinates.length > 0) {
|
|
29505
|
-
|
|
29506
|
-
logger.debug(errorString);
|
|
29507
|
-
throw new Error(errorString);
|
|
30521
|
+
throw new Error(geofenceId + ": One or more of the coordinates in the Polygon LinearRing are not valid: " + JSON.stringify(badCoordinates));
|
|
29508
30522
|
} // Validate first and last coordinates are the same
|
|
29509
30523
|
|
|
29510
30524
|
|
|
@@ -29517,22 +30531,24 @@ function validateLinearRing(linearRing) {
|
|
|
29517
30531
|
latB = _b[1];
|
|
29518
30532
|
|
|
29519
30533
|
if (lngA !== lngB || latA !== latB) {
|
|
29520
|
-
|
|
29521
|
-
|
|
29522
|
-
|
|
30534
|
+
throw new Error(geofenceId + ": LinearRing's first and last coordinates are not the same");
|
|
30535
|
+
}
|
|
30536
|
+
|
|
30537
|
+
if (Object(_turf_boolean_clockwise__WEBPACK_IMPORTED_MODULE_0__["default"])(linearRing)) {
|
|
30538
|
+
throw new Error(geofenceId + ": LinearRing coordinates must be wound counterclockwise");
|
|
29523
30539
|
}
|
|
29524
30540
|
}
|
|
29525
|
-
function validatePolygon(polygon) {
|
|
30541
|
+
function validatePolygon(polygon, geofenceId) {
|
|
29526
30542
|
if (!Array.isArray(polygon)) {
|
|
29527
|
-
|
|
29528
|
-
logger.debug(errorString);
|
|
29529
|
-
throw new Error(errorString);
|
|
30543
|
+
throw new Error(geofenceId + ": Polygon is of incorrect structure. It should be an array of LinearRings");
|
|
29530
30544
|
}
|
|
29531
30545
|
|
|
29532
|
-
if (
|
|
29533
|
-
|
|
29534
|
-
|
|
29535
|
-
|
|
30546
|
+
if (polygon.length < 1) {
|
|
30547
|
+
throw new Error(geofenceId + ": Polygon must have a single LinearRing array.");
|
|
30548
|
+
}
|
|
30549
|
+
|
|
30550
|
+
if (polygon.length > 1) {
|
|
30551
|
+
throw new Error(geofenceId + ": Polygon must have a single LinearRing array. Note: We do not currently support polygons with holes, multipolygons, polygons that are wound clockwise, or that cross the antimeridian.");
|
|
29536
30552
|
}
|
|
29537
30553
|
|
|
29538
30554
|
var verticesCount = polygon.reduce(function (prev, linearRing) {
|
|
@@ -29540,59 +30556,45 @@ function validatePolygon(polygon) {
|
|
|
29540
30556
|
}, 0);
|
|
29541
30557
|
|
|
29542
30558
|
if (verticesCount > 1000) {
|
|
29543
|
-
|
|
29544
|
-
logger.debug(errorString);
|
|
29545
|
-
throw new Error(errorString);
|
|
30559
|
+
throw new Error(geofenceId + ": Polygon has more than the maximum 1000 vertices.");
|
|
29546
30560
|
}
|
|
29547
30561
|
}
|
|
29548
|
-
function
|
|
30562
|
+
function validateGeofencesInput(geofences) {
|
|
29549
30563
|
var geofenceIds = {};
|
|
29550
30564
|
geofences.forEach(function (geofence) {
|
|
29551
30565
|
// verify all required properties are present
|
|
30566
|
+
// Validate geofenceId exists
|
|
29552
30567
|
if (!geofence.geofenceId) {
|
|
29553
|
-
|
|
29554
|
-
logger.debug(errorString);
|
|
29555
|
-
throw new Error(errorString);
|
|
30568
|
+
throw new Error("Geofence '" + geofence + "' is missing geofenceId");
|
|
29556
30569
|
}
|
|
29557
30570
|
|
|
29558
|
-
|
|
29559
|
-
|
|
29560
|
-
logger.debug(errorString);
|
|
29561
|
-
throw new Error(errorString);
|
|
29562
|
-
}
|
|
30571
|
+
var geofenceId = geofence.geofenceId;
|
|
30572
|
+
validateGeofenceId(geofenceId); // Validate geofenceId is unique
|
|
29563
30573
|
|
|
29564
|
-
if (
|
|
29565
|
-
|
|
29566
|
-
|
|
29567
|
-
|
|
29568
|
-
}
|
|
30574
|
+
if (geofenceIds[geofenceId]) {
|
|
30575
|
+
throw new Error("Duplicate geofenceId: " + geofenceId);
|
|
30576
|
+
} else {
|
|
30577
|
+
geofenceIds[geofenceId] = true;
|
|
30578
|
+
} // Validate geometry exists
|
|
29569
30579
|
|
|
29570
|
-
var geofenceId = geofence.geofenceId,
|
|
29571
|
-
polygon = geofence.geometry.polygon; // Validate geofenceId is valid
|
|
29572
30580
|
|
|
29573
|
-
|
|
29574
|
-
|
|
29575
|
-
}
|
|
29576
|
-
throw error;
|
|
29577
|
-
} // Validate geofenceId is unique
|
|
30581
|
+
if (!geofence.geometry) {
|
|
30582
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry");
|
|
30583
|
+
}
|
|
29578
30584
|
|
|
30585
|
+
var geometry = geofence.geometry; // Validate polygon exists
|
|
29579
30586
|
|
|
29580
|
-
if (
|
|
29581
|
-
|
|
29582
|
-
|
|
29583
|
-
throw new Error(errorString);
|
|
29584
|
-
} else {
|
|
29585
|
-
geofenceIds[geofenceId] = true;
|
|
29586
|
-
} // Validate polygon length and structure
|
|
30587
|
+
if (!geometry.polygon) {
|
|
30588
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry.polygon");
|
|
30589
|
+
}
|
|
29587
30590
|
|
|
30591
|
+
var polygon = geometry.polygon; // Validate polygon length and structure
|
|
29588
30592
|
|
|
29589
30593
|
try {
|
|
29590
|
-
validatePolygon(polygon);
|
|
30594
|
+
validatePolygon(polygon, geofenceId);
|
|
29591
30595
|
} catch (error) {
|
|
29592
30596
|
if (error.message === "Polygon has more than the maximum 1000 vertices.") {
|
|
29593
|
-
|
|
29594
|
-
logger.debug(errorString);
|
|
29595
|
-
throw new Error(errorString);
|
|
30597
|
+
throw new Error("Geofence '" + geofenceId + "' has more than the maximum of 1000 vertices");
|
|
29596
30598
|
}
|
|
29597
30599
|
} // Validate LinearRing length, structure, and coordinates
|
|
29598
30600
|
|
|
@@ -29600,7 +30602,7 @@ function validateGeofences(geofences) {
|
|
|
29600
30602
|
var _a = __read(polygon, 1),
|
|
29601
30603
|
linearRing = _a[0];
|
|
29602
30604
|
|
|
29603
|
-
validateLinearRing(linearRing);
|
|
30605
|
+
validateLinearRing(linearRing, geofenceId);
|
|
29604
30606
|
});
|
|
29605
30607
|
}
|
|
29606
30608
|
|