@nextgis/geocoder 1.16.8 → 1.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -5
- package/lib/geocoder.cjs.js +255 -441
- package/lib/geocoder.cjs.js.map +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +2232 -2160
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +1 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +255 -441
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +2401 -1984
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/lib/index.d.ts +131 -8
- package/package.json +7 -6
package/lib/geocoder.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 1.18.3; author: NextGIS */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -6,458 +6,272 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var CancelablePromise = require('@nextgis/cancelable-promise');
|
|
7
7
|
var utils = require('@nextgis/utils');
|
|
8
8
|
var NgwConnector = require('@nextgis/ngw-connector');
|
|
9
|
+
var ngwKit = require('@nextgis/ngw-kit');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
11
12
|
|
|
12
13
|
var CancelablePromise__default = /*#__PURE__*/_interopDefaultLegacy(CancelablePromise);
|
|
13
14
|
var NgwConnector__default = /*#__PURE__*/_interopDefaultLegacy(NgwConnector);
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
28
|
-
***************************************************************************** */
|
|
29
|
-
/* global Reflect, Promise */
|
|
30
|
-
|
|
31
|
-
var extendStatics = function(d, b) {
|
|
32
|
-
extendStatics = Object.setPrototypeOf ||
|
|
33
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
34
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
35
|
-
return extendStatics(d, b);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
function __extends(d, b) {
|
|
39
|
-
if (typeof b !== "function" && b !== null)
|
|
40
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
41
|
-
extendStatics(d, b);
|
|
42
|
-
function __() { this.constructor = d; }
|
|
43
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var __assign = function() {
|
|
47
|
-
__assign = Object.assign || function __assign(t) {
|
|
48
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
49
|
-
s = arguments[i];
|
|
50
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
51
|
-
}
|
|
52
|
-
return t;
|
|
53
|
-
};
|
|
54
|
-
return __assign.apply(this, arguments);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function __generator(thisArg, body) {
|
|
58
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
59
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
60
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
61
|
-
function step(op) {
|
|
62
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
63
|
-
while (_) try {
|
|
64
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
65
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
66
|
-
switch (op[0]) {
|
|
67
|
-
case 0: case 1: t = op; break;
|
|
68
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
69
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
70
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
71
|
-
default:
|
|
72
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
73
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
74
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
75
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
76
|
-
if (t[2]) _.ops.pop();
|
|
77
|
-
_.trys.pop(); continue;
|
|
78
|
-
}
|
|
79
|
-
op = body.call(thisArg, _);
|
|
80
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
81
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function __values(o) {
|
|
86
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
87
|
-
if (m) return m.call(o);
|
|
88
|
-
if (o && typeof o.length === "number") return {
|
|
89
|
-
next: function () {
|
|
90
|
-
if (o && i >= o.length) o = void 0;
|
|
91
|
-
return { value: o && o[i++], done: !o };
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function __await(v) {
|
|
98
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
102
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
103
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
104
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
105
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
106
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
107
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
108
|
-
function fulfill(value) { resume("next", value); }
|
|
109
|
-
function reject(value) { resume("throw", value); }
|
|
110
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function __asyncValues(o) {
|
|
114
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
115
|
-
var m = o[Symbol.asyncIterator], i;
|
|
116
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
117
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
118
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
/**
|
|
17
|
+
* Represents the base class for a geocoder.
|
|
18
|
+
* This abstract class provides the basic methods that every geocoder should implement.
|
|
19
|
+
*
|
|
20
|
+
* @template O - The type of options that can be passed to the geocoder.
|
|
21
|
+
*/
|
|
22
|
+
class BaseGeocoder {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
if (options) {
|
|
25
|
+
utils.objectAssign(this, options);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
119
28
|
}
|
|
120
29
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
case 1:
|
|
158
|
-
if (!(_i < _a.length)) return [3 /*break*/, 19];
|
|
159
|
-
provider = _a[_i];
|
|
160
|
-
_c.label = 2;
|
|
161
|
-
case 2:
|
|
162
|
-
_c.trys.push([2, 17, , 18]);
|
|
163
|
-
results = provider.search(query);
|
|
164
|
-
_c.label = 3;
|
|
165
|
-
case 3:
|
|
166
|
-
_c.trys.push([3, 10, 11, 16]);
|
|
167
|
-
results_1 = (e_1 = void 0, __asyncValues(results));
|
|
168
|
-
_c.label = 4;
|
|
169
|
-
case 4: return [4 /*yield*/, __await(results_1.next())];
|
|
170
|
-
case 5:
|
|
171
|
-
if (!(results_1_1 = _c.sent(), !results_1_1.done)) return [3 /*break*/, 9];
|
|
172
|
-
r = results_1_1.value;
|
|
173
|
-
return [4 /*yield*/, __await(__assign(__assign({}, r), { provider: provider, _id: ID++ }))];
|
|
174
|
-
case 6: return [4 /*yield*/, _c.sent()];
|
|
175
|
-
case 7:
|
|
176
|
-
_c.sent();
|
|
177
|
-
_c.label = 8;
|
|
178
|
-
case 8: return [3 /*break*/, 4];
|
|
179
|
-
case 9: return [3 /*break*/, 16];
|
|
180
|
-
case 10:
|
|
181
|
-
e_1_1 = _c.sent();
|
|
182
|
-
e_1 = { error: e_1_1 };
|
|
183
|
-
return [3 /*break*/, 16];
|
|
184
|
-
case 11:
|
|
185
|
-
_c.trys.push([11, , 14, 15]);
|
|
186
|
-
if (!(results_1_1 && !results_1_1.done && (_b = results_1.return))) return [3 /*break*/, 13];
|
|
187
|
-
return [4 /*yield*/, __await(_b.call(results_1))];
|
|
188
|
-
case 12:
|
|
189
|
-
_c.sent();
|
|
190
|
-
_c.label = 13;
|
|
191
|
-
case 13: return [3 /*break*/, 15];
|
|
192
|
-
case 14:
|
|
193
|
-
if (e_1) throw e_1.error;
|
|
194
|
-
return [7 /*endfinally*/];
|
|
195
|
-
case 15: return [7 /*endfinally*/];
|
|
196
|
-
case 16: return [3 /*break*/, 18];
|
|
197
|
-
case 17:
|
|
198
|
-
_c.sent();
|
|
199
|
-
return [3 /*break*/, 18];
|
|
200
|
-
case 18:
|
|
201
|
-
_i++;
|
|
202
|
-
return [3 /*break*/, 1];
|
|
203
|
-
case 19: return [2 /*return*/];
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
Geocoder.prototype.result = function (item) {
|
|
209
|
-
if (item.provider) {
|
|
210
|
-
return item.provider.result(item);
|
|
211
|
-
}
|
|
212
|
-
return CancelablePromise__default.resolve(undefined);
|
|
213
|
-
};
|
|
214
|
-
return Geocoder;
|
|
215
|
-
}(BaseGeocoder));
|
|
30
|
+
let ID = 0;
|
|
31
|
+
class Geocoder extends BaseGeocoder {
|
|
32
|
+
constructor(options) {
|
|
33
|
+
super(options);
|
|
34
|
+
this.providers = [];
|
|
35
|
+
if (options && options.providers) {
|
|
36
|
+
this.providers = options.providers;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
abort() {
|
|
40
|
+
this.providers.forEach((x) => {
|
|
41
|
+
if (x.abort) {
|
|
42
|
+
x.abort();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async *search(query) {
|
|
47
|
+
for (const provider of this.providers) {
|
|
48
|
+
try {
|
|
49
|
+
const results = provider.search(query);
|
|
50
|
+
for await (const r of results) {
|
|
51
|
+
yield { ...r, provider, _id: ID++ };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (er) {
|
|
55
|
+
//
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
result(item) {
|
|
60
|
+
if (item.provider) {
|
|
61
|
+
return item.provider.result(item);
|
|
62
|
+
}
|
|
63
|
+
return CancelablePromise__default.resolve(undefined);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
216
66
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
67
|
+
/**
|
|
68
|
+
* Abstract base class representing a search provider.
|
|
69
|
+
* It builds upon the BaseGeocoder functionalities with provider-specific properties.
|
|
70
|
+
* @template O - Options type which extends BaseProviderOptions.
|
|
71
|
+
*/
|
|
72
|
+
class BaseProvider extends BaseGeocoder {
|
|
73
|
+
}
|
|
224
74
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
resourceId: entry.resourceId,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
return items;
|
|
357
|
-
};
|
|
358
|
-
return NgwProvider;
|
|
359
|
-
}(BaseProvider));
|
|
75
|
+
class NgwProvider extends BaseProvider {
|
|
76
|
+
constructor(options) {
|
|
77
|
+
var _a;
|
|
78
|
+
super(options);
|
|
79
|
+
this.caseInsensitive = true;
|
|
80
|
+
this.searchResources = [];
|
|
81
|
+
this._abortControllers = [];
|
|
82
|
+
if (!options.searchUrl && !((_a = options.connectorOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
|
|
83
|
+
throw new Error('The `searchUrl` of `connectorOptions.baseUrl` are required');
|
|
84
|
+
}
|
|
85
|
+
this.connector =
|
|
86
|
+
options.connector ||
|
|
87
|
+
new NgwConnector__default({
|
|
88
|
+
baseUrl: this.searchUrl,
|
|
89
|
+
...options.connectorOptions,
|
|
90
|
+
});
|
|
91
|
+
this.searchResources = options.searchResources;
|
|
92
|
+
}
|
|
93
|
+
abort() {
|
|
94
|
+
this._abortControllers.forEach((a) => {
|
|
95
|
+
a.abort();
|
|
96
|
+
});
|
|
97
|
+
this._abortControllers.length = 0;
|
|
98
|
+
}
|
|
99
|
+
async *search(query) {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const signal = this._makeSignal();
|
|
102
|
+
for (const config of this.searchResources) {
|
|
103
|
+
if (signal.aborted) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
const { searchMethod } = config;
|
|
107
|
+
const limit = (_a = config.limit) !== null && _a !== void 0 ? _a : NgwProvider.limit;
|
|
108
|
+
//
|
|
109
|
+
const resourceId = (_b = config.id) !== null && _b !== void 0 ? _b : config.resourceId;
|
|
110
|
+
try {
|
|
111
|
+
const resource = await this.connector.getResourceOrFail(resourceId, {
|
|
112
|
+
cache: true,
|
|
113
|
+
});
|
|
114
|
+
const options = {
|
|
115
|
+
connector: this.connector,
|
|
116
|
+
resourceId,
|
|
117
|
+
signal,
|
|
118
|
+
limit,
|
|
119
|
+
};
|
|
120
|
+
if (searchMethod === 'like') {
|
|
121
|
+
options.like = query;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
options.ilike = query;
|
|
125
|
+
}
|
|
126
|
+
const request = ngwKit.fetchNgwLayerItems(options);
|
|
127
|
+
const entries = await request;
|
|
128
|
+
for (const item of this._items({
|
|
129
|
+
entries,
|
|
130
|
+
query,
|
|
131
|
+
config,
|
|
132
|
+
resourceItem: resource,
|
|
133
|
+
})) {
|
|
134
|
+
item.result = () => this.result(item);
|
|
135
|
+
yield item;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (er) {
|
|
139
|
+
if (er &&
|
|
140
|
+
'name' in er &&
|
|
141
|
+
er.name !== 'CancelError') {
|
|
142
|
+
console.warn(er);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
result(item) {
|
|
148
|
+
const signal = this._makeSignal();
|
|
149
|
+
const req = this.connector
|
|
150
|
+
.get('feature_layer.feature.item_extent', { signal }, {
|
|
151
|
+
id: item.resourceId,
|
|
152
|
+
fid: item.featureId,
|
|
153
|
+
})
|
|
154
|
+
.then((x) => {
|
|
155
|
+
const e = x.extent;
|
|
156
|
+
return {
|
|
157
|
+
text: item.text,
|
|
158
|
+
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
return req;
|
|
162
|
+
}
|
|
163
|
+
_makeSignal() {
|
|
164
|
+
const abortController = new AbortController();
|
|
165
|
+
this._abortControllers.push(abortController);
|
|
166
|
+
return abortController.signal;
|
|
167
|
+
}
|
|
168
|
+
_items({ entries, query, config, resourceItem, }) {
|
|
169
|
+
var _a;
|
|
170
|
+
const items = [];
|
|
171
|
+
let labelField = undefined;
|
|
172
|
+
if (resourceItem.feature_layer) {
|
|
173
|
+
labelField = (_a = resourceItem.feature_layer.fields.find((f) => f.label_field)) === null || _a === void 0 ? void 0 : _a.keyname;
|
|
174
|
+
}
|
|
175
|
+
const meta = this.searchResources.find((x) => { var _a; return (_a = x.id) !== null && _a !== void 0 ? _a : x.resourceId === resourceItem.resource.id; });
|
|
176
|
+
if (meta) {
|
|
177
|
+
entries.forEach((entry) => {
|
|
178
|
+
let text = labelField ? entry.fields[labelField] : entry.id;
|
|
179
|
+
if (config.renderSearch) {
|
|
180
|
+
text = config.renderSearch({
|
|
181
|
+
item: entry,
|
|
182
|
+
resourceItem,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else if (labelField) {
|
|
186
|
+
text = entry.fields[labelField];
|
|
187
|
+
}
|
|
188
|
+
items.push({
|
|
189
|
+
query: query,
|
|
190
|
+
text,
|
|
191
|
+
featureId: entry.id,
|
|
192
|
+
resourceId: resourceItem.resource.id,
|
|
193
|
+
item: entry,
|
|
194
|
+
resourceItem,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return items;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
NgwProvider.limit = 300;
|
|
360
202
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return [4 /*yield*/, __await(i)];
|
|
425
|
-
case 1: return [4 /*yield*/, _b.sent()];
|
|
426
|
-
case 2:
|
|
427
|
-
_b.sent();
|
|
428
|
-
return [2 /*return*/];
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
};
|
|
432
|
-
_i = 0, items_1 = items;
|
|
433
|
-
_a.label = 2;
|
|
434
|
-
case 2:
|
|
435
|
-
if (!(_i < items_1.length)) return [3 /*break*/, 5];
|
|
436
|
-
i = items_1[_i];
|
|
437
|
-
return [5 /*yield**/, _loop_1(i)];
|
|
438
|
-
case 3:
|
|
439
|
-
_a.sent();
|
|
440
|
-
_a.label = 4;
|
|
441
|
-
case 4:
|
|
442
|
-
_i++;
|
|
443
|
-
return [3 /*break*/, 2];
|
|
444
|
-
case 5: return [2 /*return*/];
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
NominatimProvider.prototype.result = function (model) {
|
|
450
|
-
return CancelablePromise__default.resolve({
|
|
451
|
-
text: model.text,
|
|
452
|
-
extent: model.extent || [],
|
|
453
|
-
geom: model.geom,
|
|
454
|
-
});
|
|
455
|
-
};
|
|
456
|
-
return NominatimProvider;
|
|
457
|
-
}(BaseProvider));
|
|
203
|
+
class NominatimProvider extends BaseProvider {
|
|
204
|
+
constructor(options) {
|
|
205
|
+
super(options);
|
|
206
|
+
this.searchUrl = 'https://nominatim.openstreetmap.org';
|
|
207
|
+
this._requests = [];
|
|
208
|
+
}
|
|
209
|
+
abort() {
|
|
210
|
+
this._requests.forEach((x) => x.cancel());
|
|
211
|
+
this._requests = [];
|
|
212
|
+
}
|
|
213
|
+
async *search(val) {
|
|
214
|
+
// RFC2616 accept - language string
|
|
215
|
+
const url = utils.fixUrlStr(
|
|
216
|
+
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
217
|
+
`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`);
|
|
218
|
+
const request = new CancelablePromise__default((resolve, reject, onCancel) => {
|
|
219
|
+
const xhr = new XMLHttpRequest();
|
|
220
|
+
xhr.open('GET', url, true);
|
|
221
|
+
xhr.onload = () => {
|
|
222
|
+
try {
|
|
223
|
+
const geojson = JSON.parse(xhr.responseText);
|
|
224
|
+
const features = geojson.features.map((x) => {
|
|
225
|
+
return {
|
|
226
|
+
geom: x,
|
|
227
|
+
extent: x.bbox,
|
|
228
|
+
text: x.properties && x.properties.display_name,
|
|
229
|
+
query: val,
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
resolve(features);
|
|
233
|
+
}
|
|
234
|
+
catch (er) {
|
|
235
|
+
reject(er);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
xhr.onerror = (er) => {
|
|
239
|
+
reject(er);
|
|
240
|
+
};
|
|
241
|
+
onCancel(() => {
|
|
242
|
+
xhr.abort();
|
|
243
|
+
});
|
|
244
|
+
xhr.send();
|
|
245
|
+
}).catch((er) => {
|
|
246
|
+
if (er.name === 'CancelError') ;
|
|
247
|
+
throw er;
|
|
248
|
+
});
|
|
249
|
+
this._requests.push(request);
|
|
250
|
+
const items = await request;
|
|
251
|
+
if (items) {
|
|
252
|
+
for (const i of items) {
|
|
253
|
+
i.result = () => this.result(i);
|
|
254
|
+
yield i;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
result(model) {
|
|
259
|
+
return CancelablePromise__default.resolve({
|
|
260
|
+
text: model.text,
|
|
261
|
+
extent: model.extent || [],
|
|
262
|
+
geom: model.geom,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
458
266
|
|
|
459
|
-
|
|
460
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Modern geocoder on async generators. May use different data providers.
|
|
269
|
+
*
|
|
270
|
+
* @packageDocumentation
|
|
271
|
+
* @module geocoder
|
|
272
|
+
*/
|
|
273
|
+
function create(options) {
|
|
274
|
+
return new Geocoder(options);
|
|
461
275
|
}
|
|
462
276
|
|
|
463
277
|
exports.BaseProvider = BaseProvider;
|