@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
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-geocoding
|
|
9
9
|
[travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square
|
|
10
10
|
[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js
|
|
11
|
-
[gzip-image]: https://img.badgesize.io/https://unpkg.com/@esri/arcgis-rest-geocoding/dist/
|
|
11
|
+
[gzip-image]: https://img.badgesize.io/https://unpkg.com/@esri/arcgis-rest-geocoding/dist/bundled/geocoding.umd.min.js?compression=gzip
|
|
12
12
|
[coverage-img]: https://codecov.io/gh/Esri/arcgis-rest-js/branch/master/graph/badge.svg
|
|
13
13
|
[coverage-url]: https://codecov.io/gh/Esri/arcgis-rest-js
|
|
14
14
|
|
|
@@ -24,28 +24,27 @@ npm install @esri/arcgis-rest-geocoding
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
|
-
import { geocode } from
|
|
27
|
+
import { geocode } from "@esri/arcgis-rest-geocoding";
|
|
28
28
|
|
|
29
|
-
geocode("LAX")
|
|
30
|
-
.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
29
|
+
geocode("LAX").then((response) => {
|
|
30
|
+
response.candidates[0].location;
|
|
31
|
+
// => { x: -118.409, y: 33.943 }
|
|
32
|
+
});
|
|
34
33
|
```
|
|
35
34
|
|
|
36
35
|
### [API Reference](https://esri.github.io/arcgis-rest-js/api/geocoding/)
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
- [`geocode("1 World Way Los Angeles 90045")`](https://esri.github.io/arcgis-rest-js/api/geocoding/geocode/)
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
- [`suggest("Starb")`](https://esri.github.io/arcgis-rest-js/api/geocoding/suggest/)
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
- [`reverseGeocode([-118.409,33.943 ])`](https://esri.github.io/arcgis-rest-js/api/geocoding/reverseGeocode/)
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
- [`bulkGeocode()`](https://esri.github.io/arcgis-rest-js/api/geocoding/bulkGeocode/)
|
|
45
44
|
|
|
46
45
|
### Issues
|
|
47
46
|
|
|
48
|
-
If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first.
|
|
47
|
+
If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you.
|
|
49
48
|
|
|
50
49
|
If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss).
|
|
51
50
|
|
|
@@ -61,8 +60,8 @@ Esri welcomes contributions from anyone and everyone. Please see our [guidelines
|
|
|
61
60
|
|
|
62
61
|
### In the wild
|
|
63
62
|
|
|
64
|
-
| What
|
|
65
|
-
|
|
|
63
|
+
| What | Who |
|
|
64
|
+
| -------------------------------------------------------------------------- | ---------------------------------------- |
|
|
66
65
|
| [React](https://twitter.com/oppoudel/status/1022209378378805249) component | [@oppoudel](https://github.com/oppoudel) |
|
|
67
66
|
|
|
68
67
|
### [Changelog](https://github.com/Esri/arcgis-rest-js/blob/master/CHANGELOG.md)
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/* @preserve
|
|
2
|
+
* @esri/arcgis-rest-geocoding - v3.3.0 - Apache-2.0
|
|
3
|
+
* Copyright (c) 2017-2022 Esri, Inc.
|
|
4
|
+
* Wed Mar 02 2022 19:56:01 GMT+0000 (Coordinated Universal Time)
|
|
5
|
+
*/
|
|
6
|
+
import { request, appendCustomParams, cleanUrl } from '@esri/arcgis-rest-request';
|
|
7
|
+
|
|
8
|
+
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
|
|
9
|
+
* Apache-2.0 */
|
|
10
|
+
// https always
|
|
11
|
+
const ARCGIS_ONLINE_GEOCODING_URL = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
|
|
12
|
+
const ARCGIS_ONLINE_BULK_GEOCODING_URL = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
|
|
13
|
+
/**
|
|
14
|
+
* Used to fetch metadata from a geocoding service.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* import { getGeocoderServiceInfo } from '@esri/arcgis-rest-geocoding';
|
|
18
|
+
*
|
|
19
|
+
* getGeocoderServiceInfo()
|
|
20
|
+
* .then((response) => {
|
|
21
|
+
* response.serviceDescription; // => 'World Geocoder'
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param requestOptions - Request options can contain a custom geocoding service to fetch metadata from.
|
|
26
|
+
* @returns A Promise that will resolve with the data from the response.
|
|
27
|
+
*/
|
|
28
|
+
function getGeocodeService(requestOptions) {
|
|
29
|
+
const url = (requestOptions && requestOptions.endpoint) || ARCGIS_ONLINE_GEOCODING_URL;
|
|
30
|
+
const options = Object.assign({ httpMethod: "GET", maxUrlLength: 2000 }, requestOptions);
|
|
31
|
+
return request(url, options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* @preserve
|
|
35
|
+
* @terraformer/arcgis - v2.0.7 - MIT
|
|
36
|
+
* Copyright (c) 2012-2021 Environmental Systems Research Institute, Inc.
|
|
37
|
+
* Thu Jul 22 2021 13:58:30 GMT-0700 (Pacific Daylight Time)
|
|
38
|
+
*/
|
|
39
|
+
/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
|
|
40
|
+
* Apache-2.0 */
|
|
41
|
+
|
|
42
|
+
var edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) {
|
|
43
|
+
var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);
|
|
44
|
+
var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);
|
|
45
|
+
var uB = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);
|
|
46
|
+
|
|
47
|
+
if (uB !== 0) {
|
|
48
|
+
var ua = uaT / uB;
|
|
49
|
+
var ub = ubT / uB;
|
|
50
|
+
|
|
51
|
+
if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
var coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) {
|
|
59
|
+
var contains = false;
|
|
60
|
+
|
|
61
|
+
for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {
|
|
62
|
+
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]) {
|
|
63
|
+
contains = !contains;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return contains;
|
|
68
|
+
};
|
|
69
|
+
var pointsEqual = function pointsEqual(a, b) {
|
|
70
|
+
for (var i = 0; i < a.length; i++) {
|
|
71
|
+
if (a[i] !== b[i]) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
var arrayIntersectsArray = function arrayIntersectsArray(a, b) {
|
|
79
|
+
for (var i = 0; i < a.length - 1; i++) {
|
|
80
|
+
for (var j = 0; j < b.length - 1; j++) {
|
|
81
|
+
if (edgeIntersectsEdge(a[i], a[i + 1], b[j], b[j + 1])) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
|
|
91
|
+
* Apache-2.0 */
|
|
92
|
+
|
|
93
|
+
var closeRing = function closeRing(coordinates) {
|
|
94
|
+
if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {
|
|
95
|
+
coordinates.push(coordinates[0]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return coordinates;
|
|
99
|
+
}; // determine if polygon ring coordinates are clockwise. clockwise signifies outer ring, counter-clockwise an inner ring
|
|
100
|
+
// or hole. this logic was found at http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-
|
|
101
|
+
// points-are-in-clockwise-order
|
|
102
|
+
|
|
103
|
+
var ringIsClockwise = function ringIsClockwise(ringToTest) {
|
|
104
|
+
var total = 0;
|
|
105
|
+
var i = 0;
|
|
106
|
+
var rLength = ringToTest.length;
|
|
107
|
+
var pt1 = ringToTest[i];
|
|
108
|
+
var pt2;
|
|
109
|
+
|
|
110
|
+
for (i; i < rLength - 1; i++) {
|
|
111
|
+
pt2 = ringToTest[i + 1];
|
|
112
|
+
total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);
|
|
113
|
+
pt1 = pt2;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return total >= 0;
|
|
117
|
+
}; // This function ensures that rings are oriented in the right directions
|
|
118
|
+
// from http://jsperf.com/cloning-an-object/2
|
|
119
|
+
|
|
120
|
+
var shallowClone = function shallowClone(obj) {
|
|
121
|
+
var target = {};
|
|
122
|
+
|
|
123
|
+
for (var i in obj) {
|
|
124
|
+
// both arcgis attributes and geojson props are just hardcoded keys
|
|
125
|
+
if (obj.hasOwnProperty(i)) {
|
|
126
|
+
// eslint-disable-line no-prototype-builtins
|
|
127
|
+
target[i] = obj[i];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return target;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc.
|
|
135
|
+
* Apache-2.0 */
|
|
136
|
+
|
|
137
|
+
var coordinatesContainCoordinates = function coordinatesContainCoordinates(outer, inner) {
|
|
138
|
+
var intersects = arrayIntersectsArray(outer, inner);
|
|
139
|
+
var contains = coordinatesContainPoint(outer, inner[0]);
|
|
140
|
+
|
|
141
|
+
if (!intersects && contains) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return false;
|
|
146
|
+
}; // do any polygons in this array contain any other polygons in this array?
|
|
147
|
+
// used for checking for holes in arcgis rings
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
var convertRingsToGeoJSON = function convertRingsToGeoJSON(rings) {
|
|
151
|
+
var outerRings = [];
|
|
152
|
+
var holes = [];
|
|
153
|
+
var x; // iterator
|
|
154
|
+
|
|
155
|
+
var outerRing; // current outer ring being evaluated
|
|
156
|
+
|
|
157
|
+
var hole; // current hole being evaluated
|
|
158
|
+
// for each ring
|
|
159
|
+
|
|
160
|
+
for (var r = 0; r < rings.length; r++) {
|
|
161
|
+
var ring = closeRing(rings[r].slice(0));
|
|
162
|
+
|
|
163
|
+
if (ring.length < 4) {
|
|
164
|
+
continue;
|
|
165
|
+
} // is this ring an outer ring? is it clockwise?
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if (ringIsClockwise(ring)) {
|
|
169
|
+
var polygon = [ring.slice().reverse()]; // wind outer rings counterclockwise for RFC 7946 compliance
|
|
170
|
+
|
|
171
|
+
outerRings.push(polygon); // push to outer rings
|
|
172
|
+
} else {
|
|
173
|
+
holes.push(ring.slice().reverse()); // wind inner rings clockwise for RFC 7946 compliance
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
var uncontainedHoles = []; // while there are holes left...
|
|
178
|
+
|
|
179
|
+
while (holes.length) {
|
|
180
|
+
// pop a hole off out stack
|
|
181
|
+
hole = holes.pop(); // loop over all outer rings and see if they contain our hole.
|
|
182
|
+
|
|
183
|
+
var contained = false;
|
|
184
|
+
|
|
185
|
+
for (x = outerRings.length - 1; x >= 0; x--) {
|
|
186
|
+
outerRing = outerRings[x][0];
|
|
187
|
+
|
|
188
|
+
if (coordinatesContainCoordinates(outerRing, hole)) {
|
|
189
|
+
// the hole is contained push it into our polygon
|
|
190
|
+
outerRings[x].push(hole);
|
|
191
|
+
contained = true;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
} // ring is not contained in any outer ring
|
|
195
|
+
// sometimes this happens https://github.com/Esri/esri-leaflet/issues/320
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
if (!contained) {
|
|
199
|
+
uncontainedHoles.push(hole);
|
|
200
|
+
}
|
|
201
|
+
} // if we couldn't match any holes using contains we can try intersects...
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
while (uncontainedHoles.length) {
|
|
205
|
+
// pop a hole off out stack
|
|
206
|
+
hole = uncontainedHoles.pop(); // loop over all outer rings and see if any intersect our hole.
|
|
207
|
+
|
|
208
|
+
var intersects = false;
|
|
209
|
+
|
|
210
|
+
for (x = outerRings.length - 1; x >= 0; x--) {
|
|
211
|
+
outerRing = outerRings[x][0];
|
|
212
|
+
|
|
213
|
+
if (arrayIntersectsArray(outerRing, hole)) {
|
|
214
|
+
// the hole is contained push it into our polygon
|
|
215
|
+
outerRings[x].push(hole);
|
|
216
|
+
intersects = true;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!intersects) {
|
|
222
|
+
outerRings.push([hole.reverse()]);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (outerRings.length === 1) {
|
|
227
|
+
return {
|
|
228
|
+
type: 'Polygon',
|
|
229
|
+
coordinates: outerRings[0]
|
|
230
|
+
};
|
|
231
|
+
} else {
|
|
232
|
+
return {
|
|
233
|
+
type: 'MultiPolygon',
|
|
234
|
+
coordinates: outerRings
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
var getId = function getId(attributes, idAttribute) {
|
|
240
|
+
var keys = idAttribute ? [idAttribute, 'OBJECTID', 'FID'] : ['OBJECTID', 'FID'];
|
|
241
|
+
|
|
242
|
+
for (var i = 0; i < keys.length; i++) {
|
|
243
|
+
var key = keys[i];
|
|
244
|
+
|
|
245
|
+
if (key in attributes && (typeof attributes[key] === 'string' || typeof attributes[key] === 'number')) {
|
|
246
|
+
return attributes[key];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
throw Error('No valid id attribute found');
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
var arcgisToGeoJSON = function arcgisToGeoJSON(arcgis, idAttribute) {
|
|
254
|
+
var geojson = {};
|
|
255
|
+
|
|
256
|
+
if (arcgis.features) {
|
|
257
|
+
geojson.type = 'FeatureCollection';
|
|
258
|
+
geojson.features = [];
|
|
259
|
+
|
|
260
|
+
for (var i = 0; i < arcgis.features.length; i++) {
|
|
261
|
+
geojson.features.push(arcgisToGeoJSON(arcgis.features[i], idAttribute));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (typeof arcgis.x === 'number' && typeof arcgis.y === 'number') {
|
|
266
|
+
geojson.type = 'Point';
|
|
267
|
+
geojson.coordinates = [arcgis.x, arcgis.y];
|
|
268
|
+
|
|
269
|
+
if (typeof arcgis.z === 'number') {
|
|
270
|
+
geojson.coordinates.push(arcgis.z);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (arcgis.points) {
|
|
275
|
+
geojson.type = 'MultiPoint';
|
|
276
|
+
geojson.coordinates = arcgis.points.slice(0);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (arcgis.paths) {
|
|
280
|
+
if (arcgis.paths.length === 1) {
|
|
281
|
+
geojson.type = 'LineString';
|
|
282
|
+
geojson.coordinates = arcgis.paths[0].slice(0);
|
|
283
|
+
} else {
|
|
284
|
+
geojson.type = 'MultiLineString';
|
|
285
|
+
geojson.coordinates = arcgis.paths.slice(0);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (arcgis.rings) {
|
|
290
|
+
geojson = convertRingsToGeoJSON(arcgis.rings.slice(0));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (typeof arcgis.xmin === 'number' && typeof arcgis.ymin === 'number' && typeof arcgis.xmax === 'number' && typeof arcgis.ymax === 'number') {
|
|
294
|
+
geojson.type = 'Polygon';
|
|
295
|
+
geojson.coordinates = [[[arcgis.xmax, arcgis.ymax], [arcgis.xmin, arcgis.ymax], [arcgis.xmin, arcgis.ymin], [arcgis.xmax, arcgis.ymin], [arcgis.xmax, arcgis.ymax]]];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (arcgis.geometry || arcgis.attributes) {
|
|
299
|
+
geojson.type = 'Feature';
|
|
300
|
+
geojson.geometry = arcgis.geometry ? arcgisToGeoJSON(arcgis.geometry) : null;
|
|
301
|
+
geojson.properties = arcgis.attributes ? shallowClone(arcgis.attributes) : null;
|
|
302
|
+
|
|
303
|
+
if (arcgis.attributes) {
|
|
304
|
+
try {
|
|
305
|
+
geojson.id = getId(arcgis.attributes, idAttribute);
|
|
306
|
+
} catch (err) {// don't set an id
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
} // if no valid geometry was encountered
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
if (JSON.stringify(geojson.geometry) === JSON.stringify({})) {
|
|
313
|
+
geojson.geometry = null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (arcgis.spatialReference && arcgis.spatialReference.wkid && arcgis.spatialReference.wkid !== 4326) {
|
|
317
|
+
console.warn('Object converted in non-standard crs - ' + JSON.stringify(arcgis.spatialReference));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return geojson;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
|
324
|
+
* Apache-2.0 */
|
|
325
|
+
/**
|
|
326
|
+
* ```js
|
|
327
|
+
* import { geocode } from '@esri/arcgis-rest-geocoding';
|
|
328
|
+
* //
|
|
329
|
+
* geocode("LAX")
|
|
330
|
+
* .then((response) => {
|
|
331
|
+
* response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: ... }
|
|
332
|
+
* });
|
|
333
|
+
* //
|
|
334
|
+
* geocode({
|
|
335
|
+
* address: "1600 Pennsylvania Ave",
|
|
336
|
+
* postal: 20500,
|
|
337
|
+
* countryCode: "USA"
|
|
338
|
+
* })
|
|
339
|
+
* .then((response) => {
|
|
340
|
+
* response.candidates[1].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... }
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
* 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.
|
|
344
|
+
* @param address String representing the address or point of interest or RequestOptions to pass to the endpoint.
|
|
345
|
+
* @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.
|
|
346
|
+
*/
|
|
347
|
+
function geocode(address) {
|
|
348
|
+
let options = {};
|
|
349
|
+
let endpoint;
|
|
350
|
+
if (typeof address === "string") {
|
|
351
|
+
options.params = { singleLine: address };
|
|
352
|
+
endpoint = ARCGIS_ONLINE_GEOCODING_URL;
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
endpoint = address.endpoint || ARCGIS_ONLINE_GEOCODING_URL;
|
|
356
|
+
options = appendCustomParams(address, [
|
|
357
|
+
"singleLine",
|
|
358
|
+
"address",
|
|
359
|
+
"address2",
|
|
360
|
+
"address3",
|
|
361
|
+
"neighborhood",
|
|
362
|
+
"city",
|
|
363
|
+
"subregion",
|
|
364
|
+
"region",
|
|
365
|
+
"postal",
|
|
366
|
+
"postalExt",
|
|
367
|
+
"countryCode",
|
|
368
|
+
"outFields",
|
|
369
|
+
"magicKey"
|
|
370
|
+
], { params: Object.assign({}, address.params) });
|
|
371
|
+
}
|
|
372
|
+
// add spatialReference property to individual matches
|
|
373
|
+
return request(`${cleanUrl(endpoint)}/findAddressCandidates`, options).then((response) => {
|
|
374
|
+
if (typeof address !== "string" && address.rawResponse) {
|
|
375
|
+
return response;
|
|
376
|
+
}
|
|
377
|
+
const sr = response.spatialReference;
|
|
378
|
+
response.candidates.forEach(function (candidate) {
|
|
379
|
+
candidate.location.spatialReference = sr;
|
|
380
|
+
if (candidate.extent) {
|
|
381
|
+
candidate.extent.spatialReference = sr;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
// geoJson
|
|
385
|
+
if (sr.wkid === 4326) {
|
|
386
|
+
const features = response.candidates.map((candidate) => {
|
|
387
|
+
return {
|
|
388
|
+
type: "Feature",
|
|
389
|
+
geometry: arcgisToGeoJSON(candidate.location),
|
|
390
|
+
properties: Object.assign({
|
|
391
|
+
address: candidate.address,
|
|
392
|
+
score: candidate.score
|
|
393
|
+
}, candidate.attributes)
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
response.geoJson = {
|
|
397
|
+
type: "FeatureCollection",
|
|
398
|
+
features
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
return response;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
|
406
|
+
* Apache-2.0 */
|
|
407
|
+
/**
|
|
408
|
+
* ```js
|
|
409
|
+
* import { suggest } from '@esri/arcgis-rest-geocoding';
|
|
410
|
+
* //
|
|
411
|
+
* suggest("Starb")
|
|
412
|
+
* .then(response) // response.text === "Starbucks"
|
|
413
|
+
* ```
|
|
414
|
+
* Used to return a placename [suggestion](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm) for a partial string.
|
|
415
|
+
*
|
|
416
|
+
* @param requestOptions - Options for the request including authentication and other optional parameters.
|
|
417
|
+
* @returns A Promise that will resolve with the data from the response.
|
|
418
|
+
*/
|
|
419
|
+
function suggest(partialText, requestOptions) {
|
|
420
|
+
const options = Object.assign({ endpoint: ARCGIS_ONLINE_GEOCODING_URL, params: {} }, requestOptions);
|
|
421
|
+
options.params.text = partialText;
|
|
422
|
+
return request(`${cleanUrl(options.endpoint)}/suggest`, options);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
|
426
|
+
* Apache-2.0 */
|
|
427
|
+
function isLocationArray(coords) {
|
|
428
|
+
return (coords.length === 2 ||
|
|
429
|
+
coords.length === 3);
|
|
430
|
+
}
|
|
431
|
+
function isLocation(coords) {
|
|
432
|
+
return (coords.latitude !== undefined ||
|
|
433
|
+
coords.lat !== undefined);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* ```js
|
|
437
|
+
* import { reverseGeocode } from '@esri/arcgis-rest-geocoding';
|
|
438
|
+
* //
|
|
439
|
+
* reverseGeocode([-118.409,33.943 ]) // long, lat
|
|
440
|
+
* .then((response) => {
|
|
441
|
+
* response.address.PlaceName; // => "LA Airport"
|
|
442
|
+
* });
|
|
443
|
+
* // or
|
|
444
|
+
* reverseGeocode({ long: -118.409, lat: 33.943 })
|
|
445
|
+
* reverseGeocode({ latitude: 33.943, latitude: -118.409 })
|
|
446
|
+
* reverseGeocode({ x: -118.409, y: 33.9425 }) // wgs84 is assumed
|
|
447
|
+
* reverseGeocode({ x: -13181226, y: 4021085, spatialReference: { wkid: 3857 })
|
|
448
|
+
* ```
|
|
449
|
+
* Used to determine the address of a [location](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-reverse-geocode.htm).
|
|
450
|
+
*
|
|
451
|
+
* @param coordinates - the location you'd like to associate an address with.
|
|
452
|
+
* @param requestOptions - Additional options for the request including authentication.
|
|
453
|
+
* @returns A Promise that will resolve with the data from the response.
|
|
454
|
+
*/
|
|
455
|
+
function reverseGeocode(coords, requestOptions) {
|
|
456
|
+
const options = Object.assign({ endpoint: ARCGIS_ONLINE_GEOCODING_URL, params: {} }, requestOptions);
|
|
457
|
+
if (isLocationArray(coords)) {
|
|
458
|
+
options.params.location = coords.join();
|
|
459
|
+
}
|
|
460
|
+
else if (isLocation(coords)) {
|
|
461
|
+
if (coords.lat) {
|
|
462
|
+
options.params.location = coords.long + "," + coords.lat;
|
|
463
|
+
}
|
|
464
|
+
if (coords.latitude) {
|
|
465
|
+
options.params.location = coords.longitude + "," + coords.latitude;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
// if input is a point, we can pass it straight through, with or without a spatial reference
|
|
470
|
+
options.params.location = coords;
|
|
471
|
+
}
|
|
472
|
+
return request(`${cleanUrl(options.endpoint)}/reverseGeocode`, options);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
|
476
|
+
* Apache-2.0 */
|
|
477
|
+
/**
|
|
478
|
+
* ```js
|
|
479
|
+
* import { bulkGeocode } from '@esri/arcgis-rest-geocoding';
|
|
480
|
+
* import { ApplicationSession } from '@esri/arcgis-rest-auth';
|
|
481
|
+
* //
|
|
482
|
+
* const addresses = [
|
|
483
|
+
* { "OBJECTID": 1, "SingleLine": "380 New York Street 92373" },
|
|
484
|
+
* { "OBJECTID": 2, "SingleLine": "1 World Way Los Angeles 90045" }
|
|
485
|
+
* ];
|
|
486
|
+
* //
|
|
487
|
+
* bulkGeocode({ addresses, authentication: session })
|
|
488
|
+
* .then((response) => {
|
|
489
|
+
* response.locations[0].location; // => { x: -117, y: 34, spatialReference: { wkid: 4326 } }
|
|
490
|
+
* });
|
|
491
|
+
* ```
|
|
492
|
+
* Used to geocode a [batch](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-geocode-addresses.htm) of addresses.
|
|
493
|
+
*
|
|
494
|
+
* @param requestOptions - Request options to pass to the geocoder, including an array of addresses and authentication session.
|
|
495
|
+
* @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.
|
|
496
|
+
*/
|
|
497
|
+
function bulkGeocode(requestOptions // must POST, which is the default
|
|
498
|
+
) {
|
|
499
|
+
const options = Object.assign({ endpoint: ARCGIS_ONLINE_BULK_GEOCODING_URL, params: {} }, requestOptions);
|
|
500
|
+
options.params.addresses = {
|
|
501
|
+
records: requestOptions.addresses.map((address) => {
|
|
502
|
+
return { attributes: address };
|
|
503
|
+
})
|
|
504
|
+
};
|
|
505
|
+
// the SAS service does not support anonymous requests
|
|
506
|
+
if (!requestOptions.authentication &&
|
|
507
|
+
options.endpoint === ARCGIS_ONLINE_BULK_GEOCODING_URL) {
|
|
508
|
+
return Promise.reject("bulk geocoding using the ArcGIS service requires authentication");
|
|
509
|
+
}
|
|
510
|
+
return request(`${cleanUrl(options.endpoint)}/geocodeAddresses`, options).then((response) => {
|
|
511
|
+
if (options.rawResponse) {
|
|
512
|
+
return response;
|
|
513
|
+
}
|
|
514
|
+
const sr = response.spatialReference;
|
|
515
|
+
response.locations.forEach(function (address) {
|
|
516
|
+
if (address.location) {
|
|
517
|
+
address.location.spatialReference = sr;
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
return response;
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export { ARCGIS_ONLINE_BULK_GEOCODING_URL, ARCGIS_ONLINE_GEOCODING_URL, bulkGeocode, geocode, getGeocodeService, reverseGeocode, suggest };
|
|
525
|
+
//# sourceMappingURL=geocoding.esm.js.map
|