@nextgis/geocoder 1.16.8 → 1.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -5
- package/lib/geocoder.cjs.js +255 -441
- package/lib/geocoder.cjs.js.map +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +2232 -2160
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +1 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +255 -441
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +2401 -1984
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/lib/index.d.ts +131 -8
- package/package.json +7 -6
package/lib/geocoder.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 1.18.3; author: NextGIS */
|
|
2
2
|
var Geocoder = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -16,7 +16,7 @@ var Geocoder = (function (exports) {
|
|
|
16
16
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise */
|
|
19
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
20
20
|
|
|
21
21
|
var extendStatics = function(d, b) {
|
|
22
22
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -60,7 +60,7 @@ var Geocoder = (function (exports) {
|
|
|
60
60
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
61
61
|
function step(op) {
|
|
62
62
|
if (f) throw new TypeError("Generator is already executing.");
|
|
63
|
-
while (_) try {
|
|
63
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
64
64
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
65
65
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
66
66
|
switch (op[0]) {
|
|
@@ -126,599 +126,672 @@ var Geocoder = (function (exports) {
|
|
|
126
126
|
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);
|
|
127
127
|
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); }); }; }
|
|
128
128
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
129
|
-
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
132
|
+
var e = new Error(message);
|
|
133
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
134
|
+
};
|
|
130
135
|
|
|
131
|
-
var CancelError = /** @class */ (function (_super) {
|
|
132
|
-
__extends(CancelError, _super);
|
|
133
|
-
function CancelError() {
|
|
134
|
-
var _this = _super.call(this) || this;
|
|
135
|
-
_this.name = 'CancelError';
|
|
136
|
-
Object.setPrototypeOf(_this, CancelError.prototype);
|
|
137
|
-
return _this;
|
|
138
|
-
}
|
|
139
|
-
return CancelError;
|
|
136
|
+
var CancelError = /** @class */ (function (_super) {
|
|
137
|
+
__extends(CancelError, _super);
|
|
138
|
+
function CancelError() {
|
|
139
|
+
var _this = _super.call(this) || this;
|
|
140
|
+
_this.name = 'CancelError';
|
|
141
|
+
Object.setPrototypeOf(_this, CancelError.prototype);
|
|
142
|
+
return _this;
|
|
143
|
+
}
|
|
144
|
+
return CancelError;
|
|
140
145
|
}(Error));
|
|
141
146
|
|
|
142
|
-
var PromiseControl = /** @class */ (function () {
|
|
143
|
-
function PromiseControl(options) {
|
|
144
|
-
if (options === void 0) { options = {}; }
|
|
145
|
-
this.options = options;
|
|
146
|
-
this._promises = new Map();
|
|
147
|
-
}
|
|
148
|
-
Object.defineProperty(PromiseControl.prototype, "isLoaded", {
|
|
149
|
-
get: function () {
|
|
150
|
-
return this._promises.size > 0;
|
|
151
|
-
},
|
|
152
|
-
enumerable: false,
|
|
153
|
-
configurable: true
|
|
154
|
-
});
|
|
155
|
-
PromiseControl.prototype.remove = function (promise) {
|
|
156
|
-
if (this._promises.has(promise)) {
|
|
157
|
-
this._promises.delete(promise);
|
|
158
|
-
this._onStop();
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
PromiseControl.prototype.get = function (promise) {
|
|
162
|
-
return this._promises.get(promise);
|
|
163
|
-
};
|
|
164
|
-
PromiseControl.prototype.add = function (promise, name) {
|
|
165
|
-
var _this = this;
|
|
166
|
-
var key = name ? name : promise;
|
|
167
|
-
var exist = this._promises.get(key);
|
|
168
|
-
if (this.options.onStart && !this.isLoaded) {
|
|
169
|
-
this.options.onStart();
|
|
170
|
-
}
|
|
171
|
-
if (exist) {
|
|
172
|
-
return exist;
|
|
173
|
-
}
|
|
174
|
-
this._promises.set(key, promise);
|
|
175
|
-
promise.finally(function () {
|
|
176
|
-
_this.remove(key);
|
|
177
|
-
});
|
|
178
|
-
return promise;
|
|
179
|
-
};
|
|
180
|
-
PromiseControl.prototype.abort = function () {
|
|
181
|
-
if (this.isLoaded) {
|
|
182
|
-
this._promises.forEach(function (x) {
|
|
183
|
-
if (x.cancel) {
|
|
184
|
-
x.cancel();
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
this._promises.clear();
|
|
188
|
-
this._onStop();
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
PromiseControl.prototype.waitFunc = function (func, name) {
|
|
192
|
-
if (name === void 0) { name = ''; }
|
|
193
|
-
name = name || func.name;
|
|
194
|
-
var exist = this.get(name);
|
|
195
|
-
if (exist) {
|
|
196
|
-
return exist;
|
|
197
|
-
}
|
|
198
|
-
return this.add(func(), name);
|
|
199
|
-
};
|
|
200
|
-
PromiseControl.prototype.WaitForMe = function (name) {
|
|
201
|
-
if (name === void 0) { name = ''; }
|
|
202
|
-
var get = this.get.bind(this);
|
|
203
|
-
var add = this.add.bind(this);
|
|
204
|
-
return function (target, key, descriptor) {
|
|
205
|
-
var originalMethod = descriptor.value;
|
|
206
|
-
name = name || key;
|
|
207
|
-
descriptor.value = function () {
|
|
208
|
-
var args = [];
|
|
209
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
210
|
-
args[_i] = arguments[_i];
|
|
211
|
-
}
|
|
212
|
-
var exist = get(name);
|
|
213
|
-
if (exist) {
|
|
214
|
-
return exist;
|
|
215
|
-
}
|
|
216
|
-
var result = add(originalMethod.apply(this, args), name);
|
|
217
|
-
return result;
|
|
218
|
-
};
|
|
219
|
-
return descriptor;
|
|
220
|
-
};
|
|
221
|
-
};
|
|
222
|
-
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
223
|
-
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
224
|
-
if (name === void 0) { name = ''; }
|
|
225
|
-
return this.WaitForMe(name);
|
|
226
|
-
};
|
|
227
|
-
PromiseControl.prototype._onStop = function () {
|
|
228
|
-
if (this.options.onStop && !this.isLoaded) {
|
|
229
|
-
this.options.onStop();
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
return PromiseControl;
|
|
147
|
+
var PromiseControl = /** @class */ (function () {
|
|
148
|
+
function PromiseControl(options) {
|
|
149
|
+
if (options === void 0) { options = {}; }
|
|
150
|
+
this.options = options;
|
|
151
|
+
this._promises = new Map();
|
|
152
|
+
}
|
|
153
|
+
Object.defineProperty(PromiseControl.prototype, "isLoaded", {
|
|
154
|
+
get: function () {
|
|
155
|
+
return this._promises.size > 0;
|
|
156
|
+
},
|
|
157
|
+
enumerable: false,
|
|
158
|
+
configurable: true
|
|
159
|
+
});
|
|
160
|
+
PromiseControl.prototype.remove = function (promise) {
|
|
161
|
+
if (this._promises.has(promise)) {
|
|
162
|
+
this._promises.delete(promise);
|
|
163
|
+
this._onStop();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
PromiseControl.prototype.get = function (promise) {
|
|
167
|
+
return this._promises.get(promise);
|
|
168
|
+
};
|
|
169
|
+
PromiseControl.prototype.add = function (promise, name) {
|
|
170
|
+
var _this = this;
|
|
171
|
+
var key = name ? name : promise;
|
|
172
|
+
var exist = this._promises.get(key);
|
|
173
|
+
if (this.options.onStart && !this.isLoaded) {
|
|
174
|
+
this.options.onStart();
|
|
175
|
+
}
|
|
176
|
+
if (exist) {
|
|
177
|
+
return exist;
|
|
178
|
+
}
|
|
179
|
+
this._promises.set(key, promise);
|
|
180
|
+
promise.finally(function () {
|
|
181
|
+
_this.remove(key);
|
|
182
|
+
});
|
|
183
|
+
return promise;
|
|
184
|
+
};
|
|
185
|
+
PromiseControl.prototype.abort = function () {
|
|
186
|
+
if (this.isLoaded) {
|
|
187
|
+
this._promises.forEach(function (x) {
|
|
188
|
+
if (x.cancel) {
|
|
189
|
+
x.cancel();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
this._promises.clear();
|
|
193
|
+
this._onStop();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
PromiseControl.prototype.waitFunc = function (func, name) {
|
|
197
|
+
if (name === void 0) { name = ''; }
|
|
198
|
+
name = name || func.name;
|
|
199
|
+
var exist = this.get(name);
|
|
200
|
+
if (exist) {
|
|
201
|
+
return exist;
|
|
202
|
+
}
|
|
203
|
+
return this.add(func(), name);
|
|
204
|
+
};
|
|
205
|
+
PromiseControl.prototype.WaitForMe = function (name) {
|
|
206
|
+
if (name === void 0) { name = ''; }
|
|
207
|
+
var get = this.get.bind(this);
|
|
208
|
+
var add = this.add.bind(this);
|
|
209
|
+
return function (target, key, descriptor) {
|
|
210
|
+
var originalMethod = descriptor.value;
|
|
211
|
+
name = name || key;
|
|
212
|
+
descriptor.value = function () {
|
|
213
|
+
var args = [];
|
|
214
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
215
|
+
args[_i] = arguments[_i];
|
|
216
|
+
}
|
|
217
|
+
var exist = get(name);
|
|
218
|
+
if (exist) {
|
|
219
|
+
return exist;
|
|
220
|
+
}
|
|
221
|
+
var result = add(originalMethod.apply(this, args), name);
|
|
222
|
+
return result;
|
|
223
|
+
};
|
|
224
|
+
return descriptor;
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
228
|
+
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
229
|
+
if (name === void 0) { name = ''; }
|
|
230
|
+
return this.WaitForMe(name);
|
|
231
|
+
};
|
|
232
|
+
PromiseControl.prototype._onStop = function () {
|
|
233
|
+
if (this.options.onStop && !this.isLoaded) {
|
|
234
|
+
this.options.onStop();
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
return PromiseControl;
|
|
233
238
|
}());
|
|
234
239
|
|
|
235
|
-
var TimeoutError = /** @class */ (function (_super) {
|
|
236
|
-
__extends(TimeoutError, _super);
|
|
237
|
-
function TimeoutError() {
|
|
238
|
-
var _this = _super.call(this) || this;
|
|
239
|
-
_this.name = 'TimeoutError';
|
|
240
|
-
Object.setPrototypeOf(_this, TimeoutError.prototype);
|
|
241
|
-
return _this;
|
|
242
|
-
}
|
|
243
|
-
return TimeoutError;
|
|
240
|
+
var TimeoutError = /** @class */ (function (_super) {
|
|
241
|
+
__extends(TimeoutError, _super);
|
|
242
|
+
function TimeoutError() {
|
|
243
|
+
var _this = _super.call(this) || this;
|
|
244
|
+
_this.name = 'TimeoutError';
|
|
245
|
+
Object.setPrototypeOf(_this, TimeoutError.prototype);
|
|
246
|
+
return _this;
|
|
247
|
+
}
|
|
248
|
+
return TimeoutError;
|
|
244
249
|
}(Error));
|
|
245
250
|
|
|
246
|
-
var handleCallback = function (resolve, reject, callback, r) {
|
|
247
|
-
try {
|
|
248
|
-
resolve(callback(r));
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
reject(e);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
var ID$2 = 0;
|
|
255
|
-
/**
|
|
256
|
-
* Promise that can be canceled
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* Catch `CancelError`
|
|
260
|
-
* ```javascript
|
|
261
|
-
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
262
|
-
*
|
|
263
|
-
* const promise = new CancelablePromise((resolve, reject) => {
|
|
264
|
-
* setTimeout(() => resolve(), 100);
|
|
265
|
-
* }).catch((er) => {
|
|
266
|
-
* if (er.name === "CancelError") {
|
|
267
|
-
* // handle cancel error
|
|
268
|
-
* }
|
|
269
|
-
* throw er;
|
|
270
|
-
* });
|
|
271
|
-
*
|
|
272
|
-
* promise.cancel();
|
|
273
|
-
* ```
|
|
274
|
-
* @example
|
|
275
|
-
* Handle `onCancel` callback
|
|
276
|
-
* ```javascript
|
|
277
|
-
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
278
|
-
*
|
|
279
|
-
* const promise = new CancelablePromise((resolve, reject, onCancel) => {
|
|
280
|
-
* const xhr = new XMLHttpRequest();
|
|
281
|
-
* xhr.open("GET", url, true);
|
|
282
|
-
* xhr.onload = () => {
|
|
283
|
-
* resolve(xhr.responseText);
|
|
284
|
-
* };
|
|
285
|
-
* xhr.onerror = (er) => {
|
|
286
|
-
* reject(er);
|
|
287
|
-
* };
|
|
288
|
-
*
|
|
289
|
-
* onCancel(() => {
|
|
290
|
-
* xhr.abort();
|
|
291
|
-
* });
|
|
292
|
-
*
|
|
293
|
-
* xhr.send();
|
|
294
|
-
* });
|
|
295
|
-
*
|
|
296
|
-
* promise.cancel();
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
var CancelablePromise$1 = /** @class */ (function () {
|
|
300
|
-
function CancelablePromise(executor, timeout) {
|
|
301
|
-
var _this = this;
|
|
302
|
-
this.id = ID$2++;
|
|
303
|
-
this._isCanceled = false;
|
|
304
|
-
this._isPending = true;
|
|
305
|
-
this._cancelHandlers = [];
|
|
306
|
-
this._children = [];
|
|
307
|
-
this._cancelPromise = new Promise(function (resolve_, reject_) {
|
|
308
|
-
_this._setCanceledCallback = function (er) { return resolve_(er || new CancelError()); };
|
|
309
|
-
});
|
|
310
|
-
var promises = [
|
|
311
|
-
this._cancelPromise,
|
|
312
|
-
new Promise(function (resolve, reject) {
|
|
313
|
-
var onResolve = function (value) {
|
|
314
|
-
if (value instanceof CancelablePromise) {
|
|
315
|
-
_this.attach(value);
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
_this._isPending = false;
|
|
319
|
-
}
|
|
320
|
-
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
321
|
-
resolve(value);
|
|
322
|
-
};
|
|
323
|
-
var onReject = function (error) {
|
|
324
|
-
_this._isPending = false;
|
|
325
|
-
reject(error);
|
|
326
|
-
};
|
|
327
|
-
var onCancel = function (handler) {
|
|
328
|
-
if (!_this._isPending) {
|
|
329
|
-
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
330
|
-
}
|
|
331
|
-
_this._cancelHandlers.push(handler);
|
|
332
|
-
};
|
|
333
|
-
return executor(onResolve, onReject, onCancel);
|
|
334
|
-
}),
|
|
335
|
-
];
|
|
336
|
-
if (timeout) {
|
|
337
|
-
promises.push(new Promise(function (resolve, reject) {
|
|
338
|
-
setTimeout(function () {
|
|
339
|
-
if (_this._isPending) {
|
|
340
|
-
try {
|
|
341
|
-
_this.cancel();
|
|
342
|
-
}
|
|
343
|
-
finally {
|
|
344
|
-
reject(new TimeoutError());
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}, timeout);
|
|
348
|
-
}));
|
|
349
|
-
}
|
|
350
|
-
this._promise = Promise.race(promises);
|
|
351
|
-
}
|
|
352
|
-
CancelablePromise.createControl = function (opt) {
|
|
353
|
-
return new PromiseControl(opt);
|
|
354
|
-
};
|
|
355
|
-
CancelablePromise.resolve = function (value) {
|
|
356
|
-
return new CancelablePromise(function (resolve) { return resolve(value); });
|
|
357
|
-
};
|
|
358
|
-
CancelablePromise.reject = function (value) {
|
|
359
|
-
return new CancelablePromise(function (resolve, reject) { return reject(value); });
|
|
360
|
-
};
|
|
361
|
-
CancelablePromise.all = function (values) {
|
|
362
|
-
var _this = this;
|
|
363
|
-
return new CancelablePromise(function (resolve, reject) {
|
|
364
|
-
Promise.all(values).then(resolve).catch(reject);
|
|
365
|
-
}).catch(function (er) {
|
|
366
|
-
if (er instanceof _this.CancelError) {
|
|
367
|
-
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
368
|
-
var v = values_1[_i];
|
|
369
|
-
var v_ = v;
|
|
370
|
-
if ('cancel' in v_) {
|
|
371
|
-
v_.cancel();
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
throw er;
|
|
376
|
-
});
|
|
377
|
-
};
|
|
378
|
-
CancelablePromise.prototype.attach = function (p) {
|
|
379
|
-
if (this._isCanceled) {
|
|
380
|
-
p.cancel();
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
this._children.push(p);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
CancelablePromise.prototype.then = function (onfulfilled, onrejected) {
|
|
387
|
-
var _this = this;
|
|
388
|
-
var p = new CancelablePromise(function (resolve, reject) {
|
|
389
|
-
if (_this._promise) {
|
|
390
|
-
var reject_1 = function (r) {
|
|
391
|
-
if (onrejected) {
|
|
392
|
-
handleCallback(resolve, reject, onrejected, r);
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
reject(r);
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
_this._promise.then(function (r) {
|
|
399
|
-
if (_this._isCanceled) {
|
|
400
|
-
reject_1(r);
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
if (onfulfilled) {
|
|
404
|
-
handleCallback(resolve, reject, onfulfilled, r);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
resolve(r);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}, reject_1);
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
p._parentPromise = this;
|
|
414
|
-
this._children.push(p);
|
|
415
|
-
return p;
|
|
416
|
-
};
|
|
417
|
-
CancelablePromise.prototype.catch = function (onrejected) {
|
|
418
|
-
if (this._isCanceled && onrejected) {
|
|
419
|
-
onrejected(new CancelError());
|
|
420
|
-
}
|
|
421
|
-
return this.then(undefined, onrejected);
|
|
422
|
-
};
|
|
423
|
-
CancelablePromise.prototype.finally = function (onfinally) {
|
|
424
|
-
if (this._promise) {
|
|
425
|
-
return this._promise.finally(onfinally);
|
|
426
|
-
}
|
|
427
|
-
if (this._isCanceled) {
|
|
428
|
-
return Promise.reject(new CancelError());
|
|
429
|
-
}
|
|
430
|
-
return Promise.reject(onfinally);
|
|
431
|
-
};
|
|
432
|
-
CancelablePromise.prototype.cancel = function () {
|
|
433
|
-
// No reason to run cancel action if promise is already complete
|
|
434
|
-
if (this._isCanceled || !this._isPending) {
|
|
435
|
-
return this;
|
|
436
|
-
}
|
|
437
|
-
this._isCanceled = true;
|
|
438
|
-
var parent = this._getTopParent();
|
|
439
|
-
if (parent) {
|
|
440
|
-
parent.cancel();
|
|
441
|
-
}
|
|
442
|
-
if (this._children) {
|
|
443
|
-
this._children.forEach(function (x) { return x.cancel(); });
|
|
444
|
-
}
|
|
445
|
-
if (this._isPending) {
|
|
446
|
-
if (this._cancelHandlers.length) {
|
|
447
|
-
try {
|
|
448
|
-
for (var _i = 0, _a = this._cancelHandlers; _i < _a.length; _i++) {
|
|
449
|
-
var handler = _a[_i];
|
|
450
|
-
handler();
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
catch (error) {
|
|
454
|
-
// this._setCanceledCallback(error);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if (this._setCanceledCallback) {
|
|
458
|
-
this._setCanceledCallback();
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
this._destroy();
|
|
462
|
-
return this;
|
|
463
|
-
};
|
|
464
|
-
CancelablePromise.prototype._getTopParent = function () {
|
|
465
|
-
var parent = this._parentPromise;
|
|
466
|
-
var hasParent = !!parent;
|
|
467
|
-
while (hasParent) {
|
|
468
|
-
if (parent && parent._parentPromise) {
|
|
469
|
-
parent = parent._parentPromise;
|
|
470
|
-
hasParent = !!parent;
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
hasParent = false;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return parent;
|
|
477
|
-
};
|
|
478
|
-
CancelablePromise.prototype._destroy = function () {
|
|
479
|
-
this._setCanceledCallback = undefined;
|
|
480
|
-
this._cancelPromise = undefined;
|
|
481
|
-
this._promise = undefined;
|
|
482
|
-
};
|
|
483
|
-
CancelablePromise.CancelError = CancelError;
|
|
484
|
-
CancelablePromise.TimeoutError = TimeoutError;
|
|
485
|
-
CancelablePromise.PromiseControl = PromiseControl;
|
|
486
|
-
return CancelablePromise;
|
|
487
|
-
}());
|
|
251
|
+
var handleCallback = function (resolve, reject, callback, r) {
|
|
252
|
+
try {
|
|
253
|
+
resolve(callback(r));
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
256
|
+
reject(e);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
var ID$2 = 0;
|
|
260
|
+
/**
|
|
261
|
+
* Promise that can be canceled
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* Catch `CancelError`
|
|
265
|
+
* ```javascript
|
|
266
|
+
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
267
|
+
*
|
|
268
|
+
* const promise = new CancelablePromise((resolve, reject) => {
|
|
269
|
+
* setTimeout(() => resolve(), 100);
|
|
270
|
+
* }).catch((er) => {
|
|
271
|
+
* if (er.name === "CancelError") {
|
|
272
|
+
* // handle cancel error
|
|
273
|
+
* }
|
|
274
|
+
* throw er;
|
|
275
|
+
* });
|
|
276
|
+
*
|
|
277
|
+
* promise.cancel();
|
|
278
|
+
* ```
|
|
279
|
+
* @example
|
|
280
|
+
* Handle `onCancel` callback
|
|
281
|
+
* ```javascript
|
|
282
|
+
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
283
|
+
*
|
|
284
|
+
* const promise = new CancelablePromise((resolve, reject, onCancel) => {
|
|
285
|
+
* const xhr = new XMLHttpRequest();
|
|
286
|
+
* xhr.open("GET", url, true);
|
|
287
|
+
* xhr.onload = () => {
|
|
288
|
+
* resolve(xhr.responseText);
|
|
289
|
+
* };
|
|
290
|
+
* xhr.onerror = (er) => {
|
|
291
|
+
* reject(er);
|
|
292
|
+
* };
|
|
293
|
+
*
|
|
294
|
+
* onCancel(() => {
|
|
295
|
+
* xhr.abort();
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* xhr.send();
|
|
299
|
+
* });
|
|
300
|
+
*
|
|
301
|
+
* promise.cancel();
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
var CancelablePromise$1 = /** @class */ (function () {
|
|
305
|
+
function CancelablePromise(executor, timeout) {
|
|
306
|
+
var _this = this;
|
|
307
|
+
this.id = ID$2++;
|
|
308
|
+
this._isCanceled = false;
|
|
309
|
+
this._isPending = true;
|
|
310
|
+
this._cancelHandlers = [];
|
|
311
|
+
this._children = [];
|
|
312
|
+
this._cancelPromise = new Promise(function (resolve_, reject_) {
|
|
313
|
+
_this._setCanceledCallback = function (er) { return resolve_(er || new CancelError()); };
|
|
314
|
+
});
|
|
315
|
+
var promises = [
|
|
316
|
+
this._cancelPromise,
|
|
317
|
+
new Promise(function (resolve, reject) {
|
|
318
|
+
var onResolve = function (value) {
|
|
319
|
+
if (value instanceof CancelablePromise) {
|
|
320
|
+
_this.attach(value);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
_this._isPending = false;
|
|
324
|
+
}
|
|
325
|
+
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
326
|
+
resolve(value);
|
|
327
|
+
};
|
|
328
|
+
var onReject = function (error) {
|
|
329
|
+
_this._isPending = false;
|
|
330
|
+
reject(error);
|
|
331
|
+
};
|
|
332
|
+
var onCancel = function (handler) {
|
|
333
|
+
if (!_this._isPending) {
|
|
334
|
+
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
335
|
+
}
|
|
336
|
+
_this._cancelHandlers.push(handler);
|
|
337
|
+
};
|
|
338
|
+
return executor(onResolve, onReject, onCancel);
|
|
339
|
+
}),
|
|
340
|
+
];
|
|
341
|
+
if (timeout) {
|
|
342
|
+
promises.push(new Promise(function (resolve, reject) {
|
|
343
|
+
setTimeout(function () {
|
|
344
|
+
if (_this._isPending) {
|
|
345
|
+
try {
|
|
346
|
+
_this.cancel();
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
reject(new TimeoutError());
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}, timeout);
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
this._promise = Promise.race(promises);
|
|
356
|
+
}
|
|
357
|
+
CancelablePromise.createControl = function (opt) {
|
|
358
|
+
return new PromiseControl(opt);
|
|
359
|
+
};
|
|
360
|
+
CancelablePromise.resolve = function (value) {
|
|
361
|
+
return new CancelablePromise(function (resolve) { return resolve(value); });
|
|
362
|
+
};
|
|
363
|
+
CancelablePromise.reject = function (value) {
|
|
364
|
+
return new CancelablePromise(function (resolve, reject) { return reject(value); });
|
|
365
|
+
};
|
|
366
|
+
CancelablePromise.all = function (values) {
|
|
367
|
+
var _this = this;
|
|
368
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
369
|
+
Promise.all(values).then(resolve).catch(reject);
|
|
370
|
+
}).catch(function (er) {
|
|
371
|
+
if (er instanceof _this.CancelError) {
|
|
372
|
+
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
373
|
+
var v = values_1[_i];
|
|
374
|
+
var v_ = v;
|
|
375
|
+
if ('cancel' in v_) {
|
|
376
|
+
v_.cancel();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
throw er;
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
CancelablePromise.prototype.attach = function (p) {
|
|
384
|
+
if (this._isCanceled) {
|
|
385
|
+
p.cancel();
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
this._children.push(p);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
CancelablePromise.prototype.then = function (onfulfilled, onrejected) {
|
|
392
|
+
var _this = this;
|
|
393
|
+
var p = new CancelablePromise(function (resolve, reject) {
|
|
394
|
+
if (_this._promise) {
|
|
395
|
+
var reject_1 = function (r) {
|
|
396
|
+
if (onrejected) {
|
|
397
|
+
handleCallback(resolve, reject, onrejected, r);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
reject(r);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
_this._promise.then(function (r) {
|
|
404
|
+
if (_this._isCanceled) {
|
|
405
|
+
reject_1(r);
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
if (onfulfilled) {
|
|
409
|
+
handleCallback(resolve, reject, onfulfilled, r);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
resolve(r);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}, reject_1);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
p._parentPromise = this;
|
|
419
|
+
this._children.push(p);
|
|
420
|
+
return p;
|
|
421
|
+
};
|
|
422
|
+
CancelablePromise.prototype.catch = function (onrejected) {
|
|
423
|
+
if (this._isCanceled && onrejected) {
|
|
424
|
+
onrejected(new CancelError());
|
|
425
|
+
}
|
|
426
|
+
return this.then(undefined, onrejected);
|
|
427
|
+
};
|
|
428
|
+
CancelablePromise.prototype.finally = function (onfinally) {
|
|
429
|
+
if (this._promise) {
|
|
430
|
+
return this._promise.finally(onfinally);
|
|
431
|
+
}
|
|
432
|
+
if (this._isCanceled) {
|
|
433
|
+
return Promise.reject(new CancelError());
|
|
434
|
+
}
|
|
435
|
+
return Promise.reject(onfinally);
|
|
436
|
+
};
|
|
437
|
+
CancelablePromise.prototype.cancel = function () {
|
|
438
|
+
// No reason to run cancel action if promise is already complete
|
|
439
|
+
if (this._isCanceled || !this._isPending) {
|
|
440
|
+
return this;
|
|
441
|
+
}
|
|
442
|
+
this._isCanceled = true;
|
|
443
|
+
var parent = this._getTopParent();
|
|
444
|
+
if (parent) {
|
|
445
|
+
parent.cancel();
|
|
446
|
+
}
|
|
447
|
+
if (this._children) {
|
|
448
|
+
this._children.forEach(function (x) { return x.cancel(); });
|
|
449
|
+
}
|
|
450
|
+
if (this._isPending) {
|
|
451
|
+
if (this._cancelHandlers.length) {
|
|
452
|
+
try {
|
|
453
|
+
for (var _i = 0, _a = this._cancelHandlers; _i < _a.length; _i++) {
|
|
454
|
+
var handler = _a[_i];
|
|
455
|
+
handler();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
// this._setCanceledCallback(error);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (this._setCanceledCallback) {
|
|
463
|
+
this._setCanceledCallback();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
this._destroy();
|
|
467
|
+
return this;
|
|
468
|
+
};
|
|
469
|
+
CancelablePromise.prototype._getTopParent = function () {
|
|
470
|
+
var parent = this._parentPromise;
|
|
471
|
+
var hasParent = !!parent;
|
|
472
|
+
while (hasParent) {
|
|
473
|
+
if (parent && parent._parentPromise) {
|
|
474
|
+
parent = parent._parentPromise;
|
|
475
|
+
hasParent = !!parent;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
hasParent = false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return parent;
|
|
482
|
+
};
|
|
483
|
+
CancelablePromise.prototype._destroy = function () {
|
|
484
|
+
this._setCanceledCallback = undefined;
|
|
485
|
+
this._cancelPromise = undefined;
|
|
486
|
+
this._promise = undefined;
|
|
487
|
+
};
|
|
488
|
+
CancelablePromise.CancelError = CancelError;
|
|
489
|
+
CancelablePromise.TimeoutError = TimeoutError;
|
|
490
|
+
CancelablePromise.PromiseControl = PromiseControl;
|
|
491
|
+
return CancelablePromise;
|
|
492
|
+
}());
|
|
488
493
|
Object.setPrototypeOf(CancelablePromise$1.prototype, Promise.prototype);
|
|
489
494
|
|
|
490
|
-
/**
|
|
491
|
-
* A promise you can stop
|
|
492
|
-
*
|
|
493
|
-
* @packageDocumentation
|
|
494
|
-
* @module cancelable-promise
|
|
495
|
-
*/
|
|
495
|
+
/**
|
|
496
|
+
* A promise you can stop
|
|
497
|
+
*
|
|
498
|
+
* @packageDocumentation
|
|
499
|
+
* @module cancelable-promise
|
|
500
|
+
*/
|
|
496
501
|
var CancelablePromise = CancelablePromise$1;
|
|
497
502
|
|
|
498
|
-
/**
|
|
499
|
-
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
500
|
-
*
|
|
501
|
-
* @param val - The object.
|
|
502
|
-
* @returns Returns true if the object is defined, returns false otherwise.
|
|
503
|
-
*
|
|
504
|
-
* @example
|
|
505
|
-
* ```javascript
|
|
506
|
-
* if (defined(positions)) {
|
|
507
|
-
* doSomething();
|
|
508
|
-
* } else {
|
|
509
|
-
* doSomethingElse();
|
|
510
|
-
* }
|
|
511
|
-
* ```
|
|
512
|
-
*/
|
|
513
|
-
function defined(val) {
|
|
514
|
-
return val !== undefined && val !== null;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
518
|
-
*
|
|
519
|
-
* @param val - The object.
|
|
520
|
-
* @returns Returns true if the object is defined and not empty string, returns false otherwise.
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* ```javascript
|
|
524
|
-
* full('foo') // true
|
|
525
|
-
* full('') // false
|
|
526
|
-
* full(undefined) // false
|
|
527
|
-
* full(0) // true
|
|
528
|
-
* ```
|
|
529
|
-
*/
|
|
530
|
-
function full(val) {
|
|
531
|
-
return typeof val === 'string' ? !!val : defined(val);
|
|
503
|
+
/**
|
|
504
|
+
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
505
|
+
*
|
|
506
|
+
* @param val - The object.
|
|
507
|
+
* @returns Returns true if the object is defined, returns false otherwise.
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```javascript
|
|
511
|
+
* if (defined(positions)) {
|
|
512
|
+
* doSomething();
|
|
513
|
+
* } else {
|
|
514
|
+
* doSomethingElse();
|
|
515
|
+
* }
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
function defined(val) {
|
|
519
|
+
return val !== undefined && val !== null;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
523
|
+
*
|
|
524
|
+
* @param val - The object.
|
|
525
|
+
* @returns Returns true if the object is defined and not empty string, returns false otherwise.
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```javascript
|
|
529
|
+
* full('foo') // true
|
|
530
|
+
* full('') // false
|
|
531
|
+
* full(undefined) // false
|
|
532
|
+
* full(0) // true
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
function full(val) {
|
|
536
|
+
return typeof val === 'string' ? !!val : defined(val);
|
|
532
537
|
}
|
|
533
538
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
function objectAssign(target) {
|
|
541
|
-
var sources = [];
|
|
542
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
543
|
-
sources[_i - 1] = arguments[_i];
|
|
544
|
-
}
|
|
545
|
-
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
|
|
546
|
-
var source = sources_1[_a];
|
|
547
|
-
for (var _b = 0, _c = Object.getOwnPropertyNames(source); _b < _c.length; _b++) {
|
|
548
|
-
var prop = _c[_b];
|
|
549
|
-
target[prop] = source[prop];
|
|
550
|
-
}
|
|
551
|
-
}
|
|
539
|
+
function getBoundsCoordinates(b) {
|
|
540
|
+
var westNorth = [b[0], b[1]];
|
|
541
|
+
var eastNorth = [b[2], b[1]];
|
|
542
|
+
var eastSouth = [b[2], b[3]];
|
|
543
|
+
var westSouth = [b[0], b[3]];
|
|
544
|
+
return [westNorth, eastNorth, eastSouth, westSouth, westNorth];
|
|
552
545
|
}
|
|
553
546
|
|
|
554
|
-
function
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
function objectDeepEqual(o, p) {
|
|
586
|
-
var keysO = Object.keys(o).sort();
|
|
587
|
-
var keysP = Object.keys(p).sort();
|
|
588
|
-
if (keysO.length !== keysP.length)
|
|
589
|
-
return false;
|
|
590
|
-
if (keysO.join('') !== keysP.join(''))
|
|
591
|
-
return false;
|
|
592
|
-
for (var i = 0; i < keysO.length; i++) {
|
|
593
|
-
var oVal = o[keysO[i]];
|
|
594
|
-
var pVal = p[keysP[i]];
|
|
595
|
-
if (!isEqual(oVal, pVal, o, p)) {
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return true;
|
|
547
|
+
function degrees2meters(lng, lat) {
|
|
548
|
+
lat = lat > 85.06 ? 85.06 : lat < -85.06 ? -85.06 : lat;
|
|
549
|
+
var x = (lng * 20037508.34) / 180;
|
|
550
|
+
var y = Math.log(Math.tan(((90 + lat) * Math.PI) / 360)) / (Math.PI / 180);
|
|
551
|
+
y = (y * 20037508.34) / 180;
|
|
552
|
+
return [x, y];
|
|
553
|
+
}
|
|
554
|
+
// export function degrees2meters2(lon: number, lat: number): [number, number] {
|
|
555
|
+
// const radius = 6378137.0;
|
|
556
|
+
// const x = (radius * lon * Math.PI) / 180.0;
|
|
557
|
+
// const y =
|
|
558
|
+
// radius * Math.log(Math.tan(Math.PI / 4.0 + (lat * Math.PI) / 360.0));
|
|
559
|
+
// return [x, y];
|
|
560
|
+
// }
|
|
561
|
+
// export function meters2degress2(x: number, y: number): LngLatArray {
|
|
562
|
+
// const radius = 6378137.0;
|
|
563
|
+
// const lon = (180 / Math.PI) * (x / radius);
|
|
564
|
+
// const lat = (360 / Math.PI) * (Math.atan(Math.exp(y / radius)) - Math.PI / 4);
|
|
565
|
+
// return [lon, lat];
|
|
566
|
+
// }
|
|
567
|
+
// const lon = -77.035974;
|
|
568
|
+
// const lat = 38.898717;
|
|
569
|
+
// console.log(degrees2meters(lon, lat), degrees2meters2(lon, lat));
|
|
570
|
+
// const x = -8575605.398443861;
|
|
571
|
+
// const y = 4707174.018280405;
|
|
572
|
+
// console.log(meters2degress(x, y), meters2degress2(x, y));
|
|
573
|
+
|
|
574
|
+
function isLngLatBoundsArray(array) {
|
|
575
|
+
return (Array.isArray(array) &&
|
|
576
|
+
array.length === 4 &&
|
|
577
|
+
array.every(function (x) { return typeof x === 'number'; }));
|
|
600
578
|
}
|
|
601
579
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
580
|
+
/**
|
|
581
|
+
* Copy the values of all of the enumerable own properties from one or more source objects to a
|
|
582
|
+
* target object. Returns the target object.
|
|
583
|
+
* @param target - The target object to copy to.
|
|
584
|
+
* @param sources - One or more source objects from which to copy properties
|
|
585
|
+
*/
|
|
586
|
+
function objectAssign(target) {
|
|
587
|
+
var sources = [];
|
|
588
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
589
|
+
sources[_i - 1] = arguments[_i];
|
|
590
|
+
}
|
|
591
|
+
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
|
|
592
|
+
var source = sources_1[_a];
|
|
593
|
+
for (var _b = 0, _c = Object.getOwnPropertyNames(source); _b < _c.length; _b++) {
|
|
594
|
+
var prop = _c[_b];
|
|
595
|
+
target[prop] = source[prop];
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function isEqual(a, b, o, p) {
|
|
601
|
+
if (a instanceof Array) {
|
|
602
|
+
if (!(b instanceof Array))
|
|
603
|
+
return false;
|
|
604
|
+
//if (compareObjects(oVal, pVal === false) return false
|
|
605
|
+
//would work, too, and perhaps is a better fit, still, this is easy, too
|
|
606
|
+
return b.sort().join('') === a.sort().join('');
|
|
607
|
+
}
|
|
608
|
+
else if (a instanceof Date) {
|
|
609
|
+
if (!(b instanceof Date))
|
|
610
|
+
return false;
|
|
611
|
+
return '' + a === '' + b;
|
|
612
|
+
}
|
|
613
|
+
else if (a instanceof Function) {
|
|
614
|
+
if (!(b instanceof Function))
|
|
615
|
+
return false;
|
|
616
|
+
//ignore functions, or check them regardless?
|
|
617
|
+
}
|
|
618
|
+
else if (a instanceof Object) {
|
|
619
|
+
if (!(b instanceof Object))
|
|
620
|
+
return false;
|
|
621
|
+
if (a === o) {
|
|
622
|
+
return b === p;
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
return objectDeepEqual(a, b);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return a === b;
|
|
629
|
+
}
|
|
630
|
+
// based on https://stackoverflow.com/a/13143059
|
|
631
|
+
function objectDeepEqual(o, p) {
|
|
632
|
+
var keysO = Object.keys(o).sort();
|
|
633
|
+
var keysP = Object.keys(p).sort();
|
|
634
|
+
if (keysO.length !== keysP.length)
|
|
635
|
+
return false;
|
|
636
|
+
if (keysO.join('') !== keysP.join(''))
|
|
637
|
+
return false;
|
|
638
|
+
for (var i = 0; i < keysO.length; i++) {
|
|
639
|
+
var oVal = o[keysO[i]];
|
|
640
|
+
var pVal = p[keysP[i]];
|
|
641
|
+
if (!isEqual(oVal, pVal, o, p)) {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function objectRemoveEmpty(obj) {
|
|
649
|
+
var newObj = {};
|
|
650
|
+
Object.keys(obj).forEach(function (key) {
|
|
651
|
+
if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
|
|
652
|
+
newObj[key] = objectRemoveEmpty(obj[key]);
|
|
653
|
+
}
|
|
654
|
+
else if (obj[key] !== undefined) {
|
|
655
|
+
newObj[key] = obj[key];
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
return newObj;
|
|
613
659
|
}
|
|
614
660
|
|
|
615
|
-
function
|
|
616
|
-
|
|
617
|
-
return
|
|
661
|
+
function round(val, toFixed) {
|
|
662
|
+
var n = toFixed ? Number('1e+' + toFixed) : 1;
|
|
663
|
+
return Math.round((val + Number.EPSILON) * n) / n;
|
|
618
664
|
}
|
|
619
665
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
666
|
+
function isObject$1(val) {
|
|
667
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
668
|
+
}
|
|
669
|
+
function isArray(val) {
|
|
670
|
+
return Object.prototype.toString.call(val) === '[object Array]';
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function fixUrlStr(url) {
|
|
674
|
+
// remove double slash
|
|
675
|
+
return url.replace(/([^:]\/)\/+/g, '$1');
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Represents the base class for a geocoder.
|
|
680
|
+
* This abstract class provides the basic methods that every geocoder should implement.
|
|
681
|
+
*
|
|
682
|
+
* @template O - The type of options that can be passed to the geocoder.
|
|
683
|
+
*/
|
|
684
|
+
var BaseGeocoder = /** @class */ (function () {
|
|
685
|
+
function BaseGeocoder(options) {
|
|
686
|
+
if (options) {
|
|
687
|
+
objectAssign(this, options);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return BaseGeocoder;
|
|
627
691
|
}());
|
|
628
692
|
|
|
629
|
-
var ID$1 = 0;
|
|
630
|
-
var Geocoder = /** @class */ (function (_super) {
|
|
631
|
-
__extends(Geocoder, _super);
|
|
632
|
-
function Geocoder(options) {
|
|
633
|
-
var _this = _super.call(this, options) || this;
|
|
634
|
-
_this.providers = [];
|
|
635
|
-
if (options && options.providers) {
|
|
636
|
-
_this.providers = options.providers;
|
|
637
|
-
}
|
|
638
|
-
return _this;
|
|
639
|
-
}
|
|
640
|
-
Geocoder.prototype.abort = function () {
|
|
641
|
-
this.providers.forEach(function (x) {
|
|
642
|
-
if (x.abort) {
|
|
643
|
-
x.abort();
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
};
|
|
647
|
-
Geocoder.prototype.search = function (query) {
|
|
648
|
-
return __asyncGenerator(this, arguments, function search_1() {
|
|
649
|
-
var _i, _a, provider, results, results_1, results_1_1, r, e_1_1;
|
|
650
|
-
var e_1,
|
|
651
|
-
return __generator(this, function (
|
|
652
|
-
switch (
|
|
653
|
-
case 0:
|
|
654
|
-
_i = 0, _a = this.providers;
|
|
655
|
-
|
|
656
|
-
case 1:
|
|
657
|
-
if (!(_i < _a.length)) return [3 /*break*/, 19];
|
|
658
|
-
provider = _a[_i];
|
|
659
|
-
|
|
660
|
-
case 2:
|
|
661
|
-
|
|
662
|
-
results = provider.search(query);
|
|
663
|
-
|
|
664
|
-
case 3:
|
|
665
|
-
|
|
666
|
-
results_1 = (e_1 = void 0, __asyncValues(results));
|
|
667
|
-
|
|
668
|
-
case 4: return [4 /*yield*/, __await(results_1.next())];
|
|
669
|
-
case 5:
|
|
670
|
-
if (!(results_1_1 =
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
case
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
case
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
return [
|
|
687
|
-
case
|
|
688
|
-
|
|
689
|
-
_c
|
|
690
|
-
|
|
691
|
-
case
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
case
|
|
695
|
-
case
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
case 18
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
693
|
+
var ID$1 = 0;
|
|
694
|
+
var Geocoder = /** @class */ (function (_super) {
|
|
695
|
+
__extends(Geocoder, _super);
|
|
696
|
+
function Geocoder(options) {
|
|
697
|
+
var _this = _super.call(this, options) || this;
|
|
698
|
+
_this.providers = [];
|
|
699
|
+
if (options && options.providers) {
|
|
700
|
+
_this.providers = options.providers;
|
|
701
|
+
}
|
|
702
|
+
return _this;
|
|
703
|
+
}
|
|
704
|
+
Geocoder.prototype.abort = function () {
|
|
705
|
+
this.providers.forEach(function (x) {
|
|
706
|
+
if (x.abort) {
|
|
707
|
+
x.abort();
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
};
|
|
711
|
+
Geocoder.prototype.search = function (query) {
|
|
712
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
713
|
+
var _i, _a, provider, results, _b, results_1, results_1_1, r, e_1_1;
|
|
714
|
+
var _c, e_1, _d, _e;
|
|
715
|
+
return __generator(this, function (_f) {
|
|
716
|
+
switch (_f.label) {
|
|
717
|
+
case 0:
|
|
718
|
+
_i = 0, _a = this.providers;
|
|
719
|
+
_f.label = 1;
|
|
720
|
+
case 1:
|
|
721
|
+
if (!(_i < _a.length)) return [3 /*break*/, 19];
|
|
722
|
+
provider = _a[_i];
|
|
723
|
+
_f.label = 2;
|
|
724
|
+
case 2:
|
|
725
|
+
_f.trys.push([2, 17, , 18]);
|
|
726
|
+
results = provider.search(query);
|
|
727
|
+
_f.label = 3;
|
|
728
|
+
case 3:
|
|
729
|
+
_f.trys.push([3, 10, 11, 16]);
|
|
730
|
+
_b = true, results_1 = (e_1 = void 0, __asyncValues(results));
|
|
731
|
+
_f.label = 4;
|
|
732
|
+
case 4: return [4 /*yield*/, __await(results_1.next())];
|
|
733
|
+
case 5:
|
|
734
|
+
if (!(results_1_1 = _f.sent(), _c = results_1_1.done, !_c)) return [3 /*break*/, 9];
|
|
735
|
+
_e = results_1_1.value;
|
|
736
|
+
_b = false;
|
|
737
|
+
r = _e;
|
|
738
|
+
return [4 /*yield*/, __await(__assign(__assign({}, r), { provider: provider, _id: ID$1++ }))];
|
|
739
|
+
case 6: return [4 /*yield*/, _f.sent()];
|
|
740
|
+
case 7:
|
|
741
|
+
_f.sent();
|
|
742
|
+
_f.label = 8;
|
|
743
|
+
case 8:
|
|
744
|
+
_b = true;
|
|
745
|
+
return [3 /*break*/, 4];
|
|
746
|
+
case 9: return [3 /*break*/, 16];
|
|
747
|
+
case 10:
|
|
748
|
+
e_1_1 = _f.sent();
|
|
749
|
+
e_1 = { error: e_1_1 };
|
|
750
|
+
return [3 /*break*/, 16];
|
|
751
|
+
case 11:
|
|
752
|
+
_f.trys.push([11, , 14, 15]);
|
|
753
|
+
if (!(!_b && !_c && (_d = results_1.return))) return [3 /*break*/, 13];
|
|
754
|
+
return [4 /*yield*/, __await(_d.call(results_1))];
|
|
755
|
+
case 12:
|
|
756
|
+
_f.sent();
|
|
757
|
+
_f.label = 13;
|
|
758
|
+
case 13: return [3 /*break*/, 15];
|
|
759
|
+
case 14:
|
|
760
|
+
if (e_1) throw e_1.error;
|
|
761
|
+
return [7 /*endfinally*/];
|
|
762
|
+
case 15: return [7 /*endfinally*/];
|
|
763
|
+
case 16: return [3 /*break*/, 18];
|
|
764
|
+
case 17:
|
|
765
|
+
_f.sent();
|
|
766
|
+
return [3 /*break*/, 18];
|
|
767
|
+
case 18:
|
|
768
|
+
_i++;
|
|
769
|
+
return [3 /*break*/, 1];
|
|
770
|
+
case 19: return [2 /*return*/];
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
Geocoder.prototype.result = function (item) {
|
|
776
|
+
if (item.provider) {
|
|
777
|
+
return item.provider.result(item);
|
|
778
|
+
}
|
|
779
|
+
return CancelablePromise.resolve(undefined);
|
|
780
|
+
};
|
|
781
|
+
return Geocoder;
|
|
714
782
|
}(BaseGeocoder));
|
|
715
783
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
784
|
+
/**
|
|
785
|
+
* Abstract base class representing a search provider.
|
|
786
|
+
* It builds upon the BaseGeocoder functionalities with provider-specific properties.
|
|
787
|
+
* @template O - Options type which extends BaseProviderOptions.
|
|
788
|
+
*/
|
|
789
|
+
var BaseProvider = /** @class */ (function (_super) {
|
|
790
|
+
__extends(BaseProvider, _super);
|
|
791
|
+
function BaseProvider() {
|
|
792
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
793
|
+
}
|
|
794
|
+
return BaseProvider;
|
|
722
795
|
}(BaseGeocoder));
|
|
723
796
|
|
|
724
797
|
var events = {exports: {}};
|
|
@@ -1197,1455 +1270,1799 @@ var Geocoder = (function (exports) {
|
|
|
1197
1270
|
}
|
|
1198
1271
|
}
|
|
1199
1272
|
|
|
1200
|
-
/**
|
|
1201
|
-
* @example
|
|
1202
|
-
* ```javascript
|
|
1203
|
-
* const cache1 = new Cache();
|
|
1204
|
-
* cache1.add('foo', 'value');
|
|
1205
|
-
*
|
|
1206
|
-
* const cache2 = new Cache();
|
|
1207
|
-
* cache2.match('foo'); // value
|
|
1208
|
-
*
|
|
1209
|
-
* const cache3 = new Cache({ namespace: 'foo' });
|
|
1210
|
-
* cache3.match('foo'); // undefined
|
|
1211
|
-
* ```
|
|
1212
|
-
*
|
|
1213
|
-
* @example
|
|
1214
|
-
* ```javascript
|
|
1215
|
-
* let COUNTER = 0;
|
|
1216
|
-
* const createPromise = () => new Promise((res) => {
|
|
1217
|
-
* COUNTER++
|
|
1218
|
-
* setTimeout(() => res('Ok'), 300)
|
|
1219
|
-
* });
|
|
1220
|
-
*
|
|
1221
|
-
* const cache = new Cache();
|
|
1222
|
-
* for (let i = 0; i < 10; i++) {
|
|
1223
|
-
* cache.add('foo', createPromise).then((data) => {
|
|
1224
|
-
* console.log(data); // 'Ok'
|
|
1225
|
-
* });
|
|
1226
|
-
* }
|
|
1227
|
-
* console.log(COUNTER); // 1
|
|
1228
|
-
* ```
|
|
1229
|
-
*/
|
|
1230
|
-
var Cache$1 = /** @class */ (function () {
|
|
1231
|
-
function Cache(options) {
|
|
1232
|
-
if (options === void 0) { options = {}; }
|
|
1233
|
-
var _a;
|
|
1234
|
-
this.cache = [];
|
|
1235
|
-
var namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
1236
|
-
if (Cache.instance[namespace]) {
|
|
1237
|
-
return Cache.instance[namespace];
|
|
1238
|
-
}
|
|
1239
|
-
Cache.instance[namespace] = this;
|
|
1240
|
-
return this;
|
|
1241
|
-
}
|
|
1242
|
-
Cache.prototype.clean = function () {
|
|
1243
|
-
this.cache.length = 0;
|
|
1244
|
-
};
|
|
1245
|
-
Cache.prototype.all = function () {
|
|
1246
|
-
return this.cache;
|
|
1247
|
-
};
|
|
1248
|
-
/**
|
|
1249
|
-
* Caching only a non-empty value.
|
|
1250
|
-
*
|
|
1251
|
-
* Useful for get or create strategy
|
|
1252
|
-
* @example
|
|
1253
|
-
* ```javascript
|
|
1254
|
-
* const cache = new Cache();
|
|
1255
|
-
* const getItemFunc = () => fetch(url).then((data) => {
|
|
1256
|
-
* return data.json(); // undefined
|
|
1257
|
-
* });
|
|
1258
|
-
* const item = await cache.addFull('foo', getItemFunc);
|
|
1259
|
-
* if (!item) {
|
|
1260
|
-
* await createItem(); // 'New item'
|
|
1261
|
-
* }
|
|
1262
|
-
*
|
|
1263
|
-
* // somewhere else in the code
|
|
1264
|
-
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
1265
|
-
* console.log(resp); // 'New item'
|
|
1266
|
-
* })
|
|
1267
|
-
*
|
|
1268
|
-
* ```
|
|
1269
|
-
*/
|
|
1270
|
-
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
1271
|
-
return this.add(key, valueToSet, props, true);
|
|
1272
|
-
};
|
|
1273
|
-
Cache.prototype.add = function (key, valueToSet, props, onlyFull) {
|
|
1274
|
-
var _this = this;
|
|
1275
|
-
var exist = this._find(key, props);
|
|
1276
|
-
if (!exist) {
|
|
1277
|
-
var value = void 0;
|
|
1278
|
-
if (valueToSet instanceof Function) {
|
|
1279
|
-
value = valueToSet();
|
|
1280
|
-
}
|
|
1281
|
-
else {
|
|
1282
|
-
value = valueToSet;
|
|
1283
|
-
}
|
|
1284
|
-
var props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
1285
|
-
var cacheItem = {
|
|
1286
|
-
key: key,
|
|
1287
|
-
value: value,
|
|
1288
|
-
props: props_,
|
|
1289
|
-
// TODO: remove backward compatibility use only props
|
|
1290
|
-
options: props_,
|
|
1291
|
-
};
|
|
1292
|
-
if (onlyFull && !full(value)) {
|
|
1293
|
-
return value;
|
|
1294
|
-
}
|
|
1295
|
-
this.cache.push(cacheItem);
|
|
1296
|
-
if (value instanceof Promise) {
|
|
1297
|
-
value.catch(function (er) {
|
|
1298
|
-
_this.delete(key, props);
|
|
1299
|
-
throw er;
|
|
1300
|
-
});
|
|
1301
|
-
if (onlyFull) {
|
|
1302
|
-
value.then(function (x) {
|
|
1303
|
-
if (!full(x)) {
|
|
1304
|
-
_this.delete(key, props);
|
|
1305
|
-
}
|
|
1306
|
-
return x;
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
|
-
return value;
|
|
1310
|
-
}
|
|
1311
|
-
return value;
|
|
1312
|
-
}
|
|
1313
|
-
else {
|
|
1314
|
-
return exist.value;
|
|
1315
|
-
}
|
|
1316
|
-
};
|
|
1317
|
-
Cache.prototype.match = function (key, props) {
|
|
1318
|
-
var cacheRecord = this._find(key, props);
|
|
1319
|
-
if (cacheRecord) {
|
|
1320
|
-
return cacheRecord.value;
|
|
1321
|
-
}
|
|
1322
|
-
};
|
|
1323
|
-
Cache.prototype.matchAll = function (key, props) {
|
|
1324
|
-
var _this = this;
|
|
1325
|
-
if (key) {
|
|
1326
|
-
return this.cache
|
|
1327
|
-
.filter(function (x) { return _this._filter(x, key, props); })
|
|
1328
|
-
.map(function (x) { return x.value; });
|
|
1329
|
-
}
|
|
1330
|
-
return this.cache.map(function (x) { return x.value; });
|
|
1331
|
-
};
|
|
1332
|
-
Cache.prototype.delete = function (keyOrItem, props) {
|
|
1333
|
-
var _this = this;
|
|
1334
|
-
var exist = [];
|
|
1335
|
-
if (typeof keyOrItem === 'string') {
|
|
1336
|
-
exist = this.cache.filter(function (x) { return _this._filter(x, keyOrItem, props); });
|
|
1337
|
-
}
|
|
1338
|
-
else {
|
|
1339
|
-
exist.push(keyOrItem);
|
|
1340
|
-
}
|
|
1341
|
-
for (var _i = 0, exist_1 = exist; _i < exist_1.length; _i++) {
|
|
1342
|
-
var e = exist_1[_i];
|
|
1343
|
-
var index = this.cache.indexOf(e);
|
|
1344
|
-
this.cache.splice(index, 1);
|
|
1345
|
-
}
|
|
1346
|
-
};
|
|
1347
|
-
Cache.prototype._find = function (key, props) {
|
|
1348
|
-
var _this = this;
|
|
1349
|
-
return this.cache.find(function (x) { return _this._filter(x, key, props); });
|
|
1350
|
-
};
|
|
1351
|
-
Cache.prototype._filter = function (item, key, props) {
|
|
1352
|
-
if (item.key === key) {
|
|
1353
|
-
if (props) {
|
|
1354
|
-
// TODO: remove backward compatibility
|
|
1355
|
-
var itemProps = item.props || item.options;
|
|
1356
|
-
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
1357
|
-
}
|
|
1358
|
-
return true;
|
|
1359
|
-
}
|
|
1360
|
-
return false;
|
|
1361
|
-
};
|
|
1362
|
-
Cache.instance = {};
|
|
1363
|
-
return Cache;
|
|
1273
|
+
/**
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```javascript
|
|
1276
|
+
* const cache1 = new Cache();
|
|
1277
|
+
* cache1.add('foo', 'value');
|
|
1278
|
+
*
|
|
1279
|
+
* const cache2 = new Cache();
|
|
1280
|
+
* cache2.match('foo'); // value
|
|
1281
|
+
*
|
|
1282
|
+
* const cache3 = new Cache({ namespace: 'foo' });
|
|
1283
|
+
* cache3.match('foo'); // undefined
|
|
1284
|
+
* ```
|
|
1285
|
+
*
|
|
1286
|
+
* @example
|
|
1287
|
+
* ```javascript
|
|
1288
|
+
* let COUNTER = 0;
|
|
1289
|
+
* const createPromise = () => new Promise((res) => {
|
|
1290
|
+
* COUNTER++
|
|
1291
|
+
* setTimeout(() => res('Ok'), 300)
|
|
1292
|
+
* });
|
|
1293
|
+
*
|
|
1294
|
+
* const cache = new Cache();
|
|
1295
|
+
* for (let i = 0; i < 10; i++) {
|
|
1296
|
+
* cache.add('foo', createPromise).then((data) => {
|
|
1297
|
+
* console.log(data); // 'Ok'
|
|
1298
|
+
* });
|
|
1299
|
+
* }
|
|
1300
|
+
* console.log(COUNTER); // 1
|
|
1301
|
+
* ```
|
|
1302
|
+
*/
|
|
1303
|
+
var Cache$1 = /** @class */ (function () {
|
|
1304
|
+
function Cache(options) {
|
|
1305
|
+
if (options === void 0) { options = {}; }
|
|
1306
|
+
var _a;
|
|
1307
|
+
this.cache = [];
|
|
1308
|
+
var namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
1309
|
+
if (Cache.instance[namespace]) {
|
|
1310
|
+
return Cache.instance[namespace];
|
|
1311
|
+
}
|
|
1312
|
+
Cache.instance[namespace] = this;
|
|
1313
|
+
return this;
|
|
1314
|
+
}
|
|
1315
|
+
Cache.prototype.clean = function () {
|
|
1316
|
+
this.cache.length = 0;
|
|
1317
|
+
};
|
|
1318
|
+
Cache.prototype.all = function () {
|
|
1319
|
+
return this.cache;
|
|
1320
|
+
};
|
|
1321
|
+
/**
|
|
1322
|
+
* Caching only a non-empty value.
|
|
1323
|
+
*
|
|
1324
|
+
* Useful for get or create strategy
|
|
1325
|
+
* @example
|
|
1326
|
+
* ```javascript
|
|
1327
|
+
* const cache = new Cache();
|
|
1328
|
+
* const getItemFunc = () => fetch(url).then((data) => {
|
|
1329
|
+
* return data.json(); // undefined
|
|
1330
|
+
* });
|
|
1331
|
+
* const item = await cache.addFull('foo', getItemFunc);
|
|
1332
|
+
* if (!item) {
|
|
1333
|
+
* await createItem(); // 'New item'
|
|
1334
|
+
* }
|
|
1335
|
+
*
|
|
1336
|
+
* // somewhere else in the code
|
|
1337
|
+
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
1338
|
+
* console.log(resp); // 'New item'
|
|
1339
|
+
* })
|
|
1340
|
+
*
|
|
1341
|
+
* ```
|
|
1342
|
+
*/
|
|
1343
|
+
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
1344
|
+
return this.add(key, valueToSet, props, true);
|
|
1345
|
+
};
|
|
1346
|
+
Cache.prototype.add = function (key, valueToSet, props, onlyFull) {
|
|
1347
|
+
var _this = this;
|
|
1348
|
+
var exist = this._find(key, props);
|
|
1349
|
+
if (!exist) {
|
|
1350
|
+
var value = void 0;
|
|
1351
|
+
if (valueToSet instanceof Function) {
|
|
1352
|
+
value = valueToSet();
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
value = valueToSet;
|
|
1356
|
+
}
|
|
1357
|
+
var props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
1358
|
+
var cacheItem = {
|
|
1359
|
+
key: key,
|
|
1360
|
+
value: value,
|
|
1361
|
+
props: props_,
|
|
1362
|
+
// TODO: remove backward compatibility use only props
|
|
1363
|
+
options: props_,
|
|
1364
|
+
};
|
|
1365
|
+
if (onlyFull && !full(value)) {
|
|
1366
|
+
return value;
|
|
1367
|
+
}
|
|
1368
|
+
this.cache.push(cacheItem);
|
|
1369
|
+
if (value instanceof Promise) {
|
|
1370
|
+
value.catch(function (er) {
|
|
1371
|
+
_this.delete(key, props);
|
|
1372
|
+
throw er;
|
|
1373
|
+
});
|
|
1374
|
+
if (onlyFull) {
|
|
1375
|
+
value.then(function (x) {
|
|
1376
|
+
if (!full(x)) {
|
|
1377
|
+
_this.delete(key, props);
|
|
1378
|
+
}
|
|
1379
|
+
return x;
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
return value;
|
|
1383
|
+
}
|
|
1384
|
+
return value;
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
return exist.value;
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
Cache.prototype.match = function (key, props) {
|
|
1391
|
+
var cacheRecord = this._find(key, props);
|
|
1392
|
+
if (cacheRecord) {
|
|
1393
|
+
return cacheRecord.value;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
Cache.prototype.matchAll = function (key, props) {
|
|
1397
|
+
var _this = this;
|
|
1398
|
+
if (key) {
|
|
1399
|
+
return this.cache
|
|
1400
|
+
.filter(function (x) { return _this._filter(x, key, props); })
|
|
1401
|
+
.map(function (x) { return x.value; });
|
|
1402
|
+
}
|
|
1403
|
+
return this.cache.map(function (x) { return x.value; });
|
|
1404
|
+
};
|
|
1405
|
+
Cache.prototype.delete = function (keyOrItem, props) {
|
|
1406
|
+
var _this = this;
|
|
1407
|
+
var exist = [];
|
|
1408
|
+
if (typeof keyOrItem === 'string') {
|
|
1409
|
+
exist = this.cache.filter(function (x) { return _this._filter(x, keyOrItem, props); });
|
|
1410
|
+
}
|
|
1411
|
+
else {
|
|
1412
|
+
exist.push(keyOrItem);
|
|
1413
|
+
}
|
|
1414
|
+
for (var _i = 0, exist_1 = exist; _i < exist_1.length; _i++) {
|
|
1415
|
+
var e = exist_1[_i];
|
|
1416
|
+
var index = this.cache.indexOf(e);
|
|
1417
|
+
this.cache.splice(index, 1);
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
Cache.prototype._find = function (key, props) {
|
|
1421
|
+
var _this = this;
|
|
1422
|
+
return this.cache.find(function (x) { return _this._filter(x, key, props); });
|
|
1423
|
+
};
|
|
1424
|
+
Cache.prototype._filter = function (item, key, props) {
|
|
1425
|
+
if (item.key === key) {
|
|
1426
|
+
if (props) {
|
|
1427
|
+
// TODO: remove backward compatibility
|
|
1428
|
+
var itemProps = item.props || item.options;
|
|
1429
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
1430
|
+
}
|
|
1431
|
+
return true;
|
|
1432
|
+
}
|
|
1433
|
+
return false;
|
|
1434
|
+
};
|
|
1435
|
+
Cache.instance = {};
|
|
1436
|
+
return Cache;
|
|
1364
1437
|
}());
|
|
1365
1438
|
|
|
1366
|
-
/**
|
|
1367
|
-
* Caching for asynchronous functions
|
|
1368
|
-
*
|
|
1369
|
-
* @packageDocumentation
|
|
1370
|
-
* @module cache
|
|
1371
|
-
*/
|
|
1439
|
+
/**
|
|
1440
|
+
* Caching for asynchronous functions
|
|
1441
|
+
*
|
|
1442
|
+
* @packageDocumentation
|
|
1443
|
+
* @module cache
|
|
1444
|
+
*/
|
|
1372
1445
|
var Cache = Cache$1;
|
|
1373
1446
|
|
|
1374
|
-
/**
|
|
1375
|
-
* Thrown when...
|
|
1376
|
-
*/
|
|
1377
|
-
var NetworkError = /** @class */ (function (_super) {
|
|
1378
|
-
__extends(NetworkError, _super);
|
|
1379
|
-
function NetworkError(url) {
|
|
1380
|
-
var _this = _super.call(this) || this;
|
|
1381
|
-
_this.name = 'NetworkError';
|
|
1382
|
-
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1383
|
-
_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
|
|
1384
|
-
return _this;
|
|
1385
|
-
}
|
|
1386
|
-
return NetworkError;
|
|
1447
|
+
/**
|
|
1448
|
+
* Thrown when...
|
|
1449
|
+
*/
|
|
1450
|
+
var NetworkError = /** @class */ (function (_super) {
|
|
1451
|
+
__extends(NetworkError, _super);
|
|
1452
|
+
function NetworkError(url) {
|
|
1453
|
+
var _this = _super.call(this) || this;
|
|
1454
|
+
_this.name = 'NetworkError';
|
|
1455
|
+
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1456
|
+
_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
|
|
1457
|
+
return _this;
|
|
1458
|
+
}
|
|
1459
|
+
return NetworkError;
|
|
1387
1460
|
}(Error));
|
|
1388
1461
|
|
|
1389
|
-
/**
|
|
1390
|
-
* Thrown when...
|
|
1391
|
-
*/
|
|
1392
|
-
var NgwError = /** @class */ (function (_super) {
|
|
1393
|
-
__extends(NgwError, _super);
|
|
1394
|
-
function NgwError(er) {
|
|
1395
|
-
var _this = _super.call(this) || this;
|
|
1396
|
-
_this.name = 'NgwError';
|
|
1397
|
-
Object.assign(_this, er);
|
|
1398
|
-
Object.setPrototypeOf(_this, NgwError.prototype);
|
|
1399
|
-
return _this;
|
|
1400
|
-
}
|
|
1401
|
-
return NgwError;
|
|
1462
|
+
/**
|
|
1463
|
+
* Thrown when...
|
|
1464
|
+
*/
|
|
1465
|
+
var NgwError = /** @class */ (function (_super) {
|
|
1466
|
+
__extends(NgwError, _super);
|
|
1467
|
+
function NgwError(er) {
|
|
1468
|
+
var _this = _super.call(this) || this;
|
|
1469
|
+
_this.name = 'NgwError';
|
|
1470
|
+
Object.assign(_this, er);
|
|
1471
|
+
Object.setPrototypeOf(_this, NgwError.prototype);
|
|
1472
|
+
return _this;
|
|
1473
|
+
}
|
|
1474
|
+
return NgwError;
|
|
1402
1475
|
}(Error));
|
|
1403
1476
|
|
|
1404
|
-
function isObject(val) {
|
|
1405
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1477
|
+
function isObject(val) {
|
|
1478
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1406
1479
|
}
|
|
1407
1480
|
|
|
1408
|
-
var loadData;
|
|
1409
|
-
// @ts-ignore
|
|
1410
|
-
{
|
|
1411
|
-
loadData = function (url, callback, options, error, onCancel) {
|
|
1412
|
-
if (options === void 0) { options = {}; }
|
|
1413
|
-
options.method = options.method || 'GET';
|
|
1414
|
-
var xhr = new XMLHttpRequest();
|
|
1415
|
-
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1416
|
-
if (options.responseType === 'blob') {
|
|
1417
|
-
xhr.responseType = options.responseType;
|
|
1418
|
-
}
|
|
1419
|
-
var getResponseText = function () {
|
|
1420
|
-
try {
|
|
1421
|
-
return JSON.parse(xhr.responseText);
|
|
1422
|
-
}
|
|
1423
|
-
catch (er) {
|
|
1424
|
-
return xhr.responseText;
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
var processingResponse = function (forError) {
|
|
1428
|
-
if (forError === void 0) { forError = false; }
|
|
1429
|
-
var cb = forError ? error : callback;
|
|
1430
|
-
if (options.responseType === 'blob') {
|
|
1431
|
-
cb(xhr.response);
|
|
1432
|
-
}
|
|
1433
|
-
else {
|
|
1434
|
-
if (xhr.responseText) {
|
|
1435
|
-
cb(getResponseText());
|
|
1436
|
-
}
|
|
1437
|
-
else {
|
|
1438
|
-
error({ message: '' });
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
};
|
|
1442
|
-
xhr.onload = function () {
|
|
1443
|
-
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1444
|
-
error(new NgwError(getResponseText()));
|
|
1445
|
-
}
|
|
1446
|
-
processingResponse();
|
|
1447
|
-
};
|
|
1448
|
-
// xhr.onreadystatechange = () => {
|
|
1449
|
-
// if (
|
|
1450
|
-
// (xhr.readyState === 4 && xhr.status === 200) ||
|
|
1451
|
-
// (xhr.readyState === 3 && xhr.status === 201)
|
|
1452
|
-
// ) {
|
|
1453
|
-
// processingResponse();
|
|
1454
|
-
// } else if (xhr.readyState === 3 && xhr.status === 400) {
|
|
1455
|
-
// processingResponse();
|
|
1456
|
-
// } else if (xhr.readyState === 4 && xhr.status === 500) {
|
|
1457
|
-
// processingResponse();
|
|
1458
|
-
// } else if (xhr.readyState === 4 && xhr.status === 401) {
|
|
1459
|
-
// error(xhr.statusText);
|
|
1460
|
-
// } else if (xhr.readyState === 4) {
|
|
1461
|
-
// error('request error');
|
|
1462
|
-
// }
|
|
1463
|
-
// };
|
|
1464
|
-
xhr.onerror = function (er) {
|
|
1465
|
-
if (xhr.status === 0) {
|
|
1466
|
-
error(new NetworkError(url));
|
|
1467
|
-
}
|
|
1468
|
-
else {
|
|
1469
|
-
error(er);
|
|
1470
|
-
}
|
|
1471
|
-
};
|
|
1472
|
-
xhr.upload.onprogress = function (e) {
|
|
1473
|
-
if (e.lengthComputable) {
|
|
1474
|
-
var percentComplete = (e.loaded / e.total) * 100;
|
|
1475
|
-
if (options.onProgress) {
|
|
1476
|
-
options.onProgress(percentComplete, e);
|
|
1477
|
-
}
|
|
1478
|
-
// console.log(percentComplete + '% uploaded');
|
|
1479
|
-
}
|
|
1480
|
-
};
|
|
1481
|
-
var headers = options.headers;
|
|
1482
|
-
if (headers) {
|
|
1483
|
-
for (var h in headers) {
|
|
1484
|
-
var header = headers[h];
|
|
1485
|
-
if (typeof header === 'string') {
|
|
1486
|
-
xhr.setRequestHeader(h, header);
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
if (options.withCredentials !== undefined) {
|
|
1491
|
-
xhr.withCredentials = options.withCredentials;
|
|
1492
|
-
}
|
|
1493
|
-
var data;
|
|
1494
|
-
if (options.file) {
|
|
1495
|
-
data = new FormData();
|
|
1496
|
-
data.append('file', options.file);
|
|
1497
|
-
if (options.data) {
|
|
1498
|
-
for (var d in options.data) {
|
|
1499
|
-
data.append(d, data[d]);
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
else {
|
|
1504
|
-
data = options.data
|
|
1505
|
-
? typeof options.data === 'string'
|
|
1506
|
-
? options.data
|
|
1507
|
-
: JSON.stringify(options.data)
|
|
1508
|
-
: null;
|
|
1509
|
-
}
|
|
1510
|
-
if (onCancel) {
|
|
1511
|
-
onCancel(function () {
|
|
1512
|
-
xhr.abort();
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
xhr.send(data);
|
|
1516
|
-
};
|
|
1481
|
+
var loadData;
|
|
1482
|
+
// @ts-ignore
|
|
1483
|
+
{
|
|
1484
|
+
loadData = function (url, callback, options, error, onCancel) {
|
|
1485
|
+
if (options === void 0) { options = {}; }
|
|
1486
|
+
options.method = options.method || 'GET';
|
|
1487
|
+
var xhr = new XMLHttpRequest();
|
|
1488
|
+
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1489
|
+
if (options.responseType === 'blob') {
|
|
1490
|
+
xhr.responseType = options.responseType;
|
|
1491
|
+
}
|
|
1492
|
+
var getResponseText = function () {
|
|
1493
|
+
try {
|
|
1494
|
+
return JSON.parse(xhr.responseText);
|
|
1495
|
+
}
|
|
1496
|
+
catch (er) {
|
|
1497
|
+
return xhr.responseText;
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
var processingResponse = function (forError) {
|
|
1501
|
+
if (forError === void 0) { forError = false; }
|
|
1502
|
+
var cb = forError ? error : callback;
|
|
1503
|
+
if (options.responseType === 'blob') {
|
|
1504
|
+
cb(xhr.response);
|
|
1505
|
+
}
|
|
1506
|
+
else {
|
|
1507
|
+
if (xhr.responseText) {
|
|
1508
|
+
cb(getResponseText());
|
|
1509
|
+
}
|
|
1510
|
+
else {
|
|
1511
|
+
error({ message: '' });
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
xhr.onload = function () {
|
|
1516
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1517
|
+
error(new NgwError(getResponseText()));
|
|
1518
|
+
}
|
|
1519
|
+
processingResponse();
|
|
1520
|
+
};
|
|
1521
|
+
// xhr.onreadystatechange = () => {
|
|
1522
|
+
// if (
|
|
1523
|
+
// (xhr.readyState === 4 && xhr.status === 200) ||
|
|
1524
|
+
// (xhr.readyState === 3 && xhr.status === 201)
|
|
1525
|
+
// ) {
|
|
1526
|
+
// processingResponse();
|
|
1527
|
+
// } else if (xhr.readyState === 3 && xhr.status === 400) {
|
|
1528
|
+
// processingResponse();
|
|
1529
|
+
// } else if (xhr.readyState === 4 && xhr.status === 500) {
|
|
1530
|
+
// processingResponse();
|
|
1531
|
+
// } else if (xhr.readyState === 4 && xhr.status === 401) {
|
|
1532
|
+
// error(xhr.statusText);
|
|
1533
|
+
// } else if (xhr.readyState === 4) {
|
|
1534
|
+
// error('request error');
|
|
1535
|
+
// }
|
|
1536
|
+
// };
|
|
1537
|
+
xhr.onerror = function (er) {
|
|
1538
|
+
if (xhr.status === 0) {
|
|
1539
|
+
error(new NetworkError(url));
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
error(er);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
xhr.upload.onprogress = function (e) {
|
|
1546
|
+
if (e.lengthComputable) {
|
|
1547
|
+
var percentComplete = (e.loaded / e.total) * 100;
|
|
1548
|
+
if (options.onProgress) {
|
|
1549
|
+
options.onProgress(percentComplete, e);
|
|
1550
|
+
}
|
|
1551
|
+
// console.log(percentComplete + '% uploaded');
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
var headers = options.headers;
|
|
1555
|
+
if (headers) {
|
|
1556
|
+
for (var h in headers) {
|
|
1557
|
+
var header = headers[h];
|
|
1558
|
+
if (typeof header === 'string') {
|
|
1559
|
+
xhr.setRequestHeader(h, header);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
if (options.withCredentials !== undefined) {
|
|
1564
|
+
xhr.withCredentials = options.withCredentials;
|
|
1565
|
+
}
|
|
1566
|
+
var data;
|
|
1567
|
+
if (options.file) {
|
|
1568
|
+
data = new FormData();
|
|
1569
|
+
data.append('file', options.file);
|
|
1570
|
+
if (options.data) {
|
|
1571
|
+
for (var d in options.data) {
|
|
1572
|
+
data.append(d, data[d]);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
else {
|
|
1577
|
+
data = options.data
|
|
1578
|
+
? typeof options.data === 'string'
|
|
1579
|
+
? options.data
|
|
1580
|
+
: JSON.stringify(options.data)
|
|
1581
|
+
: null;
|
|
1582
|
+
}
|
|
1583
|
+
if (onCancel) {
|
|
1584
|
+
onCancel(function () {
|
|
1585
|
+
xhr.abort();
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
xhr.send(data);
|
|
1589
|
+
};
|
|
1517
1590
|
}
|
|
1518
1591
|
|
|
1519
|
-
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1520
|
-
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1521
|
-
function template(str, data) {
|
|
1522
|
-
return str.replace(templateRe, function (s, key) {
|
|
1523
|
-
var value = data[key];
|
|
1524
|
-
if (value === undefined) {
|
|
1525
|
-
throw new Error('No value provided for letiable ' + s);
|
|
1526
|
-
}
|
|
1527
|
-
else if (typeof value === 'function') {
|
|
1528
|
-
value = value(data);
|
|
1529
|
-
}
|
|
1530
|
-
return value;
|
|
1531
|
-
});
|
|
1592
|
+
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1593
|
+
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1594
|
+
function template(str, data) {
|
|
1595
|
+
return str.replace(templateRe, function (s, key) {
|
|
1596
|
+
var value = data[key];
|
|
1597
|
+
if (value === undefined) {
|
|
1598
|
+
throw new Error('No value provided for letiable ' + s);
|
|
1599
|
+
}
|
|
1600
|
+
else if (typeof value === 'function') {
|
|
1601
|
+
value = value(data);
|
|
1602
|
+
}
|
|
1603
|
+
return value;
|
|
1604
|
+
});
|
|
1532
1605
|
}
|
|
1533
1606
|
|
|
1534
|
-
function apiRequest(opt) {
|
|
1535
|
-
var params = opt.params;
|
|
1536
|
-
return new CancelablePromise(function (resolve, reject) {
|
|
1537
|
-
opt.connector
|
|
1538
|
-
.connect()
|
|
1539
|
-
.then(function (apiItems) {
|
|
1540
|
-
var apiItem = apiItems && apiItems[opt.name];
|
|
1541
|
-
if (apiItem) {
|
|
1542
|
-
apiItem = __spreadArray([], apiItem, true);
|
|
1543
|
-
var url = apiItem.shift();
|
|
1544
|
-
if (apiItem.length) {
|
|
1545
|
-
var replaceParams = {};
|
|
1546
|
-
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1547
|
-
var arg = apiItem[fry];
|
|
1548
|
-
replaceParams[fry] = '{' + arg + '}';
|
|
1549
|
-
if (params[arg] === undefined) {
|
|
1550
|
-
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
if (url) {
|
|
1554
|
-
url = template(url, replaceParams);
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
// Transfer part of the parameters from `params` to the URL string
|
|
1558
|
-
if (params) {
|
|
1559
|
-
var paramArray_1 = [];
|
|
1560
|
-
var paramList = params.paramList;
|
|
1561
|
-
if (Array.isArray(paramList)) {
|
|
1562
|
-
delete params.paramList;
|
|
1563
|
-
paramList.forEach(function (x) {
|
|
1564
|
-
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
for (var p in params) {
|
|
1568
|
-
if (apiItem.indexOf(p) === -1) {
|
|
1569
|
-
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
if (paramArray_1.length) {
|
|
1573
|
-
url = url + '?' + paramArray_1.join('&');
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
if (url) {
|
|
1577
|
-
resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
|
|
1578
|
-
}
|
|
1579
|
-
else {
|
|
1580
|
-
reject(new Error('request url is not set'));
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
else {
|
|
1584
|
-
resolve(undefined);
|
|
1585
|
-
}
|
|
1586
|
-
})
|
|
1587
|
-
.catch(function (er) {
|
|
1588
|
-
reject(er);
|
|
1589
|
-
});
|
|
1590
|
-
});
|
|
1607
|
+
function apiRequest(opt) {
|
|
1608
|
+
var params = opt.params;
|
|
1609
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
1610
|
+
opt.connector
|
|
1611
|
+
.connect()
|
|
1612
|
+
.then(function (apiItems) {
|
|
1613
|
+
var apiItem = apiItems && apiItems[opt.name];
|
|
1614
|
+
if (apiItem) {
|
|
1615
|
+
apiItem = __spreadArray([], apiItem, true);
|
|
1616
|
+
var url = apiItem.shift();
|
|
1617
|
+
if (apiItem.length) {
|
|
1618
|
+
var replaceParams = {};
|
|
1619
|
+
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1620
|
+
var arg = apiItem[fry];
|
|
1621
|
+
replaceParams[fry] = '{' + arg + '}';
|
|
1622
|
+
if (params[arg] === undefined) {
|
|
1623
|
+
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
if (url) {
|
|
1627
|
+
url = template(url, replaceParams);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
// Transfer part of the parameters from `params` to the URL string
|
|
1631
|
+
if (params) {
|
|
1632
|
+
var paramArray_1 = [];
|
|
1633
|
+
var paramList = params.paramList;
|
|
1634
|
+
if (Array.isArray(paramList)) {
|
|
1635
|
+
delete params.paramList;
|
|
1636
|
+
paramList.forEach(function (x) {
|
|
1637
|
+
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
for (var p in params) {
|
|
1641
|
+
if (apiItem.indexOf(p) === -1) {
|
|
1642
|
+
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
if (paramArray_1.length) {
|
|
1646
|
+
url = url + '?' + paramArray_1.join('&');
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
if (url) {
|
|
1650
|
+
resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
|
|
1651
|
+
}
|
|
1652
|
+
else {
|
|
1653
|
+
reject(new Error('request url is not set'));
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
else {
|
|
1657
|
+
resolve(undefined);
|
|
1658
|
+
}
|
|
1659
|
+
})
|
|
1660
|
+
.catch(function (er) {
|
|
1661
|
+
reject(er);
|
|
1662
|
+
});
|
|
1663
|
+
});
|
|
1591
1664
|
}
|
|
1592
1665
|
|
|
1593
|
-
/**
|
|
1594
|
-
* Thrown when ...
|
|
1595
|
-
*/
|
|
1596
|
-
var ResourceNotFoundError = /** @class */ (function (_super) {
|
|
1597
|
-
__extends(ResourceNotFoundError, _super);
|
|
1598
|
-
function ResourceNotFoundError(obj) {
|
|
1599
|
-
var _this = _super.call(this, obj) || this;
|
|
1600
|
-
_this.name = 'ResourceNotFoundError';
|
|
1601
|
-
_this.exception = 'nextgisweb.resource.exception.ResourceNotFound';
|
|
1602
|
-
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
1603
|
-
return _this;
|
|
1604
|
-
}
|
|
1605
|
-
return ResourceNotFoundError;
|
|
1666
|
+
/**
|
|
1667
|
+
* Thrown when ...
|
|
1668
|
+
*/
|
|
1669
|
+
var ResourceNotFoundError = /** @class */ (function (_super) {
|
|
1670
|
+
__extends(ResourceNotFoundError, _super);
|
|
1671
|
+
function ResourceNotFoundError(obj) {
|
|
1672
|
+
var _this = _super.call(this, obj) || this;
|
|
1673
|
+
_this.name = 'ResourceNotFoundError';
|
|
1674
|
+
_this.exception = 'nextgisweb.resource.exception.ResourceNotFound';
|
|
1675
|
+
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
1676
|
+
return _this;
|
|
1677
|
+
}
|
|
1678
|
+
return ResourceNotFoundError;
|
|
1606
1679
|
}(NgwError));
|
|
1607
1680
|
|
|
1608
|
-
/**
|
|
1609
|
-
* Thrown when ...
|
|
1610
|
-
*/
|
|
1611
|
-
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
1612
|
-
__extends(InsufficientPermissionsError, _super);
|
|
1613
|
-
function InsufficientPermissionsError(obj) {
|
|
1614
|
-
var _this = _super.call(this, obj) || this;
|
|
1615
|
-
_this.name = 'InsufficientPermissionsError';
|
|
1616
|
-
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1617
|
-
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1618
|
-
return _this;
|
|
1619
|
-
}
|
|
1620
|
-
return InsufficientPermissionsError;
|
|
1681
|
+
/**
|
|
1682
|
+
* Thrown when ...
|
|
1683
|
+
*/
|
|
1684
|
+
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
1685
|
+
__extends(InsufficientPermissionsError, _super);
|
|
1686
|
+
function InsufficientPermissionsError(obj) {
|
|
1687
|
+
var _this = _super.call(this, obj) || this;
|
|
1688
|
+
_this.name = 'InsufficientPermissionsError';
|
|
1689
|
+
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1690
|
+
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1691
|
+
return _this;
|
|
1692
|
+
}
|
|
1693
|
+
return InsufficientPermissionsError;
|
|
1621
1694
|
}(NgwError));
|
|
1622
1695
|
|
|
1623
|
-
var CONNECTORS = [];
|
|
1624
|
-
function addConnector(connector) {
|
|
1625
|
-
CONNECTORS.push(connector);
|
|
1626
|
-
}
|
|
1627
|
-
function findConnector(options) {
|
|
1628
|
-
return CONNECTORS.find(function (x) {
|
|
1629
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
1630
|
-
if (options.auth) {
|
|
1631
|
-
if (x.options.auth) {
|
|
1632
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
else {
|
|
1636
|
-
// if auth not in find options; use first connector with same url
|
|
1637
|
-
return true;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
});
|
|
1641
|
-
}
|
|
1642
|
-
function removeConnector(connector) {
|
|
1643
|
-
var index = CONNECTORS.indexOf(connector);
|
|
1644
|
-
if (index !== -1) {
|
|
1645
|
-
CONNECTORS.splice(index, 1);
|
|
1646
|
-
}
|
|
1696
|
+
var CONNECTORS = [];
|
|
1697
|
+
function addConnector(connector) {
|
|
1698
|
+
CONNECTORS.push(connector);
|
|
1699
|
+
}
|
|
1700
|
+
function findConnector(options) {
|
|
1701
|
+
return CONNECTORS.find(function (x) {
|
|
1702
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
1703
|
+
if (options.auth) {
|
|
1704
|
+
if (x.options.auth) {
|
|
1705
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
else {
|
|
1709
|
+
// if auth not in find options; use first connector with same url
|
|
1710
|
+
return true;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
function removeConnector(connector) {
|
|
1716
|
+
var index = CONNECTORS.indexOf(connector);
|
|
1717
|
+
if (index !== -1) {
|
|
1718
|
+
CONNECTORS.splice(index, 1);
|
|
1719
|
+
}
|
|
1647
1720
|
}
|
|
1648
1721
|
|
|
1649
|
-
var exclude = ['description'];
|
|
1650
|
-
/**
|
|
1651
|
-
* @remarks
|
|
1652
|
-
* https://docs.nextgis.ru/docs_ngweb_dev/doc/developer/resource.html#search-resources
|
|
1653
|
-
*
|
|
1654
|
-
* ```
|
|
1655
|
-
* { keyname, owner_user: { id }} > { keyname, owner_user__id }
|
|
1656
|
-
* ```
|
|
1657
|
-
*
|
|
1658
|
-
* @param resource - Any property from NGW resource item
|
|
1659
|
-
*/
|
|
1660
|
-
function resourceToQuery(resource, prefix) {
|
|
1661
|
-
if (prefix === void 0) { prefix = ''; }
|
|
1662
|
-
prefix = prefix ? prefix + '__' : '';
|
|
1663
|
-
var query = {};
|
|
1664
|
-
for (var _i = 0, _a = Object.entries(resource); _i < _a.length; _i++) {
|
|
1665
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
1666
|
-
if (exclude.indexOf(key) === -1) {
|
|
1667
|
-
if (isObject(value)) {
|
|
1668
|
-
if (key === 'owner_user') {
|
|
1669
|
-
var children = resourceToQuery(value, key);
|
|
1670
|
-
Object.assign(query, children);
|
|
1671
|
-
}
|
|
1672
|
-
else if (key === 'parent' && 'id' in value) {
|
|
1673
|
-
query.parent_id = value.id;
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
else if (defined(value)) {
|
|
1677
|
-
query[prefix + key] = value;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
return query;
|
|
1722
|
+
var exclude = ['description'];
|
|
1723
|
+
/**
|
|
1724
|
+
* @remarks
|
|
1725
|
+
* https://docs.nextgis.ru/docs_ngweb_dev/doc/developer/resource.html#search-resources
|
|
1726
|
+
*
|
|
1727
|
+
* ```
|
|
1728
|
+
* { keyname, owner_user: { id }} > { keyname, owner_user__id }
|
|
1729
|
+
* ```
|
|
1730
|
+
*
|
|
1731
|
+
* @param resource - Any property from NGW resource item
|
|
1732
|
+
*/
|
|
1733
|
+
function resourceToQuery(resource, prefix) {
|
|
1734
|
+
if (prefix === void 0) { prefix = ''; }
|
|
1735
|
+
prefix = prefix ? prefix + '__' : '';
|
|
1736
|
+
var query = {};
|
|
1737
|
+
for (var _i = 0, _a = Object.entries(resource); _i < _a.length; _i++) {
|
|
1738
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
1739
|
+
if (exclude.indexOf(key) === -1) {
|
|
1740
|
+
if (isObject(value)) {
|
|
1741
|
+
if (key === 'owner_user') {
|
|
1742
|
+
var children = resourceToQuery(value, key);
|
|
1743
|
+
Object.assign(query, children);
|
|
1744
|
+
}
|
|
1745
|
+
else if (key === 'parent' && 'id' in value) {
|
|
1746
|
+
query.parent_id = value.id;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
else if (defined(value)) {
|
|
1750
|
+
query[prefix + key] = value;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
return query;
|
|
1682
1755
|
}
|
|
1683
1756
|
|
|
1684
|
-
function resourceCompare(res1, res2) {
|
|
1685
|
-
return objectDeepEqual(res1, res2);
|
|
1757
|
+
function resourceCompare(res1, res2) {
|
|
1758
|
+
return objectDeepEqual(res1, res2);
|
|
1686
1759
|
}
|
|
1687
1760
|
|
|
1688
|
-
var ResourcesControl = /** @class */ (function () {
|
|
1689
|
-
function ResourcesControl(connector) {
|
|
1690
|
-
this.connector = connector;
|
|
1691
|
-
this.cache = new Cache();
|
|
1692
|
-
}
|
|
1693
|
-
// -------------------------------------------------------------------------
|
|
1694
|
-
// Resource Methods
|
|
1695
|
-
// -------------------------------------------------------------------------
|
|
1696
|
-
/**
|
|
1697
|
-
* Receive resource from NGW by id, keyname or search-object parameter.
|
|
1698
|
-
* @param resource - Resource id, keyname or search-object
|
|
1699
|
-
*
|
|
1700
|
-
* @remarks
|
|
1701
|
-
* Fetching resource would be cached to speed up next call
|
|
1702
|
-
*/
|
|
1703
|
-
ResourcesControl.prototype.getOne = function (resource, requestOptions) {
|
|
1704
|
-
var _this = this;
|
|
1705
|
-
var cache = new Cache();
|
|
1706
|
-
var forCache = {};
|
|
1707
|
-
var opt = __assign(__assign({}, requestOptions), { cache: false });
|
|
1708
|
-
if (typeof resource === 'string') {
|
|
1709
|
-
forCache.keyname = resource;
|
|
1710
|
-
}
|
|
1711
|
-
else if (typeof resource === 'number') {
|
|
1712
|
-
forCache.id = resource;
|
|
1713
|
-
}
|
|
1714
|
-
else if (isObject(resource)) {
|
|
1715
|
-
if (resource.id !== undefined) {
|
|
1716
|
-
forCache.id = resource.id;
|
|
1717
|
-
}
|
|
1718
|
-
else if (resource.keyname) {
|
|
1719
|
-
forCache.keyname = resource.keyname;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
var makeRequest = function () {
|
|
1723
|
-
if (typeof resource === 'string') {
|
|
1724
|
-
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
1725
|
-
}
|
|
1726
|
-
else if (typeof resource === 'number') {
|
|
1727
|
-
return _this._fetchResourceById(resource, opt);
|
|
1728
|
-
}
|
|
1729
|
-
else if (isObject(resource)) {
|
|
1730
|
-
return _this._fetchResourceBy(resource, opt);
|
|
1731
|
-
}
|
|
1732
|
-
return CancelablePromise.resolve(undefined);
|
|
1733
|
-
};
|
|
1734
|
-
return cache.addFull('resource', makeRequest, forCache);
|
|
1735
|
-
};
|
|
1736
|
-
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
1737
|
-
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1738
|
-
if (res) {
|
|
1739
|
-
return res;
|
|
1740
|
-
}
|
|
1741
|
-
throw new ResourceNotFoundError();
|
|
1742
|
-
});
|
|
1743
|
-
};
|
|
1744
|
-
/**
|
|
1745
|
-
* A fast way to retrieve resource ID for any resource definition.
|
|
1746
|
-
* @param resource - Any available resource definition
|
|
1747
|
-
*
|
|
1748
|
-
* @remarks
|
|
1749
|
-
* There are situations when exactly the resource id is needed
|
|
1750
|
-
* (for example, to compose the correct request to the api)
|
|
1751
|
-
* then this method will come in handy to facilitate the extraction of the identifier
|
|
1752
|
-
* if the resource is specified through a keyname or other parameters.
|
|
1753
|
-
*/
|
|
1754
|
-
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
1755
|
-
if (typeof resource === 'number') {
|
|
1756
|
-
return CancelablePromise.resolve(resource);
|
|
1757
|
-
}
|
|
1758
|
-
else if (typeof resource === 'string' || isObject(resource)) {
|
|
1759
|
-
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1760
|
-
if (res) {
|
|
1761
|
-
return res.resource.id;
|
|
1762
|
-
}
|
|
1763
|
-
});
|
|
1764
|
-
}
|
|
1765
|
-
return CancelablePromise.resolve(undefined);
|
|
1766
|
-
};
|
|
1767
|
-
/**
|
|
1768
|
-
* A fast way to retrieve resource ID for any resource definition.
|
|
1769
|
-
* @param resource - Any available resource definition
|
|
1770
|
-
*
|
|
1771
|
-
* @remarks
|
|
1772
|
-
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
1773
|
-
* To not make one more checks if the resource is definitely exists
|
|
1774
|
-
*/
|
|
1775
|
-
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
1776
|
-
return this.getId(resource, requestOptions).then(function (resp) {
|
|
1777
|
-
if (resp === undefined) {
|
|
1778
|
-
throw new Error();
|
|
1779
|
-
}
|
|
1780
|
-
return resp;
|
|
1781
|
-
});
|
|
1782
|
-
};
|
|
1783
|
-
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
1784
|
-
var _this = this;
|
|
1785
|
-
return this._resourceCacheFilter(resource).then(function (items) {
|
|
1786
|
-
if (!items.length) {
|
|
1787
|
-
var query = {};
|
|
1788
|
-
if (resource.keyname) {
|
|
1789
|
-
query.keyname = resource.keyname;
|
|
1790
|
-
}
|
|
1791
|
-
else {
|
|
1792
|
-
Object.assign(query, resourceToQuery(resource));
|
|
1793
|
-
}
|
|
1794
|
-
return _this.connector
|
|
1795
|
-
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
1796
|
-
.then(function (resources) {
|
|
1797
|
-
if (resources) {
|
|
1798
|
-
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
1799
|
-
var x = resources_1[_i];
|
|
1800
|
-
_this.cache.add('resource.item', CancelablePromise.resolve(x), {
|
|
1801
|
-
id: x.resource.id,
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
return resources;
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
|
-
return items;
|
|
1809
|
-
});
|
|
1810
|
-
};
|
|
1811
|
-
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
1812
|
-
var _this = this;
|
|
1813
|
-
return this.getOne(resource, requestOptions).then(function (child) {
|
|
1814
|
-
if (child) {
|
|
1815
|
-
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
1816
|
-
}
|
|
1817
|
-
return CancelablePromise.resolve(undefined);
|
|
1818
|
-
});
|
|
1819
|
-
};
|
|
1820
|
-
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
1821
|
-
var _this = this;
|
|
1822
|
-
return this.getIdOrFail(resource).then(function (parent) {
|
|
1823
|
-
return _this._getChildrenOf(parent, requestOptions);
|
|
1824
|
-
});
|
|
1825
|
-
};
|
|
1826
|
-
ResourcesControl.prototype.update = function (resource, data) {
|
|
1827
|
-
var _this = this;
|
|
1828
|
-
return this.getId(resource).then(function (id) {
|
|
1829
|
-
if (id !== undefined) {
|
|
1830
|
-
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
1831
|
-
}
|
|
1832
|
-
});
|
|
1833
|
-
};
|
|
1834
|
-
/**
|
|
1835
|
-
* Fast way to delete resource from NGW and clean cache.
|
|
1836
|
-
* @param resource - Resource definition
|
|
1837
|
-
*/
|
|
1838
|
-
ResourcesControl.prototype.delete = function (resource) {
|
|
1839
|
-
var _this = this;
|
|
1840
|
-
return this.getId(resource).then(function (id) {
|
|
1841
|
-
if (id !== undefined) {
|
|
1842
|
-
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
1843
|
-
_this._cleanResourceItemCache(id);
|
|
1844
|
-
return undefined;
|
|
1845
|
-
});
|
|
1846
|
-
}
|
|
1847
|
-
});
|
|
1848
|
-
};
|
|
1849
|
-
ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
|
|
1850
|
-
var _this = this;
|
|
1851
|
-
if (_items === void 0) { _items = []; }
|
|
1852
|
-
return this.connector
|
|
1853
|
-
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
1854
|
-
parent: parent,
|
|
1855
|
-
})
|
|
1856
|
-
.then(function (items) {
|
|
1857
|
-
var recursivePromises = [];
|
|
1858
|
-
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
1859
|
-
var item = items_1[_i];
|
|
1860
|
-
_this.cache.add('resource.item', CancelablePromise.resolve(item), {
|
|
1861
|
-
id: item.resource.id,
|
|
1862
|
-
});
|
|
1863
|
-
_items.push(item);
|
|
1864
|
-
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1865
|
-
recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
if (recursivePromises.length) {
|
|
1869
|
-
return CancelablePromise.all(recursivePromises).then(function () {
|
|
1870
|
-
return _items;
|
|
1871
|
-
});
|
|
1872
|
-
}
|
|
1873
|
-
return _items;
|
|
1874
|
-
});
|
|
1875
|
-
};
|
|
1876
|
-
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
1877
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1878
|
-
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
1879
|
-
return __generator(this, function (_b) {
|
|
1880
|
-
switch (_b.label) {
|
|
1881
|
-
case 0:
|
|
1882
|
-
all = this.cache.all();
|
|
1883
|
-
toDelete = [];
|
|
1884
|
-
_i = 0, all_1 = all;
|
|
1885
|
-
_b.label = 1;
|
|
1886
|
-
case 1:
|
|
1887
|
-
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
1888
|
-
c = all_1[_i];
|
|
1889
|
-
cid = c.options && c.options.id;
|
|
1890
|
-
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
1891
|
-
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
1892
|
-
if (cid === id) {
|
|
1893
|
-
toDelete.push(c);
|
|
1894
|
-
}
|
|
1895
|
-
return [3 /*break*/, 4];
|
|
1896
|
-
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
1897
|
-
case 3:
|
|
1898
|
-
rid = _b.sent();
|
|
1899
|
-
if (rid === id) {
|
|
1900
|
-
toDelete.push(c);
|
|
1901
|
-
}
|
|
1902
|
-
_b.label = 4;
|
|
1903
|
-
case 4:
|
|
1904
|
-
_i++;
|
|
1905
|
-
return [3 /*break*/, 1];
|
|
1906
|
-
case 5:
|
|
1907
|
-
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
1908
|
-
d = toDelete_1[_a];
|
|
1909
|
-
this.cache.delete(d);
|
|
1910
|
-
}
|
|
1911
|
-
return [2 /*return*/];
|
|
1912
|
-
}
|
|
1913
|
-
});
|
|
1914
|
-
});
|
|
1915
|
-
};
|
|
1916
|
-
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
1917
|
-
var _this = this;
|
|
1918
|
-
var promise = function () {
|
|
1919
|
-
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
1920
|
-
};
|
|
1921
|
-
return this.cache
|
|
1922
|
-
.add('resource.item', promise, {
|
|
1923
|
-
id: id,
|
|
1924
|
-
})
|
|
1925
|
-
.catch(function (er) {
|
|
1926
|
-
if (!(er instanceof ResourceNotFoundError)) {
|
|
1927
|
-
throw er;
|
|
1928
|
-
}
|
|
1929
|
-
return undefined;
|
|
1930
|
-
});
|
|
1931
|
-
};
|
|
1932
|
-
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
1933
|
-
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
1934
|
-
return resources[0];
|
|
1935
|
-
});
|
|
1936
|
-
};
|
|
1937
|
-
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
1938
|
-
return CancelablePromise.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
1939
|
-
var items = [];
|
|
1940
|
-
resources.filter(function (x) {
|
|
1941
|
-
if (x) {
|
|
1942
|
-
// identical by uniq props
|
|
1943
|
-
if (resource.keyname && x.resource.keyname) {
|
|
1944
|
-
return resource.keyname === x.resource.keyname;
|
|
1945
|
-
}
|
|
1946
|
-
if (defined(resource.id) && defined(x.resource.id)) {
|
|
1947
|
-
return resource.id === x.resource.id;
|
|
1948
|
-
}
|
|
1949
|
-
return resourceCompare(resource, x.resource);
|
|
1950
|
-
}
|
|
1951
|
-
});
|
|
1952
|
-
return items;
|
|
1953
|
-
});
|
|
1954
|
-
};
|
|
1955
|
-
return ResourcesControl;
|
|
1761
|
+
var ResourcesControl = /** @class */ (function () {
|
|
1762
|
+
function ResourcesControl(connector) {
|
|
1763
|
+
this.connector = connector;
|
|
1764
|
+
this.cache = new Cache();
|
|
1765
|
+
}
|
|
1766
|
+
// -------------------------------------------------------------------------
|
|
1767
|
+
// Resource Methods
|
|
1768
|
+
// -------------------------------------------------------------------------
|
|
1769
|
+
/**
|
|
1770
|
+
* Receive resource from NGW by id, keyname or search-object parameter.
|
|
1771
|
+
* @param resource - Resource id, keyname or search-object
|
|
1772
|
+
*
|
|
1773
|
+
* @remarks
|
|
1774
|
+
* Fetching resource would be cached to speed up next call
|
|
1775
|
+
*/
|
|
1776
|
+
ResourcesControl.prototype.getOne = function (resource, requestOptions) {
|
|
1777
|
+
var _this = this;
|
|
1778
|
+
var cache = new Cache();
|
|
1779
|
+
var forCache = {};
|
|
1780
|
+
var opt = __assign(__assign({}, requestOptions), { cache: false });
|
|
1781
|
+
if (typeof resource === 'string') {
|
|
1782
|
+
forCache.keyname = resource;
|
|
1783
|
+
}
|
|
1784
|
+
else if (typeof resource === 'number') {
|
|
1785
|
+
forCache.id = resource;
|
|
1786
|
+
}
|
|
1787
|
+
else if (isObject(resource)) {
|
|
1788
|
+
if (resource.id !== undefined) {
|
|
1789
|
+
forCache.id = resource.id;
|
|
1790
|
+
}
|
|
1791
|
+
else if (resource.keyname) {
|
|
1792
|
+
forCache.keyname = resource.keyname;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
var makeRequest = function () {
|
|
1796
|
+
if (typeof resource === 'string') {
|
|
1797
|
+
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
1798
|
+
}
|
|
1799
|
+
else if (typeof resource === 'number') {
|
|
1800
|
+
return _this._fetchResourceById(resource, opt);
|
|
1801
|
+
}
|
|
1802
|
+
else if (isObject(resource)) {
|
|
1803
|
+
return _this._fetchResourceBy(resource, opt);
|
|
1804
|
+
}
|
|
1805
|
+
return CancelablePromise.resolve(undefined);
|
|
1806
|
+
};
|
|
1807
|
+
return cache.addFull('resource', makeRequest, forCache);
|
|
1808
|
+
};
|
|
1809
|
+
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
1810
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1811
|
+
if (res) {
|
|
1812
|
+
return res;
|
|
1813
|
+
}
|
|
1814
|
+
throw new ResourceNotFoundError();
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1817
|
+
/**
|
|
1818
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
1819
|
+
* @param resource - Any available resource definition
|
|
1820
|
+
*
|
|
1821
|
+
* @remarks
|
|
1822
|
+
* There are situations when exactly the resource id is needed
|
|
1823
|
+
* (for example, to compose the correct request to the api)
|
|
1824
|
+
* then this method will come in handy to facilitate the extraction of the identifier
|
|
1825
|
+
* if the resource is specified through a keyname or other parameters.
|
|
1826
|
+
*/
|
|
1827
|
+
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
1828
|
+
if (typeof resource === 'number') {
|
|
1829
|
+
return CancelablePromise.resolve(resource);
|
|
1830
|
+
}
|
|
1831
|
+
else if (typeof resource === 'string' || isObject(resource)) {
|
|
1832
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1833
|
+
if (res) {
|
|
1834
|
+
return res.resource.id;
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
return CancelablePromise.resolve(undefined);
|
|
1839
|
+
};
|
|
1840
|
+
/**
|
|
1841
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
1842
|
+
* @param resource - Any available resource definition
|
|
1843
|
+
*
|
|
1844
|
+
* @remarks
|
|
1845
|
+
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
1846
|
+
* To not make one more checks if the resource is definitely exists
|
|
1847
|
+
*/
|
|
1848
|
+
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
1849
|
+
return this.getId(resource, requestOptions).then(function (resp) {
|
|
1850
|
+
if (resp === undefined) {
|
|
1851
|
+
throw new Error();
|
|
1852
|
+
}
|
|
1853
|
+
return resp;
|
|
1854
|
+
});
|
|
1855
|
+
};
|
|
1856
|
+
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
1857
|
+
var _this = this;
|
|
1858
|
+
return this._resourceCacheFilter(resource).then(function (items) {
|
|
1859
|
+
if (!items.length) {
|
|
1860
|
+
var query = {};
|
|
1861
|
+
if (resource.keyname) {
|
|
1862
|
+
query.keyname = resource.keyname;
|
|
1863
|
+
}
|
|
1864
|
+
else {
|
|
1865
|
+
Object.assign(query, resourceToQuery(resource));
|
|
1866
|
+
}
|
|
1867
|
+
return _this.connector
|
|
1868
|
+
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
1869
|
+
.then(function (resources) {
|
|
1870
|
+
if (resources) {
|
|
1871
|
+
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
1872
|
+
var x = resources_1[_i];
|
|
1873
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(x), {
|
|
1874
|
+
id: x.resource.id,
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return resources;
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
return items;
|
|
1882
|
+
});
|
|
1883
|
+
};
|
|
1884
|
+
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
1885
|
+
var _this = this;
|
|
1886
|
+
return this.getOne(resource, requestOptions).then(function (child) {
|
|
1887
|
+
if (child) {
|
|
1888
|
+
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
1889
|
+
}
|
|
1890
|
+
return CancelablePromise.resolve(undefined);
|
|
1891
|
+
});
|
|
1892
|
+
};
|
|
1893
|
+
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
1894
|
+
var _this = this;
|
|
1895
|
+
return this.getIdOrFail(resource).then(function (parent) {
|
|
1896
|
+
return _this._getChildrenOf(parent, requestOptions);
|
|
1897
|
+
});
|
|
1898
|
+
};
|
|
1899
|
+
ResourcesControl.prototype.update = function (resource, data) {
|
|
1900
|
+
var _this = this;
|
|
1901
|
+
return this.getId(resource).then(function (id) {
|
|
1902
|
+
if (id !== undefined) {
|
|
1903
|
+
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
};
|
|
1907
|
+
/**
|
|
1908
|
+
* Fast way to delete resource from NGW and clean cache.
|
|
1909
|
+
* @param resource - Resource definition
|
|
1910
|
+
*/
|
|
1911
|
+
ResourcesControl.prototype.delete = function (resource) {
|
|
1912
|
+
var _this = this;
|
|
1913
|
+
return this.getId(resource).then(function (id) {
|
|
1914
|
+
if (id !== undefined) {
|
|
1915
|
+
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
1916
|
+
_this._cleanResourceItemCache(id);
|
|
1917
|
+
return undefined;
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
});
|
|
1921
|
+
};
|
|
1922
|
+
ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
|
|
1923
|
+
var _this = this;
|
|
1924
|
+
if (_items === void 0) { _items = []; }
|
|
1925
|
+
return this.connector
|
|
1926
|
+
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
1927
|
+
parent: parent,
|
|
1928
|
+
})
|
|
1929
|
+
.then(function (items) {
|
|
1930
|
+
var recursivePromises = [];
|
|
1931
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
1932
|
+
var item = items_1[_i];
|
|
1933
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(item), {
|
|
1934
|
+
id: item.resource.id,
|
|
1935
|
+
});
|
|
1936
|
+
_items.push(item);
|
|
1937
|
+
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1938
|
+
recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
if (recursivePromises.length) {
|
|
1942
|
+
return CancelablePromise.all(recursivePromises).then(function () {
|
|
1943
|
+
return _items;
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
return _items;
|
|
1947
|
+
});
|
|
1948
|
+
};
|
|
1949
|
+
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
1950
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1951
|
+
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
1952
|
+
return __generator(this, function (_b) {
|
|
1953
|
+
switch (_b.label) {
|
|
1954
|
+
case 0:
|
|
1955
|
+
all = this.cache.all();
|
|
1956
|
+
toDelete = [];
|
|
1957
|
+
_i = 0, all_1 = all;
|
|
1958
|
+
_b.label = 1;
|
|
1959
|
+
case 1:
|
|
1960
|
+
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
1961
|
+
c = all_1[_i];
|
|
1962
|
+
cid = c.options && c.options.id;
|
|
1963
|
+
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
1964
|
+
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
1965
|
+
if (cid === id) {
|
|
1966
|
+
toDelete.push(c);
|
|
1967
|
+
}
|
|
1968
|
+
return [3 /*break*/, 4];
|
|
1969
|
+
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
1970
|
+
case 3:
|
|
1971
|
+
rid = _b.sent();
|
|
1972
|
+
if (rid === id) {
|
|
1973
|
+
toDelete.push(c);
|
|
1974
|
+
}
|
|
1975
|
+
_b.label = 4;
|
|
1976
|
+
case 4:
|
|
1977
|
+
_i++;
|
|
1978
|
+
return [3 /*break*/, 1];
|
|
1979
|
+
case 5:
|
|
1980
|
+
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
1981
|
+
d = toDelete_1[_a];
|
|
1982
|
+
this.cache.delete(d);
|
|
1983
|
+
}
|
|
1984
|
+
return [2 /*return*/];
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
});
|
|
1988
|
+
};
|
|
1989
|
+
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
1990
|
+
var _this = this;
|
|
1991
|
+
var promise = function () {
|
|
1992
|
+
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
1993
|
+
};
|
|
1994
|
+
return this.cache
|
|
1995
|
+
.add('resource.item', promise, {
|
|
1996
|
+
id: id,
|
|
1997
|
+
})
|
|
1998
|
+
.catch(function (er) {
|
|
1999
|
+
if (!(er instanceof ResourceNotFoundError)) {
|
|
2000
|
+
throw er;
|
|
2001
|
+
}
|
|
2002
|
+
return undefined;
|
|
2003
|
+
});
|
|
2004
|
+
};
|
|
2005
|
+
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
2006
|
+
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
2007
|
+
return resources[0];
|
|
2008
|
+
});
|
|
2009
|
+
};
|
|
2010
|
+
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
2011
|
+
return CancelablePromise.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
2012
|
+
var items = [];
|
|
2013
|
+
resources.filter(function (x) {
|
|
2014
|
+
if (x) {
|
|
2015
|
+
// identical by uniq props
|
|
2016
|
+
if (resource.keyname && x.resource.keyname) {
|
|
2017
|
+
return resource.keyname === x.resource.keyname;
|
|
2018
|
+
}
|
|
2019
|
+
if (defined(resource.id) && defined(x.resource.id)) {
|
|
2020
|
+
return resource.id === x.resource.id;
|
|
2021
|
+
}
|
|
2022
|
+
return resourceCompare(resource, x.resource);
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
return items;
|
|
2026
|
+
});
|
|
2027
|
+
};
|
|
2028
|
+
return ResourcesControl;
|
|
1956
2029
|
}());
|
|
1957
2030
|
|
|
1958
|
-
var ID = 0;
|
|
1959
|
-
var NgwConnector$1 = /** @class */ (function () {
|
|
1960
|
-
function NgwConnector(options) {
|
|
1961
|
-
this.options = options;
|
|
1962
|
-
this.id = ID++;
|
|
1963
|
-
this.emitter = new events.exports.EventEmitter();
|
|
1964
|
-
this.routeStr = '/api/component/pyramid/route';
|
|
1965
|
-
this.activeRequests = [];
|
|
1966
|
-
var exist = findConnector(options);
|
|
1967
|
-
if (exist) {
|
|
1968
|
-
return exist;
|
|
1969
|
-
}
|
|
1970
|
-
else {
|
|
1971
|
-
if (this.options.route) {
|
|
1972
|
-
this.routeStr = this.options.route;
|
|
1973
|
-
}
|
|
1974
|
-
if (this.options.requestTransform) {
|
|
1975
|
-
this.requestTransform = this.options.requestTransform;
|
|
1976
|
-
}
|
|
1977
|
-
this.resources = new ResourcesControl(this);
|
|
1978
|
-
addConnector(this);
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
NgwConnector.create = function (options) {
|
|
1982
|
-
return new this(options);
|
|
1983
|
-
};
|
|
1984
|
-
NgwConnector.prototype.setRequestTransform = function (requestTransform) {
|
|
1985
|
-
this.requestTransform = requestTransform;
|
|
1986
|
-
};
|
|
1987
|
-
/**
|
|
1988
|
-
* Fast way to specify the connection address to NextGIS Web.
|
|
1989
|
-
* The current connection will be severed.
|
|
1990
|
-
* @param baseUrl - NGW url
|
|
1991
|
-
*/
|
|
1992
|
-
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
1993
|
-
this.logout();
|
|
1994
|
-
this.options.baseUrl = baseUrl;
|
|
1995
|
-
addConnector(this);
|
|
1996
|
-
};
|
|
1997
|
-
/**
|
|
1998
|
-
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1999
|
-
* @remarks
|
|
2000
|
-
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
2001
|
-
* Can be used to check connection.
|
|
2002
|
-
* @example
|
|
2003
|
-
* ```javascript
|
|
2004
|
-
* const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
|
|
2005
|
-
* connector.connect()
|
|
2006
|
-
* .then(() => console.log('Ok'))
|
|
2007
|
-
* .catch((er) => console.log('Connection problem', er));
|
|
2008
|
-
* ```
|
|
2009
|
-
*/
|
|
2010
|
-
NgwConnector.prototype.connect = function () {
|
|
2011
|
-
var _this = this;
|
|
2012
|
-
var cache = new Cache();
|
|
2013
|
-
var auth = this.options.auth;
|
|
2014
|
-
var makeConnect = function () {
|
|
2015
|
-
return new CancelablePromise(function (resolve, reject) {
|
|
2016
|
-
var makeQuery = function () {
|
|
2017
|
-
return _this.makeQuery(_this.routeStr, {}, {})
|
|
2018
|
-
.then(function (route) {
|
|
2019
|
-
resolve(route);
|
|
2020
|
-
})
|
|
2021
|
-
.catch(function (er) {
|
|
2022
|
-
reject(er);
|
|
2023
|
-
});
|
|
2024
|
-
};
|
|
2025
|
-
if (auth) {
|
|
2026
|
-
var login = auth.login, password = auth.password;
|
|
2027
|
-
if (login && password) {
|
|
2028
|
-
return _this._login({ login: login, password: password })
|
|
2029
|
-
.then(function () {
|
|
2030
|
-
return makeQuery();
|
|
2031
|
-
})
|
|
2032
|
-
.catch(function (er) { return reject(er); });
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
return makeQuery();
|
|
2036
|
-
});
|
|
2037
|
-
};
|
|
2038
|
-
return cache.add('route', makeConnect, {
|
|
2039
|
-
id: this.id,
|
|
2040
|
-
auth: auth,
|
|
2041
|
-
baseUrl: this.options.baseUrl,
|
|
2042
|
-
});
|
|
2043
|
-
};
|
|
2044
|
-
/**
|
|
2045
|
-
* Quick way to change NextGIS Web user.
|
|
2046
|
-
* @param credentials - New user credentials
|
|
2047
|
-
*/
|
|
2048
|
-
NgwConnector.prototype.login = function (credentials, options) {
|
|
2049
|
-
this.logout();
|
|
2050
|
-
addConnector(this);
|
|
2051
|
-
return this._login(credentials, options);
|
|
2052
|
-
};
|
|
2053
|
-
/**
|
|
2054
|
-
* Disconnecting a user. Aborting all current requests
|
|
2055
|
-
*/
|
|
2056
|
-
NgwConnector.prototype.logout = function () {
|
|
2057
|
-
this.abort();
|
|
2058
|
-
removeConnector(this);
|
|
2059
|
-
this.options.auth = undefined;
|
|
2060
|
-
this.user = undefined;
|
|
2061
|
-
this.emitter.emit('logout');
|
|
2062
|
-
this.resources.cache.clean();
|
|
2063
|
-
};
|
|
2064
|
-
NgwConnector.prototype.getUserInfo = function (credentials, options) {
|
|
2065
|
-
if (this.user && this.user.id) {
|
|
2066
|
-
return CancelablePromise.resolve(this.user);
|
|
2067
|
-
}
|
|
2068
|
-
if (credentials) {
|
|
2069
|
-
this.options.auth = credentials;
|
|
2070
|
-
}
|
|
2071
|
-
var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
|
|
2072
|
-
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
2073
|
-
return this.makeQuery('/api/component/auth/current_user', {}, options_);
|
|
2074
|
-
};
|
|
2075
|
-
/**
|
|
2076
|
-
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
2077
|
-
*/
|
|
2078
|
-
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
2079
|
-
var client = this.makeClientId(credentials);
|
|
2080
|
-
if (client) {
|
|
2081
|
-
return {
|
|
2082
|
-
Authorization: 'Basic ' + client,
|
|
2083
|
-
};
|
|
2084
|
-
}
|
|
2085
|
-
};
|
|
2086
|
-
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
2087
|
-
credentials = credentials || this.options.auth;
|
|
2088
|
-
if (credentials) {
|
|
2089
|
-
var login = credentials.login, password = credentials.password;
|
|
2090
|
-
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
2091
|
-
// @ts-ignore
|
|
2092
|
-
{
|
|
2093
|
-
return window.btoa(str);
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
};
|
|
2097
|
-
/** Stop all api requests */
|
|
2098
|
-
NgwConnector.prototype.abort = function () {
|
|
2099
|
-
for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
|
|
2100
|
-
var req = _a[_i];
|
|
2101
|
-
req.cancel();
|
|
2102
|
-
}
|
|
2103
|
-
this.activeRequests = [];
|
|
2104
|
-
};
|
|
2105
|
-
NgwConnector.prototype.getActiveApiRequests = function () {
|
|
2106
|
-
return __spreadArray([], this.activeRequests, true);
|
|
2107
|
-
};
|
|
2108
|
-
/**
|
|
2109
|
-
* Send request to NGW api router.
|
|
2110
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2111
|
-
* @param params - Request item params or query params
|
|
2112
|
-
* @param requestOptions - Request options
|
|
2113
|
-
*
|
|
2114
|
-
* @example
|
|
2115
|
-
* ```javascript
|
|
2116
|
-
*
|
|
2117
|
-
* // there is such an NGW route item
|
|
2118
|
-
* // "feature_layer.feature.item": [
|
|
2119
|
-
* // "/api/resource/{0}/feature/{1}",
|
|
2120
|
-
* // "id",
|
|
2121
|
-
* // "fid"
|
|
2122
|
-
* // ],
|
|
2123
|
-
*
|
|
2124
|
-
* const connector = new NgwConnector({ baseUrl: 'https://example.nextgis.com' });
|
|
2125
|
-
* connector.apiRequest('feature_layer.feature.item', {
|
|
2126
|
-
* // request params for {0} and {1}
|
|
2127
|
-
* 'id': 2011,
|
|
2128
|
-
* 'fid': 101,
|
|
2129
|
-
* // query params
|
|
2130
|
-
* 'srs': 4326,
|
|
2131
|
-
* 'geom_format': 'geojson',
|
|
2132
|
-
* }, { method: 'GET' });
|
|
2133
|
-
* // send get-request to 'https://example.nextgis.com/api/resource/2011/feature/101?srs=4326&geom_format=geojson'
|
|
2134
|
-
*
|
|
2135
|
-
* ```
|
|
2136
|
-
*/
|
|
2137
|
-
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
2138
|
-
var _this = this;
|
|
2139
|
-
var _a;
|
|
2140
|
-
if (params_ === void 0) { params_ = {}; }
|
|
2141
|
-
if (requestOptions === void 0) { requestOptions = {}; }
|
|
2142
|
-
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
2143
|
-
var params = objectRemoveEmpty(params_);
|
|
2144
|
-
var makeApiRequest = function () {
|
|
2145
|
-
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
2146
|
-
};
|
|
2147
|
-
if (requestOptions.cache && method === 'GET') {
|
|
2148
|
-
var cache = new Cache();
|
|
2149
|
-
return cache.add(name, makeApiRequest, __assign({ params: params }, objectRemoveEmpty({
|
|
2150
|
-
headers: headers,
|
|
2151
|
-
withCredentials: withCredentials,
|
|
2152
|
-
responseType: responseType,
|
|
2153
|
-
baseUrl: this.options.baseUrl,
|
|
2154
|
-
userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
|
|
2155
|
-
})));
|
|
2156
|
-
}
|
|
2157
|
-
return makeApiRequest();
|
|
2158
|
-
};
|
|
2159
|
-
/**
|
|
2160
|
-
* Shortcut method for send POST request to NGW.
|
|
2161
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2162
|
-
* @param options - Request options
|
|
2163
|
-
* @param params - Request item params or query params
|
|
2164
|
-
*
|
|
2165
|
-
* @example
|
|
2166
|
-
* ```javascript
|
|
2167
|
-
* connector.post('resource.collection', { data: POST_PAYLOAD })
|
|
2168
|
-
* .then((newResource) => console.log(newResource))
|
|
2169
|
-
* .catch((error) => console.warn(error));
|
|
2170
|
-
* ```
|
|
2171
|
-
*/
|
|
2172
|
-
NgwConnector.prototype.post = function (name, options, params) {
|
|
2173
|
-
options = options || {};
|
|
2174
|
-
options.method = 'POST';
|
|
2175
|
-
return this.apiRequest(name, params, options);
|
|
2176
|
-
};
|
|
2177
|
-
/**
|
|
2178
|
-
* Shortcut method for send GET request to NGW.
|
|
2179
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2180
|
-
* @param options - Request options
|
|
2181
|
-
* @param params - Request item params or query params
|
|
2182
|
-
*/
|
|
2183
|
-
NgwConnector.prototype.get = function (name, options, params) {
|
|
2184
|
-
options = options || {};
|
|
2185
|
-
options.method = 'GET';
|
|
2186
|
-
return this.apiRequest(name, params, options);
|
|
2187
|
-
};
|
|
2188
|
-
/**
|
|
2189
|
-
* Shortcut method for send PATCH request to NGW.
|
|
2190
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2191
|
-
* @param options - Request options
|
|
2192
|
-
* @param params - Request item params or query params
|
|
2193
|
-
*/
|
|
2194
|
-
NgwConnector.prototype.patch = function (name, options, params) {
|
|
2195
|
-
options = options || {};
|
|
2196
|
-
options.method = 'PATCH';
|
|
2197
|
-
return this.apiRequest(name, params, options);
|
|
2198
|
-
};
|
|
2199
|
-
/**
|
|
2200
|
-
* Shortcut method for send PUT request to NGW.
|
|
2201
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2202
|
-
* @param options - Request options
|
|
2203
|
-
* @param params - Request item params or query params
|
|
2204
|
-
*/
|
|
2205
|
-
NgwConnector.prototype.put = function (name, options, params) {
|
|
2206
|
-
options = options || {};
|
|
2207
|
-
options.method = 'PUT';
|
|
2208
|
-
return this.apiRequest(name, params, options);
|
|
2209
|
-
};
|
|
2210
|
-
/**
|
|
2211
|
-
* Shortcut method for send DELETE request to NGW.
|
|
2212
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2213
|
-
* @param options - Request options
|
|
2214
|
-
* @param params - Request item params or query params
|
|
2215
|
-
*/
|
|
2216
|
-
NgwConnector.prototype.delete = function (name, options, params) {
|
|
2217
|
-
options = options || {};
|
|
2218
|
-
options.method = 'DELETE';
|
|
2219
|
-
return this.apiRequest(name, params, options);
|
|
2220
|
-
};
|
|
2221
|
-
/**
|
|
2222
|
-
* Send request to NGW.
|
|
2223
|
-
* @param url - URL address to NGW
|
|
2224
|
-
* @param params - Query params
|
|
2225
|
-
* @param options - Request options
|
|
2226
|
-
*/
|
|
2227
|
-
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
2228
|
-
if (options === void 0) { options = {}; }
|
|
2229
|
-
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
2230
|
-
if (url) {
|
|
2231
|
-
if (params) {
|
|
2232
|
-
url = template(url, params);
|
|
2233
|
-
}
|
|
2234
|
-
url = encodeURI(fixUrlStr(url));
|
|
2235
|
-
return this._loadData(url, options);
|
|
2236
|
-
}
|
|
2237
|
-
else {
|
|
2238
|
-
throw new Error('Empty `url` not allowed');
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
// -------------------------------------------------------------------------
|
|
2242
|
-
// Resource Methods
|
|
2243
|
-
// -------------------------------------------------------------------------
|
|
2244
|
-
/**
|
|
2245
|
-
* {@link ResourcesControl.getOne}
|
|
2246
|
-
*/
|
|
2247
|
-
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
2248
|
-
return this.resources.getOne(resource, requestOptions);
|
|
2249
|
-
};
|
|
2250
|
-
/**
|
|
2251
|
-
* {@link ResourcesControl.getOneOrFail}
|
|
2252
|
-
*/
|
|
2253
|
-
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
2254
|
-
return this.resources.getOneOrFail(resource, requestOptions);
|
|
2255
|
-
};
|
|
2256
|
-
/**
|
|
2257
|
-
* @deprecated - use {@link getResource}
|
|
2258
|
-
*/
|
|
2259
|
-
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
2260
|
-
return this.resources.getOne(resource);
|
|
2261
|
-
};
|
|
2262
|
-
/**
|
|
2263
|
-
* @deprecated - use {@link getResource}
|
|
2264
|
-
*/
|
|
2265
|
-
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
2266
|
-
return this.resources.getOne(keyname);
|
|
2267
|
-
};
|
|
2268
|
-
/**
|
|
2269
|
-
* @deprecated - use {@link getResource}
|
|
2270
|
-
*/
|
|
2271
|
-
NgwConnector.prototype.getResourceById = function (id) {
|
|
2272
|
-
return this.resources.getOne(id);
|
|
2273
|
-
};
|
|
2274
|
-
/**
|
|
2275
|
-
* {@link ResourcesControl.getId}
|
|
2276
|
-
*/
|
|
2277
|
-
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
2278
|
-
return this.resources.getId(resource, requestOptions);
|
|
2279
|
-
};
|
|
2280
|
-
/**
|
|
2281
|
-
* {@link ResourcesControl.getIdOrFail}
|
|
2282
|
-
*/
|
|
2283
|
-
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
2284
|
-
return this.resources.getIdOrFail(resource, requestOptions);
|
|
2285
|
-
};
|
|
2286
|
-
/**
|
|
2287
|
-
* {@link ResourcesControl.getMany}
|
|
2288
|
-
*/
|
|
2289
|
-
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
2290
|
-
return this.resources.getMany(resource, requestOptions);
|
|
2291
|
-
};
|
|
2292
|
-
/**
|
|
2293
|
-
* {@link ResourcesControl.getParent}
|
|
2294
|
-
*/
|
|
2295
|
-
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
2296
|
-
return this.resources.getParent(resource, requestOptions);
|
|
2297
|
-
};
|
|
2298
|
-
/**
|
|
2299
|
-
* {@link ResourcesControl.getChildrenOf}
|
|
2300
|
-
*/
|
|
2301
|
-
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
2302
|
-
return this.resources.getChildrenOf(resource, requestOptions);
|
|
2303
|
-
};
|
|
2304
|
-
/**
|
|
2305
|
-
* {@link ResourcesControl.update}
|
|
2306
|
-
*/
|
|
2307
|
-
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
2308
|
-
return this.resources.update(resource, data);
|
|
2309
|
-
};
|
|
2310
|
-
/**
|
|
2311
|
-
* {@link ResourcesControl.delete}
|
|
2312
|
-
*/
|
|
2313
|
-
NgwConnector.prototype.deleteResource = function (resource) {
|
|
2314
|
-
return this.resources.delete(resource);
|
|
2315
|
-
};
|
|
2316
|
-
/**
|
|
2317
|
-
* @internal
|
|
2318
|
-
*/
|
|
2319
|
-
NgwConnector.prototype._loadData = function (url, options) {
|
|
2320
|
-
var _this = this;
|
|
2321
|
-
options.responseType = options.responseType || 'json';
|
|
2322
|
-
var request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2323
|
-
if (_this.user) {
|
|
2324
|
-
options = options || {};
|
|
2325
|
-
// options.withCredentials = true;
|
|
2326
|
-
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
2327
|
-
}
|
|
2328
|
-
if (_this.requestTransform) {
|
|
2329
|
-
var _a = _this.requestTransform(url, options), transUrl = _a[0], transOptions = _a[1];
|
|
2330
|
-
url = transUrl;
|
|
2331
|
-
options = transOptions;
|
|
2332
|
-
}
|
|
2333
|
-
loadData(url, resolve, options, reject, onCancel);
|
|
2334
|
-
})
|
|
2335
|
-
.then(function (resp) {
|
|
2336
|
-
_this._cleanActiveRequests(request);
|
|
2337
|
-
return resp;
|
|
2338
|
-
})
|
|
2339
|
-
.catch(function (httpError) {
|
|
2340
|
-
_this._cleanActiveRequests(request);
|
|
2341
|
-
if (httpError instanceof CancelablePromise.CancelError) ;
|
|
2342
|
-
else {
|
|
2343
|
-
// @ts-ignore
|
|
2344
|
-
{
|
|
2345
|
-
console.warn('DEV WARN', httpError);
|
|
2346
|
-
}
|
|
2347
|
-
var er = _this._handleHttpError(httpError);
|
|
2348
|
-
if (er) {
|
|
2349
|
-
throw er;
|
|
2350
|
-
}
|
|
2351
|
-
}
|
|
2352
|
-
});
|
|
2353
|
-
if (options.signal &&
|
|
2354
|
-
typeof options.signal.addEventListener === 'function') {
|
|
2355
|
-
options.signal.addEventListener('abort', function () {
|
|
2356
|
-
request.cancel();
|
|
2357
|
-
_this._cleanActiveRequests(request);
|
|
2358
|
-
});
|
|
2359
|
-
}
|
|
2360
|
-
this.activeRequests.push(request);
|
|
2361
|
-
return request;
|
|
2362
|
-
};
|
|
2363
|
-
NgwConnector.prototype._login = function (credentials, options) {
|
|
2364
|
-
var _this = this;
|
|
2365
|
-
return this.getUserInfo(credentials, options)
|
|
2366
|
-
.then(function (data) {
|
|
2367
|
-
_this.user = data;
|
|
2368
|
-
_this.emitter.emit('login', data);
|
|
2369
|
-
return data;
|
|
2370
|
-
})
|
|
2371
|
-
.catch(function (er) {
|
|
2372
|
-
_this.emitter.emit('login:error', er);
|
|
2373
|
-
throw er;
|
|
2374
|
-
});
|
|
2375
|
-
};
|
|
2376
|
-
NgwConnector.prototype._cleanActiveRequests = function (request) {
|
|
2377
|
-
var activeRequestIndex = this.activeRequests.indexOf(request);
|
|
2378
|
-
if (activeRequestIndex !== -1) {
|
|
2379
|
-
this.activeRequests.splice(activeRequestIndex, 1);
|
|
2380
|
-
}
|
|
2381
|
-
};
|
|
2382
|
-
NgwConnector.prototype._handleHttpError = function (er) {
|
|
2383
|
-
if (er) {
|
|
2384
|
-
if (er instanceof NgwError) {
|
|
2385
|
-
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
2386
|
-
throw new ResourceNotFoundError(er);
|
|
2387
|
-
}
|
|
2388
|
-
else if (er.exception === 'nextgisweb.core.exception.InsufficientPermissions') {
|
|
2389
|
-
throw new InsufficientPermissionsError(er);
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
return er;
|
|
2394
|
-
};
|
|
2395
|
-
NgwConnector.errors = {
|
|
2396
|
-
NgwError: NgwError,
|
|
2397
|
-
ResourceNotFoundError: ResourceNotFoundError,
|
|
2398
|
-
};
|
|
2399
|
-
return NgwConnector;
|
|
2031
|
+
var ID = 0;
|
|
2032
|
+
var NgwConnector$1 = /** @class */ (function () {
|
|
2033
|
+
function NgwConnector(options) {
|
|
2034
|
+
this.options = options;
|
|
2035
|
+
this.id = ID++;
|
|
2036
|
+
this.emitter = new events.exports.EventEmitter();
|
|
2037
|
+
this.routeStr = '/api/component/pyramid/route';
|
|
2038
|
+
this.activeRequests = [];
|
|
2039
|
+
var exist = findConnector(options);
|
|
2040
|
+
if (exist) {
|
|
2041
|
+
return exist;
|
|
2042
|
+
}
|
|
2043
|
+
else {
|
|
2044
|
+
if (this.options.route) {
|
|
2045
|
+
this.routeStr = this.options.route;
|
|
2046
|
+
}
|
|
2047
|
+
if (this.options.requestTransform) {
|
|
2048
|
+
this.requestTransform = this.options.requestTransform;
|
|
2049
|
+
}
|
|
2050
|
+
this.resources = new ResourcesControl(this);
|
|
2051
|
+
addConnector(this);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
NgwConnector.create = function (options) {
|
|
2055
|
+
return new this(options);
|
|
2056
|
+
};
|
|
2057
|
+
NgwConnector.prototype.setRequestTransform = function (requestTransform) {
|
|
2058
|
+
this.requestTransform = requestTransform;
|
|
2059
|
+
};
|
|
2060
|
+
/**
|
|
2061
|
+
* Fast way to specify the connection address to NextGIS Web.
|
|
2062
|
+
* The current connection will be severed.
|
|
2063
|
+
* @param baseUrl - NGW url
|
|
2064
|
+
*/
|
|
2065
|
+
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
2066
|
+
this.logout();
|
|
2067
|
+
this.options.baseUrl = baseUrl;
|
|
2068
|
+
addConnector(this);
|
|
2069
|
+
};
|
|
2070
|
+
/**
|
|
2071
|
+
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
2072
|
+
* @remarks
|
|
2073
|
+
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
2074
|
+
* Can be used to check connection.
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```javascript
|
|
2077
|
+
* const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
|
|
2078
|
+
* connector.connect()
|
|
2079
|
+
* .then(() => console.log('Ok'))
|
|
2080
|
+
* .catch((er) => console.log('Connection problem', er));
|
|
2081
|
+
* ```
|
|
2082
|
+
*/
|
|
2083
|
+
NgwConnector.prototype.connect = function () {
|
|
2084
|
+
var _this = this;
|
|
2085
|
+
var cache = new Cache();
|
|
2086
|
+
var auth = this.options.auth;
|
|
2087
|
+
var makeConnect = function () {
|
|
2088
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
2089
|
+
var makeQuery = function () {
|
|
2090
|
+
return _this.makeQuery(_this.routeStr, {}, {})
|
|
2091
|
+
.then(function (route) {
|
|
2092
|
+
resolve(route);
|
|
2093
|
+
})
|
|
2094
|
+
.catch(function (er) {
|
|
2095
|
+
reject(er);
|
|
2096
|
+
});
|
|
2097
|
+
};
|
|
2098
|
+
if (auth) {
|
|
2099
|
+
var login = auth.login, password = auth.password;
|
|
2100
|
+
if (login && password) {
|
|
2101
|
+
return _this._login({ login: login, password: password })
|
|
2102
|
+
.then(function () {
|
|
2103
|
+
return makeQuery();
|
|
2104
|
+
})
|
|
2105
|
+
.catch(function (er) { return reject(er); });
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
return makeQuery();
|
|
2109
|
+
});
|
|
2110
|
+
};
|
|
2111
|
+
return cache.add('route', makeConnect, {
|
|
2112
|
+
id: this.id,
|
|
2113
|
+
auth: auth,
|
|
2114
|
+
baseUrl: this.options.baseUrl,
|
|
2115
|
+
});
|
|
2116
|
+
};
|
|
2117
|
+
/**
|
|
2118
|
+
* Quick way to change NextGIS Web user.
|
|
2119
|
+
* @param credentials - New user credentials
|
|
2120
|
+
*/
|
|
2121
|
+
NgwConnector.prototype.login = function (credentials, options) {
|
|
2122
|
+
this.logout();
|
|
2123
|
+
addConnector(this);
|
|
2124
|
+
return this._login(credentials, options);
|
|
2125
|
+
};
|
|
2126
|
+
/**
|
|
2127
|
+
* Disconnecting a user. Aborting all current requests
|
|
2128
|
+
*/
|
|
2129
|
+
NgwConnector.prototype.logout = function () {
|
|
2130
|
+
this.abort();
|
|
2131
|
+
removeConnector(this);
|
|
2132
|
+
this.options.auth = undefined;
|
|
2133
|
+
this.user = undefined;
|
|
2134
|
+
this.emitter.emit('logout');
|
|
2135
|
+
this.resources.cache.clean();
|
|
2136
|
+
};
|
|
2137
|
+
NgwConnector.prototype.getUserInfo = function (credentials, options) {
|
|
2138
|
+
if (this.user && this.user.id) {
|
|
2139
|
+
return CancelablePromise.resolve(this.user);
|
|
2140
|
+
}
|
|
2141
|
+
if (credentials) {
|
|
2142
|
+
this.options.auth = credentials;
|
|
2143
|
+
}
|
|
2144
|
+
var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
|
|
2145
|
+
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
2146
|
+
return this.makeQuery('/api/component/auth/current_user', {}, options_);
|
|
2147
|
+
};
|
|
2148
|
+
/**
|
|
2149
|
+
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
2150
|
+
*/
|
|
2151
|
+
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
2152
|
+
var client = this.makeClientId(credentials);
|
|
2153
|
+
if (client) {
|
|
2154
|
+
return {
|
|
2155
|
+
Authorization: 'Basic ' + client,
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
2160
|
+
credentials = credentials || this.options.auth;
|
|
2161
|
+
if (credentials) {
|
|
2162
|
+
var login = credentials.login, password = credentials.password;
|
|
2163
|
+
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
2164
|
+
// @ts-ignore
|
|
2165
|
+
{
|
|
2166
|
+
return window.btoa(str);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
/** Stop all api requests */
|
|
2171
|
+
NgwConnector.prototype.abort = function () {
|
|
2172
|
+
for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
|
|
2173
|
+
var req = _a[_i];
|
|
2174
|
+
req.cancel();
|
|
2175
|
+
}
|
|
2176
|
+
this.activeRequests = [];
|
|
2177
|
+
};
|
|
2178
|
+
NgwConnector.prototype.getActiveApiRequests = function () {
|
|
2179
|
+
return __spreadArray([], this.activeRequests, true);
|
|
2180
|
+
};
|
|
2181
|
+
/**
|
|
2182
|
+
* Send request to NGW api router.
|
|
2183
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2184
|
+
* @param params - Request item params or query params
|
|
2185
|
+
* @param requestOptions - Request options
|
|
2186
|
+
*
|
|
2187
|
+
* @example
|
|
2188
|
+
* ```javascript
|
|
2189
|
+
*
|
|
2190
|
+
* // there is such an NGW route item
|
|
2191
|
+
* // "feature_layer.feature.item": [
|
|
2192
|
+
* // "/api/resource/{0}/feature/{1}",
|
|
2193
|
+
* // "id",
|
|
2194
|
+
* // "fid"
|
|
2195
|
+
* // ],
|
|
2196
|
+
*
|
|
2197
|
+
* const connector = new NgwConnector({ baseUrl: 'https://example.nextgis.com' });
|
|
2198
|
+
* connector.apiRequest('feature_layer.feature.item', {
|
|
2199
|
+
* // request params for {0} and {1}
|
|
2200
|
+
* 'id': 2011,
|
|
2201
|
+
* 'fid': 101,
|
|
2202
|
+
* // query params
|
|
2203
|
+
* 'srs': 4326,
|
|
2204
|
+
* 'geom_format': 'geojson',
|
|
2205
|
+
* }, { method: 'GET' });
|
|
2206
|
+
* // send get-request to 'https://example.nextgis.com/api/resource/2011/feature/101?srs=4326&geom_format=geojson'
|
|
2207
|
+
*
|
|
2208
|
+
* ```
|
|
2209
|
+
*/
|
|
2210
|
+
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
2211
|
+
var _this = this;
|
|
2212
|
+
var _a;
|
|
2213
|
+
if (params_ === void 0) { params_ = {}; }
|
|
2214
|
+
if (requestOptions === void 0) { requestOptions = {}; }
|
|
2215
|
+
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
2216
|
+
var params = objectRemoveEmpty(params_);
|
|
2217
|
+
var makeApiRequest = function () {
|
|
2218
|
+
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
2219
|
+
};
|
|
2220
|
+
if (requestOptions.cache && method === 'GET') {
|
|
2221
|
+
var cache = new Cache();
|
|
2222
|
+
return cache.add(name, makeApiRequest, __assign({ params: params }, objectRemoveEmpty({
|
|
2223
|
+
headers: headers,
|
|
2224
|
+
withCredentials: withCredentials,
|
|
2225
|
+
responseType: responseType,
|
|
2226
|
+
baseUrl: this.options.baseUrl,
|
|
2227
|
+
userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
|
|
2228
|
+
})));
|
|
2229
|
+
}
|
|
2230
|
+
return makeApiRequest();
|
|
2231
|
+
};
|
|
2232
|
+
/**
|
|
2233
|
+
* Shortcut method for send POST request to NGW.
|
|
2234
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2235
|
+
* @param options - Request options
|
|
2236
|
+
* @param params - Request item params or query params
|
|
2237
|
+
*
|
|
2238
|
+
* @example
|
|
2239
|
+
* ```javascript
|
|
2240
|
+
* connector.post('resource.collection', { data: POST_PAYLOAD })
|
|
2241
|
+
* .then((newResource) => console.log(newResource))
|
|
2242
|
+
* .catch((error) => console.warn(error));
|
|
2243
|
+
* ```
|
|
2244
|
+
*/
|
|
2245
|
+
NgwConnector.prototype.post = function (name, options, params) {
|
|
2246
|
+
options = options || {};
|
|
2247
|
+
options.method = 'POST';
|
|
2248
|
+
return this.apiRequest(name, params, options);
|
|
2249
|
+
};
|
|
2250
|
+
/**
|
|
2251
|
+
* Shortcut method for send GET request to NGW.
|
|
2252
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2253
|
+
* @param options - Request options
|
|
2254
|
+
* @param params - Request item params or query params
|
|
2255
|
+
*/
|
|
2256
|
+
NgwConnector.prototype.get = function (name, options, params) {
|
|
2257
|
+
options = options || {};
|
|
2258
|
+
options.method = 'GET';
|
|
2259
|
+
return this.apiRequest(name, params, options);
|
|
2260
|
+
};
|
|
2261
|
+
/**
|
|
2262
|
+
* Shortcut method for send PATCH request to NGW.
|
|
2263
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2264
|
+
* @param options - Request options
|
|
2265
|
+
* @param params - Request item params or query params
|
|
2266
|
+
*/
|
|
2267
|
+
NgwConnector.prototype.patch = function (name, options, params) {
|
|
2268
|
+
options = options || {};
|
|
2269
|
+
options.method = 'PATCH';
|
|
2270
|
+
return this.apiRequest(name, params, options);
|
|
2271
|
+
};
|
|
2272
|
+
/**
|
|
2273
|
+
* Shortcut method for send PUT request to NGW.
|
|
2274
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2275
|
+
* @param options - Request options
|
|
2276
|
+
* @param params - Request item params or query params
|
|
2277
|
+
*/
|
|
2278
|
+
NgwConnector.prototype.put = function (name, options, params) {
|
|
2279
|
+
options = options || {};
|
|
2280
|
+
options.method = 'PUT';
|
|
2281
|
+
return this.apiRequest(name, params, options);
|
|
2282
|
+
};
|
|
2283
|
+
/**
|
|
2284
|
+
* Shortcut method for send DELETE request to NGW.
|
|
2285
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2286
|
+
* @param options - Request options
|
|
2287
|
+
* @param params - Request item params or query params
|
|
2288
|
+
*/
|
|
2289
|
+
NgwConnector.prototype.delete = function (name, options, params) {
|
|
2290
|
+
options = options || {};
|
|
2291
|
+
options.method = 'DELETE';
|
|
2292
|
+
return this.apiRequest(name, params, options);
|
|
2293
|
+
};
|
|
2294
|
+
/**
|
|
2295
|
+
* Send request to NGW.
|
|
2296
|
+
* @param url - URL address to NGW
|
|
2297
|
+
* @param params - Query params
|
|
2298
|
+
* @param options - Request options
|
|
2299
|
+
*/
|
|
2300
|
+
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
2301
|
+
if (options === void 0) { options = {}; }
|
|
2302
|
+
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
2303
|
+
if (url) {
|
|
2304
|
+
if (params) {
|
|
2305
|
+
url = template(url, params);
|
|
2306
|
+
}
|
|
2307
|
+
url = encodeURI(fixUrlStr(url));
|
|
2308
|
+
return this._loadData(url, options);
|
|
2309
|
+
}
|
|
2310
|
+
else {
|
|
2311
|
+
throw new Error('Empty `url` not allowed');
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
// -------------------------------------------------------------------------
|
|
2315
|
+
// Resource Methods
|
|
2316
|
+
// -------------------------------------------------------------------------
|
|
2317
|
+
/**
|
|
2318
|
+
* {@link ResourcesControl.getOne}
|
|
2319
|
+
*/
|
|
2320
|
+
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
2321
|
+
return this.resources.getOne(resource, requestOptions);
|
|
2322
|
+
};
|
|
2323
|
+
/**
|
|
2324
|
+
* {@link ResourcesControl.getOneOrFail}
|
|
2325
|
+
*/
|
|
2326
|
+
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
2327
|
+
return this.resources.getOneOrFail(resource, requestOptions);
|
|
2328
|
+
};
|
|
2329
|
+
/**
|
|
2330
|
+
* @deprecated - use {@link getResource}
|
|
2331
|
+
*/
|
|
2332
|
+
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
2333
|
+
return this.resources.getOne(resource);
|
|
2334
|
+
};
|
|
2335
|
+
/**
|
|
2336
|
+
* @deprecated - use {@link getResource}
|
|
2337
|
+
*/
|
|
2338
|
+
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
2339
|
+
return this.resources.getOne(keyname);
|
|
2340
|
+
};
|
|
2341
|
+
/**
|
|
2342
|
+
* @deprecated - use {@link getResource}
|
|
2343
|
+
*/
|
|
2344
|
+
NgwConnector.prototype.getResourceById = function (id) {
|
|
2345
|
+
return this.resources.getOne(id);
|
|
2346
|
+
};
|
|
2347
|
+
/**
|
|
2348
|
+
* {@link ResourcesControl.getId}
|
|
2349
|
+
*/
|
|
2350
|
+
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
2351
|
+
return this.resources.getId(resource, requestOptions);
|
|
2352
|
+
};
|
|
2353
|
+
/**
|
|
2354
|
+
* {@link ResourcesControl.getIdOrFail}
|
|
2355
|
+
*/
|
|
2356
|
+
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
2357
|
+
return this.resources.getIdOrFail(resource, requestOptions);
|
|
2358
|
+
};
|
|
2359
|
+
/**
|
|
2360
|
+
* {@link ResourcesControl.getMany}
|
|
2361
|
+
*/
|
|
2362
|
+
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
2363
|
+
return this.resources.getMany(resource, requestOptions);
|
|
2364
|
+
};
|
|
2365
|
+
/**
|
|
2366
|
+
* {@link ResourcesControl.getParent}
|
|
2367
|
+
*/
|
|
2368
|
+
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
2369
|
+
return this.resources.getParent(resource, requestOptions);
|
|
2370
|
+
};
|
|
2371
|
+
/**
|
|
2372
|
+
* {@link ResourcesControl.getChildrenOf}
|
|
2373
|
+
*/
|
|
2374
|
+
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
2375
|
+
return this.resources.getChildrenOf(resource, requestOptions);
|
|
2376
|
+
};
|
|
2377
|
+
/**
|
|
2378
|
+
* {@link ResourcesControl.update}
|
|
2379
|
+
*/
|
|
2380
|
+
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
2381
|
+
return this.resources.update(resource, data);
|
|
2382
|
+
};
|
|
2383
|
+
/**
|
|
2384
|
+
* {@link ResourcesControl.delete}
|
|
2385
|
+
*/
|
|
2386
|
+
NgwConnector.prototype.deleteResource = function (resource) {
|
|
2387
|
+
return this.resources.delete(resource);
|
|
2388
|
+
};
|
|
2389
|
+
/**
|
|
2390
|
+
* @internal
|
|
2391
|
+
*/
|
|
2392
|
+
NgwConnector.prototype._loadData = function (url, options) {
|
|
2393
|
+
var _this = this;
|
|
2394
|
+
options.responseType = options.responseType || 'json';
|
|
2395
|
+
var request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2396
|
+
if (_this.user) {
|
|
2397
|
+
options = options || {};
|
|
2398
|
+
// options.withCredentials = true;
|
|
2399
|
+
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
2400
|
+
}
|
|
2401
|
+
if (_this.requestTransform) {
|
|
2402
|
+
var _a = _this.requestTransform(url, options), transUrl = _a[0], transOptions = _a[1];
|
|
2403
|
+
url = transUrl;
|
|
2404
|
+
options = transOptions;
|
|
2405
|
+
}
|
|
2406
|
+
loadData(url, resolve, options, reject, onCancel);
|
|
2407
|
+
})
|
|
2408
|
+
.then(function (resp) {
|
|
2409
|
+
_this._cleanActiveRequests(request);
|
|
2410
|
+
return resp;
|
|
2411
|
+
})
|
|
2412
|
+
.catch(function (httpError) {
|
|
2413
|
+
_this._cleanActiveRequests(request);
|
|
2414
|
+
if (httpError instanceof CancelablePromise.CancelError) ;
|
|
2415
|
+
else {
|
|
2416
|
+
// @ts-ignore
|
|
2417
|
+
{
|
|
2418
|
+
console.warn('DEV WARN', httpError);
|
|
2419
|
+
}
|
|
2420
|
+
var er = _this._handleHttpError(httpError);
|
|
2421
|
+
if (er) {
|
|
2422
|
+
throw er;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
});
|
|
2426
|
+
if (options.signal &&
|
|
2427
|
+
typeof options.signal.addEventListener === 'function') {
|
|
2428
|
+
options.signal.addEventListener('abort', function () {
|
|
2429
|
+
request.cancel();
|
|
2430
|
+
_this._cleanActiveRequests(request);
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
this.activeRequests.push(request);
|
|
2434
|
+
return request;
|
|
2435
|
+
};
|
|
2436
|
+
NgwConnector.prototype._login = function (credentials, options) {
|
|
2437
|
+
var _this = this;
|
|
2438
|
+
return this.getUserInfo(credentials, options)
|
|
2439
|
+
.then(function (data) {
|
|
2440
|
+
_this.user = data;
|
|
2441
|
+
_this.emitter.emit('login', data);
|
|
2442
|
+
return data;
|
|
2443
|
+
})
|
|
2444
|
+
.catch(function (er) {
|
|
2445
|
+
_this.emitter.emit('login:error', er);
|
|
2446
|
+
throw er;
|
|
2447
|
+
});
|
|
2448
|
+
};
|
|
2449
|
+
NgwConnector.prototype._cleanActiveRequests = function (request) {
|
|
2450
|
+
var activeRequestIndex = this.activeRequests.indexOf(request);
|
|
2451
|
+
if (activeRequestIndex !== -1) {
|
|
2452
|
+
this.activeRequests.splice(activeRequestIndex, 1);
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
NgwConnector.prototype._handleHttpError = function (er) {
|
|
2456
|
+
if (er) {
|
|
2457
|
+
if (er instanceof NgwError) {
|
|
2458
|
+
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
2459
|
+
throw new ResourceNotFoundError(er);
|
|
2460
|
+
}
|
|
2461
|
+
else if (er.exception === 'nextgisweb.core.exception.InsufficientPermissions') {
|
|
2462
|
+
throw new InsufficientPermissionsError(er);
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
return er;
|
|
2467
|
+
};
|
|
2468
|
+
NgwConnector.errors = {
|
|
2469
|
+
NgwError: NgwError,
|
|
2470
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
2471
|
+
};
|
|
2472
|
+
return NgwConnector;
|
|
2400
2473
|
}());
|
|
2401
2474
|
|
|
2402
|
-
/**
|
|
2403
|
-
* A lightweight HTTP client optimized for use with {@link http://docs.nextgis.ru/docs_ngweb_dev/doc/developer/toc.html | NextGIS Web} API
|
|
2404
|
-
*
|
|
2405
|
-
* @remarks
|
|
2406
|
-
* Make sure CORS is registered in the {@link https://docs.nextgis.com/docs_ngcom/source/CORS.html | NextGIS Web settings } to be able to send requests.
|
|
2407
|
-
*
|
|
2408
|
-
* @packageDocumentation
|
|
2409
|
-
* @module ngw-connector
|
|
2410
|
-
*/
|
|
2475
|
+
/**
|
|
2476
|
+
* A lightweight HTTP client optimized for use with {@link http://docs.nextgis.ru/docs_ngweb_dev/doc/developer/toc.html | NextGIS Web} API
|
|
2477
|
+
*
|
|
2478
|
+
* @remarks
|
|
2479
|
+
* Make sure CORS is registered in the {@link https://docs.nextgis.com/docs_ngcom/source/CORS.html | NextGIS Web settings } to be able to send requests.
|
|
2480
|
+
*
|
|
2481
|
+
* @packageDocumentation
|
|
2482
|
+
* @module ngw-connector
|
|
2483
|
+
*/
|
|
2411
2484
|
var NgwConnector = NgwConnector$1;
|
|
2412
2485
|
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
}
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
}
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2486
|
+
function reEscape(s) {
|
|
2487
|
+
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
2488
|
+
}
|
|
2489
|
+
function like(b, a, iLike) {
|
|
2490
|
+
a = String(a);
|
|
2491
|
+
b = String(b);
|
|
2492
|
+
if (a === b)
|
|
2493
|
+
return true;
|
|
2494
|
+
if (iLike && a.toUpperCase() === b.toUpperCase())
|
|
2495
|
+
return true;
|
|
2496
|
+
var re = "^".concat(reEscape(a), "$").replace(/%/g, '.*').replace('_', '.');
|
|
2497
|
+
return new RegExp(re, iLike ? 'i' : '').exec(b) !== null;
|
|
2498
|
+
}
|
|
2499
|
+
var operationsAliases = {
|
|
2500
|
+
// greater(>)
|
|
2501
|
+
gt: function (a, b) { return a > b; },
|
|
2502
|
+
// lower(<)
|
|
2503
|
+
lt: function (a, b) { return a < b; },
|
|
2504
|
+
// greater or equal(>=)
|
|
2505
|
+
ge: function (a, b) { return a >= b; },
|
|
2506
|
+
// lower or equal(<=)
|
|
2507
|
+
le: function (a, b) { return a <= b; },
|
|
2508
|
+
// equal(=)
|
|
2509
|
+
eq: function (a, b) { return a === b; },
|
|
2510
|
+
// not equal(!=)
|
|
2511
|
+
ne: function (a, b) { return a !== b; },
|
|
2512
|
+
in: function (a, b) { return b.indexOf(a) !== -1; },
|
|
2513
|
+
notin: function (a, b) { return b.indexOf(a) === -1; },
|
|
2514
|
+
// LIKE SQL statement(for strings compare)
|
|
2515
|
+
like: function (a, b) {
|
|
2516
|
+
return like(a, b);
|
|
2517
|
+
},
|
|
2518
|
+
// ILIKE SQL statement(for strings compare)
|
|
2519
|
+
ilike: function (a, b) {
|
|
2520
|
+
return like(a, b, true);
|
|
2521
|
+
},
|
|
2522
|
+
};
|
|
2523
|
+
function isPropertyFilter(filter) {
|
|
2524
|
+
var pf = filter;
|
|
2525
|
+
if (pf.length === 3 &&
|
|
2526
|
+
typeof pf[0] === 'string' &&
|
|
2527
|
+
typeof pf[1] === 'string') {
|
|
2528
|
+
return true;
|
|
2529
|
+
}
|
|
2530
|
+
return false;
|
|
2531
|
+
}
|
|
2532
|
+
function propertiesFilter(properties, filters) {
|
|
2533
|
+
var logic = typeof filters[0] === 'string' ? filters[0] : 'all';
|
|
2534
|
+
var filterFunction = function (p) {
|
|
2535
|
+
if (isPropertyFilter(p)) {
|
|
2536
|
+
var field_1 = p[0], operation = p[1], value_1 = p[2];
|
|
2537
|
+
var operationExec = operationsAliases[operation];
|
|
2538
|
+
if (operationExec) {
|
|
2539
|
+
if (operation === 'like' || operation === 'ilike') {
|
|
2540
|
+
if (typeof field_1 === 'string') {
|
|
2541
|
+
var prop_1 = '';
|
|
2542
|
+
var value_ = field_1.replace(/^%?(\w+)%?$/, function (match, cleanField) {
|
|
2543
|
+
prop_1 = properties[cleanField];
|
|
2544
|
+
return field_1.replace(cleanField, value_1);
|
|
2545
|
+
});
|
|
2546
|
+
return operationExec(prop_1, value_);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
return operationExec(properties[field_1], value_1);
|
|
2550
|
+
}
|
|
2551
|
+
return false;
|
|
2552
|
+
}
|
|
2553
|
+
else {
|
|
2554
|
+
return propertiesFilter(properties, p);
|
|
2555
|
+
}
|
|
2556
|
+
};
|
|
2557
|
+
var filters_ = filters.filter(function (x) { return Array.isArray(x); });
|
|
2558
|
+
return logic === 'any'
|
|
2559
|
+
? filters_.some(filterFunction)
|
|
2560
|
+
: filters_.every(filterFunction);
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
var FEATURE_REQUEST_PARAMS = {
|
|
2564
|
+
srs: 4326,
|
|
2565
|
+
geom_format: 'geojson',
|
|
2566
|
+
};
|
|
2567
|
+
function updateItemRequestParam(params, options) {
|
|
2568
|
+
var extensions = options.extensions, geom = options.geom, fields = options.fields, srs = options.srs, ilike = options.ilike, like = options.like;
|
|
2569
|
+
if (extensions) {
|
|
2570
|
+
params.extensions = extensions.join(',');
|
|
2571
|
+
}
|
|
2572
|
+
if (fields !== undefined) {
|
|
2573
|
+
params.fields = Array.isArray(fields) ? fields.join(',') : '';
|
|
2574
|
+
}
|
|
2575
|
+
if (geom !== undefined) {
|
|
2576
|
+
params.geom = geom ? 'yes' : 'no';
|
|
2577
|
+
if (!geom) {
|
|
2578
|
+
delete params.srs;
|
|
2579
|
+
delete params.geom_format;
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
if (defined(ilike)) {
|
|
2583
|
+
params.ilike = ilike;
|
|
2584
|
+
}
|
|
2585
|
+
else if (defined(like)) {
|
|
2586
|
+
params.like = like;
|
|
2587
|
+
}
|
|
2588
|
+
if (defined(srs)) {
|
|
2589
|
+
params.srs = srs;
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
// NGW REST API is not able to filtering by combined queries
|
|
2593
|
+
// therefore the filter is divided into several requests
|
|
2594
|
+
function createFeatureFieldFilterQueries(opt) {
|
|
2595
|
+
var queries = getQueries(opt);
|
|
2596
|
+
return CancelablePromise.all(queries).then(function (itemsParts) {
|
|
2597
|
+
// this list of ids used for optimization
|
|
2598
|
+
var ids = [];
|
|
2599
|
+
var items = [];
|
|
2600
|
+
for (var _i = 0, itemsParts_1 = itemsParts; _i < itemsParts_1.length; _i++) {
|
|
2601
|
+
var part = itemsParts_1[_i];
|
|
2602
|
+
for (var _a = 0, part_1 = part; _a < part_1.length; _a++) {
|
|
2603
|
+
var item = part_1[_a];
|
|
2604
|
+
if (!ids.includes(item.id)) {
|
|
2605
|
+
items.push(item);
|
|
2606
|
+
ids.push(item.id);
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
var offset = opt.offset !== undefined ? opt.offset : 0;
|
|
2611
|
+
var limit = opt.limit !== undefined ? opt.limit : items.length;
|
|
2612
|
+
if (opt.offset || opt.limit) {
|
|
2613
|
+
return items.splice(offset, limit);
|
|
2614
|
+
}
|
|
2615
|
+
return items;
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
function createParam(pf) {
|
|
2619
|
+
var field = pf[0], operation = pf[1], value = pf[2];
|
|
2620
|
+
var isFldStr = field !== 'id' ? 'fld_' : '';
|
|
2621
|
+
var vStart = '';
|
|
2622
|
+
var vEnd = '';
|
|
2623
|
+
var field_ = String(field)
|
|
2624
|
+
.trim()
|
|
2625
|
+
.replace(/^(%?)(.+?)(%?)$/, function (m, a, b, c) {
|
|
2626
|
+
vStart = a;
|
|
2627
|
+
vEnd = c;
|
|
2628
|
+
return b;
|
|
2629
|
+
});
|
|
2630
|
+
var v = vStart + value + vEnd;
|
|
2631
|
+
return ["".concat(isFldStr).concat(field_, "__").concat(operation), v];
|
|
2632
|
+
}
|
|
2633
|
+
function getQueries(opt, _queries, _parentAllParams) {
|
|
2634
|
+
if (_queries === void 0) { _queries = []; }
|
|
2635
|
+
if (_parentAllParams === void 0) { _parentAllParams = []; }
|
|
2636
|
+
var filters = opt.filters;
|
|
2637
|
+
var logic = typeof filters[0] === 'string' ? filters[0] : 'all';
|
|
2638
|
+
var filters_ = filters.filter(function (x) { return Array.isArray(x); });
|
|
2639
|
+
if (logic === 'any') {
|
|
2640
|
+
for (var _i = 0, filters_1 = filters_; _i < filters_1.length; _i++) {
|
|
2641
|
+
var f = filters_1[_i];
|
|
2642
|
+
if (isPropertyFilter(f)) {
|
|
2643
|
+
_queries.push(fetchNgwLayerItemsRequest(__assign(__assign({}, opt), { paramList: __spreadArray(__spreadArray([], _parentAllParams, true), [createParam(f)], false) })));
|
|
2644
|
+
}
|
|
2645
|
+
else {
|
|
2646
|
+
getQueries(__assign(__assign({}, opt), { filters: f }), _queries, __spreadArray([], _parentAllParams, true));
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
else if (logic === 'all') {
|
|
2651
|
+
var filters_3 = [];
|
|
2652
|
+
var propertiesFilterList = [];
|
|
2653
|
+
for (var _a = 0, filters_2 = filters_; _a < filters_2.length; _a++) {
|
|
2654
|
+
var f = filters_2[_a];
|
|
2655
|
+
if (isPropertyFilter(f)) {
|
|
2656
|
+
filters_3.push(createParam(f));
|
|
2657
|
+
}
|
|
2658
|
+
else {
|
|
2659
|
+
propertiesFilterList.push(f);
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
if (propertiesFilterList.length) {
|
|
2663
|
+
for (var _b = 0, propertiesFilterList_1 = propertiesFilterList; _b < propertiesFilterList_1.length; _b++) {
|
|
2664
|
+
var x = propertiesFilterList_1[_b];
|
|
2665
|
+
getQueries(__assign(__assign({}, opt), { filters: x }), _queries, __spreadArray(__spreadArray([], _parentAllParams, true), filters_3, true));
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
else {
|
|
2669
|
+
_queries.push(fetchNgwLayerItemsRequest(__assign(__assign({}, opt), { paramList: __spreadArray(__spreadArray([], _parentAllParams, true), filters_3, true) })));
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
return _queries;
|
|
2673
|
+
}
|
|
2674
|
+
function createWktFromCoordArray(coord) {
|
|
2675
|
+
var polygon = coord.map(function (_a) {
|
|
2676
|
+
var lng = _a[0], lat = _a[1];
|
|
2677
|
+
var _b = degrees2meters(lng, lat).map(function (c) { return round(c); }), x = _b[0], y = _b[1];
|
|
2678
|
+
return x + ' ' + y;
|
|
2679
|
+
});
|
|
2680
|
+
return "POLYGON((".concat(polygon.join(', '), "))");
|
|
2681
|
+
}
|
|
2682
|
+
function fetchNgwLayerItemsRequest(options) {
|
|
2683
|
+
var params = __assign({}, FEATURE_REQUEST_PARAMS);
|
|
2684
|
+
var limit = options.limit, cache = options.cache, signal = options.signal, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, geomFormat = options.geomFormat, intersects = options.intersects, resourceId = options.resourceId;
|
|
2685
|
+
if (limit) {
|
|
2686
|
+
if (limit !== Number.POSITIVE_INFINITY) {
|
|
2687
|
+
params.limit = limit;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
else {
|
|
2691
|
+
// Strict restriction on loading data from large layers
|
|
2692
|
+
params.limit = 7000;
|
|
2693
|
+
}
|
|
2694
|
+
if (offset) {
|
|
2695
|
+
params.offset = offset;
|
|
2696
|
+
}
|
|
2697
|
+
if (geomFormat) {
|
|
2698
|
+
params.geom_format = geomFormat;
|
|
2699
|
+
}
|
|
2700
|
+
updateItemRequestParam(params, options);
|
|
2701
|
+
if (orderBy) {
|
|
2702
|
+
params.order_by = orderBy.join(',');
|
|
2703
|
+
}
|
|
2704
|
+
if (Array.isArray(intersects)) {
|
|
2705
|
+
var coordinates = isLngLatBoundsArray(intersects)
|
|
2706
|
+
? getBoundsCoordinates(intersects)
|
|
2707
|
+
: intersects;
|
|
2708
|
+
params.intersects = createWktFromCoordArray(coordinates);
|
|
2709
|
+
}
|
|
2710
|
+
else if (typeof intersects === 'string') {
|
|
2711
|
+
params.intersects = intersects;
|
|
2712
|
+
}
|
|
2713
|
+
if (paramList) {
|
|
2714
|
+
params.paramList = paramList;
|
|
2715
|
+
}
|
|
2716
|
+
var reqParams = __assign({ id: resourceId }, params);
|
|
2717
|
+
return connector.get('feature_layer.feature.collection', { cache: cache, signal: signal }, reqParams);
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
function prepareNgwFieldsToPropertiesFilter(fields) {
|
|
2721
|
+
var f;
|
|
2722
|
+
var _loop_1 = function () {
|
|
2723
|
+
var field = fields[f];
|
|
2724
|
+
if (isObject$1(field)) {
|
|
2725
|
+
var date = field;
|
|
2726
|
+
if (defined(date.year) && defined(date.month) && defined(date.day)) {
|
|
2727
|
+
var dt_1 = [
|
|
2728
|
+
date.year,
|
|
2729
|
+
date.month - 1,
|
|
2730
|
+
date.day,
|
|
2731
|
+
];
|
|
2732
|
+
if ('hour' in date) {
|
|
2733
|
+
[date.hour, date.minute, date.second].forEach(function (x) {
|
|
2734
|
+
dt_1.push(x);
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
fields[f] = new (Date.bind.apply(Date, __spreadArray([void 0], dt_1, false)))().toISOString();
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
else if (f === 'id' && typeof field === 'string') {
|
|
2741
|
+
fields[f] = field.split(',').map(Number);
|
|
2742
|
+
}
|
|
2743
|
+
};
|
|
2744
|
+
for (f in fields) {
|
|
2745
|
+
_loop_1();
|
|
2746
|
+
}
|
|
2747
|
+
return fields;
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
function fetchNgwLayerItems(options) {
|
|
2751
|
+
var filters = options.filters;
|
|
2752
|
+
if (filters) {
|
|
2753
|
+
return createFeatureFieldFilterQueries(__assign(__assign({}, options), { filters: filters })).then(function (data) {
|
|
2754
|
+
var _a;
|
|
2755
|
+
var clientFilterValidate = (_a = options.clientFilterValidate) !== null && _a !== void 0 ? _a : isFilterWithAnyCase(filters);
|
|
2756
|
+
// Additional client-side filter check
|
|
2757
|
+
if (clientFilterValidate) {
|
|
2758
|
+
data = data.filter(function (y) {
|
|
2759
|
+
var fields = prepareNgwFieldsToPropertiesFilter(__assign(__assign({}, y.fields), { id: y.id }));
|
|
2760
|
+
var result = propertiesFilter(fields, filters);
|
|
2761
|
+
return result;
|
|
2762
|
+
});
|
|
2763
|
+
}
|
|
2764
|
+
return data;
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
else {
|
|
2768
|
+
return fetchNgwLayerItemsRequest(options);
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
function isFilterWithAnyCase(filters) {
|
|
2772
|
+
if (filters[0] === 'any') {
|
|
2773
|
+
return true;
|
|
2774
|
+
}
|
|
2775
|
+
for (var i = 1; i < filters.length; i++) {
|
|
2776
|
+
var p = filters[i];
|
|
2777
|
+
if (isArray(p)) {
|
|
2778
|
+
var deep = isFilterWithAnyCase(p);
|
|
2779
|
+
if (deep) {
|
|
2780
|
+
return true;
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
return false;
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
var NgwProvider = /** @class */ (function (_super) {
|
|
2788
|
+
__extends(NgwProvider, _super);
|
|
2789
|
+
function NgwProvider(options) {
|
|
2790
|
+
var _this = this;
|
|
2791
|
+
var _a;
|
|
2792
|
+
_this = _super.call(this, options) || this;
|
|
2793
|
+
_this.caseInsensitive = true;
|
|
2794
|
+
_this.searchResources = [];
|
|
2795
|
+
_this._abortControllers = [];
|
|
2796
|
+
if (!options.searchUrl && !((_a = options.connectorOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
|
|
2797
|
+
throw new Error('The `searchUrl` of `connectorOptions.baseUrl` are required');
|
|
2798
|
+
}
|
|
2799
|
+
_this.connector =
|
|
2800
|
+
options.connector ||
|
|
2801
|
+
new NgwConnector(__assign({ baseUrl: _this.searchUrl }, options.connectorOptions));
|
|
2802
|
+
_this.searchResources = options.searchResources;
|
|
2803
|
+
return _this;
|
|
2804
|
+
}
|
|
2805
|
+
NgwProvider.prototype.abort = function () {
|
|
2806
|
+
this._abortControllers.forEach(function (a) {
|
|
2807
|
+
a.abort();
|
|
2808
|
+
});
|
|
2809
|
+
this._abortControllers.length = 0;
|
|
2810
|
+
};
|
|
2811
|
+
NgwProvider.prototype.search = function (query) {
|
|
2812
|
+
var _a, _b;
|
|
2813
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
2814
|
+
var signal, _i, _c, config, searchMethod, limit, resourceId, resource, options, request, entries, _loop_1, _d, _e, item, er_1;
|
|
2815
|
+
var _this = this;
|
|
2816
|
+
return __generator(this, function (_f) {
|
|
2817
|
+
switch (_f.label) {
|
|
2818
|
+
case 0:
|
|
2819
|
+
signal = this._makeSignal();
|
|
2820
|
+
_i = 0, _c = this.searchResources;
|
|
2821
|
+
_f.label = 1;
|
|
2822
|
+
case 1:
|
|
2823
|
+
if (!(_i < _c.length)) return [3 /*break*/, 11];
|
|
2824
|
+
config = _c[_i];
|
|
2825
|
+
if (signal.aborted) {
|
|
2826
|
+
return [3 /*break*/, 11];
|
|
2827
|
+
}
|
|
2828
|
+
searchMethod = config.searchMethod;
|
|
2829
|
+
limit = (_a = config.limit) !== null && _a !== void 0 ? _a : NgwProvider.limit;
|
|
2830
|
+
resourceId = (_b = config.id) !== null && _b !== void 0 ? _b : config.resourceId;
|
|
2831
|
+
_f.label = 2;
|
|
2832
|
+
case 2:
|
|
2833
|
+
_f.trys.push([2, 9, , 10]);
|
|
2834
|
+
return [4 /*yield*/, __await(this.connector.getResourceOrFail(resourceId, {
|
|
2835
|
+
cache: true,
|
|
2836
|
+
}))];
|
|
2837
|
+
case 3:
|
|
2838
|
+
resource = _f.sent();
|
|
2839
|
+
options = {
|
|
2840
|
+
connector: this.connector,
|
|
2841
|
+
resourceId: resourceId,
|
|
2842
|
+
signal: signal,
|
|
2843
|
+
limit: limit,
|
|
2844
|
+
};
|
|
2845
|
+
if (searchMethod === 'like') {
|
|
2846
|
+
options.like = query;
|
|
2847
|
+
}
|
|
2848
|
+
else {
|
|
2849
|
+
options.ilike = query;
|
|
2850
|
+
}
|
|
2851
|
+
request = fetchNgwLayerItems(options);
|
|
2852
|
+
return [4 /*yield*/, __await(request)];
|
|
2853
|
+
case 4:
|
|
2854
|
+
entries = _f.sent();
|
|
2855
|
+
_loop_1 = function (item) {
|
|
2856
|
+
return __generator(this, function (_g) {
|
|
2857
|
+
switch (_g.label) {
|
|
2858
|
+
case 0:
|
|
2859
|
+
item.result = function () { return _this.result(item); };
|
|
2860
|
+
return [4 /*yield*/, __await(item)];
|
|
2861
|
+
case 1: return [4 /*yield*/, _g.sent()];
|
|
2862
|
+
case 2:
|
|
2863
|
+
_g.sent();
|
|
2864
|
+
return [2 /*return*/];
|
|
2865
|
+
}
|
|
2866
|
+
});
|
|
2867
|
+
};
|
|
2868
|
+
_d = 0, _e = this._items({
|
|
2869
|
+
entries: entries,
|
|
2870
|
+
query: query,
|
|
2871
|
+
config: config,
|
|
2872
|
+
resourceItem: resource,
|
|
2873
|
+
});
|
|
2874
|
+
_f.label = 5;
|
|
2875
|
+
case 5:
|
|
2876
|
+
if (!(_d < _e.length)) return [3 /*break*/, 8];
|
|
2877
|
+
item = _e[_d];
|
|
2878
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
2879
|
+
case 6:
|
|
2880
|
+
_f.sent();
|
|
2881
|
+
_f.label = 7;
|
|
2882
|
+
case 7:
|
|
2883
|
+
_d++;
|
|
2884
|
+
return [3 /*break*/, 5];
|
|
2885
|
+
case 8: return [3 /*break*/, 10];
|
|
2886
|
+
case 9:
|
|
2887
|
+
er_1 = _f.sent();
|
|
2888
|
+
if (er_1 &&
|
|
2889
|
+
'name' in er_1 &&
|
|
2890
|
+
er_1.name !== 'CancelError') {
|
|
2891
|
+
console.warn(er_1);
|
|
2892
|
+
}
|
|
2893
|
+
return [3 /*break*/, 10];
|
|
2894
|
+
case 10:
|
|
2895
|
+
_i++;
|
|
2896
|
+
return [3 /*break*/, 1];
|
|
2897
|
+
case 11: return [2 /*return*/];
|
|
2898
|
+
}
|
|
2899
|
+
});
|
|
2900
|
+
});
|
|
2901
|
+
};
|
|
2902
|
+
NgwProvider.prototype.result = function (item) {
|
|
2903
|
+
var signal = this._makeSignal();
|
|
2904
|
+
var req = this.connector
|
|
2905
|
+
.get('feature_layer.feature.item_extent', { signal: signal }, {
|
|
2906
|
+
id: item.resourceId,
|
|
2907
|
+
fid: item.featureId,
|
|
2908
|
+
})
|
|
2909
|
+
.then(function (x) {
|
|
2910
|
+
var e = x.extent;
|
|
2911
|
+
return {
|
|
2912
|
+
text: item.text,
|
|
2913
|
+
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],
|
|
2914
|
+
};
|
|
2915
|
+
});
|
|
2916
|
+
return req;
|
|
2917
|
+
};
|
|
2918
|
+
NgwProvider.prototype._makeSignal = function () {
|
|
2919
|
+
var abortController = new AbortController();
|
|
2920
|
+
this._abortControllers.push(abortController);
|
|
2921
|
+
return abortController.signal;
|
|
2922
|
+
};
|
|
2923
|
+
NgwProvider.prototype._items = function (_a) {
|
|
2924
|
+
var _b;
|
|
2925
|
+
var entries = _a.entries, query = _a.query, config = _a.config, resourceItem = _a.resourceItem;
|
|
2926
|
+
var items = [];
|
|
2927
|
+
var labelField = undefined;
|
|
2928
|
+
if (resourceItem.feature_layer) {
|
|
2929
|
+
labelField = (_b = resourceItem.feature_layer.fields.find(function (f) { return f.label_field; })) === null || _b === void 0 ? void 0 : _b.keyname;
|
|
2930
|
+
}
|
|
2931
|
+
var meta = this.searchResources.find(function (x) { var _a; return (_a = x.id) !== null && _a !== void 0 ? _a : x.resourceId === resourceItem.resource.id; });
|
|
2932
|
+
if (meta) {
|
|
2933
|
+
entries.forEach(function (entry) {
|
|
2934
|
+
var text = labelField ? entry.fields[labelField] : entry.id;
|
|
2935
|
+
if (config.renderSearch) {
|
|
2936
|
+
text = config.renderSearch({
|
|
2937
|
+
item: entry,
|
|
2938
|
+
resourceItem: resourceItem,
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
else if (labelField) {
|
|
2942
|
+
text = entry.fields[labelField];
|
|
2943
|
+
}
|
|
2944
|
+
items.push({
|
|
2945
|
+
query: query,
|
|
2946
|
+
text: text,
|
|
2947
|
+
featureId: entry.id,
|
|
2948
|
+
resourceId: resourceItem.resource.id,
|
|
2949
|
+
item: entry,
|
|
2950
|
+
resourceItem: resourceItem,
|
|
2951
|
+
});
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
return items;
|
|
2955
|
+
};
|
|
2956
|
+
NgwProvider.limit = 300;
|
|
2957
|
+
return NgwProvider;
|
|
2547
2958
|
}(BaseProvider));
|
|
2548
2959
|
|
|
2549
|
-
var NominatimProvider = /** @class */ (function (_super) {
|
|
2550
|
-
__extends(NominatimProvider, _super);
|
|
2551
|
-
function NominatimProvider(options) {
|
|
2552
|
-
var _this = _super.call(this, options) || this;
|
|
2553
|
-
_this.searchUrl = 'https://nominatim.openstreetmap.org';
|
|
2554
|
-
_this._requests = [];
|
|
2555
|
-
return _this;
|
|
2556
|
-
}
|
|
2557
|
-
NominatimProvider.prototype.abort = function () {
|
|
2558
|
-
this._requests.forEach(function (x) { return x.cancel(); });
|
|
2559
|
-
this._requests = [];
|
|
2560
|
-
};
|
|
2561
|
-
NominatimProvider.prototype.search = function (val) {
|
|
2562
|
-
return __asyncGenerator(this, arguments, function search_1() {
|
|
2563
|
-
var url, request, items, _loop_1, _i, items_1, i;
|
|
2564
|
-
var _this = this;
|
|
2565
|
-
return __generator(this, function (_a) {
|
|
2566
|
-
switch (_a.label) {
|
|
2567
|
-
case 0:
|
|
2568
|
-
url = fixUrlStr(
|
|
2569
|
-
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
2570
|
-
"".concat(this.searchUrl, "/search?format=geojson&polygon_geojson=1&q=").concat(val));
|
|
2571
|
-
request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2572
|
-
var xhr = new XMLHttpRequest();
|
|
2573
|
-
xhr.open('GET', url, true);
|
|
2574
|
-
xhr.onload = function () {
|
|
2575
|
-
try {
|
|
2576
|
-
var geojson = JSON.parse(xhr.responseText);
|
|
2577
|
-
var features = geojson.features.map(function (x) {
|
|
2578
|
-
return {
|
|
2579
|
-
geom: x,
|
|
2580
|
-
extent: x.bbox,
|
|
2581
|
-
text: x.properties && x.properties.display_name,
|
|
2582
|
-
query: val,
|
|
2583
|
-
};
|
|
2584
|
-
});
|
|
2585
|
-
resolve(features);
|
|
2586
|
-
}
|
|
2587
|
-
catch (er) {
|
|
2588
|
-
reject(er);
|
|
2589
|
-
}
|
|
2590
|
-
};
|
|
2591
|
-
xhr.onerror = function (er) {
|
|
2592
|
-
reject(er);
|
|
2593
|
-
};
|
|
2594
|
-
onCancel(function () {
|
|
2595
|
-
xhr.abort();
|
|
2596
|
-
});
|
|
2597
|
-
xhr.send();
|
|
2598
|
-
}).catch(function (er) {
|
|
2599
|
-
if (er.name === 'CancelError') ;
|
|
2600
|
-
throw er;
|
|
2601
|
-
});
|
|
2602
|
-
this._requests.push(request);
|
|
2603
|
-
return [4 /*yield*/, __await(request)];
|
|
2604
|
-
case 1:
|
|
2605
|
-
items = _a.sent();
|
|
2606
|
-
if (!items) return [3 /*break*/, 5];
|
|
2607
|
-
_loop_1 = function (i) {
|
|
2608
|
-
return __generator(this, function (_b) {
|
|
2609
|
-
switch (_b.label) {
|
|
2610
|
-
case 0:
|
|
2611
|
-
i.result = function () { return _this.result(i); };
|
|
2612
|
-
return [4 /*yield*/, __await(i)];
|
|
2613
|
-
case 1: return [4 /*yield*/, _b.sent()];
|
|
2614
|
-
case 2:
|
|
2615
|
-
_b.sent();
|
|
2616
|
-
return [2 /*return*/];
|
|
2617
|
-
}
|
|
2618
|
-
});
|
|
2619
|
-
};
|
|
2620
|
-
_i = 0, items_1 = items;
|
|
2621
|
-
_a.label = 2;
|
|
2622
|
-
case 2:
|
|
2623
|
-
if (!(_i < items_1.length)) return [3 /*break*/, 5];
|
|
2624
|
-
i = items_1[_i];
|
|
2625
|
-
return [5 /*yield**/, _loop_1(i)];
|
|
2626
|
-
case 3:
|
|
2627
|
-
_a.sent();
|
|
2628
|
-
_a.label = 4;
|
|
2629
|
-
case 4:
|
|
2630
|
-
_i++;
|
|
2631
|
-
return [3 /*break*/, 2];
|
|
2632
|
-
case 5: return [2 /*return*/];
|
|
2633
|
-
}
|
|
2634
|
-
});
|
|
2635
|
-
});
|
|
2636
|
-
};
|
|
2637
|
-
NominatimProvider.prototype.result = function (model) {
|
|
2638
|
-
return CancelablePromise.resolve({
|
|
2639
|
-
text: model.text,
|
|
2640
|
-
extent: model.extent || [],
|
|
2641
|
-
geom: model.geom,
|
|
2642
|
-
});
|
|
2643
|
-
};
|
|
2644
|
-
return NominatimProvider;
|
|
2960
|
+
var NominatimProvider = /** @class */ (function (_super) {
|
|
2961
|
+
__extends(NominatimProvider, _super);
|
|
2962
|
+
function NominatimProvider(options) {
|
|
2963
|
+
var _this = _super.call(this, options) || this;
|
|
2964
|
+
_this.searchUrl = 'https://nominatim.openstreetmap.org';
|
|
2965
|
+
_this._requests = [];
|
|
2966
|
+
return _this;
|
|
2967
|
+
}
|
|
2968
|
+
NominatimProvider.prototype.abort = function () {
|
|
2969
|
+
this._requests.forEach(function (x) { return x.cancel(); });
|
|
2970
|
+
this._requests = [];
|
|
2971
|
+
};
|
|
2972
|
+
NominatimProvider.prototype.search = function (val) {
|
|
2973
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
2974
|
+
var url, request, items, _loop_1, _i, items_1, i;
|
|
2975
|
+
var _this = this;
|
|
2976
|
+
return __generator(this, function (_a) {
|
|
2977
|
+
switch (_a.label) {
|
|
2978
|
+
case 0:
|
|
2979
|
+
url = fixUrlStr(
|
|
2980
|
+
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
2981
|
+
"".concat(this.searchUrl, "/search?format=geojson&polygon_geojson=1&q=").concat(val));
|
|
2982
|
+
request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2983
|
+
var xhr = new XMLHttpRequest();
|
|
2984
|
+
xhr.open('GET', url, true);
|
|
2985
|
+
xhr.onload = function () {
|
|
2986
|
+
try {
|
|
2987
|
+
var geojson = JSON.parse(xhr.responseText);
|
|
2988
|
+
var features = geojson.features.map(function (x) {
|
|
2989
|
+
return {
|
|
2990
|
+
geom: x,
|
|
2991
|
+
extent: x.bbox,
|
|
2992
|
+
text: x.properties && x.properties.display_name,
|
|
2993
|
+
query: val,
|
|
2994
|
+
};
|
|
2995
|
+
});
|
|
2996
|
+
resolve(features);
|
|
2997
|
+
}
|
|
2998
|
+
catch (er) {
|
|
2999
|
+
reject(er);
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
xhr.onerror = function (er) {
|
|
3003
|
+
reject(er);
|
|
3004
|
+
};
|
|
3005
|
+
onCancel(function () {
|
|
3006
|
+
xhr.abort();
|
|
3007
|
+
});
|
|
3008
|
+
xhr.send();
|
|
3009
|
+
}).catch(function (er) {
|
|
3010
|
+
if (er.name === 'CancelError') ;
|
|
3011
|
+
throw er;
|
|
3012
|
+
});
|
|
3013
|
+
this._requests.push(request);
|
|
3014
|
+
return [4 /*yield*/, __await(request)];
|
|
3015
|
+
case 1:
|
|
3016
|
+
items = _a.sent();
|
|
3017
|
+
if (!items) return [3 /*break*/, 5];
|
|
3018
|
+
_loop_1 = function (i) {
|
|
3019
|
+
return __generator(this, function (_b) {
|
|
3020
|
+
switch (_b.label) {
|
|
3021
|
+
case 0:
|
|
3022
|
+
i.result = function () { return _this.result(i); };
|
|
3023
|
+
return [4 /*yield*/, __await(i)];
|
|
3024
|
+
case 1: return [4 /*yield*/, _b.sent()];
|
|
3025
|
+
case 2:
|
|
3026
|
+
_b.sent();
|
|
3027
|
+
return [2 /*return*/];
|
|
3028
|
+
}
|
|
3029
|
+
});
|
|
3030
|
+
};
|
|
3031
|
+
_i = 0, items_1 = items;
|
|
3032
|
+
_a.label = 2;
|
|
3033
|
+
case 2:
|
|
3034
|
+
if (!(_i < items_1.length)) return [3 /*break*/, 5];
|
|
3035
|
+
i = items_1[_i];
|
|
3036
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
3037
|
+
case 3:
|
|
3038
|
+
_a.sent();
|
|
3039
|
+
_a.label = 4;
|
|
3040
|
+
case 4:
|
|
3041
|
+
_i++;
|
|
3042
|
+
return [3 /*break*/, 2];
|
|
3043
|
+
case 5: return [2 /*return*/];
|
|
3044
|
+
}
|
|
3045
|
+
});
|
|
3046
|
+
});
|
|
3047
|
+
};
|
|
3048
|
+
NominatimProvider.prototype.result = function (model) {
|
|
3049
|
+
return CancelablePromise.resolve({
|
|
3050
|
+
text: model.text,
|
|
3051
|
+
extent: model.extent || [],
|
|
3052
|
+
geom: model.geom,
|
|
3053
|
+
});
|
|
3054
|
+
};
|
|
3055
|
+
return NominatimProvider;
|
|
2645
3056
|
}(BaseProvider));
|
|
2646
3057
|
|
|
2647
|
-
|
|
2648
|
-
|
|
3058
|
+
/**
|
|
3059
|
+
* Modern geocoder on async generators. May use different data providers.
|
|
3060
|
+
*
|
|
3061
|
+
* @packageDocumentation
|
|
3062
|
+
* @module geocoder
|
|
3063
|
+
*/
|
|
3064
|
+
function create(options) {
|
|
3065
|
+
return new Geocoder(options);
|
|
2649
3066
|
}
|
|
2650
3067
|
|
|
2651
3068
|
exports.BaseProvider = BaseProvider;
|