@aws-amplify/geo 1.2.4 → 1.2.5-geo.11
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 +2020 -137
- package/dist/aws-amplify-geo.js.map +1 -1
- package/dist/aws-amplify-geo.min.js +6 -6
- package/dist/aws-amplify-geo.min.js.map +1 -1
- package/lib/Geo.d.ts +36 -10
- package/lib/Geo.js +140 -20
- package/lib/Geo.js.map +1 -1
- package/lib/Providers/AmazonLocationServiceProvider.d.ts +37 -8
- package/lib/Providers/AmazonLocationServiceProvider.js +405 -53
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/types/AmazonLocationServiceProvider.d.ts +21 -1
- package/lib/types/Geo.d.ts +48 -2
- package/lib/types/Provider.d.ts +5 -2
- package/lib/types/Provider.js +0 -12
- package/lib/types/Provider.js.map +1 -1
- package/lib/util.d.ts +6 -0
- package/lib/util.js +144 -0
- package/lib/util.js.map +1 -0
- package/lib-esm/Geo.d.ts +36 -10
- package/lib-esm/Geo.js +140 -20
- package/lib-esm/Geo.js.map +1 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +37 -8
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +406 -54
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib-esm/types/AmazonLocationServiceProvider.d.ts +21 -1
- package/lib-esm/types/Geo.d.ts +48 -2
- package/lib-esm/types/Provider.d.ts +5 -2
- package/lib-esm/types/Provider.js +0 -12
- package/lib-esm/types/Provider.js.map +1 -1
- package/lib-esm/util.d.ts +6 -0
- package/lib-esm/util.js +134 -0
- package/lib-esm/util.js.map +1 -0
- package/package.json +6 -4
- package/src/Geo.ts +118 -20
- package/src/Providers/AmazonLocationServiceProvider.ts +422 -75
- package/src/types/AmazonLocationServiceProvider.ts +56 -1
- package/src/types/Geo.ts +71 -4
- package/src/types/Provider.ts +29 -6
- package/src/util.ts +173 -0
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":
|
|
@@ -27556,6 +28585,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
27556
28585
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
|
|
27557
28586
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
|
|
27558
28587
|
/* harmony import */ var _Providers_AmazonLocationServiceProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Providers/AmazonLocationServiceProvider */ "./lib-esm/Providers/AmazonLocationServiceProvider.js");
|
|
28588
|
+
/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./util */ "./lib-esm/util.js");
|
|
27559
28589
|
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
27560
28590
|
function adopt(value) {
|
|
27561
28591
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -27698,6 +28728,33 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
27698
28728
|
};
|
|
27699
28729
|
}
|
|
27700
28730
|
};
|
|
28731
|
+
|
|
28732
|
+
var __read = undefined && undefined.__read || function (o, n) {
|
|
28733
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
28734
|
+
if (!m) return o;
|
|
28735
|
+
var i = m.call(o),
|
|
28736
|
+
r,
|
|
28737
|
+
ar = [],
|
|
28738
|
+
e;
|
|
28739
|
+
|
|
28740
|
+
try {
|
|
28741
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
28742
|
+
ar.push(r.value);
|
|
28743
|
+
}
|
|
28744
|
+
} catch (error) {
|
|
28745
|
+
e = {
|
|
28746
|
+
error: error
|
|
28747
|
+
};
|
|
28748
|
+
} finally {
|
|
28749
|
+
try {
|
|
28750
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28751
|
+
} finally {
|
|
28752
|
+
if (e) throw e.error;
|
|
28753
|
+
}
|
|
28754
|
+
}
|
|
28755
|
+
|
|
28756
|
+
return ar;
|
|
28757
|
+
};
|
|
27701
28758
|
/*
|
|
27702
28759
|
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
27703
28760
|
*
|
|
@@ -27714,6 +28771,7 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
27714
28771
|
|
|
27715
28772
|
|
|
27716
28773
|
|
|
28774
|
+
|
|
27717
28775
|
var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["ConsoleLogger"]('Geo');
|
|
27718
28776
|
var DEFAULT_PROVIDER = 'AmazonLocationService';
|
|
27719
28777
|
|
|
@@ -27813,35 +28871,178 @@ function () {
|
|
|
27813
28871
|
provider = DEFAULT_PROVIDER;
|
|
27814
28872
|
}
|
|
27815
28873
|
|
|
27816
|
-
var prov = this.getPluggable(provider);
|
|
27817
|
-
return prov.getAvailableMaps();
|
|
27818
|
-
};
|
|
27819
|
-
/**
|
|
27820
|
-
* Get the map resource set as default in amplify config
|
|
27821
|
-
* @param {string} provider
|
|
27822
|
-
* @returns - Map resource set as the default in amplify config
|
|
27823
|
-
*/
|
|
28874
|
+
var prov = this.getPluggable(provider);
|
|
28875
|
+
return prov.getAvailableMaps();
|
|
28876
|
+
};
|
|
28877
|
+
/**
|
|
28878
|
+
* Get the map resource set as default in amplify config
|
|
28879
|
+
* @param {string} provider
|
|
28880
|
+
* @returns - Map resource set as the default in amplify config
|
|
28881
|
+
*/
|
|
28882
|
+
|
|
28883
|
+
|
|
28884
|
+
GeoClass.prototype.getDefaultMap = function (provider) {
|
|
28885
|
+
if (provider === void 0) {
|
|
28886
|
+
provider = DEFAULT_PROVIDER;
|
|
28887
|
+
}
|
|
28888
|
+
|
|
28889
|
+
var prov = this.getPluggable(provider);
|
|
28890
|
+
return prov.getDefaultMap();
|
|
28891
|
+
};
|
|
28892
|
+
/**
|
|
28893
|
+
* Search by text input with optional parameters
|
|
28894
|
+
* @param {string} text - The text string that is to be searched for
|
|
28895
|
+
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
28896
|
+
* @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters
|
|
28897
|
+
*/
|
|
28898
|
+
|
|
28899
|
+
|
|
28900
|
+
GeoClass.prototype.searchByText = function (text, options) {
|
|
28901
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
28902
|
+
var _a, providerName, prov, error_1;
|
|
28903
|
+
|
|
28904
|
+
return __generator(this, function (_b) {
|
|
28905
|
+
switch (_b.label) {
|
|
28906
|
+
case 0:
|
|
28907
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
28908
|
+
prov = this.getPluggable(providerName);
|
|
28909
|
+
_b.label = 1;
|
|
28910
|
+
|
|
28911
|
+
case 1:
|
|
28912
|
+
_b.trys.push([1, 3,, 4]);
|
|
28913
|
+
|
|
28914
|
+
return [4
|
|
28915
|
+
/*yield*/
|
|
28916
|
+
, prov.searchByText(text, options)];
|
|
28917
|
+
|
|
28918
|
+
case 2:
|
|
28919
|
+
return [2
|
|
28920
|
+
/*return*/
|
|
28921
|
+
, _b.sent()];
|
|
28922
|
+
|
|
28923
|
+
case 3:
|
|
28924
|
+
error_1 = _b.sent();
|
|
28925
|
+
logger.debug(error_1);
|
|
28926
|
+
throw error_1;
|
|
28927
|
+
|
|
28928
|
+
case 4:
|
|
28929
|
+
return [2
|
|
28930
|
+
/*return*/
|
|
28931
|
+
];
|
|
28932
|
+
}
|
|
28933
|
+
});
|
|
28934
|
+
});
|
|
28935
|
+
};
|
|
28936
|
+
/**
|
|
28937
|
+
* Reverse geocoding search via a coordinate point on the map
|
|
28938
|
+
* @param coordinates - Coordinates array for the search input
|
|
28939
|
+
* @param options - Options parameters for the search
|
|
28940
|
+
* @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates
|
|
28941
|
+
*/
|
|
28942
|
+
|
|
28943
|
+
|
|
28944
|
+
GeoClass.prototype.searchByCoordinates = function (coordinates, options) {
|
|
28945
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
28946
|
+
var _a, providerName, prov, _b, lng, lat, error_2;
|
|
28947
|
+
|
|
28948
|
+
return __generator(this, function (_c) {
|
|
28949
|
+
switch (_c.label) {
|
|
28950
|
+
case 0:
|
|
28951
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
28952
|
+
prov = this.getPluggable(providerName);
|
|
28953
|
+
_b = __read(coordinates, 2), lng = _b[0], lat = _b[1];
|
|
28954
|
+
_c.label = 1;
|
|
28955
|
+
|
|
28956
|
+
case 1:
|
|
28957
|
+
_c.trys.push([1, 3,, 4]);
|
|
28958
|
+
|
|
28959
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateCoordinates"])(lng, lat);
|
|
28960
|
+
return [4
|
|
28961
|
+
/*yield*/
|
|
28962
|
+
, prov.searchByCoordinates(coordinates, options)];
|
|
28963
|
+
|
|
28964
|
+
case 2:
|
|
28965
|
+
return [2
|
|
28966
|
+
/*return*/
|
|
28967
|
+
, _c.sent()];
|
|
28968
|
+
|
|
28969
|
+
case 3:
|
|
28970
|
+
error_2 = _c.sent();
|
|
28971
|
+
logger.debug(error_2);
|
|
28972
|
+
throw error_2;
|
|
28973
|
+
|
|
28974
|
+
case 4:
|
|
28975
|
+
return [2
|
|
28976
|
+
/*return*/
|
|
28977
|
+
];
|
|
28978
|
+
}
|
|
28979
|
+
});
|
|
28980
|
+
});
|
|
28981
|
+
};
|
|
28982
|
+
/**
|
|
28983
|
+
* Create geofences
|
|
28984
|
+
* @param geofences - Single or array of geofence objects to create
|
|
28985
|
+
* @param options? - Optional parameters for creating geofences
|
|
28986
|
+
* @returns {Promise<SaveGeofencesResults>} - Promise that resolves to an object with:
|
|
28987
|
+
* successes: list of geofences successfully created
|
|
28988
|
+
* errors: list of geofences that failed to create
|
|
28989
|
+
*/
|
|
28990
|
+
|
|
28991
|
+
|
|
28992
|
+
GeoClass.prototype.saveGeofences = function (geofences, options) {
|
|
28993
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
28994
|
+
var _a, providerName, prov, geofenceInputArray, error_3;
|
|
28995
|
+
|
|
28996
|
+
return __generator(this, function (_b) {
|
|
28997
|
+
switch (_b.label) {
|
|
28998
|
+
case 0:
|
|
28999
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
29000
|
+
prov = this.getPluggable(providerName);
|
|
29001
|
+
|
|
29002
|
+
if (!Array.isArray(geofences)) {
|
|
29003
|
+
geofenceInputArray = [geofences];
|
|
29004
|
+
} else {
|
|
29005
|
+
geofenceInputArray = geofences;
|
|
29006
|
+
}
|
|
29007
|
+
|
|
29008
|
+
_b.label = 1;
|
|
29009
|
+
|
|
29010
|
+
case 1:
|
|
29011
|
+
_b.trys.push([1, 3,, 4]);
|
|
29012
|
+
|
|
29013
|
+
return [4
|
|
29014
|
+
/*yield*/
|
|
29015
|
+
, prov.saveGeofences(geofenceInputArray, options)];
|
|
27824
29016
|
|
|
29017
|
+
case 2:
|
|
29018
|
+
return [2
|
|
29019
|
+
/*return*/
|
|
29020
|
+
, _b.sent()];
|
|
27825
29021
|
|
|
27826
|
-
|
|
27827
|
-
|
|
27828
|
-
|
|
27829
|
-
|
|
29022
|
+
case 3:
|
|
29023
|
+
error_3 = _b.sent();
|
|
29024
|
+
logger.debug(error_3);
|
|
29025
|
+
throw error_3;
|
|
27830
29026
|
|
|
27831
|
-
|
|
27832
|
-
|
|
29027
|
+
case 4:
|
|
29028
|
+
return [2
|
|
29029
|
+
/*return*/
|
|
29030
|
+
];
|
|
29031
|
+
}
|
|
29032
|
+
});
|
|
29033
|
+
});
|
|
27833
29034
|
};
|
|
27834
29035
|
/**
|
|
27835
|
-
*
|
|
27836
|
-
* @param
|
|
27837
|
-
* @param
|
|
27838
|
-
* @returns
|
|
29036
|
+
* Get a single geofence by geofenceId
|
|
29037
|
+
* @param geofenceId: string
|
|
29038
|
+
* @param options?: GeofenceOptions
|
|
29039
|
+
* @returns Promise<Geofence> - Promise that resolves to a geofence object
|
|
27839
29040
|
*/
|
|
27840
29041
|
|
|
27841
29042
|
|
|
27842
|
-
GeoClass.prototype.
|
|
29043
|
+
GeoClass.prototype.getGeofence = function (geofenceId, options) {
|
|
27843
29044
|
return __awaiter(this, void 0, void 0, function () {
|
|
27844
|
-
var _a, providerName, prov,
|
|
29045
|
+
var _a, providerName, prov, error_4;
|
|
27845
29046
|
|
|
27846
29047
|
return __generator(this, function (_b) {
|
|
27847
29048
|
switch (_b.label) {
|
|
@@ -27855,7 +29056,7 @@ function () {
|
|
|
27855
29056
|
|
|
27856
29057
|
return [4
|
|
27857
29058
|
/*yield*/
|
|
27858
|
-
, prov.
|
|
29059
|
+
, prov.getGeofence(geofenceId, options)];
|
|
27859
29060
|
|
|
27860
29061
|
case 2:
|
|
27861
29062
|
return [2
|
|
@@ -27863,9 +29064,9 @@ function () {
|
|
|
27863
29064
|
, _b.sent()];
|
|
27864
29065
|
|
|
27865
29066
|
case 3:
|
|
27866
|
-
|
|
27867
|
-
logger.debug(
|
|
27868
|
-
throw
|
|
29067
|
+
error_4 = _b.sent();
|
|
29068
|
+
logger.debug(error_4);
|
|
29069
|
+
throw error_4;
|
|
27869
29070
|
|
|
27870
29071
|
case 4:
|
|
27871
29072
|
return [2
|
|
@@ -27876,16 +29077,17 @@ function () {
|
|
|
27876
29077
|
});
|
|
27877
29078
|
};
|
|
27878
29079
|
/**
|
|
27879
|
-
*
|
|
27880
|
-
* @param
|
|
27881
|
-
* @
|
|
27882
|
-
*
|
|
29080
|
+
* List geofences
|
|
29081
|
+
* @param options?: ListGeofenceOptions
|
|
29082
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
29083
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
29084
|
+
* nextToken: token for next page of geofences
|
|
27883
29085
|
*/
|
|
27884
29086
|
|
|
27885
29087
|
|
|
27886
|
-
GeoClass.prototype.
|
|
29088
|
+
GeoClass.prototype.listGeofences = function (options) {
|
|
27887
29089
|
return __awaiter(this, void 0, void 0, function () {
|
|
27888
|
-
var _a, providerName, prov,
|
|
29090
|
+
var _a, providerName, prov, error_5;
|
|
27889
29091
|
|
|
27890
29092
|
return __generator(this, function (_b) {
|
|
27891
29093
|
switch (_b.label) {
|
|
@@ -27899,7 +29101,7 @@ function () {
|
|
|
27899
29101
|
|
|
27900
29102
|
return [4
|
|
27901
29103
|
/*yield*/
|
|
27902
|
-
, prov.
|
|
29104
|
+
, prov.listGeofences(options)];
|
|
27903
29105
|
|
|
27904
29106
|
case 2:
|
|
27905
29107
|
return [2
|
|
@@ -27907,9 +29109,9 @@ function () {
|
|
|
27907
29109
|
, _b.sent()];
|
|
27908
29110
|
|
|
27909
29111
|
case 3:
|
|
27910
|
-
|
|
27911
|
-
logger.debug(
|
|
27912
|
-
throw
|
|
29112
|
+
error_5 = _b.sent();
|
|
29113
|
+
logger.debug(error_5);
|
|
29114
|
+
throw error_5;
|
|
27913
29115
|
|
|
27914
29116
|
case 4:
|
|
27915
29117
|
return [2
|
|
@@ -27920,22 +29122,31 @@ function () {
|
|
|
27920
29122
|
});
|
|
27921
29123
|
};
|
|
27922
29124
|
/**
|
|
27923
|
-
*
|
|
27924
|
-
* @param
|
|
27925
|
-
* @param options
|
|
27926
|
-
* @returns {Promise<
|
|
29125
|
+
* Delete geofences
|
|
29126
|
+
* @param geofenceIds: string|string[]
|
|
29127
|
+
* @param options?: GeofenceOptions
|
|
29128
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
29129
|
+
* successes: list of geofences successfully deleted
|
|
29130
|
+
* errors: list of geofences that failed to delete
|
|
27927
29131
|
*/
|
|
27928
29132
|
|
|
27929
29133
|
|
|
27930
|
-
GeoClass.prototype.
|
|
29134
|
+
GeoClass.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
27931
29135
|
return __awaiter(this, void 0, void 0, function () {
|
|
27932
|
-
var _a, providerName, prov,
|
|
29136
|
+
var _a, providerName, prov, geofenceIdsInputArray, error_6;
|
|
27933
29137
|
|
|
27934
29138
|
return __generator(this, function (_b) {
|
|
27935
29139
|
switch (_b.label) {
|
|
27936
29140
|
case 0:
|
|
27937
29141
|
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
27938
29142
|
prov = this.getPluggable(providerName);
|
|
29143
|
+
|
|
29144
|
+
if (!Array.isArray(geofenceIds)) {
|
|
29145
|
+
geofenceIdsInputArray = [geofenceIds];
|
|
29146
|
+
} else {
|
|
29147
|
+
geofenceIdsInputArray = geofenceIds;
|
|
29148
|
+
}
|
|
29149
|
+
|
|
27939
29150
|
_b.label = 1;
|
|
27940
29151
|
|
|
27941
29152
|
case 1:
|
|
@@ -27943,7 +29154,7 @@ function () {
|
|
|
27943
29154
|
|
|
27944
29155
|
return [4
|
|
27945
29156
|
/*yield*/
|
|
27946
|
-
, prov.
|
|
29157
|
+
, prov.deleteGeofences(geofenceIdsInputArray, options)];
|
|
27947
29158
|
|
|
27948
29159
|
case 2:
|
|
27949
29160
|
return [2
|
|
@@ -27951,9 +29162,9 @@ function () {
|
|
|
27951
29162
|
, _b.sent()];
|
|
27952
29163
|
|
|
27953
29164
|
case 3:
|
|
27954
|
-
|
|
27955
|
-
logger.debug(
|
|
27956
|
-
throw
|
|
29165
|
+
error_6 = _b.sent();
|
|
29166
|
+
logger.debug(error_6);
|
|
29167
|
+
throw error_6;
|
|
27957
29168
|
|
|
27958
29169
|
case 4:
|
|
27959
29170
|
return [2
|
|
@@ -27989,6 +29200,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
27989
29200
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
|
|
27990
29201
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__);
|
|
27991
29202
|
/* 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");
|
|
29203
|
+
/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util */ "./lib-esm/util.js");
|
|
27992
29204
|
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
27993
29205
|
function adopt(value) {
|
|
27994
29206
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -28131,6 +29343,41 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
28131
29343
|
};
|
|
28132
29344
|
}
|
|
28133
29345
|
};
|
|
29346
|
+
|
|
29347
|
+
var __read = undefined && undefined.__read || function (o, n) {
|
|
29348
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29349
|
+
if (!m) return o;
|
|
29350
|
+
var i = m.call(o),
|
|
29351
|
+
r,
|
|
29352
|
+
ar = [],
|
|
29353
|
+
e;
|
|
29354
|
+
|
|
29355
|
+
try {
|
|
29356
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
29357
|
+
ar.push(r.value);
|
|
29358
|
+
}
|
|
29359
|
+
} catch (error) {
|
|
29360
|
+
e = {
|
|
29361
|
+
error: error
|
|
29362
|
+
};
|
|
29363
|
+
} finally {
|
|
29364
|
+
try {
|
|
29365
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
29366
|
+
} finally {
|
|
29367
|
+
if (e) throw e.error;
|
|
29368
|
+
}
|
|
29369
|
+
}
|
|
29370
|
+
|
|
29371
|
+
return ar;
|
|
29372
|
+
};
|
|
29373
|
+
|
|
29374
|
+
var __spread = undefined && undefined.__spread || function () {
|
|
29375
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
29376
|
+
ar = ar.concat(__read(arguments[i]));
|
|
29377
|
+
}
|
|
29378
|
+
|
|
29379
|
+
return ar;
|
|
29380
|
+
};
|
|
28134
29381
|
/*
|
|
28135
29382
|
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
28136
29383
|
*
|
|
@@ -28148,6 +29395,7 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
28148
29395
|
|
|
28149
29396
|
|
|
28150
29397
|
|
|
29398
|
+
|
|
28151
29399
|
var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AmazonLocationServiceProvider');
|
|
28152
29400
|
|
|
28153
29401
|
var AmazonLocationServiceProvider =
|
|
@@ -28325,22 +29573,329 @@ function () {
|
|
|
28325
29573
|
});
|
|
28326
29574
|
return [2
|
|
28327
29575
|
/*return*/
|
|
28328
|
-
, results];
|
|
29576
|
+
, results];
|
|
29577
|
+
}
|
|
29578
|
+
});
|
|
29579
|
+
});
|
|
29580
|
+
};
|
|
29581
|
+
/**
|
|
29582
|
+
* Reverse geocoding search via a coordinate point on the map
|
|
29583
|
+
* @param coordinates - Coordinates array for the search input
|
|
29584
|
+
* @param options - Options parameters for the search
|
|
29585
|
+
* @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates
|
|
29586
|
+
*/
|
|
29587
|
+
|
|
29588
|
+
|
|
29589
|
+
AmazonLocationServiceProvider.prototype.searchByCoordinates = function (coordinates, options) {
|
|
29590
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29591
|
+
var credentialsOK, locationServiceInput, client, command, response, error_2, PascalResults, results;
|
|
29592
|
+
return __generator(this, function (_a) {
|
|
29593
|
+
switch (_a.label) {
|
|
29594
|
+
case 0:
|
|
29595
|
+
return [4
|
|
29596
|
+
/*yield*/
|
|
29597
|
+
, this._ensureCredentials()];
|
|
29598
|
+
|
|
29599
|
+
case 1:
|
|
29600
|
+
credentialsOK = _a.sent();
|
|
29601
|
+
|
|
29602
|
+
if (!credentialsOK) {
|
|
29603
|
+
throw new Error('No credentials');
|
|
29604
|
+
}
|
|
29605
|
+
|
|
29606
|
+
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
29607
|
+
|
|
29608
|
+
locationServiceInput = {
|
|
29609
|
+
Position: coordinates,
|
|
29610
|
+
IndexName: this._config.search_indices["default"]
|
|
29611
|
+
};
|
|
29612
|
+
|
|
29613
|
+
if (options) {
|
|
29614
|
+
if (options.searchIndexName) {
|
|
29615
|
+
locationServiceInput.IndexName = options.searchIndexName;
|
|
29616
|
+
}
|
|
29617
|
+
|
|
29618
|
+
locationServiceInput.MaxResults = options.maxResults;
|
|
29619
|
+
}
|
|
29620
|
+
|
|
29621
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
29622
|
+
credentials: this._config.credentials,
|
|
29623
|
+
region: this._config.region,
|
|
29624
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
29625
|
+
});
|
|
29626
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["SearchPlaceIndexForPositionCommand"](locationServiceInput);
|
|
29627
|
+
_a.label = 2;
|
|
29628
|
+
|
|
29629
|
+
case 2:
|
|
29630
|
+
_a.trys.push([2, 4,, 5]);
|
|
29631
|
+
|
|
29632
|
+
return [4
|
|
29633
|
+
/*yield*/
|
|
29634
|
+
, client.send(command)];
|
|
29635
|
+
|
|
29636
|
+
case 3:
|
|
29637
|
+
response = _a.sent();
|
|
29638
|
+
return [3
|
|
29639
|
+
/*break*/
|
|
29640
|
+
, 5];
|
|
29641
|
+
|
|
29642
|
+
case 4:
|
|
29643
|
+
error_2 = _a.sent();
|
|
29644
|
+
logger.debug(error_2);
|
|
29645
|
+
throw error_2;
|
|
29646
|
+
|
|
29647
|
+
case 5:
|
|
29648
|
+
PascalResults = response.Results.map(function (result) {
|
|
29649
|
+
return result.Place;
|
|
29650
|
+
});
|
|
29651
|
+
results = camelcase_keys__WEBPACK_IMPORTED_MODULE_0___default()(PascalResults[0], {
|
|
29652
|
+
deep: true
|
|
29653
|
+
});
|
|
29654
|
+
return [2
|
|
29655
|
+
/*return*/
|
|
29656
|
+
, results];
|
|
29657
|
+
}
|
|
29658
|
+
});
|
|
29659
|
+
});
|
|
29660
|
+
};
|
|
29661
|
+
/**
|
|
29662
|
+
* Create geofences inside of a geofence collection
|
|
29663
|
+
* @param geofences - Array of geofence objects to create
|
|
29664
|
+
* @param options? - Optional parameters for creating geofences
|
|
29665
|
+
* @returns {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
|
|
29666
|
+
* successes: list of geofences successfully created
|
|
29667
|
+
* errors: list of geofences that failed to create
|
|
29668
|
+
*/
|
|
29669
|
+
|
|
29670
|
+
|
|
29671
|
+
AmazonLocationServiceProvider.prototype.saveGeofences = function (geofences, options) {
|
|
29672
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29673
|
+
var credentialsOK, PascalGeofences, results, batches, apiLimit;
|
|
29674
|
+
|
|
29675
|
+
var _this = this;
|
|
29676
|
+
|
|
29677
|
+
return __generator(this, function (_a) {
|
|
29678
|
+
switch (_a.label) {
|
|
29679
|
+
case 0:
|
|
29680
|
+
if (geofences.length < 1) {
|
|
29681
|
+
throw new Error('Geofence input array is empty');
|
|
29682
|
+
}
|
|
29683
|
+
|
|
29684
|
+
return [4
|
|
29685
|
+
/*yield*/
|
|
29686
|
+
, this._ensureCredentials()];
|
|
29687
|
+
|
|
29688
|
+
case 1:
|
|
29689
|
+
credentialsOK = _a.sent();
|
|
29690
|
+
|
|
29691
|
+
if (!credentialsOK) {
|
|
29692
|
+
throw new Error('No credentials');
|
|
29693
|
+
} // Verify geofence collection exists in aws-config.js
|
|
29694
|
+
|
|
29695
|
+
|
|
29696
|
+
try {
|
|
29697
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
29698
|
+
} catch (error) {
|
|
29699
|
+
logger.debug(error);
|
|
29700
|
+
throw error;
|
|
29701
|
+
}
|
|
29702
|
+
|
|
29703
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofencesInput"])(geofences);
|
|
29704
|
+
PascalGeofences = geofences.map(function (_a) {
|
|
29705
|
+
var geofenceId = _a.geofenceId,
|
|
29706
|
+
polygon = _a.geometry.polygon;
|
|
29707
|
+
return {
|
|
29708
|
+
GeofenceId: geofenceId,
|
|
29709
|
+
Geometry: {
|
|
29710
|
+
Polygon: polygon
|
|
29711
|
+
}
|
|
29712
|
+
};
|
|
29713
|
+
});
|
|
29714
|
+
results = {
|
|
29715
|
+
successes: [],
|
|
29716
|
+
errors: []
|
|
29717
|
+
};
|
|
29718
|
+
batches = [];
|
|
29719
|
+
|
|
29720
|
+
while (PascalGeofences.length > 0) {
|
|
29721
|
+
apiLimit = 10;
|
|
29722
|
+
batches.push(PascalGeofences.splice(0, apiLimit));
|
|
29723
|
+
}
|
|
29724
|
+
|
|
29725
|
+
return [4
|
|
29726
|
+
/*yield*/
|
|
29727
|
+
, Promise.all(batches.map(function (batch) {
|
|
29728
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
29729
|
+
var response, error_3;
|
|
29730
|
+
return __generator(this, function (_a) {
|
|
29731
|
+
switch (_a.label) {
|
|
29732
|
+
case 0:
|
|
29733
|
+
_a.trys.push([0, 2,, 3]);
|
|
29734
|
+
|
|
29735
|
+
return [4
|
|
29736
|
+
/*yield*/
|
|
29737
|
+
, this._AmazonLocationServiceBatchPutGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"])];
|
|
29738
|
+
|
|
29739
|
+
case 1:
|
|
29740
|
+
response = _a.sent();
|
|
29741
|
+
return [3
|
|
29742
|
+
/*break*/
|
|
29743
|
+
, 3];
|
|
29744
|
+
|
|
29745
|
+
case 2:
|
|
29746
|
+
error_3 = _a.sent(); // If the API call fails, add the geofences to the errors array and move to next batch
|
|
29747
|
+
|
|
29748
|
+
batch.forEach(function (geofence) {
|
|
29749
|
+
results.errors.push({
|
|
29750
|
+
geofenceId: geofence.GeofenceId,
|
|
29751
|
+
error: {
|
|
29752
|
+
code: 'APIConnectionError',
|
|
29753
|
+
message: error_3.message
|
|
29754
|
+
}
|
|
29755
|
+
});
|
|
29756
|
+
});
|
|
29757
|
+
return [2
|
|
29758
|
+
/*return*/
|
|
29759
|
+
];
|
|
29760
|
+
|
|
29761
|
+
case 3:
|
|
29762
|
+
// Push all successes to results
|
|
29763
|
+
response.Successes.forEach(function (success) {
|
|
29764
|
+
var GeofenceId = success.GeofenceId,
|
|
29765
|
+
CreateTime = success.CreateTime,
|
|
29766
|
+
UpdateTime = success.UpdateTime;
|
|
29767
|
+
results.successes.push({
|
|
29768
|
+
geofenceId: GeofenceId,
|
|
29769
|
+
createTime: CreateTime,
|
|
29770
|
+
updateTime: UpdateTime
|
|
29771
|
+
});
|
|
29772
|
+
}); // Push all errors to results
|
|
29773
|
+
|
|
29774
|
+
response.Errors.forEach(function (error) {
|
|
29775
|
+
var _a = error.Error,
|
|
29776
|
+
Code = _a.Code,
|
|
29777
|
+
Message = _a.Message,
|
|
29778
|
+
GeofenceId = error.GeofenceId;
|
|
29779
|
+
results.errors.push({
|
|
29780
|
+
error: {
|
|
29781
|
+
code: Code,
|
|
29782
|
+
message: Message
|
|
29783
|
+
},
|
|
29784
|
+
geofenceId: GeofenceId
|
|
29785
|
+
});
|
|
29786
|
+
});
|
|
29787
|
+
return [2
|
|
29788
|
+
/*return*/
|
|
29789
|
+
];
|
|
29790
|
+
}
|
|
29791
|
+
});
|
|
29792
|
+
});
|
|
29793
|
+
}))];
|
|
29794
|
+
|
|
29795
|
+
case 2:
|
|
29796
|
+
_a.sent();
|
|
29797
|
+
|
|
29798
|
+
return [2
|
|
29799
|
+
/*return*/
|
|
29800
|
+
, results];
|
|
29801
|
+
}
|
|
29802
|
+
});
|
|
29803
|
+
});
|
|
29804
|
+
};
|
|
29805
|
+
/**
|
|
29806
|
+
* Get geofence from a geofence collection
|
|
29807
|
+
* @param geofenceId:string
|
|
29808
|
+
* @param options?: Optional parameters for getGeofence
|
|
29809
|
+
* @returns {Promise<AmazonLocationServiceGeofence>} - Promise that resolves to a geofence object
|
|
29810
|
+
*/
|
|
29811
|
+
|
|
29812
|
+
|
|
29813
|
+
AmazonLocationServiceProvider.prototype.getGeofence = function (geofenceId, options) {
|
|
29814
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29815
|
+
var credentialsOK, client, commandInput, command, response, error_4, GeofenceId, CreateTime, UpdateTime, Status, Geometry, geofence;
|
|
29816
|
+
return __generator(this, function (_a) {
|
|
29817
|
+
switch (_a.label) {
|
|
29818
|
+
case 0:
|
|
29819
|
+
return [4
|
|
29820
|
+
/*yield*/
|
|
29821
|
+
, this._ensureCredentials()];
|
|
29822
|
+
|
|
29823
|
+
case 1:
|
|
29824
|
+
credentialsOK = _a.sent();
|
|
29825
|
+
|
|
29826
|
+
if (!credentialsOK) {
|
|
29827
|
+
throw new Error('No credentials');
|
|
29828
|
+
} // Verify geofence collection exists in aws-config.js
|
|
29829
|
+
|
|
29830
|
+
|
|
29831
|
+
try {
|
|
29832
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
29833
|
+
} catch (error) {
|
|
29834
|
+
logger.debug(error);
|
|
29835
|
+
throw error;
|
|
29836
|
+
}
|
|
29837
|
+
|
|
29838
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofenceId"])(geofenceId);
|
|
29839
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
29840
|
+
credentials: this._config.credentials,
|
|
29841
|
+
region: this._config.region,
|
|
29842
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
29843
|
+
});
|
|
29844
|
+
commandInput = {
|
|
29845
|
+
GeofenceId: geofenceId,
|
|
29846
|
+
CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"]
|
|
29847
|
+
};
|
|
29848
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["GetGeofenceCommand"](commandInput);
|
|
29849
|
+
_a.label = 2;
|
|
29850
|
+
|
|
29851
|
+
case 2:
|
|
29852
|
+
_a.trys.push([2, 4,, 5]);
|
|
29853
|
+
|
|
29854
|
+
return [4
|
|
29855
|
+
/*yield*/
|
|
29856
|
+
, client.send(command)];
|
|
29857
|
+
|
|
29858
|
+
case 3:
|
|
29859
|
+
response = _a.sent();
|
|
29860
|
+
return [3
|
|
29861
|
+
/*break*/
|
|
29862
|
+
, 5];
|
|
29863
|
+
|
|
29864
|
+
case 4:
|
|
29865
|
+
error_4 = _a.sent();
|
|
29866
|
+
logger.debug(error_4);
|
|
29867
|
+
throw error_4;
|
|
29868
|
+
|
|
29869
|
+
case 5:
|
|
29870
|
+
GeofenceId = response.GeofenceId, CreateTime = response.CreateTime, UpdateTime = response.UpdateTime, Status = response.Status, Geometry = response.Geometry;
|
|
29871
|
+
geofence = {
|
|
29872
|
+
createTime: CreateTime,
|
|
29873
|
+
geofenceId: GeofenceId,
|
|
29874
|
+
geometry: {
|
|
29875
|
+
polygon: Geometry.Polygon
|
|
29876
|
+
},
|
|
29877
|
+
status: Status,
|
|
29878
|
+
updateTime: UpdateTime
|
|
29879
|
+
};
|
|
29880
|
+
return [2
|
|
29881
|
+
/*return*/
|
|
29882
|
+
, geofence];
|
|
28329
29883
|
}
|
|
28330
29884
|
});
|
|
28331
29885
|
});
|
|
28332
29886
|
};
|
|
28333
29887
|
/**
|
|
28334
|
-
*
|
|
28335
|
-
* @param
|
|
28336
|
-
* @
|
|
28337
|
-
*
|
|
29888
|
+
* List geofences from a geofence collection
|
|
29889
|
+
* @param options?: ListGeofenceOptions
|
|
29890
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
29891
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
29892
|
+
* nextToken: token for next page of geofences
|
|
28338
29893
|
*/
|
|
28339
29894
|
|
|
28340
29895
|
|
|
28341
|
-
AmazonLocationServiceProvider.prototype.
|
|
29896
|
+
AmazonLocationServiceProvider.prototype.listGeofences = function (options) {
|
|
28342
29897
|
return __awaiter(this, void 0, void 0, function () {
|
|
28343
|
-
var credentialsOK,
|
|
29898
|
+
var credentialsOK, client, listGeofencesInput, command, response, error_5, NextToken, Entries, results;
|
|
28344
29899
|
return __generator(this, function (_a) {
|
|
28345
29900
|
switch (_a.label) {
|
|
28346
29901
|
case 0:
|
|
@@ -28353,37 +29908,14 @@ function () {
|
|
|
28353
29908
|
|
|
28354
29909
|
if (!credentialsOK) {
|
|
28355
29910
|
throw new Error('No credentials');
|
|
28356
|
-
}
|
|
28357
|
-
|
|
28358
|
-
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
28359
|
-
|
|
28360
|
-
locationServiceInput = {
|
|
28361
|
-
Text: text,
|
|
28362
|
-
IndexName: this._config.search_indices["default"]
|
|
28363
|
-
};
|
|
28364
|
-
/**
|
|
28365
|
-
* Map search options to Amazon Location Service input object
|
|
28366
|
-
*/
|
|
28367
|
-
|
|
28368
|
-
if (options) {
|
|
28369
|
-
locationServiceInput.FilterCountries = options.countries;
|
|
28370
|
-
locationServiceInput.MaxResults = options.maxResults;
|
|
28371
|
-
|
|
28372
|
-
if (options.searchIndexName) {
|
|
28373
|
-
locationServiceInput.IndexName = options.searchIndexName;
|
|
28374
|
-
}
|
|
28375
|
-
|
|
28376
|
-
if (options['biasPosition'] && options['searchAreaConstraints']) {
|
|
28377
|
-
throw new Error('BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object');
|
|
28378
|
-
}
|
|
29911
|
+
} // Verify geofence collection exists in aws-config.js
|
|
28379
29912
|
|
|
28380
|
-
if (options['biasPosition']) {
|
|
28381
|
-
locationServiceInput.BiasPosition = options['biasPosition'];
|
|
28382
|
-
}
|
|
28383
29913
|
|
|
28384
|
-
|
|
28385
|
-
|
|
28386
|
-
|
|
29914
|
+
try {
|
|
29915
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
29916
|
+
} catch (error) {
|
|
29917
|
+
logger.debug(error);
|
|
29918
|
+
throw error;
|
|
28387
29919
|
}
|
|
28388
29920
|
|
|
28389
29921
|
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
@@ -28391,7 +29923,11 @@ function () {
|
|
|
28391
29923
|
region: this._config.region,
|
|
28392
29924
|
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
28393
29925
|
});
|
|
28394
|
-
|
|
29926
|
+
listGeofencesInput = {
|
|
29927
|
+
NextToken: options === null || options === void 0 ? void 0 : options.nextToken,
|
|
29928
|
+
CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"]
|
|
29929
|
+
};
|
|
29930
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["ListGeofencesCommand"](listGeofencesInput);
|
|
28395
29931
|
_a.label = 2;
|
|
28396
29932
|
|
|
28397
29933
|
case 2:
|
|
@@ -28408,14 +29944,31 @@ function () {
|
|
|
28408
29944
|
, 5];
|
|
28409
29945
|
|
|
28410
29946
|
case 4:
|
|
28411
|
-
|
|
28412
|
-
logger.debug(
|
|
28413
|
-
throw
|
|
29947
|
+
error_5 = _a.sent();
|
|
29948
|
+
logger.debug(error_5);
|
|
29949
|
+
throw error_5;
|
|
28414
29950
|
|
|
28415
29951
|
case 5:
|
|
28416
|
-
|
|
28417
|
-
|
|
28418
|
-
|
|
29952
|
+
NextToken = response.NextToken, Entries = response.Entries;
|
|
29953
|
+
results = {
|
|
29954
|
+
entries: Entries.map(function (_a) {
|
|
29955
|
+
var GeofenceId = _a.GeofenceId,
|
|
29956
|
+
CreateTime = _a.CreateTime,
|
|
29957
|
+
UpdateTime = _a.UpdateTime,
|
|
29958
|
+
Status = _a.Status,
|
|
29959
|
+
Polygon = _a.Geometry.Polygon;
|
|
29960
|
+
return {
|
|
29961
|
+
geofenceId: GeofenceId,
|
|
29962
|
+
createTime: CreateTime,
|
|
29963
|
+
updateTime: UpdateTime,
|
|
29964
|
+
status: Status,
|
|
29965
|
+
geometry: {
|
|
29966
|
+
polygon: Polygon
|
|
29967
|
+
}
|
|
29968
|
+
};
|
|
29969
|
+
}),
|
|
29970
|
+
nextToken: NextToken
|
|
29971
|
+
};
|
|
28419
29972
|
return [2
|
|
28420
29973
|
/*return*/
|
|
28421
29974
|
, results];
|
|
@@ -28424,19 +29977,28 @@ function () {
|
|
|
28424
29977
|
});
|
|
28425
29978
|
};
|
|
28426
29979
|
/**
|
|
28427
|
-
*
|
|
28428
|
-
* @param
|
|
28429
|
-
* @param options
|
|
28430
|
-
* @returns {Promise<
|
|
29980
|
+
* Delete geofences from a geofence collection
|
|
29981
|
+
* @param geofenceIds: string|string[]
|
|
29982
|
+
* @param options?: GeofenceOptions
|
|
29983
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
29984
|
+
* successes: list of geofences successfully deleted
|
|
29985
|
+
* errors: list of geofences that failed to delete
|
|
28431
29986
|
*/
|
|
28432
29987
|
|
|
28433
29988
|
|
|
28434
|
-
AmazonLocationServiceProvider.prototype.
|
|
29989
|
+
AmazonLocationServiceProvider.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
28435
29990
|
return __awaiter(this, void 0, void 0, function () {
|
|
28436
|
-
var credentialsOK,
|
|
29991
|
+
var credentialsOK, badGeofenceIds, results, batches, count;
|
|
29992
|
+
|
|
29993
|
+
var _this = this;
|
|
29994
|
+
|
|
28437
29995
|
return __generator(this, function (_a) {
|
|
28438
29996
|
switch (_a.label) {
|
|
28439
29997
|
case 0:
|
|
29998
|
+
if (geofenceIds.length < 1) {
|
|
29999
|
+
throw new Error('GeofenceId input array is empty');
|
|
30000
|
+
}
|
|
30001
|
+
|
|
28440
30002
|
return [4
|
|
28441
30003
|
/*yield*/
|
|
28442
30004
|
, this._ensureCredentials()];
|
|
@@ -28448,54 +30010,92 @@ function () {
|
|
|
28448
30010
|
throw new Error('No credentials');
|
|
28449
30011
|
}
|
|
28450
30012
|
|
|
28451
|
-
this.
|
|
28452
|
-
|
|
28453
|
-
locationServiceInput = {
|
|
28454
|
-
Position: coordinates,
|
|
28455
|
-
IndexName: this._config.search_indices["default"]
|
|
28456
|
-
};
|
|
30013
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
28457
30014
|
|
|
28458
|
-
|
|
28459
|
-
|
|
28460
|
-
|
|
30015
|
+
badGeofenceIds = geofenceIds.filter(function (geofenceId) {
|
|
30016
|
+
try {
|
|
30017
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofenceId"])(geofenceId);
|
|
30018
|
+
} catch (error) {
|
|
30019
|
+
return true;
|
|
28461
30020
|
}
|
|
30021
|
+
});
|
|
28462
30022
|
|
|
28463
|
-
|
|
30023
|
+
if (badGeofenceIds.length > 0) {
|
|
30024
|
+
throw new Error("Invalid geofence ids: " + badGeofenceIds.join(', '));
|
|
28464
30025
|
}
|
|
28465
30026
|
|
|
28466
|
-
|
|
28467
|
-
|
|
28468
|
-
|
|
28469
|
-
|
|
28470
|
-
|
|
28471
|
-
|
|
28472
|
-
_a.label = 2;
|
|
30027
|
+
results = {
|
|
30028
|
+
successes: [],
|
|
30029
|
+
errors: []
|
|
30030
|
+
};
|
|
30031
|
+
batches = [];
|
|
30032
|
+
count = 0;
|
|
28473
30033
|
|
|
28474
|
-
|
|
28475
|
-
|
|
30034
|
+
while (count < geofenceIds.length) {
|
|
30035
|
+
batches.push(geofenceIds.slice(count, count += 10));
|
|
30036
|
+
}
|
|
28476
30037
|
|
|
28477
30038
|
return [4
|
|
28478
30039
|
/*yield*/
|
|
28479
|
-
,
|
|
30040
|
+
, Promise.all(batches.map(function (batch) {
|
|
30041
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
30042
|
+
var response, error_6, badGeofenceIds;
|
|
28480
30043
|
|
|
28481
|
-
|
|
28482
|
-
response = _a.sent();
|
|
28483
|
-
return [3
|
|
28484
|
-
/*break*/
|
|
28485
|
-
, 5];
|
|
30044
|
+
var _a;
|
|
28486
30045
|
|
|
28487
|
-
|
|
28488
|
-
|
|
28489
|
-
|
|
28490
|
-
|
|
30046
|
+
return __generator(this, function (_b) {
|
|
30047
|
+
switch (_b.label) {
|
|
30048
|
+
case 0:
|
|
30049
|
+
_b.trys.push([0, 2,, 3]);
|
|
30050
|
+
|
|
30051
|
+
return [4
|
|
30052
|
+
/*yield*/
|
|
30053
|
+
, this._AmazonLocationServiceBatchDeleteGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"])];
|
|
30054
|
+
|
|
30055
|
+
case 1:
|
|
30056
|
+
response = _b.sent();
|
|
30057
|
+
return [3
|
|
30058
|
+
/*break*/
|
|
30059
|
+
, 3];
|
|
30060
|
+
|
|
30061
|
+
case 2:
|
|
30062
|
+
error_6 = _b.sent(); // If the API call fails, add the geofences to the errors array and move to next batch
|
|
30063
|
+
|
|
30064
|
+
batch.forEach(function (geofenceId) {
|
|
30065
|
+
var errorObject = {
|
|
30066
|
+
geofenceId: geofenceId,
|
|
30067
|
+
error: {
|
|
30068
|
+
code: error_6.message,
|
|
30069
|
+
message: error_6.message
|
|
30070
|
+
}
|
|
30071
|
+
};
|
|
30072
|
+
results.errors.push(errorObject);
|
|
30073
|
+
});
|
|
30074
|
+
return [2
|
|
30075
|
+
/*return*/
|
|
30076
|
+
];
|
|
30077
|
+
|
|
30078
|
+
case 3:
|
|
30079
|
+
badGeofenceIds = response.Errors.map(function (_a) {
|
|
30080
|
+
var geofenceId = _a.geofenceId;
|
|
30081
|
+
return geofenceId;
|
|
30082
|
+
});
|
|
30083
|
+
|
|
30084
|
+
(_a = results.successes).push.apply(_a, __spread(batch.filter(function (Id) {
|
|
30085
|
+
return !badGeofenceIds.includes(Id);
|
|
30086
|
+
})));
|
|
30087
|
+
|
|
30088
|
+
return [2
|
|
30089
|
+
/*return*/
|
|
30090
|
+
];
|
|
30091
|
+
}
|
|
30092
|
+
});
|
|
30093
|
+
});
|
|
30094
|
+
}))];
|
|
30095
|
+
|
|
30096
|
+
case 2:
|
|
30097
|
+
_a.sent();
|
|
28491
30098
|
|
|
28492
|
-
case 5:
|
|
28493
|
-
PascalResults = response.Results.map(function (result) {
|
|
28494
|
-
return result.Place;
|
|
28495
|
-
});
|
|
28496
|
-
results = camelcase_keys__WEBPACK_IMPORTED_MODULE_0___default()(PascalResults[0], {
|
|
28497
|
-
deep: true
|
|
28498
|
-
});
|
|
28499
30099
|
return [2
|
|
28500
30100
|
/*return*/
|
|
28501
30101
|
, results];
|
|
@@ -28510,7 +30110,7 @@ function () {
|
|
|
28510
30110
|
|
|
28511
30111
|
AmazonLocationServiceProvider.prototype._ensureCredentials = function () {
|
|
28512
30112
|
return __awaiter(this, void 0, void 0, function () {
|
|
28513
|
-
var credentials, cred,
|
|
30113
|
+
var credentials, cred, error_7;
|
|
28514
30114
|
return __generator(this, function (_a) {
|
|
28515
30115
|
switch (_a.label) {
|
|
28516
30116
|
case 0:
|
|
@@ -28533,8 +30133,8 @@ function () {
|
|
|
28533
30133
|
, true];
|
|
28534
30134
|
|
|
28535
30135
|
case 2:
|
|
28536
|
-
|
|
28537
|
-
logger.
|
|
30136
|
+
error_7 = _a.sent();
|
|
30137
|
+
logger.debug('Ensure credentials error. Credentials are:', error_7);
|
|
28538
30138
|
return [2
|
|
28539
30139
|
/*return*/
|
|
28540
30140
|
, false];
|
|
@@ -28550,26 +30150,122 @@ function () {
|
|
|
28550
30150
|
|
|
28551
30151
|
AmazonLocationServiceProvider.prototype._verifyMapResources = function () {
|
|
28552
30152
|
if (!this._config.maps) {
|
|
28553
|
-
var errorString = "No map resources found in amplify config, run 'amplify add geo' to create
|
|
28554
|
-
logger.
|
|
30153
|
+
var errorString = "No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
30154
|
+
logger.debug(errorString);
|
|
28555
30155
|
throw new Error(errorString);
|
|
28556
30156
|
}
|
|
28557
30157
|
|
|
28558
30158
|
if (!this._config.maps["default"]) {
|
|
28559
30159
|
var errorString = "No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
28560
|
-
logger.
|
|
30160
|
+
logger.debug(errorString);
|
|
28561
30161
|
throw new Error(errorString);
|
|
28562
30162
|
}
|
|
28563
30163
|
};
|
|
28564
30164
|
|
|
28565
30165
|
AmazonLocationServiceProvider.prototype._verifySearchIndex = function (optionalSearchIndex) {
|
|
28566
30166
|
if ((!this._config.search_indices || !this._config.search_indices["default"]) && !optionalSearchIndex) {
|
|
28567
|
-
var errorString = 'No Search Index found, please run `amplify add geo` to
|
|
28568
|
-
logger.
|
|
30167
|
+
var errorString = 'No Search Index found in amplify config, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
30168
|
+
logger.debug(errorString);
|
|
30169
|
+
throw new Error(errorString);
|
|
30170
|
+
}
|
|
30171
|
+
};
|
|
30172
|
+
|
|
30173
|
+
AmazonLocationServiceProvider.prototype._verifyGeofenceCollections = function (optionalGeofenceCollectionName) {
|
|
30174
|
+
if ((!this._config.geofenceCollections || !this._config.geofenceCollections["default"]) && !optionalGeofenceCollectionName) {
|
|
30175
|
+
var errorString = 'No Geofence Collections found, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
30176
|
+
logger.debug(errorString);
|
|
28569
30177
|
throw new Error(errorString);
|
|
28570
30178
|
}
|
|
28571
30179
|
};
|
|
28572
30180
|
|
|
30181
|
+
AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchPutGeofenceCall = function (PascalGeofences, collectionName) {
|
|
30182
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30183
|
+
var geofenceInput, client, command, response, error_8;
|
|
30184
|
+
return __generator(this, function (_a) {
|
|
30185
|
+
switch (_a.label) {
|
|
30186
|
+
case 0:
|
|
30187
|
+
geofenceInput = {
|
|
30188
|
+
Entries: PascalGeofences,
|
|
30189
|
+
CollectionName: collectionName || this._config.geofenceCollections["default"]
|
|
30190
|
+
};
|
|
30191
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
30192
|
+
credentials: this._config.credentials,
|
|
30193
|
+
region: this._config.region,
|
|
30194
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
30195
|
+
});
|
|
30196
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["BatchPutGeofenceCommand"](geofenceInput);
|
|
30197
|
+
_a.label = 1;
|
|
30198
|
+
|
|
30199
|
+
case 1:
|
|
30200
|
+
_a.trys.push([1, 3,, 4]);
|
|
30201
|
+
|
|
30202
|
+
return [4
|
|
30203
|
+
/*yield*/
|
|
30204
|
+
, client.send(command)];
|
|
30205
|
+
|
|
30206
|
+
case 2:
|
|
30207
|
+
response = _a.sent();
|
|
30208
|
+
return [3
|
|
30209
|
+
/*break*/
|
|
30210
|
+
, 4];
|
|
30211
|
+
|
|
30212
|
+
case 3:
|
|
30213
|
+
error_8 = _a.sent();
|
|
30214
|
+
throw error_8;
|
|
30215
|
+
|
|
30216
|
+
case 4:
|
|
30217
|
+
return [2
|
|
30218
|
+
/*return*/
|
|
30219
|
+
, response];
|
|
30220
|
+
}
|
|
30221
|
+
});
|
|
30222
|
+
});
|
|
30223
|
+
};
|
|
30224
|
+
|
|
30225
|
+
AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchDeleteGeofenceCall = function (geofenceIds, collectionName) {
|
|
30226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30227
|
+
var deleteGeofencesInput, client, command, response, error_9;
|
|
30228
|
+
return __generator(this, function (_a) {
|
|
30229
|
+
switch (_a.label) {
|
|
30230
|
+
case 0:
|
|
30231
|
+
deleteGeofencesInput = {
|
|
30232
|
+
GeofenceIds: geofenceIds,
|
|
30233
|
+
CollectionName: collectionName || this._config.geofenceCollections["default"]
|
|
30234
|
+
};
|
|
30235
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
30236
|
+
credentials: this._config.credentials,
|
|
30237
|
+
region: this._config.region,
|
|
30238
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
30239
|
+
});
|
|
30240
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["BatchDeleteGeofenceCommand"](deleteGeofencesInput);
|
|
30241
|
+
_a.label = 1;
|
|
30242
|
+
|
|
30243
|
+
case 1:
|
|
30244
|
+
_a.trys.push([1, 3,, 4]);
|
|
30245
|
+
|
|
30246
|
+
return [4
|
|
30247
|
+
/*yield*/
|
|
30248
|
+
, client.send(command)];
|
|
30249
|
+
|
|
30250
|
+
case 2:
|
|
30251
|
+
response = _a.sent();
|
|
30252
|
+
return [3
|
|
30253
|
+
/*break*/
|
|
30254
|
+
, 4];
|
|
30255
|
+
|
|
30256
|
+
case 3:
|
|
30257
|
+
error_9 = _a.sent();
|
|
30258
|
+
throw error_9;
|
|
30259
|
+
|
|
30260
|
+
case 4:
|
|
30261
|
+
return [2
|
|
30262
|
+
/*return*/
|
|
30263
|
+
, response];
|
|
30264
|
+
}
|
|
30265
|
+
});
|
|
30266
|
+
});
|
|
30267
|
+
};
|
|
30268
|
+
|
|
28573
30269
|
AmazonLocationServiceProvider.CATEGORY = 'Geo';
|
|
28574
30270
|
AmazonLocationServiceProvider.PROVIDER_NAME = 'AmazonLocationService';
|
|
28575
30271
|
return AmazonLocationServiceProvider;
|
|
@@ -28593,6 +30289,193 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
28593
30289
|
|
|
28594
30290
|
|
|
28595
30291
|
|
|
30292
|
+
/***/ }),
|
|
30293
|
+
|
|
30294
|
+
/***/ "./lib-esm/util.js":
|
|
30295
|
+
/*!*************************!*\
|
|
30296
|
+
!*** ./lib-esm/util.js ***!
|
|
30297
|
+
\*************************/
|
|
30298
|
+
/*! exports provided: validateCoordinates, validateGeofenceId, validateLinearRing, validatePolygon, validateGeofencesInput */
|
|
30299
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
30300
|
+
|
|
30301
|
+
"use strict";
|
|
30302
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30303
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateCoordinates", function() { return validateCoordinates; });
|
|
30304
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofenceId", function() { return validateGeofenceId; });
|
|
30305
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateLinearRing", function() { return validateLinearRing; });
|
|
30306
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validatePolygon", function() { return validatePolygon; });
|
|
30307
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofencesInput", function() { return validateGeofencesInput; });
|
|
30308
|
+
/* harmony import */ var _turf_boolean_clockwise__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @turf/boolean-clockwise */ "../../node_modules/@turf/boolean-clockwise/dist/es/index.js");
|
|
30309
|
+
var __read = undefined && undefined.__read || function (o, n) {
|
|
30310
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30311
|
+
if (!m) return o;
|
|
30312
|
+
var i = m.call(o),
|
|
30313
|
+
r,
|
|
30314
|
+
ar = [],
|
|
30315
|
+
e;
|
|
30316
|
+
|
|
30317
|
+
try {
|
|
30318
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
30319
|
+
ar.push(r.value);
|
|
30320
|
+
}
|
|
30321
|
+
} catch (error) {
|
|
30322
|
+
e = {
|
|
30323
|
+
error: error
|
|
30324
|
+
};
|
|
30325
|
+
} finally {
|
|
30326
|
+
try {
|
|
30327
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
30328
|
+
} finally {
|
|
30329
|
+
if (e) throw e.error;
|
|
30330
|
+
}
|
|
30331
|
+
}
|
|
30332
|
+
|
|
30333
|
+
return ar;
|
|
30334
|
+
};
|
|
30335
|
+
/*
|
|
30336
|
+
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
30337
|
+
*
|
|
30338
|
+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
30339
|
+
* the License. A copy of the License is located at
|
|
30340
|
+
*
|
|
30341
|
+
* http://aws.amazon.com/apache2.0/
|
|
30342
|
+
*
|
|
30343
|
+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
30344
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
30345
|
+
* and limitations under the License.
|
|
30346
|
+
*/
|
|
30347
|
+
|
|
30348
|
+
|
|
30349
|
+
|
|
30350
|
+
function validateCoordinates(lng, lat) {
|
|
30351
|
+
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
30352
|
+
throw new Error("Invalid coordinates: [" + lng + "," + lat + "]");
|
|
30353
|
+
}
|
|
30354
|
+
|
|
30355
|
+
if (lat < -90 || lat > 90) {
|
|
30356
|
+
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
30357
|
+
} else if (lng < -180 || lng > 180) {
|
|
30358
|
+
throw new Error('Longitude must be between -180 and 180 degrees inclusive.');
|
|
30359
|
+
}
|
|
30360
|
+
}
|
|
30361
|
+
function validateGeofenceId(geofenceId) {
|
|
30362
|
+
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
|
|
30363
|
+
|
|
30364
|
+
if (!geofenceIdRegex.test(geofenceId)) {
|
|
30365
|
+
throw new Error("Invalid geofenceId: '" + geofenceId + "' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.");
|
|
30366
|
+
}
|
|
30367
|
+
}
|
|
30368
|
+
function validateLinearRing(linearRing, geofenceId) {
|
|
30369
|
+
var errorPrefix = geofenceId ? geofenceId + ": " : ''; // Validate LinearRing size, must be at least 4 points
|
|
30370
|
+
|
|
30371
|
+
if (linearRing.length < 4) {
|
|
30372
|
+
throw new Error(errorPrefix + "LinearRing must contain 4 or more coordinates.");
|
|
30373
|
+
} // Validate all coordinates are valid, error with which ones are bad
|
|
30374
|
+
|
|
30375
|
+
|
|
30376
|
+
var badCoordinates = [];
|
|
30377
|
+
linearRing.forEach(function (coordinates) {
|
|
30378
|
+
try {
|
|
30379
|
+
validateCoordinates(coordinates[0], coordinates[1]);
|
|
30380
|
+
} catch (error) {
|
|
30381
|
+
badCoordinates.push({
|
|
30382
|
+
coordinates: coordinates,
|
|
30383
|
+
error: error.message
|
|
30384
|
+
});
|
|
30385
|
+
}
|
|
30386
|
+
});
|
|
30387
|
+
|
|
30388
|
+
if (badCoordinates.length > 0) {
|
|
30389
|
+
throw new Error(errorPrefix + "One or more of the coordinates in the Polygon LinearRing are not valid: " + JSON.stringify(badCoordinates));
|
|
30390
|
+
} // Validate first and last coordinates are the same
|
|
30391
|
+
|
|
30392
|
+
|
|
30393
|
+
var _a = __read(linearRing[0], 2),
|
|
30394
|
+
lngA = _a[0],
|
|
30395
|
+
latA = _a[1];
|
|
30396
|
+
|
|
30397
|
+
var _b = __read(linearRing[linearRing.length - 1], 2),
|
|
30398
|
+
lngB = _b[0],
|
|
30399
|
+
latB = _b[1];
|
|
30400
|
+
|
|
30401
|
+
if (lngA !== lngB || latA !== latB) {
|
|
30402
|
+
throw new Error(errorPrefix + "LinearRing's first and last coordinates are not the same");
|
|
30403
|
+
}
|
|
30404
|
+
|
|
30405
|
+
if (Object(_turf_boolean_clockwise__WEBPACK_IMPORTED_MODULE_0__["default"])(linearRing)) {
|
|
30406
|
+
throw new Error(errorPrefix + "LinearRing coordinates must be wound counterclockwise");
|
|
30407
|
+
}
|
|
30408
|
+
}
|
|
30409
|
+
function validatePolygon(polygon, geofenceId) {
|
|
30410
|
+
var errorPrefix = geofenceId ? geofenceId + ": " : '';
|
|
30411
|
+
|
|
30412
|
+
if (!Array.isArray(polygon)) {
|
|
30413
|
+
throw new Error(errorPrefix + "Polygon is of incorrect structure. It should be an array of LinearRings");
|
|
30414
|
+
}
|
|
30415
|
+
|
|
30416
|
+
if (polygon.length < 1) {
|
|
30417
|
+
throw new Error(errorPrefix + "Polygon must have a single LinearRing array.");
|
|
30418
|
+
}
|
|
30419
|
+
|
|
30420
|
+
if (polygon.length > 1) {
|
|
30421
|
+
throw new Error(errorPrefix + "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.");
|
|
30422
|
+
}
|
|
30423
|
+
|
|
30424
|
+
var verticesCount = polygon.reduce(function (prev, linearRing) {
|
|
30425
|
+
return prev + linearRing.length;
|
|
30426
|
+
}, 0);
|
|
30427
|
+
|
|
30428
|
+
if (verticesCount > 1000) {
|
|
30429
|
+
throw new Error(errorPrefix + "Polygon has more than the maximum 1000 vertices.");
|
|
30430
|
+
}
|
|
30431
|
+
}
|
|
30432
|
+
function validateGeofencesInput(geofences) {
|
|
30433
|
+
var geofenceIds = {};
|
|
30434
|
+
geofences.forEach(function (geofence) {
|
|
30435
|
+
// verify all required properties are present
|
|
30436
|
+
// Validate geofenceId exists
|
|
30437
|
+
if (!geofence.geofenceId) {
|
|
30438
|
+
throw new Error("Geofence '" + geofence + "' is missing geofenceId");
|
|
30439
|
+
}
|
|
30440
|
+
|
|
30441
|
+
var geofenceId = geofence.geofenceId;
|
|
30442
|
+
validateGeofenceId(geofenceId); // Validate geofenceId is unique
|
|
30443
|
+
|
|
30444
|
+
if (geofenceIds[geofenceId]) {
|
|
30445
|
+
throw new Error("Duplicate geofenceId: " + geofenceId);
|
|
30446
|
+
} else {
|
|
30447
|
+
geofenceIds[geofenceId] = true;
|
|
30448
|
+
} // Validate geometry exists
|
|
30449
|
+
|
|
30450
|
+
|
|
30451
|
+
if (!geofence.geometry) {
|
|
30452
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry");
|
|
30453
|
+
}
|
|
30454
|
+
|
|
30455
|
+
var geometry = geofence.geometry; // Validate polygon exists
|
|
30456
|
+
|
|
30457
|
+
if (!geometry.polygon) {
|
|
30458
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry.polygon");
|
|
30459
|
+
}
|
|
30460
|
+
|
|
30461
|
+
var polygon = geometry.polygon; // Validate polygon length and structure
|
|
30462
|
+
|
|
30463
|
+
try {
|
|
30464
|
+
validatePolygon(polygon, geofenceId);
|
|
30465
|
+
} catch (error) {
|
|
30466
|
+
if (error.message === "Polygon has more than the maximum 1000 vertices.") {
|
|
30467
|
+
throw new Error("Geofence '" + geofenceId + "' has more than the maximum of 1000 vertices");
|
|
30468
|
+
}
|
|
30469
|
+
} // Validate LinearRing length, structure, and coordinates
|
|
30470
|
+
|
|
30471
|
+
|
|
30472
|
+
var _a = __read(polygon, 1),
|
|
30473
|
+
linearRing = _a[0];
|
|
30474
|
+
|
|
30475
|
+
validateLinearRing(linearRing, geofenceId);
|
|
30476
|
+
});
|
|
30477
|
+
}
|
|
30478
|
+
|
|
28596
30479
|
/***/ }),
|
|
28597
30480
|
|
|
28598
30481
|
/***/ "@aws-amplify/core":
|