@esri/arcgis-rest-routing 4.0.3 → 4.8.0

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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/dist/bundled/routing.esm.js +15 -11
  3. package/dist/bundled/routing.esm.js.map +1 -1
  4. package/dist/bundled/routing.esm.min.js +8 -8
  5. package/dist/bundled/routing.esm.min.js.map +1 -1
  6. package/dist/bundled/routing.umd.js +686 -684
  7. package/dist/bundled/routing.umd.js.map +1 -1
  8. package/dist/bundled/routing.umd.min.js +8 -8
  9. package/dist/bundled/routing.umd.min.js.map +1 -1
  10. package/dist/cjs/closestFacility.js +3 -3
  11. package/dist/cjs/closestFacility.js.map +1 -1
  12. package/dist/cjs/helpers.js +5 -5
  13. package/dist/cjs/helpers.js.map +1 -1
  14. package/dist/cjs/index.js +5 -5
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/originDestinationMatrix.js +3 -3
  17. package/dist/cjs/originDestinationMatrix.js.map +1 -1
  18. package/dist/cjs/serviceArea.js +3 -3
  19. package/dist/cjs/serviceArea.js.map +1 -1
  20. package/dist/cjs/solveRoute.js +3 -3
  21. package/dist/cjs/solveRoute.js.map +1 -1
  22. package/dist/esm/closestFacility.d.ts +3 -5
  23. package/dist/esm/closestFacility.js +2 -1
  24. package/dist/esm/closestFacility.js.map +1 -1
  25. package/dist/esm/helpers.d.ts +4 -1
  26. package/dist/esm/helpers.js.map +1 -1
  27. package/dist/esm/originDestinationMatrix.d.ts +3 -5
  28. package/dist/esm/originDestinationMatrix.js +2 -1
  29. package/dist/esm/originDestinationMatrix.js.map +1 -1
  30. package/dist/esm/serviceArea.d.ts +3 -5
  31. package/dist/esm/serviceArea.js +2 -1
  32. package/dist/esm/serviceArea.js.map +1 -1
  33. package/dist/esm/solveRoute.d.ts +3 -5
  34. package/dist/esm/solveRoute.js +2 -1
  35. package/dist/esm/solveRoute.js.map +1 -1
  36. package/package.json +2 -2
@@ -1,767 +1,769 @@
1
1
  /* @preserve
2
- * @esri/arcgis-rest-routing - v4.0.2 - Apache-2.0
3
- * Copyright (c) 2017-2022 Esri, Inc.
4
- * Wed Oct 19 2022 03:11:49 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/arcgis-rest-routing - v4.8.0 - Apache-2.0
3
+ * Copyright (c) 2017-2026 Esri, Inc.
4
+ * Fri Jan 16 2026 01:29:33 GMT+0000 (Coordinated Universal Time)
5
5
  */
6
6
  (function (global, factory) {
7
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/arcgis-rest-request')) :
8
- typeof define === 'function' && define.amd ? define(['exports', '@esri/arcgis-rest-request'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisRest = global.arcgisRest || {}, global.arcgisRest));
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/arcgis-rest-request')) :
8
+ typeof define === 'function' && define.amd ? define(['exports', '@esri/arcgis-rest-request'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisRest = global.arcgisRest || {}, global.arcgisRest));
10
10
  })(this, (function (exports, arcgisRestRequest) { 'use strict';
11
11
 
12
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
13
- * Apache-2.0 */
14
- // https always
15
- const ARCGIS_ONLINE_ROUTING_URL = "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
16
- const ARCGIS_ONLINE_CLOSEST_FACILITY_URL = "https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World";
17
- const ARCGIS_ONLINE_SERVICE_AREA_URL = "https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World";
18
- const ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = "https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World";
19
- function isLocationArray$1(coords) {
20
- return (coords.length === 2 ||
21
- coords.length === 3);
22
- }
23
- function isLocation$1(coords) {
24
- return (coords.latitude !== undefined ||
25
- coords.lat !== undefined);
26
- }
27
- function normalizeLocationsList(locations) {
28
- return locations.map((coords) => {
29
- if (isLocationArray$1(coords)) {
30
- return coords.join();
31
- }
32
- else if (isLocation$1(coords)) {
33
- if (coords.lat) {
34
- return coords.long + "," + coords.lat;
35
- }
36
- else {
37
- return coords.longitude + "," + coords.latitude;
38
- }
39
- }
40
- else {
41
- return coords.x + "," + coords.y;
42
- }
43
- });
44
- }
45
- function decompressGeometry(str) {
46
- let xDiffPrev = 0;
47
- let yDiffPrev = 0;
48
- const points = [];
49
- let x;
50
- let y;
51
- // Split the string into an array on the + and - characters
52
- const strings = str.match(/((\+|-)[^+-]+)/g);
53
- // The first value is the coefficient in base 32
54
- const coefficient = parseInt(strings[0], 32);
55
- for (let j = 1; j < strings.length; j += 2) {
56
- // j is the offset for the x value
57
- // Convert the value from base 32 and add the previous x value
58
- x = parseInt(strings[j], 32) + xDiffPrev;
59
- xDiffPrev = x;
60
- // j+1 is the offset for the y value
61
- // Convert the value from base 32 and add the previous y value
62
- y = parseInt(strings[j + 1], 32) + yDiffPrev;
63
- yDiffPrev = y;
64
- points.push([x / coefficient, y / coefficient]);
65
- }
66
- return {
67
- paths: [points]
68
- };
69
- }
70
- /**
71
- * User Defined Type Guard that verifies this is a featureSet
72
- */
73
- function isFeatureSet(arg) {
74
- return Object.prototype.hasOwnProperty.call(arg, "features");
75
- }
76
- /**
77
- * User Defined Type Guard that verifies this is a JSON with `url` property
78
- */
79
- function isJsonWithURL(arg) {
80
- return "url" in arg;
81
- }
82
-
83
- /* @preserve
84
- * @terraformer/arcgis - v2.0.7 - MIT
85
- * Copyright (c) 2012-2021 Environmental Systems Research Institute, Inc.
86
- * Thu Jul 22 2021 13:58:30 GMT-0700 (Pacific Daylight Time)
87
- */
88
- /* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
89
- * Apache-2.0 */
90
-
91
- var edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) {
92
- var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);
93
- var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);
94
- var uB = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);
95
-
96
- if (uB !== 0) {
97
- var ua = uaT / uB;
98
- var ub = ubT / uB;
99
-
100
- if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
101
- return true;
102
- }
12
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
13
+ * Apache-2.0 */
14
+ // https always
15
+ const ARCGIS_ONLINE_ROUTING_URL = "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
16
+ const ARCGIS_ONLINE_CLOSEST_FACILITY_URL = "https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World";
17
+ const ARCGIS_ONLINE_SERVICE_AREA_URL = "https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World";
18
+ const ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = "https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World";
19
+ function isLocationArray$1(coords) {
20
+ return (coords.length === 2 ||
21
+ coords.length === 3);
22
+ }
23
+ function isLocation$1(coords) {
24
+ return (coords.latitude !== undefined ||
25
+ coords.lat !== undefined);
26
+ }
27
+ function normalizeLocationsList(locations) {
28
+ return locations.map((coords) => {
29
+ if (isLocationArray$1(coords)) {
30
+ return coords.join();
31
+ }
32
+ else if (isLocation$1(coords)) {
33
+ if (coords.lat) {
34
+ return coords.long + "," + coords.lat;
35
+ }
36
+ else {
37
+ return coords.longitude + "," + coords.latitude;
38
+ }
39
+ }
40
+ else {
41
+ return coords.x + "," + coords.y;
42
+ }
43
+ });
44
+ }
45
+ function decompressGeometry(str) {
46
+ let xDiffPrev = 0;
47
+ let yDiffPrev = 0;
48
+ const points = [];
49
+ let x;
50
+ let y;
51
+ // Split the string into an array on the + and - characters
52
+ const strings = str.match(/((\+|-)[^+-]+)/g);
53
+ // The first value is the coefficient in base 32
54
+ const coefficient = parseInt(strings[0], 32);
55
+ for (let j = 1; j < strings.length; j += 2) {
56
+ // j is the offset for the x value
57
+ // Convert the value from base 32 and add the previous x value
58
+ x = parseInt(strings[j], 32) + xDiffPrev;
59
+ xDiffPrev = x;
60
+ // j+1 is the offset for the y value
61
+ // Convert the value from base 32 and add the previous y value
62
+ y = parseInt(strings[j + 1], 32) + yDiffPrev;
63
+ yDiffPrev = y;
64
+ points.push([x / coefficient, y / coefficient]);
65
+ }
66
+ return {
67
+ paths: [points]
68
+ };
69
+ }
70
+ /**
71
+ * User Defined Type Guard that verifies this is a featureSet
72
+ */
73
+ function isFeatureSet(arg) {
74
+ return Object.prototype.hasOwnProperty.call(arg, "features");
103
75
  }
76
+ /**
77
+ * User Defined Type Guard that verifies this is a JSON with `url` property
78
+ */
79
+ function isJsonWithURL(arg) {
80
+ return "url" in arg;
81
+ }
82
+
83
+ /* @preserve
84
+ * @terraformer/arcgis - v2.1.1 - MIT
85
+ * Copyright (c) 2012-2022 Environmental Systems Research Institute, Inc.
86
+ * Tue Aug 02 2022 14:23:48 GMT-0700 (Pacific Daylight Time)
87
+ */
88
+ /* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
89
+ * Apache-2.0 */
90
+
91
+ var edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) {
92
+ var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);
93
+ var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);
94
+ var uB = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);
104
95
 
105
- return false;
106
- };
107
- var coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) {
108
- var contains = false;
96
+ if (uB !== 0) {
97
+ var ua = uaT / uB;
98
+ var ub = ubT / uB;
109
99
 
110
- for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {
111
- if ((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1] || coordinates[j][1] <= point[1] && point[1] < coordinates[i][1]) && point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0]) {
112
- contains = !contains;
100
+ if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
101
+ return true;
102
+ }
113
103
  }
114
- }
115
104
 
116
- return contains;
117
- };
118
- var pointsEqual = function pointsEqual(a, b) {
119
- for (var i = 0; i < a.length; i++) {
120
- if (a[i] !== b[i]) {
121
- return false;
105
+ return false;
106
+ };
107
+ var coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) {
108
+ var contains = false;
109
+
110
+ for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {
111
+ if ((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1] || coordinates[j][1] <= point[1] && point[1] < coordinates[i][1]) && point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0]) {
112
+ contains = !contains;
113
+ }
122
114
  }
123
- }
124
115
 
125
- return true;
126
- };
127
- var arrayIntersectsArray = function arrayIntersectsArray(a, b) {
128
- for (var i = 0; i < a.length - 1; i++) {
129
- for (var j = 0; j < b.length - 1; j++) {
130
- if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {
131
- return true;
116
+ return contains;
117
+ };
118
+ var pointsEqual = function pointsEqual(a, b) {
119
+ for (var i = 0; i < a.length; i++) {
120
+ if (a[i] !== b[i]) {
121
+ return false;
132
122
  }
133
123
  }
134
- }
135
124
 
136
- return false;
137
- };
125
+ return true;
126
+ };
127
+ var arrayIntersectsArray = function arrayIntersectsArray(a, b) {
128
+ for (var i = 0; i < a.length - 1; i++) {
129
+ for (var j = 0; j < b.length - 1; j++) {
130
+ if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {
131
+ return true;
132
+ }
133
+ }
134
+ }
138
135
 
139
- /* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
140
- * Apache-2.0 */
136
+ return false;
137
+ };
141
138
 
142
- var closeRing = function closeRing(coordinates) {
143
- if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {
144
- coordinates.push(coordinates[0]);
145
- }
139
+ /* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
140
+ * Apache-2.0 */
146
141
 
147
- return coordinates;
148
- }; // determine if polygon ring coordinates are clockwise. clockwise signifies outer ring, counter-clockwise an inner ring
149
- // or hole. this logic was found at http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-
150
- // points-are-in-clockwise-order
151
-
152
- var ringIsClockwise = function ringIsClockwise(ringToTest) {
153
- var total = 0;
154
- var i = 0;
155
- var rLength = ringToTest.length;
156
- var pt1 = ringToTest[i];
157
- var pt2;
158
-
159
- for (i; i < rLength - 1; i++) {
160
- pt2 = ringToTest[i + 1];
161
- total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);
162
- pt1 = pt2;
163
- }
142
+ var closeRing = function closeRing(coordinates) {
143
+ if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {
144
+ coordinates.push(coordinates[0]);
145
+ }
164
146
 
165
- return total >= 0;
166
- }; // This function ensures that rings are oriented in the right directions
167
- // from http://jsperf.com/cloning-an-object/2
147
+ return coordinates;
148
+ }; // determine if polygon ring coordinates are clockwise. clockwise signifies outer ring, counter-clockwise an inner ring
149
+ // or hole. this logic was found at http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-
150
+ // points-are-in-clockwise-order
168
151
 
169
- var shallowClone = function shallowClone(obj) {
170
- var target = {};
152
+ var ringIsClockwise = function ringIsClockwise(ringToTest) {
153
+ var total = 0;
154
+ var i = 0;
155
+ var rLength = ringToTest.length;
156
+ var pt1 = ringToTest[i];
157
+ var pt2;
171
158
 
172
- for (var i in obj) {
173
- // both arcgis attributes and geojson props are just hardcoded keys
174
- if (obj.hasOwnProperty(i)) {
175
- // eslint-disable-line no-prototype-builtins
176
- target[i] = obj[i];
159
+ for (i; i < rLength - 1; i++) {
160
+ pt2 = ringToTest[i + 1];
161
+ total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);
162
+ pt1 = pt2;
177
163
  }
178
- }
179
164
 
180
- return target;
181
- };
165
+ return total >= 0;
166
+ }; // This function ensures that rings are oriented in the right directions
167
+ // from http://jsperf.com/cloning-an-object/2
168
+
169
+ var shallowClone = function shallowClone(obj) {
170
+ var target = {};
182
171
 
183
- /* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
184
- * Apache-2.0 */
172
+ for (var i in obj) {
173
+ // both arcgis attributes and geojson props are just hardcoded keys
174
+ if (obj.hasOwnProperty(i)) {
175
+ // eslint-disable-line no-prototype-builtins
176
+ target[i] = obj[i];
177
+ }
178
+ }
185
179
 
186
- var coordinatesContainCoordinates = function coordinatesContainCoordinates(outer, inner) {
187
- var intersects = arrayIntersectsArray(outer, inner);
188
- var contains = coordinatesContainPoint(outer, inner[0]);
180
+ return target;
181
+ };
189
182
 
190
- if (!intersects && contains) {
191
- return true;
192
- }
183
+ /* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
184
+ * Apache-2.0 */
185
+
186
+ var coordinatesContainCoordinates = function coordinatesContainCoordinates(outer, inner) {
187
+ var intersects = arrayIntersectsArray(outer, inner);
188
+ var contains = coordinatesContainPoint(outer, inner[0]);
193
189
 
194
- return false;
195
- }; // do any polygons in this array contain any other polygons in this array?
196
- // used for checking for holes in arcgis rings
190
+ if (!intersects && contains) {
191
+ return true;
192
+ }
197
193
 
194
+ return false;
195
+ }; // do any polygons in this array contain any other polygons in this array?
196
+ // used for checking for holes in arcgis rings
198
197
 
199
- var convertRingsToGeoJSON = function convertRingsToGeoJSON(rings) {
200
- var outerRings = [];
201
- var holes = [];
202
- var x; // iterator
203
198
 
204
- var outerRing; // current outer ring being evaluated
199
+ var convertRingsToGeoJSON = function convertRingsToGeoJSON(rings) {
200
+ var outerRings = [];
201
+ var holes = [];
202
+ var x; // iterator
205
203
 
206
- var hole; // current hole being evaluated
207
- // for each ring
204
+ var outerRing; // current outer ring being evaluated
208
205
 
209
- for (var r = 0; r < rings.length; r++) {
210
- var ring = closeRing(rings[r].slice(0));
206
+ var hole; // current hole being evaluated
207
+ // for each ring
211
208
 
212
- if (ring.length < 4) {
213
- continue;
214
- } // is this ring an outer ring? is it clockwise?
209
+ for (var r = 0; r < rings.length; r++) {
210
+ var ring = closeRing(rings[r].slice(0));
215
211
 
212
+ if (ring.length < 4) {
213
+ continue;
214
+ } // is this ring an outer ring? is it clockwise?
216
215
 
217
- if (ringIsClockwise(ring)) {
218
- var polygon = [ring.slice().reverse()]; // wind outer rings counterclockwise for RFC 7946 compliance
219
216
 
220
- outerRings.push(polygon); // push to outer rings
221
- } else {
222
- holes.push(ring.slice().reverse()); // wind inner rings clockwise for RFC 7946 compliance
217
+ if (ringIsClockwise(ring)) {
218
+ var polygon = [ring.slice().reverse()]; // wind outer rings counterclockwise for RFC 7946 compliance
219
+
220
+ outerRings.push(polygon); // push to outer rings
221
+ } else {
222
+ holes.push(ring.slice().reverse()); // wind inner rings clockwise for RFC 7946 compliance
223
+ }
223
224
  }
224
- }
225
225
 
226
- var uncontainedHoles = []; // while there are holes left...
226
+ var uncontainedHoles = []; // while there are holes left...
227
227
 
228
- while (holes.length) {
229
- // pop a hole off out stack
230
- hole = holes.pop(); // loop over all outer rings and see if they contain our hole.
228
+ while (holes.length) {
229
+ // pop a hole off out stack
230
+ hole = holes.pop(); // loop over all outer rings and see if they contain our hole.
231
231
 
232
- var contained = false;
232
+ var contained = false;
233
233
 
234
- for (x = outerRings.length - 1; x >= 0; x--) {
235
- outerRing = outerRings[x][0];
234
+ for (x = outerRings.length - 1; x >= 0; x--) {
235
+ outerRing = outerRings[x][0];
236
236
 
237
- if (coordinatesContainCoordinates(outerRing, hole)) {
238
- // the hole is contained push it into our polygon
239
- outerRings[x].push(hole);
240
- contained = true;
241
- break;
242
- }
243
- } // ring is not contained in any outer ring
244
- // sometimes this happens https://github.com/Esri/esri-leaflet/issues/320
237
+ if (coordinatesContainCoordinates(outerRing, hole)) {
238
+ // the hole is contained push it into our polygon
239
+ outerRings[x].push(hole);
240
+ contained = true;
241
+ break;
242
+ }
243
+ } // ring is not contained in any outer ring
244
+ // sometimes this happens https://github.com/Esri/esri-leaflet/issues/320
245
245
 
246
246
 
247
- if (!contained) {
248
- uncontainedHoles.push(hole);
249
- }
250
- } // if we couldn't match any holes using contains we can try intersects...
247
+ if (!contained) {
248
+ uncontainedHoles.push(hole);
249
+ }
250
+ } // if we couldn't match any holes using contains we can try intersects...
251
251
 
252
252
 
253
- while (uncontainedHoles.length) {
254
- // pop a hole off out stack
255
- hole = uncontainedHoles.pop(); // loop over all outer rings and see if any intersect our hole.
253
+ while (uncontainedHoles.length) {
254
+ // pop a hole off out stack
255
+ hole = uncontainedHoles.pop(); // loop over all outer rings and see if any intersect our hole.
256
256
 
257
- var intersects = false;
257
+ var intersects = false;
258
258
 
259
- for (x = outerRings.length - 1; x >= 0; x--) {
260
- outerRing = outerRings[x][0];
259
+ for (x = outerRings.length - 1; x >= 0; x--) {
260
+ outerRing = outerRings[x][0];
261
261
 
262
- if (arrayIntersectsArray(outerRing, hole)) {
263
- // the hole is contained push it into our polygon
264
- outerRings[x].push(hole);
265
- intersects = true;
266
- break;
262
+ if (arrayIntersectsArray(outerRing, hole)) {
263
+ // the hole is contained push it into our polygon
264
+ outerRings[x].push(hole);
265
+ intersects = true;
266
+ break;
267
+ }
267
268
  }
268
- }
269
269
 
270
- if (!intersects) {
271
- outerRings.push([hole.reverse()]);
270
+ if (!intersects) {
271
+ outerRings.push([hole.reverse()]);
272
+ }
272
273
  }
273
- }
274
274
 
275
- if (outerRings.length === 1) {
276
- return {
277
- type: 'Polygon',
278
- coordinates: outerRings[0]
279
- };
280
- } else {
281
- return {
282
- type: 'MultiPolygon',
283
- coordinates: outerRings
284
- };
285
- }
286
- };
275
+ if (outerRings.length === 1) {
276
+ return {
277
+ type: 'Polygon',
278
+ coordinates: outerRings[0]
279
+ };
280
+ } else {
281
+ return {
282
+ type: 'MultiPolygon',
283
+ coordinates: outerRings
284
+ };
285
+ }
286
+ };
287
287
 
288
- var getId = function getId(attributes, idAttribute) {
289
- var keys = idAttribute ? [idAttribute, 'OBJECTID', 'FID'] : ['OBJECTID', 'FID'];
288
+ var getId = function getId(attributes, idAttribute) {
289
+ var keys = ['OBJECTID', 'FID'];
290
290
 
291
- for (var i = 0; i < keys.length; i++) {
292
- var key = keys[i];
291
+ for (var i = 0; i < keys.length; i++) {
292
+ var key = keys[i];
293
293
 
294
- if (key in attributes && (typeof attributes[key] === 'string' || typeof attributes[key] === 'number')) {
295
- return attributes[key];
294
+ if (key in attributes && (typeof attributes[key] === 'string' || typeof attributes[key] === 'number')) {
295
+ return attributes[key];
296
+ }
296
297
  }
297
- }
298
298
 
299
- throw Error('No valid id attribute found');
300
- };
299
+ throw Error('No valid id attribute found');
300
+ };
301
301
 
302
- var arcgisToGeoJSON = function arcgisToGeoJSON(arcgis, idAttribute) {
303
- var geojson = {};
302
+ var arcgisToGeoJSON = function arcgisToGeoJSON(arcgis, idAttribute) {
303
+ var geojson = {};
304
304
 
305
- if (arcgis.features) {
306
- geojson.type = 'FeatureCollection';
307
- geojson.features = [];
305
+ if (arcgis.features) {
306
+ geojson.type = 'FeatureCollection';
307
+ geojson.features = [];
308
308
 
309
- for (var i = 0; i < arcgis.features.length; i++) {
310
- geojson.features.push(arcgisToGeoJSON(arcgis.features[i], idAttribute));
309
+ for (var i = 0; i < arcgis.features.length; i++) {
310
+ geojson.features.push(arcgisToGeoJSON(arcgis.features[i], idAttribute));
311
+ }
311
312
  }
312
- }
313
313
 
314
- if (typeof arcgis.x === 'number' && typeof arcgis.y === 'number') {
315
- geojson.type = 'Point';
316
- geojson.coordinates = [arcgis.x, arcgis.y];
314
+ if (typeof arcgis.x === 'number' && typeof arcgis.y === 'number') {
315
+ geojson.type = 'Point';
316
+ geojson.coordinates = [arcgis.x, arcgis.y];
317
317
 
318
- if (typeof arcgis.z === 'number') {
319
- geojson.coordinates.push(arcgis.z);
318
+ if (typeof arcgis.z === 'number') {
319
+ geojson.coordinates.push(arcgis.z);
320
+ }
320
321
  }
321
- }
322
322
 
323
- if (arcgis.points) {
324
- geojson.type = 'MultiPoint';
325
- geojson.coordinates = arcgis.points.slice(0);
326
- }
323
+ if (arcgis.points) {
324
+ geojson.type = 'MultiPoint';
325
+ geojson.coordinates = arcgis.points.slice(0);
326
+ }
327
327
 
328
- if (arcgis.paths) {
329
- if (arcgis.paths.length === 1) {
330
- geojson.type = 'LineString';
331
- geojson.coordinates = arcgis.paths[0].slice(0);
332
- } else {
333
- geojson.type = 'MultiLineString';
334
- geojson.coordinates = arcgis.paths.slice(0);
328
+ if (arcgis.paths) {
329
+ if (arcgis.paths.length === 1) {
330
+ geojson.type = 'LineString';
331
+ geojson.coordinates = arcgis.paths[0].slice(0);
332
+ } else {
333
+ geojson.type = 'MultiLineString';
334
+ geojson.coordinates = arcgis.paths.slice(0);
335
+ }
335
336
  }
336
- }
337
337
 
338
- if (arcgis.rings) {
339
- geojson = convertRingsToGeoJSON(arcgis.rings.slice(0));
340
- }
338
+ if (arcgis.rings) {
339
+ geojson = convertRingsToGeoJSON(arcgis.rings.slice(0));
340
+ }
341
341
 
342
- if (typeof arcgis.xmin === 'number' && typeof arcgis.ymin === 'number' && typeof arcgis.xmax === 'number' && typeof arcgis.ymax === 'number') {
343
- geojson.type = 'Polygon';
344
- geojson.coordinates = [[[arcgis.xmax, arcgis.ymax], [arcgis.xmin, arcgis.ymax], [arcgis.xmin, arcgis.ymin], [arcgis.xmax, arcgis.ymin], [arcgis.xmax, arcgis.ymax]]];
345
- }
342
+ if (typeof arcgis.xmin === 'number' && typeof arcgis.ymin === 'number' && typeof arcgis.xmax === 'number' && typeof arcgis.ymax === 'number') {
343
+ geojson.type = 'Polygon';
344
+ geojson.coordinates = [[[arcgis.xmax, arcgis.ymax], [arcgis.xmin, arcgis.ymax], [arcgis.xmin, arcgis.ymin], [arcgis.xmax, arcgis.ymin], [arcgis.xmax, arcgis.ymax]]];
345
+ }
346
346
 
347
- if (arcgis.geometry || arcgis.attributes) {
348
- geojson.type = 'Feature';
349
- geojson.geometry = arcgis.geometry ? arcgisToGeoJSON(arcgis.geometry) : null;
350
- geojson.properties = arcgis.attributes ? shallowClone(arcgis.attributes) : null;
347
+ if (arcgis.geometry || arcgis.attributes) {
348
+ geojson.type = 'Feature';
349
+ geojson.geometry = arcgis.geometry ? arcgisToGeoJSON(arcgis.geometry) : null;
350
+ geojson.properties = arcgis.attributes ? shallowClone(arcgis.attributes) : null;
351
351
 
352
- if (arcgis.attributes) {
353
- try {
354
- geojson.id = getId(arcgis.attributes, idAttribute);
355
- } catch (err) {// don't set an id
352
+ if (arcgis.attributes) {
353
+ try {
354
+ geojson.id = getId(arcgis.attributes, idAttribute);
355
+ } catch (err) {// don't set an id
356
+ }
356
357
  }
358
+ } // if no valid geometry was encountered
359
+
360
+
361
+ if (JSON.stringify(geojson.geometry) === JSON.stringify({})) {
362
+ geojson.geometry = null;
357
363
  }
358
- } // if no valid geometry was encountered
359
364
 
365
+ if (arcgis.spatialReference && arcgis.spatialReference.wkid && arcgis.spatialReference.wkid !== 4326) {
366
+ console.warn('Object converted in non-standard crs - ' + JSON.stringify(arcgis.spatialReference));
367
+ }
368
+
369
+ return geojson;
370
+ };
360
371
 
361
- if (JSON.stringify(geojson.geometry) === JSON.stringify({})) {
362
- geojson.geometry = null;
372
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
373
+ * Apache-2.0 */
374
+ function isLocationArray(coords) {
375
+ return (coords.length === 2 ||
376
+ coords.length === 3);
377
+ }
378
+ function isLocation(coords) {
379
+ return (coords.latitude !== undefined ||
380
+ coords.lat !== undefined);
381
+ }
382
+ /**
383
+ * Used to find the best way to get from one location to another or to visit several locations. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm) for more information.
384
+ *
385
+ * ```js
386
+ * import { solveRoute } from '@esri/arcgis-rest-routing';
387
+ *
388
+ * solveRoute({
389
+ * stops: [
390
+ * [-117.195677, 34.056383],
391
+ * [-117.918976, 33.812092],
392
+ * ],
393
+ * authentication
394
+ * })
395
+ * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
396
+ * ```
397
+ *
398
+ * See the [REST API documentation](https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm) for more information.
399
+ *
400
+ * @param requestOptions Options to pass through to the routing service.
401
+ * @returns A Promise that will resolve with routes and directions for the request.
402
+ */
403
+ function solveRoute(requestOptions) {
404
+ const options = Object.assign({ endpoint: requestOptions.endpoint || ARCGIS_ONLINE_ROUTING_URL, params: {} }, requestOptions);
405
+ // the SAAS service does not support anonymous requests
406
+ if (!requestOptions.authentication &&
407
+ options.endpoint === ARCGIS_ONLINE_ROUTING_URL) {
408
+ return Promise.reject("Routing using the ArcGIS service requires authentication");
409
+ }
410
+ if (isFeatureSet(requestOptions.stops)) {
411
+ options.params.stops = requestOptions.stops;
412
+ }
413
+ else {
414
+ const stops = requestOptions.stops.map((coords) => {
415
+ if (isLocationArray(coords)) {
416
+ return coords.join();
417
+ }
418
+ else if (isLocation(coords)) {
419
+ if (coords.lat) {
420
+ return (coords.long + "," + coords.lat + (coords.z ? "," + coords.z : ""));
421
+ }
422
+ else {
423
+ return (coords.longitude +
424
+ "," +
425
+ coords.latitude +
426
+ (coords.z ? "," + coords.z : ""));
427
+ }
428
+ }
429
+ else {
430
+ return coords.x + "," + coords.y + (coords.z ? "," + coords.z : "");
431
+ }
432
+ });
433
+ options.params.stops = stops.join(";");
434
+ }
435
+ return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(options.endpoint)}/solve`, options).then(cleanResponse$3);
436
+ }
437
+ function cleanResponse$3(res) {
438
+ if (res.directions && res.directions.length > 0) {
439
+ res.directions = res.directions.map((direction) => {
440
+ direction.features = direction.features.map((feature) => {
441
+ feature.geometry = decompressGeometry(feature.compressedGeometry);
442
+ return feature;
443
+ });
444
+ return direction;
445
+ });
446
+ }
447
+ // add "geoJson" property to "routes"
448
+ if (res.routes.spatialReference.wkid === 4326) {
449
+ const features = res.routes.features.map((feature) => {
450
+ return {
451
+ type: "Feature",
452
+ geometry: arcgisToGeoJSON(feature.geometry),
453
+ properties: Object.assign({}, feature.attributes)
454
+ };
455
+ });
456
+ res.routes.geoJson = {
457
+ type: "FeatureCollection",
458
+ features
459
+ };
460
+ }
461
+ return res;
363
462
  }
364
463
 
365
- if (arcgis.spatialReference && arcgis.spatialReference.wkid && arcgis.spatialReference.wkid !== 4326) {
366
- console.warn('Object converted in non-standard crs - ' + JSON.stringify(arcgis.spatialReference));
464
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
465
+ * Apache-2.0 */
466
+ function getTravelDirection$1(key) {
467
+ if (key === "incidentsToFacilities") {
468
+ return "esriNATravelDirectionFromFacility";
469
+ }
470
+ else {
471
+ return "esriNATravelDirectionToFacility";
472
+ }
473
+ }
474
+ /**
475
+ * Used to find a route to the nearest of several possible destinations. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm) for more information.
476
+ *
477
+ * ```js
478
+ * import { closestFacility } from '@esri/arcgis-rest-routing';
479
+ *
480
+ * closestFacility({
481
+ * incidents: [
482
+ * [-90.404302, 38.600621],
483
+ * [-90.364293, 38.620427],
484
+ * ],
485
+ * facilities: [
486
+ * [-90.444716, 38.635501],
487
+ * [-90.311919, 38.633523],
488
+ * [-90.451147, 38.581107]
489
+ * ],
490
+ * authentication
491
+ * })
492
+ * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
493
+ * ```
494
+ *
495
+ * See the [REST API documentation](https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm) for more information.
496
+ *
497
+ * @param requestOptions Options to pass through to the routing service.
498
+ * @returns A Promise that will resolve with routes and directions for the request.
499
+ * @inline IClosestFacilityOptions
500
+ */
501
+ function closestFacility(requestOptions) {
502
+ const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;
503
+ requestOptions.params = Object.assign({ returnFacilities: true, returnDirections: true, returnIncidents: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true, preserveObjectID: true }, requestOptions.params);
504
+ const options = arcgisRestRequest.appendCustomParams(requestOptions, [
505
+ "returnCFRoutes",
506
+ // "travelDirection",
507
+ "barriers",
508
+ "polylineBarriers",
509
+ "polygonBarriers",
510
+ "returnDirections",
511
+ "directionsOutputType",
512
+ "directionsLengthUnits",
513
+ "outputLines",
514
+ "returnFacilities",
515
+ "returnIncidents",
516
+ "returnBarriers",
517
+ "returnPolylineBarriers",
518
+ "returnPolygonBarriers",
519
+ "preserveObjectID"
520
+ ]);
521
+ // Set travelDirection
522
+ if (requestOptions.travelDirection) {
523
+ options.params.travelDirection = getTravelDirection$1(requestOptions.travelDirection);
524
+ }
525
+ // the SAAS service does not support anonymous requests
526
+ if (!requestOptions.authentication &&
527
+ endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL) {
528
+ return Promise.reject("Finding the closest facility using the ArcGIS service requires authentication");
529
+ }
530
+ if (isFeatureSet(requestOptions.incidents) ||
531
+ isJsonWithURL(requestOptions.incidents)) {
532
+ options.params.incidents = requestOptions.incidents;
533
+ }
534
+ else {
535
+ options.params.incidents = normalizeLocationsList(requestOptions.incidents).join(";");
536
+ }
537
+ if (isFeatureSet(requestOptions.facilities) ||
538
+ isJsonWithURL(requestOptions.facilities)) {
539
+ options.params.facilities = requestOptions.facilities;
540
+ }
541
+ else {
542
+ options.params.facilities = normalizeLocationsList(requestOptions.facilities).join(";");
543
+ }
544
+ // optional input param that may need point geometry normalizing
545
+ if (requestOptions.barriers) {
546
+ if (isFeatureSet(requestOptions.barriers)) {
547
+ options.params.barriers = requestOptions.barriers;
548
+ }
549
+ else {
550
+ // optional point geometry barriers must be normalized, too
551
+ // but not if provided as IFeatureSet type
552
+ // note that optional polylineBarriers and polygonBarriers do not need to be normalized
553
+ options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
554
+ }
555
+ }
556
+ return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveClosestFacility`, options).then(cleanResponse$2);
557
+ }
558
+ function cleanResponse$2(res) {
559
+ // add "geoJson" property to "routes"
560
+ if (res.routes.spatialReference.wkid === 4326) {
561
+ res.routes.geoJson = arcgisToGeoJSON(res.routes);
562
+ }
563
+ return res;
367
564
  }
368
565
 
369
- return geojson;
370
- };
371
-
372
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
373
- * Apache-2.0 */
374
- function isLocationArray(coords) {
375
- return (coords.length === 2 ||
376
- coords.length === 3);
377
- }
378
- function isLocation(coords) {
379
- return (coords.latitude !== undefined ||
380
- coords.lat !== undefined);
381
- }
382
- /**
383
- * Used to find the best way to get from one location to another or to visit several locations. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm) for more information.
384
- *
385
- * ```js
386
- * import { solveRoute } from '@esri/arcgis-rest-routing';
387
- *
388
- * solveRoute({
389
- * stops: [
390
- * [-117.195677, 34.056383],
391
- * [-117.918976, 33.812092],
392
- * ],
393
- * authentication
394
- * })
395
- * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
396
- * ```
397
- *
398
- * @param requestOptions Options to pass through to the routing service.
399
- * @returns A Promise that will resolve with routes and directions for the request.
400
- * @restlink https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm
401
- */
402
- function solveRoute(requestOptions) {
403
- const options = Object.assign({ endpoint: requestOptions.endpoint || ARCGIS_ONLINE_ROUTING_URL, params: {} }, requestOptions);
404
- // the SAAS service does not support anonymous requests
405
- if (!requestOptions.authentication &&
406
- options.endpoint === ARCGIS_ONLINE_ROUTING_URL) {
407
- return Promise.reject("Routing using the ArcGIS service requires authentication");
408
- }
409
- if (isFeatureSet(requestOptions.stops)) {
410
- options.params.stops = requestOptions.stops;
411
- }
412
- else {
413
- const stops = requestOptions.stops.map((coords) => {
414
- if (isLocationArray(coords)) {
415
- return coords.join();
416
- }
417
- else if (isLocation(coords)) {
418
- if (coords.lat) {
419
- return (coords.long + "," + coords.lat + (coords.z ? "," + coords.z : ""));
420
- }
421
- else {
422
- return (coords.longitude +
423
- "," +
424
- coords.latitude +
425
- (coords.z ? "," + coords.z : ""));
426
- }
427
- }
428
- else {
429
- return coords.x + "," + coords.y + (coords.z ? "," + coords.z : "");
430
- }
431
- });
432
- options.params.stops = stops.join(";");
433
- }
434
- return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(options.endpoint)}/solve`, options).then(cleanResponse$3);
435
- }
436
- function cleanResponse$3(res) {
437
- if (res.directions && res.directions.length > 0) {
438
- res.directions = res.directions.map((direction) => {
439
- direction.features = direction.features.map((feature) => {
440
- feature.geometry = decompressGeometry(feature.compressedGeometry);
441
- return feature;
442
- });
443
- return direction;
444
- });
445
- }
446
- // add "geoJson" property to "routes"
447
- if (res.routes.spatialReference.wkid === 4326) {
448
- const features = res.routes.features.map((feature) => {
449
- return {
450
- type: "Feature",
451
- geometry: arcgisToGeoJSON(feature.geometry),
452
- properties: Object.assign({}, feature.attributes)
453
- };
454
- });
455
- res.routes.geoJson = {
456
- type: "FeatureCollection",
457
- features
458
- };
459
- }
460
- return res;
461
- }
462
-
463
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
464
- * Apache-2.0 */
465
- function getTravelDirection$1(key) {
466
- if (key === "incidentsToFacilities") {
467
- return "esriNATravelDirectionFromFacility";
468
- }
469
- else {
470
- return "esriNATravelDirectionToFacility";
471
- }
472
- }
473
- /**
474
- * Used to find a route to the nearest of several possible destinations. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm) for more information.
475
- *
476
- * ```js
477
- * import { closestFacility } from '@esri/arcgis-rest-routing';
478
- *
479
- * closestFacility({
480
- * incidents: [
481
- * [-90.404302, 38.600621],
482
- * [-90.364293, 38.620427],
483
- * ],
484
- * facilities: [
485
- * [-90.444716, 38.635501],
486
- * [-90.311919, 38.633523],
487
- * [-90.451147, 38.581107]
488
- * ],
489
- * authentication
490
- * })
491
- * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
492
- * ```
493
- *
494
- * @param requestOptions Options to pass through to the routing service.
495
- * @returns A Promise that will resolve with routes and directions for the request.
496
- * @restlink https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm
497
- * @inline IClosestFacilityOptions
498
- */
499
- function closestFacility(requestOptions) {
500
- const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;
501
- requestOptions.params = Object.assign({ returnFacilities: true, returnDirections: true, returnIncidents: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true, preserveObjectID: true }, requestOptions.params);
502
- const options = arcgisRestRequest.appendCustomParams(requestOptions, [
503
- "returnCFRoutes",
504
- // "travelDirection",
505
- "barriers",
506
- "polylineBarriers",
507
- "polygonBarriers",
508
- "returnDirections",
509
- "directionsOutputType",
510
- "directionsLengthUnits",
511
- "outputLines",
512
- "returnFacilities",
513
- "returnIncidents",
514
- "returnBarriers",
515
- "returnPolylineBarriers",
516
- "returnPolygonBarriers",
517
- "preserveObjectID"
518
- ]);
519
- // Set travelDirection
520
- if (requestOptions.travelDirection) {
521
- options.params.travelDirection = getTravelDirection$1(requestOptions.travelDirection);
522
- }
523
- // the SAAS service does not support anonymous requests
524
- if (!requestOptions.authentication &&
525
- endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL) {
526
- return Promise.reject("Finding the closest facility using the ArcGIS service requires authentication");
527
- }
528
- if (isFeatureSet(requestOptions.incidents) ||
529
- isJsonWithURL(requestOptions.incidents)) {
530
- options.params.incidents = requestOptions.incidents;
531
- }
532
- else {
533
- options.params.incidents = normalizeLocationsList(requestOptions.incidents).join(";");
534
- }
535
- if (isFeatureSet(requestOptions.facilities) ||
536
- isJsonWithURL(requestOptions.facilities)) {
537
- options.params.facilities = requestOptions.facilities;
538
- }
539
- else {
540
- options.params.facilities = normalizeLocationsList(requestOptions.facilities).join(";");
541
- }
542
- // optional input param that may need point geometry normalizing
543
- if (requestOptions.barriers) {
544
- if (isFeatureSet(requestOptions.barriers)) {
545
- options.params.barriers = requestOptions.barriers;
546
- }
547
- else {
548
- // optional point geometry barriers must be normalized, too
549
- // but not if provided as IFeatureSet type
550
- // note that optional polylineBarriers and polygonBarriers do not need to be normalized
551
- options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
552
- }
553
- }
554
- return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveClosestFacility`, options).then(cleanResponse$2);
555
- }
556
- function cleanResponse$2(res) {
557
- // add "geoJson" property to "routes"
558
- if (res.routes.spatialReference.wkid === 4326) {
559
- res.routes.geoJson = arcgisToGeoJSON(res.routes);
560
- }
561
- return res;
562
- }
563
-
564
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
565
- * Apache-2.0 */
566
- function getTravelDirection(key) {
567
- if (key === "incidentsToFacilities") {
568
- return "esriNATravelDirectionFromFacility";
569
- }
570
- else {
571
- return "esriNATravelDirectionToFacility";
572
- }
573
- }
574
- /**
575
- * Used to find the area that can be reached from the input location within a given travel time or travel distance. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm) for more information.
576
- *
577
- * ```js
578
- * import { serviceArea } from '@esri/arcgis-rest-routing';
579
- *
580
- * serviceArea({
581
- * facilities: [
582
- * [-90.444716, 38.635501],
583
- * [-90.311919, 38.633523],
584
- * [-90.451147, 38.581107]
585
- * ],
586
- * authentication
587
- * })
588
- * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
589
- * ```
590
- *
591
- * @param requestOptions Options to pass through to the routing service.
592
- * @returns A Promise that will resolve with service area polygons for the request.
593
- * @restlink https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm
594
- */
595
- function serviceArea(requestOptions) {
596
- const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_SERVICE_AREA_URL;
597
- requestOptions.params = Object.assign({ returnFacilities: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true, preserveObjectID: true }, requestOptions.params);
598
- const options = arcgisRestRequest.appendCustomParams(requestOptions, [
599
- "barriers",
600
- "polylineBarriers",
601
- "polygonBarriers",
602
- "outputLines",
603
- "returnFacilities",
604
- "returnBarriers",
605
- "returnPolylineBarriers",
606
- "returnPolygonBarriers",
607
- "preserveObjectID"
608
- ]);
609
- // Set travelDirection
610
- if (requestOptions.travelDirection) {
611
- options.params.travelDirection = getTravelDirection(requestOptions.travelDirection);
612
- }
613
- // the SAAS service does not support anonymous requests
614
- if (!requestOptions.authentication &&
615
- endpoint === ARCGIS_ONLINE_SERVICE_AREA_URL) {
616
- return Promise.reject("Finding service areas using the ArcGIS service requires authentication");
617
- }
618
- if (isFeatureSet(requestOptions.facilities)) {
619
- options.params.facilities = requestOptions.facilities;
620
- }
621
- else {
622
- options.params.facilities = normalizeLocationsList(requestOptions.facilities).join(";");
623
- }
624
- // optional input param that may need point geometry normalizing
625
- if (requestOptions.barriers) {
626
- if (isFeatureSet(requestOptions.barriers)) {
627
- options.params.barriers = requestOptions.barriers;
628
- }
629
- else {
630
- // optional point geometry barriers must be normalized, too
631
- // but not if provided as IFeatureSet type
632
- // note that optional polylineBarriers and polygonBarriers do not need to be normalized
633
- options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
634
- }
635
- }
636
- return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveServiceArea`, options).then(cleanResponse$1);
637
- }
638
- function cleanResponse$1(res) {
639
- // remove "fieldAliases" because it does not do anything.
640
- delete res.saPolygons.fieldAliases;
641
- // add "geoJson" property to "saPolygons"
642
- if (res.saPolygons.spatialReference.wkid === 4326) {
643
- res.saPolygons.geoJson = arcgisToGeoJSON(res.saPolygons);
644
- }
645
- return res;
646
- }
647
-
648
- /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
649
- * Apache-2.0 */
650
- /**
651
- * Used to create an origin-destination (OD) cost matrix from multiple origins to multiple destinations. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm) for more information.
652
- *
653
- * ```js
654
- * import { originDestinationMatrix } from '@esri/arcgis-rest-routing';
655
- *
656
- * originDestinationMatrix({
657
- * origins: [
658
- * [-90.404302, 38.600621],
659
- * [-90.364293, 38.620427],
660
- * ],
661
- * destinations: [
662
- * [-90.444716, 38.635501],
663
- * [-90.311919, 38.633523],
664
- * [-90.451147, 38.581107]
665
- * ],
666
- * authentication
667
- * })
668
- * .then(response) // => { ... }
669
- * ```
670
- *
671
- * @param requestOptions Options to pass through to the routing service.
672
- * @returns A Promise that will resolve with travel time and/or distance for each origin-destination pair. It returns either odLines or odCostMatrix for this information depending on the outputType you specify.
673
- * @restlink https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm
674
- */
675
- function originDestinationMatrix(requestOptions) {
676
- const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;
677
- requestOptions.params = Object.assign({ outputType: "esriNAODOutputSparseMatrix", returnOrigins: true, returnDestinations: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true }, requestOptions.params);
678
- const options = arcgisRestRequest.appendCustomParams(requestOptions, [
679
- "outputType",
680
- "barriers",
681
- "polylineBarriers",
682
- "polygonBarriers",
683
- "returnOrigins",
684
- "returnDestinations",
685
- "returnBarriers",
686
- "returnPolylineBarriers",
687
- "returnPolygonBarriers"
688
- ]);
689
- // the SAAS service does not support anonymous requests
690
- if (!requestOptions.authentication &&
691
- endpoint === ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL) {
692
- return Promise.reject("Calculating the origin-destination cost matrix using the ArcGIS service requires authentication");
693
- }
694
- // use a formatting helper for input params of this type: Array<IPoint | ILocation | [number, number]>
695
- if (isFeatureSet(requestOptions.origins)) {
696
- options.params.origins = requestOptions.origins;
697
- }
698
- else {
699
- options.params.origins = normalizeLocationsList(requestOptions.origins).join(";");
700
- }
701
- if (isFeatureSet(requestOptions.destinations)) {
702
- options.params.destinations = requestOptions.destinations;
703
- }
704
- else {
705
- options.params.destinations = normalizeLocationsList(requestOptions.destinations).join(";");
706
- }
707
- // optional input param that may need point geometry normalizing
708
- if (requestOptions.barriers) {
709
- if (isFeatureSet(requestOptions.barriers)) {
710
- options.params.barriers = requestOptions.barriers;
711
- }
712
- else {
713
- // optional point geometry barriers must be normalized, too
714
- // but not if provided as IFeatureSet type
715
- // note that optional polylineBarriers and polygonBarriers do not need to be normalized
716
- options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
717
- }
718
- }
719
- return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveODCostMatrix`, options).then(function (res) {
720
- return cleanResponse(res, options);
721
- });
722
- }
723
- function cleanResponse(res, options) {
724
- // add "geoJson" property to each response property that is an arcgis featureSet
725
- // res.odLines only exists and only includes geometry in this condition (out of 3 possible options.params.outputType conditions)
726
- if (options.params.outputType === "esriNAODOutputStraightLines" &&
727
- res.odLines &&
728
- res.odLines.spatialReference.wkid === 4326) {
729
- res.odLines.geoJson = arcgisToGeoJSON(res.odLines);
730
- }
731
- if (res.origins && res.origins.spatialReference.wkid === 4326) {
732
- res.origins.geoJson = arcgisToGeoJSON(res.origins);
733
- }
734
- if (res.destinations && res.destinations.spatialReference.wkid === 4326) {
735
- res.destinations.geoJson = arcgisToGeoJSON(res.destinations);
736
- }
737
- if (res.barriers && res.barriers.spatialReference.wkid === 4326) {
738
- res.barriers.geoJson = arcgisToGeoJSON(res.barriers);
739
- }
740
- if (res.polygonBarriers &&
741
- res.polygonBarriers.spatialReference.wkid === 4326) {
742
- res.polygonBarriers.geoJson = arcgisToGeoJSON(res.polygonBarriers);
743
- }
744
- if (res.polylineBarriers &&
745
- res.polylineBarriers.spatialReference.wkid === 4326) {
746
- res.polylineBarriers.geoJson = arcgisToGeoJSON(res.polylineBarriers);
747
- }
748
- return res;
749
- }
750
-
751
- exports.ARCGIS_ONLINE_CLOSEST_FACILITY_URL = ARCGIS_ONLINE_CLOSEST_FACILITY_URL;
752
- exports.ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;
753
- exports.ARCGIS_ONLINE_ROUTING_URL = ARCGIS_ONLINE_ROUTING_URL;
754
- exports.ARCGIS_ONLINE_SERVICE_AREA_URL = ARCGIS_ONLINE_SERVICE_AREA_URL;
755
- exports.closestFacility = closestFacility;
756
- exports.decompressGeometry = decompressGeometry;
757
- exports.isFeatureSet = isFeatureSet;
758
- exports.isJsonWithURL = isJsonWithURL;
759
- exports.normalizeLocationsList = normalizeLocationsList;
760
- exports.originDestinationMatrix = originDestinationMatrix;
761
- exports.serviceArea = serviceArea;
762
- exports.solveRoute = solveRoute;
763
-
764
- Object.defineProperty(exports, '__esModule', { value: true });
566
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
567
+ * Apache-2.0 */
568
+ function getTravelDirection(key) {
569
+ if (key === "incidentsToFacilities") {
570
+ return "esriNATravelDirectionFromFacility";
571
+ }
572
+ else {
573
+ return "esriNATravelDirectionToFacility";
574
+ }
575
+ }
576
+ /**
577
+ * Used to find the area that can be reached from the input location within a given travel time or travel distance. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm) for more information.
578
+ *
579
+ * ```js
580
+ * import { serviceArea } from '@esri/arcgis-rest-routing';
581
+ *
582
+ * serviceArea({
583
+ * facilities: [
584
+ * [-90.444716, 38.635501],
585
+ * [-90.311919, 38.633523],
586
+ * [-90.451147, 38.581107]
587
+ * ],
588
+ * authentication
589
+ * })
590
+ * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
591
+ * ```
592
+ *
593
+ * See the [REST API documentation](https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm) for more information.
594
+ *
595
+ * @param requestOptions Options to pass through to the routing service.
596
+ * @returns A Promise that will resolve with service area polygons for the request.
597
+ */
598
+ function serviceArea(requestOptions) {
599
+ const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_SERVICE_AREA_URL;
600
+ requestOptions.params = Object.assign({ returnFacilities: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true, preserveObjectID: true }, requestOptions.params);
601
+ const options = arcgisRestRequest.appendCustomParams(requestOptions, [
602
+ "barriers",
603
+ "polylineBarriers",
604
+ "polygonBarriers",
605
+ "outputLines",
606
+ "returnFacilities",
607
+ "returnBarriers",
608
+ "returnPolylineBarriers",
609
+ "returnPolygonBarriers",
610
+ "preserveObjectID"
611
+ ]);
612
+ // Set travelDirection
613
+ if (requestOptions.travelDirection) {
614
+ options.params.travelDirection = getTravelDirection(requestOptions.travelDirection);
615
+ }
616
+ // the SAAS service does not support anonymous requests
617
+ if (!requestOptions.authentication &&
618
+ endpoint === ARCGIS_ONLINE_SERVICE_AREA_URL) {
619
+ return Promise.reject("Finding service areas using the ArcGIS service requires authentication");
620
+ }
621
+ if (isFeatureSet(requestOptions.facilities)) {
622
+ options.params.facilities = requestOptions.facilities;
623
+ }
624
+ else {
625
+ options.params.facilities = normalizeLocationsList(requestOptions.facilities).join(";");
626
+ }
627
+ // optional input param that may need point geometry normalizing
628
+ if (requestOptions.barriers) {
629
+ if (isFeatureSet(requestOptions.barriers)) {
630
+ options.params.barriers = requestOptions.barriers;
631
+ }
632
+ else {
633
+ // optional point geometry barriers must be normalized, too
634
+ // but not if provided as IFeatureSet type
635
+ // note that optional polylineBarriers and polygonBarriers do not need to be normalized
636
+ options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
637
+ }
638
+ }
639
+ return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveServiceArea`, options).then(cleanResponse$1);
640
+ }
641
+ function cleanResponse$1(res) {
642
+ // remove "fieldAliases" because it does not do anything.
643
+ delete res.saPolygons.fieldAliases;
644
+ // add "geoJson" property to "saPolygons"
645
+ if (res.saPolygons.spatialReference.wkid === 4326) {
646
+ res.saPolygons.geoJson = arcgisToGeoJSON(res.saPolygons);
647
+ }
648
+ return res;
649
+ }
650
+
651
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
652
+ * Apache-2.0 */
653
+ /**
654
+ * Used to create an origin-destination (OD) cost matrix from multiple origins to multiple destinations. See the [REST Documentation](https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm) for more information.
655
+ *
656
+ * ```js
657
+ * import { originDestinationMatrix } from '@esri/arcgis-rest-routing';
658
+ *
659
+ * originDestinationMatrix({
660
+ * origins: [
661
+ * [-90.404302, 38.600621],
662
+ * [-90.364293, 38.620427],
663
+ * ],
664
+ * destinations: [
665
+ * [-90.444716, 38.635501],
666
+ * [-90.311919, 38.633523],
667
+ * [-90.451147, 38.581107]
668
+ * ],
669
+ * authentication
670
+ * })
671
+ * .then(response) // => { ... }
672
+ * ```
673
+ *
674
+ * See the [REST API documentation](https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm) for more information.
675
+ *
676
+ * @param requestOptions Options to pass through to the routing service.
677
+ * @returns A Promise that will resolve with travel time and/or distance for each origin-destination pair. It returns either odLines or odCostMatrix for this information depending on the outputType you specify.
678
+ */
679
+ function originDestinationMatrix(requestOptions) {
680
+ const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;
681
+ requestOptions.params = Object.assign({ outputType: "esriNAODOutputSparseMatrix", returnOrigins: true, returnDestinations: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true }, requestOptions.params);
682
+ const options = arcgisRestRequest.appendCustomParams(requestOptions, [
683
+ "outputType",
684
+ "barriers",
685
+ "polylineBarriers",
686
+ "polygonBarriers",
687
+ "returnOrigins",
688
+ "returnDestinations",
689
+ "returnBarriers",
690
+ "returnPolylineBarriers",
691
+ "returnPolygonBarriers"
692
+ ]);
693
+ // the SAAS service does not support anonymous requests
694
+ if (!requestOptions.authentication &&
695
+ endpoint === ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL) {
696
+ return Promise.reject("Calculating the origin-destination cost matrix using the ArcGIS service requires authentication");
697
+ }
698
+ // use a formatting helper for input params of this type: Array<IPoint | ILocation | [number, number]>
699
+ if (isFeatureSet(requestOptions.origins)) {
700
+ options.params.origins = requestOptions.origins;
701
+ }
702
+ else {
703
+ options.params.origins = normalizeLocationsList(requestOptions.origins).join(";");
704
+ }
705
+ if (isFeatureSet(requestOptions.destinations)) {
706
+ options.params.destinations = requestOptions.destinations;
707
+ }
708
+ else {
709
+ options.params.destinations = normalizeLocationsList(requestOptions.destinations).join(";");
710
+ }
711
+ // optional input param that may need point geometry normalizing
712
+ if (requestOptions.barriers) {
713
+ if (isFeatureSet(requestOptions.barriers)) {
714
+ options.params.barriers = requestOptions.barriers;
715
+ }
716
+ else {
717
+ // optional point geometry barriers must be normalized, too
718
+ // but not if provided as IFeatureSet type
719
+ // note that optional polylineBarriers and polygonBarriers do not need to be normalized
720
+ options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
721
+ }
722
+ }
723
+ return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveODCostMatrix`, options).then(function (res) {
724
+ return cleanResponse(res, options);
725
+ });
726
+ }
727
+ function cleanResponse(res, options) {
728
+ // add "geoJson" property to each response property that is an arcgis featureSet
729
+ // res.odLines only exists and only includes geometry in this condition (out of 3 possible options.params.outputType conditions)
730
+ if (options.params.outputType === "esriNAODOutputStraightLines" &&
731
+ res.odLines &&
732
+ res.odLines.spatialReference.wkid === 4326) {
733
+ res.odLines.geoJson = arcgisToGeoJSON(res.odLines);
734
+ }
735
+ if (res.origins && res.origins.spatialReference.wkid === 4326) {
736
+ res.origins.geoJson = arcgisToGeoJSON(res.origins);
737
+ }
738
+ if (res.destinations && res.destinations.spatialReference.wkid === 4326) {
739
+ res.destinations.geoJson = arcgisToGeoJSON(res.destinations);
740
+ }
741
+ if (res.barriers && res.barriers.spatialReference.wkid === 4326) {
742
+ res.barriers.geoJson = arcgisToGeoJSON(res.barriers);
743
+ }
744
+ if (res.polygonBarriers &&
745
+ res.polygonBarriers.spatialReference.wkid === 4326) {
746
+ res.polygonBarriers.geoJson = arcgisToGeoJSON(res.polygonBarriers);
747
+ }
748
+ if (res.polylineBarriers &&
749
+ res.polylineBarriers.spatialReference.wkid === 4326) {
750
+ res.polylineBarriers.geoJson = arcgisToGeoJSON(res.polylineBarriers);
751
+ }
752
+ return res;
753
+ }
754
+
755
+ exports.ARCGIS_ONLINE_CLOSEST_FACILITY_URL = ARCGIS_ONLINE_CLOSEST_FACILITY_URL;
756
+ exports.ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;
757
+ exports.ARCGIS_ONLINE_ROUTING_URL = ARCGIS_ONLINE_ROUTING_URL;
758
+ exports.ARCGIS_ONLINE_SERVICE_AREA_URL = ARCGIS_ONLINE_SERVICE_AREA_URL;
759
+ exports.closestFacility = closestFacility;
760
+ exports.decompressGeometry = decompressGeometry;
761
+ exports.isFeatureSet = isFeatureSet;
762
+ exports.isJsonWithURL = isJsonWithURL;
763
+ exports.normalizeLocationsList = normalizeLocationsList;
764
+ exports.originDestinationMatrix = originDestinationMatrix;
765
+ exports.serviceArea = serviceArea;
766
+ exports.solveRoute = solveRoute;
765
767
 
766
768
  }));
767
769
  //# sourceMappingURL=routing.umd.js.map