@nextgis/geocoder 2.5.0 → 3.0.0-alpha.1
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/lib/geocoder.cjs.js +53 -64
- 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 +446 -651
- 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 +53 -64
- 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 +446 -651
- 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 +6 -7
- package/package.json +7 -7
package/lib/geocoder.global.js
CHANGED
|
@@ -1,309 +1,7 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version:
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.1; author: NextGIS */
|
|
2
2
|
var Geocoder = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
var __defProp$g = Object.defineProperty;
|
|
6
|
-
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
|
|
8
|
-
class CancelError extends Error {
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
__publicField$e(this, "name", "CancelError");
|
|
12
|
-
Object.setPrototypeOf(this, CancelError.prototype);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var __defProp$f = Object.defineProperty;
|
|
17
|
-
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
-
var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
|
|
19
|
-
class PromiseControl {
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
this.options = options;
|
|
22
|
-
__publicField$d(this, "_promises", /* @__PURE__ */ new Map());
|
|
23
|
-
}
|
|
24
|
-
get isLoaded() {
|
|
25
|
-
return this._promises.size > 0;
|
|
26
|
-
}
|
|
27
|
-
remove(promise) {
|
|
28
|
-
if (this._promises.has(promise)) {
|
|
29
|
-
this._promises.delete(promise);
|
|
30
|
-
this._onStop();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
get(promise) {
|
|
34
|
-
return this._promises.get(promise);
|
|
35
|
-
}
|
|
36
|
-
add(promise, name) {
|
|
37
|
-
const key = name ? name : promise;
|
|
38
|
-
const exist = this._promises.get(key);
|
|
39
|
-
if (this.options.onStart && !this.isLoaded) {
|
|
40
|
-
this.options.onStart();
|
|
41
|
-
}
|
|
42
|
-
if (exist) {
|
|
43
|
-
return exist;
|
|
44
|
-
}
|
|
45
|
-
this._promises.set(key, promise);
|
|
46
|
-
promise.finally(() => {
|
|
47
|
-
this.remove(key);
|
|
48
|
-
});
|
|
49
|
-
return promise;
|
|
50
|
-
}
|
|
51
|
-
abort() {
|
|
52
|
-
if (this.isLoaded) {
|
|
53
|
-
this._promises.forEach((x) => {
|
|
54
|
-
if (x.cancel) {
|
|
55
|
-
x.cancel();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
this._promises.clear();
|
|
59
|
-
this._onStop();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
waitFunc(func, name = "") {
|
|
63
|
-
name = name || func.name;
|
|
64
|
-
const exist = this.get(name);
|
|
65
|
-
if (exist) {
|
|
66
|
-
return exist;
|
|
67
|
-
}
|
|
68
|
-
return this.add(func(), name);
|
|
69
|
-
}
|
|
70
|
-
WaitForMe(name = "") {
|
|
71
|
-
const get = this.get.bind(this);
|
|
72
|
-
const add = this.add.bind(this);
|
|
73
|
-
return function(target, key, descriptor) {
|
|
74
|
-
const originalMethod = descriptor.value;
|
|
75
|
-
name = name || key;
|
|
76
|
-
descriptor.value = function(...args) {
|
|
77
|
-
const exist = get(name);
|
|
78
|
-
if (exist) {
|
|
79
|
-
return exist;
|
|
80
|
-
}
|
|
81
|
-
const result = add(originalMethod.apply(this, args), name);
|
|
82
|
-
return result;
|
|
83
|
-
};
|
|
84
|
-
return descriptor;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
88
|
-
GetOrCreateDecorator(name = "") {
|
|
89
|
-
return this.WaitForMe(name);
|
|
90
|
-
}
|
|
91
|
-
_onStop() {
|
|
92
|
-
if (this.options.onStop && !this.isLoaded) {
|
|
93
|
-
this.options.onStop();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
var __defProp$e = Object.defineProperty;
|
|
99
|
-
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
100
|
-
var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
|
|
101
|
-
class TimeoutError extends Error {
|
|
102
|
-
constructor() {
|
|
103
|
-
super();
|
|
104
|
-
__publicField$c(this, "name", "TimeoutError");
|
|
105
|
-
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
var __defProp$d = Object.defineProperty;
|
|
110
|
-
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
111
|
-
var __publicField$b = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
112
|
-
var _a;
|
|
113
|
-
const handleCallback = (resolve, reject, callback, r) => {
|
|
114
|
-
try {
|
|
115
|
-
resolve(callback(r));
|
|
116
|
-
} catch (e) {
|
|
117
|
-
reject(e);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
let ID$2 = 0;
|
|
121
|
-
_a = Symbol.toStringTag;
|
|
122
|
-
const _CancelablePromise = class _CancelablePromise {
|
|
123
|
-
constructor(executor, timeout) {
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
__publicField$b(this, _a);
|
|
126
|
-
__publicField$b(this, "id", ID$2++);
|
|
127
|
-
__publicField$b(this, "_isCanceled", false);
|
|
128
|
-
__publicField$b(this, "_isPending", true);
|
|
129
|
-
__publicField$b(this, "_promise");
|
|
130
|
-
__publicField$b(this, "_cancelPromise");
|
|
131
|
-
__publicField$b(this, "_cancelHandlers", []);
|
|
132
|
-
__publicField$b(this, "_setCanceledCallback");
|
|
133
|
-
__publicField$b(this, "_parentPromise");
|
|
134
|
-
__publicField$b(this, "_children", []);
|
|
135
|
-
this._cancelPromise = new Promise((resolve_, reject_) => {
|
|
136
|
-
this._setCanceledCallback = (er) => resolve_(er || new CancelError());
|
|
137
|
-
});
|
|
138
|
-
const promises = [
|
|
139
|
-
this._cancelPromise,
|
|
140
|
-
new Promise((resolve, reject) => {
|
|
141
|
-
const onResolve = (value) => {
|
|
142
|
-
if (value instanceof _CancelablePromise) {
|
|
143
|
-
this.attach(value);
|
|
144
|
-
} else {
|
|
145
|
-
this._isPending = false;
|
|
146
|
-
}
|
|
147
|
-
resolve(value);
|
|
148
|
-
};
|
|
149
|
-
const onReject = (error) => {
|
|
150
|
-
this._isPending = false;
|
|
151
|
-
reject(error);
|
|
152
|
-
};
|
|
153
|
-
const onCancel = (handler) => {
|
|
154
|
-
if (!this._isPending) {
|
|
155
|
-
throw new Error(
|
|
156
|
-
"The `onCancel` handler was attached after the promise settled."
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
this._cancelHandlers.push(handler);
|
|
160
|
-
};
|
|
161
|
-
return executor(onResolve, onReject, onCancel);
|
|
162
|
-
})
|
|
163
|
-
];
|
|
164
|
-
if (timeout) {
|
|
165
|
-
promises.push(
|
|
166
|
-
new Promise((resolve, reject) => {
|
|
167
|
-
setTimeout(() => {
|
|
168
|
-
if (this._isPending) {
|
|
169
|
-
try {
|
|
170
|
-
this.cancel();
|
|
171
|
-
} finally {
|
|
172
|
-
reject(new TimeoutError());
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}, timeout);
|
|
176
|
-
})
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
this._promise = Promise.race(promises);
|
|
180
|
-
}
|
|
181
|
-
static createControl(opt) {
|
|
182
|
-
return new PromiseControl(opt);
|
|
183
|
-
}
|
|
184
|
-
static resolve(value) {
|
|
185
|
-
return new _CancelablePromise((resolve) => resolve(value));
|
|
186
|
-
}
|
|
187
|
-
static reject(value) {
|
|
188
|
-
return new _CancelablePromise((resolve, reject) => reject(value));
|
|
189
|
-
}
|
|
190
|
-
static all(values) {
|
|
191
|
-
return new _CancelablePromise((resolve, reject) => {
|
|
192
|
-
Promise.all(values).then(resolve).catch(reject);
|
|
193
|
-
}).catch((er) => {
|
|
194
|
-
if (er instanceof this.CancelError) {
|
|
195
|
-
for (const v of values) {
|
|
196
|
-
const v_ = v;
|
|
197
|
-
if ("cancel" in v_) {
|
|
198
|
-
v_.cancel();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
throw er;
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
attach(p) {
|
|
206
|
-
if (this._isCanceled) {
|
|
207
|
-
p.cancel();
|
|
208
|
-
} else {
|
|
209
|
-
this._children.push(p);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
then(onfulfilled, onrejected) {
|
|
213
|
-
const p = new _CancelablePromise((resolve, reject) => {
|
|
214
|
-
if (this._promise) {
|
|
215
|
-
const reject_ = (r) => {
|
|
216
|
-
if (onrejected) {
|
|
217
|
-
handleCallback(resolve, reject, onrejected, r);
|
|
218
|
-
} else {
|
|
219
|
-
reject(r);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
this._promise.then((r) => {
|
|
223
|
-
if (this._isCanceled) {
|
|
224
|
-
reject_(r);
|
|
225
|
-
} else {
|
|
226
|
-
if (onfulfilled) {
|
|
227
|
-
handleCallback(resolve, reject, onfulfilled, r);
|
|
228
|
-
} else {
|
|
229
|
-
resolve(r);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}, reject_);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
p._parentPromise = this;
|
|
236
|
-
this._children.push(p);
|
|
237
|
-
return p;
|
|
238
|
-
}
|
|
239
|
-
catch(onrejected) {
|
|
240
|
-
if (this._isCanceled && onrejected) {
|
|
241
|
-
onrejected(new CancelError());
|
|
242
|
-
}
|
|
243
|
-
return this.then(void 0, onrejected);
|
|
244
|
-
}
|
|
245
|
-
finally(onfinally) {
|
|
246
|
-
if (this._promise) {
|
|
247
|
-
return this._promise.finally(onfinally);
|
|
248
|
-
}
|
|
249
|
-
if (this._isCanceled) {
|
|
250
|
-
return Promise.reject(new CancelError());
|
|
251
|
-
}
|
|
252
|
-
return Promise.reject(onfinally);
|
|
253
|
-
}
|
|
254
|
-
cancel() {
|
|
255
|
-
if (this._isCanceled || !this._isPending) {
|
|
256
|
-
return this;
|
|
257
|
-
}
|
|
258
|
-
this._isCanceled = true;
|
|
259
|
-
const parent = this._getTopParent();
|
|
260
|
-
if (parent) {
|
|
261
|
-
parent.cancel();
|
|
262
|
-
}
|
|
263
|
-
if (this._children) {
|
|
264
|
-
this._children.forEach((x) => x.cancel());
|
|
265
|
-
}
|
|
266
|
-
if (this._isPending) {
|
|
267
|
-
if (this._cancelHandlers.length) {
|
|
268
|
-
try {
|
|
269
|
-
for (const handler of this._cancelHandlers) {
|
|
270
|
-
handler();
|
|
271
|
-
}
|
|
272
|
-
} catch (error) {
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (this._setCanceledCallback) {
|
|
276
|
-
this._setCanceledCallback();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
this._destroy();
|
|
280
|
-
return this;
|
|
281
|
-
}
|
|
282
|
-
_getTopParent() {
|
|
283
|
-
let parent = this._parentPromise;
|
|
284
|
-
let hasParent = !!parent;
|
|
285
|
-
while (hasParent) {
|
|
286
|
-
if (parent && parent._parentPromise) {
|
|
287
|
-
parent = parent._parentPromise;
|
|
288
|
-
hasParent = !!parent;
|
|
289
|
-
} else {
|
|
290
|
-
hasParent = false;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return parent;
|
|
294
|
-
}
|
|
295
|
-
_destroy() {
|
|
296
|
-
this._setCanceledCallback = void 0;
|
|
297
|
-
this._cancelPromise = void 0;
|
|
298
|
-
this._promise = void 0;
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
__publicField$b(_CancelablePromise, "CancelError", CancelError);
|
|
302
|
-
__publicField$b(_CancelablePromise, "TimeoutError", TimeoutError);
|
|
303
|
-
__publicField$b(_CancelablePromise, "PromiseControl", PromiseControl);
|
|
304
|
-
let CancelablePromise = _CancelablePromise;
|
|
305
|
-
Object.setPrototypeOf(CancelablePromise.prototype, Promise.prototype);
|
|
306
|
-
|
|
307
5
|
function defined(val) {
|
|
308
6
|
return val !== void 0 && val !== null;
|
|
309
7
|
}
|
|
@@ -409,28 +107,28 @@ var Geocoder = (function (exports) {
|
|
|
409
107
|
}
|
|
410
108
|
}
|
|
411
109
|
|
|
412
|
-
var __defProp$
|
|
110
|
+
var __defProp$d = Object.defineProperty;
|
|
413
111
|
var __defProps$3 = Object.defineProperties;
|
|
414
112
|
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
415
|
-
var __getOwnPropSymbols$
|
|
416
|
-
var __hasOwnProp$
|
|
417
|
-
var __propIsEnum$
|
|
113
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
114
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
115
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
418
116
|
var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
419
|
-
var __defNormalProp$
|
|
420
|
-
var __spreadValues$
|
|
117
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
118
|
+
var __spreadValues$6 = (a, b) => {
|
|
421
119
|
for (var prop in b || (b = {}))
|
|
422
|
-
if (__hasOwnProp$
|
|
423
|
-
__defNormalProp$
|
|
424
|
-
if (__getOwnPropSymbols$
|
|
425
|
-
for (var prop of __getOwnPropSymbols$
|
|
426
|
-
if (__propIsEnum$
|
|
427
|
-
__defNormalProp$
|
|
120
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
121
|
+
__defNormalProp$d(a, prop, b[prop]);
|
|
122
|
+
if (__getOwnPropSymbols$6)
|
|
123
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
124
|
+
if (__propIsEnum$6.call(b, prop))
|
|
125
|
+
__defNormalProp$d(a, prop, b[prop]);
|
|
428
126
|
}
|
|
429
127
|
return a;
|
|
430
128
|
};
|
|
431
129
|
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
432
|
-
var __publicField$a = (obj, key, value) => __defNormalProp$
|
|
433
|
-
var __async$
|
|
130
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$d(obj, key + "" , value);
|
|
131
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
434
132
|
return new Promise((resolve, reject) => {
|
|
435
133
|
var fulfilled = (value) => {
|
|
436
134
|
try {
|
|
@@ -494,7 +192,7 @@ var Geocoder = (function (exports) {
|
|
|
494
192
|
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
495
193
|
const r = temp.value;
|
|
496
194
|
allProvidersFailed = false;
|
|
497
|
-
yield __spreadProps$3(__spreadValues$
|
|
195
|
+
yield __spreadProps$3(__spreadValues$6({}, r), { provider, _id: ID$1++ });
|
|
498
196
|
}
|
|
499
197
|
} catch (temp) {
|
|
500
198
|
error = [temp];
|
|
@@ -524,7 +222,7 @@ var Geocoder = (function (exports) {
|
|
|
524
222
|
if (item.provider) {
|
|
525
223
|
return item.provider.result(item);
|
|
526
224
|
}
|
|
527
|
-
return
|
|
225
|
+
return Promise.resolve(void 0);
|
|
528
226
|
}
|
|
529
227
|
reverse(coordinates) {
|
|
530
228
|
return __asyncGenerator$2(this, null, function* () {
|
|
@@ -537,7 +235,7 @@ var Geocoder = (function (exports) {
|
|
|
537
235
|
try {
|
|
538
236
|
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
539
237
|
const r = temp.value;
|
|
540
|
-
yield __spreadProps$3(__spreadValues$
|
|
238
|
+
yield __spreadProps$3(__spreadValues$6({}, r), { provider, _id: ID$1++ });
|
|
541
239
|
}
|
|
542
240
|
} catch (temp) {
|
|
543
241
|
error = [temp];
|
|
@@ -561,7 +259,7 @@ var Geocoder = (function (exports) {
|
|
|
561
259
|
* @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
|
|
562
260
|
*/
|
|
563
261
|
reverseGeocodeFirstResult(coordinates) {
|
|
564
|
-
return __async$
|
|
262
|
+
return __async$5(this, null, function* () {
|
|
565
263
|
for (const provider of this.providers) {
|
|
566
264
|
if (typeof provider.reverse === "function") {
|
|
567
265
|
try {
|
|
@@ -590,9 +288,9 @@ var Geocoder = (function (exports) {
|
|
|
590
288
|
}
|
|
591
289
|
}
|
|
592
290
|
|
|
593
|
-
var __defProp$
|
|
594
|
-
var __defNormalProp$
|
|
595
|
-
var __publicField$9 = (obj, key, value) => __defNormalProp$
|
|
291
|
+
var __defProp$c = Object.defineProperty;
|
|
292
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
293
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
596
294
|
class BaseProvider extends BaseGeocoder {
|
|
597
295
|
constructor() {
|
|
598
296
|
super(...arguments);
|
|
@@ -1081,9 +779,9 @@ var Geocoder = (function (exports) {
|
|
|
1081
779
|
return ret;
|
|
1082
780
|
}
|
|
1083
781
|
|
|
1084
|
-
var __defProp$
|
|
1085
|
-
var __defNormalProp$
|
|
1086
|
-
var __publicField$8 = (obj, key, value) => __defNormalProp$
|
|
782
|
+
var __defProp$b = Object.defineProperty;
|
|
783
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
784
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1087
785
|
const _Cache = class _Cache {
|
|
1088
786
|
constructor(options = {}) {
|
|
1089
787
|
__publicField$8(this, "cache", []);
|
|
@@ -1119,8 +817,7 @@ var Geocoder = (function (exports) {
|
|
|
1119
817
|
* // somewhere else in the code
|
|
1120
818
|
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
1121
819
|
* console.log(resp); // 'New item'
|
|
1122
|
-
* })
|
|
1123
|
-
*
|
|
820
|
+
* });
|
|
1124
821
|
* ```
|
|
1125
822
|
*/
|
|
1126
823
|
addFull(key, valueToSet, props) {
|
|
@@ -1135,13 +832,11 @@ var Geocoder = (function (exports) {
|
|
|
1135
832
|
} else {
|
|
1136
833
|
value = valueToSet;
|
|
1137
834
|
}
|
|
1138
|
-
const
|
|
835
|
+
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
1139
836
|
const cacheItem = {
|
|
1140
837
|
key,
|
|
1141
838
|
value,
|
|
1142
|
-
props:
|
|
1143
|
-
// TODO: remove backward compatibility use only props
|
|
1144
|
-
options: props_
|
|
839
|
+
props: nonEmptyProps
|
|
1145
840
|
};
|
|
1146
841
|
if (onlyFull && !full(value)) {
|
|
1147
842
|
return value;
|
|
@@ -1150,7 +845,6 @@ var Geocoder = (function (exports) {
|
|
|
1150
845
|
if (value instanceof Promise) {
|
|
1151
846
|
value.catch((er) => {
|
|
1152
847
|
this.delete(key, props);
|
|
1153
|
-
throw er;
|
|
1154
848
|
});
|
|
1155
849
|
if (onlyFull) {
|
|
1156
850
|
value.then((x) => {
|
|
@@ -1169,9 +863,7 @@ var Geocoder = (function (exports) {
|
|
|
1169
863
|
}
|
|
1170
864
|
match(key, props) {
|
|
1171
865
|
const cacheRecord = this._find(key, props);
|
|
1172
|
-
|
|
1173
|
-
return cacheRecord.value;
|
|
1174
|
-
}
|
|
866
|
+
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
1175
867
|
}
|
|
1176
868
|
matchAll(key, props) {
|
|
1177
869
|
if (key) {
|
|
@@ -1180,37 +872,30 @@ var Geocoder = (function (exports) {
|
|
|
1180
872
|
return this.cache.map((x) => x.value);
|
|
1181
873
|
}
|
|
1182
874
|
delete(keyOrItem, props) {
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
for (const e of exist) {
|
|
1190
|
-
const index = this.cache.indexOf(e);
|
|
1191
|
-
this.cache.splice(index, 1);
|
|
875
|
+
const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
|
|
876
|
+
for (const item of itemsToDelete) {
|
|
877
|
+
const index = this.cache.indexOf(item);
|
|
878
|
+
if (index !== -1) {
|
|
879
|
+
this.cache.splice(index, 1);
|
|
880
|
+
}
|
|
1192
881
|
}
|
|
1193
882
|
}
|
|
1194
883
|
_find(key, props) {
|
|
1195
884
|
return this.cache.find((x) => this._filter(x, key, props));
|
|
1196
885
|
}
|
|
1197
886
|
_filter(item, key, props) {
|
|
1198
|
-
if (item.key
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
}
|
|
1203
|
-
return true;
|
|
1204
|
-
}
|
|
1205
|
-
return false;
|
|
887
|
+
if (item.key !== key) return false;
|
|
888
|
+
if (!props) return true;
|
|
889
|
+
const itemProps = item.props;
|
|
890
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
1206
891
|
}
|
|
1207
892
|
};
|
|
1208
893
|
__publicField$8(_Cache, "instance", {});
|
|
1209
894
|
let Cache = _Cache;
|
|
1210
895
|
|
|
1211
|
-
var __defProp$
|
|
1212
|
-
var __defNormalProp$
|
|
1213
|
-
var __publicField$7 = (obj, key, value) => __defNormalProp$
|
|
896
|
+
var __defProp$a = Object.defineProperty;
|
|
897
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
898
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1214
899
|
class NgwError extends Error {
|
|
1215
900
|
constructor(er) {
|
|
1216
901
|
super();
|
|
@@ -1227,9 +912,9 @@ var Geocoder = (function (exports) {
|
|
|
1227
912
|
}
|
|
1228
913
|
}
|
|
1229
914
|
|
|
1230
|
-
var __defProp$
|
|
1231
|
-
var __defNormalProp$
|
|
1232
|
-
var __publicField$6 = (obj, key, value) => __defNormalProp$
|
|
915
|
+
var __defProp$9 = Object.defineProperty;
|
|
916
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
917
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1233
918
|
class ResourceNotFoundError extends NgwError {
|
|
1234
919
|
constructor(obj) {
|
|
1235
920
|
super(obj);
|
|
@@ -1268,27 +953,24 @@ var Geocoder = (function (exports) {
|
|
|
1268
953
|
return query;
|
|
1269
954
|
}
|
|
1270
955
|
|
|
1271
|
-
var __defProp$
|
|
1272
|
-
var
|
|
1273
|
-
var
|
|
1274
|
-
var
|
|
1275
|
-
var
|
|
1276
|
-
var
|
|
1277
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1278
|
-
var __spreadValues$4 = (a, b) => {
|
|
956
|
+
var __defProp$8 = Object.defineProperty;
|
|
957
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
958
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
959
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
960
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
961
|
+
var __spreadValues$5 = (a, b) => {
|
|
1279
962
|
for (var prop in b || (b = {}))
|
|
1280
|
-
if (__hasOwnProp$
|
|
1281
|
-
__defNormalProp$
|
|
1282
|
-
if (__getOwnPropSymbols$
|
|
1283
|
-
for (var prop of __getOwnPropSymbols$
|
|
1284
|
-
if (__propIsEnum$
|
|
1285
|
-
__defNormalProp$
|
|
963
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
964
|
+
__defNormalProp$8(a, prop, b[prop]);
|
|
965
|
+
if (__getOwnPropSymbols$5)
|
|
966
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
967
|
+
if (__propIsEnum$5.call(b, prop))
|
|
968
|
+
__defNormalProp$8(a, prop, b[prop]);
|
|
1286
969
|
}
|
|
1287
970
|
return a;
|
|
1288
971
|
};
|
|
1289
|
-
var
|
|
1290
|
-
var
|
|
1291
|
-
var __async = (__this, __arguments, generator) => {
|
|
972
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
973
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
1292
974
|
return new Promise((resolve, reject) => {
|
|
1293
975
|
var fulfilled = (value) => {
|
|
1294
976
|
try {
|
|
@@ -1329,39 +1011,27 @@ var Geocoder = (function (exports) {
|
|
|
1329
1011
|
* Fetching resource would be cached to speed up next call
|
|
1330
1012
|
*/
|
|
1331
1013
|
getOne(resource, requestOptions) {
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
const opt = __spreadProps$2(__spreadValues$4({}, requestOptions), { cache: false });
|
|
1335
|
-
if (typeof resource === "string") {
|
|
1336
|
-
forCache.keyname = resource;
|
|
1337
|
-
} else if (typeof resource === "number") {
|
|
1338
|
-
forCache.id = resource;
|
|
1339
|
-
} else if (isObject(resource)) {
|
|
1014
|
+
const opt = __spreadValues$5({}, requestOptions);
|
|
1015
|
+
if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
|
|
1340
1016
|
if (resource.id !== void 0) {
|
|
1341
|
-
|
|
1017
|
+
resource.id;
|
|
1342
1018
|
} else {
|
|
1343
1019
|
if (resource.keyname) {
|
|
1344
|
-
|
|
1020
|
+
resource.keyname;
|
|
1345
1021
|
}
|
|
1346
1022
|
if (resource.display_name) {
|
|
1347
|
-
|
|
1023
|
+
resource.display_name;
|
|
1348
1024
|
}
|
|
1349
1025
|
}
|
|
1350
1026
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
return this._fetchResourceBy(resource, opt);
|
|
1358
|
-
}
|
|
1359
|
-
return CancelablePromise.resolve(void 0);
|
|
1360
|
-
};
|
|
1361
|
-
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
1362
|
-
return cache.addFull("resource", makeRequest, forCache);
|
|
1027
|
+
if (typeof resource === "string") {
|
|
1028
|
+
return this._fetchResourceBy({ keyname: resource }, opt);
|
|
1029
|
+
} else if (typeof resource === "number") {
|
|
1030
|
+
return this._fetchResourceById(resource, opt);
|
|
1031
|
+
} else if (isObject(resource)) {
|
|
1032
|
+
return this._fetchResourceBy(resource, opt);
|
|
1363
1033
|
}
|
|
1364
|
-
return
|
|
1034
|
+
return Promise.resolve(void 0);
|
|
1365
1035
|
}
|
|
1366
1036
|
getOneOrFail(resource, requestOptions) {
|
|
1367
1037
|
return this.getOne(resource, requestOptions).then((res) => {
|
|
@@ -1383,7 +1053,7 @@ var Geocoder = (function (exports) {
|
|
|
1383
1053
|
*/
|
|
1384
1054
|
getId(resource, requestOptions) {
|
|
1385
1055
|
if (typeof resource === "number") {
|
|
1386
|
-
return
|
|
1056
|
+
return Promise.resolve(resource);
|
|
1387
1057
|
} else if (typeof resource === "string" || isObject(resource)) {
|
|
1388
1058
|
return this.getOne(resource, requestOptions).then((res) => {
|
|
1389
1059
|
if (res) {
|
|
@@ -1391,7 +1061,7 @@ var Geocoder = (function (exports) {
|
|
|
1391
1061
|
}
|
|
1392
1062
|
});
|
|
1393
1063
|
}
|
|
1394
|
-
return
|
|
1064
|
+
return Promise.resolve(void 0);
|
|
1395
1065
|
}
|
|
1396
1066
|
/**
|
|
1397
1067
|
* A fast way to retrieve resource ID for any resource definition.
|
|
@@ -1418,12 +1088,12 @@ var Geocoder = (function (exports) {
|
|
|
1418
1088
|
} else {
|
|
1419
1089
|
Object.assign(query, resourceToQuery(resource));
|
|
1420
1090
|
}
|
|
1421
|
-
return this.connector.get("resource.search", requestOptions, __spreadValues$
|
|
1091
|
+
return this.connector.get("resource.search", requestOptions, __spreadValues$5({
|
|
1422
1092
|
serialization: "full"
|
|
1423
1093
|
}, query)).then((resources) => {
|
|
1424
|
-
if (resources) {
|
|
1094
|
+
if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
|
|
1425
1095
|
for (const x of resources) {
|
|
1426
|
-
this.cache.add("resource.item",
|
|
1096
|
+
this.cache.add("resource.item", Promise.resolve(x), {
|
|
1427
1097
|
id: x.resource.id
|
|
1428
1098
|
});
|
|
1429
1099
|
}
|
|
@@ -1439,7 +1109,7 @@ var Geocoder = (function (exports) {
|
|
|
1439
1109
|
if (child) {
|
|
1440
1110
|
return this.getOne(child.resource.parent.id, requestOptions);
|
|
1441
1111
|
}
|
|
1442
|
-
return
|
|
1112
|
+
return Promise.resolve(void 0);
|
|
1443
1113
|
});
|
|
1444
1114
|
}
|
|
1445
1115
|
getChildrenOf(resource, requestOptions) {
|
|
@@ -1469,18 +1139,16 @@ var Geocoder = (function (exports) {
|
|
|
1469
1139
|
});
|
|
1470
1140
|
}
|
|
1471
1141
|
_getChildrenOf(parent, requestOptions, _items = []) {
|
|
1472
|
-
return this.connector.get(
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
{
|
|
1476
|
-
parent
|
|
1477
|
-
}
|
|
1478
|
-
).then((items) => {
|
|
1142
|
+
return this.connector.get("resource.collection", requestOptions, {
|
|
1143
|
+
parent
|
|
1144
|
+
}).then((items) => {
|
|
1479
1145
|
const recursivePromises = [];
|
|
1480
1146
|
for (const item of items) {
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1147
|
+
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
1148
|
+
this.cache.add("resource.item", Promise.resolve(item), {
|
|
1149
|
+
id: item.resource.id
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1484
1152
|
_items.push(item);
|
|
1485
1153
|
if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1486
1154
|
recursivePromises.push(
|
|
@@ -1489,7 +1157,7 @@ var Geocoder = (function (exports) {
|
|
|
1489
1157
|
}
|
|
1490
1158
|
}
|
|
1491
1159
|
if (recursivePromises.length) {
|
|
1492
|
-
return
|
|
1160
|
+
return Promise.all(recursivePromises).then(() => {
|
|
1493
1161
|
return _items;
|
|
1494
1162
|
});
|
|
1495
1163
|
}
|
|
@@ -1497,11 +1165,12 @@ var Geocoder = (function (exports) {
|
|
|
1497
1165
|
});
|
|
1498
1166
|
}
|
|
1499
1167
|
_cleanResourceItemCache(id) {
|
|
1500
|
-
return __async(this, null, function* () {
|
|
1168
|
+
return __async$4(this, null, function* () {
|
|
1169
|
+
var _a;
|
|
1501
1170
|
const all = this.cache.all();
|
|
1502
1171
|
const toDelete = [];
|
|
1503
1172
|
for (const c of all) {
|
|
1504
|
-
const cid = c.
|
|
1173
|
+
const cid = (_a = c.props) == null ? void 0 : _a.id;
|
|
1505
1174
|
if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
|
|
1506
1175
|
if (typeof cid === "number") {
|
|
1507
1176
|
if (cid === id) {
|
|
@@ -1521,18 +1190,7 @@ var Geocoder = (function (exports) {
|
|
|
1521
1190
|
});
|
|
1522
1191
|
}
|
|
1523
1192
|
_fetchResourceById(id, requestOptions) {
|
|
1524
|
-
|
|
1525
|
-
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
1526
|
-
return this.cache.add("resource.item", promise, {
|
|
1527
|
-
id
|
|
1528
|
-
}).catch((er) => {
|
|
1529
|
-
if (!(er instanceof ResourceNotFoundError)) {
|
|
1530
|
-
throw er;
|
|
1531
|
-
}
|
|
1532
|
-
return void 0;
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
return promise();
|
|
1193
|
+
return this.connector.get("resource.item", requestOptions, { id });
|
|
1536
1194
|
}
|
|
1537
1195
|
_fetchResourceBy(resource, requestOptions) {
|
|
1538
1196
|
return this.getMany(resource, requestOptions).then((resources) => {
|
|
@@ -1540,7 +1198,7 @@ var Geocoder = (function (exports) {
|
|
|
1540
1198
|
});
|
|
1541
1199
|
}
|
|
1542
1200
|
_resourceCacheFilter(resource) {
|
|
1543
|
-
return
|
|
1201
|
+
return Promise.all(this.cache.matchAll("resource.item")).then(
|
|
1544
1202
|
(resources) => {
|
|
1545
1203
|
const items = [];
|
|
1546
1204
|
resources.filter((x) => {
|
|
@@ -1584,9 +1242,16 @@ var Geocoder = (function (exports) {
|
|
|
1584
1242
|
}
|
|
1585
1243
|
}
|
|
1586
1244
|
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1245
|
+
class AbortError extends Error {
|
|
1246
|
+
constructor(message = "AbortError") {
|
|
1247
|
+
super(message);
|
|
1248
|
+
this.name = "AbortError";
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
var __defProp$7 = Object.defineProperty;
|
|
1253
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1254
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1590
1255
|
class InsufficientPermissionsError extends NgwError {
|
|
1591
1256
|
constructor(obj) {
|
|
1592
1257
|
super(obj);
|
|
@@ -1609,58 +1274,90 @@ var Geocoder = (function (exports) {
|
|
|
1609
1274
|
});
|
|
1610
1275
|
}
|
|
1611
1276
|
|
|
1277
|
+
var __defProp$6 = Object.defineProperty;
|
|
1278
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
1279
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
1280
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
1281
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1282
|
+
var __spreadValues$4 = (a, b) => {
|
|
1283
|
+
for (var prop in b || (b = {}))
|
|
1284
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
1285
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
1286
|
+
if (__getOwnPropSymbols$4)
|
|
1287
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
1288
|
+
if (__propIsEnum$4.call(b, prop))
|
|
1289
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
1290
|
+
}
|
|
1291
|
+
return a;
|
|
1292
|
+
};
|
|
1293
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
1294
|
+
return new Promise((resolve, reject) => {
|
|
1295
|
+
var fulfilled = (value) => {
|
|
1296
|
+
try {
|
|
1297
|
+
step(generator.next(value));
|
|
1298
|
+
} catch (e) {
|
|
1299
|
+
reject(e);
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
var rejected = (value) => {
|
|
1303
|
+
try {
|
|
1304
|
+
step(generator.throw(value));
|
|
1305
|
+
} catch (e) {
|
|
1306
|
+
reject(e);
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1310
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1311
|
+
});
|
|
1312
|
+
};
|
|
1612
1313
|
function apiRequest(opt) {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
"`" + arg + "` url api argument is not specified"
|
|
1628
|
-
);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
if (url) {
|
|
1632
|
-
url = template(url, replaceParams);
|
|
1314
|
+
return __async$3(this, null, function* () {
|
|
1315
|
+
const { params, name, connector, requestOptions } = opt;
|
|
1316
|
+
const apiItems = yield connector.connect();
|
|
1317
|
+
let apiItem = apiItems && apiItems[name];
|
|
1318
|
+
if (apiItem) {
|
|
1319
|
+
apiItem = [...apiItem];
|
|
1320
|
+
let url = apiItem.shift();
|
|
1321
|
+
if (apiItem.length) {
|
|
1322
|
+
const replaceParams = {};
|
|
1323
|
+
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
1324
|
+
const arg = apiItem[fry];
|
|
1325
|
+
replaceParams[fry] = `{${arg}}`;
|
|
1326
|
+
if (params[arg] === void 0) {
|
|
1327
|
+
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
1633
1328
|
}
|
|
1634
1329
|
}
|
|
1635
|
-
if (
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
url = url + "?" + paramArray.join("&");
|
|
1330
|
+
if (url) {
|
|
1331
|
+
url = template(url, replaceParams);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
if (params) {
|
|
1335
|
+
const paramArray = [];
|
|
1336
|
+
const paramList = params.paramList;
|
|
1337
|
+
if (Array.isArray(paramList)) {
|
|
1338
|
+
paramList.forEach(([key, value]) => {
|
|
1339
|
+
paramArray.push(`${key}=${value}`);
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
for (const p in params) {
|
|
1343
|
+
if (apiItem.indexOf(p) === -1) {
|
|
1344
|
+
paramArray.push(`${p}=${params[p]}`);
|
|
1651
1345
|
}
|
|
1652
1346
|
}
|
|
1653
|
-
if (
|
|
1654
|
-
|
|
1655
|
-
} else {
|
|
1656
|
-
reject(new Error("request url is not set"));
|
|
1347
|
+
if (paramArray.length) {
|
|
1348
|
+
url = `${url}?${paramArray.join("&")}`;
|
|
1657
1349
|
}
|
|
1350
|
+
}
|
|
1351
|
+
if (url) {
|
|
1352
|
+
return connector.makeQuery(url, params, __spreadValues$4({
|
|
1353
|
+
cacheName: name
|
|
1354
|
+
}, requestOptions));
|
|
1658
1355
|
} else {
|
|
1659
|
-
|
|
1356
|
+
throw new Error("Request URL is not set");
|
|
1660
1357
|
}
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1358
|
+
} else {
|
|
1359
|
+
return void 0;
|
|
1360
|
+
}
|
|
1664
1361
|
});
|
|
1665
1362
|
}
|
|
1666
1363
|
|
|
@@ -1760,6 +1457,8 @@ var Geocoder = (function (exports) {
|
|
|
1760
1457
|
}
|
|
1761
1458
|
|
|
1762
1459
|
var __defProp$4 = Object.defineProperty;
|
|
1460
|
+
var __defProps$2 = Object.defineProperties;
|
|
1461
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1763
1462
|
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
1764
1463
|
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
1765
1464
|
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
@@ -1775,8 +1474,42 @@ var Geocoder = (function (exports) {
|
|
|
1775
1474
|
}
|
|
1776
1475
|
return a;
|
|
1777
1476
|
};
|
|
1477
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
1478
|
+
var __objRest = (source, exclude) => {
|
|
1479
|
+
var target = {};
|
|
1480
|
+
for (var prop in source)
|
|
1481
|
+
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1482
|
+
target[prop] = source[prop];
|
|
1483
|
+
if (source != null && __getOwnPropSymbols$3)
|
|
1484
|
+
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
1485
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
1486
|
+
target[prop] = source[prop];
|
|
1487
|
+
}
|
|
1488
|
+
return target;
|
|
1489
|
+
};
|
|
1778
1490
|
var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1491
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
1492
|
+
return new Promise((resolve, reject) => {
|
|
1493
|
+
var fulfilled = (value) => {
|
|
1494
|
+
try {
|
|
1495
|
+
step(generator.next(value));
|
|
1496
|
+
} catch (e) {
|
|
1497
|
+
reject(e);
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
var rejected = (value) => {
|
|
1501
|
+
try {
|
|
1502
|
+
step(generator.throw(value));
|
|
1503
|
+
} catch (e) {
|
|
1504
|
+
reject(e);
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1508
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1509
|
+
});
|
|
1510
|
+
};
|
|
1779
1511
|
let ID = 0;
|
|
1512
|
+
let REQUEST_ID = 0;
|
|
1780
1513
|
class NgwConnector {
|
|
1781
1514
|
constructor(options) {
|
|
1782
1515
|
this.options = options;
|
|
@@ -1787,7 +1520,7 @@ var Geocoder = (function (exports) {
|
|
|
1787
1520
|
__publicField$2(this, "cache");
|
|
1788
1521
|
__publicField$2(this, "withCredentials");
|
|
1789
1522
|
__publicField$2(this, "routeStr", "/api/component/pyramid/route");
|
|
1790
|
-
__publicField$2(this, "activeRequests",
|
|
1523
|
+
__publicField$2(this, "activeRequests", {});
|
|
1791
1524
|
__publicField$2(this, "requestTransform");
|
|
1792
1525
|
const exist = findConnector(options);
|
|
1793
1526
|
this.cache = new Cache({ namespace: options.cacheId });
|
|
@@ -1848,29 +1581,27 @@ var Geocoder = (function (exports) {
|
|
|
1848
1581
|
* ```
|
|
1849
1582
|
*/
|
|
1850
1583
|
connect() {
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
const makeQuery = () => {
|
|
1854
|
-
return this.makeQuery(this.routeStr, {}, {}).then((route) => {
|
|
1855
|
-
resolve(route);
|
|
1856
|
-
}).catch((er) => {
|
|
1857
|
-
reject(er);
|
|
1858
|
-
});
|
|
1859
|
-
};
|
|
1584
|
+
return __async$2(this, null, function* () {
|
|
1585
|
+
const auth = this.options.auth;
|
|
1860
1586
|
if (auth) {
|
|
1861
1587
|
const { login, password } = auth;
|
|
1862
1588
|
if (login && password) {
|
|
1863
|
-
|
|
1864
|
-
return makeQuery();
|
|
1865
|
-
}).catch((er) => reject(er));
|
|
1589
|
+
yield this._login({ login, password });
|
|
1866
1590
|
}
|
|
1867
1591
|
}
|
|
1868
|
-
return makeQuery(
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1592
|
+
return yield this.makeQuery(
|
|
1593
|
+
this.routeStr,
|
|
1594
|
+
{},
|
|
1595
|
+
{
|
|
1596
|
+
cacheName: "route",
|
|
1597
|
+
cache: true,
|
|
1598
|
+
cacheProps: {
|
|
1599
|
+
id: this.id,
|
|
1600
|
+
auth,
|
|
1601
|
+
baseUrl: this.options.baseUrl
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
);
|
|
1874
1605
|
});
|
|
1875
1606
|
}
|
|
1876
1607
|
/**
|
|
@@ -1894,20 +1625,22 @@ var Geocoder = (function (exports) {
|
|
|
1894
1625
|
this.emitter.emit("logout");
|
|
1895
1626
|
}
|
|
1896
1627
|
getUserInfo(credentials, options) {
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1628
|
+
return __async$2(this, null, function* () {
|
|
1629
|
+
if (this.user && this.user.id) {
|
|
1630
|
+
return this.user;
|
|
1631
|
+
}
|
|
1632
|
+
if (credentials) {
|
|
1633
|
+
this.options.auth = credentials;
|
|
1634
|
+
}
|
|
1635
|
+
const options_ = __spreadValues$3({
|
|
1636
|
+
headers: this.getAuthorizationHeaders(credentials)
|
|
1637
|
+
}, options);
|
|
1638
|
+
return this.makeQuery(
|
|
1639
|
+
"/api/component/auth/current_user",
|
|
1640
|
+
{},
|
|
1641
|
+
options_
|
|
1642
|
+
);
|
|
1643
|
+
});
|
|
1911
1644
|
}
|
|
1912
1645
|
/**
|
|
1913
1646
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
@@ -1916,7 +1649,7 @@ var Geocoder = (function (exports) {
|
|
|
1916
1649
|
const client = this.makeClientId(credentials);
|
|
1917
1650
|
if (client) {
|
|
1918
1651
|
return {
|
|
1919
|
-
Authorization:
|
|
1652
|
+
Authorization: `Basic ${client}`
|
|
1920
1653
|
};
|
|
1921
1654
|
}
|
|
1922
1655
|
}
|
|
@@ -1924,21 +1657,22 @@ var Geocoder = (function (exports) {
|
|
|
1924
1657
|
credentials = credentials || this.options.auth;
|
|
1925
1658
|
if (credentials) {
|
|
1926
1659
|
const { login, password } = credentials;
|
|
1927
|
-
const str =
|
|
1660
|
+
const str = `${login}:${password}`;
|
|
1661
|
+
const encodedStr = encodeURIComponent(str);
|
|
1928
1662
|
{
|
|
1929
|
-
return window.btoa(
|
|
1663
|
+
return window.btoa(encodedStr);
|
|
1930
1664
|
}
|
|
1931
1665
|
}
|
|
1932
1666
|
}
|
|
1933
1667
|
/** Stop all api requests */
|
|
1934
1668
|
abort() {
|
|
1935
|
-
for (const
|
|
1936
|
-
|
|
1669
|
+
for (const abortController of Object.values(this.activeRequests)) {
|
|
1670
|
+
abortController.abort();
|
|
1937
1671
|
}
|
|
1938
|
-
this.activeRequests =
|
|
1672
|
+
this.activeRequests = {};
|
|
1939
1673
|
}
|
|
1940
1674
|
getActiveApiRequests() {
|
|
1941
|
-
return
|
|
1675
|
+
return __spreadValues$3({}, this.activeRequests);
|
|
1942
1676
|
}
|
|
1943
1677
|
/**
|
|
1944
1678
|
* Send request to NGW api router.
|
|
@@ -1970,26 +1704,10 @@ var Geocoder = (function (exports) {
|
|
|
1970
1704
|
* ```
|
|
1971
1705
|
*/
|
|
1972
1706
|
apiRequest(name, params_ = {}, requestOptions = {}) {
|
|
1973
|
-
var _a
|
|
1974
|
-
requestOptions = __spreadValues$3({
|
|
1975
|
-
withCredentials: this.withCredentials
|
|
1976
|
-
}, requestOptions);
|
|
1977
|
-
const { method, headers, withCredentials, responseType } = requestOptions;
|
|
1707
|
+
var _a;
|
|
1978
1708
|
params_ = (_a = requestOptions.params) != null ? _a : params_;
|
|
1979
1709
|
const params = objectRemoveEmpty(params_);
|
|
1980
|
-
|
|
1981
|
-
if (requestOptions.cache && method === "GET") {
|
|
1982
|
-
return this.cache.add(name, makeApiRequest, __spreadValues$3({
|
|
1983
|
-
params
|
|
1984
|
-
}, objectRemoveEmpty({
|
|
1985
|
-
headers,
|
|
1986
|
-
withCredentials,
|
|
1987
|
-
responseType,
|
|
1988
|
-
baseUrl: this.options.baseUrl,
|
|
1989
|
-
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1990
|
-
})));
|
|
1991
|
-
}
|
|
1992
|
-
return makeApiRequest();
|
|
1710
|
+
return apiRequest({ name, params, requestOptions, connector: this });
|
|
1993
1711
|
}
|
|
1994
1712
|
/**
|
|
1995
1713
|
* Shortcut method for send POST request to NGW.
|
|
@@ -2079,17 +1797,68 @@ var Geocoder = (function (exports) {
|
|
|
2079
1797
|
* @param params - Query params
|
|
2080
1798
|
* @param options - Request options
|
|
2081
1799
|
*/
|
|
2082
|
-
makeQuery(
|
|
2083
|
-
|
|
2084
|
-
|
|
1800
|
+
makeQuery(_0, _1) {
|
|
1801
|
+
return __async$2(this, arguments, function* (url, params, options = {}) {
|
|
1802
|
+
var _b;
|
|
1803
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1804
|
+
if (!url) {
|
|
1805
|
+
throw new Error("Empty `url` not allowed");
|
|
1806
|
+
}
|
|
2085
1807
|
if (params) {
|
|
2086
|
-
|
|
1808
|
+
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1809
|
+
url = template(url, restParams);
|
|
2087
1810
|
}
|
|
2088
1811
|
url = encodeURI(fixUrlStr(url));
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
1812
|
+
options = __spreadValues$3({ withCredentials: this.withCredentials }, options);
|
|
1813
|
+
const {
|
|
1814
|
+
cache,
|
|
1815
|
+
signal: externalSignal,
|
|
1816
|
+
method = "GET",
|
|
1817
|
+
headers,
|
|
1818
|
+
cacheName,
|
|
1819
|
+
cacheProps,
|
|
1820
|
+
responseType,
|
|
1821
|
+
withCredentials
|
|
1822
|
+
} = options;
|
|
1823
|
+
const internalAbortController = new AbortController();
|
|
1824
|
+
const internalSignal = internalAbortController.signal;
|
|
1825
|
+
if (externalSignal) {
|
|
1826
|
+
if (externalSignal.aborted) {
|
|
1827
|
+
throw new AbortError();
|
|
1828
|
+
}
|
|
1829
|
+
externalSignal.addEventListener("abort", () => {
|
|
1830
|
+
internalAbortController.abort();
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
options.signal = internalSignal;
|
|
1834
|
+
const createPromise = () => __async$2(this, null, function* () {
|
|
1835
|
+
const id = REQUEST_ID++;
|
|
1836
|
+
this.activeRequests[id] = internalAbortController;
|
|
1837
|
+
try {
|
|
1838
|
+
return this._loadData(url, options);
|
|
1839
|
+
} finally {
|
|
1840
|
+
this._cleanActiveRequest(id);
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
if (cache && method === "GET") {
|
|
1844
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$3({}, objectRemoveEmpty({
|
|
1845
|
+
headers,
|
|
1846
|
+
withCredentials,
|
|
1847
|
+
responseType,
|
|
1848
|
+
baseUrl: this.options.baseUrl,
|
|
1849
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1850
|
+
})), {
|
|
1851
|
+
params
|
|
1852
|
+
});
|
|
1853
|
+
return this.cache.add(
|
|
1854
|
+
cacheName || url,
|
|
1855
|
+
createPromise,
|
|
1856
|
+
cacheOptions,
|
|
1857
|
+
false
|
|
1858
|
+
);
|
|
1859
|
+
}
|
|
1860
|
+
return createPromise();
|
|
1861
|
+
});
|
|
2093
1862
|
}
|
|
2094
1863
|
// -------------------------------------------------------------------------
|
|
2095
1864
|
// Resource Methods
|
|
@@ -2171,10 +1940,8 @@ var Geocoder = (function (exports) {
|
|
|
2171
1940
|
*/
|
|
2172
1941
|
_loadData(url, options) {
|
|
2173
1942
|
options.responseType = options.responseType || "json";
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
}
|
|
2177
|
-
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
1943
|
+
return new Promise((resolve, reject) => {
|
|
1944
|
+
var _a;
|
|
2178
1945
|
if (this.user) {
|
|
2179
1946
|
options = options || {};
|
|
2180
1947
|
options.headers = __spreadValues$3(__spreadValues$3({}, this.getAuthorizationHeaders()), options.headers);
|
|
@@ -2184,13 +1951,18 @@ var Geocoder = (function (exports) {
|
|
|
2184
1951
|
url = transUrl;
|
|
2185
1952
|
options = transOptions;
|
|
2186
1953
|
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
1954
|
+
let runOnAbort = void 0;
|
|
1955
|
+
loadData(url, resolve, options, reject, (handler) => {
|
|
1956
|
+
runOnAbort = handler;
|
|
1957
|
+
});
|
|
1958
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1959
|
+
if (runOnAbort !== void 0) {
|
|
1960
|
+
runOnAbort();
|
|
1961
|
+
}
|
|
1962
|
+
reject(new AbortError());
|
|
1963
|
+
});
|
|
2191
1964
|
}).catch((httpError) => {
|
|
2192
|
-
|
|
2193
|
-
if (httpError instanceof CancelablePromise.CancelError) ; else {
|
|
1965
|
+
if (httpError.name !== "AbortError") {
|
|
2194
1966
|
{
|
|
2195
1967
|
console.warn("DEV WARN", httpError);
|
|
2196
1968
|
}
|
|
@@ -2199,31 +1971,24 @@ var Geocoder = (function (exports) {
|
|
|
2199
1971
|
throw er;
|
|
2200
1972
|
}
|
|
2201
1973
|
}
|
|
1974
|
+
throw httpError;
|
|
2202
1975
|
});
|
|
2203
|
-
if (options.signal && typeof options.signal.addEventListener === "function") {
|
|
2204
|
-
options.signal.addEventListener("abort", () => {
|
|
2205
|
-
request.cancel();
|
|
2206
|
-
this._cleanActiveRequests(request);
|
|
2207
|
-
});
|
|
2208
|
-
}
|
|
2209
|
-
this.activeRequests.push(request);
|
|
2210
|
-
return request;
|
|
2211
1976
|
}
|
|
2212
1977
|
_login(credentials, options) {
|
|
2213
|
-
return this
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
1978
|
+
return __async$2(this, null, function* () {
|
|
1979
|
+
try {
|
|
1980
|
+
const data = yield this.getUserInfo(credentials, options);
|
|
1981
|
+
this.user = data;
|
|
1982
|
+
this.emitter.emit("login", data);
|
|
1983
|
+
return data;
|
|
1984
|
+
} catch (er) {
|
|
1985
|
+
this.emitter.emit("login:error", er);
|
|
1986
|
+
throw er;
|
|
1987
|
+
}
|
|
2220
1988
|
});
|
|
2221
1989
|
}
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
if (activeRequestIndex !== -1) {
|
|
2225
|
-
this.activeRequests.splice(activeRequestIndex, 1);
|
|
2226
|
-
}
|
|
1990
|
+
_cleanActiveRequest(requestId) {
|
|
1991
|
+
delete this.activeRequests[requestId];
|
|
2227
1992
|
}
|
|
2228
1993
|
_handleHttpError(er) {
|
|
2229
1994
|
if (er) {
|
|
@@ -2332,6 +2097,26 @@ var Geocoder = (function (exports) {
|
|
|
2332
2097
|
return a;
|
|
2333
2098
|
};
|
|
2334
2099
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
2100
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
2101
|
+
return new Promise((resolve, reject) => {
|
|
2102
|
+
var fulfilled = (value) => {
|
|
2103
|
+
try {
|
|
2104
|
+
step(generator.next(value));
|
|
2105
|
+
} catch (e) {
|
|
2106
|
+
reject(e);
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
var rejected = (value) => {
|
|
2110
|
+
try {
|
|
2111
|
+
step(generator.throw(value));
|
|
2112
|
+
} catch (e) {
|
|
2113
|
+
reject(e);
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2117
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2118
|
+
});
|
|
2119
|
+
};
|
|
2335
2120
|
const FEATURE_REQUEST_PARAMS = {
|
|
2336
2121
|
srs: 4326,
|
|
2337
2122
|
geom_format: "geojson"
|
|
@@ -2362,10 +2147,9 @@ var Geocoder = (function (exports) {
|
|
|
2362
2147
|
}
|
|
2363
2148
|
}
|
|
2364
2149
|
function createFeatureFieldFilterQueries(opt) {
|
|
2365
|
-
|
|
2366
|
-
opt
|
|
2367
|
-
|
|
2368
|
-
return CancelablePromise.all(queries).then((itemsParts) => {
|
|
2150
|
+
return __async$1(this, null, function* () {
|
|
2151
|
+
const queries = getQueries(opt);
|
|
2152
|
+
const itemsParts = yield Promise.all(queries);
|
|
2369
2153
|
const ids = [];
|
|
2370
2154
|
const items = [];
|
|
2371
2155
|
for (const part of itemsParts) {
|
|
@@ -2553,13 +2337,34 @@ var Geocoder = (function (exports) {
|
|
|
2553
2337
|
return a;
|
|
2554
2338
|
};
|
|
2555
2339
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2340
|
+
var __async = (__this, __arguments, generator) => {
|
|
2341
|
+
return new Promise((resolve, reject) => {
|
|
2342
|
+
var fulfilled = (value) => {
|
|
2343
|
+
try {
|
|
2344
|
+
step(generator.next(value));
|
|
2345
|
+
} catch (e) {
|
|
2346
|
+
reject(e);
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
var rejected = (value) => {
|
|
2350
|
+
try {
|
|
2351
|
+
step(generator.throw(value));
|
|
2352
|
+
} catch (e) {
|
|
2353
|
+
reject(e);
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2357
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2358
|
+
});
|
|
2359
|
+
};
|
|
2556
2360
|
function fetchNgwLayerItems(options) {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2361
|
+
return __async(this, null, function* () {
|
|
2362
|
+
var _a;
|
|
2363
|
+
const filters = options.filters;
|
|
2364
|
+
if (filters) {
|
|
2365
|
+
let data = yield createFeatureFieldFilterQueries(__spreadProps(__spreadValues$1({}, options), {
|
|
2366
|
+
filters
|
|
2367
|
+
}));
|
|
2563
2368
|
const clientFilterValidate = (_a = options.clientFilterValidate) != null ? _a : isFilterWithAnyCase(filters);
|
|
2564
2369
|
if (clientFilterValidate) {
|
|
2565
2370
|
data = data.filter((y) => {
|
|
@@ -2571,10 +2376,10 @@ var Geocoder = (function (exports) {
|
|
|
2571
2376
|
});
|
|
2572
2377
|
}
|
|
2573
2378
|
return data;
|
|
2574
|
-
}
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
}
|
|
2379
|
+
} else {
|
|
2380
|
+
return fetchNgwLayerItemsRequest(options);
|
|
2381
|
+
}
|
|
2382
|
+
});
|
|
2578
2383
|
}
|
|
2579
2384
|
function isFilterWithAnyCase(filters) {
|
|
2580
2385
|
if (filters[0] === "any") {
|
|
@@ -2791,14 +2596,14 @@ var Geocoder = (function (exports) {
|
|
|
2791
2596
|
constructor(options) {
|
|
2792
2597
|
super(options);
|
|
2793
2598
|
__publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
|
|
2794
|
-
__publicField(this, "
|
|
2599
|
+
__publicField(this, "_abort", []);
|
|
2795
2600
|
if (options && options.searchUrl) {
|
|
2796
2601
|
this.searchUrl = options.searchUrl;
|
|
2797
2602
|
}
|
|
2798
2603
|
}
|
|
2799
2604
|
abort() {
|
|
2800
|
-
this.
|
|
2801
|
-
this.
|
|
2605
|
+
this._abort.forEach((x) => x());
|
|
2606
|
+
this._abort = [];
|
|
2802
2607
|
}
|
|
2803
2608
|
search(val) {
|
|
2804
2609
|
return __asyncGenerator(this, null, function* () {
|
|
@@ -2806,39 +2611,34 @@ var Geocoder = (function (exports) {
|
|
|
2806
2611
|
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
2807
2612
|
`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`
|
|
2808
2613
|
);
|
|
2809
|
-
const request = new
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
} catch (er) {
|
|
2826
|
-
reject(er);
|
|
2827
|
-
}
|
|
2828
|
-
};
|
|
2829
|
-
xhr.onerror = (er) => {
|
|
2614
|
+
const request = new Promise((resolve, reject) => {
|
|
2615
|
+
const xhr = new XMLHttpRequest();
|
|
2616
|
+
xhr.open("GET", url, true);
|
|
2617
|
+
xhr.onload = () => {
|
|
2618
|
+
try {
|
|
2619
|
+
const geojson = JSON.parse(xhr.responseText);
|
|
2620
|
+
const features = geojson.features.map((x) => {
|
|
2621
|
+
return {
|
|
2622
|
+
geom: x,
|
|
2623
|
+
extent: x.bbox,
|
|
2624
|
+
text: x.properties && x.properties.display_name,
|
|
2625
|
+
query: val
|
|
2626
|
+
};
|
|
2627
|
+
});
|
|
2628
|
+
resolve(features);
|
|
2629
|
+
} catch (er) {
|
|
2830
2630
|
reject(er);
|
|
2831
|
-
}
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2631
|
+
}
|
|
2632
|
+
};
|
|
2633
|
+
xhr.onerror = (er) => {
|
|
2634
|
+
reject(er);
|
|
2635
|
+
};
|
|
2636
|
+
this._abort.push(xhr.abort);
|
|
2637
|
+
xhr.send();
|
|
2638
|
+
}).catch((er) => {
|
|
2838
2639
|
if (er.name === "CancelError") ;
|
|
2839
2640
|
throw er;
|
|
2840
2641
|
});
|
|
2841
|
-
this._requests.push(request);
|
|
2842
2642
|
const items = yield new __await(request);
|
|
2843
2643
|
if (items) {
|
|
2844
2644
|
for (const i of items) {
|
|
@@ -2849,7 +2649,7 @@ var Geocoder = (function (exports) {
|
|
|
2849
2649
|
});
|
|
2850
2650
|
}
|
|
2851
2651
|
result(model) {
|
|
2852
|
-
return
|
|
2652
|
+
return Promise.resolve({
|
|
2853
2653
|
text: model.text,
|
|
2854
2654
|
extent: model.extent || [],
|
|
2855
2655
|
geom: model.geom
|
|
@@ -2861,38 +2661,33 @@ var Geocoder = (function (exports) {
|
|
|
2861
2661
|
const url = fixUrlStr(
|
|
2862
2662
|
`${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`
|
|
2863
2663
|
);
|
|
2864
|
-
const request = new
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
} catch (er) {
|
|
2880
|
-
reject(er);
|
|
2881
|
-
}
|
|
2882
|
-
};
|
|
2883
|
-
xhr.onerror = (er) => {
|
|
2664
|
+
const request = new Promise((resolve, reject) => {
|
|
2665
|
+
const xhr = new XMLHttpRequest();
|
|
2666
|
+
xhr.open("GET", url, true);
|
|
2667
|
+
xhr.onload = () => {
|
|
2668
|
+
try {
|
|
2669
|
+
const geojson = JSON.parse(xhr.responseText);
|
|
2670
|
+
const feature = geojson.features[0];
|
|
2671
|
+
const result = {
|
|
2672
|
+
geom: feature,
|
|
2673
|
+
extent: feature.bbox,
|
|
2674
|
+
text: feature.properties && feature.properties.display_name,
|
|
2675
|
+
query: `${lat}, ${lng}`
|
|
2676
|
+
};
|
|
2677
|
+
resolve(result);
|
|
2678
|
+
} catch (er) {
|
|
2884
2679
|
reject(er);
|
|
2885
|
-
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2680
|
+
}
|
|
2681
|
+
};
|
|
2682
|
+
xhr.onerror = (er) => {
|
|
2683
|
+
reject(er);
|
|
2684
|
+
};
|
|
2685
|
+
this._abort.push(xhr.abort);
|
|
2686
|
+
xhr.send();
|
|
2687
|
+
}).catch((er) => {
|
|
2892
2688
|
if (er.name === "CancelError") ;
|
|
2893
2689
|
throw er;
|
|
2894
2690
|
});
|
|
2895
|
-
this._requests.push(request);
|
|
2896
2691
|
const item = yield new __await(request);
|
|
2897
2692
|
if (item) {
|
|
2898
2693
|
item.result = () => this.result(item);
|