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