@esri/arcgis-rest-geocoding 4.0.4-alpha.1 → 4.8.0

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