@esri/arcgis-rest-geocoding 3.4.3 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -14
- package/dist/bundled/geocoding.esm.js +525 -0
- package/dist/bundled/geocoding.esm.js.map +1 -0
- package/dist/bundled/geocoding.esm.min.js +12 -0
- package/dist/bundled/geocoding.esm.min.js.map +1 -0
- package/dist/bundled/geocoding.umd.js +539 -0
- package/dist/bundled/geocoding.umd.js.map +1 -0
- package/dist/bundled/geocoding.umd.min.js +13 -0
- package/dist/bundled/geocoding.umd.min.js.map +1 -0
- package/dist/{node → cjs}/bulk.js +7 -8
- package/dist/cjs/bulk.js.map +1 -0
- package/dist/{node → cjs}/geocode.js +16 -17
- package/dist/cjs/geocode.js.map +1 -0
- package/dist/{node → cjs}/helpers.js +4 -5
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/{node → cjs}/reverse.js +5 -6
- package/dist/cjs/reverse.js.map +1 -0
- package/dist/{node → cjs}/suggest.js +5 -6
- package/dist/cjs/suggest.js.map +1 -0
- package/dist/esm/bulk.d.ts +2 -2
- package/dist/esm/bulk.js +5 -6
- package/dist/esm/bulk.js.map +1 -1
- package/dist/esm/geocode.d.ts +4 -2
- package/dist/esm/geocode.js +10 -11
- package/dist/esm/geocode.js.map +1 -1
- package/dist/esm/helpers.js +4 -5
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/reverse.d.ts +2 -2
- package/dist/esm/reverse.js +4 -5
- package/dist/esm/reverse.js.map +1 -1
- package/dist/esm/suggest.d.ts +1 -1
- package/dist/esm/suggest.js +4 -5
- package/dist/esm/suggest.js.map +1 -1
- package/package.json +45 -42
- package/dist/node/bulk.js.map +0 -1
- package/dist/node/geocode.js.map +0 -1
- package/dist/node/helpers.js.map +0 -1
- package/dist/node/index.js +0 -11
- package/dist/node/index.js.map +0 -1
- package/dist/node/reverse.js.map +0 -1
- package/dist/node/suggest.js.map +0 -1
- package/dist/umd/geocoding.umd.js +0 -565
- package/dist/umd/geocoding.umd.js.map +0 -1
- package/dist/umd/geocoding.umd.min.js +0 -12
- package/dist/umd/geocoding.umd.min.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding.umd.min.js","sources":["../../src/helpers.ts","../../../../node_modules/@terraformer/arcgis/dist/t-arcgis.esm.js","../../src/bulk.ts","../../src/geocode.ts","../../src/reverse.ts","../../src/suggest.ts"],"sourcesContent":["/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, IRequestOptions } from \"@esri/arcgis-rest-request\";\n\n// https always\nexport const ARCGIS_ONLINE_GEOCODING_URL =\n \"https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/\";\nexport const ARCGIS_ONLINE_BULK_GEOCODING_URL =\n \"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/\";\n\n// nice to have: verify custom endpoints contain 'GeocodeServer' and end in a '/'\nexport interface IEndpointOptions extends IRequestOptions {\n /**\n * Any ArcGIS Geocoding service (example: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Locators/SanDiego/GeocodeServer )\n */\n endpoint?: string;\n}\n\nexport interface IGetGeocodeServiceResponse {\n currentVersion: number;\n serviceDescription: string;\n addressFields: any[];\n countries: string[];\n capabilities: string;\n}\n\n/**\n * Used to fetch metadata from a geocoding service.\n *\n * ```js\n * import { getGeocoderServiceInfo } from '@esri/arcgis-rest-geocoding';\n *\n * getGeocoderServiceInfo()\n * .then((response) => {\n * response.serviceDescription; // => 'World Geocoder'\n * });\n * ```\n *\n * @param requestOptions - Request options can contain a custom geocoding service to fetch metadata from.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function getGeocodeService(\n requestOptions?: IEndpointOptions\n): Promise<IGetGeocodeServiceResponse> {\n const url =\n (requestOptions && requestOptions.endpoint) || ARCGIS_ONLINE_GEOCODING_URL;\n\n const options: IEndpointOptions = {\n httpMethod: \"GET\",\n maxUrlLength: 2000,\n ...requestOptions\n };\n\n return request(url, options);\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) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl, ISpatialReference, IPoint } from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_BULK_GEOCODING_URL,\n IEndpointOptions\n} from \"./helpers.js\";\n\n// It would be better if doc did not display these properties in alphabetical order\nexport interface IAddressBulk {\n /**\n * A unique id must be passed along for each individual address.\n */\n OBJECTID: number;\n address?: string;\n address2?: string;\n address3?: string;\n neighborhood?: string;\n city?: string;\n subregion?: string;\n /**\n * The World Geocoding Service considers US states regions.\n */\n region?: string;\n postal?: number;\n postalExt?: number;\n countryCode?: string;\n}\n\nexport interface IBulkGeocodeOptions extends IEndpointOptions {\n addresses: IAddressBulk[];\n}\n\nexport interface IBulkGeocodeResponse {\n spatialReference: ISpatialReference;\n locations: Array<{\n address: string;\n location?: IPoint; // candidates with a score of 0 wont include a location\n score: number;\n attributes: object;\n }>;\n}\n\n/**\n * ```js\n * import { bulkGeocode } from '@esri/arcgis-rest-geocoding';\n * import { ApplicationSession } from '@esri/arcgis-rest-auth';\n * //\n * const addresses = [\n * { \"OBJECTID\": 1, \"SingleLine\": \"380 New York Street 92373\" },\n * { \"OBJECTID\": 2, \"SingleLine\": \"1 World Way Los Angeles 90045\" }\n * ];\n * //\n * bulkGeocode({ addresses, authentication: session })\n * .then((response) => {\n * response.locations[0].location; // => { x: -117, y: 34, spatialReference: { wkid: 4326 } }\n * });\n * ```\n * Used to geocode a [batch](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-geocode-addresses.htm) of addresses.\n *\n * @param requestOptions - Request options to pass to the geocoder, including an array of addresses and authentication session.\n * @returns A Promise that will resolve with the data from the response. The spatial reference will be added to address locations unless `rawResponse: true` was passed.\n */\nexport function bulkGeocode(\n requestOptions: IBulkGeocodeOptions // must POST, which is the default\n): Promise<IBulkGeocodeResponse> {\n const options: IBulkGeocodeOptions = {\n endpoint: ARCGIS_ONLINE_BULK_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n options.params.addresses = {\n records: requestOptions.addresses.map((address) => {\n return { attributes: address };\n })\n };\n\n // the SAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n options.endpoint === ARCGIS_ONLINE_BULK_GEOCODING_URL\n ) {\n return Promise.reject(\n \"bulk geocoding using the ArcGIS service requires authentication\"\n );\n }\n\n return request(\n `${cleanUrl(options.endpoint)}/geocodeAddresses`,\n options\n ).then((response) => {\n if (options.rawResponse) {\n return response;\n }\n const sr = response.spatialReference;\n response.locations.forEach(function (address: { location: IPoint }) {\n if (address.location) {\n address.location.spatialReference = sr;\n }\n });\n return response;\n });\n}\n","/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n IExtent,\n ISpatialReference,\n IPoint\n} from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IGeocodeOptions extends IEndpointOptions {\n /**\n * use this if all your address info is contained in a single string.\n */\n singleLine?: string;\n address?: string;\n address2?: string;\n address3?: string;\n neighborhood?: string;\n city?: string;\n subregion?: string;\n outFields?: \"*\" | string[];\n /**\n * The World Geocoding Service expects US states to be passed in as a 'region'.\n */\n region?: string;\n postal?: number;\n postalExt?: number;\n countryCode?: string;\n /**\n * You can create an autocomplete experience by making a call to suggest with partial text and then passing through the magicKey and complete address that are returned to geocode.\n *\n * ```js\n * import { suggest, geocode } from '@esri/arcgis-rest-geocoding';\n *\n * suggest(\"LAX\")\n * .then((response) => {\n * geocode({\n * singleLine: response.suggestions[1].text,\n * magicKey: response.suggestions[0].magicKey\n * })\n * })\n * ```\n */\n magicKey?: string;\n}\n\nexport interface IGeocodeResponse {\n spatialReference: ISpatialReference;\n candidates: Array<{\n address: string;\n location: IPoint;\n extent?: IExtent;\n score: number;\n attributes: object;\n }>;\n geoJson?: {\n type: string;\n features: Array<{\n type: string;\n geometry: object;\n properties: any;\n }>;\n };\n}\n\n/**\n * ```js\n * import { geocode } from '@esri/arcgis-rest-geocoding';\n * //\n * geocode(\"LAX\")\n * .then((response) => {\n * response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: ... }\n * });\n * //\n * geocode({\n * address: \"1600 Pennsylvania Ave\",\n * postal: 20500,\n * countryCode: \"USA\"\n * })\n * .then((response) => {\n * response.candidates[1].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... }\n * });\n * ```\n * Used to determine the location of a single address or point of interest. See the [REST Documentation](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) for more information.\n * @param address String representing the address or point of interest or RequestOptions to pass to the endpoint.\n * @returns A Promise that will resolve with address candidates for the request. The spatial reference will be added to candidate locations and extents unless `rawResponse: true` was passed.\n */\nexport function geocode(\n address: string | IGeocodeOptions\n): Promise<IGeocodeResponse> {\n let options: IGeocodeOptions = {};\n let endpoint: string;\n\n if (typeof address === \"string\") {\n options.params = { singleLine: address };\n endpoint = ARCGIS_ONLINE_GEOCODING_URL;\n } else {\n endpoint = address.endpoint || ARCGIS_ONLINE_GEOCODING_URL;\n options = appendCustomParams<IGeocodeOptions>(\n address,\n [\n \"singleLine\",\n \"address\",\n \"address2\",\n \"address3\",\n \"neighborhood\",\n \"city\",\n \"subregion\",\n \"region\",\n \"postal\",\n \"postalExt\",\n \"countryCode\",\n \"outFields\",\n \"magicKey\"\n ],\n { params: { ...address.params } }\n );\n }\n\n // add spatialReference property to individual matches\n return request(`${cleanUrl(endpoint)}/findAddressCandidates`, options).then(\n (response) => {\n if (typeof address !== \"string\" && address.rawResponse) {\n return response;\n }\n const sr: ISpatialReference = response.spatialReference;\n response.candidates.forEach(function (candidate: {\n location: IPoint;\n extent?: IExtent;\n }) {\n candidate.location.spatialReference = sr;\n if (candidate.extent) {\n candidate.extent.spatialReference = sr;\n }\n });\n\n // geoJson\n if (sr.wkid === 4326) {\n const features = response.candidates.map((candidate: any) => {\n return {\n type: \"Feature\",\n geometry: arcgisToGeoJSON(candidate.location),\n properties: Object.assign(\n {\n address: candidate.address,\n score: candidate.score\n },\n candidate.attributes\n )\n };\n });\n\n response.geoJson = {\n type: \"FeatureCollection\",\n features\n };\n }\n\n return response;\n }\n );\n}\n","/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl, IPoint, ILocation } from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nexport interface IReverseGeocodeResponse {\n address: {\n [key: string]: any;\n };\n location: IPoint;\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 * ```js\n * import { reverseGeocode } from '@esri/arcgis-rest-geocoding';\n * //\n * reverseGeocode([-118.409,33.943 ]) // long, lat\n * .then((response) => {\n * response.address.PlaceName; // => \"LA Airport\"\n * });\n * // or\n * reverseGeocode({ long: -118.409, lat: 33.943 })\n * reverseGeocode({ latitude: 33.943, latitude: -118.409 })\n * reverseGeocode({ x: -118.409, y: 33.9425 }) // wgs84 is assumed\n * reverseGeocode({ x: -13181226, y: 4021085, spatialReference: { wkid: 3857 })\n * ```\n * Used to determine the address of a [location](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-reverse-geocode.htm).\n *\n * @param coordinates - the location you'd like to associate an address with.\n * @param requestOptions - Additional options for the request including authentication.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function reverseGeocode(\n coords: IPoint | ILocation | [number, number],\n requestOptions?: IEndpointOptions\n): Promise<IReverseGeocodeResponse> {\n const options: IEndpointOptions = {\n endpoint: ARCGIS_ONLINE_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n if (isLocationArray(coords)) {\n options.params.location = coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n options.params.location = coords.long + \",\" + coords.lat;\n }\n if (coords.latitude) {\n options.params.location = coords.longitude + \",\" + coords.latitude;\n }\n } else {\n // if input is a point, we can pass it straight through, with or without a spatial reference\n options.params.location = coords;\n }\n\n return request(`${cleanUrl(options.endpoint)}/reverseGeocode`, options);\n}\n\nexport default {\n reverseGeocode\n};\n","/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl } from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nexport interface ISuggestResponse {\n suggestions: Array<{\n text: string;\n magicKey: string;\n isCollection: boolean;\n }>;\n}\n\n/**\n * ```js\n * import { suggest } from '@esri/arcgis-rest-geocoding';\n * //\n * suggest(\"Starb\")\n * .then(response) // response.text === \"Starbucks\"\n * ```\n * Used to return a placename [suggestion](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm) for a partial string.\n *\n * @param requestOptions - Options for the request including authentication and other optional parameters.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function suggest(\n partialText: string,\n requestOptions?: IEndpointOptions\n): Promise<ISuggestResponse> {\n const options: IEndpointOptions = {\n endpoint: ARCGIS_ONLINE_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n options.params.text = partialText;\n\n return request(`${cleanUrl(options.endpoint)}/suggest`, options);\n}\n\nexport default {\n suggest\n};\n"],"names":["ARCGIS_ONLINE_GEOCODING_URL","ARCGIS_ONLINE_BULK_GEOCODING_URL","edgeIntersectsEdge","a1","a2","b1","b2","uaT","ubT","uB","ua","ub","arrayIntersectsArray","a","b","i","length","j","ringIsClockwise","ringToTest","pt2","total","rLength","pt1","coordinatesContainCoordinates","outer","inner","intersects","contains","coordinates","point","l","coordinatesContainPoint","arcgisToGeoJSON","arcgis","idAttribute","geojson","features","type","push","x","y","z","points","slice","paths","rings","outerRing","hole","outerRings","holes","r","ring","pointsEqual","polygon","reverse","uncontainedHoles","pop","contained","convertRingsToGeoJSON","xmin","ymin","xmax","ymax","geometry","attributes","properties","obj","target","hasOwnProperty","shallowClone","id","keys","key","Error","getId","err","JSON","stringify","spatialReference","wkid","console","warn","requestOptions","options","endpoint","params","addresses","records","map","address","authentication","request","cleanUrl","then","response","rawResponse","sr","locations","forEach","location","Promise","reject","singleLine","appendCustomParams","candidates","candidate","extent","Object","assign","score","geoJson","url","httpMethod","maxUrlLength","coords","isLocationArray","undefined","latitude","lat","isLocation","long","longitude","join","partialText","text"],"mappings":";;;;;sVAMaA,EACX,2EACWC,EACX;;;;;;ACDF,IAAIC,EAAqB,SAA4BC,EAAIC,EAAIC,EAAIC,GAC/D,IAAIC,GAAOD,EAAG,GAAKD,EAAG,KAAOF,EAAG,GAAKE,EAAG,KAAOC,EAAG,GAAKD,EAAG,KAAOF,EAAG,GAAKE,EAAG,IACxEG,GAAOJ,EAAG,GAAKD,EAAG,KAAOA,EAAG,GAAKE,EAAG,KAAOD,EAAG,GAAKD,EAAG,KAAOA,EAAG,GAAKE,EAAG,IACxEI,GAAMH,EAAG,GAAKD,EAAG,KAAOD,EAAG,GAAKD,EAAG,KAAOG,EAAG,GAAKD,EAAG,KAAOD,EAAG,GAAKD,EAAG,IAE3E,GAAW,IAAPM,EAAU,CACZ,IAAIC,EAAKH,EAAME,EACXE,EAAKH,EAAMC,EAEf,GAAIC,GAAM,GAAKA,GAAM,GAAKC,GAAM,GAAKA,GAAM,EACzC,OAAO,EAIX,OAAO,GAsBLC,EAAuB,SAA8BC,EAAGC,GAC1D,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAEG,OAAS,EAAGD,IAChC,IAAK,IAAIE,EAAI,EAAGA,EAAIH,EAAEE,OAAS,EAAGC,IAChC,GAAIf,EAAmBW,EAAEE,GAAIF,EAAEE,EAAI,GAAID,EAAEG,GAAIH,EAAEG,EAAI,IACjD,OAAO,EAKb,OAAO,GAgBLC,EAAkB,SAAyBC,GAO7C,IANA,IAIIC,EAJAC,EAAQ,EACRN,EAAI,EACJO,EAAUH,EAAWH,OACrBO,EAAMJ,EAAWJ,GAGbA,EAAIO,EAAU,EAAGP,IAEvBM,KADAD,EAAMD,EAAWJ,EAAI,IACP,GAAKQ,EAAI,KAAOH,EAAI,GAAKG,EAAI,IAC3CA,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KAAM,UACN0B,SAAU/B,EAAgByE,EAAUN,UACpClC,WAAY0C,OAAOC,OACjB,CACEnB,QAASgB,EAAUhB,QACnBoB,MAAOJ,EAAUI,OAEnBJ,EAAUzC,gBAKhB8B,EAASgB,QAAU,CACjBzE,KAAM,oBACND,SAAAA,GAIJ,OAAO0D,mCH1HXZ,GAEA,MAAM6B,EACH7B,GAAkBA,EAAeE,UAAarF,EAE3CoF,iBACJ6B,WAAY,MACZC,aAAc,KACX/B,GAGL,OAAOS,UAAQoB,EAAK5B,8BIDpB+B,EACAhC,GAEA,MAAMC,iBACJC,SAAUrF,EACVsF,OAAQ,IACLH,GAiBL,OA9DF,SACEgC,GAEA,OAC0C,IAAvCA,EAA4BnG,QACmB,IAA/CmG,EAAoCnG,OA2CnCoG,CAAgBD,IAvCtB,SACEA,GAEA,YACqCE,IAAlCF,EAAqBG,eACQD,IAA7BF,EAAqBI,IAoCbC,CAAWL,GASpB/B,EAAQE,OAAOc,SAAWe,GARtBA,EAAOI,MACTnC,EAAQE,OAAOc,SAAWe,EAAOM,KAAO,IAAMN,EAAOI,KAEnDJ,EAAOG,WACTlC,EAAQE,OAAOc,SAAWe,EAAOO,UAAY,IAAMP,EAAOG,WAN5DlC,EAAQE,OAAOc,SAAWe,EAAOQ,OAa5B/B,UAAQ,GAAGC,WAAST,EAAQC,2BAA4BD,uBChD/DwC,EACAzC,GAEA,MAAMC,iBACJC,SAAUrF,EACVsF,OAAQ,IACLH,GAKL,OAFAC,EAAQE,OAAOuC,KAAOD,EAEfhC,UAAQ,GAAGC,WAAST,EAAQC,oBAAqBD"}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Apache-2.0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.bulkGeocode = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var helpers_1 = require("./helpers");
|
|
6
|
+
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
7
|
+
const helpers_js_1 = require("./helpers.js");
|
|
9
8
|
/**
|
|
10
9
|
* ```js
|
|
11
10
|
* import { bulkGeocode } from '@esri/arcgis-rest-geocoding';
|
|
@@ -28,22 +27,22 @@ var helpers_1 = require("./helpers");
|
|
|
28
27
|
*/
|
|
29
28
|
function bulkGeocode(requestOptions // must POST, which is the default
|
|
30
29
|
) {
|
|
31
|
-
|
|
30
|
+
const options = Object.assign({ endpoint: helpers_js_1.ARCGIS_ONLINE_BULK_GEOCODING_URL, params: {} }, requestOptions);
|
|
32
31
|
options.params.addresses = {
|
|
33
|
-
records: requestOptions.addresses.map(
|
|
32
|
+
records: requestOptions.addresses.map((address) => {
|
|
34
33
|
return { attributes: address };
|
|
35
34
|
})
|
|
36
35
|
};
|
|
37
36
|
// the SAS service does not support anonymous requests
|
|
38
37
|
if (!requestOptions.authentication &&
|
|
39
|
-
options.endpoint ===
|
|
38
|
+
options.endpoint === helpers_js_1.ARCGIS_ONLINE_BULK_GEOCODING_URL) {
|
|
40
39
|
return Promise.reject("bulk geocoding using the ArcGIS service requires authentication");
|
|
41
40
|
}
|
|
42
|
-
return arcgis_rest_request_1.request(arcgis_rest_request_1.cleanUrl(options.endpoint)
|
|
41
|
+
return (0, arcgis_rest_request_1.request)(`${(0, arcgis_rest_request_1.cleanUrl)(options.endpoint)}/geocodeAddresses`, options).then((response) => {
|
|
43
42
|
if (options.rawResponse) {
|
|
44
43
|
return response;
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
const sr = response.spatialReference;
|
|
47
46
|
response.locations.forEach(function (address) {
|
|
48
47
|
if (address.location) {
|
|
49
48
|
address.location.spatialReference = sr;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk.js","sourceRoot":"","sources":["../../src/bulk.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAAyF;AAEzF,6CAGsB;AAqCtB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,WAAW,CACzB,cAAmC,CAAC,kCAAkC;;IAEtE,MAAM,OAAO,mBACX,QAAQ,EAAE,6CAAgC,EAC1C,MAAM,EAAE,EAAE,IACP,cAAc,CAClB,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,SAAS,GAAG;QACzB,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YAChD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QACjC,CAAC,CAAC;KACH,CAAC;IAEF,sDAAsD;IACtD,IACE,CAAC,cAAc,CAAC,cAAc;QAC9B,OAAO,CAAC,QAAQ,KAAK,6CAAgC,EACrD;QACA,OAAO,OAAO,CAAC,MAAM,CACnB,iEAAiE,CAClE,CAAC;KACH;IAED,OAAO,IAAA,6BAAO,EACZ,GAAG,IAAA,8BAAQ,EAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,EAChD,OAAO,CACR,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QAClB,IAAI,OAAO,CAAC,WAAW,EAAE;YACvB,OAAO,QAAQ,CAAC;SACjB;QACD,MAAM,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC;QACrC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,OAA6B;YAChE,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACpB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,GAAG,EAAE,CAAC;aACxC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAxCD,kCAwCC","sourcesContent":["/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl, ISpatialReference, IPoint } from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_BULK_GEOCODING_URL,\n IEndpointOptions\n} from \"./helpers.js\";\n\n// It would be better if doc did not display these properties in alphabetical order\nexport interface IAddressBulk {\n /**\n * A unique id must be passed along for each individual address.\n */\n OBJECTID: number;\n address?: string;\n address2?: string;\n address3?: string;\n neighborhood?: string;\n city?: string;\n subregion?: string;\n /**\n * The World Geocoding Service considers US states regions.\n */\n region?: string;\n postal?: number;\n postalExt?: number;\n countryCode?: string;\n}\n\nexport interface IBulkGeocodeOptions extends IEndpointOptions {\n addresses: IAddressBulk[];\n}\n\nexport interface IBulkGeocodeResponse {\n spatialReference: ISpatialReference;\n locations: Array<{\n address: string;\n location?: IPoint; // candidates with a score of 0 wont include a location\n score: number;\n attributes: object;\n }>;\n}\n\n/**\n * ```js\n * import { bulkGeocode } from '@esri/arcgis-rest-geocoding';\n * import { ApplicationSession } from '@esri/arcgis-rest-auth';\n * //\n * const addresses = [\n * { \"OBJECTID\": 1, \"SingleLine\": \"380 New York Street 92373\" },\n * { \"OBJECTID\": 2, \"SingleLine\": \"1 World Way Los Angeles 90045\" }\n * ];\n * //\n * bulkGeocode({ addresses, authentication: session })\n * .then((response) => {\n * response.locations[0].location; // => { x: -117, y: 34, spatialReference: { wkid: 4326 } }\n * });\n * ```\n * Used to geocode a [batch](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-geocode-addresses.htm) of addresses.\n *\n * @param requestOptions - Request options to pass to the geocoder, including an array of addresses and authentication session.\n * @returns A Promise that will resolve with the data from the response. The spatial reference will be added to address locations unless `rawResponse: true` was passed.\n */\nexport function bulkGeocode(\n requestOptions: IBulkGeocodeOptions // must POST, which is the default\n): Promise<IBulkGeocodeResponse> {\n const options: IBulkGeocodeOptions = {\n endpoint: ARCGIS_ONLINE_BULK_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n options.params.addresses = {\n records: requestOptions.addresses.map((address) => {\n return { attributes: address };\n })\n };\n\n // the SAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n options.endpoint === ARCGIS_ONLINE_BULK_GEOCODING_URL\n ) {\n return Promise.reject(\n \"bulk geocoding using the ArcGIS service requires authentication\"\n );\n }\n\n return request(\n `${cleanUrl(options.endpoint)}/geocodeAddresses`,\n options\n ).then((response) => {\n if (options.rawResponse) {\n return response;\n }\n const sr = response.spatialReference;\n response.locations.forEach(function (address: { location: IPoint }) {\n if (address.location) {\n address.location.spatialReference = sr;\n }\n });\n return response;\n });\n}\n"]}
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
* Apache-2.0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.geocode = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var arcgis_1 = require("@terraformer/arcgis");
|
|
6
|
+
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
7
|
+
const helpers_js_1 = require("./helpers.js");
|
|
8
|
+
const arcgis_1 = require("@terraformer/arcgis");
|
|
10
9
|
/**
|
|
11
10
|
* ```js
|
|
12
11
|
* import { geocode } from '@esri/arcgis-rest-geocoding';
|
|
@@ -30,15 +29,15 @@ var arcgis_1 = require("@terraformer/arcgis");
|
|
|
30
29
|
* @returns A Promise that will resolve with address candidates for the request. The spatial reference will be added to candidate locations and extents unless `rawResponse: true` was passed.
|
|
31
30
|
*/
|
|
32
31
|
function geocode(address) {
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
let options = {};
|
|
33
|
+
let endpoint;
|
|
35
34
|
if (typeof address === "string") {
|
|
36
35
|
options.params = { singleLine: address };
|
|
37
|
-
endpoint =
|
|
36
|
+
endpoint = helpers_js_1.ARCGIS_ONLINE_GEOCODING_URL;
|
|
38
37
|
}
|
|
39
38
|
else {
|
|
40
|
-
endpoint = address.endpoint ||
|
|
41
|
-
options = arcgis_rest_request_1.appendCustomParams(address, [
|
|
39
|
+
endpoint = address.endpoint || helpers_js_1.ARCGIS_ONLINE_GEOCODING_URL;
|
|
40
|
+
options = (0, arcgis_rest_request_1.appendCustomParams)(address, [
|
|
42
41
|
"singleLine",
|
|
43
42
|
"address",
|
|
44
43
|
"address2",
|
|
@@ -52,14 +51,14 @@ function geocode(address) {
|
|
|
52
51
|
"countryCode",
|
|
53
52
|
"outFields",
|
|
54
53
|
"magicKey"
|
|
55
|
-
], { params:
|
|
54
|
+
], { params: Object.assign({}, address.params) });
|
|
56
55
|
}
|
|
57
56
|
// add spatialReference property to individual matches
|
|
58
|
-
return arcgis_rest_request_1.request(arcgis_rest_request_1.cleanUrl(endpoint)
|
|
57
|
+
return (0, arcgis_rest_request_1.request)(`${(0, arcgis_rest_request_1.cleanUrl)(endpoint)}/findAddressCandidates`, options).then((response) => {
|
|
59
58
|
if (typeof address !== "string" && address.rawResponse) {
|
|
60
59
|
return response;
|
|
61
60
|
}
|
|
62
|
-
|
|
61
|
+
const sr = response.spatialReference;
|
|
63
62
|
response.candidates.forEach(function (candidate) {
|
|
64
63
|
candidate.location.spatialReference = sr;
|
|
65
64
|
if (candidate.extent) {
|
|
@@ -68,19 +67,19 @@ function geocode(address) {
|
|
|
68
67
|
});
|
|
69
68
|
// geoJson
|
|
70
69
|
if (sr.wkid === 4326) {
|
|
71
|
-
|
|
70
|
+
const features = response.candidates.map((candidate) => {
|
|
72
71
|
return {
|
|
73
72
|
type: "Feature",
|
|
74
|
-
geometry: arcgis_1.arcgisToGeoJSON(candidate.location),
|
|
73
|
+
geometry: (0, arcgis_1.arcgisToGeoJSON)(candidate.location),
|
|
75
74
|
properties: Object.assign({
|
|
76
75
|
address: candidate.address,
|
|
77
|
-
score: candidate.score
|
|
78
|
-
}, candidate.attributes)
|
|
76
|
+
score: candidate.score
|
|
77
|
+
}, candidate.attributes)
|
|
79
78
|
};
|
|
80
79
|
});
|
|
81
80
|
response.geoJson = {
|
|
82
81
|
type: "FeatureCollection",
|
|
83
|
-
features
|
|
82
|
+
features
|
|
84
83
|
};
|
|
85
84
|
}
|
|
86
85
|
return response;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocode.js","sourceRoot":"","sources":["../../src/geocode.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAO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AI,KAAK,IAAI,EAAE;YACpB,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAc,EAAE,EAAE;gBAC1D,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,IAAA,wBAAe,EAAC,SAAS,CAAC,QAAQ,CAAC;oBAC7C,UAAU,EAAE,MAAM,CAAC,MAAM,CACvB;wBACE,OAAO,EAAE,SAAS,CAAC,OAAO;wBAC1B,KAAK,EAAE,SAAS,CAAC,KAAK;qBACvB,EACD,SAAS,CAAC,UAAU,CACrB;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,OAAO,GAAG;gBACjB,IAAI,EAAE,mBAAmB;gBACzB,QAAQ;aACT,CAAC;SACH;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC;AA1ED,0BA0EC","sourcesContent":["/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n IExtent,\n ISpatialReference,\n IPoint\n} from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IGeocodeOptions extends IEndpointOptions {\n /**\n * use this if all your address info is contained in a single string.\n */\n singleLine?: string;\n address?: string;\n address2?: string;\n address3?: string;\n neighborhood?: string;\n city?: string;\n subregion?: string;\n outFields?: \"*\" | string[];\n /**\n * The World Geocoding Service expects US states to be passed in as a 'region'.\n */\n region?: string;\n postal?: number;\n postalExt?: number;\n countryCode?: string;\n /**\n * You can create an autocomplete experience by making a call to suggest with partial text and then passing through the magicKey and complete address that are returned to geocode.\n *\n * ```js\n * import { suggest, geocode } from '@esri/arcgis-rest-geocoding';\n *\n * suggest(\"LAX\")\n * .then((response) => {\n * geocode({\n * singleLine: response.suggestions[1].text,\n * magicKey: response.suggestions[0].magicKey\n * })\n * })\n * ```\n */\n magicKey?: string;\n}\n\nexport interface IGeocodeResponse {\n spatialReference: ISpatialReference;\n candidates: Array<{\n address: string;\n location: IPoint;\n extent?: IExtent;\n score: number;\n attributes: object;\n }>;\n geoJson?: {\n type: string;\n features: Array<{\n type: string;\n geometry: object;\n properties: any;\n }>;\n };\n}\n\n/**\n * ```js\n * import { geocode } from '@esri/arcgis-rest-geocoding';\n * //\n * geocode(\"LAX\")\n * .then((response) => {\n * response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: ... }\n * });\n * //\n * geocode({\n * address: \"1600 Pennsylvania Ave\",\n * postal: 20500,\n * countryCode: \"USA\"\n * })\n * .then((response) => {\n * response.candidates[1].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... }\n * });\n * ```\n * Used to determine the location of a single address or point of interest. See the [REST Documentation](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) for more information.\n * @param address String representing the address or point of interest or RequestOptions to pass to the endpoint.\n * @returns A Promise that will resolve with address candidates for the request. The spatial reference will be added to candidate locations and extents unless `rawResponse: true` was passed.\n */\nexport function geocode(\n address: string | IGeocodeOptions\n): Promise<IGeocodeResponse> {\n let options: IGeocodeOptions = {};\n let endpoint: string;\n\n if (typeof address === \"string\") {\n options.params = { singleLine: address };\n endpoint = ARCGIS_ONLINE_GEOCODING_URL;\n } else {\n endpoint = address.endpoint || ARCGIS_ONLINE_GEOCODING_URL;\n options = appendCustomParams<IGeocodeOptions>(\n address,\n [\n \"singleLine\",\n \"address\",\n \"address2\",\n \"address3\",\n \"neighborhood\",\n \"city\",\n \"subregion\",\n \"region\",\n \"postal\",\n \"postalExt\",\n \"countryCode\",\n \"outFields\",\n \"magicKey\"\n ],\n { params: { ...address.params } }\n );\n }\n\n // add spatialReference property to individual matches\n return request(`${cleanUrl(endpoint)}/findAddressCandidates`, options).then(\n (response) => {\n if (typeof address !== \"string\" && address.rawResponse) {\n return response;\n }\n const sr: ISpatialReference = response.spatialReference;\n response.candidates.forEach(function (candidate: {\n location: IPoint;\n extent?: IExtent;\n }) {\n candidate.location.spatialReference = sr;\n if (candidate.extent) {\n candidate.extent.spatialReference = sr;\n }\n });\n\n // geoJson\n if (sr.wkid === 4326) {\n const features = response.candidates.map((candidate: any) => {\n return {\n type: \"Feature\",\n geometry: arcgisToGeoJSON(candidate.location),\n properties: Object.assign(\n {\n address: candidate.address,\n score: candidate.score\n },\n candidate.attributes\n )\n };\n });\n\n response.geoJson = {\n type: \"FeatureCollection\",\n features\n };\n }\n\n return response;\n }\n );\n}\n"]}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* Apache-2.0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.getGeocodeService = exports.ARCGIS_ONLINE_BULK_GEOCODING_URL = exports.ARCGIS_ONLINE_GEOCODING_URL = void 0;
|
|
6
|
-
|
|
7
|
-
var arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
6
|
+
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
8
7
|
// https always
|
|
9
8
|
exports.ARCGIS_ONLINE_GEOCODING_URL = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
|
|
10
9
|
exports.ARCGIS_ONLINE_BULK_GEOCODING_URL = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
|
|
@@ -24,9 +23,9 @@ exports.ARCGIS_ONLINE_BULK_GEOCODING_URL = "https://geocode.arcgis.com/arcgis/re
|
|
|
24
23
|
* @returns A Promise that will resolve with the data from the response.
|
|
25
24
|
*/
|
|
26
25
|
function getGeocodeService(requestOptions) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return arcgis_rest_request_1.request(url, options);
|
|
26
|
+
const url = (requestOptions && requestOptions.endpoint) || exports.ARCGIS_ONLINE_GEOCODING_URL;
|
|
27
|
+
const options = Object.assign({ httpMethod: "GET", maxUrlLength: 2000 }, requestOptions);
|
|
28
|
+
return (0, arcgis_rest_request_1.request)(url, options);
|
|
30
29
|
}
|
|
31
30
|
exports.getGeocodeService = getGeocodeService;
|
|
32
31
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAAqE;AAErE,eAAe;AACF,QAAA,2BAA2B,GACtC,0EAA0E,CAAC;AAChE,QAAA,gCAAgC,GAC3C,sEAAsE,CAAC;AAkBzE;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB,CAC/B,cAAiC;IAEjC,MAAM,GAAG,GACP,CAAC,cAAc,IAAI,cAAc,CAAC,QAAQ,CAAC,IAAI,mCAA2B,CAAC;IAE7E,MAAM,OAAO,mBACX,UAAU,EAAE,KAAK,EACjB,YAAY,EAAE,IAAI,IACf,cAAc,CAClB,CAAC;IAEF,OAAO,IAAA,6BAAO,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC;AAbD,8CAaC","sourcesContent":["/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, IRequestOptions } from \"@esri/arcgis-rest-request\";\n\n// https always\nexport const ARCGIS_ONLINE_GEOCODING_URL =\n \"https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/\";\nexport const ARCGIS_ONLINE_BULK_GEOCODING_URL =\n \"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/\";\n\n// nice to have: verify custom endpoints contain 'GeocodeServer' and end in a '/'\nexport interface IEndpointOptions extends IRequestOptions {\n /**\n * Any ArcGIS Geocoding service (example: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Locators/SanDiego/GeocodeServer )\n */\n endpoint?: string;\n}\n\nexport interface IGetGeocodeServiceResponse {\n currentVersion: number;\n serviceDescription: string;\n addressFields: any[];\n countries: string[];\n capabilities: string;\n}\n\n/**\n * Used to fetch metadata from a geocoding service.\n *\n * ```js\n * import { getGeocoderServiceInfo } from '@esri/arcgis-rest-geocoding';\n *\n * getGeocoderServiceInfo()\n * .then((response) => {\n * response.serviceDescription; // => 'World Geocoder'\n * });\n * ```\n *\n * @param requestOptions - Request options can contain a custom geocoding service to fetch metadata from.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function getGeocodeService(\n requestOptions?: IEndpointOptions\n): Promise<IGetGeocodeServiceResponse> {\n const url =\n (requestOptions && requestOptions.endpoint) || ARCGIS_ONLINE_GEOCODING_URL;\n\n const options: IEndpointOptions = {\n httpMethod: \"GET\",\n maxUrlLength: 2000,\n ...requestOptions\n };\n\n return request(url, options);\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
3
|
+
* Apache-2.0 */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./geocode.js"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./suggest.js"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./reverse.js"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./bulk.js"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./helpers.js"), exports);
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,4DAA6B;AAC7B,4DAA6B;AAC7B,4DAA6B;AAC7B,yDAA0B;AAC1B,4DAA6B","sourcesContent":["/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./geocode.js\";\nexport * from \"./suggest.js\";\nexport * from \"./reverse.js\";\nexport * from \"./bulk.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 IPoint,\n ILocation,\n IExtent,\n ISpatialReference\n} from \"@esri/arcgis-rest-request\";\n"]}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Apache-2.0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.reverseGeocode = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var helpers_1 = require("./helpers");
|
|
6
|
+
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
7
|
+
const helpers_js_1 = require("./helpers.js");
|
|
9
8
|
function isLocationArray(coords) {
|
|
10
9
|
return (coords.length === 2 ||
|
|
11
10
|
coords.length === 3);
|
|
@@ -35,7 +34,7 @@ function isLocation(coords) {
|
|
|
35
34
|
* @returns A Promise that will resolve with the data from the response.
|
|
36
35
|
*/
|
|
37
36
|
function reverseGeocode(coords, requestOptions) {
|
|
38
|
-
|
|
37
|
+
const options = Object.assign({ endpoint: helpers_js_1.ARCGIS_ONLINE_GEOCODING_URL, params: {} }, requestOptions);
|
|
39
38
|
if (isLocationArray(coords)) {
|
|
40
39
|
options.params.location = coords.join();
|
|
41
40
|
}
|
|
@@ -51,10 +50,10 @@ function reverseGeocode(coords, requestOptions) {
|
|
|
51
50
|
// if input is a point, we can pass it straight through, with or without a spatial reference
|
|
52
51
|
options.params.location = coords;
|
|
53
52
|
}
|
|
54
|
-
return arcgis_rest_request_1.request(arcgis_rest_request_1.cleanUrl(options.endpoint)
|
|
53
|
+
return (0, arcgis_rest_request_1.request)(`${(0, arcgis_rest_request_1.cleanUrl)(options.endpoint)}/reverseGeocode`, options);
|
|
55
54
|
}
|
|
56
55
|
exports.reverseGeocode = reverseGeocode;
|
|
57
56
|
exports.default = {
|
|
58
|
-
reverseGeocode
|
|
57
|
+
reverseGeocode
|
|
59
58
|
};
|
|
60
59
|
//#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O,CAAC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAC1E,CAAC;AAzBD,wCAyBC;AAED,kBAAe;IACb,cAAc;CACf,CAAC","sourcesContent":["/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl, IPoint, ILocation } from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nexport interface IReverseGeocodeResponse {\n address: {\n [key: string]: any;\n };\n location: IPoint;\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 * ```js\n * import { reverseGeocode } from '@esri/arcgis-rest-geocoding';\n * //\n * reverseGeocode([-118.409,33.943 ]) // long, lat\n * .then((response) => {\n * response.address.PlaceName; // => \"LA Airport\"\n * });\n * // or\n * reverseGeocode({ long: -118.409, lat: 33.943 })\n * reverseGeocode({ latitude: 33.943, latitude: -118.409 })\n * reverseGeocode({ x: -118.409, y: 33.9425 }) // wgs84 is assumed\n * reverseGeocode({ x: -13181226, y: 4021085, spatialReference: { wkid: 3857 })\n * ```\n * Used to determine the address of a [location](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-reverse-geocode.htm).\n *\n * @param coordinates - the location you'd like to associate an address with.\n * @param requestOptions - Additional options for the request including authentication.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function reverseGeocode(\n coords: IPoint | ILocation | [number, number],\n requestOptions?: IEndpointOptions\n): Promise<IReverseGeocodeResponse> {\n const options: IEndpointOptions = {\n endpoint: ARCGIS_ONLINE_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n if (isLocationArray(coords)) {\n options.params.location = coords.join();\n } else if (isLocation(coords)) {\n if (coords.lat) {\n options.params.location = coords.long + \",\" + coords.lat;\n }\n if (coords.latitude) {\n options.params.location = coords.longitude + \",\" + coords.latitude;\n }\n } else {\n // if input is a point, we can pass it straight through, with or without a spatial reference\n options.params.location = coords;\n }\n\n return request(`${cleanUrl(options.endpoint)}/reverseGeocode`, options);\n}\n\nexport default {\n reverseGeocode\n};\n"]}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Apache-2.0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.suggest = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var helpers_1 = require("./helpers");
|
|
6
|
+
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
7
|
+
const helpers_js_1 = require("./helpers.js");
|
|
9
8
|
/**
|
|
10
9
|
* ```js
|
|
11
10
|
* import { suggest } from '@esri/arcgis-rest-geocoding';
|
|
@@ -19,12 +18,12 @@ var helpers_1 = require("./helpers");
|
|
|
19
18
|
* @returns A Promise that will resolve with the data from the response.
|
|
20
19
|
*/
|
|
21
20
|
function suggest(partialText, requestOptions) {
|
|
22
|
-
|
|
21
|
+
const options = Object.assign({ endpoint: helpers_js_1.ARCGIS_ONLINE_GEOCODING_URL, params: {} }, requestOptions);
|
|
23
22
|
options.params.text = partialText;
|
|
24
|
-
return arcgis_rest_request_1.request(arcgis_rest_request_1.cleanUrl(options.endpoint)
|
|
23
|
+
return (0, arcgis_rest_request_1.request)(`${(0, arcgis_rest_request_1.cleanUrl)(options.endpoint)}/suggest`, options);
|
|
25
24
|
}
|
|
26
25
|
exports.suggest = suggest;
|
|
27
26
|
exports.default = {
|
|
28
|
-
suggest
|
|
27
|
+
suggest
|
|
29
28
|
};
|
|
30
29
|
//# sourceMappingURL=suggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suggest.js","sourceRoot":"","sources":["../../src/suggest.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAA8D;AAE9D,6CAA6E;AAU7E;;;;;;;;;;;GAWG;AACH,SAAgB,OAAO,CACrB,WAAmB,EACnB,cAAiC;IAEjC,MAAM,OAAO,mBACX,QAAQ,EAAE,wCAA2B,EACrC,MAAM,EAAE,EAAE,IACP,cAAc,CAClB,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,IAAI,GAAG,WAAW,CAAC;IAElC,OAAO,IAAA,6BAAO,EAAC,GAAG,IAAA,8BAAQ,EAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC;AAbD,0BAaC;AAED,kBAAe;IACb,OAAO;CACR,CAAC","sourcesContent":["/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl } from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nexport interface ISuggestResponse {\n suggestions: Array<{\n text: string;\n magicKey: string;\n isCollection: boolean;\n }>;\n}\n\n/**\n * ```js\n * import { suggest } from '@esri/arcgis-rest-geocoding';\n * //\n * suggest(\"Starb\")\n * .then(response) // response.text === \"Starbucks\"\n * ```\n * Used to return a placename [suggestion](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm) for a partial string.\n *\n * @param requestOptions - Options for the request including authentication and other optional parameters.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function suggest(\n partialText: string,\n requestOptions?: IEndpointOptions\n): Promise<ISuggestResponse> {\n const options: IEndpointOptions = {\n endpoint: ARCGIS_ONLINE_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n options.params.text = partialText;\n\n return request(`${cleanUrl(options.endpoint)}/suggest`, options);\n}\n\nexport default {\n suggest\n};\n"]}
|
package/dist/esm/bulk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ISpatialReference, IPoint } from "@esri/arcgis-rest-
|
|
2
|
-
import { IEndpointOptions } from "./helpers";
|
|
1
|
+
import { ISpatialReference, IPoint } from "@esri/arcgis-rest-request";
|
|
2
|
+
import { IEndpointOptions } from "./helpers.js";
|
|
3
3
|
export interface IAddressBulk {
|
|
4
4
|
/**
|
|
5
5
|
* A unique id must be passed along for each individual address.
|
package/dist/esm/bulk.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
|
2
2
|
* Apache-2.0 */
|
|
3
|
-
import { __assign } from "tslib";
|
|
4
3
|
import { request, cleanUrl } from "@esri/arcgis-rest-request";
|
|
5
|
-
import { ARCGIS_ONLINE_BULK_GEOCODING_URL } from "./helpers";
|
|
4
|
+
import { ARCGIS_ONLINE_BULK_GEOCODING_URL } from "./helpers.js";
|
|
6
5
|
/**
|
|
7
6
|
* ```js
|
|
8
7
|
* import { bulkGeocode } from '@esri/arcgis-rest-geocoding';
|
|
@@ -25,9 +24,9 @@ import { ARCGIS_ONLINE_BULK_GEOCODING_URL } from "./helpers";
|
|
|
25
24
|
*/
|
|
26
25
|
export function bulkGeocode(requestOptions // must POST, which is the default
|
|
27
26
|
) {
|
|
28
|
-
|
|
27
|
+
const options = Object.assign({ endpoint: ARCGIS_ONLINE_BULK_GEOCODING_URL, params: {} }, requestOptions);
|
|
29
28
|
options.params.addresses = {
|
|
30
|
-
records: requestOptions.addresses.map(
|
|
29
|
+
records: requestOptions.addresses.map((address) => {
|
|
31
30
|
return { attributes: address };
|
|
32
31
|
})
|
|
33
32
|
};
|
|
@@ -36,11 +35,11 @@ export function bulkGeocode(requestOptions // must POST, which is the default
|
|
|
36
35
|
options.endpoint === ARCGIS_ONLINE_BULK_GEOCODING_URL) {
|
|
37
36
|
return Promise.reject("bulk geocoding using the ArcGIS service requires authentication");
|
|
38
37
|
}
|
|
39
|
-
return request(cleanUrl(options.endpoint)
|
|
38
|
+
return request(`${cleanUrl(options.endpoint)}/geocodeAddresses`, options).then((response) => {
|
|
40
39
|
if (options.rawResponse) {
|
|
41
40
|
return response;
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
const sr = response.spatialReference;
|
|
44
43
|
response.locations.forEach(function (address) {
|
|
45
44
|
if (address.location) {
|
|
46
45
|
address.location.spatialReference = sr;
|
package/dist/esm/bulk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulk.js","sourceRoot":"","sources":["../../src/bulk.ts"],"names":[],"mappings":"AAAA;gBACgB
|
|
1
|
+
{"version":3,"file":"bulk.js","sourceRoot":"","sources":["../../src/bulk.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAA6B,MAAM,2BAA2B,CAAC;AAEzF,OAAO,EACL,gCAAgC,EAEjC,MAAM,cAAc,CAAC;AAqCtB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,WAAW,CACzB,cAAmC,CAAC,kCAAkC;;IAEtE,MAAM,OAAO,mBACX,QAAQ,EAAE,gCAAgC,EAC1C,MAAM,EAAE,EAAE,IACP,cAAc,CAClB,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,SAAS,GAAG;QACzB,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YAChD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QACjC,CAAC,CAAC;KACH,CAAC;IAEF,sDAAsD;IACtD,IACE,CAAC,cAAc,CAAC,cAAc;QAC9B,OAAO,CAAC,QAAQ,KAAK,gCAAgC,EACrD;QACA,OAAO,OAAO,CAAC,MAAM,CACnB,iEAAiE,CAClE,CAAC;KACH;IAED,OAAO,OAAO,CACZ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,EAChD,OAAO,CACR,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QAClB,IAAI,OAAO,CAAC,WAAW,EAAE;YACvB,OAAO,QAAQ,CAAC;SACjB;QACD,MAAM,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC;QACrC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,OAA6B;YAChE,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACpB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,GAAG,EAAE,CAAC;aACxC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, cleanUrl, ISpatialReference, IPoint } from \"@esri/arcgis-rest-request\";\n\nimport {\n ARCGIS_ONLINE_BULK_GEOCODING_URL,\n IEndpointOptions\n} from \"./helpers.js\";\n\n// It would be better if doc did not display these properties in alphabetical order\nexport interface IAddressBulk {\n /**\n * A unique id must be passed along for each individual address.\n */\n OBJECTID: number;\n address?: string;\n address2?: string;\n address3?: string;\n neighborhood?: string;\n city?: string;\n subregion?: string;\n /**\n * The World Geocoding Service considers US states regions.\n */\n region?: string;\n postal?: number;\n postalExt?: number;\n countryCode?: string;\n}\n\nexport interface IBulkGeocodeOptions extends IEndpointOptions {\n addresses: IAddressBulk[];\n}\n\nexport interface IBulkGeocodeResponse {\n spatialReference: ISpatialReference;\n locations: Array<{\n address: string;\n location?: IPoint; // candidates with a score of 0 wont include a location\n score: number;\n attributes: object;\n }>;\n}\n\n/**\n * ```js\n * import { bulkGeocode } from '@esri/arcgis-rest-geocoding';\n * import { ApplicationSession } from '@esri/arcgis-rest-auth';\n * //\n * const addresses = [\n * { \"OBJECTID\": 1, \"SingleLine\": \"380 New York Street 92373\" },\n * { \"OBJECTID\": 2, \"SingleLine\": \"1 World Way Los Angeles 90045\" }\n * ];\n * //\n * bulkGeocode({ addresses, authentication: session })\n * .then((response) => {\n * response.locations[0].location; // => { x: -117, y: 34, spatialReference: { wkid: 4326 } }\n * });\n * ```\n * Used to geocode a [batch](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-geocode-addresses.htm) of addresses.\n *\n * @param requestOptions - Request options to pass to the geocoder, including an array of addresses and authentication session.\n * @returns A Promise that will resolve with the data from the response. The spatial reference will be added to address locations unless `rawResponse: true` was passed.\n */\nexport function bulkGeocode(\n requestOptions: IBulkGeocodeOptions // must POST, which is the default\n): Promise<IBulkGeocodeResponse> {\n const options: IBulkGeocodeOptions = {\n endpoint: ARCGIS_ONLINE_BULK_GEOCODING_URL,\n params: {},\n ...requestOptions\n };\n\n options.params.addresses = {\n records: requestOptions.addresses.map((address) => {\n return { attributes: address };\n })\n };\n\n // the SAS service does not support anonymous requests\n if (\n !requestOptions.authentication &&\n options.endpoint === ARCGIS_ONLINE_BULK_GEOCODING_URL\n ) {\n return Promise.reject(\n \"bulk geocoding using the ArcGIS service requires authentication\"\n );\n }\n\n return request(\n `${cleanUrl(options.endpoint)}/geocodeAddresses`,\n options\n ).then((response) => {\n if (options.rawResponse) {\n return response;\n }\n const sr = response.spatialReference;\n response.locations.forEach(function (address: { location: IPoint }) {\n if (address.location) {\n address.location.spatialReference = sr;\n }\n });\n return response;\n });\n}\n"]}
|
package/dist/esm/geocode.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IExtent, ISpatialReference, IPoint } from "@esri/arcgis-rest-
|
|
2
|
-
import { IEndpointOptions } from "./helpers";
|
|
1
|
+
import { IExtent, ISpatialReference, IPoint } from "@esri/arcgis-rest-request";
|
|
2
|
+
import { IEndpointOptions } from "./helpers.js";
|
|
3
3
|
export interface IGeocodeOptions extends IEndpointOptions {
|
|
4
4
|
/**
|
|
5
5
|
* use this if all your address info is contained in a single string.
|
|
@@ -21,8 +21,10 @@ export interface IGeocodeOptions extends IEndpointOptions {
|
|
|
21
21
|
countryCode?: string;
|
|
22
22
|
/**
|
|
23
23
|
* You can create an autocomplete experience by making a call to suggest with partial text and then passing through the magicKey and complete address that are returned to geocode.
|
|
24
|
+
*
|
|
24
25
|
* ```js
|
|
25
26
|
* import { suggest, geocode } from '@esri/arcgis-rest-geocoding';
|
|
27
|
+
*
|
|
26
28
|
* suggest("LAX")
|
|
27
29
|
* .then((response) => {
|
|
28
30
|
* geocode({
|
package/dist/esm/geocode.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
|
2
2
|
* Apache-2.0 */
|
|
3
|
-
import { __assign } from "tslib";
|
|
4
3
|
import { request, cleanUrl, appendCustomParams } from "@esri/arcgis-rest-request";
|
|
5
|
-
import { ARCGIS_ONLINE_GEOCODING_URL } from "./helpers";
|
|
4
|
+
import { ARCGIS_ONLINE_GEOCODING_URL } from "./helpers.js";
|
|
6
5
|
import { arcgisToGeoJSON } from "@terraformer/arcgis";
|
|
7
6
|
/**
|
|
8
7
|
* ```js
|
|
@@ -27,8 +26,8 @@ import { arcgisToGeoJSON } from "@terraformer/arcgis";
|
|
|
27
26
|
* @returns A Promise that will resolve with address candidates for the request. The spatial reference will be added to candidate locations and extents unless `rawResponse: true` was passed.
|
|
28
27
|
*/
|
|
29
28
|
export function geocode(address) {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
let options = {};
|
|
30
|
+
let endpoint;
|
|
32
31
|
if (typeof address === "string") {
|
|
33
32
|
options.params = { singleLine: address };
|
|
34
33
|
endpoint = ARCGIS_ONLINE_GEOCODING_URL;
|
|
@@ -49,14 +48,14 @@ export function geocode(address) {
|
|
|
49
48
|
"countryCode",
|
|
50
49
|
"outFields",
|
|
51
50
|
"magicKey"
|
|
52
|
-
], { params:
|
|
51
|
+
], { params: Object.assign({}, address.params) });
|
|
53
52
|
}
|
|
54
53
|
// add spatialReference property to individual matches
|
|
55
|
-
return request(cleanUrl(endpoint)
|
|
54
|
+
return request(`${cleanUrl(endpoint)}/findAddressCandidates`, options).then((response) => {
|
|
56
55
|
if (typeof address !== "string" && address.rawResponse) {
|
|
57
56
|
return response;
|
|
58
57
|
}
|
|
59
|
-
|
|
58
|
+
const sr = response.spatialReference;
|
|
60
59
|
response.candidates.forEach(function (candidate) {
|
|
61
60
|
candidate.location.spatialReference = sr;
|
|
62
61
|
if (candidate.extent) {
|
|
@@ -65,19 +64,19 @@ export function geocode(address) {
|
|
|
65
64
|
});
|
|
66
65
|
// geoJson
|
|
67
66
|
if (sr.wkid === 4326) {
|
|
68
|
-
|
|
67
|
+
const features = response.candidates.map((candidate) => {
|
|
69
68
|
return {
|
|
70
69
|
type: "Feature",
|
|
71
70
|
geometry: arcgisToGeoJSON(candidate.location),
|
|
72
71
|
properties: Object.assign({
|
|
73
72
|
address: candidate.address,
|
|
74
|
-
score: candidate.score
|
|
75
|
-
}, candidate.attributes)
|
|
73
|
+
score: candidate.score
|
|
74
|
+
}, candidate.attributes)
|
|
76
75
|
};
|
|
77
76
|
});
|
|
78
77
|
response.geoJson = {
|
|
79
78
|
type: "FeatureCollection",
|
|
80
|
-
features
|
|
79
|
+
features
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
return response;
|
package/dist/esm/geocode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geocode.js","sourceRoot":"","sources":["../../src/geocode.ts"],"names":[],"mappings":"AAAA;gBACgB
|
|
1
|
+
{"version":3,"file":"geocode.js","sourceRoot":"","sources":["../../src/geocode.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EACL,OAAO,EACP,QAAQ,EACR,kBAAkB,EAInB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,2BAA2B,EAAoB,MAAM,cAAc,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA0DtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,OAAO,CACrB,OAAiC;IAEjC,IAAI,OAAO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S;oBACf,QAAQ,EAAE,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC;oBAC7C,UAAU,EAAE,MAAM,CAAC,MAAM,CACvB;wBACE,OAAO,EAAE,SAAS,CAAC,OAAO;wBAC1B,KAAK,EAAE,SAAS,CAAC,KAAK;qBACvB,EACD,SAAS,CAAC,UAAU,CACrB;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,OAAO,GAAG;gBACjB,IAAI,EAAE,mBAAmB;gBACzB,QAAQ;aACT,CAAC;SACH;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n request,\n cleanUrl,\n appendCustomParams,\n IExtent,\n ISpatialReference,\n IPoint\n} from \"@esri/arcgis-rest-request\";\n\nimport { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from \"./helpers.js\";\n\nimport { arcgisToGeoJSON } from \"@terraformer/arcgis\";\n\nexport interface IGeocodeOptions extends IEndpointOptions {\n /**\n * use this if all your address info is contained in a single string.\n */\n singleLine?: string;\n address?: string;\n address2?: string;\n address3?: string;\n neighborhood?: string;\n city?: string;\n subregion?: string;\n outFields?: \"*\" | string[];\n /**\n * The World Geocoding Service expects US states to be passed in as a 'region'.\n */\n region?: string;\n postal?: number;\n postalExt?: number;\n countryCode?: string;\n /**\n * You can create an autocomplete experience by making a call to suggest with partial text and then passing through the magicKey and complete address that are returned to geocode.\n *\n * ```js\n * import { suggest, geocode } from '@esri/arcgis-rest-geocoding';\n *\n * suggest(\"LAX\")\n * .then((response) => {\n * geocode({\n * singleLine: response.suggestions[1].text,\n * magicKey: response.suggestions[0].magicKey\n * })\n * })\n * ```\n */\n magicKey?: string;\n}\n\nexport interface IGeocodeResponse {\n spatialReference: ISpatialReference;\n candidates: Array<{\n address: string;\n location: IPoint;\n extent?: IExtent;\n score: number;\n attributes: object;\n }>;\n geoJson?: {\n type: string;\n features: Array<{\n type: string;\n geometry: object;\n properties: any;\n }>;\n };\n}\n\n/**\n * ```js\n * import { geocode } from '@esri/arcgis-rest-geocoding';\n * //\n * geocode(\"LAX\")\n * .then((response) => {\n * response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: ... }\n * });\n * //\n * geocode({\n * address: \"1600 Pennsylvania Ave\",\n * postal: 20500,\n * countryCode: \"USA\"\n * })\n * .then((response) => {\n * response.candidates[1].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... }\n * });\n * ```\n * Used to determine the location of a single address or point of interest. See the [REST Documentation](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) for more information.\n * @param address String representing the address or point of interest or RequestOptions to pass to the endpoint.\n * @returns A Promise that will resolve with address candidates for the request. The spatial reference will be added to candidate locations and extents unless `rawResponse: true` was passed.\n */\nexport function geocode(\n address: string | IGeocodeOptions\n): Promise<IGeocodeResponse> {\n let options: IGeocodeOptions = {};\n let endpoint: string;\n\n if (typeof address === \"string\") {\n options.params = { singleLine: address };\n endpoint = ARCGIS_ONLINE_GEOCODING_URL;\n } else {\n endpoint = address.endpoint || ARCGIS_ONLINE_GEOCODING_URL;\n options = appendCustomParams<IGeocodeOptions>(\n address,\n [\n \"singleLine\",\n \"address\",\n \"address2\",\n \"address3\",\n \"neighborhood\",\n \"city\",\n \"subregion\",\n \"region\",\n \"postal\",\n \"postalExt\",\n \"countryCode\",\n \"outFields\",\n \"magicKey\"\n ],\n { params: { ...address.params } }\n );\n }\n\n // add spatialReference property to individual matches\n return request(`${cleanUrl(endpoint)}/findAddressCandidates`, options).then(\n (response) => {\n if (typeof address !== \"string\" && address.rawResponse) {\n return response;\n }\n const sr: ISpatialReference = response.spatialReference;\n response.candidates.forEach(function (candidate: {\n location: IPoint;\n extent?: IExtent;\n }) {\n candidate.location.spatialReference = sr;\n if (candidate.extent) {\n candidate.extent.spatialReference = sr;\n }\n });\n\n // geoJson\n if (sr.wkid === 4326) {\n const features = response.candidates.map((candidate: any) => {\n return {\n type: \"Feature\",\n geometry: arcgisToGeoJSON(candidate.location),\n properties: Object.assign(\n {\n address: candidate.address,\n score: candidate.score\n },\n candidate.attributes\n )\n };\n });\n\n response.geoJson = {\n type: \"FeatureCollection\",\n features\n };\n }\n\n return response;\n }\n );\n}\n"]}
|
package/dist/esm/helpers.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
|
|
2
2
|
* Apache-2.0 */
|
|
3
|
-
import { __assign } from "tslib";
|
|
4
3
|
import { request } from "@esri/arcgis-rest-request";
|
|
5
4
|
// https always
|
|
6
|
-
export
|
|
7
|
-
export
|
|
5
|
+
export const ARCGIS_ONLINE_GEOCODING_URL = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
|
|
6
|
+
export const ARCGIS_ONLINE_BULK_GEOCODING_URL = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
|
|
8
7
|
/**
|
|
9
8
|
* Used to fetch metadata from a geocoding service.
|
|
10
9
|
*
|
|
@@ -21,8 +20,8 @@ export var ARCGIS_ONLINE_BULK_GEOCODING_URL = "https://geocode.arcgis.com/arcgis
|
|
|
21
20
|
* @returns A Promise that will resolve with the data from the response.
|
|
22
21
|
*/
|
|
23
22
|
export function getGeocodeService(requestOptions) {
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const url = (requestOptions && requestOptions.endpoint) || ARCGIS_ONLINE_GEOCODING_URL;
|
|
24
|
+
const options = Object.assign({ httpMethod: "GET", maxUrlLength: 2000 }, requestOptions);
|
|
26
25
|
return request(url, options);
|
|
27
26
|
}
|
|
28
27
|
//# sourceMappingURL=helpers.js.map
|
package/dist/esm/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA;gBACgB
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EAAE,OAAO,EAAmB,MAAM,2BAA2B,CAAC;AAErE,eAAe;AACf,MAAM,CAAC,MAAM,2BAA2B,GACtC,0EAA0E,CAAC;AAC7E,MAAM,CAAC,MAAM,gCAAgC,GAC3C,sEAAsE,CAAC;AAkBzE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC/B,cAAiC;IAEjC,MAAM,GAAG,GACP,CAAC,cAAc,IAAI,cAAc,CAAC,QAAQ,CAAC,IAAI,2BAA2B,CAAC;IAE7E,MAAM,OAAO,mBACX,UAAU,EAAE,KAAK,EACjB,YAAY,EAAE,IAAI,IACf,cAAc,CAClB,CAAC;IAEF,OAAO,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, IRequestOptions } from \"@esri/arcgis-rest-request\";\n\n// https always\nexport const ARCGIS_ONLINE_GEOCODING_URL =\n \"https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/\";\nexport const ARCGIS_ONLINE_BULK_GEOCODING_URL =\n \"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/\";\n\n// nice to have: verify custom endpoints contain 'GeocodeServer' and end in a '/'\nexport interface IEndpointOptions extends IRequestOptions {\n /**\n * Any ArcGIS Geocoding service (example: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Locators/SanDiego/GeocodeServer )\n */\n endpoint?: string;\n}\n\nexport interface IGetGeocodeServiceResponse {\n currentVersion: number;\n serviceDescription: string;\n addressFields: any[];\n countries: string[];\n capabilities: string;\n}\n\n/**\n * Used to fetch metadata from a geocoding service.\n *\n * ```js\n * import { getGeocoderServiceInfo } from '@esri/arcgis-rest-geocoding';\n *\n * getGeocoderServiceInfo()\n * .then((response) => {\n * response.serviceDescription; // => 'World Geocoder'\n * });\n * ```\n *\n * @param requestOptions - Request options can contain a custom geocoding service to fetch metadata from.\n * @returns A Promise that will resolve with the data from the response.\n */\nexport function getGeocodeService(\n requestOptions?: IEndpointOptions\n): Promise<IGetGeocodeServiceResponse> {\n const url =\n (requestOptions && requestOptions.endpoint) || ARCGIS_ONLINE_GEOCODING_URL;\n\n const options: IEndpointOptions = {\n httpMethod: \"GET\",\n maxUrlLength: 2000,\n ...requestOptions\n };\n\n return request(url, options);\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./geocode";
|
|
2
|
-
export * from "./suggest";
|
|
3
|
-
export * from "./reverse";
|
|
4
|
-
export * from "./bulk";
|
|
5
|
-
export * from "./helpers";
|
|
6
|
-
export { IPoint, ILocation, IExtent, ISpatialReference } from "@esri/arcgis-rest-
|
|
1
|
+
export * from "./geocode.js";
|
|
2
|
+
export * from "./suggest.js";
|
|
3
|
+
export * from "./reverse.js";
|
|
4
|
+
export * from "./bulk.js";
|
|
5
|
+
export * from "./helpers.js";
|
|
6
|
+
export type { IPoint, ILocation, IExtent, ISpatialReference } from "@esri/arcgis-rest-request";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
2
2
|
* Apache-2.0 */
|
|
3
|
-
export * from "./geocode";
|
|
4
|
-
export * from "./suggest";
|
|
5
|
-
export * from "./reverse";
|
|
6
|
-
export * from "./bulk";
|
|
7
|
-
export * from "./helpers";
|
|
3
|
+
export * from "./geocode.js";
|
|
4
|
+
export * from "./suggest.js";
|
|
5
|
+
export * from "./reverse.js";
|
|
6
|
+
export * from "./bulk.js";
|
|
7
|
+
export * from "./helpers.js";
|
|
8
8
|
//# sourceMappingURL=index.js.map
|