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