@aws-amplify/geo 1.2.4 → 1.2.5-geo.7
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 +2145 -136
- 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 +37 -4
- package/lib/Geo.js +153 -5
- package/lib/Geo.js.map +1 -1
- package/lib/Providers/AmazonLocationServiceProvider.d.ts +37 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +417 -8
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/types/AmazonLocationServiceProvider.d.ts +21 -1
- package/lib/types/Geo.d.ts +48 -1
- package/lib/types/Provider.d.ts +5 -1
- 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 +142 -0
- package/lib/util.js.map +1 -0
- package/lib-esm/Geo.d.ts +37 -4
- package/lib-esm/Geo.js +153 -5
- package/lib-esm/Geo.js.map +1 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +37 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +418 -9
- 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 -1
- package/lib-esm/types/Provider.d.ts +5 -1
- 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 +132 -0
- package/lib-esm/util.js.map +1 -0
- package/package.json +6 -4
- package/src/Geo.ts +122 -3
- package/src/Providers/AmazonLocationServiceProvider.ts +423 -6
- package/src/types/AmazonLocationServiceProvider.ts +56 -1
- package/src/types/Geo.ts +72 -2
- package/src/types/Provider.ts +31 -1
- package/src/util.ts +171 -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) {
|
|
@@ -27690,13 +28720,40 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
27690
28720
|
f = t = 0;
|
|
27691
28721
|
}
|
|
27692
28722
|
}
|
|
27693
|
-
|
|
27694
|
-
if (op[0] & 5) throw op[1];
|
|
27695
|
-
return {
|
|
27696
|
-
value: op[0] ? op[1] : void 0,
|
|
27697
|
-
done: true
|
|
28723
|
+
|
|
28724
|
+
if (op[0] & 5) throw op[1];
|
|
28725
|
+
return {
|
|
28726
|
+
value: op[0] ? op[1] : void 0,
|
|
28727
|
+
done: true
|
|
28728
|
+
};
|
|
28729
|
+
}
|
|
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
|
|
27698
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
|
+
}
|
|
27699
28754
|
}
|
|
28755
|
+
|
|
28756
|
+
return ar;
|
|
27700
28757
|
};
|
|
27701
28758
|
/*
|
|
27702
28759
|
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
@@ -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
|
|
|
@@ -27929,13 +28987,68 @@ function () {
|
|
|
27929
28987
|
|
|
27930
28988
|
GeoClass.prototype.searchByCoordinates = function (coordinates, options) {
|
|
27931
28989
|
return __awaiter(this, void 0, void 0, function () {
|
|
27932
|
-
var _a, providerName, prov, error_3;
|
|
28990
|
+
var _a, providerName, prov, _b, lng, lat, error_3;
|
|
28991
|
+
|
|
28992
|
+
return __generator(this, function (_c) {
|
|
28993
|
+
switch (_c.label) {
|
|
28994
|
+
case 0:
|
|
28995
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
28996
|
+
prov = this.getPluggable(providerName);
|
|
28997
|
+
_b = __read(coordinates, 2), lng = _b[0], lat = _b[1];
|
|
28998
|
+
_c.label = 1;
|
|
28999
|
+
|
|
29000
|
+
case 1:
|
|
29001
|
+
_c.trys.push([1, 3,, 4]);
|
|
29002
|
+
|
|
29003
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateCoordinates"])(lng, lat);
|
|
29004
|
+
return [4
|
|
29005
|
+
/*yield*/
|
|
29006
|
+
, prov.searchByCoordinates(coordinates, options)];
|
|
29007
|
+
|
|
29008
|
+
case 2:
|
|
29009
|
+
return [2
|
|
29010
|
+
/*return*/
|
|
29011
|
+
, _c.sent()];
|
|
29012
|
+
|
|
29013
|
+
case 3:
|
|
29014
|
+
error_3 = _c.sent();
|
|
29015
|
+
logger.debug(error_3);
|
|
29016
|
+
throw error_3;
|
|
29017
|
+
|
|
29018
|
+
case 4:
|
|
29019
|
+
return [2
|
|
29020
|
+
/*return*/
|
|
29021
|
+
];
|
|
29022
|
+
}
|
|
29023
|
+
});
|
|
29024
|
+
});
|
|
29025
|
+
};
|
|
29026
|
+
/**
|
|
29027
|
+
* Create geofences
|
|
29028
|
+
* @param geofences - Single or array of geofence objects to create
|
|
29029
|
+
* @param options? - Optional parameters for creating geofences
|
|
29030
|
+
* @returns {Promise<SaveGeofencesResults>} - Promise that resolves to an object with:
|
|
29031
|
+
* successes: list of geofences successfully created
|
|
29032
|
+
* errors: list of geofences that failed to create
|
|
29033
|
+
*/
|
|
29034
|
+
|
|
29035
|
+
|
|
29036
|
+
GeoClass.prototype.saveGeofences = function (geofences, options) {
|
|
29037
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29038
|
+
var _a, providerName, prov, geofenceInputArray, error_4;
|
|
27933
29039
|
|
|
27934
29040
|
return __generator(this, function (_b) {
|
|
27935
29041
|
switch (_b.label) {
|
|
27936
29042
|
case 0:
|
|
27937
29043
|
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
27938
29044
|
prov = this.getPluggable(providerName);
|
|
29045
|
+
|
|
29046
|
+
if (!Array.isArray(geofences)) {
|
|
29047
|
+
geofenceInputArray = [geofences];
|
|
29048
|
+
} else {
|
|
29049
|
+
geofenceInputArray = geofences;
|
|
29050
|
+
}
|
|
29051
|
+
|
|
27939
29052
|
_b.label = 1;
|
|
27940
29053
|
|
|
27941
29054
|
case 1:
|
|
@@ -27943,7 +29056,7 @@ function () {
|
|
|
27943
29056
|
|
|
27944
29057
|
return [4
|
|
27945
29058
|
/*yield*/
|
|
27946
|
-
, prov.
|
|
29059
|
+
, prov.saveGeofences(geofenceInputArray, options)];
|
|
27947
29060
|
|
|
27948
29061
|
case 2:
|
|
27949
29062
|
return [2
|
|
@@ -27951,9 +29064,151 @@ function () {
|
|
|
27951
29064
|
, _b.sent()];
|
|
27952
29065
|
|
|
27953
29066
|
case 3:
|
|
27954
|
-
|
|
27955
|
-
logger.debug(
|
|
27956
|
-
throw
|
|
29067
|
+
error_4 = _b.sent();
|
|
29068
|
+
logger.debug(error_4);
|
|
29069
|
+
throw error_4;
|
|
29070
|
+
|
|
29071
|
+
case 4:
|
|
29072
|
+
return [2
|
|
29073
|
+
/*return*/
|
|
29074
|
+
];
|
|
29075
|
+
}
|
|
29076
|
+
});
|
|
29077
|
+
});
|
|
29078
|
+
};
|
|
29079
|
+
/**
|
|
29080
|
+
* Get a single geofence by geofenceId
|
|
29081
|
+
* @param geofenceId: string
|
|
29082
|
+
* @param options?: GeofenceOptions
|
|
29083
|
+
* @returns Promise<Geofence> - Promise that resolves to a geofence object
|
|
29084
|
+
*/
|
|
29085
|
+
|
|
29086
|
+
|
|
29087
|
+
GeoClass.prototype.getGeofence = function (geofenceId, options) {
|
|
29088
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29089
|
+
var _a, providerName, prov, error_5;
|
|
29090
|
+
|
|
29091
|
+
return __generator(this, function (_b) {
|
|
29092
|
+
switch (_b.label) {
|
|
29093
|
+
case 0:
|
|
29094
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
29095
|
+
prov = this.getPluggable(providerName);
|
|
29096
|
+
_b.label = 1;
|
|
29097
|
+
|
|
29098
|
+
case 1:
|
|
29099
|
+
_b.trys.push([1, 3,, 4]);
|
|
29100
|
+
|
|
29101
|
+
return [4
|
|
29102
|
+
/*yield*/
|
|
29103
|
+
, prov.getGeofence(geofenceId, options)];
|
|
29104
|
+
|
|
29105
|
+
case 2:
|
|
29106
|
+
return [2
|
|
29107
|
+
/*return*/
|
|
29108
|
+
, _b.sent()];
|
|
29109
|
+
|
|
29110
|
+
case 3:
|
|
29111
|
+
error_5 = _b.sent();
|
|
29112
|
+
logger.debug(error_5);
|
|
29113
|
+
throw error_5;
|
|
29114
|
+
|
|
29115
|
+
case 4:
|
|
29116
|
+
return [2
|
|
29117
|
+
/*return*/
|
|
29118
|
+
];
|
|
29119
|
+
}
|
|
29120
|
+
});
|
|
29121
|
+
});
|
|
29122
|
+
};
|
|
29123
|
+
/**
|
|
29124
|
+
* List geofences
|
|
29125
|
+
* @param options?: ListGeofenceOptions
|
|
29126
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
29127
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
29128
|
+
* nextToken: token for next page of geofences
|
|
29129
|
+
*/
|
|
29130
|
+
|
|
29131
|
+
|
|
29132
|
+
GeoClass.prototype.listGeofences = function (options) {
|
|
29133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29134
|
+
var _a, providerName, prov, error_6;
|
|
29135
|
+
|
|
29136
|
+
return __generator(this, function (_b) {
|
|
29137
|
+
switch (_b.label) {
|
|
29138
|
+
case 0:
|
|
29139
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
29140
|
+
prov = this.getPluggable(providerName);
|
|
29141
|
+
_b.label = 1;
|
|
29142
|
+
|
|
29143
|
+
case 1:
|
|
29144
|
+
_b.trys.push([1, 3,, 4]);
|
|
29145
|
+
|
|
29146
|
+
return [4
|
|
29147
|
+
/*yield*/
|
|
29148
|
+
, prov.listGeofences(options)];
|
|
29149
|
+
|
|
29150
|
+
case 2:
|
|
29151
|
+
return [2
|
|
29152
|
+
/*return*/
|
|
29153
|
+
, _b.sent()];
|
|
29154
|
+
|
|
29155
|
+
case 3:
|
|
29156
|
+
error_6 = _b.sent();
|
|
29157
|
+
logger.debug(error_6);
|
|
29158
|
+
throw error_6;
|
|
29159
|
+
|
|
29160
|
+
case 4:
|
|
29161
|
+
return [2
|
|
29162
|
+
/*return*/
|
|
29163
|
+
];
|
|
29164
|
+
}
|
|
29165
|
+
});
|
|
29166
|
+
});
|
|
29167
|
+
};
|
|
29168
|
+
/**
|
|
29169
|
+
* Delete geofences
|
|
29170
|
+
* @param geofenceIds: string|string[]
|
|
29171
|
+
* @param options?: GeofenceOptions
|
|
29172
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
29173
|
+
* successes: list of geofences successfully deleted
|
|
29174
|
+
* errors: list of geofences that failed to delete
|
|
29175
|
+
*/
|
|
29176
|
+
|
|
29177
|
+
|
|
29178
|
+
GeoClass.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
29179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29180
|
+
var _a, providerName, prov, geofenceIdsInputArray, error_7;
|
|
29181
|
+
|
|
29182
|
+
return __generator(this, function (_b) {
|
|
29183
|
+
switch (_b.label) {
|
|
29184
|
+
case 0:
|
|
29185
|
+
_a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
|
|
29186
|
+
prov = this.getPluggable(providerName);
|
|
29187
|
+
|
|
29188
|
+
if (!Array.isArray(geofenceIds)) {
|
|
29189
|
+
geofenceIdsInputArray = [geofenceIds];
|
|
29190
|
+
} else {
|
|
29191
|
+
geofenceIdsInputArray = geofenceIds;
|
|
29192
|
+
}
|
|
29193
|
+
|
|
29194
|
+
_b.label = 1;
|
|
29195
|
+
|
|
29196
|
+
case 1:
|
|
29197
|
+
_b.trys.push([1, 3,, 4]);
|
|
29198
|
+
|
|
29199
|
+
return [4
|
|
29200
|
+
/*yield*/
|
|
29201
|
+
, prov.deleteGeofences(geofenceIdsInputArray, options)];
|
|
29202
|
+
|
|
29203
|
+
case 2:
|
|
29204
|
+
return [2
|
|
29205
|
+
/*return*/
|
|
29206
|
+
, _b.sent()];
|
|
29207
|
+
|
|
29208
|
+
case 3:
|
|
29209
|
+
error_7 = _b.sent();
|
|
29210
|
+
logger.debug(error_7);
|
|
29211
|
+
throw error_7;
|
|
27957
29212
|
|
|
27958
29213
|
case 4:
|
|
27959
29214
|
return [2
|
|
@@ -27989,6 +29244,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
27989
29244
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
|
|
27990
29245
|
/* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__);
|
|
27991
29246
|
/* harmony import */ var _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @aws-sdk/client-location */ "../../node_modules/@aws-sdk/client-location/dist-es/index.js");
|
|
29247
|
+
/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util */ "./lib-esm/util.js");
|
|
27992
29248
|
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
27993
29249
|
function adopt(value) {
|
|
27994
29250
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -28131,6 +29387,41 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
28131
29387
|
};
|
|
28132
29388
|
}
|
|
28133
29389
|
};
|
|
29390
|
+
|
|
29391
|
+
var __read = undefined && undefined.__read || function (o, n) {
|
|
29392
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29393
|
+
if (!m) return o;
|
|
29394
|
+
var i = m.call(o),
|
|
29395
|
+
r,
|
|
29396
|
+
ar = [],
|
|
29397
|
+
e;
|
|
29398
|
+
|
|
29399
|
+
try {
|
|
29400
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
29401
|
+
ar.push(r.value);
|
|
29402
|
+
}
|
|
29403
|
+
} catch (error) {
|
|
29404
|
+
e = {
|
|
29405
|
+
error: error
|
|
29406
|
+
};
|
|
29407
|
+
} finally {
|
|
29408
|
+
try {
|
|
29409
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
29410
|
+
} finally {
|
|
29411
|
+
if (e) throw e.error;
|
|
29412
|
+
}
|
|
29413
|
+
}
|
|
29414
|
+
|
|
29415
|
+
return ar;
|
|
29416
|
+
};
|
|
29417
|
+
|
|
29418
|
+
var __spread = undefined && undefined.__spread || function () {
|
|
29419
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
29420
|
+
ar = ar.concat(__read(arguments[i]));
|
|
29421
|
+
}
|
|
29422
|
+
|
|
29423
|
+
return ar;
|
|
29424
|
+
};
|
|
28134
29425
|
/*
|
|
28135
29426
|
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
28136
29427
|
*
|
|
@@ -28148,6 +29439,7 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
|
|
|
28148
29439
|
|
|
28149
29440
|
|
|
28150
29441
|
|
|
29442
|
+
|
|
28151
29443
|
var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AmazonLocationServiceProvider');
|
|
28152
29444
|
|
|
28153
29445
|
var AmazonLocationServiceProvider =
|
|
@@ -28205,46 +29497,142 @@ function () {
|
|
|
28205
29497
|
var availableMaps = this._config.maps.items;
|
|
28206
29498
|
var region = this._config.region;
|
|
28207
29499
|
|
|
28208
|
-
for (var mapName in availableMaps) {
|
|
28209
|
-
var style = availableMaps[mapName].style;
|
|
28210
|
-
mapStyles.push({
|
|
28211
|
-
mapName: mapName,
|
|
28212
|
-
style: style,
|
|
28213
|
-
region: region
|
|
28214
|
-
});
|
|
28215
|
-
}
|
|
29500
|
+
for (var mapName in availableMaps) {
|
|
29501
|
+
var style = availableMaps[mapName].style;
|
|
29502
|
+
mapStyles.push({
|
|
29503
|
+
mapName: mapName,
|
|
29504
|
+
style: style,
|
|
29505
|
+
region: region
|
|
29506
|
+
});
|
|
29507
|
+
}
|
|
29508
|
+
|
|
29509
|
+
return mapStyles;
|
|
29510
|
+
};
|
|
29511
|
+
/**
|
|
29512
|
+
* Get the map resource set as default in amplify config
|
|
29513
|
+
* @returns {AmazonLocationServiceMapStyle} - Map resource set as the default in amplify config
|
|
29514
|
+
*/
|
|
29515
|
+
|
|
29516
|
+
|
|
29517
|
+
AmazonLocationServiceProvider.prototype.getDefaultMap = function () {
|
|
29518
|
+
this._verifyMapResources();
|
|
29519
|
+
|
|
29520
|
+
var mapName = this._config.maps["default"];
|
|
29521
|
+
var style = this._config.maps.items[mapName].style;
|
|
29522
|
+
var region = this._config.region;
|
|
29523
|
+
return {
|
|
29524
|
+
mapName: mapName,
|
|
29525
|
+
style: style,
|
|
29526
|
+
region: region
|
|
29527
|
+
};
|
|
29528
|
+
};
|
|
29529
|
+
/**
|
|
29530
|
+
* Search by text input with optional parameters
|
|
29531
|
+
* @param {string} text - The text string that is to be searched for
|
|
29532
|
+
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
29533
|
+
* @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters
|
|
29534
|
+
*/
|
|
29535
|
+
|
|
29536
|
+
|
|
29537
|
+
AmazonLocationServiceProvider.prototype.searchByText = function (text, options) {
|
|
29538
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29539
|
+
var credentialsOK, locationServiceInput, client, command, response, error_1, PascalResults, results;
|
|
29540
|
+
return __generator(this, function (_a) {
|
|
29541
|
+
switch (_a.label) {
|
|
29542
|
+
case 0:
|
|
29543
|
+
return [4
|
|
29544
|
+
/*yield*/
|
|
29545
|
+
, this._ensureCredentials()];
|
|
29546
|
+
|
|
29547
|
+
case 1:
|
|
29548
|
+
credentialsOK = _a.sent();
|
|
29549
|
+
|
|
29550
|
+
if (!credentialsOK) {
|
|
29551
|
+
throw new Error('No credentials');
|
|
29552
|
+
}
|
|
29553
|
+
|
|
29554
|
+
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
29555
|
+
|
|
29556
|
+
locationServiceInput = {
|
|
29557
|
+
Text: text,
|
|
29558
|
+
IndexName: this._config.search_indices["default"]
|
|
29559
|
+
};
|
|
29560
|
+
/**
|
|
29561
|
+
* Map search options to Amazon Location Service input object
|
|
29562
|
+
*/
|
|
29563
|
+
|
|
29564
|
+
if (options) {
|
|
29565
|
+
locationServiceInput.FilterCountries = options.countries;
|
|
29566
|
+
locationServiceInput.MaxResults = options.maxResults;
|
|
29567
|
+
|
|
29568
|
+
if (options.searchIndexName) {
|
|
29569
|
+
locationServiceInput.IndexName = options.searchIndexName;
|
|
29570
|
+
}
|
|
29571
|
+
|
|
29572
|
+
if (options['biasPosition'] && options['searchAreaConstraints']) {
|
|
29573
|
+
throw new Error('BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object');
|
|
29574
|
+
}
|
|
29575
|
+
|
|
29576
|
+
if (options['biasPosition']) {
|
|
29577
|
+
locationServiceInput.BiasPosition = options['biasPosition'];
|
|
29578
|
+
}
|
|
29579
|
+
|
|
29580
|
+
if (options['searchAreaConstraints']) {
|
|
29581
|
+
locationServiceInput.FilterBBox = options['searchAreaConstraints'];
|
|
29582
|
+
}
|
|
29583
|
+
}
|
|
29584
|
+
|
|
29585
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
29586
|
+
credentials: this._config.credentials,
|
|
29587
|
+
region: this._config.region,
|
|
29588
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
29589
|
+
});
|
|
29590
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["SearchPlaceIndexForTextCommand"](locationServiceInput);
|
|
29591
|
+
_a.label = 2;
|
|
29592
|
+
|
|
29593
|
+
case 2:
|
|
29594
|
+
_a.trys.push([2, 4,, 5]);
|
|
28216
29595
|
|
|
28217
|
-
|
|
28218
|
-
|
|
28219
|
-
|
|
28220
|
-
* Get the map resource set as default in amplify config
|
|
28221
|
-
* @returns {AmazonLocationServiceMapStyle} - Map resource set as the default in amplify config
|
|
28222
|
-
*/
|
|
29596
|
+
return [4
|
|
29597
|
+
/*yield*/
|
|
29598
|
+
, client.send(command)];
|
|
28223
29599
|
|
|
29600
|
+
case 3:
|
|
29601
|
+
response = _a.sent();
|
|
29602
|
+
return [3
|
|
29603
|
+
/*break*/
|
|
29604
|
+
, 5];
|
|
28224
29605
|
|
|
28225
|
-
|
|
28226
|
-
|
|
29606
|
+
case 4:
|
|
29607
|
+
error_1 = _a.sent();
|
|
29608
|
+
logger.debug(error_1);
|
|
29609
|
+
throw error_1;
|
|
28227
29610
|
|
|
28228
|
-
|
|
28229
|
-
|
|
28230
|
-
|
|
28231
|
-
|
|
28232
|
-
|
|
28233
|
-
|
|
28234
|
-
|
|
28235
|
-
|
|
29611
|
+
case 5:
|
|
29612
|
+
PascalResults = response.Results.map(function (result) {
|
|
29613
|
+
return result.Place;
|
|
29614
|
+
});
|
|
29615
|
+
results = camelcase_keys__WEBPACK_IMPORTED_MODULE_0___default()(PascalResults, {
|
|
29616
|
+
deep: true
|
|
29617
|
+
});
|
|
29618
|
+
return [2
|
|
29619
|
+
/*return*/
|
|
29620
|
+
, results];
|
|
29621
|
+
}
|
|
29622
|
+
});
|
|
29623
|
+
});
|
|
28236
29624
|
};
|
|
28237
29625
|
/**
|
|
28238
|
-
* Search
|
|
29626
|
+
* Search for suggestions based on the input text
|
|
28239
29627
|
* @param {string} text - The text string that is to be searched for
|
|
28240
29628
|
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
28241
|
-
* @returns {Promise<
|
|
29629
|
+
* @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
|
|
28242
29630
|
*/
|
|
28243
29631
|
|
|
28244
29632
|
|
|
28245
|
-
AmazonLocationServiceProvider.prototype.
|
|
29633
|
+
AmazonLocationServiceProvider.prototype.searchForSuggestions = function (text, options) {
|
|
28246
29634
|
return __awaiter(this, void 0, void 0, function () {
|
|
28247
|
-
var credentialsOK, locationServiceInput, client, command, response,
|
|
29635
|
+
var credentialsOK, locationServiceInput, client, command, response, error_2, results;
|
|
28248
29636
|
return __generator(this, function (_a) {
|
|
28249
29637
|
switch (_a.label) {
|
|
28250
29638
|
case 0:
|
|
@@ -28295,7 +29683,7 @@ function () {
|
|
|
28295
29683
|
region: this._config.region,
|
|
28296
29684
|
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
28297
29685
|
});
|
|
28298
|
-
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["
|
|
29686
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["SearchPlaceIndexForSuggestionsCommand"](locationServiceInput);
|
|
28299
29687
|
_a.label = 2;
|
|
28300
29688
|
|
|
28301
29689
|
case 2:
|
|
@@ -28312,35 +29700,335 @@ function () {
|
|
|
28312
29700
|
, 5];
|
|
28313
29701
|
|
|
28314
29702
|
case 4:
|
|
28315
|
-
|
|
28316
|
-
logger.debug(
|
|
28317
|
-
throw
|
|
29703
|
+
error_2 = _a.sent();
|
|
29704
|
+
logger.debug(error_2);
|
|
29705
|
+
throw error_2;
|
|
29706
|
+
|
|
29707
|
+
case 5:
|
|
29708
|
+
results = response.Results.map(function (result) {
|
|
29709
|
+
return result.Text;
|
|
29710
|
+
});
|
|
29711
|
+
return [2
|
|
29712
|
+
/*return*/
|
|
29713
|
+
, results];
|
|
29714
|
+
}
|
|
29715
|
+
});
|
|
29716
|
+
});
|
|
29717
|
+
};
|
|
29718
|
+
/**
|
|
29719
|
+
* Reverse geocoding search via a coordinate point on the map
|
|
29720
|
+
* @param coordinates - Coordinates array for the search input
|
|
29721
|
+
* @param options - Options parameters for the search
|
|
29722
|
+
* @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates
|
|
29723
|
+
*/
|
|
29724
|
+
|
|
29725
|
+
|
|
29726
|
+
AmazonLocationServiceProvider.prototype.searchByCoordinates = function (coordinates, options) {
|
|
29727
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29728
|
+
var credentialsOK, locationServiceInput, client, command, response, error_3, PascalResults, results;
|
|
29729
|
+
return __generator(this, function (_a) {
|
|
29730
|
+
switch (_a.label) {
|
|
29731
|
+
case 0:
|
|
29732
|
+
return [4
|
|
29733
|
+
/*yield*/
|
|
29734
|
+
, this._ensureCredentials()];
|
|
29735
|
+
|
|
29736
|
+
case 1:
|
|
29737
|
+
credentialsOK = _a.sent();
|
|
29738
|
+
|
|
29739
|
+
if (!credentialsOK) {
|
|
29740
|
+
throw new Error('No credentials');
|
|
29741
|
+
}
|
|
29742
|
+
|
|
29743
|
+
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
29744
|
+
|
|
29745
|
+
locationServiceInput = {
|
|
29746
|
+
Position: coordinates,
|
|
29747
|
+
IndexName: this._config.search_indices["default"]
|
|
29748
|
+
};
|
|
29749
|
+
|
|
29750
|
+
if (options) {
|
|
29751
|
+
if (options.searchIndexName) {
|
|
29752
|
+
locationServiceInput.IndexName = options.searchIndexName;
|
|
29753
|
+
}
|
|
29754
|
+
|
|
29755
|
+
locationServiceInput.MaxResults = options.maxResults;
|
|
29756
|
+
}
|
|
29757
|
+
|
|
29758
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
29759
|
+
credentials: this._config.credentials,
|
|
29760
|
+
region: this._config.region,
|
|
29761
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
29762
|
+
});
|
|
29763
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["SearchPlaceIndexForPositionCommand"](locationServiceInput);
|
|
29764
|
+
_a.label = 2;
|
|
29765
|
+
|
|
29766
|
+
case 2:
|
|
29767
|
+
_a.trys.push([2, 4,, 5]);
|
|
29768
|
+
|
|
29769
|
+
return [4
|
|
29770
|
+
/*yield*/
|
|
29771
|
+
, client.send(command)];
|
|
29772
|
+
|
|
29773
|
+
case 3:
|
|
29774
|
+
response = _a.sent();
|
|
29775
|
+
return [3
|
|
29776
|
+
/*break*/
|
|
29777
|
+
, 5];
|
|
29778
|
+
|
|
29779
|
+
case 4:
|
|
29780
|
+
error_3 = _a.sent();
|
|
29781
|
+
logger.debug(error_3);
|
|
29782
|
+
throw error_3;
|
|
28318
29783
|
|
|
28319
29784
|
case 5:
|
|
28320
29785
|
PascalResults = response.Results.map(function (result) {
|
|
28321
29786
|
return result.Place;
|
|
28322
29787
|
});
|
|
28323
|
-
results = camelcase_keys__WEBPACK_IMPORTED_MODULE_0___default()(PascalResults, {
|
|
29788
|
+
results = camelcase_keys__WEBPACK_IMPORTED_MODULE_0___default()(PascalResults[0], {
|
|
28324
29789
|
deep: true
|
|
28325
29790
|
});
|
|
28326
29791
|
return [2
|
|
28327
29792
|
/*return*/
|
|
28328
|
-
, results];
|
|
29793
|
+
, results];
|
|
29794
|
+
}
|
|
29795
|
+
});
|
|
29796
|
+
});
|
|
29797
|
+
};
|
|
29798
|
+
/**
|
|
29799
|
+
* Create geofences inside of a geofence collection
|
|
29800
|
+
* @param geofences - Array of geofence objects to create
|
|
29801
|
+
* @param options? - Optional parameters for creating geofences
|
|
29802
|
+
* @returns {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
|
|
29803
|
+
* successes: list of geofences successfully created
|
|
29804
|
+
* errors: list of geofences that failed to create
|
|
29805
|
+
*/
|
|
29806
|
+
|
|
29807
|
+
|
|
29808
|
+
AmazonLocationServiceProvider.prototype.saveGeofences = function (geofences, options) {
|
|
29809
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29810
|
+
var credentialsOK, PascalGeofences, results, batches;
|
|
29811
|
+
|
|
29812
|
+
var _this = this;
|
|
29813
|
+
|
|
29814
|
+
return __generator(this, function (_a) {
|
|
29815
|
+
switch (_a.label) {
|
|
29816
|
+
case 0:
|
|
29817
|
+
return [4
|
|
29818
|
+
/*yield*/
|
|
29819
|
+
, this._ensureCredentials()];
|
|
29820
|
+
|
|
29821
|
+
case 1:
|
|
29822
|
+
credentialsOK = _a.sent();
|
|
29823
|
+
|
|
29824
|
+
if (!credentialsOK) {
|
|
29825
|
+
throw new Error('No credentials');
|
|
29826
|
+
} // Verify geofence collection exists in aws-config.js
|
|
29827
|
+
|
|
29828
|
+
|
|
29829
|
+
try {
|
|
29830
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
29831
|
+
} catch (error) {
|
|
29832
|
+
logger.debug(error);
|
|
29833
|
+
throw error;
|
|
29834
|
+
}
|
|
29835
|
+
|
|
29836
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofencesInput"])(geofences);
|
|
29837
|
+
PascalGeofences = geofences.map(function (_a) {
|
|
29838
|
+
var geofenceId = _a.geofenceId,
|
|
29839
|
+
polygon = _a.geometry.polygon;
|
|
29840
|
+
return {
|
|
29841
|
+
GeofenceId: geofenceId,
|
|
29842
|
+
Geometry: {
|
|
29843
|
+
Polygon: polygon
|
|
29844
|
+
}
|
|
29845
|
+
};
|
|
29846
|
+
});
|
|
29847
|
+
results = {
|
|
29848
|
+
successes: [],
|
|
29849
|
+
errors: []
|
|
29850
|
+
};
|
|
29851
|
+
batches = [];
|
|
29852
|
+
|
|
29853
|
+
while (PascalGeofences.length > 0) {
|
|
29854
|
+
// Splice off 10 geofences from input clone due to Amazon Location Service API limit
|
|
29855
|
+
batches.push(PascalGeofences.splice(0, 10));
|
|
29856
|
+
}
|
|
29857
|
+
|
|
29858
|
+
return [4
|
|
29859
|
+
/*yield*/
|
|
29860
|
+
, Promise.all(batches.map(function (batch) {
|
|
29861
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
29862
|
+
var response, error_4;
|
|
29863
|
+
return __generator(this, function (_a) {
|
|
29864
|
+
switch (_a.label) {
|
|
29865
|
+
case 0:
|
|
29866
|
+
_a.trys.push([0, 2,, 3]);
|
|
29867
|
+
|
|
29868
|
+
return [4
|
|
29869
|
+
/*yield*/
|
|
29870
|
+
, this._AmazonLocationServiceBatchPutGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"])];
|
|
29871
|
+
|
|
29872
|
+
case 1:
|
|
29873
|
+
response = _a.sent();
|
|
29874
|
+
return [3
|
|
29875
|
+
/*break*/
|
|
29876
|
+
, 3];
|
|
29877
|
+
|
|
29878
|
+
case 2:
|
|
29879
|
+
error_4 = _a.sent(); // If the API call fails, add the geofences to the errors array and move to next batch
|
|
29880
|
+
|
|
29881
|
+
batch.forEach(function (geofence) {
|
|
29882
|
+
results.errors.push({
|
|
29883
|
+
geofenceId: geofence.GeofenceId,
|
|
29884
|
+
error: {
|
|
29885
|
+
code: 'APIConnectionError',
|
|
29886
|
+
message: error_4.message
|
|
29887
|
+
}
|
|
29888
|
+
});
|
|
29889
|
+
});
|
|
29890
|
+
return [2
|
|
29891
|
+
/*return*/
|
|
29892
|
+
];
|
|
29893
|
+
|
|
29894
|
+
case 3:
|
|
29895
|
+
// Push all successes to results
|
|
29896
|
+
response.Successes.forEach(function (success) {
|
|
29897
|
+
var GeofenceId = success.GeofenceId,
|
|
29898
|
+
CreateTime = success.CreateTime,
|
|
29899
|
+
UpdateTime = success.UpdateTime;
|
|
29900
|
+
results.successes.push({
|
|
29901
|
+
geofenceId: GeofenceId,
|
|
29902
|
+
createTime: CreateTime,
|
|
29903
|
+
updateTime: UpdateTime
|
|
29904
|
+
});
|
|
29905
|
+
}); // Push all errors to results
|
|
29906
|
+
|
|
29907
|
+
response.Errors.forEach(function (error) {
|
|
29908
|
+
var _a = error.Error,
|
|
29909
|
+
Code = _a.Code,
|
|
29910
|
+
Message = _a.Message,
|
|
29911
|
+
GeofenceId = error.GeofenceId;
|
|
29912
|
+
results.errors.push({
|
|
29913
|
+
error: {
|
|
29914
|
+
code: Code,
|
|
29915
|
+
message: Message
|
|
29916
|
+
},
|
|
29917
|
+
geofenceId: GeofenceId
|
|
29918
|
+
});
|
|
29919
|
+
});
|
|
29920
|
+
return [2
|
|
29921
|
+
/*return*/
|
|
29922
|
+
];
|
|
29923
|
+
}
|
|
29924
|
+
});
|
|
29925
|
+
});
|
|
29926
|
+
}))];
|
|
29927
|
+
|
|
29928
|
+
case 2:
|
|
29929
|
+
_a.sent();
|
|
29930
|
+
|
|
29931
|
+
return [2
|
|
29932
|
+
/*return*/
|
|
29933
|
+
, results];
|
|
29934
|
+
}
|
|
29935
|
+
});
|
|
29936
|
+
});
|
|
29937
|
+
};
|
|
29938
|
+
/**
|
|
29939
|
+
* Get geofence from a geofence collection
|
|
29940
|
+
* @param geofenceId:string
|
|
29941
|
+
* @param options?: Optional parameters for getGeofence
|
|
29942
|
+
* @returns {Promise<AmazonLocationServiceGeofence>} - Promise that resolves to a geofence object
|
|
29943
|
+
*/
|
|
29944
|
+
|
|
29945
|
+
|
|
29946
|
+
AmazonLocationServiceProvider.prototype.getGeofence = function (geofenceId, options) {
|
|
29947
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29948
|
+
var credentialsOK, client, commandInput, command, response, error_5, GeofenceId, CreateTime, UpdateTime, Status, Geometry, geofence;
|
|
29949
|
+
return __generator(this, function (_a) {
|
|
29950
|
+
switch (_a.label) {
|
|
29951
|
+
case 0:
|
|
29952
|
+
return [4
|
|
29953
|
+
/*yield*/
|
|
29954
|
+
, this._ensureCredentials()];
|
|
29955
|
+
|
|
29956
|
+
case 1:
|
|
29957
|
+
credentialsOK = _a.sent();
|
|
29958
|
+
|
|
29959
|
+
if (!credentialsOK) {
|
|
29960
|
+
throw new Error('No credentials');
|
|
29961
|
+
} // Verify geofence collection exists in aws-config.js
|
|
29962
|
+
|
|
29963
|
+
|
|
29964
|
+
try {
|
|
29965
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
29966
|
+
} catch (error) {
|
|
29967
|
+
logger.debug(error);
|
|
29968
|
+
throw error;
|
|
29969
|
+
}
|
|
29970
|
+
|
|
29971
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofenceId"])(geofenceId);
|
|
29972
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
29973
|
+
credentials: this._config.credentials,
|
|
29974
|
+
region: this._config.region,
|
|
29975
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
29976
|
+
});
|
|
29977
|
+
commandInput = {
|
|
29978
|
+
GeofenceId: geofenceId,
|
|
29979
|
+
CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"]
|
|
29980
|
+
};
|
|
29981
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["GetGeofenceCommand"](commandInput);
|
|
29982
|
+
_a.label = 2;
|
|
29983
|
+
|
|
29984
|
+
case 2:
|
|
29985
|
+
_a.trys.push([2, 4,, 5]);
|
|
29986
|
+
|
|
29987
|
+
return [4
|
|
29988
|
+
/*yield*/
|
|
29989
|
+
, client.send(command)];
|
|
29990
|
+
|
|
29991
|
+
case 3:
|
|
29992
|
+
response = _a.sent();
|
|
29993
|
+
return [3
|
|
29994
|
+
/*break*/
|
|
29995
|
+
, 5];
|
|
29996
|
+
|
|
29997
|
+
case 4:
|
|
29998
|
+
error_5 = _a.sent();
|
|
29999
|
+
logger.debug(error_5);
|
|
30000
|
+
throw error_5;
|
|
30001
|
+
|
|
30002
|
+
case 5:
|
|
30003
|
+
GeofenceId = response.GeofenceId, CreateTime = response.CreateTime, UpdateTime = response.UpdateTime, Status = response.Status, Geometry = response.Geometry;
|
|
30004
|
+
geofence = {
|
|
30005
|
+
createTime: CreateTime,
|
|
30006
|
+
geofenceId: GeofenceId,
|
|
30007
|
+
geometry: {
|
|
30008
|
+
polygon: Geometry.Polygon
|
|
30009
|
+
},
|
|
30010
|
+
status: Status,
|
|
30011
|
+
updateTime: UpdateTime
|
|
30012
|
+
};
|
|
30013
|
+
return [2
|
|
30014
|
+
/*return*/
|
|
30015
|
+
, geofence];
|
|
28329
30016
|
}
|
|
28330
30017
|
});
|
|
28331
30018
|
});
|
|
28332
30019
|
};
|
|
28333
30020
|
/**
|
|
28334
|
-
*
|
|
28335
|
-
* @param
|
|
28336
|
-
* @
|
|
28337
|
-
*
|
|
30021
|
+
* List geofences from a geofence collection
|
|
30022
|
+
* @param options?: ListGeofenceOptions
|
|
30023
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
30024
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
30025
|
+
* nextToken: token for next page of geofences
|
|
28338
30026
|
*/
|
|
28339
30027
|
|
|
28340
30028
|
|
|
28341
|
-
AmazonLocationServiceProvider.prototype.
|
|
30029
|
+
AmazonLocationServiceProvider.prototype.listGeofences = function (options) {
|
|
28342
30030
|
return __awaiter(this, void 0, void 0, function () {
|
|
28343
|
-
var credentialsOK,
|
|
30031
|
+
var credentialsOK, client, listGeofencesInput, command, response, error_6, NextToken, Entries, results;
|
|
28344
30032
|
return __generator(this, function (_a) {
|
|
28345
30033
|
switch (_a.label) {
|
|
28346
30034
|
case 0:
|
|
@@ -28353,37 +30041,14 @@ function () {
|
|
|
28353
30041
|
|
|
28354
30042
|
if (!credentialsOK) {
|
|
28355
30043
|
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
|
-
}
|
|
30044
|
+
} // Verify geofence collection exists in aws-config.js
|
|
28379
30045
|
|
|
28380
|
-
if (options['biasPosition']) {
|
|
28381
|
-
locationServiceInput.BiasPosition = options['biasPosition'];
|
|
28382
|
-
}
|
|
28383
30046
|
|
|
28384
|
-
|
|
28385
|
-
|
|
28386
|
-
|
|
30047
|
+
try {
|
|
30048
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
30049
|
+
} catch (error) {
|
|
30050
|
+
logger.debug(error);
|
|
30051
|
+
throw error;
|
|
28387
30052
|
}
|
|
28388
30053
|
|
|
28389
30054
|
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
@@ -28391,7 +30056,11 @@ function () {
|
|
|
28391
30056
|
region: this._config.region,
|
|
28392
30057
|
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
28393
30058
|
});
|
|
28394
|
-
|
|
30059
|
+
listGeofencesInput = {
|
|
30060
|
+
NextToken: options === null || options === void 0 ? void 0 : options.nextToken,
|
|
30061
|
+
CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"]
|
|
30062
|
+
};
|
|
30063
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["ListGeofencesCommand"](listGeofencesInput);
|
|
28395
30064
|
_a.label = 2;
|
|
28396
30065
|
|
|
28397
30066
|
case 2:
|
|
@@ -28408,14 +30077,31 @@ function () {
|
|
|
28408
30077
|
, 5];
|
|
28409
30078
|
|
|
28410
30079
|
case 4:
|
|
28411
|
-
|
|
28412
|
-
logger.debug(
|
|
28413
|
-
throw
|
|
30080
|
+
error_6 = _a.sent();
|
|
30081
|
+
logger.debug(error_6);
|
|
30082
|
+
throw error_6;
|
|
28414
30083
|
|
|
28415
30084
|
case 5:
|
|
28416
|
-
|
|
28417
|
-
|
|
28418
|
-
|
|
30085
|
+
NextToken = response.NextToken, Entries = response.Entries;
|
|
30086
|
+
results = {
|
|
30087
|
+
entries: Entries.map(function (_a) {
|
|
30088
|
+
var GeofenceId = _a.GeofenceId,
|
|
30089
|
+
CreateTime = _a.CreateTime,
|
|
30090
|
+
UpdateTime = _a.UpdateTime,
|
|
30091
|
+
Status = _a.Status,
|
|
30092
|
+
Polygon = _a.Geometry.Polygon;
|
|
30093
|
+
return {
|
|
30094
|
+
geofenceId: GeofenceId,
|
|
30095
|
+
createTime: CreateTime,
|
|
30096
|
+
updateTime: UpdateTime,
|
|
30097
|
+
status: Status,
|
|
30098
|
+
geometry: {
|
|
30099
|
+
polygon: Polygon
|
|
30100
|
+
}
|
|
30101
|
+
};
|
|
30102
|
+
}),
|
|
30103
|
+
nextToken: NextToken
|
|
30104
|
+
};
|
|
28419
30105
|
return [2
|
|
28420
30106
|
/*return*/
|
|
28421
30107
|
, results];
|
|
@@ -28424,16 +30110,21 @@ function () {
|
|
|
28424
30110
|
});
|
|
28425
30111
|
};
|
|
28426
30112
|
/**
|
|
28427
|
-
*
|
|
28428
|
-
* @param
|
|
28429
|
-
* @param options
|
|
28430
|
-
* @returns {Promise<
|
|
30113
|
+
* Delete geofences from a geofence collection
|
|
30114
|
+
* @param geofenceIds: string|string[]
|
|
30115
|
+
* @param options?: GeofenceOptions
|
|
30116
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
30117
|
+
* successes: list of geofences successfully deleted
|
|
30118
|
+
* errors: list of geofences that failed to delete
|
|
28431
30119
|
*/
|
|
28432
30120
|
|
|
28433
30121
|
|
|
28434
|
-
AmazonLocationServiceProvider.prototype.
|
|
30122
|
+
AmazonLocationServiceProvider.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
28435
30123
|
return __awaiter(this, void 0, void 0, function () {
|
|
28436
|
-
var credentialsOK,
|
|
30124
|
+
var credentialsOK, badGeofenceIds, results, batches, count;
|
|
30125
|
+
|
|
30126
|
+
var _this = this;
|
|
30127
|
+
|
|
28437
30128
|
return __generator(this, function (_a) {
|
|
28438
30129
|
switch (_a.label) {
|
|
28439
30130
|
case 0:
|
|
@@ -28448,54 +30139,92 @@ function () {
|
|
|
28448
30139
|
throw new Error('No credentials');
|
|
28449
30140
|
}
|
|
28450
30141
|
|
|
28451
|
-
this.
|
|
28452
|
-
|
|
28453
|
-
locationServiceInput = {
|
|
28454
|
-
Position: coordinates,
|
|
28455
|
-
IndexName: this._config.search_indices["default"]
|
|
28456
|
-
};
|
|
30142
|
+
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
28457
30143
|
|
|
28458
|
-
|
|
28459
|
-
|
|
28460
|
-
|
|
30144
|
+
badGeofenceIds = geofenceIds.filter(function (geofenceId) {
|
|
30145
|
+
try {
|
|
30146
|
+
Object(_util__WEBPACK_IMPORTED_MODULE_3__["validateGeofenceId"])(geofenceId);
|
|
30147
|
+
} catch (error) {
|
|
30148
|
+
return true;
|
|
28461
30149
|
}
|
|
30150
|
+
});
|
|
28462
30151
|
|
|
28463
|
-
|
|
30152
|
+
if (badGeofenceIds.length > 0) {
|
|
30153
|
+
throw new Error("Invalid geofence ids: " + badGeofenceIds.join(', '));
|
|
28464
30154
|
}
|
|
28465
30155
|
|
|
28466
|
-
|
|
28467
|
-
|
|
28468
|
-
|
|
28469
|
-
|
|
28470
|
-
|
|
28471
|
-
|
|
28472
|
-
_a.label = 2;
|
|
30156
|
+
results = {
|
|
30157
|
+
successes: [],
|
|
30158
|
+
errors: []
|
|
30159
|
+
};
|
|
30160
|
+
batches = [];
|
|
30161
|
+
count = 0;
|
|
28473
30162
|
|
|
28474
|
-
|
|
28475
|
-
|
|
30163
|
+
while (count < geofenceIds.length) {
|
|
30164
|
+
batches.push(geofenceIds.slice(count, count += 10));
|
|
30165
|
+
}
|
|
28476
30166
|
|
|
28477
30167
|
return [4
|
|
28478
30168
|
/*yield*/
|
|
28479
|
-
,
|
|
30169
|
+
, Promise.all(batches.map(function (batch) {
|
|
30170
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
30171
|
+
var response, error_7, badGeofenceIds;
|
|
28480
30172
|
|
|
28481
|
-
|
|
28482
|
-
response = _a.sent();
|
|
28483
|
-
return [3
|
|
28484
|
-
/*break*/
|
|
28485
|
-
, 5];
|
|
30173
|
+
var _a;
|
|
28486
30174
|
|
|
28487
|
-
|
|
28488
|
-
|
|
28489
|
-
|
|
28490
|
-
|
|
30175
|
+
return __generator(this, function (_b) {
|
|
30176
|
+
switch (_b.label) {
|
|
30177
|
+
case 0:
|
|
30178
|
+
_b.trys.push([0, 2,, 3]);
|
|
30179
|
+
|
|
30180
|
+
return [4
|
|
30181
|
+
/*yield*/
|
|
30182
|
+
, this._AmazonLocationServiceBatchDeleteGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"])];
|
|
30183
|
+
|
|
30184
|
+
case 1:
|
|
30185
|
+
response = _b.sent();
|
|
30186
|
+
return [3
|
|
30187
|
+
/*break*/
|
|
30188
|
+
, 3];
|
|
30189
|
+
|
|
30190
|
+
case 2:
|
|
30191
|
+
error_7 = _b.sent(); // If the API call fails, add the geofences to the errors array and move to next batch
|
|
30192
|
+
|
|
30193
|
+
batch.forEach(function (geofenceId) {
|
|
30194
|
+
var errorObject = {
|
|
30195
|
+
geofenceId: geofenceId,
|
|
30196
|
+
error: {
|
|
30197
|
+
code: error_7.message,
|
|
30198
|
+
message: error_7.message
|
|
30199
|
+
}
|
|
30200
|
+
};
|
|
30201
|
+
results.errors.push(errorObject);
|
|
30202
|
+
});
|
|
30203
|
+
return [2
|
|
30204
|
+
/*return*/
|
|
30205
|
+
];
|
|
30206
|
+
|
|
30207
|
+
case 3:
|
|
30208
|
+
badGeofenceIds = response.Errors.map(function (_a) {
|
|
30209
|
+
var geofenceId = _a.geofenceId;
|
|
30210
|
+
return geofenceId;
|
|
30211
|
+
});
|
|
30212
|
+
|
|
30213
|
+
(_a = results.successes).push.apply(_a, __spread(batch.filter(function (Id) {
|
|
30214
|
+
return !badGeofenceIds.includes(Id);
|
|
30215
|
+
})));
|
|
30216
|
+
|
|
30217
|
+
return [2
|
|
30218
|
+
/*return*/
|
|
30219
|
+
];
|
|
30220
|
+
}
|
|
30221
|
+
});
|
|
30222
|
+
});
|
|
30223
|
+
}))];
|
|
30224
|
+
|
|
30225
|
+
case 2:
|
|
30226
|
+
_a.sent();
|
|
28491
30227
|
|
|
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
30228
|
return [2
|
|
28500
30229
|
/*return*/
|
|
28501
30230
|
, results];
|
|
@@ -28510,7 +30239,7 @@ function () {
|
|
|
28510
30239
|
|
|
28511
30240
|
AmazonLocationServiceProvider.prototype._ensureCredentials = function () {
|
|
28512
30241
|
return __awaiter(this, void 0, void 0, function () {
|
|
28513
|
-
var credentials, cred,
|
|
30242
|
+
var credentials, cred, error_8;
|
|
28514
30243
|
return __generator(this, function (_a) {
|
|
28515
30244
|
switch (_a.label) {
|
|
28516
30245
|
case 0:
|
|
@@ -28533,8 +30262,8 @@ function () {
|
|
|
28533
30262
|
, true];
|
|
28534
30263
|
|
|
28535
30264
|
case 2:
|
|
28536
|
-
|
|
28537
|
-
logger.
|
|
30265
|
+
error_8 = _a.sent();
|
|
30266
|
+
logger.debug('Ensure credentials error. Credentials are:', error_8);
|
|
28538
30267
|
return [2
|
|
28539
30268
|
/*return*/
|
|
28540
30269
|
, false];
|
|
@@ -28550,26 +30279,122 @@ function () {
|
|
|
28550
30279
|
|
|
28551
30280
|
AmazonLocationServiceProvider.prototype._verifyMapResources = function () {
|
|
28552
30281
|
if (!this._config.maps) {
|
|
28553
|
-
var errorString = "No map resources found in amplify config, run 'amplify add geo' to create
|
|
28554
|
-
logger.
|
|
30282
|
+
var errorString = "No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
30283
|
+
logger.debug(errorString);
|
|
28555
30284
|
throw new Error(errorString);
|
|
28556
30285
|
}
|
|
28557
30286
|
|
|
28558
30287
|
if (!this._config.maps["default"]) {
|
|
28559
30288
|
var errorString = "No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
28560
|
-
logger.
|
|
30289
|
+
logger.debug(errorString);
|
|
28561
30290
|
throw new Error(errorString);
|
|
28562
30291
|
}
|
|
28563
30292
|
};
|
|
28564
30293
|
|
|
28565
30294
|
AmazonLocationServiceProvider.prototype._verifySearchIndex = function (optionalSearchIndex) {
|
|
28566
30295
|
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.
|
|
30296
|
+
var errorString = 'No Search Index found in amplify config, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
30297
|
+
logger.debug(errorString);
|
|
30298
|
+
throw new Error(errorString);
|
|
30299
|
+
}
|
|
30300
|
+
};
|
|
30301
|
+
|
|
30302
|
+
AmazonLocationServiceProvider.prototype._verifyGeofenceCollections = function (optionalGeofenceCollectionName) {
|
|
30303
|
+
if ((!this._config.geofenceCollections || !this._config.geofenceCollections["default"]) && !optionalGeofenceCollectionName) {
|
|
30304
|
+
var errorString = 'No Geofence Collections found, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
30305
|
+
logger.debug(errorString);
|
|
28569
30306
|
throw new Error(errorString);
|
|
28570
30307
|
}
|
|
28571
30308
|
};
|
|
28572
30309
|
|
|
30310
|
+
AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchPutGeofenceCall = function (PascalGeofences, collectionName) {
|
|
30311
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30312
|
+
var geofenceInput, client, command, response, error_9;
|
|
30313
|
+
return __generator(this, function (_a) {
|
|
30314
|
+
switch (_a.label) {
|
|
30315
|
+
case 0:
|
|
30316
|
+
geofenceInput = {
|
|
30317
|
+
Entries: PascalGeofences,
|
|
30318
|
+
CollectionName: collectionName || this._config.geofenceCollections["default"]
|
|
30319
|
+
};
|
|
30320
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
30321
|
+
credentials: this._config.credentials,
|
|
30322
|
+
region: this._config.region,
|
|
30323
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
30324
|
+
});
|
|
30325
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["BatchPutGeofenceCommand"](geofenceInput);
|
|
30326
|
+
_a.label = 1;
|
|
30327
|
+
|
|
30328
|
+
case 1:
|
|
30329
|
+
_a.trys.push([1, 3,, 4]);
|
|
30330
|
+
|
|
30331
|
+
return [4
|
|
30332
|
+
/*yield*/
|
|
30333
|
+
, client.send(command)];
|
|
30334
|
+
|
|
30335
|
+
case 2:
|
|
30336
|
+
response = _a.sent();
|
|
30337
|
+
return [3
|
|
30338
|
+
/*break*/
|
|
30339
|
+
, 4];
|
|
30340
|
+
|
|
30341
|
+
case 3:
|
|
30342
|
+
error_9 = _a.sent();
|
|
30343
|
+
throw error_9;
|
|
30344
|
+
|
|
30345
|
+
case 4:
|
|
30346
|
+
return [2
|
|
30347
|
+
/*return*/
|
|
30348
|
+
, response];
|
|
30349
|
+
}
|
|
30350
|
+
});
|
|
30351
|
+
});
|
|
30352
|
+
};
|
|
30353
|
+
|
|
30354
|
+
AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchDeleteGeofenceCall = function (geofenceIds, collectionName) {
|
|
30355
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30356
|
+
var deleteGeofencesInput, client, command, response, error_10;
|
|
30357
|
+
return __generator(this, function (_a) {
|
|
30358
|
+
switch (_a.label) {
|
|
30359
|
+
case 0:
|
|
30360
|
+
deleteGeofencesInput = {
|
|
30361
|
+
GeofenceIds: geofenceIds,
|
|
30362
|
+
CollectionName: collectionName || this._config.geofenceCollections["default"]
|
|
30363
|
+
};
|
|
30364
|
+
client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
|
|
30365
|
+
credentials: this._config.credentials,
|
|
30366
|
+
region: this._config.region,
|
|
30367
|
+
customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
|
|
30368
|
+
});
|
|
30369
|
+
command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["BatchDeleteGeofenceCommand"](deleteGeofencesInput);
|
|
30370
|
+
_a.label = 1;
|
|
30371
|
+
|
|
30372
|
+
case 1:
|
|
30373
|
+
_a.trys.push([1, 3,, 4]);
|
|
30374
|
+
|
|
30375
|
+
return [4
|
|
30376
|
+
/*yield*/
|
|
30377
|
+
, client.send(command)];
|
|
30378
|
+
|
|
30379
|
+
case 2:
|
|
30380
|
+
response = _a.sent();
|
|
30381
|
+
return [3
|
|
30382
|
+
/*break*/
|
|
30383
|
+
, 4];
|
|
30384
|
+
|
|
30385
|
+
case 3:
|
|
30386
|
+
error_10 = _a.sent();
|
|
30387
|
+
throw error_10;
|
|
30388
|
+
|
|
30389
|
+
case 4:
|
|
30390
|
+
return [2
|
|
30391
|
+
/*return*/
|
|
30392
|
+
, response];
|
|
30393
|
+
}
|
|
30394
|
+
});
|
|
30395
|
+
});
|
|
30396
|
+
};
|
|
30397
|
+
|
|
28573
30398
|
AmazonLocationServiceProvider.CATEGORY = 'Geo';
|
|
28574
30399
|
AmazonLocationServiceProvider.PROVIDER_NAME = 'AmazonLocationService';
|
|
28575
30400
|
return AmazonLocationServiceProvider;
|
|
@@ -28593,6 +30418,190 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
28593
30418
|
|
|
28594
30419
|
|
|
28595
30420
|
|
|
30421
|
+
/***/ }),
|
|
30422
|
+
|
|
30423
|
+
/***/ "./lib-esm/util.js":
|
|
30424
|
+
/*!*************************!*\
|
|
30425
|
+
!*** ./lib-esm/util.js ***!
|
|
30426
|
+
\*************************/
|
|
30427
|
+
/*! exports provided: validateCoordinates, validateGeofenceId, validateLinearRing, validatePolygon, validateGeofencesInput */
|
|
30428
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
30429
|
+
|
|
30430
|
+
"use strict";
|
|
30431
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30432
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateCoordinates", function() { return validateCoordinates; });
|
|
30433
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofenceId", function() { return validateGeofenceId; });
|
|
30434
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateLinearRing", function() { return validateLinearRing; });
|
|
30435
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validatePolygon", function() { return validatePolygon; });
|
|
30436
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofencesInput", function() { return validateGeofencesInput; });
|
|
30437
|
+
/* harmony import */ var _turf_boolean_clockwise__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @turf/boolean-clockwise */ "../../node_modules/@turf/boolean-clockwise/dist/es/index.js");
|
|
30438
|
+
var __read = undefined && undefined.__read || function (o, n) {
|
|
30439
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30440
|
+
if (!m) return o;
|
|
30441
|
+
var i = m.call(o),
|
|
30442
|
+
r,
|
|
30443
|
+
ar = [],
|
|
30444
|
+
e;
|
|
30445
|
+
|
|
30446
|
+
try {
|
|
30447
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
30448
|
+
ar.push(r.value);
|
|
30449
|
+
}
|
|
30450
|
+
} catch (error) {
|
|
30451
|
+
e = {
|
|
30452
|
+
error: error
|
|
30453
|
+
};
|
|
30454
|
+
} finally {
|
|
30455
|
+
try {
|
|
30456
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
30457
|
+
} finally {
|
|
30458
|
+
if (e) throw e.error;
|
|
30459
|
+
}
|
|
30460
|
+
}
|
|
30461
|
+
|
|
30462
|
+
return ar;
|
|
30463
|
+
};
|
|
30464
|
+
/*
|
|
30465
|
+
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
30466
|
+
*
|
|
30467
|
+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
30468
|
+
* the License. A copy of the License is located at
|
|
30469
|
+
*
|
|
30470
|
+
* http://aws.amazon.com/apache2.0/
|
|
30471
|
+
*
|
|
30472
|
+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
30473
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
30474
|
+
* and limitations under the License.
|
|
30475
|
+
*/
|
|
30476
|
+
|
|
30477
|
+
|
|
30478
|
+
|
|
30479
|
+
function validateCoordinates(lng, lat) {
|
|
30480
|
+
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
30481
|
+
throw new Error("Invalid coordinates: [" + lng + "," + lat + "]");
|
|
30482
|
+
}
|
|
30483
|
+
|
|
30484
|
+
if (lat < -90 || lat > 90) {
|
|
30485
|
+
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
30486
|
+
} else if (lng < -180 || lng > 180) {
|
|
30487
|
+
throw new Error('Longitude must be between -180 and 180 degrees inclusive.');
|
|
30488
|
+
}
|
|
30489
|
+
}
|
|
30490
|
+
function validateGeofenceId(geofenceId) {
|
|
30491
|
+
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
|
|
30492
|
+
|
|
30493
|
+
if (!geofenceIdRegex.test(geofenceId)) {
|
|
30494
|
+
throw new Error("Invalid geofenceId: '" + geofenceId + "' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.");
|
|
30495
|
+
}
|
|
30496
|
+
}
|
|
30497
|
+
function validateLinearRing(linearRing, geofenceId) {
|
|
30498
|
+
// Validate LinearRing size, must be at least 4 points
|
|
30499
|
+
if (linearRing.length < 4) {
|
|
30500
|
+
throw new Error(geofenceId + ": LinearRing must contain 4 or more coordinates.");
|
|
30501
|
+
} // Validate all coordinates are valid, error with which ones are bad
|
|
30502
|
+
|
|
30503
|
+
|
|
30504
|
+
var badCoordinates = [];
|
|
30505
|
+
linearRing.forEach(function (coordinates) {
|
|
30506
|
+
try {
|
|
30507
|
+
validateCoordinates(coordinates[0], coordinates[1]);
|
|
30508
|
+
} catch (error) {
|
|
30509
|
+
badCoordinates.push({
|
|
30510
|
+
coordinates: coordinates,
|
|
30511
|
+
error: error.message
|
|
30512
|
+
});
|
|
30513
|
+
}
|
|
30514
|
+
});
|
|
30515
|
+
|
|
30516
|
+
if (badCoordinates.length > 0) {
|
|
30517
|
+
throw new Error(geofenceId + ": One or more of the coordinates in the Polygon LinearRing are not valid: " + JSON.stringify(badCoordinates));
|
|
30518
|
+
} // Validate first and last coordinates are the same
|
|
30519
|
+
|
|
30520
|
+
|
|
30521
|
+
var _a = __read(linearRing[0], 2),
|
|
30522
|
+
lngA = _a[0],
|
|
30523
|
+
latA = _a[1];
|
|
30524
|
+
|
|
30525
|
+
var _b = __read(linearRing[linearRing.length - 1], 2),
|
|
30526
|
+
lngB = _b[0],
|
|
30527
|
+
latB = _b[1];
|
|
30528
|
+
|
|
30529
|
+
if (lngA !== lngB || latA !== latB) {
|
|
30530
|
+
throw new Error(geofenceId + ": LinearRing's first and last coordinates are not the same");
|
|
30531
|
+
}
|
|
30532
|
+
|
|
30533
|
+
if (Object(_turf_boolean_clockwise__WEBPACK_IMPORTED_MODULE_0__["default"])(linearRing)) {
|
|
30534
|
+
throw new Error(geofenceId + ": LinearRing coordinates must be wound counterclockwise");
|
|
30535
|
+
}
|
|
30536
|
+
}
|
|
30537
|
+
function validatePolygon(polygon, geofenceId) {
|
|
30538
|
+
if (!Array.isArray(polygon)) {
|
|
30539
|
+
throw new Error(geofenceId + ": Polygon is of incorrect structure. It should be an array of LinearRings");
|
|
30540
|
+
}
|
|
30541
|
+
|
|
30542
|
+
if (polygon.length < 1) {
|
|
30543
|
+
throw new Error(geofenceId + ": Polygon must have a single LinearRing array.");
|
|
30544
|
+
}
|
|
30545
|
+
|
|
30546
|
+
if (polygon.length > 1) {
|
|
30547
|
+
throw new Error(geofenceId + ": Polygon must have a single LinearRing array. Note: We do not currently support polygons with holes, multipolygons, polygons that are wound clockwise, or that cross the antimeridian.");
|
|
30548
|
+
}
|
|
30549
|
+
|
|
30550
|
+
var verticesCount = polygon.reduce(function (prev, linearRing) {
|
|
30551
|
+
return prev + linearRing.length;
|
|
30552
|
+
}, 0);
|
|
30553
|
+
|
|
30554
|
+
if (verticesCount > 1000) {
|
|
30555
|
+
throw new Error(geofenceId + ": Polygon has more than the maximum 1000 vertices.");
|
|
30556
|
+
}
|
|
30557
|
+
}
|
|
30558
|
+
function validateGeofencesInput(geofences) {
|
|
30559
|
+
var geofenceIds = {};
|
|
30560
|
+
geofences.forEach(function (geofence) {
|
|
30561
|
+
// verify all required properties are present
|
|
30562
|
+
// Validate geofenceId exists
|
|
30563
|
+
if (!geofence.geofenceId) {
|
|
30564
|
+
throw new Error("Geofence '" + geofence + "' is missing geofenceId");
|
|
30565
|
+
}
|
|
30566
|
+
|
|
30567
|
+
var geofenceId = geofence.geofenceId;
|
|
30568
|
+
validateGeofenceId(geofenceId); // Validate geofenceId is unique
|
|
30569
|
+
|
|
30570
|
+
if (geofenceIds[geofenceId]) {
|
|
30571
|
+
throw new Error("Duplicate geofenceId: " + geofenceId);
|
|
30572
|
+
} else {
|
|
30573
|
+
geofenceIds[geofenceId] = true;
|
|
30574
|
+
} // Validate geometry exists
|
|
30575
|
+
|
|
30576
|
+
|
|
30577
|
+
if (!geofence.geometry) {
|
|
30578
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry");
|
|
30579
|
+
}
|
|
30580
|
+
|
|
30581
|
+
var geometry = geofence.geometry; // Validate polygon exists
|
|
30582
|
+
|
|
30583
|
+
if (!geometry.polygon) {
|
|
30584
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry.polygon");
|
|
30585
|
+
}
|
|
30586
|
+
|
|
30587
|
+
var polygon = geometry.polygon; // Validate polygon length and structure
|
|
30588
|
+
|
|
30589
|
+
try {
|
|
30590
|
+
validatePolygon(polygon, geofenceId);
|
|
30591
|
+
} catch (error) {
|
|
30592
|
+
if (error.message === "Polygon has more than the maximum 1000 vertices.") {
|
|
30593
|
+
throw new Error("Geofence '" + geofenceId + "' has more than the maximum of 1000 vertices");
|
|
30594
|
+
}
|
|
30595
|
+
} // Validate LinearRing length, structure, and coordinates
|
|
30596
|
+
|
|
30597
|
+
|
|
30598
|
+
var _a = __read(polygon, 1),
|
|
30599
|
+
linearRing = _a[0];
|
|
30600
|
+
|
|
30601
|
+
validateLinearRing(linearRing, geofenceId);
|
|
30602
|
+
});
|
|
30603
|
+
}
|
|
30604
|
+
|
|
28596
30605
|
/***/ }),
|
|
28597
30606
|
|
|
28598
30607
|
/***/ "@aws-amplify/core":
|