@nextgis/ngw-leaflet 1.16.0 → 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-leaflet; version: 1.16.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.16.2; author: NextGIS */
2
2
  /******************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -15263,7 +15263,9 @@ function getBoundsFeature(b) {
15263
15263
 
15264
15264
  var d2r = Math.PI / 180; // degrees to radians
15265
15265
  var r2d = 180 / Math.PI; // radians to degrees
15266
- function getCirclePolygonCoordinates(lng, lat, radius, points) {
15266
+ function getCirclePolygonCoordinates(lng, lat,
15267
+ /** In kilometers */
15268
+ radius, points) {
15267
15269
  if (radius === void 0) { radius = 10; }
15268
15270
  if (points === void 0) { points = 6; }
15269
15271
  // find the radius in lat/lon
@@ -15313,6 +15315,14 @@ function isLngLatBoundsArray(array) {
15313
15315
  array.every(function (x) { return typeof x === 'number'; }));
15314
15316
  }
15315
15317
 
15318
+ function getIdentifyRadius(center, zoom, pixelRadius) {
15319
+ pixelRadius = pixelRadius !== null && pixelRadius !== void 0 ? pixelRadius : 10;
15320
+ var metresPerPixel = (40075016.686 * Math.abs(Math.cos((center[1] * 180) / Math.PI))) /
15321
+ Math.pow(2, zoom + 8);
15322
+ var radius = pixelRadius * metresPerPixel * 0.0005;
15323
+ return radius;
15324
+ }
15325
+
15316
15326
  /**
15317
15327
  * Copy the values of all of the enumerable own properties from one or more source objects to a
15318
15328
  * target object. Returns the target object.
@@ -15394,6 +15404,11 @@ function objectRemoveEmpty(obj) {
15394
15404
  return newObj;
15395
15405
  }
15396
15406
 
15407
+ function round(val, toFixed) {
15408
+ var n = toFixed ? Number('1e+' + toFixed) : 1;
15409
+ return Math.round((val + Number.EPSILON) * n) / n;
15410
+ }
15411
+
15397
15412
  function isObject$1(val) {
15398
15413
  return Object.prototype.toString.call(val) === '[object Object]';
15399
15414
  }
@@ -18282,6 +18297,65 @@ function template(str, data) {
18282
18297
  });
18283
18298
  }
18284
18299
 
18300
+ function apiRequest(opt) {
18301
+ var params = opt.params;
18302
+ return new CancelablePromise(function (resolve, reject) {
18303
+ opt.connector
18304
+ .connect()
18305
+ .then(function (apiItems) {
18306
+ var apiItem = apiItems && apiItems[opt.name];
18307
+ if (apiItem) {
18308
+ apiItem = __spreadArray([], apiItem, true);
18309
+ var url = apiItem.shift();
18310
+ if (apiItem.length) {
18311
+ var replaceParams = {};
18312
+ for (var fry = 0; fry < apiItem.length; fry++) {
18313
+ var arg = apiItem[fry];
18314
+ replaceParams[fry] = '{' + arg + '}';
18315
+ if (params[arg] === undefined) {
18316
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
18317
+ }
18318
+ }
18319
+ if (url) {
18320
+ url = template(url, replaceParams);
18321
+ }
18322
+ }
18323
+ // Transfer part of the parameters from `params` to the URL string
18324
+ if (params) {
18325
+ var paramArray_1 = [];
18326
+ var paramList = params.paramList;
18327
+ if (Array.isArray(paramList)) {
18328
+ delete params.paramList;
18329
+ paramList.forEach(function (x) {
18330
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
18331
+ });
18332
+ }
18333
+ for (var p in params) {
18334
+ if (apiItem.indexOf(p) === -1) {
18335
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
18336
+ }
18337
+ }
18338
+ if (paramArray_1.length) {
18339
+ url = url + '?' + paramArray_1.join('&');
18340
+ }
18341
+ }
18342
+ if (url) {
18343
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
18344
+ }
18345
+ else {
18346
+ reject(new Error('request url is not set'));
18347
+ }
18348
+ }
18349
+ else {
18350
+ resolve(undefined);
18351
+ }
18352
+ })
18353
+ .catch(function (er) {
18354
+ reject(er);
18355
+ });
18356
+ });
18357
+ }
18358
+
18285
18359
  /**
18286
18360
  * Thrown when ...
18287
18361
  */
@@ -18647,65 +18721,6 @@ var ResourcesControl = /** @class */ (function () {
18647
18721
  return ResourcesControl;
18648
18722
  }());
18649
18723
 
18650
- function apiRequest(opt) {
18651
- var params = opt.params;
18652
- return new CancelablePromise(function (resolve, reject) {
18653
- opt.connector
18654
- .connect()
18655
- .then(function (apiItems) {
18656
- var apiItem = apiItems && apiItems[opt.name];
18657
- if (apiItem) {
18658
- apiItem = __spreadArray([], apiItem, true);
18659
- var url = apiItem.shift();
18660
- if (apiItem.length) {
18661
- var replaceParams = {};
18662
- for (var fry = 0; fry < apiItem.length; fry++) {
18663
- var arg = apiItem[fry];
18664
- replaceParams[fry] = '{' + arg + '}';
18665
- if (params[arg] === undefined) {
18666
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
18667
- }
18668
- }
18669
- if (url) {
18670
- url = template(url, replaceParams);
18671
- }
18672
- }
18673
- // Transfer part of the parameters from `params` to the URL string
18674
- if (params) {
18675
- var paramArray_1 = [];
18676
- var paramList = params.paramList;
18677
- if (Array.isArray(paramList)) {
18678
- delete params.paramList;
18679
- paramList.forEach(function (x) {
18680
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
18681
- });
18682
- }
18683
- for (var p in params) {
18684
- if (apiItem.indexOf(p) === -1) {
18685
- paramArray_1.push("".concat(p, "=").concat(params[p]));
18686
- }
18687
- }
18688
- if (paramArray_1.length) {
18689
- url = url + '?' + paramArray_1.join('&');
18690
- }
18691
- }
18692
- if (url) {
18693
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
18694
- }
18695
- else {
18696
- reject(new Error('request url is not set'));
18697
- }
18698
- }
18699
- else {
18700
- resolve(undefined);
18701
- }
18702
- })
18703
- .catch(function (er) {
18704
- reject(er);
18705
- });
18706
- });
18707
- }
18708
-
18709
18724
  var ID$1 = 0;
18710
18725
  var NgwConnector = /** @class */ (function () {
18711
18726
  function NgwConnector(options) {
@@ -18776,9 +18791,9 @@ var NgwConnector = /** @class */ (function () {
18776
18791
  if (auth) {
18777
18792
  var login = auth.login, password = auth.password;
18778
18793
  if (login && password) {
18779
- return _this.getUserInfo({ login: login, password: password })
18794
+ return _this._login({ login: login, password: password })
18780
18795
  .then(function () {
18781
- makeQuery();
18796
+ return makeQuery();
18782
18797
  })
18783
18798
  .catch(function (er) { return reject(er); });
18784
18799
  }
@@ -18796,10 +18811,10 @@ var NgwConnector = /** @class */ (function () {
18796
18811
  * Quick way to change NextGIS Web user.
18797
18812
  * @param credentials - New user credentials
18798
18813
  */
18799
- NgwConnector.prototype.login = function (credentials) {
18814
+ NgwConnector.prototype.login = function (credentials, options) {
18800
18815
  this.logout();
18801
18816
  addConnector(this);
18802
- return this.getUserInfo(credentials);
18817
+ return this._login(credentials, options);
18803
18818
  };
18804
18819
  /**
18805
18820
  * Disconnecting a user. Aborting all current requests
@@ -18812,29 +18827,16 @@ var NgwConnector = /** @class */ (function () {
18812
18827
  this.emitter.emit('logout');
18813
18828
  this.resources.cache.clean();
18814
18829
  };
18815
- NgwConnector.prototype.getUserInfo = function (credentials) {
18816
- var _this = this;
18830
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
18817
18831
  if (this.user && this.user.id) {
18818
18832
  return CancelablePromise.resolve(this.user);
18819
18833
  }
18820
18834
  if (credentials) {
18821
18835
  this.options.auth = credentials;
18822
18836
  }
18823
- var options = {
18824
- headers: this.getAuthorizationHeaders(credentials),
18825
- // withCredentials: true
18826
- };
18837
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
18827
18838
  // Do not use apiRequest('auth.current_user') to avoid circular-references
18828
- return this.makeQuery('/api/component/auth/current_user', {}, options)
18829
- .then(function (data) {
18830
- _this.user = data;
18831
- _this.emitter.emit('login', data);
18832
- return data;
18833
- })
18834
- .catch(function (er) {
18835
- _this.emitter.emit('login:error', er);
18836
- throw er;
18837
- });
18839
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
18838
18840
  };
18839
18841
  /**
18840
18842
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -18900,6 +18902,7 @@ var NgwConnector = /** @class */ (function () {
18900
18902
  */
18901
18903
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
18902
18904
  var _this = this;
18905
+ var _a;
18903
18906
  if (params_ === void 0) { params_ = {}; }
18904
18907
  if (requestOptions === void 0) { requestOptions = {}; }
18905
18908
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -18914,7 +18917,7 @@ var NgwConnector = /** @class */ (function () {
18914
18917
  withCredentials: withCredentials,
18915
18918
  responseType: responseType,
18916
18919
  baseUrl: this.options.baseUrl,
18917
- auth: this.options.auth,
18920
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
18918
18921
  })));
18919
18922
  }
18920
18923
  return makeApiRequest();
@@ -19123,6 +19126,19 @@ var NgwConnector = /** @class */ (function () {
19123
19126
  this.activeRequests.push(request);
19124
19127
  return request;
19125
19128
  };
19129
+ NgwConnector.prototype._login = function (credentials, options) {
19130
+ var _this = this;
19131
+ return this.getUserInfo(credentials, options)
19132
+ .then(function (data) {
19133
+ _this.user = data;
19134
+ _this.emitter.emit('login', data);
19135
+ return data;
19136
+ })
19137
+ .catch(function (er) {
19138
+ _this.emitter.emit('login:error', er);
19139
+ throw er;
19140
+ });
19141
+ };
19126
19142
  NgwConnector.prototype._cleanActiveRequests = function (request) {
19127
19143
  var activeRequestIndex = this.activeRequests.indexOf(request);
19128
19144
  if (activeRequestIndex !== -1) {
@@ -19454,14 +19470,14 @@ function getQueries(opt, _queries, _parentAllParams) {
19454
19470
  function createWktFromCoordArray(coord) {
19455
19471
  var polygon = coord.map(function (_a) {
19456
19472
  var lng = _a[0], lat = _a[1];
19457
- var _b = degrees2meters(lng, lat), x = _b[0], y = _b[1];
19473
+ var _b = degrees2meters(lng, lat).map(function (c) { return round(c); }), x = _b[0], y = _b[1];
19458
19474
  return x + ' ' + y;
19459
19475
  });
19460
19476
  return "POLYGON((".concat(polygon.join(', '), "))");
19461
19477
  }
19462
19478
  function fetchNgwLayerItemsRequest(options) {
19463
19479
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
19464
- 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;
19480
+ 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;
19465
19481
  if (limit) {
19466
19482
  if (limit !== Number.POSITIVE_INFINITY) {
19467
19483
  params.limit = limit;
@@ -19474,6 +19490,9 @@ function fetchNgwLayerItemsRequest(options) {
19474
19490
  if (offset) {
19475
19491
  params.offset = offset;
19476
19492
  }
19493
+ if (geomFormat) {
19494
+ params.geom_format = geomFormat;
19495
+ }
19477
19496
  updateItemRequestParam(params, options);
19478
19497
  if (orderBy) {
19479
19498
  params.order_by = orderBy.join(',');
@@ -22380,14 +22399,6 @@ function prepareWebMapOptions(options) {
22380
22399
  return options;
22381
22400
  }
22382
22401
 
22383
- function getIdentifyRadius(center, zoom, pixelRadius) {
22384
- pixelRadius = pixelRadius !== null && pixelRadius !== void 0 ? pixelRadius : 10;
22385
- var metresPerPixel = (40075016.686 * Math.abs(Math.cos((center[1] * 180) / Math.PI))) /
22386
- Math.pow(2, zoom + 8);
22387
- var radius = pixelRadius * metresPerPixel * 0.0005;
22388
- return radius;
22389
- }
22390
-
22391
22402
  /**
22392
22403
  * Base class containing the logic of interaction WebMap with NextGIS services.
22393
22404
  *
@@ -22736,7 +22747,7 @@ var NgwMap = /** @class */ (function (_super) {
22736
22747
  this.$$selectFromNgwRaster = function (ev) {
22737
22748
  var count = _this._getSelectListenersCount();
22738
22749
  if (count) {
22739
- _this._selectFromNgwRaster(ev);
22750
+ _this.selectFromNgwRaster(ev);
22740
22751
  }
22741
22752
  };
22742
22753
  this.$$selectFromNgwVector = function (ev) {
@@ -22808,6 +22819,72 @@ var NgwMap = /** @class */ (function (_super) {
22808
22819
  }
22809
22820
  });
22810
22821
  };
22822
+ NgwMap.prototype.selectFromNgwRaster = function (ev) {
22823
+ return __awaiter(this, void 0, void 0, function () {
22824
+ var promises, layers, _i, layers_1, l, layer, identFunc, getIdsPromise, getIds, ids, _a, getIds_1, x, pixelRadius, center, zoom, radius, selectPromise;
22825
+ var _this = this;
22826
+ return __generator(this, function (_b) {
22827
+ switch (_b.label) {
22828
+ case 0:
22829
+ this._emitStatusEvent('ngw:preselect');
22830
+ promises = [];
22831
+ layers = Object.values(this._ngwLayers);
22832
+ layers.sort(function (a, b) {
22833
+ if (a.layer.order && b.layer.order) {
22834
+ return b.layer.order - a.layer.order;
22835
+ }
22836
+ return 1;
22837
+ });
22838
+ for (_i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
22839
+ l = layers_1[_i];
22840
+ layer = l.layer;
22841
+ identFunc = typeof layer.getIdentificationIds === 'function'
22842
+ ? layer.getIdentificationIds
22843
+ : false;
22844
+ if (identFunc && layer.options.selectable && this.isLayerVisible(layer)) {
22845
+ promises.push(identFunc.call(layer));
22846
+ }
22847
+ }
22848
+ getIdsPromise = Promise.all(promises);
22849
+ return [4 /*yield*/, getIdsPromise];
22850
+ case 1:
22851
+ getIds = _b.sent();
22852
+ ids = [];
22853
+ for (_a = 0, getIds_1 = getIds; _a < getIds_1.length; _a++) {
22854
+ x = getIds_1[_a];
22855
+ if (x) {
22856
+ ids.push.apply(ids, x);
22857
+ }
22858
+ }
22859
+ if (!ids.length) {
22860
+ this._emitStatusEvent('ngw:select', null);
22861
+ return [2 /*return*/];
22862
+ }
22863
+ pixelRadius = this.options.pixelRadius || 10;
22864
+ center = this.getCenter();
22865
+ zoom = this.getZoom();
22866
+ zoom = zoom !== undefined ? zoom : 20;
22867
+ if (!center || !zoom) {
22868
+ this._emitStatusEvent('ngw:select', null);
22869
+ return [2 /*return*/];
22870
+ }
22871
+ radius = getIdentifyRadius(center, zoom, pixelRadius);
22872
+ selectPromise = sendIdentifyRequest(ev, {
22873
+ layers: ids,
22874
+ connector: this.connector,
22875
+ radius: radius,
22876
+ }).then(function (resp) {
22877
+ var identify = __assign(__assign({}, resp), { resources: ids, sourceType: 'raster', event: ev });
22878
+ var identifyEvent = _this._prepareToIdentify(identify);
22879
+ _this._emitStatusEvent('ngw:select', identify);
22880
+ return identifyEvent;
22881
+ });
22882
+ this._addPromise('select', selectPromise);
22883
+ return [2 /*return*/, selectPromise];
22884
+ }
22885
+ });
22886
+ });
22887
+ };
22811
22888
  NgwMap.prototype._addPromise = function (groupName, promise) {
22812
22889
  var group = this._promises[groupName];
22813
22890
  if (group && group.indexOf(promise) === -1) {
@@ -22943,70 +23020,6 @@ var NgwMap = /** @class */ (function (_super) {
22943
23020
  }
22944
23021
  }
22945
23022
  };
22946
- NgwMap.prototype._selectFromNgwRaster = function (ev) {
22947
- return __awaiter(this, void 0, void 0, function () {
22948
- var promises, layers, _i, layers_1, l, layer, identFunc, getIdsPromise, getIds, ids, _a, getIds_1, x, pixelRadius, center, zoom, radius, selectPromise;
22949
- var _this = this;
22950
- return __generator(this, function (_b) {
22951
- switch (_b.label) {
22952
- case 0:
22953
- this._emitStatusEvent('ngw:preselect');
22954
- promises = [];
22955
- layers = Object.values(this._ngwLayers);
22956
- layers.sort(function (a, b) {
22957
- if (a.layer.order && b.layer.order) {
22958
- return b.layer.order - a.layer.order;
22959
- }
22960
- return 1;
22961
- });
22962
- for (_i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
22963
- l = layers_1[_i];
22964
- layer = l.layer;
22965
- identFunc = typeof layer.getIdentificationIds === 'function'
22966
- ? layer.getIdentificationIds
22967
- : false;
22968
- if (identFunc && layer.options.selectable && this.isLayerVisible(layer)) {
22969
- promises.push(identFunc.call(layer));
22970
- }
22971
- }
22972
- getIdsPromise = Promise.all(promises);
22973
- return [4 /*yield*/, getIdsPromise];
22974
- case 1:
22975
- getIds = _b.sent();
22976
- ids = [];
22977
- for (_a = 0, getIds_1 = getIds; _a < getIds_1.length; _a++) {
22978
- x = getIds_1[_a];
22979
- if (x) {
22980
- ids.push.apply(ids, x);
22981
- }
22982
- }
22983
- if (!ids.length) {
22984
- this._emitStatusEvent('ngw:select', null);
22985
- return [2 /*return*/];
22986
- }
22987
- pixelRadius = this.options.pixelRadius || 10;
22988
- center = this.getCenter();
22989
- zoom = this.getZoom();
22990
- zoom = zoom !== undefined ? zoom : 20;
22991
- if (!center || !zoom) {
22992
- this._emitStatusEvent('ngw:select', null);
22993
- return [2 /*return*/];
22994
- }
22995
- radius = getIdentifyRadius(center, zoom, pixelRadius);
22996
- selectPromise = sendIdentifyRequest(ev, {
22997
- layers: ids,
22998
- connector: this.connector,
22999
- radius: radius,
23000
- }).then(function (resp) {
23001
- _this._emitStatusEvent('ngw:select', _this._prepareToIdentify(__assign(__assign({}, resp), { resources: ids, sourceType: 'raster', event: ev })));
23002
- return resp;
23003
- });
23004
- this._addPromise('select', selectPromise);
23005
- return [2 /*return*/, selectPromise];
23006
- }
23007
- });
23008
- });
23009
- };
23010
23023
  NgwMap.prototype._prepareToIdentify = function (identify) {
23011
23024
  var _this = this;
23012
23025
  var getIdentifyItems_ = function () {