@esri/arcgis-rest-routing 3.4.3 → 4.0.0-beta.4

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