@nextgis/geocoder 1.11.10 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/geocoder.cjs.js +384 -135
- 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 +947 -592
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +15 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +384 -135
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +15 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +1 -1
- package/package.json +6 -6
|
@@ -1,32 +1,167 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 1.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 1.12.0; author: NextGIS */
|
|
2
|
+
/*! *****************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
/* global Reflect, Promise */
|
|
17
|
+
|
|
18
|
+
var extendStatics = function(d, b) {
|
|
19
|
+
extendStatics = Object.setPrototypeOf ||
|
|
20
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
21
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
22
|
+
return extendStatics(d, b);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function __extends(d, b) {
|
|
26
|
+
if (typeof b !== "function" && b !== null)
|
|
27
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
28
|
+
extendStatics(d, b);
|
|
29
|
+
function __() { this.constructor = d; }
|
|
30
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var __assign = function() {
|
|
34
|
+
__assign = Object.assign || function __assign(t) {
|
|
35
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
36
|
+
s = arguments[i];
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
return __assign.apply(this, arguments);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
45
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function __generator(thisArg, body) {
|
|
55
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
56
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
57
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
58
|
+
function step(op) {
|
|
59
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
60
|
+
while (_) try {
|
|
61
|
+
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;
|
|
62
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
63
|
+
switch (op[0]) {
|
|
64
|
+
case 0: case 1: t = op; break;
|
|
65
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
66
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
67
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
68
|
+
default:
|
|
69
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
70
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
71
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
72
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
73
|
+
if (t[2]) _.ops.pop();
|
|
74
|
+
_.trys.pop(); continue;
|
|
75
|
+
}
|
|
76
|
+
op = body.call(thisArg, _);
|
|
77
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
78
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
7
79
|
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function __values(o) {
|
|
83
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
84
|
+
if (m) return m.call(o);
|
|
85
|
+
if (o && typeof o.length === "number") return {
|
|
86
|
+
next: function () {
|
|
87
|
+
if (o && i >= o.length) o = void 0;
|
|
88
|
+
return { value: o && o[i++], done: !o };
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function __spreadArray(to, from, pack) {
|
|
95
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
96
|
+
if (ar || !(i in from)) {
|
|
97
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
98
|
+
ar[i] = from[i];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function __await(v) {
|
|
105
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
109
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
110
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
111
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
112
|
+
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); }); }; }
|
|
113
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
114
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
115
|
+
function fulfill(value) { resume("next", value); }
|
|
116
|
+
function reject(value) { resume("throw", value); }
|
|
117
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function __asyncValues(o) {
|
|
121
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
122
|
+
var m = o[Symbol.asyncIterator], i;
|
|
123
|
+
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);
|
|
124
|
+
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); }); }; }
|
|
125
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
126
|
}
|
|
9
127
|
|
|
10
|
-
class
|
|
11
|
-
|
|
128
|
+
var CancelError = /** @class */ (function (_super) {
|
|
129
|
+
__extends(CancelError, _super);
|
|
130
|
+
function CancelError() {
|
|
131
|
+
var _this = _super.call(this) || this;
|
|
132
|
+
_this.name = 'CancelError';
|
|
133
|
+
Object.setPrototypeOf(_this, CancelError.prototype);
|
|
134
|
+
return _this;
|
|
135
|
+
}
|
|
136
|
+
return CancelError;
|
|
137
|
+
}(Error));
|
|
138
|
+
|
|
139
|
+
var PromiseControl = /** @class */ (function () {
|
|
140
|
+
function PromiseControl(options) {
|
|
141
|
+
if (options === void 0) { options = {}; }
|
|
12
142
|
this.options = options;
|
|
13
143
|
this._promises = new Map();
|
|
14
144
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
145
|
+
Object.defineProperty(PromiseControl.prototype, "isLoaded", {
|
|
146
|
+
get: function () {
|
|
147
|
+
return this._promises.size > 0;
|
|
148
|
+
},
|
|
149
|
+
enumerable: false,
|
|
150
|
+
configurable: true
|
|
151
|
+
});
|
|
152
|
+
PromiseControl.prototype.remove = function (promise) {
|
|
19
153
|
if (this._promises.has(promise)) {
|
|
20
154
|
this._promises.delete(promise);
|
|
21
155
|
this._onStop();
|
|
22
156
|
}
|
|
23
|
-
}
|
|
24
|
-
get(promise) {
|
|
157
|
+
};
|
|
158
|
+
PromiseControl.prototype.get = function (promise) {
|
|
25
159
|
return this._promises.get(promise);
|
|
26
|
-
}
|
|
27
|
-
add(promise, name) {
|
|
28
|
-
|
|
29
|
-
|
|
160
|
+
};
|
|
161
|
+
PromiseControl.prototype.add = function (promise, name) {
|
|
162
|
+
var _this = this;
|
|
163
|
+
var key = name ? name : promise;
|
|
164
|
+
var exist = this._promises.get(key);
|
|
30
165
|
if (this.options.onStart && !this.isLoaded) {
|
|
31
166
|
this.options.onStart();
|
|
32
167
|
}
|
|
@@ -34,14 +169,14 @@ class PromiseControl {
|
|
|
34
169
|
return exist;
|
|
35
170
|
}
|
|
36
171
|
this._promises.set(key, promise);
|
|
37
|
-
promise.finally(()
|
|
38
|
-
|
|
172
|
+
promise.finally(function () {
|
|
173
|
+
_this.remove(key);
|
|
39
174
|
});
|
|
40
175
|
return promise;
|
|
41
|
-
}
|
|
42
|
-
abort() {
|
|
176
|
+
};
|
|
177
|
+
PromiseControl.prototype.abort = function () {
|
|
43
178
|
if (this.isLoaded) {
|
|
44
|
-
this._promises.forEach((x)
|
|
179
|
+
this._promises.forEach(function (x) {
|
|
45
180
|
if (x.cancel) {
|
|
46
181
|
x.cancel();
|
|
47
182
|
}
|
|
@@ -49,52 +184,63 @@ class PromiseControl {
|
|
|
49
184
|
this._promises.clear();
|
|
50
185
|
this._onStop();
|
|
51
186
|
}
|
|
52
|
-
}
|
|
53
|
-
waitFunc(func, name
|
|
187
|
+
};
|
|
188
|
+
PromiseControl.prototype.waitFunc = function (func, name) {
|
|
189
|
+
if (name === void 0) { name = ''; }
|
|
54
190
|
name = name || func.name;
|
|
55
|
-
|
|
191
|
+
var exist = this.get(name);
|
|
56
192
|
if (exist) {
|
|
57
193
|
return exist;
|
|
58
194
|
}
|
|
59
195
|
return this.add(func(), name);
|
|
60
|
-
}
|
|
61
|
-
WaitForMe
|
|
62
|
-
|
|
63
|
-
|
|
196
|
+
};
|
|
197
|
+
PromiseControl.prototype.WaitForMe = function (name) {
|
|
198
|
+
if (name === void 0) { name = ''; }
|
|
199
|
+
var get = this.get.bind(this);
|
|
200
|
+
var add = this.add.bind(this);
|
|
64
201
|
return function (target, key, descriptor) {
|
|
65
|
-
|
|
202
|
+
var originalMethod = descriptor.value;
|
|
66
203
|
name = name || key;
|
|
67
|
-
descriptor.value = function (
|
|
68
|
-
|
|
204
|
+
descriptor.value = function () {
|
|
205
|
+
var args = [];
|
|
206
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
207
|
+
args[_i] = arguments[_i];
|
|
208
|
+
}
|
|
209
|
+
var exist = get(name);
|
|
69
210
|
if (exist) {
|
|
70
211
|
return exist;
|
|
71
212
|
}
|
|
72
|
-
|
|
213
|
+
var result = add(originalMethod.apply(this, args), name);
|
|
73
214
|
return result;
|
|
74
215
|
};
|
|
75
216
|
return descriptor;
|
|
76
217
|
};
|
|
77
|
-
}
|
|
218
|
+
};
|
|
78
219
|
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
79
|
-
GetOrCreateDecorator
|
|
220
|
+
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
221
|
+
if (name === void 0) { name = ''; }
|
|
80
222
|
return this.WaitForMe(name);
|
|
81
|
-
}
|
|
82
|
-
_onStop() {
|
|
223
|
+
};
|
|
224
|
+
PromiseControl.prototype._onStop = function () {
|
|
83
225
|
if (this.options.onStop && !this.isLoaded) {
|
|
84
226
|
this.options.onStop();
|
|
85
227
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
228
|
+
};
|
|
229
|
+
return PromiseControl;
|
|
230
|
+
}());
|
|
88
231
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
232
|
+
var TimeoutError = /** @class */ (function (_super) {
|
|
233
|
+
__extends(TimeoutError, _super);
|
|
234
|
+
function TimeoutError() {
|
|
235
|
+
var _this = _super.call(this) || this;
|
|
236
|
+
_this.name = 'TimeoutError';
|
|
237
|
+
Object.setPrototypeOf(_this, TimeoutError.prototype);
|
|
238
|
+
return _this;
|
|
94
239
|
}
|
|
95
|
-
|
|
240
|
+
return TimeoutError;
|
|
241
|
+
}(Error));
|
|
96
242
|
|
|
97
|
-
|
|
243
|
+
var handleCallback = function (resolve, reject, callback, r) {
|
|
98
244
|
try {
|
|
99
245
|
resolve(callback(r));
|
|
100
246
|
}
|
|
@@ -102,7 +248,7 @@ const handleCallback = (resolve, reject, callback, r) => {
|
|
|
102
248
|
reject(e);
|
|
103
249
|
}
|
|
104
250
|
};
|
|
105
|
-
|
|
251
|
+
var ID$2 = 0;
|
|
106
252
|
/**
|
|
107
253
|
* Promise that can be canceled
|
|
108
254
|
*
|
|
@@ -147,48 +293,49 @@ let ID$2 = 0;
|
|
|
147
293
|
* promise.cancel();
|
|
148
294
|
* ```
|
|
149
295
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
296
|
+
var CancelablePromise$1 = /** @class */ (function () {
|
|
297
|
+
function CancelablePromise(executor, timeout) {
|
|
298
|
+
var _this = this;
|
|
152
299
|
this.id = ID$2++;
|
|
153
300
|
this._isCanceled = false;
|
|
154
301
|
this._isPending = true;
|
|
155
302
|
this._cancelHandlers = [];
|
|
156
303
|
this._children = [];
|
|
157
|
-
this._cancelPromise = new Promise((resolve_, reject_)
|
|
158
|
-
|
|
304
|
+
this._cancelPromise = new Promise(function (resolve_, reject_) {
|
|
305
|
+
_this._setCanceledCallback = function (er) { return resolve_(er || new CancelError()); };
|
|
159
306
|
});
|
|
160
|
-
|
|
307
|
+
var promises = [
|
|
161
308
|
this._cancelPromise,
|
|
162
|
-
new Promise((resolve, reject)
|
|
163
|
-
|
|
164
|
-
if (value instanceof CancelablePromise
|
|
165
|
-
|
|
309
|
+
new Promise(function (resolve, reject) {
|
|
310
|
+
var onResolve = function (value) {
|
|
311
|
+
if (value instanceof CancelablePromise) {
|
|
312
|
+
_this.attach(value);
|
|
166
313
|
}
|
|
167
314
|
else {
|
|
168
|
-
|
|
315
|
+
_this._isPending = false;
|
|
169
316
|
}
|
|
170
317
|
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
171
318
|
resolve(value);
|
|
172
319
|
};
|
|
173
|
-
|
|
174
|
-
|
|
320
|
+
var onReject = function (error) {
|
|
321
|
+
_this._isPending = false;
|
|
175
322
|
reject(error);
|
|
176
323
|
};
|
|
177
|
-
|
|
178
|
-
if (!
|
|
324
|
+
var onCancel = function (handler) {
|
|
325
|
+
if (!_this._isPending) {
|
|
179
326
|
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
180
327
|
}
|
|
181
|
-
|
|
328
|
+
_this._cancelHandlers.push(handler);
|
|
182
329
|
};
|
|
183
330
|
return executor(onResolve, onReject, onCancel);
|
|
184
331
|
}),
|
|
185
332
|
];
|
|
186
333
|
if (timeout) {
|
|
187
|
-
promises.push(new Promise((resolve, reject)
|
|
188
|
-
setTimeout(()
|
|
189
|
-
if (
|
|
334
|
+
promises.push(new Promise(function (resolve, reject) {
|
|
335
|
+
setTimeout(function () {
|
|
336
|
+
if (_this._isPending) {
|
|
190
337
|
try {
|
|
191
|
-
|
|
338
|
+
_this.cancel();
|
|
192
339
|
}
|
|
193
340
|
finally {
|
|
194
341
|
reject(new TimeoutError());
|
|
@@ -199,21 +346,23 @@ class CancelablePromise$1 {
|
|
|
199
346
|
}
|
|
200
347
|
this._promise = Promise.race(promises);
|
|
201
348
|
}
|
|
202
|
-
|
|
349
|
+
CancelablePromise.createControl = function (opt) {
|
|
203
350
|
return new PromiseControl(opt);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return new CancelablePromise
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return new CancelablePromise
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
351
|
+
};
|
|
352
|
+
CancelablePromise.resolve = function (value) {
|
|
353
|
+
return new CancelablePromise(function (resolve) { return resolve(value); });
|
|
354
|
+
};
|
|
355
|
+
CancelablePromise.reject = function (value) {
|
|
356
|
+
return new CancelablePromise(function (resolve, reject) { return reject(value); });
|
|
357
|
+
};
|
|
358
|
+
CancelablePromise.all = function (values) {
|
|
359
|
+
var _this = this;
|
|
360
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
213
361
|
Promise.all(values).then(resolve).catch(reject);
|
|
214
|
-
}).catch((er)
|
|
215
|
-
if (er instanceof
|
|
216
|
-
for (
|
|
362
|
+
}).catch(function (er) {
|
|
363
|
+
if (er instanceof _this.CancelError) {
|
|
364
|
+
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
365
|
+
var v = values_1[_i];
|
|
217
366
|
if ('cancel' in v) {
|
|
218
367
|
v.cancel();
|
|
219
368
|
}
|
|
@@ -221,19 +370,20 @@ class CancelablePromise$1 {
|
|
|
221
370
|
}
|
|
222
371
|
throw er;
|
|
223
372
|
});
|
|
224
|
-
}
|
|
225
|
-
attach(p) {
|
|
373
|
+
};
|
|
374
|
+
CancelablePromise.prototype.attach = function (p) {
|
|
226
375
|
if (this._isCanceled) {
|
|
227
376
|
p.cancel();
|
|
228
377
|
}
|
|
229
378
|
else {
|
|
230
379
|
this._children.push(p);
|
|
231
380
|
}
|
|
232
|
-
}
|
|
233
|
-
then(onfulfilled, onrejected) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
381
|
+
};
|
|
382
|
+
CancelablePromise.prototype.then = function (onfulfilled, onrejected) {
|
|
383
|
+
var _this = this;
|
|
384
|
+
var p = new CancelablePromise(function (resolve, reject) {
|
|
385
|
+
if (_this._promise) {
|
|
386
|
+
var reject_1 = function (r) {
|
|
237
387
|
if (onrejected) {
|
|
238
388
|
handleCallback(resolve, reject, onrejected, r);
|
|
239
389
|
}
|
|
@@ -241,9 +391,9 @@ class CancelablePromise$1 {
|
|
|
241
391
|
reject(r);
|
|
242
392
|
}
|
|
243
393
|
};
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
|
|
394
|
+
_this._promise.then(function (r) {
|
|
395
|
+
if (_this._isCanceled) {
|
|
396
|
+
reject_1(r);
|
|
247
397
|
}
|
|
248
398
|
else {
|
|
249
399
|
if (onfulfilled) {
|
|
@@ -253,20 +403,20 @@ class CancelablePromise$1 {
|
|
|
253
403
|
resolve(r);
|
|
254
404
|
}
|
|
255
405
|
}
|
|
256
|
-
},
|
|
406
|
+
}, reject_1);
|
|
257
407
|
}
|
|
258
408
|
});
|
|
259
409
|
p._parentPromise = this;
|
|
260
410
|
this._children.push(p);
|
|
261
411
|
return p;
|
|
262
|
-
}
|
|
263
|
-
catch(onrejected) {
|
|
412
|
+
};
|
|
413
|
+
CancelablePromise.prototype.catch = function (onrejected) {
|
|
264
414
|
if (this._isCanceled && onrejected) {
|
|
265
415
|
onrejected(new CancelError());
|
|
266
416
|
}
|
|
267
417
|
return this.then(undefined, onrejected);
|
|
268
|
-
}
|
|
269
|
-
finally(onfinally) {
|
|
418
|
+
};
|
|
419
|
+
CancelablePromise.prototype.finally = function (onfinally) {
|
|
270
420
|
if (this._promise) {
|
|
271
421
|
return this._promise.finally(onfinally);
|
|
272
422
|
}
|
|
@@ -274,24 +424,25 @@ class CancelablePromise$1 {
|
|
|
274
424
|
return Promise.reject(new CancelError());
|
|
275
425
|
}
|
|
276
426
|
return Promise.reject(onfinally);
|
|
277
|
-
}
|
|
278
|
-
cancel() {
|
|
427
|
+
};
|
|
428
|
+
CancelablePromise.prototype.cancel = function () {
|
|
279
429
|
// No reason to run cancel action if promise is already complete
|
|
280
430
|
if (this._isCanceled || !this._isPending) {
|
|
281
431
|
return this;
|
|
282
432
|
}
|
|
283
433
|
this._isCanceled = true;
|
|
284
|
-
|
|
434
|
+
var parent = this._getTopParent();
|
|
285
435
|
if (parent) {
|
|
286
436
|
parent.cancel();
|
|
287
437
|
}
|
|
288
438
|
if (this._children) {
|
|
289
|
-
this._children.forEach((x)
|
|
439
|
+
this._children.forEach(function (x) { return x.cancel(); });
|
|
290
440
|
}
|
|
291
441
|
if (this._isPending) {
|
|
292
442
|
if (this._cancelHandlers.length) {
|
|
293
443
|
try {
|
|
294
|
-
for (
|
|
444
|
+
for (var _i = 0, _a = this._cancelHandlers; _i < _a.length; _i++) {
|
|
445
|
+
var handler = _a[_i];
|
|
295
446
|
handler();
|
|
296
447
|
}
|
|
297
448
|
}
|
|
@@ -305,10 +456,10 @@ class CancelablePromise$1 {
|
|
|
305
456
|
}
|
|
306
457
|
this._destroy();
|
|
307
458
|
return this;
|
|
308
|
-
}
|
|
309
|
-
_getTopParent() {
|
|
310
|
-
|
|
311
|
-
|
|
459
|
+
};
|
|
460
|
+
CancelablePromise.prototype._getTopParent = function () {
|
|
461
|
+
var parent = this._parentPromise;
|
|
462
|
+
var hasParent = !!parent;
|
|
312
463
|
while (hasParent) {
|
|
313
464
|
if (parent && parent._parentPromise) {
|
|
314
465
|
parent = parent._parentPromise;
|
|
@@ -319,16 +470,17 @@ class CancelablePromise$1 {
|
|
|
319
470
|
}
|
|
320
471
|
}
|
|
321
472
|
return parent;
|
|
322
|
-
}
|
|
323
|
-
_destroy() {
|
|
473
|
+
};
|
|
474
|
+
CancelablePromise.prototype._destroy = function () {
|
|
324
475
|
this._setCanceledCallback = undefined;
|
|
325
476
|
this._cancelPromise = undefined;
|
|
326
477
|
this._promise = undefined;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
CancelablePromise
|
|
330
|
-
CancelablePromise
|
|
331
|
-
CancelablePromise
|
|
478
|
+
};
|
|
479
|
+
CancelablePromise.CancelError = CancelError;
|
|
480
|
+
CancelablePromise.TimeoutError = TimeoutError;
|
|
481
|
+
CancelablePromise.PromiseControl = PromiseControl;
|
|
482
|
+
return CancelablePromise;
|
|
483
|
+
}());
|
|
332
484
|
Object.setPrototypeOf(CancelablePromise$1.prototype, Promise.prototype);
|
|
333
485
|
|
|
334
486
|
/**
|
|
@@ -381,9 +533,15 @@ function full(val) {
|
|
|
381
533
|
* @param target - The target object to copy to.
|
|
382
534
|
* @param sources - One or more source objects from which to copy properties
|
|
383
535
|
*/
|
|
384
|
-
function objectAssign(target
|
|
385
|
-
|
|
386
|
-
|
|
536
|
+
function objectAssign(target) {
|
|
537
|
+
var sources = [];
|
|
538
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
539
|
+
sources[_i - 1] = arguments[_i];
|
|
540
|
+
}
|
|
541
|
+
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
|
|
542
|
+
var source = sources_1[_a];
|
|
543
|
+
for (var _b = 0, _c = Object.getOwnPropertyNames(source); _b < _c.length; _b++) {
|
|
544
|
+
var prop = _c[_b];
|
|
387
545
|
target[prop] = source[prop];
|
|
388
546
|
}
|
|
389
547
|
}
|
|
@@ -421,15 +579,15 @@ function isEqual(a, b, o, p) {
|
|
|
421
579
|
}
|
|
422
580
|
// based on https://stackoverflow.com/a/13143059
|
|
423
581
|
function objectDeepEqual(o, p) {
|
|
424
|
-
|
|
425
|
-
|
|
582
|
+
var keysO = Object.keys(o).sort();
|
|
583
|
+
var keysP = Object.keys(p).sort();
|
|
426
584
|
if (keysO.length !== keysP.length)
|
|
427
585
|
return false;
|
|
428
586
|
if (keysO.join('') !== keysP.join(''))
|
|
429
587
|
return false;
|
|
430
|
-
for (
|
|
431
|
-
|
|
432
|
-
|
|
588
|
+
for (var i = 0; i < keysO.length; i++) {
|
|
589
|
+
var oVal = o[keysO[i]];
|
|
590
|
+
var pVal = p[keysP[i]];
|
|
433
591
|
if (!isEqual(oVal, pVal, o, p)) {
|
|
434
592
|
return false;
|
|
435
593
|
}
|
|
@@ -438,8 +596,8 @@ function objectDeepEqual(o, p) {
|
|
|
438
596
|
}
|
|
439
597
|
|
|
440
598
|
function objectRemoveEmpty(obj) {
|
|
441
|
-
|
|
442
|
-
Object.keys(obj).forEach((key)
|
|
599
|
+
var newObj = {};
|
|
600
|
+
Object.keys(obj).forEach(function (key) {
|
|
443
601
|
if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
|
|
444
602
|
newObj[key] = objectRemoveEmpty(obj[key]);
|
|
445
603
|
}
|
|
@@ -455,53 +613,109 @@ function fixUrlStr(url) {
|
|
|
455
613
|
return url.replace(/([^:]\/)\/+/g, '$1');
|
|
456
614
|
}
|
|
457
615
|
|
|
458
|
-
|
|
459
|
-
|
|
616
|
+
var BaseGeocoder = /** @class */ (function () {
|
|
617
|
+
function BaseGeocoder(options) {
|
|
460
618
|
if (options) {
|
|
461
619
|
objectAssign(this, options);
|
|
462
620
|
}
|
|
463
621
|
}
|
|
464
|
-
|
|
622
|
+
return BaseGeocoder;
|
|
623
|
+
}());
|
|
465
624
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
625
|
+
var ID$1 = 0;
|
|
626
|
+
var Geocoder = /** @class */ (function (_super) {
|
|
627
|
+
__extends(Geocoder, _super);
|
|
628
|
+
function Geocoder(options) {
|
|
629
|
+
var _this = _super.call(this, options) || this;
|
|
630
|
+
_this.providers = [];
|
|
471
631
|
if (options && options.providers) {
|
|
472
|
-
|
|
632
|
+
_this.providers = options.providers;
|
|
473
633
|
}
|
|
634
|
+
return _this;
|
|
474
635
|
}
|
|
475
|
-
abort() {
|
|
476
|
-
this.providers.forEach((x)
|
|
636
|
+
Geocoder.prototype.abort = function () {
|
|
637
|
+
this.providers.forEach(function (x) {
|
|
477
638
|
if (x.abort) {
|
|
478
639
|
x.abort();
|
|
479
640
|
}
|
|
480
641
|
});
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
642
|
+
};
|
|
643
|
+
Geocoder.prototype.search = function (query) {
|
|
644
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
645
|
+
var _i, _a, provider, results, results_1, results_1_1, r, e_1_1;
|
|
646
|
+
var e_1, _b;
|
|
647
|
+
return __generator(this, function (_c) {
|
|
648
|
+
switch (_c.label) {
|
|
649
|
+
case 0:
|
|
650
|
+
_i = 0, _a = this.providers;
|
|
651
|
+
_c.label = 1;
|
|
652
|
+
case 1:
|
|
653
|
+
if (!(_i < _a.length)) return [3 /*break*/, 19];
|
|
654
|
+
provider = _a[_i];
|
|
655
|
+
_c.label = 2;
|
|
656
|
+
case 2:
|
|
657
|
+
_c.trys.push([2, 17, , 18]);
|
|
658
|
+
results = provider.search(query);
|
|
659
|
+
_c.label = 3;
|
|
660
|
+
case 3:
|
|
661
|
+
_c.trys.push([3, 10, 11, 16]);
|
|
662
|
+
results_1 = (e_1 = void 0, __asyncValues(results));
|
|
663
|
+
_c.label = 4;
|
|
664
|
+
case 4: return [4 /*yield*/, __await(results_1.next())];
|
|
665
|
+
case 5:
|
|
666
|
+
if (!(results_1_1 = _c.sent(), !results_1_1.done)) return [3 /*break*/, 9];
|
|
667
|
+
r = results_1_1.value;
|
|
668
|
+
return [4 /*yield*/, __await(__assign(__assign({}, r), { provider: provider, _id: ID$1++ }))];
|
|
669
|
+
case 6: return [4 /*yield*/, _c.sent()];
|
|
670
|
+
case 7:
|
|
671
|
+
_c.sent();
|
|
672
|
+
_c.label = 8;
|
|
673
|
+
case 8: return [3 /*break*/, 4];
|
|
674
|
+
case 9: return [3 /*break*/, 16];
|
|
675
|
+
case 10:
|
|
676
|
+
e_1_1 = _c.sent();
|
|
677
|
+
e_1 = { error: e_1_1 };
|
|
678
|
+
return [3 /*break*/, 16];
|
|
679
|
+
case 11:
|
|
680
|
+
_c.trys.push([11, , 14, 15]);
|
|
681
|
+
if (!(results_1_1 && !results_1_1.done && (_b = results_1.return))) return [3 /*break*/, 13];
|
|
682
|
+
return [4 /*yield*/, __await(_b.call(results_1))];
|
|
683
|
+
case 12:
|
|
684
|
+
_c.sent();
|
|
685
|
+
_c.label = 13;
|
|
686
|
+
case 13: return [3 /*break*/, 15];
|
|
687
|
+
case 14:
|
|
688
|
+
if (e_1) throw e_1.error;
|
|
689
|
+
return [7 /*endfinally*/];
|
|
690
|
+
case 15: return [7 /*endfinally*/];
|
|
691
|
+
case 16: return [3 /*break*/, 18];
|
|
692
|
+
case 17:
|
|
693
|
+
_c.sent();
|
|
694
|
+
return [3 /*break*/, 18];
|
|
695
|
+
case 18:
|
|
696
|
+
_i++;
|
|
697
|
+
return [3 /*break*/, 1];
|
|
698
|
+
case 19: return [2 /*return*/];
|
|
488
699
|
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
result(item) {
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
Geocoder.prototype.result = function (item) {
|
|
496
704
|
if (item.provider) {
|
|
497
705
|
return item.provider.result(item);
|
|
498
706
|
}
|
|
499
707
|
return CancelablePromise.resolve(undefined);
|
|
500
|
-
}
|
|
501
|
-
|
|
708
|
+
};
|
|
709
|
+
return Geocoder;
|
|
710
|
+
}(BaseGeocoder));
|
|
502
711
|
|
|
503
|
-
|
|
504
|
-
|
|
712
|
+
var BaseProvider = /** @class */ (function (_super) {
|
|
713
|
+
__extends(BaseProvider, _super);
|
|
714
|
+
function BaseProvider() {
|
|
715
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
716
|
+
}
|
|
717
|
+
return BaseProvider;
|
|
718
|
+
}(BaseGeocoder));
|
|
505
719
|
|
|
506
720
|
var events = {exports: {}};
|
|
507
721
|
|
|
@@ -1009,23 +1223,24 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
1009
1223
|
* console.log(COUNTER); // 1
|
|
1010
1224
|
* ```
|
|
1011
1225
|
*/
|
|
1012
|
-
|
|
1013
|
-
|
|
1226
|
+
var Cache$1 = /** @class */ (function () {
|
|
1227
|
+
function Cache(options) {
|
|
1228
|
+
if (options === void 0) { options = {}; }
|
|
1014
1229
|
var _a;
|
|
1015
1230
|
this.cache = [];
|
|
1016
|
-
|
|
1017
|
-
if (Cache
|
|
1018
|
-
return Cache
|
|
1231
|
+
var namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
1232
|
+
if (Cache.instance[namespace]) {
|
|
1233
|
+
return Cache.instance[namespace];
|
|
1019
1234
|
}
|
|
1020
|
-
Cache
|
|
1235
|
+
Cache.instance[namespace] = this;
|
|
1021
1236
|
return this;
|
|
1022
1237
|
}
|
|
1023
|
-
clean() {
|
|
1238
|
+
Cache.prototype.clean = function () {
|
|
1024
1239
|
this.cache.length = 0;
|
|
1025
|
-
}
|
|
1026
|
-
all() {
|
|
1240
|
+
};
|
|
1241
|
+
Cache.prototype.all = function () {
|
|
1027
1242
|
return this.cache;
|
|
1028
|
-
}
|
|
1243
|
+
};
|
|
1029
1244
|
/**
|
|
1030
1245
|
* Caching only a non-empty value.
|
|
1031
1246
|
*
|
|
@@ -1048,23 +1263,24 @@ class Cache$1 {
|
|
|
1048
1263
|
*
|
|
1049
1264
|
* ```
|
|
1050
1265
|
*/
|
|
1051
|
-
addFull(key, valueToSet, props) {
|
|
1266
|
+
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
1052
1267
|
return this.add(key, valueToSet, props, true);
|
|
1053
|
-
}
|
|
1054
|
-
add(key, valueToSet, props, onlyFull) {
|
|
1055
|
-
|
|
1268
|
+
};
|
|
1269
|
+
Cache.prototype.add = function (key, valueToSet, props, onlyFull) {
|
|
1270
|
+
var _this = this;
|
|
1271
|
+
var exist = this._find(key, props);
|
|
1056
1272
|
if (!exist) {
|
|
1057
|
-
|
|
1273
|
+
var value = void 0;
|
|
1058
1274
|
if (valueToSet instanceof Function) {
|
|
1059
1275
|
value = valueToSet();
|
|
1060
1276
|
}
|
|
1061
1277
|
else {
|
|
1062
1278
|
value = valueToSet;
|
|
1063
1279
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
key,
|
|
1067
|
-
value,
|
|
1280
|
+
var props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
1281
|
+
var cacheItem = {
|
|
1282
|
+
key: key,
|
|
1283
|
+
value: value,
|
|
1068
1284
|
props: props_,
|
|
1069
1285
|
// TODO: remove backward compatibility use only props
|
|
1070
1286
|
options: props_,
|
|
@@ -1074,14 +1290,14 @@ class Cache$1 {
|
|
|
1074
1290
|
}
|
|
1075
1291
|
this.cache.push(cacheItem);
|
|
1076
1292
|
if (value instanceof Promise) {
|
|
1077
|
-
value.catch((er)
|
|
1078
|
-
|
|
1293
|
+
value.catch(function (er) {
|
|
1294
|
+
_this.delete(key, props);
|
|
1079
1295
|
throw er;
|
|
1080
1296
|
});
|
|
1081
1297
|
if (onlyFull) {
|
|
1082
|
-
value.then((x)
|
|
1298
|
+
value.then(function (x) {
|
|
1083
1299
|
if (!full(x)) {
|
|
1084
|
-
|
|
1300
|
+
_this.delete(key, props);
|
|
1085
1301
|
}
|
|
1086
1302
|
return x;
|
|
1087
1303
|
});
|
|
@@ -1093,50 +1309,55 @@ class Cache$1 {
|
|
|
1093
1309
|
else {
|
|
1094
1310
|
return exist.value;
|
|
1095
1311
|
}
|
|
1096
|
-
}
|
|
1097
|
-
match(key, props) {
|
|
1098
|
-
|
|
1312
|
+
};
|
|
1313
|
+
Cache.prototype.match = function (key, props) {
|
|
1314
|
+
var cacheRecord = this._find(key, props);
|
|
1099
1315
|
if (cacheRecord) {
|
|
1100
1316
|
return cacheRecord.value;
|
|
1101
1317
|
}
|
|
1102
|
-
}
|
|
1103
|
-
matchAll(key, props) {
|
|
1318
|
+
};
|
|
1319
|
+
Cache.prototype.matchAll = function (key, props) {
|
|
1320
|
+
var _this = this;
|
|
1104
1321
|
if (key) {
|
|
1105
1322
|
return this.cache
|
|
1106
|
-
.filter((x)
|
|
1107
|
-
.map((x)
|
|
1323
|
+
.filter(function (x) { return _this._filter(x, key, props); })
|
|
1324
|
+
.map(function (x) { return x.value; });
|
|
1108
1325
|
}
|
|
1109
|
-
return this.cache.map((x)
|
|
1110
|
-
}
|
|
1111
|
-
delete(keyOrItem, props) {
|
|
1112
|
-
|
|
1326
|
+
return this.cache.map(function (x) { return x.value; });
|
|
1327
|
+
};
|
|
1328
|
+
Cache.prototype.delete = function (keyOrItem, props) {
|
|
1329
|
+
var _this = this;
|
|
1330
|
+
var exist = [];
|
|
1113
1331
|
if (typeof keyOrItem === 'string') {
|
|
1114
|
-
exist = this.cache.filter((x)
|
|
1332
|
+
exist = this.cache.filter(function (x) { return _this._filter(x, keyOrItem, props); });
|
|
1115
1333
|
}
|
|
1116
1334
|
else {
|
|
1117
1335
|
exist.push(keyOrItem);
|
|
1118
1336
|
}
|
|
1119
|
-
for (
|
|
1120
|
-
|
|
1337
|
+
for (var _i = 0, exist_1 = exist; _i < exist_1.length; _i++) {
|
|
1338
|
+
var e = exist_1[_i];
|
|
1339
|
+
var index = this.cache.indexOf(e);
|
|
1121
1340
|
this.cache.splice(index, 1);
|
|
1122
1341
|
}
|
|
1123
|
-
}
|
|
1124
|
-
_find(key, props) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1342
|
+
};
|
|
1343
|
+
Cache.prototype._find = function (key, props) {
|
|
1344
|
+
var _this = this;
|
|
1345
|
+
return this.cache.find(function (x) { return _this._filter(x, key, props); });
|
|
1346
|
+
};
|
|
1347
|
+
Cache.prototype._filter = function (item, key, props) {
|
|
1128
1348
|
if (item.key === key) {
|
|
1129
1349
|
if (props) {
|
|
1130
1350
|
// TODO: remove backward compatibility
|
|
1131
|
-
|
|
1351
|
+
var itemProps = item.props || item.options;
|
|
1132
1352
|
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
1133
1353
|
}
|
|
1134
1354
|
return true;
|
|
1135
1355
|
}
|
|
1136
1356
|
return false;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
Cache
|
|
1357
|
+
};
|
|
1358
|
+
Cache.instance = {};
|
|
1359
|
+
return Cache;
|
|
1360
|
+
}());
|
|
1140
1361
|
|
|
1141
1362
|
/**
|
|
1142
1363
|
* Caching for asynchronous functions
|
|
@@ -1149,43 +1370,49 @@ var Cache = Cache$1;
|
|
|
1149
1370
|
/**
|
|
1150
1371
|
* Thrown when...
|
|
1151
1372
|
*/
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
Object.
|
|
1158
|
-
|
|
1159
|
-
|
|
1373
|
+
var NgwError = /** @class */ (function (_super) {
|
|
1374
|
+
__extends(NgwError, _super);
|
|
1375
|
+
function NgwError(er) {
|
|
1376
|
+
var _this = _super.call(this) || this;
|
|
1377
|
+
_this.name = 'NgwError';
|
|
1378
|
+
Object.assign(_this, er);
|
|
1379
|
+
Object.setPrototypeOf(_this, NgwError.prototype);
|
|
1380
|
+
return _this;
|
|
1381
|
+
}
|
|
1382
|
+
return NgwError;
|
|
1383
|
+
}(Error));
|
|
1160
1384
|
|
|
1161
1385
|
/**
|
|
1162
1386
|
* Thrown when...
|
|
1163
1387
|
*/
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
Possibly invalid NGW URL entered or CORS not configured to get request from
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1388
|
+
var NetworkError = /** @class */ (function (_super) {
|
|
1389
|
+
__extends(NetworkError, _super);
|
|
1390
|
+
function NetworkError(url) {
|
|
1391
|
+
var _this = _super.call(this) || this;
|
|
1392
|
+
_this.name = 'NetworkError';
|
|
1393
|
+
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1394
|
+
_this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
|
|
1395
|
+
return _this;
|
|
1396
|
+
}
|
|
1397
|
+
return NetworkError;
|
|
1398
|
+
}(Error));
|
|
1173
1399
|
|
|
1174
1400
|
function isObject(val) {
|
|
1175
1401
|
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1176
1402
|
}
|
|
1177
1403
|
|
|
1178
|
-
|
|
1404
|
+
var loadData;
|
|
1179
1405
|
// @ts-ignore
|
|
1180
1406
|
{
|
|
1181
|
-
loadData = (url, callback, options
|
|
1407
|
+
loadData = function (url, callback, options, error, onCancel) {
|
|
1408
|
+
if (options === void 0) { options = {}; }
|
|
1182
1409
|
options.method = options.method || 'GET';
|
|
1183
|
-
|
|
1410
|
+
var xhr = new XMLHttpRequest();
|
|
1184
1411
|
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1185
1412
|
if (options.responseType === 'blob') {
|
|
1186
1413
|
xhr.responseType = options.responseType;
|
|
1187
1414
|
}
|
|
1188
|
-
|
|
1415
|
+
var getResponseText = function () {
|
|
1189
1416
|
try {
|
|
1190
1417
|
return JSON.parse(xhr.responseText);
|
|
1191
1418
|
}
|
|
@@ -1193,8 +1420,9 @@ let loadData;
|
|
|
1193
1420
|
return xhr.responseText;
|
|
1194
1421
|
}
|
|
1195
1422
|
};
|
|
1196
|
-
|
|
1197
|
-
|
|
1423
|
+
var processingResponse = function (forError) {
|
|
1424
|
+
if (forError === void 0) { forError = false; }
|
|
1425
|
+
var cb = forError ? error : callback;
|
|
1198
1426
|
if (options.responseType === 'blob') {
|
|
1199
1427
|
cb(xhr.response);
|
|
1200
1428
|
}
|
|
@@ -1207,7 +1435,7 @@ let loadData;
|
|
|
1207
1435
|
}
|
|
1208
1436
|
}
|
|
1209
1437
|
};
|
|
1210
|
-
xhr.onload = ()
|
|
1438
|
+
xhr.onload = function () {
|
|
1211
1439
|
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1212
1440
|
error(new NgwError(getResponseText()));
|
|
1213
1441
|
}
|
|
@@ -1229,7 +1457,7 @@ let loadData;
|
|
|
1229
1457
|
// error('request error');
|
|
1230
1458
|
// }
|
|
1231
1459
|
// };
|
|
1232
|
-
xhr.onerror = (er)
|
|
1460
|
+
xhr.onerror = function (er) {
|
|
1233
1461
|
if (xhr.status === 0) {
|
|
1234
1462
|
error(new NetworkError(url));
|
|
1235
1463
|
}
|
|
@@ -1239,17 +1467,17 @@ let loadData;
|
|
|
1239
1467
|
};
|
|
1240
1468
|
xhr.upload.onprogress = function (e) {
|
|
1241
1469
|
if (e.lengthComputable) {
|
|
1242
|
-
|
|
1470
|
+
var percentComplete = (e.loaded / e.total) * 100;
|
|
1243
1471
|
if (options.onProgress) {
|
|
1244
1472
|
options.onProgress(percentComplete, e);
|
|
1245
1473
|
}
|
|
1246
1474
|
// console.log(percentComplete + '% uploaded');
|
|
1247
1475
|
}
|
|
1248
1476
|
};
|
|
1249
|
-
|
|
1477
|
+
var headers = options.headers;
|
|
1250
1478
|
if (headers) {
|
|
1251
|
-
for (
|
|
1252
|
-
|
|
1479
|
+
for (var h in headers) {
|
|
1480
|
+
var header = headers[h];
|
|
1253
1481
|
if (typeof header === 'string') {
|
|
1254
1482
|
xhr.setRequestHeader(h, header);
|
|
1255
1483
|
}
|
|
@@ -1258,12 +1486,12 @@ let loadData;
|
|
|
1258
1486
|
if (options.withCredentials !== undefined) {
|
|
1259
1487
|
xhr.withCredentials = options.withCredentials;
|
|
1260
1488
|
}
|
|
1261
|
-
|
|
1489
|
+
var data;
|
|
1262
1490
|
if (options.file) {
|
|
1263
1491
|
data = new FormData();
|
|
1264
1492
|
data.append('file', options.file);
|
|
1265
1493
|
if (options.data) {
|
|
1266
|
-
for (
|
|
1494
|
+
for (var d in options.data) {
|
|
1267
1495
|
data.append(d, data[d]);
|
|
1268
1496
|
}
|
|
1269
1497
|
}
|
|
@@ -1276,7 +1504,7 @@ let loadData;
|
|
|
1276
1504
|
: null;
|
|
1277
1505
|
}
|
|
1278
1506
|
if (onCancel) {
|
|
1279
|
-
onCancel(()
|
|
1507
|
+
onCancel(function () {
|
|
1280
1508
|
xhr.abort();
|
|
1281
1509
|
});
|
|
1282
1510
|
}
|
|
@@ -1285,10 +1513,10 @@ let loadData;
|
|
|
1285
1513
|
}
|
|
1286
1514
|
|
|
1287
1515
|
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1288
|
-
|
|
1516
|
+
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1289
1517
|
function template(str, data) {
|
|
1290
|
-
return str.replace(templateRe, (s, key)
|
|
1291
|
-
|
|
1518
|
+
return str.replace(templateRe, function (s, key) {
|
|
1519
|
+
var value = data[key];
|
|
1292
1520
|
if (value === undefined) {
|
|
1293
1521
|
throw new Error('No value provided for letiable ' + s);
|
|
1294
1522
|
}
|
|
@@ -1302,33 +1530,39 @@ function template(str, data) {
|
|
|
1302
1530
|
/**
|
|
1303
1531
|
* Thrown when ...
|
|
1304
1532
|
*/
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1533
|
+
var ResourceNotFoundError = /** @class */ (function (_super) {
|
|
1534
|
+
__extends(ResourceNotFoundError, _super);
|
|
1535
|
+
function ResourceNotFoundError(obj) {
|
|
1536
|
+
var _this = _super.call(this, obj) || this;
|
|
1537
|
+
_this.name = 'ResourceNotFoundError';
|
|
1538
|
+
_this.exception = 'nextgisweb.resource.exception.ResourceNotFound';
|
|
1539
|
+
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
1540
|
+
return _this;
|
|
1541
|
+
}
|
|
1542
|
+
return ResourceNotFoundError;
|
|
1543
|
+
}(NgwError));
|
|
1313
1544
|
|
|
1314
1545
|
/**
|
|
1315
1546
|
* Thrown when ...
|
|
1316
1547
|
*/
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1548
|
+
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
1549
|
+
__extends(InsufficientPermissionsError, _super);
|
|
1550
|
+
function InsufficientPermissionsError(obj) {
|
|
1551
|
+
var _this = _super.call(this, obj) || this;
|
|
1552
|
+
_this.name = 'InsufficientPermissionsError';
|
|
1553
|
+
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1554
|
+
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1555
|
+
return _this;
|
|
1556
|
+
}
|
|
1557
|
+
return InsufficientPermissionsError;
|
|
1558
|
+
}(NgwError));
|
|
1559
|
+
|
|
1560
|
+
var CONNECTORS = [];
|
|
1327
1561
|
function addConnector(connector) {
|
|
1328
1562
|
CONNECTORS.push(connector);
|
|
1329
1563
|
}
|
|
1330
1564
|
function findConnector(options) {
|
|
1331
|
-
return CONNECTORS.find((x)
|
|
1565
|
+
return CONNECTORS.find(function (x) {
|
|
1332
1566
|
if (x.options.baseUrl === options.baseUrl) {
|
|
1333
1567
|
if (options.auth) {
|
|
1334
1568
|
if (x.options.auth) {
|
|
@@ -1343,13 +1577,13 @@ function findConnector(options) {
|
|
|
1343
1577
|
});
|
|
1344
1578
|
}
|
|
1345
1579
|
function removeConnector(connector) {
|
|
1346
|
-
|
|
1580
|
+
var index = CONNECTORS.indexOf(connector);
|
|
1347
1581
|
if (index !== -1) {
|
|
1348
1582
|
CONNECTORS.splice(index, 1);
|
|
1349
1583
|
}
|
|
1350
1584
|
}
|
|
1351
1585
|
|
|
1352
|
-
|
|
1586
|
+
var exclude = ['description'];
|
|
1353
1587
|
/**
|
|
1354
1588
|
* @remarks
|
|
1355
1589
|
* https://docs.nextgis.ru/docs_ngweb_dev/doc/developer/resource.html#search-resources
|
|
@@ -1360,14 +1594,16 @@ const exclude = ['description'];
|
|
|
1360
1594
|
*
|
|
1361
1595
|
* @param resource - Any property from NGW resource item
|
|
1362
1596
|
*/
|
|
1363
|
-
function resourceToQuery(resource, prefix
|
|
1597
|
+
function resourceToQuery(resource, prefix) {
|
|
1598
|
+
if (prefix === void 0) { prefix = ''; }
|
|
1364
1599
|
prefix = prefix ? prefix + '__' : '';
|
|
1365
|
-
|
|
1366
|
-
for (
|
|
1600
|
+
var query = {};
|
|
1601
|
+
for (var _i = 0, _a = Object.entries(resource); _i < _a.length; _i++) {
|
|
1602
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
1367
1603
|
if (exclude.indexOf(key) === -1) {
|
|
1368
1604
|
if (isObject(value)) {
|
|
1369
1605
|
if (key === 'owner_user') {
|
|
1370
|
-
|
|
1606
|
+
var children = resourceToQuery(value, key);
|
|
1371
1607
|
Object.assign(query, children);
|
|
1372
1608
|
}
|
|
1373
1609
|
else if (key === 'parent' && 'id' in value) {
|
|
@@ -1386,8 +1622,8 @@ function resourceCompare(res1, res2) {
|
|
|
1386
1622
|
return objectDeepEqual(res1, res2);
|
|
1387
1623
|
}
|
|
1388
1624
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1625
|
+
var ResourcesControl = /** @class */ (function () {
|
|
1626
|
+
function ResourcesControl(connector) {
|
|
1391
1627
|
this.connector = connector;
|
|
1392
1628
|
this.cache = new Cache();
|
|
1393
1629
|
}
|
|
@@ -1401,10 +1637,11 @@ class ResourcesControl {
|
|
|
1401
1637
|
* @remarks
|
|
1402
1638
|
* Fetching resource would be cached to speed up next call
|
|
1403
1639
|
*/
|
|
1404
|
-
getOne(resource, requestOptions) {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1640
|
+
ResourcesControl.prototype.getOne = function (resource, requestOptions) {
|
|
1641
|
+
var _this = this;
|
|
1642
|
+
var cache = new Cache();
|
|
1643
|
+
var forCache = {};
|
|
1644
|
+
var opt = __assign(__assign({}, requestOptions), { cache: false });
|
|
1408
1645
|
if (typeof resource === 'string') {
|
|
1409
1646
|
forCache.keyname = resource;
|
|
1410
1647
|
}
|
|
@@ -1414,28 +1651,28 @@ class ResourcesControl {
|
|
|
1414
1651
|
else if (isObject(resource)) {
|
|
1415
1652
|
forCache.id = resource.id;
|
|
1416
1653
|
}
|
|
1417
|
-
|
|
1654
|
+
var makeRequest = function () {
|
|
1418
1655
|
if (typeof resource === 'string') {
|
|
1419
|
-
return
|
|
1656
|
+
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
1420
1657
|
}
|
|
1421
1658
|
else if (typeof resource === 'number') {
|
|
1422
|
-
return
|
|
1659
|
+
return _this._fetchResourceById(resource, opt);
|
|
1423
1660
|
}
|
|
1424
1661
|
else if (isObject(resource)) {
|
|
1425
|
-
return
|
|
1662
|
+
return _this._fetchResourceBy(resource, opt);
|
|
1426
1663
|
}
|
|
1427
1664
|
return CancelablePromise.resolve(undefined);
|
|
1428
1665
|
};
|
|
1429
1666
|
return cache.addFull('resource', makeRequest, forCache);
|
|
1430
|
-
}
|
|
1431
|
-
getOneOrFail(resource, requestOptions) {
|
|
1432
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
1667
|
+
};
|
|
1668
|
+
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
1669
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1433
1670
|
if (res) {
|
|
1434
1671
|
return res;
|
|
1435
1672
|
}
|
|
1436
1673
|
throw new ResourceNotFoundError();
|
|
1437
1674
|
});
|
|
1438
|
-
}
|
|
1675
|
+
};
|
|
1439
1676
|
/**
|
|
1440
1677
|
* A fast way to retrieve resource ID for any resource definition.
|
|
1441
1678
|
* @param resource - Any available resource definition
|
|
@@ -1446,19 +1683,19 @@ class ResourcesControl {
|
|
|
1446
1683
|
* then this method will come in handy to facilitate the extraction of the identifier
|
|
1447
1684
|
* if the resource is specified through a keyname or other parameters.
|
|
1448
1685
|
*/
|
|
1449
|
-
getId(resource, requestOptions) {
|
|
1686
|
+
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
1450
1687
|
if (typeof resource === 'number') {
|
|
1451
1688
|
return CancelablePromise.resolve(resource);
|
|
1452
1689
|
}
|
|
1453
1690
|
else if (typeof resource === 'string' || isObject(resource)) {
|
|
1454
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
1691
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1455
1692
|
if (res) {
|
|
1456
1693
|
return res.resource.id;
|
|
1457
1694
|
}
|
|
1458
1695
|
});
|
|
1459
1696
|
}
|
|
1460
1697
|
return CancelablePromise.resolve(undefined);
|
|
1461
|
-
}
|
|
1698
|
+
};
|
|
1462
1699
|
/**
|
|
1463
1700
|
* A fast way to retrieve resource ID for any resource definition.
|
|
1464
1701
|
* @param resource - Any available resource definition
|
|
@@ -1467,33 +1704,32 @@ class ResourcesControl {
|
|
|
1467
1704
|
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
1468
1705
|
* To not make one more checks if the resource is definitely exists
|
|
1469
1706
|
*/
|
|
1470
|
-
getIdOrFail(resource, requestOptions) {
|
|
1471
|
-
return this.getId(resource, requestOptions).then((resp)
|
|
1707
|
+
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
1708
|
+
return this.getId(resource, requestOptions).then(function (resp) {
|
|
1472
1709
|
if (resp === undefined) {
|
|
1473
1710
|
throw new Error();
|
|
1474
1711
|
}
|
|
1475
1712
|
return resp;
|
|
1476
1713
|
});
|
|
1477
|
-
}
|
|
1478
|
-
getMany(resource, requestOptions) {
|
|
1479
|
-
|
|
1714
|
+
};
|
|
1715
|
+
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
1716
|
+
var _this = this;
|
|
1717
|
+
return this._resourceCacheFilter(resource).then(function (items) {
|
|
1480
1718
|
if (!items.length) {
|
|
1481
|
-
|
|
1719
|
+
var query = {};
|
|
1482
1720
|
if (resource.keyname) {
|
|
1483
1721
|
query.keyname = resource.keyname;
|
|
1484
1722
|
}
|
|
1485
1723
|
else {
|
|
1486
1724
|
Object.assign(query, resourceToQuery(resource));
|
|
1487
1725
|
}
|
|
1488
|
-
return
|
|
1489
|
-
.get('resource.search', requestOptions, {
|
|
1490
|
-
|
|
1491
|
-
...query,
|
|
1492
|
-
})
|
|
1493
|
-
.then((resources) => {
|
|
1726
|
+
return _this.connector
|
|
1727
|
+
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
1728
|
+
.then(function (resources) {
|
|
1494
1729
|
if (resources) {
|
|
1495
|
-
for (
|
|
1496
|
-
|
|
1730
|
+
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
1731
|
+
var x = resources_1[_i];
|
|
1732
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(x), {
|
|
1497
1733
|
id: x.resource.id,
|
|
1498
1734
|
});
|
|
1499
1735
|
}
|
|
@@ -1503,97 +1739,122 @@ class ResourcesControl {
|
|
|
1503
1739
|
}
|
|
1504
1740
|
return items;
|
|
1505
1741
|
});
|
|
1506
|
-
}
|
|
1507
|
-
getParent(resource, requestOptions) {
|
|
1508
|
-
|
|
1742
|
+
};
|
|
1743
|
+
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
1744
|
+
var _this = this;
|
|
1745
|
+
return this.getOne(resource, requestOptions).then(function (child) {
|
|
1509
1746
|
if (child) {
|
|
1510
|
-
return
|
|
1747
|
+
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
1511
1748
|
}
|
|
1512
1749
|
return CancelablePromise.resolve(undefined);
|
|
1513
1750
|
});
|
|
1514
|
-
}
|
|
1515
|
-
getChildrenOf(resource, requestOptions) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1751
|
+
};
|
|
1752
|
+
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
1753
|
+
var _this = this;
|
|
1754
|
+
return this.getId(resource).then(function (parent) {
|
|
1755
|
+
return _this.connector
|
|
1756
|
+
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
1757
|
+
parent: parent,
|
|
1520
1758
|
})
|
|
1521
|
-
.then((items)
|
|
1522
|
-
for (
|
|
1523
|
-
|
|
1759
|
+
.then(function (items) {
|
|
1760
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
1761
|
+
var i = items_1[_i];
|
|
1762
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(i), {
|
|
1524
1763
|
id: i.resource.id,
|
|
1525
1764
|
});
|
|
1526
1765
|
}
|
|
1527
1766
|
return items;
|
|
1528
1767
|
});
|
|
1529
1768
|
});
|
|
1530
|
-
}
|
|
1531
|
-
update(resource, data) {
|
|
1532
|
-
|
|
1769
|
+
};
|
|
1770
|
+
ResourcesControl.prototype.update = function (resource, data) {
|
|
1771
|
+
var _this = this;
|
|
1772
|
+
return this.getId(resource).then(function (id) {
|
|
1533
1773
|
if (id !== undefined) {
|
|
1534
|
-
return
|
|
1774
|
+
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
1535
1775
|
}
|
|
1536
1776
|
});
|
|
1537
|
-
}
|
|
1777
|
+
};
|
|
1538
1778
|
/**
|
|
1539
1779
|
* Fast way to delete resource from NGW and clean cache.
|
|
1540
1780
|
* @param resource - Resource definition
|
|
1541
1781
|
*/
|
|
1542
|
-
delete(resource) {
|
|
1543
|
-
|
|
1782
|
+
ResourcesControl.prototype.delete = function (resource) {
|
|
1783
|
+
var _this = this;
|
|
1784
|
+
return this.getId(resource).then(function (id) {
|
|
1544
1785
|
if (id !== undefined) {
|
|
1545
|
-
return
|
|
1546
|
-
|
|
1786
|
+
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
1787
|
+
_this._cleanResourceItemCache(id);
|
|
1547
1788
|
return undefined;
|
|
1548
1789
|
});
|
|
1549
1790
|
}
|
|
1550
1791
|
});
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1792
|
+
};
|
|
1793
|
+
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
1794
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1795
|
+
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
1796
|
+
return __generator(this, function (_b) {
|
|
1797
|
+
switch (_b.label) {
|
|
1798
|
+
case 0:
|
|
1799
|
+
all = this.cache.all();
|
|
1800
|
+
toDelete = [];
|
|
1801
|
+
_i = 0, all_1 = all;
|
|
1802
|
+
_b.label = 1;
|
|
1803
|
+
case 1:
|
|
1804
|
+
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
1805
|
+
c = all_1[_i];
|
|
1806
|
+
cid = c.options && c.options.id;
|
|
1807
|
+
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
1808
|
+
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
1809
|
+
if (cid === id) {
|
|
1810
|
+
toDelete.push(c);
|
|
1811
|
+
}
|
|
1812
|
+
return [3 /*break*/, 4];
|
|
1813
|
+
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
1814
|
+
case 3:
|
|
1815
|
+
rid = _b.sent();
|
|
1816
|
+
if (rid === id) {
|
|
1817
|
+
toDelete.push(c);
|
|
1818
|
+
}
|
|
1819
|
+
_b.label = 4;
|
|
1820
|
+
case 4:
|
|
1821
|
+
_i++;
|
|
1822
|
+
return [3 /*break*/, 1];
|
|
1823
|
+
case 5:
|
|
1824
|
+
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
1825
|
+
d = toDelete_1[_a];
|
|
1826
|
+
this.cache.delete(d);
|
|
1827
|
+
}
|
|
1828
|
+
return [2 /*return*/];
|
|
1568
1829
|
}
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1830
|
+
});
|
|
1831
|
+
});
|
|
1832
|
+
};
|
|
1833
|
+
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
1834
|
+
var _this = this;
|
|
1835
|
+
var promise = function () {
|
|
1836
|
+
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
1837
|
+
};
|
|
1577
1838
|
return this.cache
|
|
1578
1839
|
.add('resource.item', promise, {
|
|
1579
|
-
id,
|
|
1840
|
+
id: id,
|
|
1580
1841
|
})
|
|
1581
|
-
.catch((er)
|
|
1842
|
+
.catch(function (er) {
|
|
1582
1843
|
if (!(er instanceof ResourceNotFoundError)) {
|
|
1583
1844
|
throw er;
|
|
1584
1845
|
}
|
|
1585
1846
|
return undefined;
|
|
1586
1847
|
});
|
|
1587
|
-
}
|
|
1588
|
-
_fetchResourceBy(resource, requestOptions) {
|
|
1589
|
-
return this.getMany(resource, requestOptions).then((resources)
|
|
1848
|
+
};
|
|
1849
|
+
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
1850
|
+
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
1590
1851
|
return resources[0];
|
|
1591
1852
|
});
|
|
1592
|
-
}
|
|
1593
|
-
_resourceCacheFilter(resource) {
|
|
1594
|
-
return CancelablePromise.all(this.cache.matchAll('resource.item')).then((resources)
|
|
1595
|
-
|
|
1596
|
-
resources.filter((x)
|
|
1853
|
+
};
|
|
1854
|
+
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
1855
|
+
return CancelablePromise.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
1856
|
+
var items = [];
|
|
1857
|
+
resources.filter(function (x) {
|
|
1597
1858
|
if (x) {
|
|
1598
1859
|
// identical by uniq props
|
|
1599
1860
|
if (resource.keyname && x.resource.keyname) {
|
|
@@ -1607,23 +1868,24 @@ class ResourcesControl {
|
|
|
1607
1868
|
});
|
|
1608
1869
|
return items;
|
|
1609
1870
|
});
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1871
|
+
};
|
|
1872
|
+
return ResourcesControl;
|
|
1873
|
+
}());
|
|
1612
1874
|
|
|
1613
1875
|
function apiRequest(opt) {
|
|
1614
|
-
|
|
1615
|
-
return new CancelablePromise((resolve, reject)
|
|
1876
|
+
var params = opt.params;
|
|
1877
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
1616
1878
|
opt.connector
|
|
1617
1879
|
.connect()
|
|
1618
|
-
.then((apiItems)
|
|
1619
|
-
|
|
1880
|
+
.then(function (apiItems) {
|
|
1881
|
+
var apiItem = apiItems && apiItems[opt.name];
|
|
1620
1882
|
if (apiItem) {
|
|
1621
|
-
apiItem = [
|
|
1622
|
-
|
|
1883
|
+
apiItem = __spreadArray([], apiItem, true);
|
|
1884
|
+
var url = apiItem.shift();
|
|
1623
1885
|
if (apiItem.length) {
|
|
1624
|
-
|
|
1625
|
-
for (
|
|
1626
|
-
|
|
1886
|
+
var replaceParams = {};
|
|
1887
|
+
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1888
|
+
var arg = apiItem[fry];
|
|
1627
1889
|
replaceParams[fry] = '{' + arg + '}';
|
|
1628
1890
|
if (params[arg] === undefined) {
|
|
1629
1891
|
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
@@ -1635,21 +1897,21 @@ function apiRequest(opt) {
|
|
|
1635
1897
|
}
|
|
1636
1898
|
// Transfer part of the parameters from `params` to the URL string
|
|
1637
1899
|
if (params) {
|
|
1638
|
-
|
|
1639
|
-
|
|
1900
|
+
var paramArray_1 = [];
|
|
1901
|
+
var paramList = params.paramList;
|
|
1640
1902
|
if (Array.isArray(paramList)) {
|
|
1641
1903
|
delete params.paramList;
|
|
1642
|
-
paramList.forEach((x)
|
|
1643
|
-
|
|
1904
|
+
paramList.forEach(function (x) {
|
|
1905
|
+
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1644
1906
|
});
|
|
1645
1907
|
}
|
|
1646
|
-
for (
|
|
1908
|
+
for (var p in params) {
|
|
1647
1909
|
if (apiItem.indexOf(p) === -1) {
|
|
1648
|
-
|
|
1910
|
+
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1649
1911
|
}
|
|
1650
1912
|
}
|
|
1651
|
-
if (
|
|
1652
|
-
url = url + '?' +
|
|
1913
|
+
if (paramArray_1.length) {
|
|
1914
|
+
url = url + '?' + paramArray_1.join('&');
|
|
1653
1915
|
}
|
|
1654
1916
|
}
|
|
1655
1917
|
if (url) {
|
|
@@ -1663,20 +1925,20 @@ function apiRequest(opt) {
|
|
|
1663
1925
|
resolve(undefined);
|
|
1664
1926
|
}
|
|
1665
1927
|
})
|
|
1666
|
-
.catch((er)
|
|
1928
|
+
.catch(function (er) {
|
|
1667
1929
|
reject(er);
|
|
1668
1930
|
});
|
|
1669
1931
|
});
|
|
1670
1932
|
}
|
|
1671
1933
|
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1934
|
+
var ID = 0;
|
|
1935
|
+
var NgwConnector$1 = /** @class */ (function () {
|
|
1936
|
+
function NgwConnector(options) {
|
|
1675
1937
|
this.options = options;
|
|
1676
1938
|
this.id = ID++;
|
|
1677
1939
|
this.emitter = new events.exports.EventEmitter();
|
|
1678
1940
|
this.routeStr = '/api/component/pyramid/route';
|
|
1679
|
-
|
|
1941
|
+
var exist = findConnector(options);
|
|
1680
1942
|
if (exist) {
|
|
1681
1943
|
return exist;
|
|
1682
1944
|
}
|
|
@@ -1688,19 +1950,19 @@ class NgwConnector$1 {
|
|
|
1688
1950
|
addConnector(this);
|
|
1689
1951
|
}
|
|
1690
1952
|
}
|
|
1691
|
-
|
|
1953
|
+
NgwConnector.create = function (options) {
|
|
1692
1954
|
return new this(options);
|
|
1693
|
-
}
|
|
1955
|
+
};
|
|
1694
1956
|
/**
|
|
1695
1957
|
* Fast way to specify the connection address to NextGIS Web.
|
|
1696
1958
|
* The current connection will be severed.
|
|
1697
1959
|
* @param baseUrl - NGW url
|
|
1698
1960
|
*/
|
|
1699
|
-
setNgw(baseUrl) {
|
|
1961
|
+
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
1700
1962
|
this.logout();
|
|
1701
1963
|
this.options.baseUrl = baseUrl;
|
|
1702
1964
|
addConnector(this);
|
|
1703
|
-
}
|
|
1965
|
+
};
|
|
1704
1966
|
/**
|
|
1705
1967
|
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1706
1968
|
* @remarks
|
|
@@ -1714,101 +1976,105 @@ class NgwConnector$1 {
|
|
|
1714
1976
|
* .catch((er) => console.log('Connection problem', er));
|
|
1715
1977
|
* ```
|
|
1716
1978
|
*/
|
|
1717
|
-
connect() {
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
reject(er);
|
|
1728
|
-
});
|
|
1729
|
-
};
|
|
1730
|
-
if (auth) {
|
|
1731
|
-
const { login, password } = auth;
|
|
1732
|
-
if (login && password) {
|
|
1733
|
-
return this.getUserInfo({ login, password })
|
|
1734
|
-
.then(() => {
|
|
1735
|
-
makeQuery();
|
|
1979
|
+
NgwConnector.prototype.connect = function () {
|
|
1980
|
+
var _this = this;
|
|
1981
|
+
var cache = new Cache();
|
|
1982
|
+
var auth = this.options.auth;
|
|
1983
|
+
var makeConnect = function () {
|
|
1984
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
1985
|
+
var makeQuery = function () {
|
|
1986
|
+
return _this.makeQuery(_this.routeStr, {}, {})
|
|
1987
|
+
.then(function (route) {
|
|
1988
|
+
resolve(route);
|
|
1736
1989
|
})
|
|
1737
|
-
.catch((er)
|
|
1990
|
+
.catch(function (er) {
|
|
1991
|
+
reject(er);
|
|
1992
|
+
});
|
|
1993
|
+
};
|
|
1994
|
+
if (auth) {
|
|
1995
|
+
var login = auth.login, password = auth.password;
|
|
1996
|
+
if (login && password) {
|
|
1997
|
+
return _this.getUserInfo({ login: login, password: password })
|
|
1998
|
+
.then(function () {
|
|
1999
|
+
makeQuery();
|
|
2000
|
+
})
|
|
2001
|
+
.catch(function (er) { return reject(er); });
|
|
2002
|
+
}
|
|
1738
2003
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
}
|
|
2004
|
+
return makeQuery();
|
|
2005
|
+
});
|
|
2006
|
+
};
|
|
1742
2007
|
return cache.add('route', makeConnect, {
|
|
1743
2008
|
id: this.id,
|
|
1744
|
-
auth,
|
|
2009
|
+
auth: auth,
|
|
1745
2010
|
baseUrl: this.options.baseUrl,
|
|
1746
2011
|
});
|
|
1747
|
-
}
|
|
2012
|
+
};
|
|
1748
2013
|
/**
|
|
1749
2014
|
* Quick way to change NextGIS Web user.
|
|
1750
2015
|
* @param credentials - New user credentials
|
|
1751
2016
|
*/
|
|
1752
|
-
login(credentials) {
|
|
2017
|
+
NgwConnector.prototype.login = function (credentials) {
|
|
1753
2018
|
this.logout();
|
|
1754
2019
|
addConnector(this);
|
|
1755
2020
|
return this.getUserInfo(credentials);
|
|
1756
|
-
}
|
|
2021
|
+
};
|
|
1757
2022
|
/**
|
|
1758
2023
|
* Disconnecting a user. Aborting all current requests
|
|
1759
2024
|
*/
|
|
1760
|
-
logout() {
|
|
2025
|
+
NgwConnector.prototype.logout = function () {
|
|
1761
2026
|
removeConnector(this);
|
|
1762
2027
|
this.options.auth = undefined;
|
|
1763
2028
|
this.user = undefined;
|
|
1764
2029
|
this.emitter.emit('logout');
|
|
1765
2030
|
this.resources.cache.clean();
|
|
1766
|
-
}
|
|
1767
|
-
getUserInfo(credentials) {
|
|
2031
|
+
};
|
|
2032
|
+
NgwConnector.prototype.getUserInfo = function (credentials) {
|
|
2033
|
+
var _this = this;
|
|
1768
2034
|
if (this.user && this.user.id) {
|
|
1769
2035
|
return CancelablePromise.resolve(this.user);
|
|
1770
2036
|
}
|
|
1771
2037
|
if (credentials) {
|
|
1772
2038
|
this.options.auth = credentials;
|
|
1773
2039
|
}
|
|
1774
|
-
|
|
2040
|
+
var options = {
|
|
1775
2041
|
headers: this.getAuthorizationHeaders(credentials),
|
|
1776
2042
|
// withCredentials: true
|
|
1777
2043
|
};
|
|
1778
2044
|
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
1779
2045
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
1780
|
-
.then((data)
|
|
1781
|
-
|
|
1782
|
-
|
|
2046
|
+
.then(function (data) {
|
|
2047
|
+
_this.user = data;
|
|
2048
|
+
_this.emitter.emit('login', data);
|
|
1783
2049
|
return data;
|
|
1784
2050
|
})
|
|
1785
|
-
.catch((er)
|
|
1786
|
-
|
|
2051
|
+
.catch(function (er) {
|
|
2052
|
+
_this.emitter.emit('login:error', er);
|
|
1787
2053
|
throw er;
|
|
1788
2054
|
});
|
|
1789
|
-
}
|
|
2055
|
+
};
|
|
1790
2056
|
/**
|
|
1791
2057
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
1792
2058
|
*/
|
|
1793
|
-
getAuthorizationHeaders(credentials) {
|
|
1794
|
-
|
|
2059
|
+
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
2060
|
+
var client = this.makeClientId(credentials);
|
|
1795
2061
|
if (client) {
|
|
1796
2062
|
return {
|
|
1797
2063
|
Authorization: 'Basic ' + client,
|
|
1798
2064
|
};
|
|
1799
2065
|
}
|
|
1800
|
-
}
|
|
1801
|
-
makeClientId(credentials) {
|
|
2066
|
+
};
|
|
2067
|
+
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
1802
2068
|
credentials = credentials || this.options.auth;
|
|
1803
2069
|
if (credentials) {
|
|
1804
|
-
|
|
1805
|
-
|
|
2070
|
+
var login = credentials.login, password = credentials.password;
|
|
2071
|
+
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
1806
2072
|
// @ts-ignore
|
|
1807
2073
|
{
|
|
1808
2074
|
return window.btoa(str);
|
|
1809
2075
|
}
|
|
1810
2076
|
}
|
|
1811
|
-
}
|
|
2077
|
+
};
|
|
1812
2078
|
/**
|
|
1813
2079
|
* Send request to NGW api router.
|
|
1814
2080
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -1838,25 +2104,27 @@ class NgwConnector$1 {
|
|
|
1838
2104
|
*
|
|
1839
2105
|
* ```
|
|
1840
2106
|
*/
|
|
1841
|
-
apiRequest(name, params_
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
2107
|
+
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
2108
|
+
var _this = this;
|
|
2109
|
+
if (params_ === void 0) { params_ = {}; }
|
|
2110
|
+
if (requestOptions === void 0) { requestOptions = {}; }
|
|
2111
|
+
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
2112
|
+
var params = objectRemoveEmpty(params_);
|
|
2113
|
+
var makeApiRequest = function () {
|
|
2114
|
+
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
2115
|
+
};
|
|
1845
2116
|
if (requestOptions.cache && method === 'GET') {
|
|
1846
|
-
|
|
1847
|
-
return cache.add(name, makeApiRequest, {
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
auth: this.options.auth,
|
|
1855
|
-
}),
|
|
1856
|
-
});
|
|
2117
|
+
var cache = new Cache();
|
|
2118
|
+
return cache.add(name, makeApiRequest, __assign({ params: params }, objectRemoveEmpty({
|
|
2119
|
+
headers: headers,
|
|
2120
|
+
withCredentials: withCredentials,
|
|
2121
|
+
responseType: responseType,
|
|
2122
|
+
baseUrl: this.options.baseUrl,
|
|
2123
|
+
auth: this.options.auth,
|
|
2124
|
+
})));
|
|
1857
2125
|
}
|
|
1858
2126
|
return makeApiRequest();
|
|
1859
|
-
}
|
|
2127
|
+
};
|
|
1860
2128
|
/**
|
|
1861
2129
|
* Shortcut method for send POST request to NGW.
|
|
1862
2130
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -1870,62 +2138,63 @@ class NgwConnector$1 {
|
|
|
1870
2138
|
* .catch((error) => console.warn(error));
|
|
1871
2139
|
* ```
|
|
1872
2140
|
*/
|
|
1873
|
-
post(name, options, params) {
|
|
2141
|
+
NgwConnector.prototype.post = function (name, options, params) {
|
|
1874
2142
|
options = options || {};
|
|
1875
2143
|
options.method = 'POST';
|
|
1876
2144
|
return this.apiRequest(name, params, options);
|
|
1877
|
-
}
|
|
2145
|
+
};
|
|
1878
2146
|
/**
|
|
1879
2147
|
* Shortcut method for send GET request to NGW.
|
|
1880
2148
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1881
2149
|
* @param options - Request options
|
|
1882
2150
|
* @param params - Request item params or query params
|
|
1883
2151
|
*/
|
|
1884
|
-
get(name, options, params) {
|
|
2152
|
+
NgwConnector.prototype.get = function (name, options, params) {
|
|
1885
2153
|
options = options || {};
|
|
1886
2154
|
options.method = 'GET';
|
|
1887
2155
|
return this.apiRequest(name, params, options);
|
|
1888
|
-
}
|
|
2156
|
+
};
|
|
1889
2157
|
/**
|
|
1890
2158
|
* Shortcut method for send PATCH request to NGW.
|
|
1891
2159
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1892
2160
|
* @param options - Request options
|
|
1893
2161
|
* @param params - Request item params or query params
|
|
1894
2162
|
*/
|
|
1895
|
-
patch(name, options, params) {
|
|
2163
|
+
NgwConnector.prototype.patch = function (name, options, params) {
|
|
1896
2164
|
options = options || {};
|
|
1897
2165
|
options.method = 'PATCH';
|
|
1898
2166
|
return this.apiRequest(name, params, options);
|
|
1899
|
-
}
|
|
2167
|
+
};
|
|
1900
2168
|
/**
|
|
1901
2169
|
* Shortcut method for send PUT request to NGW.
|
|
1902
2170
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1903
2171
|
* @param options - Request options
|
|
1904
2172
|
* @param params - Request item params or query params
|
|
1905
2173
|
*/
|
|
1906
|
-
put(name, options, params) {
|
|
2174
|
+
NgwConnector.prototype.put = function (name, options, params) {
|
|
1907
2175
|
options = options || {};
|
|
1908
2176
|
options.method = 'PUT';
|
|
1909
2177
|
return this.apiRequest(name, params, options);
|
|
1910
|
-
}
|
|
2178
|
+
};
|
|
1911
2179
|
/**
|
|
1912
2180
|
* Shortcut method for send DELETE request to NGW.
|
|
1913
2181
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1914
2182
|
* @param options - Request options
|
|
1915
2183
|
* @param params - Request item params or query params
|
|
1916
2184
|
*/
|
|
1917
|
-
delete(name, options, params) {
|
|
2185
|
+
NgwConnector.prototype.delete = function (name, options, params) {
|
|
1918
2186
|
options = options || {};
|
|
1919
2187
|
options.method = 'DELETE';
|
|
1920
2188
|
return this.apiRequest(name, params, options);
|
|
1921
|
-
}
|
|
2189
|
+
};
|
|
1922
2190
|
/**
|
|
1923
2191
|
* Send request to NGW.
|
|
1924
2192
|
* @param url - URL address to NGW
|
|
1925
2193
|
* @param params - Query params
|
|
1926
2194
|
* @param options - Request options
|
|
1927
2195
|
*/
|
|
1928
|
-
makeQuery(url, params, options
|
|
2196
|
+
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
2197
|
+
if (options === void 0) { options = {}; }
|
|
1929
2198
|
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
1930
2199
|
if (url) {
|
|
1931
2200
|
if (params) {
|
|
@@ -1938,112 +2207,110 @@ class NgwConnector$1 {
|
|
|
1938
2207
|
else {
|
|
1939
2208
|
throw new Error('Empty `url` not allowed');
|
|
1940
2209
|
}
|
|
1941
|
-
}
|
|
2210
|
+
};
|
|
1942
2211
|
// -------------------------------------------------------------------------
|
|
1943
2212
|
// Resource Methods
|
|
1944
2213
|
// -------------------------------------------------------------------------
|
|
1945
2214
|
/**
|
|
1946
2215
|
* {@inheritDoc ResourcesControl.getOne}
|
|
1947
2216
|
*/
|
|
1948
|
-
getResource(resource, requestOptions) {
|
|
2217
|
+
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
1949
2218
|
return this.resources.getOne(resource, requestOptions);
|
|
1950
|
-
}
|
|
2219
|
+
};
|
|
1951
2220
|
/**
|
|
1952
2221
|
* {@inheritDoc ResourcesControl.getOneOrFail}
|
|
1953
2222
|
*/
|
|
1954
|
-
getResourceOrFail(resource, requestOptions) {
|
|
2223
|
+
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
1955
2224
|
return this.resources.getOneOrFail(resource, requestOptions);
|
|
1956
|
-
}
|
|
2225
|
+
};
|
|
1957
2226
|
/**
|
|
1958
2227
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
1959
2228
|
*/
|
|
1960
|
-
getResourceBy(resource) {
|
|
2229
|
+
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
1961
2230
|
return this.resources.getOne(resource);
|
|
1962
|
-
}
|
|
2231
|
+
};
|
|
1963
2232
|
/**
|
|
1964
2233
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
1965
2234
|
*/
|
|
1966
|
-
getResourceByKeyname(keyname) {
|
|
2235
|
+
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
1967
2236
|
return this.resources.getOne(keyname);
|
|
1968
|
-
}
|
|
2237
|
+
};
|
|
1969
2238
|
/**
|
|
1970
2239
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
1971
2240
|
*/
|
|
1972
|
-
getResourceById(id) {
|
|
2241
|
+
NgwConnector.prototype.getResourceById = function (id) {
|
|
1973
2242
|
return this.resources.getOne(id);
|
|
1974
|
-
}
|
|
2243
|
+
};
|
|
1975
2244
|
/**
|
|
1976
2245
|
* {@inheritDoc ResourcesControl.getId}
|
|
1977
2246
|
*/
|
|
1978
|
-
getResourceId(resource, requestOptions) {
|
|
2247
|
+
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
1979
2248
|
return this.resources.getId(resource, requestOptions);
|
|
1980
|
-
}
|
|
2249
|
+
};
|
|
1981
2250
|
/**
|
|
1982
2251
|
* {@inheritDoc ResourcesControl.getIdOrFail}
|
|
1983
2252
|
*/
|
|
1984
|
-
getResourceIdOrFail(resource, requestOptions) {
|
|
2253
|
+
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
1985
2254
|
return this.resources.getIdOrFail(resource, requestOptions);
|
|
1986
|
-
}
|
|
2255
|
+
};
|
|
1987
2256
|
/**
|
|
1988
2257
|
* {@inheritDoc ResourcesControl.getMany}
|
|
1989
2258
|
*/
|
|
1990
|
-
getResourcesBy(resource, requestOptions) {
|
|
2259
|
+
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
1991
2260
|
return this.resources.getMany(resource, requestOptions);
|
|
1992
|
-
}
|
|
2261
|
+
};
|
|
1993
2262
|
/**
|
|
1994
2263
|
* {@inheritDoc ResourcesControl.getParent}
|
|
1995
2264
|
*/
|
|
1996
|
-
getResourceParent(resource, requestOptions) {
|
|
2265
|
+
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
1997
2266
|
return this.resources.getParent(resource, requestOptions);
|
|
1998
|
-
}
|
|
2267
|
+
};
|
|
1999
2268
|
/**
|
|
2000
2269
|
* {@inheritDoc ResourcesControl.getChildrenOf}
|
|
2001
2270
|
*/
|
|
2002
|
-
getResourceChildren(resource, requestOptions) {
|
|
2271
|
+
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
2003
2272
|
return this.resources.getChildrenOf(resource, requestOptions);
|
|
2004
|
-
}
|
|
2273
|
+
};
|
|
2005
2274
|
/**
|
|
2006
2275
|
* {@inheritDoc ResourcesControl.update}
|
|
2007
2276
|
*/
|
|
2008
|
-
updateResource(resource, data) {
|
|
2277
|
+
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
2009
2278
|
return this.resources.update(resource, data);
|
|
2010
|
-
}
|
|
2279
|
+
};
|
|
2011
2280
|
/**
|
|
2012
2281
|
* {@inheritDoc ResourcesControl.delete}
|
|
2013
2282
|
*/
|
|
2014
|
-
deleteResource(resource) {
|
|
2283
|
+
NgwConnector.prototype.deleteResource = function (resource) {
|
|
2015
2284
|
return this.resources.delete(resource);
|
|
2016
|
-
}
|
|
2285
|
+
};
|
|
2017
2286
|
/**
|
|
2018
2287
|
* @internal
|
|
2019
2288
|
*/
|
|
2020
|
-
_loadData(url, options) {
|
|
2289
|
+
NgwConnector.prototype._loadData = function (url, options) {
|
|
2290
|
+
var _this = this;
|
|
2021
2291
|
options.responseType = options.responseType || 'json';
|
|
2022
|
-
return new CancelablePromise((resolve, reject, onCancel)
|
|
2023
|
-
if (
|
|
2292
|
+
return new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2293
|
+
if (_this.user) {
|
|
2024
2294
|
options = options || {};
|
|
2025
2295
|
// options.withCredentials = true;
|
|
2026
|
-
options.headers = {
|
|
2027
|
-
...this.getAuthorizationHeaders(),
|
|
2028
|
-
...options.headers,
|
|
2029
|
-
};
|
|
2296
|
+
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
2030
2297
|
}
|
|
2031
2298
|
loadData(url, resolve, options, reject, onCancel);
|
|
2032
|
-
}).catch((httpError)
|
|
2299
|
+
}).catch(function (httpError) {
|
|
2033
2300
|
if (httpError instanceof CancelablePromise.CancelError) ;
|
|
2034
2301
|
else {
|
|
2035
2302
|
// @ts-ignore
|
|
2036
2303
|
{
|
|
2037
2304
|
console.warn('DEV WARN', httpError);
|
|
2038
2305
|
}
|
|
2039
|
-
|
|
2306
|
+
var er = _this._handleHttpError(httpError);
|
|
2040
2307
|
if (er) {
|
|
2041
2308
|
throw er;
|
|
2042
2309
|
}
|
|
2043
2310
|
}
|
|
2044
2311
|
});
|
|
2045
|
-
}
|
|
2046
|
-
_handleHttpError(er) {
|
|
2312
|
+
};
|
|
2313
|
+
NgwConnector.prototype._handleHttpError = function (er) {
|
|
2047
2314
|
if (er) {
|
|
2048
2315
|
if (er instanceof NgwError) {
|
|
2049
2316
|
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
@@ -2055,12 +2322,13 @@ class NgwConnector$1 {
|
|
|
2055
2322
|
}
|
|
2056
2323
|
}
|
|
2057
2324
|
return er;
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2325
|
+
};
|
|
2326
|
+
NgwConnector.errors = {
|
|
2327
|
+
NgwError: NgwError,
|
|
2328
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
2329
|
+
};
|
|
2330
|
+
return NgwConnector;
|
|
2331
|
+
}());
|
|
2064
2332
|
|
|
2065
2333
|
/**
|
|
2066
2334
|
* A lightweight HTTP client optimized for use with {@link http://docs.nextgis.ru/docs_ngweb_dev/doc/developer/toc.html | NextGIS Web} API
|
|
@@ -2074,64 +2342,115 @@ NgwConnector$1.errors = {
|
|
|
2074
2342
|
// export { NgwConnector };
|
|
2075
2343
|
var NgwConnector = NgwConnector$1;
|
|
2076
2344
|
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2345
|
+
var NgwProvider = /** @class */ (function (_super) {
|
|
2346
|
+
__extends(NgwProvider, _super);
|
|
2347
|
+
function NgwProvider(options) {
|
|
2348
|
+
var _this = _super.call(this, options) || this;
|
|
2349
|
+
_this.caseInsensitive = true;
|
|
2350
|
+
_this.searchUrl = 'https://maxim.nextgis.com';
|
|
2351
|
+
_this.searchResources = [];
|
|
2352
|
+
_this.requests = [];
|
|
2353
|
+
_this.connector =
|
|
2085
2354
|
options.connector ||
|
|
2086
2355
|
new NgwConnector({
|
|
2087
|
-
baseUrl:
|
|
2356
|
+
baseUrl: _this.searchUrl,
|
|
2088
2357
|
});
|
|
2089
|
-
|
|
2358
|
+
_this.searchResources = options.searchResources;
|
|
2359
|
+
return _this;
|
|
2090
2360
|
}
|
|
2091
|
-
abort() {
|
|
2092
|
-
this.requests.forEach((x)
|
|
2361
|
+
NgwProvider.prototype.abort = function () {
|
|
2362
|
+
this.requests.forEach(function (x) {
|
|
2093
2363
|
x.cancel();
|
|
2094
2364
|
});
|
|
2095
2365
|
this.requests = [];
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2366
|
+
};
|
|
2367
|
+
NgwProvider.prototype.search = function (like) {
|
|
2368
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
2369
|
+
var _loop_1, this_1, _i, _a, resource;
|
|
2370
|
+
var _this = this;
|
|
2371
|
+
return __generator(this, function (_b) {
|
|
2372
|
+
switch (_b.label) {
|
|
2373
|
+
case 0:
|
|
2374
|
+
_loop_1 = function (resource) {
|
|
2375
|
+
var limit, request, resp, entries, _loop_2, _c, _d, item;
|
|
2376
|
+
return __generator(this, function (_e) {
|
|
2377
|
+
switch (_e.label) {
|
|
2378
|
+
case 0:
|
|
2379
|
+
limit = resource.limit || 300;
|
|
2380
|
+
request = this_1.connector.get('feature_layer.store', {
|
|
2381
|
+
headers: { RANGE: "items=0-".concat(limit) },
|
|
2382
|
+
}, {
|
|
2383
|
+
id: resource.id,
|
|
2384
|
+
like: like,
|
|
2385
|
+
});
|
|
2386
|
+
this_1.requests.push(request);
|
|
2387
|
+
request.catch(function (er) {
|
|
2388
|
+
console.warn(er);
|
|
2389
|
+
});
|
|
2390
|
+
return [4 /*yield*/, __await(request)];
|
|
2391
|
+
case 1:
|
|
2392
|
+
resp = _e.sent();
|
|
2393
|
+
entries = [];
|
|
2394
|
+
if (resp) {
|
|
2395
|
+
resp.forEach(function (x) {
|
|
2396
|
+
entries.push(__assign({ query: like, resourceId: resource.id }, x));
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
_loop_2 = function (item) {
|
|
2400
|
+
return __generator(this, function (_f) {
|
|
2401
|
+
switch (_f.label) {
|
|
2402
|
+
case 0:
|
|
2403
|
+
item.result = function () { return _this.result(item); };
|
|
2404
|
+
return [4 /*yield*/, __await(item)];
|
|
2405
|
+
case 1: return [4 /*yield*/, _f.sent()];
|
|
2406
|
+
case 2:
|
|
2407
|
+
_f.sent();
|
|
2408
|
+
return [2 /*return*/];
|
|
2409
|
+
}
|
|
2410
|
+
});
|
|
2411
|
+
};
|
|
2412
|
+
_c = 0, _d = this_1._items(entries);
|
|
2413
|
+
_e.label = 2;
|
|
2414
|
+
case 2:
|
|
2415
|
+
if (!(_c < _d.length)) return [3 /*break*/, 5];
|
|
2416
|
+
item = _d[_c];
|
|
2417
|
+
return [5 /*yield**/, _loop_2(item)];
|
|
2418
|
+
case 3:
|
|
2419
|
+
_e.sent();
|
|
2420
|
+
_e.label = 4;
|
|
2421
|
+
case 4:
|
|
2422
|
+
_c++;
|
|
2423
|
+
return [3 /*break*/, 2];
|
|
2424
|
+
case 5: return [2 /*return*/];
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2427
|
+
};
|
|
2428
|
+
this_1 = this;
|
|
2429
|
+
_i = 0, _a = this.searchResources;
|
|
2430
|
+
_b.label = 1;
|
|
2431
|
+
case 1:
|
|
2432
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
2433
|
+
resource = _a[_i];
|
|
2434
|
+
return [5 /*yield**/, _loop_1(resource)];
|
|
2435
|
+
case 2:
|
|
2436
|
+
_b.sent();
|
|
2437
|
+
_b.label = 3;
|
|
2438
|
+
case 3:
|
|
2439
|
+
_i++;
|
|
2440
|
+
return [3 /*break*/, 1];
|
|
2441
|
+
case 4: return [2 /*return*/];
|
|
2442
|
+
}
|
|
2109
2443
|
});
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
entries.push({
|
|
2115
|
-
query: like,
|
|
2116
|
-
resourceId: resource.id,
|
|
2117
|
-
...x,
|
|
2118
|
-
});
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
for (const item of this._items(entries)) {
|
|
2122
|
-
item.result = () => this.result(item);
|
|
2123
|
-
yield item;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
result(item) {
|
|
2128
|
-
const req = this.connector
|
|
2444
|
+
});
|
|
2445
|
+
};
|
|
2446
|
+
NgwProvider.prototype.result = function (item) {
|
|
2447
|
+
var req = this.connector
|
|
2129
2448
|
.get('feature_layer.feature.item_extent', null, {
|
|
2130
2449
|
id: item.resourceId,
|
|
2131
2450
|
fid: item.featureId,
|
|
2132
2451
|
})
|
|
2133
|
-
.then((x)
|
|
2134
|
-
|
|
2452
|
+
.then(function (x) {
|
|
2453
|
+
var e = x.extent;
|
|
2135
2454
|
return {
|
|
2136
2455
|
text: item.text,
|
|
2137
2456
|
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],
|
|
@@ -2139,11 +2458,12 @@ class NgwProvider extends BaseProvider {
|
|
|
2139
2458
|
});
|
|
2140
2459
|
this.requests.push(req);
|
|
2141
2460
|
return req;
|
|
2142
|
-
}
|
|
2143
|
-
_items(entries) {
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2461
|
+
};
|
|
2462
|
+
NgwProvider.prototype._items = function (entries) {
|
|
2463
|
+
var _this = this;
|
|
2464
|
+
var items = [];
|
|
2465
|
+
entries.forEach(function (entry) {
|
|
2466
|
+
var meta = _this.searchResources.find(function (x) { return x.id === entry.resourceId; });
|
|
2147
2467
|
if (meta) {
|
|
2148
2468
|
items.push({
|
|
2149
2469
|
query: entry.query,
|
|
@@ -2154,72 +2474,107 @@ class NgwProvider extends BaseProvider {
|
|
|
2154
2474
|
}
|
|
2155
2475
|
});
|
|
2156
2476
|
return items;
|
|
2157
|
-
}
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2477
|
+
};
|
|
2478
|
+
return NgwProvider;
|
|
2479
|
+
}(BaseProvider));
|
|
2480
|
+
|
|
2481
|
+
var NominatimProvider = /** @class */ (function (_super) {
|
|
2482
|
+
__extends(NominatimProvider, _super);
|
|
2483
|
+
function NominatimProvider(options) {
|
|
2484
|
+
var _this = _super.call(this, options) || this;
|
|
2485
|
+
_this.searchUrl = 'https://nominatim.openstreetmap.org';
|
|
2486
|
+
_this._requests = [];
|
|
2487
|
+
return _this;
|
|
2488
|
+
}
|
|
2489
|
+
NominatimProvider.prototype.abort = function () {
|
|
2490
|
+
this._requests.forEach(function (x) { return x.cancel(); });
|
|
2168
2491
|
this._requests = [];
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2492
|
+
};
|
|
2493
|
+
NominatimProvider.prototype.search = function (val) {
|
|
2494
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
2495
|
+
var url, request, items, _loop_1, _i, items_1, i;
|
|
2496
|
+
var _this = this;
|
|
2497
|
+
return __generator(this, function (_a) {
|
|
2498
|
+
switch (_a.label) {
|
|
2499
|
+
case 0:
|
|
2500
|
+
url = fixUrlStr(
|
|
2501
|
+
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
2502
|
+
"".concat(this.searchUrl, "/search?format=geojson&polygon_geojson=1&q=").concat(val));
|
|
2503
|
+
request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2504
|
+
var xhr = new XMLHttpRequest();
|
|
2505
|
+
xhr.open('GET', url, true);
|
|
2506
|
+
xhr.onload = function () {
|
|
2507
|
+
try {
|
|
2508
|
+
var geojson = JSON.parse(xhr.responseText);
|
|
2509
|
+
var features = geojson.features.map(function (x) {
|
|
2510
|
+
return {
|
|
2511
|
+
geom: x,
|
|
2512
|
+
extent: x.bbox,
|
|
2513
|
+
text: x.properties && x.properties.display_name,
|
|
2514
|
+
query: val,
|
|
2515
|
+
};
|
|
2516
|
+
});
|
|
2517
|
+
resolve(features);
|
|
2518
|
+
}
|
|
2519
|
+
catch (er) {
|
|
2520
|
+
reject(er);
|
|
2521
|
+
}
|
|
2522
|
+
};
|
|
2523
|
+
xhr.onerror = function (er) {
|
|
2524
|
+
reject(er);
|
|
2525
|
+
};
|
|
2526
|
+
onCancel(function () {
|
|
2527
|
+
xhr.abort();
|
|
2528
|
+
});
|
|
2529
|
+
xhr.send();
|
|
2530
|
+
}).catch(function (er) {
|
|
2531
|
+
if (er.name === 'CancelError') ;
|
|
2532
|
+
throw er;
|
|
2533
|
+
});
|
|
2534
|
+
this._requests.push(request);
|
|
2535
|
+
return [4 /*yield*/, __await(request)];
|
|
2536
|
+
case 1:
|
|
2537
|
+
items = _a.sent();
|
|
2538
|
+
if (!items) return [3 /*break*/, 5];
|
|
2539
|
+
_loop_1 = function (i) {
|
|
2540
|
+
return __generator(this, function (_b) {
|
|
2541
|
+
switch (_b.label) {
|
|
2542
|
+
case 0:
|
|
2543
|
+
i.result = function () { return _this.result(i); };
|
|
2544
|
+
return [4 /*yield*/, __await(i)];
|
|
2545
|
+
case 1: return [4 /*yield*/, _b.sent()];
|
|
2546
|
+
case 2:
|
|
2547
|
+
_b.sent();
|
|
2548
|
+
return [2 /*return*/];
|
|
2549
|
+
}
|
|
2550
|
+
});
|
|
2187
2551
|
};
|
|
2188
|
-
|
|
2189
|
-
|
|
2552
|
+
_i = 0, items_1 = items;
|
|
2553
|
+
_a.label = 2;
|
|
2554
|
+
case 2:
|
|
2555
|
+
if (!(_i < items_1.length)) return [3 /*break*/, 5];
|
|
2556
|
+
i = items_1[_i];
|
|
2557
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
2558
|
+
case 3:
|
|
2559
|
+
_a.sent();
|
|
2560
|
+
_a.label = 4;
|
|
2561
|
+
case 4:
|
|
2562
|
+
_i++;
|
|
2563
|
+
return [3 /*break*/, 2];
|
|
2564
|
+
case 5: return [2 /*return*/];
|
|
2190
2565
|
}
|
|
2191
|
-
catch (er) {
|
|
2192
|
-
reject(er);
|
|
2193
|
-
}
|
|
2194
|
-
};
|
|
2195
|
-
xhr.onerror = (er) => {
|
|
2196
|
-
reject(er);
|
|
2197
|
-
};
|
|
2198
|
-
onCancel(() => {
|
|
2199
|
-
xhr.abort();
|
|
2200
2566
|
});
|
|
2201
|
-
xhr.send();
|
|
2202
|
-
}).catch((er) => {
|
|
2203
|
-
if (er.name === 'CancelError') ;
|
|
2204
|
-
throw er;
|
|
2205
2567
|
});
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
if (items) {
|
|
2209
|
-
for (const i of items) {
|
|
2210
|
-
i.result = () => this.result(i);
|
|
2211
|
-
yield i;
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
result(model) {
|
|
2568
|
+
};
|
|
2569
|
+
NominatimProvider.prototype.result = function (model) {
|
|
2216
2570
|
return CancelablePromise.resolve({
|
|
2217
2571
|
text: model.text,
|
|
2218
2572
|
extent: model.extent || [],
|
|
2219
2573
|
geom: model.geom,
|
|
2220
2574
|
});
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2575
|
+
};
|
|
2576
|
+
return NominatimProvider;
|
|
2577
|
+
}(BaseProvider));
|
|
2223
2578
|
|
|
2224
2579
|
function create(options) {
|
|
2225
2580
|
return new Geocoder(options);
|