@esri/arcgis-rest-routing 3.4.1 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/dist/bundled/routing.esm.js +736 -0
- package/dist/bundled/routing.esm.js.map +1 -0
- package/dist/bundled/routing.esm.min.js +12 -0
- package/dist/bundled/routing.esm.min.js.map +1 -0
- package/dist/bundled/routing.umd.js +754 -0
- package/dist/bundled/routing.umd.js.map +1 -0
- package/dist/bundled/routing.umd.min.js +12 -0
- package/dist/bundled/routing.umd.min.js.map +1 -0
- package/dist/{node → cjs}/closestFacility.js +18 -18
- package/dist/cjs/closestFacility.js.map +1 -0
- package/dist/{node → cjs}/helpers.js +11 -11
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/{node → cjs}/originDestinationMatrix.js +22 -23
- package/dist/cjs/originDestinationMatrix.js.map +1 -0
- package/dist/{node → cjs}/serviceArea.js +15 -16
- package/dist/cjs/serviceArea.js.map +1 -0
- package/dist/{node → cjs}/solveRoute.js +16 -17
- package/dist/cjs/solveRoute.js.map +1 -0
- package/dist/esm/closestFacility.d.ts +3 -2
- package/dist/esm/closestFacility.js +9 -9
- package/dist/esm/closestFacility.js.map +1 -1
- package/dist/esm/helpers.d.ts +1 -2
- package/dist/esm/helpers.js +15 -15
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/originDestinationMatrix.d.ts +2 -2
- package/dist/esm/originDestinationMatrix.js +8 -9
- package/dist/esm/originDestinationMatrix.js.map +1 -1
- package/dist/esm/serviceArea.d.ts +2 -2
- package/dist/esm/serviceArea.js +8 -9
- package/dist/esm/serviceArea.js.map +1 -1
- package/dist/esm/solveRoute.d.ts +2 -2
- package/dist/esm/solveRoute.js +10 -11
- package/dist/esm/solveRoute.js.map +1 -1
- package/package.json +45 -41
- package/dist/node/closestFacility.js.map +0 -1
- package/dist/node/helpers.js.map +0 -1
- package/dist/node/index.js +0 -11
- package/dist/node/index.js.map +0 -1
- package/dist/node/originDestinationMatrix.js.map +0 -1
- package/dist/node/serviceArea.js.map +0 -1
- package/dist/node/solveRoute.js.map +0 -1
- package/dist/umd/routing.umd.js +0 -779
- package/dist/umd/routing.umd.js.map +0 -1
- package/dist/umd/routing.umd.min.js +0 -12
- package/dist/umd/routing.umd.min.js.map +0 -1
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
/* @preserve
|
|
2
|
+
* @esri/arcgis-rest-routing - v4.0.0-beta.2 - Apache-2.0
|
|
3
|
+
* Copyright (c) 2017-2022 Esri, Inc.
|
|
4
|
+
* Wed Mar 02 2022 21:39:55 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
|
+
* ```js
|
|
378
|
+
* import { solveRoute } from '@esri/arcgis-rest-routing';
|
|
379
|
+
* //
|
|
380
|
+
* solveRoute({
|
|
381
|
+
* stops: [
|
|
382
|
+
* [-117.195677, 34.056383],
|
|
383
|
+
* [-117.918976, 33.812092],
|
|
384
|
+
* ],
|
|
385
|
+
* authentication
|
|
386
|
+
* })
|
|
387
|
+
* .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
|
|
388
|
+
* ```
|
|
389
|
+
* 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.
|
|
390
|
+
*
|
|
391
|
+
* @param requestOptions Options to pass through to the routing service.
|
|
392
|
+
* @returns A Promise that will resolve with routes and directions for the request.
|
|
393
|
+
* @restlink https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm
|
|
394
|
+
*/
|
|
395
|
+
function solveRoute(requestOptions) {
|
|
396
|
+
const options = Object.assign({ endpoint: requestOptions.endpoint || ARCGIS_ONLINE_ROUTING_URL, params: {} }, requestOptions);
|
|
397
|
+
// the SAAS service does not support anonymous requests
|
|
398
|
+
if (!requestOptions.authentication &&
|
|
399
|
+
options.endpoint === ARCGIS_ONLINE_ROUTING_URL) {
|
|
400
|
+
return Promise.reject("Routing using the ArcGIS service requires authentication");
|
|
401
|
+
}
|
|
402
|
+
if (isFeatureSet(requestOptions.stops)) {
|
|
403
|
+
options.params.stops = requestOptions.stops;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
const stops = requestOptions.stops.map((coords) => {
|
|
407
|
+
if (isLocationArray(coords)) {
|
|
408
|
+
return coords.join();
|
|
409
|
+
}
|
|
410
|
+
else if (isLocation(coords)) {
|
|
411
|
+
if (coords.lat) {
|
|
412
|
+
return (coords.long + "," + coords.lat + (coords.z ? "," + coords.z : ""));
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
return (coords.longitude +
|
|
416
|
+
"," +
|
|
417
|
+
coords.latitude +
|
|
418
|
+
(coords.z ? "," + coords.z : ""));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
return coords.x + "," + coords.y + (coords.z ? "," + coords.z : "");
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
options.params.stops = stops.join(";");
|
|
426
|
+
}
|
|
427
|
+
return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(options.endpoint)}/solve`, options).then(cleanResponse$3);
|
|
428
|
+
}
|
|
429
|
+
function cleanResponse$3(res) {
|
|
430
|
+
if (res.directions && res.directions.length > 0) {
|
|
431
|
+
res.directions = res.directions.map((direction) => {
|
|
432
|
+
direction.features = direction.features.map((feature) => {
|
|
433
|
+
feature.geometry = decompressGeometry(feature.compressedGeometry);
|
|
434
|
+
return feature;
|
|
435
|
+
});
|
|
436
|
+
return direction;
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
// add "geoJson" property to "routes"
|
|
440
|
+
if (res.routes.spatialReference.wkid === 4326) {
|
|
441
|
+
const features = res.routes.features.map((feature) => {
|
|
442
|
+
return {
|
|
443
|
+
type: "Feature",
|
|
444
|
+
geometry: arcgisToGeoJSON(feature.geometry),
|
|
445
|
+
properties: Object.assign({}, feature.attributes)
|
|
446
|
+
};
|
|
447
|
+
});
|
|
448
|
+
res.routes.geoJson = {
|
|
449
|
+
type: "FeatureCollection",
|
|
450
|
+
features
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
return res;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
457
|
+
* Apache-2.0 */
|
|
458
|
+
function getTravelDirection$1(key) {
|
|
459
|
+
if (key === "incidentsToFacilities") {
|
|
460
|
+
return "esriNATravelDirectionFromFacility";
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
return "esriNATravelDirectionToFacility";
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* ```js
|
|
468
|
+
* import { closestFacility } from '@esri/arcgis-rest-routing';
|
|
469
|
+
* //
|
|
470
|
+
* closestFacility({
|
|
471
|
+
* incidents: [
|
|
472
|
+
* [-90.404302, 38.600621],
|
|
473
|
+
* [-90.364293, 38.620427],
|
|
474
|
+
* ],
|
|
475
|
+
* facilities: [
|
|
476
|
+
* [-90.444716, 38.635501],
|
|
477
|
+
* [-90.311919, 38.633523],
|
|
478
|
+
* [-90.451147, 38.581107]
|
|
479
|
+
* ],
|
|
480
|
+
* authentication
|
|
481
|
+
* })
|
|
482
|
+
* .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
|
|
483
|
+
* ```
|
|
484
|
+
* 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.
|
|
485
|
+
*
|
|
486
|
+
* @param requestOptions Options to pass through to the routing service.
|
|
487
|
+
* @returns A Promise that will resolve with routes and directions for the request.
|
|
488
|
+
* @restlink https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm
|
|
489
|
+
* @inline IClosestFacilityOptions
|
|
490
|
+
*/
|
|
491
|
+
function closestFacility(requestOptions) {
|
|
492
|
+
const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;
|
|
493
|
+
requestOptions.params = Object.assign({ returnFacilities: true, returnDirections: true, returnIncidents: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true, preserveObjectID: true }, requestOptions.params);
|
|
494
|
+
const options = arcgisRestRequest.appendCustomParams(requestOptions, [
|
|
495
|
+
"returnCFRoutes",
|
|
496
|
+
// "travelDirection",
|
|
497
|
+
"barriers",
|
|
498
|
+
"polylineBarriers",
|
|
499
|
+
"polygonBarriers",
|
|
500
|
+
"returnDirections",
|
|
501
|
+
"directionsOutputType",
|
|
502
|
+
"directionsLengthUnits",
|
|
503
|
+
"outputLines",
|
|
504
|
+
"returnFacilities",
|
|
505
|
+
"returnIncidents",
|
|
506
|
+
"returnBarriers",
|
|
507
|
+
"returnPolylineBarriers",
|
|
508
|
+
"returnPolygonBarriers",
|
|
509
|
+
"preserveObjectID"
|
|
510
|
+
]);
|
|
511
|
+
// Set travelDirection
|
|
512
|
+
if (requestOptions.travelDirection) {
|
|
513
|
+
options.params.travelDirection = getTravelDirection$1(requestOptions.travelDirection);
|
|
514
|
+
}
|
|
515
|
+
// the SAAS service does not support anonymous requests
|
|
516
|
+
if (!requestOptions.authentication &&
|
|
517
|
+
endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL) {
|
|
518
|
+
return Promise.reject("Finding the closest facility using the ArcGIS service requires authentication");
|
|
519
|
+
}
|
|
520
|
+
if (isFeatureSet(requestOptions.incidents)) {
|
|
521
|
+
options.params.incidents = requestOptions.incidents;
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
options.params.incidents = normalizeLocationsList(requestOptions.incidents).join(";");
|
|
525
|
+
}
|
|
526
|
+
if (isFeatureSet(requestOptions.facilities)) {
|
|
527
|
+
options.params.facilities = requestOptions.facilities;
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
options.params.facilities = normalizeLocationsList(requestOptions.facilities).join(";");
|
|
531
|
+
}
|
|
532
|
+
// optional input param that may need point geometry normalizing
|
|
533
|
+
if (requestOptions.barriers) {
|
|
534
|
+
if (isFeatureSet(requestOptions.barriers)) {
|
|
535
|
+
options.params.barriers = requestOptions.barriers;
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
// optional point geometry barriers must be normalized, too
|
|
539
|
+
// but not if provided as IFeatureSet type
|
|
540
|
+
// note that optional polylineBarriers and polygonBarriers do not need to be normalized
|
|
541
|
+
options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveClosestFacility`, options).then(cleanResponse$2);
|
|
545
|
+
}
|
|
546
|
+
function cleanResponse$2(res) {
|
|
547
|
+
// add "geoJson" property to "routes"
|
|
548
|
+
if (res.routes.spatialReference.wkid === 4326) {
|
|
549
|
+
res.routes.geoJson = arcgisToGeoJSON(res.routes);
|
|
550
|
+
}
|
|
551
|
+
return res;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
555
|
+
* Apache-2.0 */
|
|
556
|
+
function getTravelDirection(key) {
|
|
557
|
+
if (key === "incidentsToFacilities") {
|
|
558
|
+
return "esriNATravelDirectionFromFacility";
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
return "esriNATravelDirectionToFacility";
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* ```js
|
|
566
|
+
* import { serviceArea } from '@esri/arcgis-rest-routing';
|
|
567
|
+
* //
|
|
568
|
+
* serviceArea({
|
|
569
|
+
* facilities: [
|
|
570
|
+
* [-90.444716, 38.635501],
|
|
571
|
+
* [-90.311919, 38.633523],
|
|
572
|
+
* [-90.451147, 38.581107]
|
|
573
|
+
* ],
|
|
574
|
+
* authentication
|
|
575
|
+
* })
|
|
576
|
+
* .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}
|
|
577
|
+
* ```
|
|
578
|
+
* 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.
|
|
579
|
+
*
|
|
580
|
+
* @param requestOptions Options to pass through to the routing service.
|
|
581
|
+
* @returns A Promise that will resolve with service area polygons for the request.
|
|
582
|
+
* @restlink https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm
|
|
583
|
+
*/
|
|
584
|
+
function serviceArea(requestOptions) {
|
|
585
|
+
const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_SERVICE_AREA_URL;
|
|
586
|
+
requestOptions.params = Object.assign({ returnFacilities: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true, preserveObjectID: true }, requestOptions.params);
|
|
587
|
+
const options = arcgisRestRequest.appendCustomParams(requestOptions, [
|
|
588
|
+
"barriers",
|
|
589
|
+
"polylineBarriers",
|
|
590
|
+
"polygonBarriers",
|
|
591
|
+
"outputLines",
|
|
592
|
+
"returnFacilities",
|
|
593
|
+
"returnBarriers",
|
|
594
|
+
"returnPolylineBarriers",
|
|
595
|
+
"returnPolygonBarriers",
|
|
596
|
+
"preserveObjectID"
|
|
597
|
+
]);
|
|
598
|
+
// Set travelDirection
|
|
599
|
+
if (requestOptions.travelDirection) {
|
|
600
|
+
options.params.travelDirection = getTravelDirection(requestOptions.travelDirection);
|
|
601
|
+
}
|
|
602
|
+
// the SAAS service does not support anonymous requests
|
|
603
|
+
if (!requestOptions.authentication &&
|
|
604
|
+
endpoint === ARCGIS_ONLINE_SERVICE_AREA_URL) {
|
|
605
|
+
return Promise.reject("Finding service areas using the ArcGIS service requires authentication");
|
|
606
|
+
}
|
|
607
|
+
if (isFeatureSet(requestOptions.facilities)) {
|
|
608
|
+
options.params.facilities = requestOptions.facilities;
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
options.params.facilities = normalizeLocationsList(requestOptions.facilities).join(";");
|
|
612
|
+
}
|
|
613
|
+
// optional input param that may need point geometry normalizing
|
|
614
|
+
if (requestOptions.barriers) {
|
|
615
|
+
if (isFeatureSet(requestOptions.barriers)) {
|
|
616
|
+
options.params.barriers = requestOptions.barriers;
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
// optional point geometry barriers must be normalized, too
|
|
620
|
+
// but not if provided as IFeatureSet type
|
|
621
|
+
// note that optional polylineBarriers and polygonBarriers do not need to be normalized
|
|
622
|
+
options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveServiceArea`, options).then(cleanResponse$1);
|
|
626
|
+
}
|
|
627
|
+
function cleanResponse$1(res) {
|
|
628
|
+
// remove "fieldAliases" because it does not do anything.
|
|
629
|
+
delete res.saPolygons.fieldAliases;
|
|
630
|
+
// add "geoJson" property to "saPolygons"
|
|
631
|
+
if (res.saPolygons.spatialReference.wkid === 4326) {
|
|
632
|
+
res.saPolygons.geoJson = arcgisToGeoJSON(res.saPolygons);
|
|
633
|
+
}
|
|
634
|
+
return res;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
638
|
+
* Apache-2.0 */
|
|
639
|
+
/**
|
|
640
|
+
* ```js
|
|
641
|
+
* import { originDestinationMatrix } from '@esri/arcgis-rest-routing';
|
|
642
|
+
* //
|
|
643
|
+
* originDestinationMatrix({
|
|
644
|
+
* origins: [
|
|
645
|
+
* [-90.404302, 38.600621],
|
|
646
|
+
* [-90.364293, 38.620427],
|
|
647
|
+
* ],
|
|
648
|
+
* destinations: [
|
|
649
|
+
* [-90.444716, 38.635501],
|
|
650
|
+
* [-90.311919, 38.633523],
|
|
651
|
+
* [-90.451147, 38.581107]
|
|
652
|
+
* ],
|
|
653
|
+
* authentication
|
|
654
|
+
* })
|
|
655
|
+
* .then(response) // => { ... }
|
|
656
|
+
* ```
|
|
657
|
+
* 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.
|
|
658
|
+
*
|
|
659
|
+
* @param requestOptions Options to pass through to the routing service.
|
|
660
|
+
* @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.
|
|
661
|
+
* @restlink https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm
|
|
662
|
+
*/
|
|
663
|
+
function originDestinationMatrix(requestOptions) {
|
|
664
|
+
const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;
|
|
665
|
+
requestOptions.params = Object.assign({ outputType: "esriNAODOutputSparseMatrix", returnOrigins: true, returnDestinations: true, returnBarriers: true, returnPolylineBarriers: true, returnPolygonBarriers: true }, requestOptions.params);
|
|
666
|
+
const options = arcgisRestRequest.appendCustomParams(requestOptions, [
|
|
667
|
+
"outputType",
|
|
668
|
+
"barriers",
|
|
669
|
+
"polylineBarriers",
|
|
670
|
+
"polygonBarriers",
|
|
671
|
+
"returnOrigins",
|
|
672
|
+
"returnDestinations",
|
|
673
|
+
"returnBarriers",
|
|
674
|
+
"returnPolylineBarriers",
|
|
675
|
+
"returnPolygonBarriers"
|
|
676
|
+
]);
|
|
677
|
+
// the SAAS service does not support anonymous requests
|
|
678
|
+
if (!requestOptions.authentication &&
|
|
679
|
+
endpoint === ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL) {
|
|
680
|
+
return Promise.reject("Calculating the origin-destination cost matrix using the ArcGIS service requires authentication");
|
|
681
|
+
}
|
|
682
|
+
// use a formatting helper for input params of this type: Array<IPoint | ILocation | [number, number]>
|
|
683
|
+
if (isFeatureSet(requestOptions.origins)) {
|
|
684
|
+
options.params.origins = requestOptions.origins;
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
options.params.origins = normalizeLocationsList(requestOptions.origins).join(";");
|
|
688
|
+
}
|
|
689
|
+
if (isFeatureSet(requestOptions.destinations)) {
|
|
690
|
+
options.params.destinations = requestOptions.destinations;
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
options.params.destinations = normalizeLocationsList(requestOptions.destinations).join(";");
|
|
694
|
+
}
|
|
695
|
+
// optional input param that may need point geometry normalizing
|
|
696
|
+
if (requestOptions.barriers) {
|
|
697
|
+
if (isFeatureSet(requestOptions.barriers)) {
|
|
698
|
+
options.params.barriers = requestOptions.barriers;
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
// optional point geometry barriers must be normalized, too
|
|
702
|
+
// but not if provided as IFeatureSet type
|
|
703
|
+
// note that optional polylineBarriers and polygonBarriers do not need to be normalized
|
|
704
|
+
options.params.barriers = normalizeLocationsList(requestOptions.barriers).join(";");
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return arcgisRestRequest.request(`${arcgisRestRequest.cleanUrl(endpoint)}/solveODCostMatrix`, options).then(function (res) {
|
|
708
|
+
return cleanResponse(res, options);
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
function cleanResponse(res, options) {
|
|
712
|
+
// add "geoJson" property to each response property that is an arcgis featureSet
|
|
713
|
+
// res.odLines only exists and only includes geometry in this condition (out of 3 possible options.params.outputType conditions)
|
|
714
|
+
if (options.params.outputType === "esriNAODOutputStraightLines" &&
|
|
715
|
+
res.odLines &&
|
|
716
|
+
res.odLines.spatialReference.wkid === 4326) {
|
|
717
|
+
res.odLines.geoJson = arcgisToGeoJSON(res.odLines);
|
|
718
|
+
}
|
|
719
|
+
if (res.origins && res.origins.spatialReference.wkid === 4326) {
|
|
720
|
+
res.origins.geoJson = arcgisToGeoJSON(res.origins);
|
|
721
|
+
}
|
|
722
|
+
if (res.destinations && res.destinations.spatialReference.wkid === 4326) {
|
|
723
|
+
res.destinations.geoJson = arcgisToGeoJSON(res.destinations);
|
|
724
|
+
}
|
|
725
|
+
if (res.barriers && res.barriers.spatialReference.wkid === 4326) {
|
|
726
|
+
res.barriers.geoJson = arcgisToGeoJSON(res.barriers);
|
|
727
|
+
}
|
|
728
|
+
if (res.polygonBarriers &&
|
|
729
|
+
res.polygonBarriers.spatialReference.wkid === 4326) {
|
|
730
|
+
res.polygonBarriers.geoJson = arcgisToGeoJSON(res.polygonBarriers);
|
|
731
|
+
}
|
|
732
|
+
if (res.polylineBarriers &&
|
|
733
|
+
res.polylineBarriers.spatialReference.wkid === 4326) {
|
|
734
|
+
res.polylineBarriers.geoJson = arcgisToGeoJSON(res.polylineBarriers);
|
|
735
|
+
}
|
|
736
|
+
return res;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
exports.ARCGIS_ONLINE_CLOSEST_FACILITY_URL = ARCGIS_ONLINE_CLOSEST_FACILITY_URL;
|
|
740
|
+
exports.ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;
|
|
741
|
+
exports.ARCGIS_ONLINE_ROUTING_URL = ARCGIS_ONLINE_ROUTING_URL;
|
|
742
|
+
exports.ARCGIS_ONLINE_SERVICE_AREA_URL = ARCGIS_ONLINE_SERVICE_AREA_URL;
|
|
743
|
+
exports.closestFacility = closestFacility;
|
|
744
|
+
exports.decompressGeometry = decompressGeometry;
|
|
745
|
+
exports.isFeatureSet = isFeatureSet;
|
|
746
|
+
exports.normalizeLocationsList = normalizeLocationsList;
|
|
747
|
+
exports.originDestinationMatrix = originDestinationMatrix;
|
|
748
|
+
exports.serviceArea = serviceArea;
|
|
749
|
+
exports.solveRoute = solveRoute;
|
|
750
|
+
|
|
751
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
752
|
+
|
|
753
|
+
}));
|
|
754
|
+
//# sourceMappingURL=routing.umd.js.map
|