@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
|
@@ -1,454 +1,268 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 1.18.3; author: NextGIS */
|
|
2
2
|
import CancelablePromise from '@nextgis/cancelable-promise';
|
|
3
3
|
import { objectAssign, fixUrlStr } from '@nextgis/utils';
|
|
4
4
|
import NgwConnector from '@nextgis/ngw-connector';
|
|
5
|
+
import { fetchNgwLayerItems } from '@nextgis/ngw-kit';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise */
|
|
21
|
-
|
|
22
|
-
var extendStatics = function(d, b) {
|
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
26
|
-
return extendStatics(d, b);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function __extends(d, b) {
|
|
30
|
-
if (typeof b !== "function" && b !== null)
|
|
31
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
32
|
-
extendStatics(d, b);
|
|
33
|
-
function __() { this.constructor = d; }
|
|
34
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var __assign = function() {
|
|
38
|
-
__assign = Object.assign || function __assign(t) {
|
|
39
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
-
s = arguments[i];
|
|
41
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
42
|
-
}
|
|
43
|
-
return t;
|
|
44
|
-
};
|
|
45
|
-
return __assign.apply(this, arguments);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
function __generator(thisArg, body) {
|
|
49
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
50
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
51
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
52
|
-
function step(op) {
|
|
53
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
54
|
-
while (_) try {
|
|
55
|
-
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;
|
|
56
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
57
|
-
switch (op[0]) {
|
|
58
|
-
case 0: case 1: t = op; break;
|
|
59
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
60
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
61
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
62
|
-
default:
|
|
63
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
64
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
65
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
66
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
67
|
-
if (t[2]) _.ops.pop();
|
|
68
|
-
_.trys.pop(); continue;
|
|
69
|
-
}
|
|
70
|
-
op = body.call(thisArg, _);
|
|
71
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
72
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function __values(o) {
|
|
77
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
78
|
-
if (m) return m.call(o);
|
|
79
|
-
if (o && typeof o.length === "number") return {
|
|
80
|
-
next: function () {
|
|
81
|
-
if (o && i >= o.length) o = void 0;
|
|
82
|
-
return { value: o && o[i++], done: !o };
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function __await(v) {
|
|
89
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
93
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
94
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
95
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
96
|
-
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); }); }; }
|
|
97
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
98
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
99
|
-
function fulfill(value) { resume("next", value); }
|
|
100
|
-
function reject(value) { resume("throw", value); }
|
|
101
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function __asyncValues(o) {
|
|
105
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
106
|
-
var m = o[Symbol.asyncIterator], i;
|
|
107
|
-
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);
|
|
108
|
-
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); }); }; }
|
|
109
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
+
/**
|
|
8
|
+
* Represents the base class for a geocoder.
|
|
9
|
+
* This abstract class provides the basic methods that every geocoder should implement.
|
|
10
|
+
*
|
|
11
|
+
* @template O - The type of options that can be passed to the geocoder.
|
|
12
|
+
*/
|
|
13
|
+
class BaseGeocoder {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
if (options) {
|
|
16
|
+
objectAssign(this, options);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
110
19
|
}
|
|
111
20
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
case 1:
|
|
149
|
-
if (!(_i < _a.length)) return [3 /*break*/, 19];
|
|
150
|
-
provider = _a[_i];
|
|
151
|
-
_c.label = 2;
|
|
152
|
-
case 2:
|
|
153
|
-
_c.trys.push([2, 17, , 18]);
|
|
154
|
-
results = provider.search(query);
|
|
155
|
-
_c.label = 3;
|
|
156
|
-
case 3:
|
|
157
|
-
_c.trys.push([3, 10, 11, 16]);
|
|
158
|
-
results_1 = (e_1 = void 0, __asyncValues(results));
|
|
159
|
-
_c.label = 4;
|
|
160
|
-
case 4: return [4 /*yield*/, __await(results_1.next())];
|
|
161
|
-
case 5:
|
|
162
|
-
if (!(results_1_1 = _c.sent(), !results_1_1.done)) return [3 /*break*/, 9];
|
|
163
|
-
r = results_1_1.value;
|
|
164
|
-
return [4 /*yield*/, __await(__assign(__assign({}, r), { provider: provider, _id: ID++ }))];
|
|
165
|
-
case 6: return [4 /*yield*/, _c.sent()];
|
|
166
|
-
case 7:
|
|
167
|
-
_c.sent();
|
|
168
|
-
_c.label = 8;
|
|
169
|
-
case 8: return [3 /*break*/, 4];
|
|
170
|
-
case 9: return [3 /*break*/, 16];
|
|
171
|
-
case 10:
|
|
172
|
-
e_1_1 = _c.sent();
|
|
173
|
-
e_1 = { error: e_1_1 };
|
|
174
|
-
return [3 /*break*/, 16];
|
|
175
|
-
case 11:
|
|
176
|
-
_c.trys.push([11, , 14, 15]);
|
|
177
|
-
if (!(results_1_1 && !results_1_1.done && (_b = results_1.return))) return [3 /*break*/, 13];
|
|
178
|
-
return [4 /*yield*/, __await(_b.call(results_1))];
|
|
179
|
-
case 12:
|
|
180
|
-
_c.sent();
|
|
181
|
-
_c.label = 13;
|
|
182
|
-
case 13: return [3 /*break*/, 15];
|
|
183
|
-
case 14:
|
|
184
|
-
if (e_1) throw e_1.error;
|
|
185
|
-
return [7 /*endfinally*/];
|
|
186
|
-
case 15: return [7 /*endfinally*/];
|
|
187
|
-
case 16: return [3 /*break*/, 18];
|
|
188
|
-
case 17:
|
|
189
|
-
_c.sent();
|
|
190
|
-
return [3 /*break*/, 18];
|
|
191
|
-
case 18:
|
|
192
|
-
_i++;
|
|
193
|
-
return [3 /*break*/, 1];
|
|
194
|
-
case 19: return [2 /*return*/];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
Geocoder.prototype.result = function (item) {
|
|
200
|
-
if (item.provider) {
|
|
201
|
-
return item.provider.result(item);
|
|
202
|
-
}
|
|
203
|
-
return CancelablePromise.resolve(undefined);
|
|
204
|
-
};
|
|
205
|
-
return Geocoder;
|
|
206
|
-
}(BaseGeocoder));
|
|
21
|
+
let ID = 0;
|
|
22
|
+
class Geocoder extends BaseGeocoder {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super(options);
|
|
25
|
+
this.providers = [];
|
|
26
|
+
if (options && options.providers) {
|
|
27
|
+
this.providers = options.providers;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
abort() {
|
|
31
|
+
this.providers.forEach((x) => {
|
|
32
|
+
if (x.abort) {
|
|
33
|
+
x.abort();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async *search(query) {
|
|
38
|
+
for (const provider of this.providers) {
|
|
39
|
+
try {
|
|
40
|
+
const results = provider.search(query);
|
|
41
|
+
for await (const r of results) {
|
|
42
|
+
yield { ...r, provider, _id: ID++ };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (er) {
|
|
46
|
+
//
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
result(item) {
|
|
51
|
+
if (item.provider) {
|
|
52
|
+
return item.provider.result(item);
|
|
53
|
+
}
|
|
54
|
+
return CancelablePromise.resolve(undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
207
57
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
58
|
+
/**
|
|
59
|
+
* Abstract base class representing a search provider.
|
|
60
|
+
* It builds upon the BaseGeocoder functionalities with provider-specific properties.
|
|
61
|
+
* @template O - Options type which extends BaseProviderOptions.
|
|
62
|
+
*/
|
|
63
|
+
class BaseProvider extends BaseGeocoder {
|
|
64
|
+
}
|
|
215
65
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
resourceId: entry.resourceId,
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
return items;
|
|
348
|
-
};
|
|
349
|
-
return NgwProvider;
|
|
350
|
-
}(BaseProvider));
|
|
66
|
+
class NgwProvider extends BaseProvider {
|
|
67
|
+
constructor(options) {
|
|
68
|
+
var _a;
|
|
69
|
+
super(options);
|
|
70
|
+
this.caseInsensitive = true;
|
|
71
|
+
this.searchResources = [];
|
|
72
|
+
this._abortControllers = [];
|
|
73
|
+
if (!options.searchUrl && !((_a = options.connectorOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
|
|
74
|
+
throw new Error('The `searchUrl` of `connectorOptions.baseUrl` are required');
|
|
75
|
+
}
|
|
76
|
+
this.connector =
|
|
77
|
+
options.connector ||
|
|
78
|
+
new NgwConnector({
|
|
79
|
+
baseUrl: this.searchUrl,
|
|
80
|
+
...options.connectorOptions,
|
|
81
|
+
});
|
|
82
|
+
this.searchResources = options.searchResources;
|
|
83
|
+
}
|
|
84
|
+
abort() {
|
|
85
|
+
this._abortControllers.forEach((a) => {
|
|
86
|
+
a.abort();
|
|
87
|
+
});
|
|
88
|
+
this._abortControllers.length = 0;
|
|
89
|
+
}
|
|
90
|
+
async *search(query) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const signal = this._makeSignal();
|
|
93
|
+
for (const config of this.searchResources) {
|
|
94
|
+
if (signal.aborted) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
const { searchMethod } = config;
|
|
98
|
+
const limit = (_a = config.limit) !== null && _a !== void 0 ? _a : NgwProvider.limit;
|
|
99
|
+
//
|
|
100
|
+
const resourceId = (_b = config.id) !== null && _b !== void 0 ? _b : config.resourceId;
|
|
101
|
+
try {
|
|
102
|
+
const resource = await this.connector.getResourceOrFail(resourceId, {
|
|
103
|
+
cache: true,
|
|
104
|
+
});
|
|
105
|
+
const options = {
|
|
106
|
+
connector: this.connector,
|
|
107
|
+
resourceId,
|
|
108
|
+
signal,
|
|
109
|
+
limit,
|
|
110
|
+
};
|
|
111
|
+
if (searchMethod === 'like') {
|
|
112
|
+
options.like = query;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
options.ilike = query;
|
|
116
|
+
}
|
|
117
|
+
const request = fetchNgwLayerItems(options);
|
|
118
|
+
const entries = await request;
|
|
119
|
+
for (const item of this._items({
|
|
120
|
+
entries,
|
|
121
|
+
query,
|
|
122
|
+
config,
|
|
123
|
+
resourceItem: resource,
|
|
124
|
+
})) {
|
|
125
|
+
item.result = () => this.result(item);
|
|
126
|
+
yield item;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (er) {
|
|
130
|
+
if (er &&
|
|
131
|
+
'name' in er &&
|
|
132
|
+
er.name !== 'CancelError') {
|
|
133
|
+
console.warn(er);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
result(item) {
|
|
139
|
+
const signal = this._makeSignal();
|
|
140
|
+
const req = this.connector
|
|
141
|
+
.get('feature_layer.feature.item_extent', { signal }, {
|
|
142
|
+
id: item.resourceId,
|
|
143
|
+
fid: item.featureId,
|
|
144
|
+
})
|
|
145
|
+
.then((x) => {
|
|
146
|
+
const e = x.extent;
|
|
147
|
+
return {
|
|
148
|
+
text: item.text,
|
|
149
|
+
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
return req;
|
|
153
|
+
}
|
|
154
|
+
_makeSignal() {
|
|
155
|
+
const abortController = new AbortController();
|
|
156
|
+
this._abortControllers.push(abortController);
|
|
157
|
+
return abortController.signal;
|
|
158
|
+
}
|
|
159
|
+
_items({ entries, query, config, resourceItem, }) {
|
|
160
|
+
var _a;
|
|
161
|
+
const items = [];
|
|
162
|
+
let labelField = undefined;
|
|
163
|
+
if (resourceItem.feature_layer) {
|
|
164
|
+
labelField = (_a = resourceItem.feature_layer.fields.find((f) => f.label_field)) === null || _a === void 0 ? void 0 : _a.keyname;
|
|
165
|
+
}
|
|
166
|
+
const meta = this.searchResources.find((x) => { var _a; return (_a = x.id) !== null && _a !== void 0 ? _a : x.resourceId === resourceItem.resource.id; });
|
|
167
|
+
if (meta) {
|
|
168
|
+
entries.forEach((entry) => {
|
|
169
|
+
let text = labelField ? entry.fields[labelField] : entry.id;
|
|
170
|
+
if (config.renderSearch) {
|
|
171
|
+
text = config.renderSearch({
|
|
172
|
+
item: entry,
|
|
173
|
+
resourceItem,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else if (labelField) {
|
|
177
|
+
text = entry.fields[labelField];
|
|
178
|
+
}
|
|
179
|
+
items.push({
|
|
180
|
+
query: query,
|
|
181
|
+
text,
|
|
182
|
+
featureId: entry.id,
|
|
183
|
+
resourceId: resourceItem.resource.id,
|
|
184
|
+
item: entry,
|
|
185
|
+
resourceItem,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return items;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
NgwProvider.limit = 300;
|
|
351
193
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
return [4 /*yield*/, __await(i)];
|
|
416
|
-
case 1: return [4 /*yield*/, _b.sent()];
|
|
417
|
-
case 2:
|
|
418
|
-
_b.sent();
|
|
419
|
-
return [2 /*return*/];
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
};
|
|
423
|
-
_i = 0, items_1 = items;
|
|
424
|
-
_a.label = 2;
|
|
425
|
-
case 2:
|
|
426
|
-
if (!(_i < items_1.length)) return [3 /*break*/, 5];
|
|
427
|
-
i = items_1[_i];
|
|
428
|
-
return [5 /*yield**/, _loop_1(i)];
|
|
429
|
-
case 3:
|
|
430
|
-
_a.sent();
|
|
431
|
-
_a.label = 4;
|
|
432
|
-
case 4:
|
|
433
|
-
_i++;
|
|
434
|
-
return [3 /*break*/, 2];
|
|
435
|
-
case 5: return [2 /*return*/];
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
};
|
|
440
|
-
NominatimProvider.prototype.result = function (model) {
|
|
441
|
-
return CancelablePromise.resolve({
|
|
442
|
-
text: model.text,
|
|
443
|
-
extent: model.extent || [],
|
|
444
|
-
geom: model.geom,
|
|
445
|
-
});
|
|
446
|
-
};
|
|
447
|
-
return NominatimProvider;
|
|
448
|
-
}(BaseProvider));
|
|
194
|
+
class NominatimProvider extends BaseProvider {
|
|
195
|
+
constructor(options) {
|
|
196
|
+
super(options);
|
|
197
|
+
this.searchUrl = 'https://nominatim.openstreetmap.org';
|
|
198
|
+
this._requests = [];
|
|
199
|
+
}
|
|
200
|
+
abort() {
|
|
201
|
+
this._requests.forEach((x) => x.cancel());
|
|
202
|
+
this._requests = [];
|
|
203
|
+
}
|
|
204
|
+
async *search(val) {
|
|
205
|
+
// RFC2616 accept - language string
|
|
206
|
+
const url = fixUrlStr(
|
|
207
|
+
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
208
|
+
`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`);
|
|
209
|
+
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
210
|
+
const xhr = new XMLHttpRequest();
|
|
211
|
+
xhr.open('GET', url, true);
|
|
212
|
+
xhr.onload = () => {
|
|
213
|
+
try {
|
|
214
|
+
const geojson = JSON.parse(xhr.responseText);
|
|
215
|
+
const features = geojson.features.map((x) => {
|
|
216
|
+
return {
|
|
217
|
+
geom: x,
|
|
218
|
+
extent: x.bbox,
|
|
219
|
+
text: x.properties && x.properties.display_name,
|
|
220
|
+
query: val,
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
resolve(features);
|
|
224
|
+
}
|
|
225
|
+
catch (er) {
|
|
226
|
+
reject(er);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
xhr.onerror = (er) => {
|
|
230
|
+
reject(er);
|
|
231
|
+
};
|
|
232
|
+
onCancel(() => {
|
|
233
|
+
xhr.abort();
|
|
234
|
+
});
|
|
235
|
+
xhr.send();
|
|
236
|
+
}).catch((er) => {
|
|
237
|
+
if (er.name === 'CancelError') ;
|
|
238
|
+
throw er;
|
|
239
|
+
});
|
|
240
|
+
this._requests.push(request);
|
|
241
|
+
const items = await request;
|
|
242
|
+
if (items) {
|
|
243
|
+
for (const i of items) {
|
|
244
|
+
i.result = () => this.result(i);
|
|
245
|
+
yield i;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
result(model) {
|
|
250
|
+
return CancelablePromise.resolve({
|
|
251
|
+
text: model.text,
|
|
252
|
+
extent: model.extent || [],
|
|
253
|
+
geom: model.geom,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
449
257
|
|
|
450
|
-
|
|
451
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Modern geocoder on async generators. May use different data providers.
|
|
260
|
+
*
|
|
261
|
+
* @packageDocumentation
|
|
262
|
+
* @module geocoder
|
|
263
|
+
*/
|
|
264
|
+
function create(options) {
|
|
265
|
+
return new Geocoder(options);
|
|
452
266
|
}
|
|
453
267
|
|
|
454
268
|
export { BaseProvider, Geocoder, NgwProvider, NominatimProvider, create };
|