@esri/arcgis-rest-routing 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled/routing.esm.js +13 -5
- package/dist/bundled/routing.esm.js.map +1 -1
- package/dist/bundled/routing.esm.min.js +4 -4
- package/dist/bundled/routing.esm.min.js.map +1 -1
- package/dist/bundled/routing.umd.js +13 -4
- package/dist/bundled/routing.umd.js.map +1 -1
- package/dist/bundled/routing.umd.min.js +4 -4
- package/dist/bundled/routing.umd.min.js.map +1 -1
- package/dist/cjs/closestFacility.js +4 -2
- package/dist/cjs/closestFacility.js.map +1 -1
- package/dist/cjs/helpers.js +8 -1
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/closestFacility.d.ts +6 -2
- package/dist/esm/closestFacility.js +5 -3
- package/dist/esm/closestFacility.js.map +1 -1
- package/dist/esm/helpers.d.ts +4 -0
- package/dist/esm/helpers.js +6 -0
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.umd.min.js","sources":["../../src/helpers.ts","../../../../node_modules/@terraformer/arcgis/dist/t-arcgis.esm.js","../../src/solveRoute.ts","../../src/closestFacility.ts","../../src/serviceArea.ts","../../src/originDestinationMatrix.ts"],"sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\r\n * Apache-2.0 */\r\n\r\nimport { \r\n IRequestOptions,\r\n ILocation,\r\n IPoint,\r\n IPolyline,\r\n Position2D,\r\n IFeatureSet\r\n} from \"@esri/arcgis-rest-request\";\r\n\r\n// https always\r\nexport const ARCGIS_ONLINE_ROUTING_URL =\r\n \"https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World\";\r\nexport const ARCGIS_ONLINE_CLOSEST_FACILITY_URL =\r\n \"https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World\";\r\nexport const ARCGIS_ONLINE_SERVICE_AREA_URL =\r\n \"https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World\";\r\nexport const ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL =\r\n \"https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World\";\r\n\r\n// nice to have: verify custom endpoints contain 'NAServer' and end in a '/'\r\nexport interface IEndpointOptions extends IRequestOptions {\r\n /**\r\n * Any ArcGIS Routing service (example: https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/ ) to use for the routing service request.\r\n */\r\n endpoint?: string;\r\n}\r\n\r\nfunction isLocationArray(\r\n coords: ILocation | IPoint | [number, number] | [number, number, number]\r\n): coords is [number, number] | [number, number, number] {\r\n return (\r\n (coords as [number, number]).length === 2 ||\r\n (coords as [number, number, number]).length === 3\r\n );\r\n}\r\n\r\nfunction isLocation(\r\n coords: ILocation | IPoint | [number, number] | [number, number, number]\r\n): coords is ILocation {\r\n return (\r\n (coords as ILocation).latitude !== undefined ||\r\n (coords as ILocation).lat !== undefined\r\n );\r\n}\r\n\r\nexport function normalizeLocationsList(\r\n locations: Array<IPoint | ILocation | [number, number]>\r\n): string[] {\r\n return locations.map((coords) => {\r\n if (isLocationArray(coords)) {\r\n return coords.join();\r\n } else if (isLocation(coords)) {\r\n if (coords.lat) {\r\n return coords.long + \",\" + coords.lat;\r\n } else {\r\n return coords.longitude + \",\" + coords.latitude;\r\n }\r\n } else {\r\n return coords.x + \",\" + coords.y;\r\n }\r\n });\r\n}\r\n\r\nexport function decompressGeometry(str: string) {\r\n let xDiffPrev = 0;\r\n let yDiffPrev = 0;\r\n const points = [];\r\n let x;\r\n let y;\r\n\r\n // Split the string into an array on the + and - characters\r\n const strings = str.match(/((\\+|-)[^+-]+)/g);\r\n\r\n // The first value is the coefficient in base 32\r\n const coefficient = parseInt(strings[0], 32);\r\n\r\n for (let j = 1; j < strings.length; j += 2) {\r\n // j is the offset for the x value\r\n // Convert the value from base 32 and add the previous x value\r\n x = parseInt(strings[j], 32) + xDiffPrev;\r\n xDiffPrev = x;\r\n\r\n // j+1 is the offset for the y value\r\n // Convert the value from base 32 and add the previous y value\r\n y = parseInt(strings[j + 1], 32) + yDiffPrev;\r\n yDiffPrev = y;\r\n\r\n points.push([x / coefficient, y / coefficient] as Position2D);\r\n }\r\n\r\n return {\r\n paths: [points]\r\n } as IPolyline;\r\n}\r\n\r\n/**\r\n * User Defined Type Guard that verifies this is a featureSet\r\n */\r\nexport function isFeatureSet(arg: any): arg is IFeatureSet {\r\n return Object.prototype.hasOwnProperty.call(arg, \"features\");\r\n}\r\n","/* @preserve\n* @terraformer/arcgis - v2.0.7 - MIT\n* Copyright (c) 2012-2021 Environmental Systems Research Institute, Inc.\n* Thu Jul 22 2021 13:58:30 GMT-0700 (Pacific Daylight Time)\n*/\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nvar edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) {\n var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);\n var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);\n var uB = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);\n\n if (uB !== 0) {\n var ua = uaT / uB;\n var ub = ubT / uB;\n\n if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {\n return true;\n }\n }\n\n return false;\n};\nvar coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) {\n var contains = false;\n\n for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {\n 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]) {\n contains = !contains;\n }\n }\n\n return contains;\n};\nvar pointsEqual = function pointsEqual(a, b) {\n for (var i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n\n return true;\n};\nvar arrayIntersectsArray = function arrayIntersectsArray(a, b) {\n for (var i = 0; i < a.length - 1; i++) {\n for (var j = 0; j < b.length - 1; j++) {\n if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {\n return true;\n }\n }\n }\n\n return false;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nvar closeRing = function closeRing(coordinates) {\n if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {\n coordinates.push(coordinates[0]);\n }\n\n return coordinates;\n}; // determine if polygon ring coordinates are clockwise. clockwise signifies outer ring, counter-clockwise an inner ring\n// or hole. this logic was found at http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-\n// points-are-in-clockwise-order\n\nvar ringIsClockwise = function ringIsClockwise(ringToTest) {\n var total = 0;\n var i = 0;\n var rLength = ringToTest.length;\n var pt1 = ringToTest[i];\n var pt2;\n\n for (i; i < rLength - 1; i++) {\n pt2 = ringToTest[i + 1];\n total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);\n pt1 = pt2;\n }\n\n return total >= 0;\n}; // This function ensures that rings are oriented in the right directions\n// from http://jsperf.com/cloning-an-object/2\n\nvar shallowClone = function shallowClone(obj) {\n var target = {};\n\n for (var i in obj) {\n // both arcgis attributes and geojson props are just hardcoded keys\n if (obj.hasOwnProperty(i)) {\n // eslint-disable-line no-prototype-builtins\n target[i] = obj[i];\n }\n }\n\n return target;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nvar coordinatesContainCoordinates = function coordinatesContainCoordinates(outer, inner) {\n var intersects = arrayIntersectsArray(outer, inner);\n var contains = coordinatesContainPoint(outer, inner[0]);\n\n if (!intersects && contains) {\n return true;\n }\n\n return false;\n}; // do any polygons in this array contain any other polygons in this array?\n// used for checking for holes in arcgis rings\n\n\nvar convertRingsToGeoJSON = function convertRingsToGeoJSON(rings) {\n var outerRings = [];\n var holes = [];\n var x; // iterator\n\n var outerRing; // current outer ring being evaluated\n\n var hole; // current hole being evaluated\n // for each ring\n\n for (var r = 0; r < rings.length; r++) {\n var ring = closeRing(rings[r].slice(0));\n\n if (ring.length < 4) {\n continue;\n } // is this ring an outer ring? is it clockwise?\n\n\n if (ringIsClockwise(ring)) {\n var polygon = [ring.slice().reverse()]; // wind outer rings counterclockwise for RFC 7946 compliance\n\n outerRings.push(polygon); // push to outer rings\n } else {\n holes.push(ring.slice().reverse()); // wind inner rings clockwise for RFC 7946 compliance\n }\n }\n\n var uncontainedHoles = []; // while there are holes left...\n\n while (holes.length) {\n // pop a hole off out stack\n hole = holes.pop(); // loop over all outer rings and see if they contain our hole.\n\n var contained = false;\n\n for (x = outerRings.length - 1; x >= 0; x--) {\n outerRing = outerRings[x][0];\n\n if (coordinatesContainCoordinates(outerRing, hole)) {\n // the hole is contained push it into our polygon\n outerRings[x].push(hole);\n contained = true;\n break;\n }\n } // ring is not contained in any outer ring\n // sometimes this happens https://github.com/Esri/esri-leaflet/issues/320\n\n\n if (!contained) {\n uncontainedHoles.push(hole);\n }\n } // if we couldn't match any holes using contains we can try intersects...\n\n\n while (uncontainedHoles.length) {\n // pop a hole off out stack\n hole = uncontainedHoles.pop(); // loop over all outer rings and see if any intersect our hole.\n\n var intersects = false;\n\n for (x = outerRings.length - 1; x >= 0; x--) {\n outerRing = outerRings[x][0];\n\n if (arrayIntersectsArray(outerRing, hole)) {\n // the hole is contained push it into our polygon\n outerRings[x].push(hole);\n intersects = true;\n break;\n }\n }\n\n if (!intersects) {\n outerRings.push([hole.reverse()]);\n }\n }\n\n if (outerRings.length === 1) {\n return {\n type: 'Polygon',\n coordinates: outerRings[0]\n };\n } else {\n return {\n type: 'MultiPolygon',\n coordinates: outerRings\n };\n }\n};\n\nvar getId = function getId(attributes, idAttribute) {\n var keys = idAttribute ? [idAttribute, 'OBJECTID', 'FID'] : ['OBJECTID', 'FID'];\n\n for (var i = 0; i < keys.length; i++) {\n var key = keys[i];\n\n if (key in attributes && (typeof attributes[key] === 'string' || typeof attributes[key] === 'number')) {\n return attributes[key];\n }\n }\n\n throw Error('No valid id attribute found');\n};\n\nvar arcgisToGeoJSON = function arcgisToGeoJSON(arcgis, idAttribute) {\n var geojson = {};\n\n if (arcgis.features) {\n geojson.type = 'FeatureCollection';\n geojson.features = [];\n\n for (var i = 0; i < arcgis.features.length; i++) {\n geojson.features.push(arcgisToGeoJSON(arcgis.features[i], idAttribute));\n }\n }\n\n if (typeof arcgis.x === 'number' && typeof arcgis.y === 'number') {\n geojson.type = 'Point';\n geojson.coordinates = [arcgis.x, arcgis.y];\n\n if (typeof arcgis.z === 'number') {\n geojson.coordinates.push(arcgis.z);\n }\n }\n\n if (arcgis.points) {\n geojson.type = 'MultiPoint';\n geojson.coordinates = arcgis.points.slice(0);\n }\n\n if (arcgis.paths) {\n if (arcgis.paths.length === 1) {\n geojson.type = 'LineString';\n geojson.coordinates = arcgis.paths[0].slice(0);\n } else {\n geojson.type = 'MultiLineString';\n geojson.coordinates = arcgis.paths.slice(0);\n }\n }\n\n if (arcgis.rings) {\n geojson = convertRingsToGeoJSON(arcgis.rings.slice(0));\n }\n\n if (typeof arcgis.xmin === 'number' && typeof arcgis.ymin === 'number' && typeof arcgis.xmax === 'number' && typeof arcgis.ymax === 'number') {\n geojson.type = 'Polygon';\n geojson.coordinates = [[[arcgis.xmax, arcgis.ymax], [arcgis.xmin, arcgis.ymax], [arcgis.xmin, arcgis.ymin], [arcgis.xmax, arcgis.ymin], [arcgis.xmax, arcgis.ymax]]];\n }\n\n if (arcgis.geometry || arcgis.attributes) {\n geojson.type = 'Feature';\n geojson.geometry = arcgis.geometry ? arcgisToGeoJSON(arcgis.geometry) : null;\n geojson.properties = arcgis.attributes ? shallowClone(arcgis.attributes) : null;\n\n if (arcgis.attributes) {\n try {\n geojson.id = getId(arcgis.attributes, idAttribute);\n } catch (err) {// don't set an id\n }\n }\n } // if no valid geometry was encountered\n\n\n if (JSON.stringify(geojson.geometry) === JSON.stringify({})) {\n geojson.geometry = null;\n }\n\n if (arcgis.spatialReference && arcgis.spatialReference.wkid && arcgis.spatialReference.wkid !== 4326) {\n console.warn('Object converted in non-standard crs - ' + JSON.stringify(arcgis.spatialReference));\n }\n\n return geojson;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n// outer rings are clockwise, holes are counterclockwise\n// used for converting GeoJSON Polygons to ArcGIS Polygons\n\nvar orientRings = function orientRings(poly) {\n var output = [];\n var polygon = poly.slice(0);\n var outerRing = closeRing(polygon.shift().slice(0));\n\n if (outerRing.length >= 4) {\n if (!ringIsClockwise(outerRing)) {\n outerRing.reverse();\n }\n\n output.push(outerRing);\n\n for (var i = 0; i < polygon.length; i++) {\n var hole = closeRing(polygon[i].slice(0));\n\n if (hole.length >= 4) {\n if (ringIsClockwise(hole)) {\n hole.reverse();\n }\n\n output.push(hole);\n }\n }\n }\n\n return output;\n}; // This function flattens holes in multipolygons to one array of polygons\n// used for converting GeoJSON Polygons to ArcGIS Polygons\n\n\nvar flattenMultiPolygonRings = function flattenMultiPolygonRings(rings) {\n var output = [];\n\n for (var i = 0; i < rings.length; i++) {\n var polygon = orientRings(rings[i]);\n\n for (var x = polygon.length - 1; x >= 0; x--) {\n var ring = polygon[x].slice(0);\n output.push(ring);\n }\n }\n\n return output;\n};\n\nvar geojsonToArcGIS = function geojsonToArcGIS(geojson, idAttribute) {\n idAttribute = idAttribute || 'OBJECTID';\n var spatialReference = {\n wkid: 4326\n };\n var result = {};\n var i;\n\n switch (geojson.type) {\n case 'Point':\n result.x = geojson.coordinates[0];\n result.y = geojson.coordinates[1];\n\n if (geojson.coordinates[2]) {\n result.z = geojson.coordinates[2];\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'MultiPoint':\n result.points = geojson.coordinates.slice(0);\n\n if (geojson.coordinates[0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'LineString':\n result.paths = [geojson.coordinates.slice(0)];\n\n if (geojson.coordinates[0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'MultiLineString':\n result.paths = geojson.coordinates.slice(0);\n\n if (geojson.coordinates[0][0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'Polygon':\n result.rings = orientRings(geojson.coordinates.slice(0));\n\n if (geojson.coordinates[0][0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'MultiPolygon':\n result.rings = flattenMultiPolygonRings(geojson.coordinates.slice(0));\n\n if (geojson.coordinates[0][0][0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'Feature':\n if (geojson.geometry) {\n result.geometry = geojsonToArcGIS(geojson.geometry, idAttribute);\n }\n\n result.attributes = geojson.properties ? shallowClone(geojson.properties) : {};\n\n if (geojson.id) {\n result.attributes[idAttribute] = geojson.id;\n }\n\n break;\n\n case 'FeatureCollection':\n result = [];\n\n for (i = 0; i < geojson.features.length; i++) {\n result.push(geojsonToArcGIS(geojson.features[i], idAttribute));\n }\n\n break;\n\n case 'GeometryCollection':\n result = [];\n\n for (i = 0; i < geojson.geometries.length; i++) {\n result.push(geojsonToArcGIS(geojson.geometries[i], idAttribute));\n }\n\n break;\n }\n\n return result;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport { arcgisToGeoJSON, geojsonToArcGIS };\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n ILocation,\n IPoint,\n IFeature,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_ROUTING_URL,\n IEndpointOptions,\n decompressGeometry,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\ninterface IFeatureWithCompressedGeometry extends IFeature {\n compressedGeometry?: string;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: {};\n}\n\nexport interface ISolveRouteOptions extends IEndpointOptions {\n /**\n * Specify two or more locations between which the route is to be found.\n */\n stops:\n | Array<IPoint | ILocation | [number, number] | [number, number, number]>\n | IFeatureSet;\n}\n\nexport interface ISolveRouteResponse {\n messages: string[];\n checksum: string;\n routes: IFeatureSetWithGeoJson;\n directions?: Array<{\n routeId: number;\n routeName: string;\n summary: object;\n features: IFeature[];\n }>;\n}\n\nfunction isLocationArray(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is [number, number] | [number, number, number] {\n return (\n (coords as [number, number]).length === 2 ||\n (coords as [number, number, number]).length === 3\n );\n}\n\nfunction isLocation(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is ILocation {\n return (\n (coords as ILocation).latitude !== undefined ||\n (coords as ILocation).lat !== undefined\n );\n}\n\n/**\n * 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.\n *\n * ```js\n * import { solveRoute } from '@esri/arcgis-rest-routing';\n *\n * solveRoute({\n * stops: [\n * [-117.195677, 34.056383],\n * [-117.918976, 33.812092],\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with routes and directions for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm\n */\nexport function solveRoute(\n requestOptions: ISolveRouteOptions\n): Promise<ISolveRouteResponse> {\n const options: ISolveRouteOptions = {\n endpoint: requestOptions.endpoint || ARCGIS_ONLINE_ROUTING_URL,\n params: {},\n ...requestOptions\n };\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n options.endpoint === ARCGIS_ONLINE_ROUTING_URL\n ) {\n return Promise.reject(\n \"Routing using the ArcGIS service requires authentication\"\n );\n }\n\n if (isFeatureSet(requestOptions.stops)) {\n options.params.stops = requestOptions.stops;\n } else {\n const stops: string[] = requestOptions.stops.map((coords) => {\n if (isLocationArray(coords)) {\n return coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n return (\n coords.long + \",\" + coords.lat + (coords.z ? \",\" + coords.z : \"\")\n );\n } else {\n return (\n coords.longitude +\n \",\" +\n coords.latitude +\n (coords.z ? \",\" + coords.z : \"\")\n );\n }\n } else {\n return coords.x + \",\" + coords.y + (coords.z ? \",\" + coords.z : \"\");\n }\n });\n\n options.params.stops = stops.join(\";\");\n }\n\n return request(`${cleanUrl(options.endpoint)}/solve`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): ISolveRouteResponse {\n if (res.directions && res.directions.length > 0) {\n res.directions = res.directions.map(\n (direction: {\n features: IFeatureWithCompressedGeometry[];\n routeId: number;\n routeName: string;\n summary: {};\n }) => {\n direction.features = direction.features.map(\n (feature: IFeatureWithCompressedGeometry) => {\n feature.geometry = decompressGeometry(feature.compressedGeometry);\n return feature;\n }\n );\n return direction;\n }\n );\n }\n\n // add \"geoJson\" property to \"routes\"\n if (res.routes.spatialReference.wkid === 4326) {\n const features = res.routes.features.map((feature: any) => {\n return {\n type: \"Feature\",\n geometry: arcgisToGeoJSON(feature.geometry),\n properties: Object.assign({}, feature.attributes)\n };\n });\n\n res.routes.geoJson = {\n type: \"FeatureCollection\",\n features\n };\n }\n return res;\n}\n\nexport default {\n solveRoute\n};\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n ILocation,\n IPoint,\n IFeature,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_CLOSEST_FACILITY_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IClosestFacilityOptions extends IEndpointOptions {\n /**\n * Specify one or more locations from which the service searches for the nearby locations. These locations are referred to as incidents.\n */\n incidents: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n\n /**\n * Specify one or more locations that are searched for when finding the closest location.\n */\n facilities: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify if the service should return routes.\n */\n returnCFRoutes: boolean;\n travelDirection?: \"incidentsToFacilities\" | \"facilitiesToIncidents\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n returnDirections?: boolean;\n directionsOutputType?:\n | \"esriDOTComplete\"\n | \"esriDOTCompleteNoEvents\"\n | \"esriDOTInstructionsOnly\"\n | \"esriDOTStandard\"\n | \"esriDOTSummaryOnly\"\n | \"esriDOTFeatureSets\";\n directionsLengthUnits?:\n | \"esriNAUCentimeters\"\n | \"esriNAUDecimalDegrees\"\n | \"esriNAUDecimeters\"\n | \"esriNAUFeet\"\n | \"esriNAUInches\"\n | \"esriNAUKilometers\"\n | \"esriNAUMeters\"\n | \"esriNAUMiles\"\n | \"esriNAUMillimeters\"\n | \"esriNAUNauticalMiles\"\n | \"esriNAUPoints\"\n | \"esriNAUYards\";\n outputLines?: boolean;\n returnFacilities?: boolean;\n returnIncidents?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n preserveObjectID?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IClosestFacilityResponse {\n messages: string[];\n routes?: IFeatureSetWithGeoJson;\n directions?: Array<{\n routeId: number;\n routeName: string;\n summary: object;\n features: IFeature[];\n }>;\n incidents?: IFeatureSet;\n facilities?: IFeatureSet;\n barriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n polylineBarriers?: IFeatureSet;\n}\n\nfunction getTravelDirection(\n key: \"incidentsToFacilities\" | \"facilitiesToIncidents\"\n): \"esriNATravelDirectionFromFacility\" | \"esriNATravelDirectionToFacility\" {\n if (key === \"incidentsToFacilities\") {\n return \"esriNATravelDirectionFromFacility\";\n } else {\n return \"esriNATravelDirectionToFacility\";\n }\n}\n\n/**\n * 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.\n *\n * ```js\n * import { closestFacility } from '@esri/arcgis-rest-routing';\n *\n * closestFacility({\n * incidents: [\n * [-90.404302, 38.600621],\n * [-90.364293, 38.620427],\n * ],\n * facilities: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with routes and directions for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm\n * @inline IClosestFacilityOptions\n */\nexport function closestFacility(\n requestOptions: IClosestFacilityOptions\n): Promise<IClosestFacilityResponse> {\n const endpoint =\n requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;\n\n requestOptions.params = {\n returnFacilities: true,\n returnDirections: true,\n returnIncidents: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n preserveObjectID: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IClosestFacilityOptions>(requestOptions, [\n \"returnCFRoutes\",\n // \"travelDirection\",\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"returnDirections\",\n \"directionsOutputType\",\n \"directionsLengthUnits\",\n \"outputLines\",\n \"returnFacilities\",\n \"returnIncidents\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\",\n \"preserveObjectID\"\n ]);\n\n // Set travelDirection\n if (requestOptions.travelDirection) {\n options.params.travelDirection = getTravelDirection(\n requestOptions.travelDirection\n );\n }\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL\n ) {\n return Promise.reject(\n \"Finding the closest facility using the ArcGIS service requires authentication\"\n );\n }\n\n if (isFeatureSet(requestOptions.incidents)) {\n options.params.incidents = requestOptions.incidents;\n } else {\n options.params.incidents = normalizeLocationsList(\n requestOptions.incidents\n ).join(\";\");\n }\n\n if (isFeatureSet(requestOptions.facilities)) {\n options.params.facilities = requestOptions.facilities;\n } else {\n options.params.facilities = normalizeLocationsList(\n requestOptions.facilities\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveClosestFacility`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): IClosestFacilityResponse {\n // add \"geoJson\" property to \"routes\"\n if (res.routes.spatialReference.wkid === 4326) {\n res.routes.geoJson = arcgisToGeoJSON(res.routes);\n }\n return res;\n}\n\nexport default {\n closestFacility\n};\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n ILocation,\n IPoint,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_SERVICE_AREA_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IServiceAreaOptions extends IEndpointOptions {\n /**\n * Specify one or more locations around which service areas are generated.\n */\n facilities: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify if the service should return routes.\n */\n travelDirection?: \"incidentsToFacilities\" | \"facilitiesToIncidents\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n outputLines?: boolean;\n returnFacilities?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n preserveObjectID?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IServiceAreaResponse {\n messages: string[];\n saPolygons?: IFeatureSetWithGeoJson;\n incidents?: IFeatureSet;\n facilities?: IFeatureSet;\n barriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n polylineBarriers?: IFeatureSet;\n}\n\nfunction getTravelDirection(\n key: \"incidentsToFacilities\" | \"facilitiesToIncidents\"\n): \"esriNATravelDirectionFromFacility\" | \"esriNATravelDirectionToFacility\" {\n if (key === \"incidentsToFacilities\") {\n return \"esriNATravelDirectionFromFacility\";\n } else {\n return \"esriNATravelDirectionToFacility\";\n }\n}\n\n/**\n * 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.\n *\n * ```js\n * import { serviceArea } from '@esri/arcgis-rest-routing';\n *\n * serviceArea({\n * facilities: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with service area polygons for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm\n */\nexport function serviceArea(\n requestOptions: IServiceAreaOptions\n): Promise<IServiceAreaResponse> {\n const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_SERVICE_AREA_URL;\n\n requestOptions.params = {\n returnFacilities: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n preserveObjectID: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IServiceAreaOptions>(requestOptions, [\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"outputLines\",\n \"returnFacilities\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\",\n \"preserveObjectID\"\n ]);\n\n // Set travelDirection\n if (requestOptions.travelDirection) {\n options.params.travelDirection = getTravelDirection(\n requestOptions.travelDirection\n );\n }\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_SERVICE_AREA_URL\n ) {\n return Promise.reject(\n \"Finding service areas using the ArcGIS service requires authentication\"\n );\n }\n\n if (isFeatureSet(requestOptions.facilities)) {\n options.params.facilities = requestOptions.facilities;\n } else {\n options.params.facilities = normalizeLocationsList(\n requestOptions.facilities\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveServiceArea`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): IServiceAreaResponse {\n // remove \"fieldAliases\" because it does not do anything.\n delete res.saPolygons.fieldAliases;\n\n // add \"geoJson\" property to \"saPolygons\"\n if (res.saPolygons.spatialReference.wkid === 4326) {\n res.saPolygons.geoJson = arcgisToGeoJSON(res.saPolygons);\n }\n return res;\n}\n\nexport default {\n serviceArea\n};\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n IRequestOptions,\n ILocation,\n IPoint,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IOriginDestinationMatrixOptions extends IEndpointOptions {\n /**\n * Specify the starting points from which to travel to the destinations.\n */\n origins: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify the ending point locations to travel to from the origins.\n */\n destinations: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify the type of output returned by the service. Defaults to \"esriNAODOutputSparseMatrix\".\n */\n outputType?:\n | \"esriNAODOutputSparseMatrix\"\n | \"esriNAODOutputStraightLines\"\n | \"esriNAODOutputNoLines\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n returnOrigins?: boolean;\n returnDestinations?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IOriginDestinationMatrixResponse {\n messages: [{ type: number; description: string }];\n /**\n * Only present if outputType is \"esriNAODOutputSparseMatrix\". Full description is available at https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm#ESRI_SECTION2_114F8364507C4B56B780DFAD505270FB.\n */\n odCostMatrix?: any;\n /**\n * Only present if outputType is \"esriNAODOutputStraightLines\" or \"esriNAODOutputNoLines\". Includes the geometry for the straight line connecting each origin-destination pair when the outputType is \"esriNAODOutputStraightLines\".\n */\n odLines?: IFeatureSetWithGeoJson;\n origins?: IFeatureSetWithGeoJson;\n destinations?: IFeatureSetWithGeoJson;\n barriers?: IFeatureSetWithGeoJson;\n polylineBarriers?: IFeatureSetWithGeoJson;\n polygonBarriers?: IFeatureSetWithGeoJson;\n}\n\n/**\n * 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.\n *\n * ```js\n * import { originDestinationMatrix } from '@esri/arcgis-rest-routing';\n *\n * originDestinationMatrix({\n * origins: [\n * [-90.404302, 38.600621],\n * [-90.364293, 38.620427],\n * ],\n * destinations: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => { ... }\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @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.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm\n */\nexport function originDestinationMatrix(\n requestOptions: IOriginDestinationMatrixOptions\n): Promise<IOriginDestinationMatrixResponse> {\n const endpoint =\n requestOptions.endpoint || ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;\n\n requestOptions.params = {\n outputType: \"esriNAODOutputSparseMatrix\",\n returnOrigins: true,\n returnDestinations: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IOriginDestinationMatrixOptions>(\n requestOptions,\n [\n \"outputType\",\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"returnOrigins\",\n \"returnDestinations\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\"\n ]\n );\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL\n ) {\n return Promise.reject(\n \"Calculating the origin-destination cost matrix using the ArcGIS service requires authentication\"\n );\n }\n\n // use a formatting helper for input params of this type: Array<IPoint | ILocation | [number, number]>\n if (isFeatureSet(requestOptions.origins)) {\n options.params.origins = requestOptions.origins;\n } else {\n options.params.origins = normalizeLocationsList(\n requestOptions.origins\n ).join(\";\");\n }\n\n if (isFeatureSet(requestOptions.destinations)) {\n options.params.destinations = requestOptions.destinations;\n } else {\n options.params.destinations = normalizeLocationsList(\n requestOptions.destinations\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveODCostMatrix`, options).then(\n function (res) {\n return cleanResponse(res, options);\n }\n );\n}\n\nfunction cleanResponse(\n res: any,\n options: IRequestOptions\n): IOriginDestinationMatrixResponse {\n // add \"geoJson\" property to each response property that is an arcgis featureSet\n\n // res.odLines only exists and only includes geometry in this condition (out of 3 possible options.params.outputType conditions)\n if (\n options.params.outputType === \"esriNAODOutputStraightLines\" &&\n res.odLines &&\n res.odLines.spatialReference.wkid === 4326\n ) {\n res.odLines.geoJson = arcgisToGeoJSON(res.odLines);\n }\n\n if (res.origins && res.origins.spatialReference.wkid === 4326) {\n res.origins.geoJson = arcgisToGeoJSON(res.origins);\n }\n\n if (res.destinations && res.destinations.spatialReference.wkid === 4326) {\n res.destinations.geoJson = arcgisToGeoJSON(res.destinations);\n }\n\n if (res.barriers && res.barriers.spatialReference.wkid === 4326) {\n res.barriers.geoJson = arcgisToGeoJSON(res.barriers);\n }\n\n if (\n res.polygonBarriers &&\n res.polygonBarriers.spatialReference.wkid === 4326\n ) {\n res.polygonBarriers.geoJson = arcgisToGeoJSON(res.polygonBarriers);\n }\n\n if (\n res.polylineBarriers &&\n res.polylineBarriers.spatialReference.wkid === 4326\n ) {\n res.polylineBarriers.geoJson = arcgisToGeoJSON(res.polylineBarriers);\n }\n\n return res;\n}\n\nexport default {\n originDestinationMatrix\n};\n"],"names":["ARCGIS_ONLINE_ROUTING_URL","ARCGIS_ONLINE_CLOSEST_FACILITY_URL","ARCGIS_ONLINE_SERVICE_AREA_URL","ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL","normalizeLocationsList","locations","map","coords","length","isLocationArray","join","undefined","latitude","lat","isLocation","long","longitude","x","y","decompressGeometry","str","xDiffPrev","yDiffPrev","points","strings","match","coefficient","parseInt","j","push","paths","isFeatureSet","arg","Object","prototype","hasOwnProperty","call","edgeIntersectsEdge","a1","a2","b1","b2","uaT","ubT","uB","ua","ub","arrayIntersectsArray","a","b","i","ringIsClockwise","ringToTest","pt2","total","rLength","pt1","coordinatesContainCoordinates","outer","inner","intersects","contains","coordinates","point","l","coordinatesContainPoint","arcgisToGeoJSON","arcgis","idAttribute","geojson","features","type","z","slice","rings","outerRing","hole","outerRings","holes","r","ring","pointsEqual","polygon","reverse","uncontainedHoles","pop","contained","convertRingsToGeoJSON","xmin","ymin","xmax","ymax","geometry","attributes","properties","obj","target","shallowClone","id","keys","key","Error","getId","err","JSON","stringify","spatialReference","wkid","console","warn","cleanResponse","res","directions","direction","feature","compressedGeometry","routes","assign","geoJson","saPolygons","fieldAliases","requestOptions","endpoint","params","returnFacilities","returnDirections","returnIncidents","returnBarriers","returnPolylineBarriers","returnPolygonBarriers","preserveObjectID","options","appendCustomParams","travelDirection","authentication","incidents","facilities","barriers","request","cleanUrl","then","Promise","reject","outputType","returnO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,iGFpCJrB,GAEA,MAAMU,iBACJT,SAAUD,EAAeC,UAAY1H,EACrC2H,OAAQ,IACLF,GAIL,IACGA,EAAea,gBAChBH,EAAQT,WAAa1H,EAErB,OAAO6I,QAAQC,OACb,4DAIJ,GAAI/G,EAAa0F,EAAe8B,OAC9BpB,EAAQR,OAAO4B,MAAQ9B,EAAe8B,UACjC,CACL,MAAMA,EAAkB9B,EAAe8B,MAAMjJ,KAAKC,GA5DtD,SACEA,GAEA,OAC0C,IAAvCA,EAA4BC,QACmB,IAA/CD,EAAoCC,OAwD/BC,CAAgBF,GACXA,EAAOG,OArDtB,SACEH,GAEA,YACqCI,IAAlCJ,EAAqBK,eACQD,IAA7BJ,EAAqBM,IAiDTC,CAAWP,GAChBA,EAAOM,IAEPN,EAAOQ,KAAO,IAAMR,EAAOM,KAAON,EAAOiE,EAAI,IAAMjE,EAAOiE,EAAI,IAI9DjE,EAAOS,UACP,IACAT,EAAOK,UACNL,EAAOiE,EAAI,IAAMjE,EAAOiE,EAAI,IAI1BjE,EAAOU,EAAI,IAAMV,EAAOW,GAAKX,EAAOiE,EAAI,IAAMjE,EAAOiE,EAAI,MAIpE2D,EAAQR,OAAO4B,MAAQA,EAAM7I,KAAK,KAGpC,OAAOgI,UAAQ,GAAGC,WAASR,EAAQT,kBAAmBS,GAASS,KAC7D9B"}
|
|
1
|
+
{"version":3,"file":"routing.umd.min.js","sources":["../../src/helpers.ts","../../../../node_modules/@terraformer/arcgis/dist/t-arcgis.esm.js","../../src/solveRoute.ts","../../src/closestFacility.ts","../../src/serviceArea.ts","../../src/originDestinationMatrix.ts"],"sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IRequestOptions,\n ILocation,\n IPoint,\n IPolyline,\n Position2D,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\n// https always\nexport const ARCGIS_ONLINE_ROUTING_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World\";\nexport const ARCGIS_ONLINE_CLOSEST_FACILITY_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World\";\nexport const ARCGIS_ONLINE_SERVICE_AREA_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World\";\nexport const ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World\";\n\n// nice to have: verify custom endpoints contain 'NAServer' and end in a '/'\nexport interface IEndpointOptions extends IRequestOptions {\n /**\n * Any ArcGIS Routing service (example: https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/ ) to use for the routing service request.\n */\n endpoint?: string;\n}\n\nfunction isLocationArray(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is [number, number] | [number, number, number] {\n return (\n (coords as [number, number]).length === 2 ||\n (coords as [number, number, number]).length === 3\n );\n}\n\nfunction isLocation(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is ILocation {\n return (\n (coords as ILocation).latitude !== undefined ||\n (coords as ILocation).lat !== undefined\n );\n}\n\nexport function normalizeLocationsList(\n locations: Array<IPoint | ILocation | [number, number]>\n): string[] {\n return locations.map((coords) => {\n if (isLocationArray(coords)) {\n return coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n return coords.long + \",\" + coords.lat;\n } else {\n return coords.longitude + \",\" + coords.latitude;\n }\n } else {\n return coords.x + \",\" + coords.y;\n }\n });\n}\n\nexport function decompressGeometry(str: string) {\n let xDiffPrev = 0;\n let yDiffPrev = 0;\n const points = [];\n let x;\n let y;\n\n // Split the string into an array on the + and - characters\n const strings = str.match(/((\\+|-)[^+-]+)/g);\n\n // The first value is the coefficient in base 32\n const coefficient = parseInt(strings[0], 32);\n\n for (let j = 1; j < strings.length; j += 2) {\n // j is the offset for the x value\n // Convert the value from base 32 and add the previous x value\n x = parseInt(strings[j], 32) + xDiffPrev;\n xDiffPrev = x;\n\n // j+1 is the offset for the y value\n // Convert the value from base 32 and add the previous y value\n y = parseInt(strings[j + 1], 32) + yDiffPrev;\n yDiffPrev = y;\n\n points.push([x / coefficient, y / coefficient] as Position2D);\n }\n\n return {\n paths: [points]\n } as IPolyline;\n}\n\n/**\n * User Defined Type Guard that verifies this is a featureSet\n */\nexport function isFeatureSet(arg: any): arg is IFeatureSet {\n return Object.prototype.hasOwnProperty.call(arg, \"features\");\n}\n\n/**\n * User Defined Type Guard that verifies this is a JSON with `url` property\n */\nexport function isJsonWithURL(arg: any): arg is Object {\n return \"url\" in arg;\n}\n","/* @preserve\n* @terraformer/arcgis - v2.0.7 - MIT\n* Copyright (c) 2012-2021 Environmental Systems Research Institute, Inc.\n* Thu Jul 22 2021 13:58:30 GMT-0700 (Pacific Daylight Time)\n*/\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nvar edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) {\n var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);\n var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);\n var uB = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);\n\n if (uB !== 0) {\n var ua = uaT / uB;\n var ub = ubT / uB;\n\n if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {\n return true;\n }\n }\n\n return false;\n};\nvar coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) {\n var contains = false;\n\n for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {\n 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]) {\n contains = !contains;\n }\n }\n\n return contains;\n};\nvar pointsEqual = function pointsEqual(a, b) {\n for (var i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n\n return true;\n};\nvar arrayIntersectsArray = function arrayIntersectsArray(a, b) {\n for (var i = 0; i < a.length - 1; i++) {\n for (var j = 0; j < b.length - 1; j++) {\n if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {\n return true;\n }\n }\n }\n\n return false;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nvar closeRing = function closeRing(coordinates) {\n if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {\n coordinates.push(coordinates[0]);\n }\n\n return coordinates;\n}; // determine if polygon ring coordinates are clockwise. clockwise signifies outer ring, counter-clockwise an inner ring\n// or hole. this logic was found at http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-\n// points-are-in-clockwise-order\n\nvar ringIsClockwise = function ringIsClockwise(ringToTest) {\n var total = 0;\n var i = 0;\n var rLength = ringToTest.length;\n var pt1 = ringToTest[i];\n var pt2;\n\n for (i; i < rLength - 1; i++) {\n pt2 = ringToTest[i + 1];\n total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);\n pt1 = pt2;\n }\n\n return total >= 0;\n}; // This function ensures that rings are oriented in the right directions\n// from http://jsperf.com/cloning-an-object/2\n\nvar shallowClone = function shallowClone(obj) {\n var target = {};\n\n for (var i in obj) {\n // both arcgis attributes and geojson props are just hardcoded keys\n if (obj.hasOwnProperty(i)) {\n // eslint-disable-line no-prototype-builtins\n target[i] = obj[i];\n }\n }\n\n return target;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nvar coordinatesContainCoordinates = function coordinatesContainCoordinates(outer, inner) {\n var intersects = arrayIntersectsArray(outer, inner);\n var contains = coordinatesContainPoint(outer, inner[0]);\n\n if (!intersects && contains) {\n return true;\n }\n\n return false;\n}; // do any polygons in this array contain any other polygons in this array?\n// used for checking for holes in arcgis rings\n\n\nvar convertRingsToGeoJSON = function convertRingsToGeoJSON(rings) {\n var outerRings = [];\n var holes = [];\n var x; // iterator\n\n var outerRing; // current outer ring being evaluated\n\n var hole; // current hole being evaluated\n // for each ring\n\n for (var r = 0; r < rings.length; r++) {\n var ring = closeRing(rings[r].slice(0));\n\n if (ring.length < 4) {\n continue;\n } // is this ring an outer ring? is it clockwise?\n\n\n if (ringIsClockwise(ring)) {\n var polygon = [ring.slice().reverse()]; // wind outer rings counterclockwise for RFC 7946 compliance\n\n outerRings.push(polygon); // push to outer rings\n } else {\n holes.push(ring.slice().reverse()); // wind inner rings clockwise for RFC 7946 compliance\n }\n }\n\n var uncontainedHoles = []; // while there are holes left...\n\n while (holes.length) {\n // pop a hole off out stack\n hole = holes.pop(); // loop over all outer rings and see if they contain our hole.\n\n var contained = false;\n\n for (x = outerRings.length - 1; x >= 0; x--) {\n outerRing = outerRings[x][0];\n\n if (coordinatesContainCoordinates(outerRing, hole)) {\n // the hole is contained push it into our polygon\n outerRings[x].push(hole);\n contained = true;\n break;\n }\n } // ring is not contained in any outer ring\n // sometimes this happens https://github.com/Esri/esri-leaflet/issues/320\n\n\n if (!contained) {\n uncontainedHoles.push(hole);\n }\n } // if we couldn't match any holes using contains we can try intersects...\n\n\n while (uncontainedHoles.length) {\n // pop a hole off out stack\n hole = uncontainedHoles.pop(); // loop over all outer rings and see if any intersect our hole.\n\n var intersects = false;\n\n for (x = outerRings.length - 1; x >= 0; x--) {\n outerRing = outerRings[x][0];\n\n if (arrayIntersectsArray(outerRing, hole)) {\n // the hole is contained push it into our polygon\n outerRings[x].push(hole);\n intersects = true;\n break;\n }\n }\n\n if (!intersects) {\n outerRings.push([hole.reverse()]);\n }\n }\n\n if (outerRings.length === 1) {\n return {\n type: 'Polygon',\n coordinates: outerRings[0]\n };\n } else {\n return {\n type: 'MultiPolygon',\n coordinates: outerRings\n };\n }\n};\n\nvar getId = function getId(attributes, idAttribute) {\n var keys = idAttribute ? [idAttribute, 'OBJECTID', 'FID'] : ['OBJECTID', 'FID'];\n\n for (var i = 0; i < keys.length; i++) {\n var key = keys[i];\n\n if (key in attributes && (typeof attributes[key] === 'string' || typeof attributes[key] === 'number')) {\n return attributes[key];\n }\n }\n\n throw Error('No valid id attribute found');\n};\n\nvar arcgisToGeoJSON = function arcgisToGeoJSON(arcgis, idAttribute) {\n var geojson = {};\n\n if (arcgis.features) {\n geojson.type = 'FeatureCollection';\n geojson.features = [];\n\n for (var i = 0; i < arcgis.features.length; i++) {\n geojson.features.push(arcgisToGeoJSON(arcgis.features[i], idAttribute));\n }\n }\n\n if (typeof arcgis.x === 'number' && typeof arcgis.y === 'number') {\n geojson.type = 'Point';\n geojson.coordinates = [arcgis.x, arcgis.y];\n\n if (typeof arcgis.z === 'number') {\n geojson.coordinates.push(arcgis.z);\n }\n }\n\n if (arcgis.points) {\n geojson.type = 'MultiPoint';\n geojson.coordinates = arcgis.points.slice(0);\n }\n\n if (arcgis.paths) {\n if (arcgis.paths.length === 1) {\n geojson.type = 'LineString';\n geojson.coordinates = arcgis.paths[0].slice(0);\n } else {\n geojson.type = 'MultiLineString';\n geojson.coordinates = arcgis.paths.slice(0);\n }\n }\n\n if (arcgis.rings) {\n geojson = convertRingsToGeoJSON(arcgis.rings.slice(0));\n }\n\n if (typeof arcgis.xmin === 'number' && typeof arcgis.ymin === 'number' && typeof arcgis.xmax === 'number' && typeof arcgis.ymax === 'number') {\n geojson.type = 'Polygon';\n geojson.coordinates = [[[arcgis.xmax, arcgis.ymax], [arcgis.xmin, arcgis.ymax], [arcgis.xmin, arcgis.ymin], [arcgis.xmax, arcgis.ymin], [arcgis.xmax, arcgis.ymax]]];\n }\n\n if (arcgis.geometry || arcgis.attributes) {\n geojson.type = 'Feature';\n geojson.geometry = arcgis.geometry ? arcgisToGeoJSON(arcgis.geometry) : null;\n geojson.properties = arcgis.attributes ? shallowClone(arcgis.attributes) : null;\n\n if (arcgis.attributes) {\n try {\n geojson.id = getId(arcgis.attributes, idAttribute);\n } catch (err) {// don't set an id\n }\n }\n } // if no valid geometry was encountered\n\n\n if (JSON.stringify(geojson.geometry) === JSON.stringify({})) {\n geojson.geometry = null;\n }\n\n if (arcgis.spatialReference && arcgis.spatialReference.wkid && arcgis.spatialReference.wkid !== 4326) {\n console.warn('Object converted in non-standard crs - ' + JSON.stringify(arcgis.spatialReference));\n }\n\n return geojson;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n// outer rings are clockwise, holes are counterclockwise\n// used for converting GeoJSON Polygons to ArcGIS Polygons\n\nvar orientRings = function orientRings(poly) {\n var output = [];\n var polygon = poly.slice(0);\n var outerRing = closeRing(polygon.shift().slice(0));\n\n if (outerRing.length >= 4) {\n if (!ringIsClockwise(outerRing)) {\n outerRing.reverse();\n }\n\n output.push(outerRing);\n\n for (var i = 0; i < polygon.length; i++) {\n var hole = closeRing(polygon[i].slice(0));\n\n if (hole.length >= 4) {\n if (ringIsClockwise(hole)) {\n hole.reverse();\n }\n\n output.push(hole);\n }\n }\n }\n\n return output;\n}; // This function flattens holes in multipolygons to one array of polygons\n// used for converting GeoJSON Polygons to ArcGIS Polygons\n\n\nvar flattenMultiPolygonRings = function flattenMultiPolygonRings(rings) {\n var output = [];\n\n for (var i = 0; i < rings.length; i++) {\n var polygon = orientRings(rings[i]);\n\n for (var x = polygon.length - 1; x >= 0; x--) {\n var ring = polygon[x].slice(0);\n output.push(ring);\n }\n }\n\n return output;\n};\n\nvar geojsonToArcGIS = function geojsonToArcGIS(geojson, idAttribute) {\n idAttribute = idAttribute || 'OBJECTID';\n var spatialReference = {\n wkid: 4326\n };\n var result = {};\n var i;\n\n switch (geojson.type) {\n case 'Point':\n result.x = geojson.coordinates[0];\n result.y = geojson.coordinates[1];\n\n if (geojson.coordinates[2]) {\n result.z = geojson.coordinates[2];\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'MultiPoint':\n result.points = geojson.coordinates.slice(0);\n\n if (geojson.coordinates[0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'LineString':\n result.paths = [geojson.coordinates.slice(0)];\n\n if (geojson.coordinates[0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'MultiLineString':\n result.paths = geojson.coordinates.slice(0);\n\n if (geojson.coordinates[0][0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'Polygon':\n result.rings = orientRings(geojson.coordinates.slice(0));\n\n if (geojson.coordinates[0][0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'MultiPolygon':\n result.rings = flattenMultiPolygonRings(geojson.coordinates.slice(0));\n\n if (geojson.coordinates[0][0][0][2]) {\n result.hasZ = true;\n }\n\n result.spatialReference = spatialReference;\n break;\n\n case 'Feature':\n if (geojson.geometry) {\n result.geometry = geojsonToArcGIS(geojson.geometry, idAttribute);\n }\n\n result.attributes = geojson.properties ? shallowClone(geojson.properties) : {};\n\n if (geojson.id) {\n result.attributes[idAttribute] = geojson.id;\n }\n\n break;\n\n case 'FeatureCollection':\n result = [];\n\n for (i = 0; i < geojson.features.length; i++) {\n result.push(geojsonToArcGIS(geojson.features[i], idAttribute));\n }\n\n break;\n\n case 'GeometryCollection':\n result = [];\n\n for (i = 0; i < geojson.geometries.length; i++) {\n result.push(geojsonToArcGIS(geojson.geometries[i], idAttribute));\n }\n\n break;\n }\n\n return result;\n};\n\n/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport { arcgisToGeoJSON, geojsonToArcGIS };\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n ILocation,\n IPoint,\n IFeature,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_ROUTING_URL,\n IEndpointOptions,\n decompressGeometry,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\ninterface IFeatureWithCompressedGeometry extends IFeature {\n compressedGeometry?: string;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: {};\n}\n\nexport interface ISolveRouteOptions extends IEndpointOptions {\n /**\n * Specify two or more locations between which the route is to be found.\n */\n stops:\n | Array<IPoint | ILocation | [number, number] | [number, number, number]>\n | IFeatureSet;\n}\n\nexport interface ISolveRouteResponse {\n messages: string[];\n checksum: string;\n routes: IFeatureSetWithGeoJson;\n directions?: Array<{\n routeId: number;\n routeName: string;\n summary: object;\n features: IFeature[];\n }>;\n}\n\nfunction isLocationArray(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is [number, number] | [number, number, number] {\n return (\n (coords as [number, number]).length === 2 ||\n (coords as [number, number, number]).length === 3\n );\n}\n\nfunction isLocation(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is ILocation {\n return (\n (coords as ILocation).latitude !== undefined ||\n (coords as ILocation).lat !== undefined\n );\n}\n\n/**\n * 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.\n *\n * ```js\n * import { solveRoute } from '@esri/arcgis-rest-routing';\n *\n * solveRoute({\n * stops: [\n * [-117.195677, 34.056383],\n * [-117.918976, 33.812092],\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with routes and directions for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/route-synchronous-service.htm\n */\nexport function solveRoute(\n requestOptions: ISolveRouteOptions\n): Promise<ISolveRouteResponse> {\n const options: ISolveRouteOptions = {\n endpoint: requestOptions.endpoint || ARCGIS_ONLINE_ROUTING_URL,\n params: {},\n ...requestOptions\n };\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n options.endpoint === ARCGIS_ONLINE_ROUTING_URL\n ) {\n return Promise.reject(\n \"Routing using the ArcGIS service requires authentication\"\n );\n }\n\n if (isFeatureSet(requestOptions.stops)) {\n options.params.stops = requestOptions.stops;\n } else {\n const stops: string[] = requestOptions.stops.map((coords) => {\n if (isLocationArray(coords)) {\n return coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n return (\n coords.long + \",\" + coords.lat + (coords.z ? \",\" + coords.z : \"\")\n );\n } else {\n return (\n coords.longitude +\n \",\" +\n coords.latitude +\n (coords.z ? \",\" + coords.z : \"\")\n );\n }\n } else {\n return coords.x + \",\" + coords.y + (coords.z ? \",\" + coords.z : \"\");\n }\n });\n\n options.params.stops = stops.join(\";\");\n }\n\n return request(`${cleanUrl(options.endpoint)}/solve`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): ISolveRouteResponse {\n if (res.directions && res.directions.length > 0) {\n res.directions = res.directions.map(\n (direction: {\n features: IFeatureWithCompressedGeometry[];\n routeId: number;\n routeName: string;\n summary: {};\n }) => {\n direction.features = direction.features.map(\n (feature: IFeatureWithCompressedGeometry) => {\n feature.geometry = decompressGeometry(feature.compressedGeometry);\n return feature;\n }\n );\n return direction;\n }\n );\n }\n\n // add \"geoJson\" property to \"routes\"\n if (res.routes.spatialReference.wkid === 4326) {\n const features = res.routes.features.map((feature: any) => {\n return {\n type: \"Feature\",\n geometry: arcgisToGeoJSON(feature.geometry),\n properties: Object.assign({}, feature.attributes)\n };\n });\n\n res.routes.geoJson = {\n type: \"FeatureCollection\",\n features\n };\n }\n return res;\n}\n\nexport default {\n solveRoute\n};\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n ILocation,\n IPoint,\n IFeature,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_CLOSEST_FACILITY_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet,\n isJsonWithURL\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IClosestFacilityOptions extends IEndpointOptions {\n /**\n * Specify one or more locations from which the service searches for the nearby locations. These locations are referred to as incidents.\n */\n incidents:\n | Array<IPoint | ILocation | [number, number]>\n | IFeatureSet\n | { url: string };\n\n /**\n * Specify one or more locations that are searched for when finding the closest location.\n */\n facilities:\n | Array<IPoint | ILocation | [number, number]>\n | IFeatureSet\n | { url: string };\n /**\n * Specify if the service should return routes.\n */\n returnCFRoutes: boolean;\n travelDirection?: \"incidentsToFacilities\" | \"facilitiesToIncidents\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n returnDirections?: boolean;\n directionsOutputType?:\n | \"esriDOTComplete\"\n | \"esriDOTCompleteNoEvents\"\n | \"esriDOTInstructionsOnly\"\n | \"esriDOTStandard\"\n | \"esriDOTSummaryOnly\"\n | \"esriDOTFeatureSets\";\n directionsLengthUnits?:\n | \"esriNAUCentimeters\"\n | \"esriNAUDecimalDegrees\"\n | \"esriNAUDecimeters\"\n | \"esriNAUFeet\"\n | \"esriNAUInches\"\n | \"esriNAUKilometers\"\n | \"esriNAUMeters\"\n | \"esriNAUMiles\"\n | \"esriNAUMillimeters\"\n | \"esriNAUNauticalMiles\"\n | \"esriNAUPoints\"\n | \"esriNAUYards\";\n outputLines?: boolean;\n returnFacilities?: boolean;\n returnIncidents?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n preserveObjectID?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IClosestFacilityResponse {\n messages: string[];\n routes?: IFeatureSetWithGeoJson;\n directions?: Array<{\n routeId: number;\n routeName: string;\n summary: object;\n features: IFeature[];\n }>;\n incidents?: IFeatureSet;\n facilities?: IFeatureSet;\n barriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n polylineBarriers?: IFeatureSet;\n}\n\nfunction getTravelDirection(\n key: \"incidentsToFacilities\" | \"facilitiesToIncidents\"\n): \"esriNATravelDirectionFromFacility\" | \"esriNATravelDirectionToFacility\" {\n if (key === \"incidentsToFacilities\") {\n return \"esriNATravelDirectionFromFacility\";\n } else {\n return \"esriNATravelDirectionToFacility\";\n }\n}\n\n/**\n * 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.\n *\n * ```js\n * import { closestFacility } from '@esri/arcgis-rest-routing';\n *\n * closestFacility({\n * incidents: [\n * [-90.404302, 38.600621],\n * [-90.364293, 38.620427],\n * ],\n * facilities: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with routes and directions for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm\n * @inline IClosestFacilityOptions\n */\nexport function closestFacility(\n requestOptions: IClosestFacilityOptions\n): Promise<IClosestFacilityResponse> {\n const endpoint =\n requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;\n\n requestOptions.params = {\n returnFacilities: true,\n returnDirections: true,\n returnIncidents: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n preserveObjectID: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IClosestFacilityOptions>(requestOptions, [\n \"returnCFRoutes\",\n // \"travelDirection\",\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"returnDirections\",\n \"directionsOutputType\",\n \"directionsLengthUnits\",\n \"outputLines\",\n \"returnFacilities\",\n \"returnIncidents\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\",\n \"preserveObjectID\"\n ]);\n\n // Set travelDirection\n if (requestOptions.travelDirection) {\n options.params.travelDirection = getTravelDirection(\n requestOptions.travelDirection\n );\n }\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL\n ) {\n return Promise.reject(\n \"Finding the closest facility using the ArcGIS service requires authentication\"\n );\n }\n\n if (\n isFeatureSet(requestOptions.incidents) ||\n isJsonWithURL(requestOptions.incidents)\n ) {\n options.params.incidents = requestOptions.incidents;\n } else {\n options.params.incidents = normalizeLocationsList(\n requestOptions.incidents\n ).join(\";\");\n }\n\n if (\n isFeatureSet(requestOptions.facilities) ||\n isJsonWithURL(requestOptions.facilities)\n ) {\n options.params.facilities = requestOptions.facilities;\n } else {\n options.params.facilities = normalizeLocationsList(\n requestOptions.facilities\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveClosestFacility`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): IClosestFacilityResponse {\n // add \"geoJson\" property to \"routes\"\n if (res.routes.spatialReference.wkid === 4326) {\n res.routes.geoJson = arcgisToGeoJSON(res.routes);\n }\n return res;\n}\n\nexport default {\n closestFacility\n};\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n ILocation,\n IPoint,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_SERVICE_AREA_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IServiceAreaOptions extends IEndpointOptions {\n /**\n * Specify one or more locations around which service areas are generated.\n */\n facilities: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify if the service should return routes.\n */\n travelDirection?: \"incidentsToFacilities\" | \"facilitiesToIncidents\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n outputLines?: boolean;\n returnFacilities?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n preserveObjectID?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IServiceAreaResponse {\n messages: string[];\n saPolygons?: IFeatureSetWithGeoJson;\n incidents?: IFeatureSet;\n facilities?: IFeatureSet;\n barriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n polylineBarriers?: IFeatureSet;\n}\n\nfunction getTravelDirection(\n key: \"incidentsToFacilities\" | \"facilitiesToIncidents\"\n): \"esriNATravelDirectionFromFacility\" | \"esriNATravelDirectionToFacility\" {\n if (key === \"incidentsToFacilities\") {\n return \"esriNATravelDirectionFromFacility\";\n } else {\n return \"esriNATravelDirectionToFacility\";\n }\n}\n\n/**\n * 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.\n *\n * ```js\n * import { serviceArea } from '@esri/arcgis-rest-routing';\n *\n * serviceArea({\n * facilities: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with service area polygons for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/service-area-synchronous-service.htm\n */\nexport function serviceArea(\n requestOptions: IServiceAreaOptions\n): Promise<IServiceAreaResponse> {\n const endpoint = requestOptions.endpoint || ARCGIS_ONLINE_SERVICE_AREA_URL;\n\n requestOptions.params = {\n returnFacilities: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n preserveObjectID: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IServiceAreaOptions>(requestOptions, [\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"outputLines\",\n \"returnFacilities\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\",\n \"preserveObjectID\"\n ]);\n\n // Set travelDirection\n if (requestOptions.travelDirection) {\n options.params.travelDirection = getTravelDirection(\n requestOptions.travelDirection\n );\n }\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_SERVICE_AREA_URL\n ) {\n return Promise.reject(\n \"Finding service areas using the ArcGIS service requires authentication\"\n );\n }\n\n if (isFeatureSet(requestOptions.facilities)) {\n options.params.facilities = requestOptions.facilities;\n } else {\n options.params.facilities = normalizeLocationsList(\n requestOptions.facilities\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveServiceArea`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): IServiceAreaResponse {\n // remove \"fieldAliases\" because it does not do anything.\n delete res.saPolygons.fieldAliases;\n\n // add \"geoJson\" property to \"saPolygons\"\n if (res.saPolygons.spatialReference.wkid === 4326) {\n res.saPolygons.geoJson = arcgisToGeoJSON(res.saPolygons);\n }\n return res;\n}\n\nexport default {\n serviceArea\n};\n","/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n IRequestOptions,\n ILocation,\n IPoint,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IOriginDestinationMatrixOptions extends IEndpointOptions {\n /**\n * Specify the starting points from which to travel to the destinations.\n */\n origins: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify the ending point locations to travel to from the origins.\n */\n destinations: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n /**\n * Specify the type of output returned by the service. Defaults to \"esriNAODOutputSparseMatrix\".\n */\n outputType?:\n | \"esriNAODOutputSparseMatrix\"\n | \"esriNAODOutputStraightLines\"\n | \"esriNAODOutputNoLines\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n returnOrigins?: boolean;\n returnDestinations?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IOriginDestinationMatrixResponse {\n messages: [{ type: number; description: string }];\n /**\n * Only present if outputType is \"esriNAODOutputSparseMatrix\". Full description is available at https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm#ESRI_SECTION2_114F8364507C4B56B780DFAD505270FB.\n */\n odCostMatrix?: any;\n /**\n * Only present if outputType is \"esriNAODOutputStraightLines\" or \"esriNAODOutputNoLines\". Includes the geometry for the straight line connecting each origin-destination pair when the outputType is \"esriNAODOutputStraightLines\".\n */\n odLines?: IFeatureSetWithGeoJson;\n origins?: IFeatureSetWithGeoJson;\n destinations?: IFeatureSetWithGeoJson;\n barriers?: IFeatureSetWithGeoJson;\n polylineBarriers?: IFeatureSetWithGeoJson;\n polygonBarriers?: IFeatureSetWithGeoJson;\n}\n\n/**\n * 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.\n *\n * ```js\n * import { originDestinationMatrix } from '@esri/arcgis-rest-routing';\n *\n * originDestinationMatrix({\n * origins: [\n * [-90.404302, 38.600621],\n * [-90.364293, 38.620427],\n * ],\n * destinations: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => { ... }\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @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.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-synchronous-service.htm\n */\nexport function originDestinationMatrix(\n requestOptions: IOriginDestinationMatrixOptions\n): Promise<IOriginDestinationMatrixResponse> {\n const endpoint =\n requestOptions.endpoint || ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL;\n\n requestOptions.params = {\n outputType: \"esriNAODOutputSparseMatrix\",\n returnOrigins: true,\n returnDestinations: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IOriginDestinationMatrixOptions>(\n requestOptions,\n [\n \"outputType\",\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"returnOrigins\",\n \"returnDestinations\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\"\n ]\n );\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL\n ) {\n return Promise.reject(\n \"Calculating the origin-destination cost matrix using the ArcGIS service requires authentication\"\n );\n }\n\n // use a formatting helper for input params of this type: Array<IPoint | ILocation | [number, number]>\n if (isFeatureSet(requestOptions.origins)) {\n options.params.origins = requestOptions.origins;\n } else {\n options.params.origins = normalizeLocationsList(\n requestOptions.origins\n ).join(\";\");\n }\n\n if (isFeatureSet(requestOptions.destinations)) {\n options.params.destinations = requestOptions.destinations;\n } else {\n options.params.destinations = normalizeLocationsList(\n requestOptions.destinations\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveODCostMatrix`, options).then(\n function (res) {\n return cleanResponse(res, options);\n }\n );\n}\n\nfunction cleanResponse(\n res: any,\n options: IRequestOptions\n): IOriginDestinationMatrixResponse {\n // add \"geoJson\" property to each response property that is an arcgis featureSet\n\n // res.odLines only exists and only includes geometry in this condition (out of 3 possible options.params.outputType conditions)\n if (\n options.params.outputType === \"esriNAODOutputStraightLines\" &&\n res.odLines &&\n res.odLines.spatialReference.wkid === 4326\n ) {\n res.odLines.geoJson = arcgisToGeoJSON(res.odLines);\n }\n\n if (res.origins && res.origins.spatialReference.wkid === 4326) {\n res.origins.geoJson = arcgisToGeoJSON(res.origins);\n }\n\n if (res.destinations && res.destinations.spatialReference.wkid === 4326) {\n res.destinations.geoJson = arcgisToGeoJSON(res.destinations);\n }\n\n if (res.barriers && res.barriers.spatialReference.wkid === 4326) {\n res.barriers.geoJson = arcgisToGeoJSON(res.barriers);\n }\n\n if (\n res.polygonBarriers &&\n res.polygonBarriers.spatialReference.wkid === 4326\n ) {\n res.polygonBarriers.geoJson = arcgisToGeoJSON(res.polygonBarriers);\n }\n\n if (\n res.polylineBarriers &&\n res.polylineBarriers.spatialReference.wkid === 4326\n ) {\n res.polylineBarriers.geoJson = arcgisToGeoJSON(res.polylineBarriers);\n }\n\n return res;\n}\n\nexport default {\n originDestinationMatrix\n};\n"],"names":["ARCGIS_ONLINE_ROUTING_URL","ARCGIS_ONLINE_CLOSEST_FACILITY_URL","ARCGIS_ONLINE_SERVICE_AREA_URL","ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL","normalizeLocationsList","locations","map","coords","length","isLocationArray","join","undefined","latitude","lat","isLocation","long","longitude","x","y","decompressGeometry","str","xDiffPrev","yDiffPrev","points","strings","match","coefficient","parseInt","j","push","paths","isFeatureSet","arg","Object","prototype","hasOwnProperty","call","isJsonWithURL","edgeIntersectsEdge","a1","a2","b1","b2","uaT","ubT","uB","ua","ub","arrayIntersectsArray","a","b","i","ringIsClockwise","ringToTest","pt2","total","rLength","pt1","coordinatesContainCoordinates","outer","inner","intersects","contains","coordinates","point","l","coordinatesContainPoint","arcgisToGeoJSON","arcgis","idAttribute","geojson","features","type","z","slice","rings","outerRing","hole","outerRings","holes","r","ring","pointsEqual","polygon","reverse","uncontainedHoles","pop","contained","convertRingsToGeoJSON","xmin","ymin","xmax","ymax","geometry","attributes","properties","obj","target","shallowClone","id","keys","key","Error","getId","err","JSON","stringify","spatialReference","wkid","console","warn","cleanResponse","res","directions","direction","feature","compressedGeometry","routes","assign","geoJson","saPolygons","fieldAliases","requestOptions","endpoint","params","returnFacilities","returnDirections","returnIncidents","returnBarriers","returnPolylineBarriers","returnPolygonBarriers","preserveObjectID","options","appendCustomParams","travelDirection","authentication","incidents","facilities","barriers","request","cleanUrl","then","Promise","reject","outputType","returnOrigins","returnDestinations","origins","destinations","odLines","polygonBarriers","polylineBarriers","stops"],"mappings":";;;;;sVAaaA,EACX,iFACWC,EACX,qGACWC,EACX,8FACWC,EACX,sIA4BcC,EACdC,GAEA,OAAOA,EAAUC,KAAKC,GArBxB,SACEA,GAEA,OAC0C,IAAvCA,EAA4BC,QACmB,IAA/CD,EAAoCC,OAiBjCC,CAAgBF,GACXA,EAAOG,OAdpB,SACEH,GAEA,YACqCI,IAAlCJ,EAAqBK,eACQD,IAA7BJ,EAAqBM,IAUXC,CAAWP,GAChBA,EAAOM,IACFN,EAAOQ,KAAO,IAAMR,EAAOM,IAE3BN,EAAOS,UAAY,IAAMT,EAAOK,SAGlCL,EAAOU,EAAI,IAAMV,EAAOW,aAKrBC,EAAmBC,GACjC,IAAIC,EAAY,EACZC,EAAY,EAChB,MAAMC,EAAS,GACf,IAAIN,EACAC,EAGJ,MAAMM,EAAUJ,EAAIK,MAAM,mBAGpBC,EAAcC,SAASH,EAAQ,GAAI,IAEzC,IAAK,IAAII,EAAI,EAAGA,EAAIJ,EAAQhB,OAAQoB,GAAK,EAGvCX,EAAIU,SAASH,EAAQI,GAAI,IAAMP,EAC/BA,EAAYJ,EAIZC,EAAIS,SAASH,EAAQI,EAAI,GAAI,IAAMN,EACnCA,EAAYJ,EAEZK,EAAOM,KAAK,CAACZ,EAAIS,EAAaR,EAAIQ,IAGpC,MAAO,CACLI,MAAO,CAACP,aAOIQ,EAAaC,GAC3B,OAAOC,OAAOC,UAAUC,eAAeC,KAAKJ,EAAK,qBAMnCK,EAAcL,GAC5B,MAAO,QAASA;;;;;ICrGlB,IAAIM,EAAqB,SAA4BC,EAAIC,EAAIC,EAAIC,GAC/D,IAAIC,GAAOD,EAAG,GAAKD,EAAG,KAAOF,EAAG,GAAKE,EAAG,KAAOC,EAAG,GAAKD,EAAG,KAAOF,EAAG,GAAKE,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EAAQR,OAAOc,SAAWhB,EAAegB,SAKzCN,EAAQR,OAAOc,SAAWtI,EACxBsH,EAAegB,UACfhI,KAAK,MAIJiI,UAAQ,GAAGC,WAASjB,sBAA8BS,GAASS,KAChE9B,IA5BO+B,QAAQC,OACb,iGFpCJrB,GAEA,MAAMU,iBACJT,SAAUD,EAAeC,UAAY3H,EACrC4H,OAAQ,IACLF,GAIL,IACGA,EAAea,gBAChBH,EAAQT,WAAa3H,EAErB,OAAO8I,QAAQC,OACb,4DAIJ,GAAIhH,EAAa2F,EAAe8B,OAC9BpB,EAAQR,OAAO4B,MAAQ9B,EAAe8B,UACjC,CACL,MAAMA,EAAkB9B,EAAe8B,MAAMlJ,KAAKC,GA5DtD,SACEA,GAEA,OAC0C,IAAvCA,EAA4BC,QACmB,IAA/CD,EAAoCC,OAwD/BC,CAAgBF,GACXA,EAAOG,OArDtB,SACEH,GAEA,YACqCI,IAAlCJ,EAAqBK,eACQD,IAA7BJ,EAAqBM,IAiDTC,CAAWP,GAChBA,EAAOM,IAEPN,EAAOQ,KAAO,IAAMR,EAAOM,KAAON,EAAOkE,EAAI,IAAMlE,EAAOkE,EAAI,IAI9DlE,EAAOS,UACP,IACAT,EAAOK,UACNL,EAAOkE,EAAI,IAAMlE,EAAOkE,EAAI,IAI1BlE,EAAOU,EAAI,IAAMV,EAAOW,GAAKX,EAAOkE,EAAI,IAAMlE,EAAOkE,EAAI,MAIpE2D,EAAQR,OAAO4B,MAAQA,EAAM9I,KAAK,KAGpC,OAAOiI,UAAQ,GAAGC,WAASR,EAAQT,kBAAmBS,GAASS,KAC7D9B"}
|
|
@@ -69,13 +69,15 @@ function closestFacility(requestOptions) {
|
|
|
69
69
|
endpoint === helpers_js_1.ARCGIS_ONLINE_CLOSEST_FACILITY_URL) {
|
|
70
70
|
return Promise.reject("Finding the closest facility using the ArcGIS service requires authentication");
|
|
71
71
|
}
|
|
72
|
-
if ((0, helpers_js_1.isFeatureSet)(requestOptions.incidents)
|
|
72
|
+
if ((0, helpers_js_1.isFeatureSet)(requestOptions.incidents) ||
|
|
73
|
+
(0, helpers_js_1.isJsonWithURL)(requestOptions.incidents)) {
|
|
73
74
|
options.params.incidents = requestOptions.incidents;
|
|
74
75
|
}
|
|
75
76
|
else {
|
|
76
77
|
options.params.incidents = (0, helpers_js_1.normalizeLocationsList)(requestOptions.incidents).join(";");
|
|
77
78
|
}
|
|
78
|
-
if ((0, helpers_js_1.isFeatureSet)(requestOptions.facilities)
|
|
79
|
+
if ((0, helpers_js_1.isFeatureSet)(requestOptions.facilities) ||
|
|
80
|
+
(0, helpers_js_1.isJsonWithURL)(requestOptions.facilities)) {
|
|
79
81
|
options.params.facilities = requestOptions.facilities;
|
|
80
82
|
}
|
|
81
83
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closestFacility.js","sourceRoot":"","sources":["../../src/closestFacility.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAQmC;AAEnC,
|
|
1
|
+
{"version":3,"file":"closestFacility.js","sourceRoot":"","sources":["../../src/closestFacility.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAQmC;AAEnC,6CAMsB;AAEtB,gDAAsD;AA4EtD,SAAS,kBAAkB,CACzB,GAAsD;IAEtD,IAAI,GAAG,KAAK,uBAAuB,EAAE;QACnC,OAAO,mCAAmC,CAAC;KAC5C;SAAM;QACL,OAAO,iCAAiC,CAAC;KAC1C;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,eAAe,CAC7B,cAAuC;IAEvC,MAAM,QAAQ,GACZ,cAAc,CAAC,QAAQ,IAAI,+CAAkC,CAAC;IAEhE,cAAc,CAAC,MAAM,mBACnB,gBAAgB,EAAE,IAAI,EACtB,gBAAgB,EAAE,IAAI,EACtB,eAAe,EAAE,IAAI,EACrB,cAAc,EAAE,IAAI,EACpB,sBAAsB,EAAE,IAAI,EAC5B,qBAAqB,EAAE,IAAI,EAC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AAC,GAAG,CAAC,CAAC;KACb;IAED,gEAAgE;IAChE,IAAI,cAAc,CAAC,QAAQ,EAAE;QAC3B,IAAI,IAAA,yBAAY,EAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC;SACnD;aAAM;YACL,2DAA2D;YAC3D,0CAA0C;YAC1C,uFAAuF;YACvF,OAAO,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAA,mCAAsB,EAC9C,cAAc,CAAC,QAAQ,CACxB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACb;KACF;IAED,OAAO,IAAA,6BAAO,EAAC,GAAG,IAAA,8BAAQ,EAAC,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC,IAAI,CACxE,aAAa,CACd,CAAC;AACJ,CAAC;AA3FD,0CA2FC;AAED,SAAS,aAAa,CAAC,GAAQ;IAC7B,qCAAqC;IACrC,IAAI,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,KAAK,IAAI,EAAE;QAC7C,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,IAAA,wBAAe,EAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAClD;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,kBAAe;IACb,eAAe;CAChB,CAAC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n ILocation,\n IPoint,\n IFeature,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_CLOSEST_FACILITY_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet,\n isJsonWithURL\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IClosestFacilityOptions extends IEndpointOptions {\n /**\n * Specify one or more locations from which the service searches for the nearby locations. These locations are referred to as incidents.\n */\n incidents:\n | Array<IPoint | ILocation | [number, number]>\n | IFeatureSet\n | { url: string };\n\n /**\n * Specify one or more locations that are searched for when finding the closest location.\n */\n facilities:\n | Array<IPoint | ILocation | [number, number]>\n | IFeatureSet\n | { url: string };\n /**\n * Specify if the service should return routes.\n */\n returnCFRoutes: boolean;\n travelDirection?: \"incidentsToFacilities\" | \"facilitiesToIncidents\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n returnDirections?: boolean;\n directionsOutputType?:\n | \"esriDOTComplete\"\n | \"esriDOTCompleteNoEvents\"\n | \"esriDOTInstructionsOnly\"\n | \"esriDOTStandard\"\n | \"esriDOTSummaryOnly\"\n | \"esriDOTFeatureSets\";\n directionsLengthUnits?:\n | \"esriNAUCentimeters\"\n | \"esriNAUDecimalDegrees\"\n | \"esriNAUDecimeters\"\n | \"esriNAUFeet\"\n | \"esriNAUInches\"\n | \"esriNAUKilometers\"\n | \"esriNAUMeters\"\n | \"esriNAUMiles\"\n | \"esriNAUMillimeters\"\n | \"esriNAUNauticalMiles\"\n | \"esriNAUPoints\"\n | \"esriNAUYards\";\n outputLines?: boolean;\n returnFacilities?: boolean;\n returnIncidents?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n preserveObjectID?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IClosestFacilityResponse {\n messages: string[];\n routes?: IFeatureSetWithGeoJson;\n directions?: Array<{\n routeId: number;\n routeName: string;\n summary: object;\n features: IFeature[];\n }>;\n incidents?: IFeatureSet;\n facilities?: IFeatureSet;\n barriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n polylineBarriers?: IFeatureSet;\n}\n\nfunction getTravelDirection(\n key: \"incidentsToFacilities\" | \"facilitiesToIncidents\"\n): \"esriNATravelDirectionFromFacility\" | \"esriNATravelDirectionToFacility\" {\n if (key === \"incidentsToFacilities\") {\n return \"esriNATravelDirectionFromFacility\";\n } else {\n return \"esriNATravelDirectionToFacility\";\n }\n}\n\n/**\n * 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.\n *\n * ```js\n * import { closestFacility } from '@esri/arcgis-rest-routing';\n *\n * closestFacility({\n * incidents: [\n * [-90.404302, 38.600621],\n * [-90.364293, 38.620427],\n * ],\n * facilities: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with routes and directions for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm\n * @inline IClosestFacilityOptions\n */\nexport function closestFacility(\n requestOptions: IClosestFacilityOptions\n): Promise<IClosestFacilityResponse> {\n const endpoint =\n requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;\n\n requestOptions.params = {\n returnFacilities: true,\n returnDirections: true,\n returnIncidents: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n preserveObjectID: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IClosestFacilityOptions>(requestOptions, [\n \"returnCFRoutes\",\n // \"travelDirection\",\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"returnDirections\",\n \"directionsOutputType\",\n \"directionsLengthUnits\",\n \"outputLines\",\n \"returnFacilities\",\n \"returnIncidents\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\",\n \"preserveObjectID\"\n ]);\n\n // Set travelDirection\n if (requestOptions.travelDirection) {\n options.params.travelDirection = getTravelDirection(\n requestOptions.travelDirection\n );\n }\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL\n ) {\n return Promise.reject(\n \"Finding the closest facility using the ArcGIS service requires authentication\"\n );\n }\n\n if (\n isFeatureSet(requestOptions.incidents) ||\n isJsonWithURL(requestOptions.incidents)\n ) {\n options.params.incidents = requestOptions.incidents;\n } else {\n options.params.incidents = normalizeLocationsList(\n requestOptions.incidents\n ).join(\";\");\n }\n\n if (\n isFeatureSet(requestOptions.facilities) ||\n isJsonWithURL(requestOptions.facilities)\n ) {\n options.params.facilities = requestOptions.facilities;\n } else {\n options.params.facilities = normalizeLocationsList(\n requestOptions.facilities\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveClosestFacility`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): IClosestFacilityResponse {\n // add \"geoJson\" property to \"routes\"\n if (res.routes.spatialReference.wkid === 4326) {\n res.routes.geoJson = arcgisToGeoJSON(res.routes);\n }\n return res;\n}\n\nexport default {\n closestFacility\n};\n"]}
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
3
3
|
* Apache-2.0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.isFeatureSet = exports.decompressGeometry = exports.normalizeLocationsList = exports.ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = exports.ARCGIS_ONLINE_SERVICE_AREA_URL = exports.ARCGIS_ONLINE_CLOSEST_FACILITY_URL = exports.ARCGIS_ONLINE_ROUTING_URL = void 0;
|
|
5
|
+
exports.isJsonWithURL = exports.isFeatureSet = exports.decompressGeometry = exports.normalizeLocationsList = exports.ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL = exports.ARCGIS_ONLINE_SERVICE_AREA_URL = exports.ARCGIS_ONLINE_CLOSEST_FACILITY_URL = exports.ARCGIS_ONLINE_ROUTING_URL = void 0;
|
|
6
6
|
// https always
|
|
7
7
|
exports.ARCGIS_ONLINE_ROUTING_URL = "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
|
|
8
8
|
exports.ARCGIS_ONLINE_CLOSEST_FACILITY_URL = "https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World";
|
|
@@ -68,4 +68,11 @@ function isFeatureSet(arg) {
|
|
|
68
68
|
return Object.prototype.hasOwnProperty.call(arg, "features");
|
|
69
69
|
}
|
|
70
70
|
exports.isFeatureSet = isFeatureSet;
|
|
71
|
+
/**
|
|
72
|
+
* User Defined Type Guard that verifies this is a JSON with `url` property
|
|
73
|
+
*/
|
|
74
|
+
function isJsonWithURL(arg) {
|
|
75
|
+
return "url" in arg;
|
|
76
|
+
}
|
|
77
|
+
exports.isJsonWithURL = isJsonWithURL;
|
|
71
78
|
//# sourceMappingURL=helpers.js.map
|
package/dist/cjs/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAWhB,eAAe;AACF,QAAA,yBAAyB,GACpC,gFAAgF,CAAC;AACtE,QAAA,kCAAkC,GAC7C,oGAAoG,CAAC;AAC1F,QAAA,8BAA8B,GACzC,6FAA6F,CAAC;AACnF,QAAA,2CAA2C,GACtD,4HAA4H,CAAC;AAU/H,SAAS,eAAe,CACtB,MAAwE;IAExE,OAAO,CACJ,MAA2B,CAAC,MAAM,KAAK,CAAC;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,IAAI,CAAC,EAAE;QAC1C,kCAAkC;QAClC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QACzC,SAAS,GAAG,CAAC,CAAC;QAEd,oCAAoC;QACpC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QAC7C,SAAS,GAAG,CAAC,CAAC;QAEd,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,WAAW,CAAe,CAAC,CAAC;KAC/D;IAED,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,CAAC;KACH,CAAC;AACjB,CAAC;AA9BD,gDA8BC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,GAAQ;IACnC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AAC/D,CAAC;AAFD,oCAEC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAWhB,eAAe;AACF,QAAA,yBAAyB,GACpC,gFAAgF,CAAC;AACtE,QAAA,kCAAkC,GAC7C,oGAAoG,CAAC;AAC1F,QAAA,8BAA8B,GACzC,6FAA6F,CAAC;AACnF,QAAA,2CAA2C,GACtD,4HAA4H,CAAC;AAU/H,SAAS,eAAe,CACtB,MAAwE;IAExE,OAAO,CACJ,MAA2B,CAAC,MAAM,KAAK,CAAC;QACxC,MAAmC,CAAC,MAAM,KAAK,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,MAAwE;IAExE,OAAO,CACJ,MAAoB,CAAC,QAAQ,KAAK,SAAS;QAC3C,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AAS,GAAG,CAAC,CAAC;QAEd,oCAAoC;QACpC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QAC7C,SAAS,GAAG,CAAC,CAAC;QAEd,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,WAAW,CAAe,CAAC,CAAC;KAC/D;IAED,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,CAAC;KACH,CAAC;AACjB,CAAC;AA9BD,gDA8BC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,GAAQ;IACnC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AAC/D,CAAC;AAFD,oCAEC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,GAAQ;IACpC,OAAO,KAAK,IAAI,GAAG,CAAC;AACtB,CAAC;AAFD,sCAEC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IRequestOptions,\n ILocation,\n IPoint,\n IPolyline,\n Position2D,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\n// https always\nexport const ARCGIS_ONLINE_ROUTING_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World\";\nexport const ARCGIS_ONLINE_CLOSEST_FACILITY_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World\";\nexport const ARCGIS_ONLINE_SERVICE_AREA_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World\";\nexport const ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World\";\n\n// nice to have: verify custom endpoints contain 'NAServer' and end in a '/'\nexport interface IEndpointOptions extends IRequestOptions {\n /**\n * Any ArcGIS Routing service (example: https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/ ) to use for the routing service request.\n */\n endpoint?: string;\n}\n\nfunction isLocationArray(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is [number, number] | [number, number, number] {\n return (\n (coords as [number, number]).length === 2 ||\n (coords as [number, number, number]).length === 3\n );\n}\n\nfunction isLocation(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is ILocation {\n return (\n (coords as ILocation).latitude !== undefined ||\n (coords as ILocation).lat !== undefined\n );\n}\n\nexport function normalizeLocationsList(\n locations: Array<IPoint | ILocation | [number, number]>\n): string[] {\n return locations.map((coords) => {\n if (isLocationArray(coords)) {\n return coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n return coords.long + \",\" + coords.lat;\n } else {\n return coords.longitude + \",\" + coords.latitude;\n }\n } else {\n return coords.x + \",\" + coords.y;\n }\n });\n}\n\nexport function decompressGeometry(str: string) {\n let xDiffPrev = 0;\n let yDiffPrev = 0;\n const points = [];\n let x;\n let y;\n\n // Split the string into an array on the + and - characters\n const strings = str.match(/((\\+|-)[^+-]+)/g);\n\n // The first value is the coefficient in base 32\n const coefficient = parseInt(strings[0], 32);\n\n for (let j = 1; j < strings.length; j += 2) {\n // j is the offset for the x value\n // Convert the value from base 32 and add the previous x value\n x = parseInt(strings[j], 32) + xDiffPrev;\n xDiffPrev = x;\n\n // j+1 is the offset for the y value\n // Convert the value from base 32 and add the previous y value\n y = parseInt(strings[j + 1], 32) + yDiffPrev;\n yDiffPrev = y;\n\n points.push([x / coefficient, y / coefficient] as Position2D);\n }\n\n return {\n paths: [points]\n } as IPolyline;\n}\n\n/**\n * User Defined Type Guard that verifies this is a featureSet\n */\nexport function isFeatureSet(arg: any): arg is IFeatureSet {\n return Object.prototype.hasOwnProperty.call(arg, \"features\");\n}\n\n/**\n * User Defined Type Guard that verifies this is a JSON with `url` property\n */\nexport function isJsonWithURL(arg: any): arg is Object {\n return \"url\" in arg;\n}\n"]}
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,+DAAgC;AAChC,oEAAqC;AACrC,gEAAiC;AACjC,4EAA6C;AAC7C,4DAA6B","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,+DAAgC;AAChC,oEAAqC;AACrC,gEAAiC;AACjC,4EAA6C;AAC7C,4DAA6B","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./solveRoute.js\";\nexport * from \"./closestFacility.js\";\nexport * from \"./serviceArea.js\";\nexport * from \"./originDestinationMatrix.js\";\nexport * from \"./helpers.js\";\n\n// Types that are used in this package are re-exported for convenience and\n// to make the links work correctly in the documentation pages.\nexport type {\n IRequestOptions,\n ILocation,\n IPoint,\n IPolyline,\n Position2D,\n IFeatureSet,\n IFeature\n} from \"@esri/arcgis-rest-request\";\n"]}
|
|
@@ -4,11 +4,15 @@ export interface IClosestFacilityOptions extends IEndpointOptions {
|
|
|
4
4
|
/**
|
|
5
5
|
* Specify one or more locations from which the service searches for the nearby locations. These locations are referred to as incidents.
|
|
6
6
|
*/
|
|
7
|
-
incidents: Array<IPoint | ILocation | [number, number]> | IFeatureSet
|
|
7
|
+
incidents: Array<IPoint | ILocation | [number, number]> | IFeatureSet | {
|
|
8
|
+
url: string;
|
|
9
|
+
};
|
|
8
10
|
/**
|
|
9
11
|
* Specify one or more locations that are searched for when finding the closest location.
|
|
10
12
|
*/
|
|
11
|
-
facilities: Array<IPoint | ILocation | [number, number]> | IFeatureSet
|
|
13
|
+
facilities: Array<IPoint | ILocation | [number, number]> | IFeatureSet | {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
12
16
|
/**
|
|
13
17
|
* Specify if the service should return routes.
|
|
14
18
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
2
2
|
* Apache-2.0 */
|
|
3
3
|
import { request, cleanUrl, appendCustomParams } from "@esri/arcgis-rest-request";
|
|
4
|
-
import { ARCGIS_ONLINE_CLOSEST_FACILITY_URL, normalizeLocationsList, isFeatureSet } from "./helpers.js";
|
|
4
|
+
import { ARCGIS_ONLINE_CLOSEST_FACILITY_URL, normalizeLocationsList, isFeatureSet, isJsonWithURL } from "./helpers.js";
|
|
5
5
|
import { arcgisToGeoJSON } from "@terraformer/arcgis";
|
|
6
6
|
function getTravelDirection(key) {
|
|
7
7
|
if (key === "incidentsToFacilities") {
|
|
@@ -66,13 +66,15 @@ export function closestFacility(requestOptions) {
|
|
|
66
66
|
endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL) {
|
|
67
67
|
return Promise.reject("Finding the closest facility using the ArcGIS service requires authentication");
|
|
68
68
|
}
|
|
69
|
-
if (isFeatureSet(requestOptions.incidents)
|
|
69
|
+
if (isFeatureSet(requestOptions.incidents) ||
|
|
70
|
+
isJsonWithURL(requestOptions.incidents)) {
|
|
70
71
|
options.params.incidents = requestOptions.incidents;
|
|
71
72
|
}
|
|
72
73
|
else {
|
|
73
74
|
options.params.incidents = normalizeLocationsList(requestOptions.incidents).join(";");
|
|
74
75
|
}
|
|
75
|
-
if (isFeatureSet(requestOptions.facilities)
|
|
76
|
+
if (isFeatureSet(requestOptions.facilities) ||
|
|
77
|
+
isJsonWithURL(requestOptions.facilities)) {
|
|
76
78
|
options.params.facilities = requestOptions.facilities;
|
|
77
79
|
}
|
|
78
80
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closestFacility.js","sourceRoot":"","sources":["../../src/closestFacility.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EACL,OAAO,EACP,QAAQ,EACR,kBAAkB,EAKnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,kCAAkC,EAElC,sBAAsB,EACtB,YAAY,
|
|
1
|
+
{"version":3,"file":"closestFacility.js","sourceRoot":"","sources":["../../src/closestFacility.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EACL,OAAO,EACP,QAAQ,EACR,kBAAkB,EAKnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,kCAAkC,EAElC,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA4EtD,SAAS,kBAAkB,CACzB,GAAsD;IAEtD,IAAI,GAAG,KAAK,uBAAuB,EAAE;QACnC,OAAO,mCAAmC,CAAC;KAC5C;SAAM;QACL,OAAO,iCAAiC,CAAC;KAC1C;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,eAAe,CAC7B,cAAuC;IAEvC,MAAM,QAAQ,GACZ,cAAc,CAAC,QAAQ,IAAI,kCAAkC,CAAC;IAEhE,cAAc,CAAC,MAAM,mBACnB,gBAAgB,EAAE,IAAI,EACtB,gBAAgB,EAAE,IAAI,EACtB,eAAe,EAAE,IAAI,EACrB,cAAc,EAAE,IAAI,EACpB,sBAAsB,EAAE,IAAI,EAC5B,qBAAqB,EAAE,IAAI,EAC3B,gBAAgB,EAAE,IAAI,IACnB,cAAc,CAAC,MAAM,CACzB,CAAC;IAEF,MAAM,OAAO,GAAG,kBAAkB,CAA0B,cAAc,EAAE;QAC1E,gBAAgB;QAChB,qBAAqB;QACrB,UAAU;QACV,kBAAkB;QAClB,iBAAiB;QACjB,kBAAkB;QAClB,sBAAsB;QACtB,uBAAuB;QACvB,aAAa;QACb,kBAAkB;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GAAG,sBAAsB,CAC9C,cAAc,CAAC,QAAQ,CACxB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACb;KACF;IAED,OAAO,OAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC,IAAI,CACxE,aAAa,CACd,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,GAAQ;IAC7B,qCAAqC;IACrC,IAAI,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,KAAK,IAAI,EAAE;QAC7C,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAClD;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,eAAe;IACb,eAAe;CAChB,CAAC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n ILocation,\n IPoint,\n IFeature,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_CLOSEST_FACILITY_URL,\n IEndpointOptions,\n normalizeLocationsList,\n isFeatureSet,\n isJsonWithURL\n} from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IClosestFacilityOptions extends IEndpointOptions {\n /**\n * Specify one or more locations from which the service searches for the nearby locations. These locations are referred to as incidents.\n */\n incidents:\n | Array<IPoint | ILocation | [number, number]>\n | IFeatureSet\n | { url: string };\n\n /**\n * Specify one or more locations that are searched for when finding the closest location.\n */\n facilities:\n | Array<IPoint | ILocation | [number, number]>\n | IFeatureSet\n | { url: string };\n /**\n * Specify if the service should return routes.\n */\n returnCFRoutes: boolean;\n travelDirection?: \"incidentsToFacilities\" | \"facilitiesToIncidents\";\n barriers?: Array<IPoint | ILocation | [number, number]> | IFeatureSet;\n polylineBarriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n returnDirections?: boolean;\n directionsOutputType?:\n | \"esriDOTComplete\"\n | \"esriDOTCompleteNoEvents\"\n | \"esriDOTInstructionsOnly\"\n | \"esriDOTStandard\"\n | \"esriDOTSummaryOnly\"\n | \"esriDOTFeatureSets\";\n directionsLengthUnits?:\n | \"esriNAUCentimeters\"\n | \"esriNAUDecimalDegrees\"\n | \"esriNAUDecimeters\"\n | \"esriNAUFeet\"\n | \"esriNAUInches\"\n | \"esriNAUKilometers\"\n | \"esriNAUMeters\"\n | \"esriNAUMiles\"\n | \"esriNAUMillimeters\"\n | \"esriNAUNauticalMiles\"\n | \"esriNAUPoints\"\n | \"esriNAUYards\";\n outputLines?: boolean;\n returnFacilities?: boolean;\n returnIncidents?: boolean;\n returnBarriers?: boolean;\n returnPolylineBarriers?: boolean;\n returnPolygonBarriers?: boolean;\n preserveObjectID?: boolean;\n}\n\ninterface IFeatureSetWithGeoJson extends IFeatureSet {\n geoJson?: any;\n}\n\nexport interface IClosestFacilityResponse {\n messages: string[];\n routes?: IFeatureSetWithGeoJson;\n directions?: Array<{\n routeId: number;\n routeName: string;\n summary: object;\n features: IFeature[];\n }>;\n incidents?: IFeatureSet;\n facilities?: IFeatureSet;\n barriers?: IFeatureSet;\n polygonBarriers?: IFeatureSet;\n polylineBarriers?: IFeatureSet;\n}\n\nfunction getTravelDirection(\n key: \"incidentsToFacilities\" | \"facilitiesToIncidents\"\n): \"esriNATravelDirectionFromFacility\" | \"esriNATravelDirectionToFacility\" {\n if (key === \"incidentsToFacilities\") {\n return \"esriNATravelDirectionFromFacility\";\n } else {\n return \"esriNATravelDirectionToFacility\";\n }\n}\n\n/**\n * 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.\n *\n * ```js\n * import { closestFacility } from '@esri/arcgis-rest-routing';\n *\n * closestFacility({\n * incidents: [\n * [-90.404302, 38.600621],\n * [-90.364293, 38.620427],\n * ],\n * facilities: [\n * [-90.444716, 38.635501],\n * [-90.311919, 38.633523],\n * [-90.451147, 38.581107]\n * ],\n * authentication\n * })\n * .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}\n * ```\n *\n * @param requestOptions Options to pass through to the routing service.\n * @returns A Promise that will resolve with routes and directions for the request.\n * @restlink https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm\n * @inline IClosestFacilityOptions\n */\nexport function closestFacility(\n requestOptions: IClosestFacilityOptions\n): Promise<IClosestFacilityResponse> {\n const endpoint =\n requestOptions.endpoint || ARCGIS_ONLINE_CLOSEST_FACILITY_URL;\n\n requestOptions.params = {\n returnFacilities: true,\n returnDirections: true,\n returnIncidents: true,\n returnBarriers: true,\n returnPolylineBarriers: true,\n returnPolygonBarriers: true,\n preserveObjectID: true,\n ...requestOptions.params\n };\n\n const options = appendCustomParams<IClosestFacilityOptions>(requestOptions, [\n \"returnCFRoutes\",\n // \"travelDirection\",\n \"barriers\",\n \"polylineBarriers\",\n \"polygonBarriers\",\n \"returnDirections\",\n \"directionsOutputType\",\n \"directionsLengthUnits\",\n \"outputLines\",\n \"returnFacilities\",\n \"returnIncidents\",\n \"returnBarriers\",\n \"returnPolylineBarriers\",\n \"returnPolygonBarriers\",\n \"preserveObjectID\"\n ]);\n\n // Set travelDirection\n if (requestOptions.travelDirection) {\n options.params.travelDirection = getTravelDirection(\n requestOptions.travelDirection\n );\n }\n\n // the SAAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n endpoint === ARCGIS_ONLINE_CLOSEST_FACILITY_URL\n ) {\n return Promise.reject(\n \"Finding the closest facility using the ArcGIS service requires authentication\"\n );\n }\n\n if (\n isFeatureSet(requestOptions.incidents) ||\n isJsonWithURL(requestOptions.incidents)\n ) {\n options.params.incidents = requestOptions.incidents;\n } else {\n options.params.incidents = normalizeLocationsList(\n requestOptions.incidents\n ).join(\";\");\n }\n\n if (\n isFeatureSet(requestOptions.facilities) ||\n isJsonWithURL(requestOptions.facilities)\n ) {\n options.params.facilities = requestOptions.facilities;\n } else {\n options.params.facilities = normalizeLocationsList(\n requestOptions.facilities\n ).join(\";\");\n }\n\n // optional input param that may need point geometry normalizing\n if (requestOptions.barriers) {\n if (isFeatureSet(requestOptions.barriers)) {\n options.params.barriers = requestOptions.barriers;\n } else {\n // optional point geometry barriers must be normalized, too\n // but not if provided as IFeatureSet type\n // note that optional polylineBarriers and polygonBarriers do not need to be normalized\n options.params.barriers = normalizeLocationsList(\n requestOptions.barriers\n ).join(\";\");\n }\n }\n\n return request(`${cleanUrl(endpoint)}/solveClosestFacility`, options).then(\n cleanResponse\n );\n}\n\nfunction cleanResponse(res: any): IClosestFacilityResponse {\n // add \"geoJson\" property to \"routes\"\n if (res.routes.spatialReference.wkid === 4326) {\n res.routes.geoJson = arcgisToGeoJSON(res.routes);\n }\n return res;\n}\n\nexport default {\n closestFacility\n};\n"]}
|
package/dist/esm/helpers.d.ts
CHANGED
|
@@ -15,3 +15,7 @@ export declare function decompressGeometry(str: string): IPolyline;
|
|
|
15
15
|
* User Defined Type Guard that verifies this is a featureSet
|
|
16
16
|
*/
|
|
17
17
|
export declare function isFeatureSet(arg: any): arg is IFeatureSet;
|
|
18
|
+
/**
|
|
19
|
+
* User Defined Type Guard that verifies this is a JSON with `url` property
|
|
20
|
+
*/
|
|
21
|
+
export declare function isJsonWithURL(arg: any): arg is Object;
|
package/dist/esm/helpers.js
CHANGED
|
@@ -62,4 +62,10 @@ export function decompressGeometry(str) {
|
|
|
62
62
|
export function isFeatureSet(arg) {
|
|
63
63
|
return Object.prototype.hasOwnProperty.call(arg, "features");
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* User Defined Type Guard that verifies this is a JSON with `url` property
|
|
67
|
+
*/
|
|
68
|
+
export function isJsonWithURL(arg) {
|
|
69
|
+
return "url" in arg;
|
|
70
|
+
}
|
|
65
71
|
//# sourceMappingURL=helpers.js.map
|
package/dist/esm/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|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B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,CAAC,CAAC;IACN,IAAI,CAAC,CAAC;IAEN,2DAA2D;IAC3D,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAE7C,gDAAgD;IAChD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QAC1C,kCAAkC;QAClC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QACzC,SAAS,GAAG,CAAC,CAAC;QAEd,oCAAoC;QACpC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QAC7C,SAAS,GAAG,CAAC,CAAC;QAEd,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,WAAW,CAAe,CAAC,CAAC;KAC/D;IAED,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,CAAC;KACH,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,GAAQ;IACnC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA;gBACgB;AAWhB,eAAe;AACf,MAAM,CAAC,MAAM,yBAAyB,GACpC,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D,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAE7C,gDAAgD;IAChD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QAC1C,kCAAkC;QAClC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QACzC,SAAS,GAAG,CAAC,CAAC;QAEd,oCAAoC;QACpC,8DAA8D;QAC9D,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;QAC7C,SAAS,GAAG,CAAC,CAAC;QAEd,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,WAAW,CAAe,CAAC,CAAC;KAC/D;IAED,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,CAAC;KACH,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,GAAQ;IACnC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAQ;IACpC,OAAO,KAAK,IAAI,GAAG,CAAC;AACtB,CAAC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IRequestOptions,\n ILocation,\n IPoint,\n IPolyline,\n Position2D,\n IFeatureSet\n} from \"@esri/arcgis-rest-request\";\n\n// https always\nexport const ARCGIS_ONLINE_ROUTING_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World\";\nexport const ARCGIS_ONLINE_CLOSEST_FACILITY_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World\";\nexport const ARCGIS_ONLINE_SERVICE_AREA_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World\";\nexport const ARCGIS_ONLINE_ORIGIN_DESTINATION_MATRIX_URL =\n \"https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World\";\n\n// nice to have: verify custom endpoints contain 'NAServer' and end in a '/'\nexport interface IEndpointOptions extends IRequestOptions {\n /**\n * Any ArcGIS Routing service (example: https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/ ) to use for the routing service request.\n */\n endpoint?: string;\n}\n\nfunction isLocationArray(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is [number, number] | [number, number, number] {\n return (\n (coords as [number, number]).length === 2 ||\n (coords as [number, number, number]).length === 3\n );\n}\n\nfunction isLocation(\n coords: ILocation | IPoint | [number, number] | [number, number, number]\n): coords is ILocation {\n return (\n (coords as ILocation).latitude !== undefined ||\n (coords as ILocation).lat !== undefined\n );\n}\n\nexport function normalizeLocationsList(\n locations: Array<IPoint | ILocation | [number, number]>\n): string[] {\n return locations.map((coords) => {\n if (isLocationArray(coords)) {\n return coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n return coords.long + \",\" + coords.lat;\n } else {\n return coords.longitude + \",\" + coords.latitude;\n }\n } else {\n return coords.x + \",\" + coords.y;\n }\n });\n}\n\nexport function decompressGeometry(str: string) {\n let xDiffPrev = 0;\n let yDiffPrev = 0;\n const points = [];\n let x;\n let y;\n\n // Split the string into an array on the + and - characters\n const strings = str.match(/((\\+|-)[^+-]+)/g);\n\n // The first value is the coefficient in base 32\n const coefficient = parseInt(strings[0], 32);\n\n for (let j = 1; j < strings.length; j += 2) {\n // j is the offset for the x value\n // Convert the value from base 32 and add the previous x value\n x = parseInt(strings[j], 32) + xDiffPrev;\n xDiffPrev = x;\n\n // j+1 is the offset for the y value\n // Convert the value from base 32 and add the previous y value\n y = parseInt(strings[j + 1], 32) + yDiffPrev;\n yDiffPrev = y;\n\n points.push([x / coefficient, y / coefficient] as Position2D);\n }\n\n return {\n paths: [points]\n } as IPolyline;\n}\n\n/**\n * User Defined Type Guard that verifies this is a featureSet\n */\nexport function isFeatureSet(arg: any): arg is IFeatureSet {\n return Object.prototype.hasOwnProperty.call(arg, \"features\");\n}\n\n/**\n * User Defined Type Guard that verifies this is a JSON with `url` property\n */\nexport function isJsonWithURL(arg: any): arg is Object {\n return \"url\" in arg;\n}\n"]}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./solveRoute.js\";\nexport * from \"./closestFacility.js\";\nexport * from \"./serviceArea.js\";\nexport * from \"./originDestinationMatrix.js\";\nexport * from \"./helpers.js\";\n\n// Types that are used in this package are re-exported for convenience and\n// to make the links work correctly in the documentation pages.\nexport type {\n IRequestOptions,\n ILocation,\n IPoint,\n IPolyline,\n Position2D,\n IFeatureSet,\n IFeature\n} from \"@esri/arcgis-rest-request\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esri/arcgis-rest-routing",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Routing helpers for @esri/arcgis-rest-js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"tslib": "^2.3.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@esri/arcgis-rest-request": "4.0.
|
|
51
|
+
"@esri/arcgis-rest-request": "^4.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@esri/arcgis-rest-request": "4.0.1"
|
|
54
|
+
"@esri/arcgis-rest-request": "^4.0.1"
|
|
55
55
|
},
|
|
56
56
|
"contributors": [
|
|
57
57
|
"Gavin Rehkemper <gavin@gavinr.com>"
|