@nextgis/ngw-leaflet 1.16.1 → 1.16.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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-leaflet; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.16.3; author: NextGIS */
2
2
  import 'leaflet/dist/leaflet.css';
3
3
  import { Icon } from 'leaflet';
4
4
  import { NgwMap } from '@nextgis/ngw-map';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-leaflet; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.16.3; author: NextGIS */
2
2
  var NgwLeaflet = (function () {
3
3
  'use strict';
4
4
 
@@ -15407,6 +15407,11 @@ var NgwLeaflet = (function () {
15407
15407
  return newObj;
15408
15408
  }
15409
15409
 
15410
+ function round(val, toFixed) {
15411
+ var n = toFixed ? Number('1e+' + toFixed) : 1;
15412
+ return Math.round((val + Number.EPSILON) * n) / n;
15413
+ }
15414
+
15410
15415
  function isObject$1(val) {
15411
15416
  return Object.prototype.toString.call(val) === '[object Object]';
15412
15417
  }
@@ -18295,6 +18300,65 @@ var NgwLeaflet = (function () {
18295
18300
  });
18296
18301
  }
18297
18302
 
18303
+ function apiRequest(opt) {
18304
+ var params = opt.params;
18305
+ return new CancelablePromise(function (resolve, reject) {
18306
+ opt.connector
18307
+ .connect()
18308
+ .then(function (apiItems) {
18309
+ var apiItem = apiItems && apiItems[opt.name];
18310
+ if (apiItem) {
18311
+ apiItem = __spreadArray([], apiItem, true);
18312
+ var url = apiItem.shift();
18313
+ if (apiItem.length) {
18314
+ var replaceParams = {};
18315
+ for (var fry = 0; fry < apiItem.length; fry++) {
18316
+ var arg = apiItem[fry];
18317
+ replaceParams[fry] = '{' + arg + '}';
18318
+ if (params[arg] === undefined) {
18319
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
18320
+ }
18321
+ }
18322
+ if (url) {
18323
+ url = template(url, replaceParams);
18324
+ }
18325
+ }
18326
+ // Transfer part of the parameters from `params` to the URL string
18327
+ if (params) {
18328
+ var paramArray_1 = [];
18329
+ var paramList = params.paramList;
18330
+ if (Array.isArray(paramList)) {
18331
+ delete params.paramList;
18332
+ paramList.forEach(function (x) {
18333
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
18334
+ });
18335
+ }
18336
+ for (var p in params) {
18337
+ if (apiItem.indexOf(p) === -1) {
18338
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
18339
+ }
18340
+ }
18341
+ if (paramArray_1.length) {
18342
+ url = url + '?' + paramArray_1.join('&');
18343
+ }
18344
+ }
18345
+ if (url) {
18346
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
18347
+ }
18348
+ else {
18349
+ reject(new Error('request url is not set'));
18350
+ }
18351
+ }
18352
+ else {
18353
+ resolve(undefined);
18354
+ }
18355
+ })
18356
+ .catch(function (er) {
18357
+ reject(er);
18358
+ });
18359
+ });
18360
+ }
18361
+
18298
18362
  /**
18299
18363
  * Thrown when ...
18300
18364
  */
@@ -18660,65 +18724,6 @@ var NgwLeaflet = (function () {
18660
18724
  return ResourcesControl;
18661
18725
  }());
18662
18726
 
18663
- function apiRequest(opt) {
18664
- var params = opt.params;
18665
- return new CancelablePromise(function (resolve, reject) {
18666
- opt.connector
18667
- .connect()
18668
- .then(function (apiItems) {
18669
- var apiItem = apiItems && apiItems[opt.name];
18670
- if (apiItem) {
18671
- apiItem = __spreadArray([], apiItem, true);
18672
- var url = apiItem.shift();
18673
- if (apiItem.length) {
18674
- var replaceParams = {};
18675
- for (var fry = 0; fry < apiItem.length; fry++) {
18676
- var arg = apiItem[fry];
18677
- replaceParams[fry] = '{' + arg + '}';
18678
- if (params[arg] === undefined) {
18679
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
18680
- }
18681
- }
18682
- if (url) {
18683
- url = template(url, replaceParams);
18684
- }
18685
- }
18686
- // Transfer part of the parameters from `params` to the URL string
18687
- if (params) {
18688
- var paramArray_1 = [];
18689
- var paramList = params.paramList;
18690
- if (Array.isArray(paramList)) {
18691
- delete params.paramList;
18692
- paramList.forEach(function (x) {
18693
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
18694
- });
18695
- }
18696
- for (var p in params) {
18697
- if (apiItem.indexOf(p) === -1) {
18698
- paramArray_1.push("".concat(p, "=").concat(params[p]));
18699
- }
18700
- }
18701
- if (paramArray_1.length) {
18702
- url = url + '?' + paramArray_1.join('&');
18703
- }
18704
- }
18705
- if (url) {
18706
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
18707
- }
18708
- else {
18709
- reject(new Error('request url is not set'));
18710
- }
18711
- }
18712
- else {
18713
- resolve(undefined);
18714
- }
18715
- })
18716
- .catch(function (er) {
18717
- reject(er);
18718
- });
18719
- });
18720
- }
18721
-
18722
18727
  var ID$1 = 0;
18723
18728
  var NgwConnector = /** @class */ (function () {
18724
18729
  function NgwConnector(options) {
@@ -18789,9 +18794,9 @@ var NgwLeaflet = (function () {
18789
18794
  if (auth) {
18790
18795
  var login = auth.login, password = auth.password;
18791
18796
  if (login && password) {
18792
- return _this.getUserInfo({ login: login, password: password })
18797
+ return _this._login({ login: login, password: password })
18793
18798
  .then(function () {
18794
- makeQuery();
18799
+ return makeQuery();
18795
18800
  })
18796
18801
  .catch(function (er) { return reject(er); });
18797
18802
  }
@@ -18809,10 +18814,10 @@ var NgwLeaflet = (function () {
18809
18814
  * Quick way to change NextGIS Web user.
18810
18815
  * @param credentials - New user credentials
18811
18816
  */
18812
- NgwConnector.prototype.login = function (credentials) {
18817
+ NgwConnector.prototype.login = function (credentials, options) {
18813
18818
  this.logout();
18814
18819
  addConnector(this);
18815
- return this.getUserInfo(credentials);
18820
+ return this._login(credentials, options);
18816
18821
  };
18817
18822
  /**
18818
18823
  * Disconnecting a user. Aborting all current requests
@@ -18825,29 +18830,16 @@ var NgwLeaflet = (function () {
18825
18830
  this.emitter.emit('logout');
18826
18831
  this.resources.cache.clean();
18827
18832
  };
18828
- NgwConnector.prototype.getUserInfo = function (credentials) {
18829
- var _this = this;
18833
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
18830
18834
  if (this.user && this.user.id) {
18831
18835
  return CancelablePromise.resolve(this.user);
18832
18836
  }
18833
18837
  if (credentials) {
18834
18838
  this.options.auth = credentials;
18835
18839
  }
18836
- var options = {
18837
- headers: this.getAuthorizationHeaders(credentials),
18838
- // withCredentials: true
18839
- };
18840
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
18840
18841
  // Do not use apiRequest('auth.current_user') to avoid circular-references
18841
- return this.makeQuery('/api/component/auth/current_user', {}, options)
18842
- .then(function (data) {
18843
- _this.user = data;
18844
- _this.emitter.emit('login', data);
18845
- return data;
18846
- })
18847
- .catch(function (er) {
18848
- _this.emitter.emit('login:error', er);
18849
- throw er;
18850
- });
18842
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
18851
18843
  };
18852
18844
  /**
18853
18845
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -18913,6 +18905,7 @@ var NgwLeaflet = (function () {
18913
18905
  */
18914
18906
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
18915
18907
  var _this = this;
18908
+ var _a;
18916
18909
  if (params_ === void 0) { params_ = {}; }
18917
18910
  if (requestOptions === void 0) { requestOptions = {}; }
18918
18911
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -18927,7 +18920,7 @@ var NgwLeaflet = (function () {
18927
18920
  withCredentials: withCredentials,
18928
18921
  responseType: responseType,
18929
18922
  baseUrl: this.options.baseUrl,
18930
- auth: this.options.auth,
18923
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
18931
18924
  })));
18932
18925
  }
18933
18926
  return makeApiRequest();
@@ -19136,6 +19129,19 @@ var NgwLeaflet = (function () {
19136
19129
  this.activeRequests.push(request);
19137
19130
  return request;
19138
19131
  };
19132
+ NgwConnector.prototype._login = function (credentials, options) {
19133
+ var _this = this;
19134
+ return this.getUserInfo(credentials, options)
19135
+ .then(function (data) {
19136
+ _this.user = data;
19137
+ _this.emitter.emit('login', data);
19138
+ return data;
19139
+ })
19140
+ .catch(function (er) {
19141
+ _this.emitter.emit('login:error', er);
19142
+ throw er;
19143
+ });
19144
+ };
19139
19145
  NgwConnector.prototype._cleanActiveRequests = function (request) {
19140
19146
  var activeRequestIndex = this.activeRequests.indexOf(request);
19141
19147
  if (activeRequestIndex !== -1) {
@@ -19467,14 +19473,14 @@ var NgwLeaflet = (function () {
19467
19473
  function createWktFromCoordArray(coord) {
19468
19474
  var polygon = coord.map(function (_a) {
19469
19475
  var lng = _a[0], lat = _a[1];
19470
- var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
19476
+ var _b = degrees2meters(lng, lat).map(function (c) { return round(c); }), x = _b[0], y = _b[1];
19471
19477
  return x + ' ' + y;
19472
19478
  });
19473
19479
  return "POLYGON((".concat(polygon.join(', '), "))");
19474
19480
  }
19475
19481
  function fetchNgwLayerItemsRequest(options) {
19476
19482
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
19477
- 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;
19483
+ 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;
19478
19484
  if (limit) {
19479
19485
  if (limit !== Number.POSITIVE_INFINITY) {
19480
19486
  params.limit = limit;
@@ -19487,6 +19493,9 @@ var NgwLeaflet = (function () {
19487
19493
  if (offset) {
19488
19494
  params.offset = offset;
19489
19495
  }
19496
+ if (geomFormat) {
19497
+ params.geom_format = geomFormat;
19498
+ }
19490
19499
  updateItemRequestParam(params, options);
19491
19500
  if (orderBy) {
19492
19501
  params.order_by = orderBy.join(',');
@@ -21704,6 +21713,7 @@ var NgwLeaflet = (function () {
21704
21713
  'basemap_layer',
21705
21714
  'vector_layer',
21706
21715
  'raster_layer',
21716
+ 'postgis_layer',
21707
21717
  'webmap',
21708
21718
  // in tms branch
21709
21719
  'tmsclient_layer',
@@ -21721,7 +21731,6 @@ var NgwLeaflet = (function () {
21721
21731
  childrenStyles = _b.sent();
21722
21732
  firstStyle = childrenStyles && childrenStyles[0];
21723
21733
  if (firstStyle) {
21724
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
21725
21734
  return [2 /*return*/, createAsyncAdapter(__assign(__assign({}, layerOptions), { resource: firstStyle.resource.id }), webMap, connector)];
21726
21735
  }
21727
21736
  return [2 /*return*/];
@@ -21766,7 +21775,7 @@ var NgwLeaflet = (function () {
21766
21775
  adapter = createWebMapAdapter(adapterOptions);
21767
21776
  return [3 /*break*/, 11];
21768
21777
  case 5:
21769
- if (!(cls === 'vector_layer')) return [3 /*break*/, 6];
21778
+ if (!(cls === 'vector_layer' || cls === 'postgis_layer')) return [3 /*break*/, 6];
21770
21779
  type = item.vector_layer &&
21771
21780
  vectorLayerGeomToPaintTypeAlias[item.vector_layer.geometry_type];
21772
21781
  adapterOptions_ = adapterOptions.layerOptions.adapterOptions || {};