@nextgis/ngw-map 1.16.1 → 1.16.2

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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-map; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.16.2; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-map; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-map; version: 1.16.2; author: NextGIS */
2
2
  /******************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -1313,6 +1313,11 @@ function objectRemoveEmpty(obj) {
1313
1313
  return newObj;
1314
1314
  }
1315
1315
 
1316
+ function round(val, toFixed) {
1317
+ var n = toFixed ? Number('1e+' + toFixed) : 1;
1318
+ return Math.round((val + Number.EPSILON) * n) / n;
1319
+ }
1320
+
1316
1321
  function isObject$1(val) {
1317
1322
  return Object.prototype.toString.call(val) === '[object Object]';
1318
1323
  }
@@ -4219,6 +4224,65 @@ function template(str, data) {
4219
4224
  });
4220
4225
  }
4221
4226
 
4227
+ function apiRequest(opt) {
4228
+ var params = opt.params;
4229
+ return new CancelablePromise(function (resolve, reject) {
4230
+ opt.connector
4231
+ .connect()
4232
+ .then(function (apiItems) {
4233
+ var apiItem = apiItems && apiItems[opt.name];
4234
+ if (apiItem) {
4235
+ apiItem = __spreadArray([], apiItem, true);
4236
+ var url = apiItem.shift();
4237
+ if (apiItem.length) {
4238
+ var replaceParams = {};
4239
+ for (var fry = 0; fry < apiItem.length; fry++) {
4240
+ var arg = apiItem[fry];
4241
+ replaceParams[fry] = '{' + arg + '}';
4242
+ if (params[arg] === undefined) {
4243
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
4244
+ }
4245
+ }
4246
+ if (url) {
4247
+ url = template(url, replaceParams);
4248
+ }
4249
+ }
4250
+ // Transfer part of the parameters from `params` to the URL string
4251
+ if (params) {
4252
+ var paramArray_1 = [];
4253
+ var paramList = params.paramList;
4254
+ if (Array.isArray(paramList)) {
4255
+ delete params.paramList;
4256
+ paramList.forEach(function (x) {
4257
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
4258
+ });
4259
+ }
4260
+ for (var p in params) {
4261
+ if (apiItem.indexOf(p) === -1) {
4262
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
4263
+ }
4264
+ }
4265
+ if (paramArray_1.length) {
4266
+ url = url + '?' + paramArray_1.join('&');
4267
+ }
4268
+ }
4269
+ if (url) {
4270
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
4271
+ }
4272
+ else {
4273
+ reject(new Error('request url is not set'));
4274
+ }
4275
+ }
4276
+ else {
4277
+ resolve(undefined);
4278
+ }
4279
+ })
4280
+ .catch(function (er) {
4281
+ reject(er);
4282
+ });
4283
+ });
4284
+ }
4285
+
4222
4286
  /**
4223
4287
  * Thrown when ...
4224
4288
  */
@@ -4584,65 +4648,6 @@ var ResourcesControl = /** @class */ (function () {
4584
4648
  return ResourcesControl;
4585
4649
  }());
4586
4650
 
4587
- function apiRequest(opt) {
4588
- var params = opt.params;
4589
- return new CancelablePromise(function (resolve, reject) {
4590
- opt.connector
4591
- .connect()
4592
- .then(function (apiItems) {
4593
- var apiItem = apiItems && apiItems[opt.name];
4594
- if (apiItem) {
4595
- apiItem = __spreadArray([], apiItem, true);
4596
- var url = apiItem.shift();
4597
- if (apiItem.length) {
4598
- var replaceParams = {};
4599
- for (var fry = 0; fry < apiItem.length; fry++) {
4600
- var arg = apiItem[fry];
4601
- replaceParams[fry] = '{' + arg + '}';
4602
- if (params[arg] === undefined) {
4603
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
4604
- }
4605
- }
4606
- if (url) {
4607
- url = template(url, replaceParams);
4608
- }
4609
- }
4610
- // Transfer part of the parameters from `params` to the URL string
4611
- if (params) {
4612
- var paramArray_1 = [];
4613
- var paramList = params.paramList;
4614
- if (Array.isArray(paramList)) {
4615
- delete params.paramList;
4616
- paramList.forEach(function (x) {
4617
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
4618
- });
4619
- }
4620
- for (var p in params) {
4621
- if (apiItem.indexOf(p) === -1) {
4622
- paramArray_1.push("".concat(p, "=").concat(params[p]));
4623
- }
4624
- }
4625
- if (paramArray_1.length) {
4626
- url = url + '?' + paramArray_1.join('&');
4627
- }
4628
- }
4629
- if (url) {
4630
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
4631
- }
4632
- else {
4633
- reject(new Error('request url is not set'));
4634
- }
4635
- }
4636
- else {
4637
- resolve(undefined);
4638
- }
4639
- })
4640
- .catch(function (er) {
4641
- reject(er);
4642
- });
4643
- });
4644
- }
4645
-
4646
4651
  var ID$1 = 0;
4647
4652
  var NgwConnector$1 = /** @class */ (function () {
4648
4653
  function NgwConnector(options) {
@@ -4713,9 +4718,9 @@ var NgwConnector$1 = /** @class */ (function () {
4713
4718
  if (auth) {
4714
4719
  var login = auth.login, password = auth.password;
4715
4720
  if (login && password) {
4716
- return _this.getUserInfo({ login: login, password: password })
4721
+ return _this._login({ login: login, password: password })
4717
4722
  .then(function () {
4718
- makeQuery();
4723
+ return makeQuery();
4719
4724
  })
4720
4725
  .catch(function (er) { return reject(er); });
4721
4726
  }
@@ -4733,10 +4738,10 @@ var NgwConnector$1 = /** @class */ (function () {
4733
4738
  * Quick way to change NextGIS Web user.
4734
4739
  * @param credentials - New user credentials
4735
4740
  */
4736
- NgwConnector.prototype.login = function (credentials) {
4741
+ NgwConnector.prototype.login = function (credentials, options) {
4737
4742
  this.logout();
4738
4743
  addConnector(this);
4739
- return this.getUserInfo(credentials);
4744
+ return this._login(credentials, options);
4740
4745
  };
4741
4746
  /**
4742
4747
  * Disconnecting a user. Aborting all current requests
@@ -4749,29 +4754,16 @@ var NgwConnector$1 = /** @class */ (function () {
4749
4754
  this.emitter.emit('logout');
4750
4755
  this.resources.cache.clean();
4751
4756
  };
4752
- NgwConnector.prototype.getUserInfo = function (credentials) {
4753
- var _this = this;
4757
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
4754
4758
  if (this.user && this.user.id) {
4755
4759
  return CancelablePromise.resolve(this.user);
4756
4760
  }
4757
4761
  if (credentials) {
4758
4762
  this.options.auth = credentials;
4759
4763
  }
4760
- var options = {
4761
- headers: this.getAuthorizationHeaders(credentials),
4762
- // withCredentials: true
4763
- };
4764
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
4764
4765
  // Do not use apiRequest('auth.current_user') to avoid circular-references
4765
- return this.makeQuery('/api/component/auth/current_user', {}, options)
4766
- .then(function (data) {
4767
- _this.user = data;
4768
- _this.emitter.emit('login', data);
4769
- return data;
4770
- })
4771
- .catch(function (er) {
4772
- _this.emitter.emit('login:error', er);
4773
- throw er;
4774
- });
4766
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
4775
4767
  };
4776
4768
  /**
4777
4769
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -4837,6 +4829,7 @@ var NgwConnector$1 = /** @class */ (function () {
4837
4829
  */
4838
4830
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
4839
4831
  var _this = this;
4832
+ var _a;
4840
4833
  if (params_ === void 0) { params_ = {}; }
4841
4834
  if (requestOptions === void 0) { requestOptions = {}; }
4842
4835
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -4851,7 +4844,7 @@ var NgwConnector$1 = /** @class */ (function () {
4851
4844
  withCredentials: withCredentials,
4852
4845
  responseType: responseType,
4853
4846
  baseUrl: this.options.baseUrl,
4854
- auth: this.options.auth,
4847
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
4855
4848
  })));
4856
4849
  }
4857
4850
  return makeApiRequest();
@@ -5060,6 +5053,19 @@ var NgwConnector$1 = /** @class */ (function () {
5060
5053
  this.activeRequests.push(request);
5061
5054
  return request;
5062
5055
  };
5056
+ NgwConnector.prototype._login = function (credentials, options) {
5057
+ var _this = this;
5058
+ return this.getUserInfo(credentials, options)
5059
+ .then(function (data) {
5060
+ _this.user = data;
5061
+ _this.emitter.emit('login', data);
5062
+ return data;
5063
+ })
5064
+ .catch(function (er) {
5065
+ _this.emitter.emit('login:error', er);
5066
+ throw er;
5067
+ });
5068
+ };
5063
5069
  NgwConnector.prototype._cleanActiveRequests = function (request) {
5064
5070
  var activeRequestIndex = this.activeRequests.indexOf(request);
5065
5071
  if (activeRequestIndex !== -1) {
@@ -5403,14 +5409,14 @@ function getQueries(opt, _queries, _parentAllParams) {
5403
5409
  function createWktFromCoordArray(coord) {
5404
5410
  var polygon = coord.map(function (_a) {
5405
5411
  var lng = _a[0], lat = _a[1];
5406
- var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
5412
+ var _b = degrees2meters(lng, lat).map(function (c) { return round(c); }), x = _b[0], y = _b[1];
5407
5413
  return x + ' ' + y;
5408
5414
  });
5409
5415
  return "POLYGON((".concat(polygon.join(', '), "))");
5410
5416
  }
5411
5417
  function fetchNgwLayerItemsRequest(options) {
5412
5418
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
5413
- var limit = options.limit, cache = options.cache, signal = options.signal, offset = options.offset, orderBy = options.orderBy, paramList = options.paramList, connector = options.connector, intersects = options.intersects, resourceId = options.resourceId;
5419
+ 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;
5414
5420
  if (limit) {
5415
5421
  if (limit !== Number.POSITIVE_INFINITY) {
5416
5422
  params.limit = limit;
@@ -5423,6 +5429,9 @@ function fetchNgwLayerItemsRequest(options) {
5423
5429
  if (offset) {
5424
5430
  params.offset = offset;
5425
5431
  }
5432
+ if (geomFormat) {
5433
+ params.geom_format = geomFormat;
5434
+ }
5426
5435
  updateItemRequestParam(params, options);
5427
5436
  if (orderBy) {
5428
5437
  params.order_by = orderBy.join(',');