@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
  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.0; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-leaflet; version: 1.16.2; author: NextGIS */
2
2
  var NgwLeaflet = (function () {
3
3
  'use strict';
4
4
 
@@ -15266,7 +15266,9 @@ var NgwLeaflet = (function () {
15266
15266
 
15267
15267
  var d2r = Math.PI / 180; // degrees to radians
15268
15268
  var r2d = 180 / Math.PI; // radians to degrees
15269
- function getCirclePolygonCoordinates(lng, lat, radius, points) {
15269
+ function getCirclePolygonCoordinates(lng, lat,
15270
+ /** In kilometers */
15271
+ radius, points) {
15270
15272
  if (radius === void 0) { radius = 10; }
15271
15273
  if (points === void 0) { points = 6; }
15272
15274
  // find the radius in lat/lon
@@ -15316,6 +15318,14 @@ var NgwLeaflet = (function () {
15316
15318
  array.every(function (x) { return typeof x === 'number'; }));
15317
15319
  }
15318
15320
 
15321
+ function getIdentifyRadius(center, zoom, pixelRadius) {
15322
+ pixelRadius = pixelRadius !== null && pixelRadius !== void 0 ? pixelRadius : 10;
15323
+ var metresPerPixel = (40075016.686 * Math.abs(Math.cos((center[1] * 180) / Math.PI))) /
15324
+ Math.pow(2, zoom + 8);
15325
+ var radius = pixelRadius * metresPerPixel * 0.0005;
15326
+ return radius;
15327
+ }
15328
+
15319
15329
  /**
15320
15330
  * Copy the values of all of the enumerable own properties from one or more source objects to a
15321
15331
  * target object. Returns the target object.
@@ -15397,6 +15407,11 @@ var NgwLeaflet = (function () {
15397
15407
  return newObj;
15398
15408
  }
15399
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
+
15400
15415
  function isObject$1(val) {
15401
15416
  return Object.prototype.toString.call(val) === '[object Object]';
15402
15417
  }
@@ -18285,6 +18300,65 @@ var NgwLeaflet = (function () {
18285
18300
  });
18286
18301
  }
18287
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
+
18288
18362
  /**
18289
18363
  * Thrown when ...
18290
18364
  */
@@ -18650,65 +18724,6 @@ var NgwLeaflet = (function () {
18650
18724
  return ResourcesControl;
18651
18725
  }());
18652
18726
 
18653
- function apiRequest(opt) {
18654
- var params = opt.params;
18655
- return new CancelablePromise(function (resolve, reject) {
18656
- opt.connector
18657
- .connect()
18658
- .then(function (apiItems) {
18659
- var apiItem = apiItems && apiItems[opt.name];
18660
- if (apiItem) {
18661
- apiItem = __spreadArray([], apiItem, true);
18662
- var url = apiItem.shift();
18663
- if (apiItem.length) {
18664
- var replaceParams = {};
18665
- for (var fry = 0; fry < apiItem.length; fry++) {
18666
- var arg = apiItem[fry];
18667
- replaceParams[fry] = '{' + arg + '}';
18668
- if (params[arg] === undefined) {
18669
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
18670
- }
18671
- }
18672
- if (url) {
18673
- url = template(url, replaceParams);
18674
- }
18675
- }
18676
- // Transfer part of the parameters from `params` to the URL string
18677
- if (params) {
18678
- var paramArray_1 = [];
18679
- var paramList = params.paramList;
18680
- if (Array.isArray(paramList)) {
18681
- delete params.paramList;
18682
- paramList.forEach(function (x) {
18683
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
18684
- });
18685
- }
18686
- for (var p in params) {
18687
- if (apiItem.indexOf(p) === -1) {
18688
- paramArray_1.push("".concat(p, "=").concat(params[p]));
18689
- }
18690
- }
18691
- if (paramArray_1.length) {
18692
- url = url + '?' + paramArray_1.join('&');
18693
- }
18694
- }
18695
- if (url) {
18696
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
18697
- }
18698
- else {
18699
- reject(new Error('request url is not set'));
18700
- }
18701
- }
18702
- else {
18703
- resolve(undefined);
18704
- }
18705
- })
18706
- .catch(function (er) {
18707
- reject(er);
18708
- });
18709
- });
18710
- }
18711
-
18712
18727
  var ID$1 = 0;
18713
18728
  var NgwConnector = /** @class */ (function () {
18714
18729
  function NgwConnector(options) {
@@ -18779,9 +18794,9 @@ var NgwLeaflet = (function () {
18779
18794
  if (auth) {
18780
18795
  var login = auth.login, password = auth.password;
18781
18796
  if (login && password) {
18782
- return _this.getUserInfo({ login: login, password: password })
18797
+ return _this._login({ login: login, password: password })
18783
18798
  .then(function () {
18784
- makeQuery();
18799
+ return makeQuery();
18785
18800
  })
18786
18801
  .catch(function (er) { return reject(er); });
18787
18802
  }
@@ -18799,10 +18814,10 @@ var NgwLeaflet = (function () {
18799
18814
  * Quick way to change NextGIS Web user.
18800
18815
  * @param credentials - New user credentials
18801
18816
  */
18802
- NgwConnector.prototype.login = function (credentials) {
18817
+ NgwConnector.prototype.login = function (credentials, options) {
18803
18818
  this.logout();
18804
18819
  addConnector(this);
18805
- return this.getUserInfo(credentials);
18820
+ return this._login(credentials, options);
18806
18821
  };
18807
18822
  /**
18808
18823
  * Disconnecting a user. Aborting all current requests
@@ -18815,29 +18830,16 @@ var NgwLeaflet = (function () {
18815
18830
  this.emitter.emit('logout');
18816
18831
  this.resources.cache.clean();
18817
18832
  };
18818
- NgwConnector.prototype.getUserInfo = function (credentials) {
18819
- var _this = this;
18833
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
18820
18834
  if (this.user && this.user.id) {
18821
18835
  return CancelablePromise.resolve(this.user);
18822
18836
  }
18823
18837
  if (credentials) {
18824
18838
  this.options.auth = credentials;
18825
18839
  }
18826
- var options = {
18827
- headers: this.getAuthorizationHeaders(credentials),
18828
- // withCredentials: true
18829
- };
18840
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
18830
18841
  // Do not use apiRequest('auth.current_user') to avoid circular-references
18831
- return this.makeQuery('/api/component/auth/current_user', {}, options)
18832
- .then(function (data) {
18833
- _this.user = data;
18834
- _this.emitter.emit('login', data);
18835
- return data;
18836
- })
18837
- .catch(function (er) {
18838
- _this.emitter.emit('login:error', er);
18839
- throw er;
18840
- });
18842
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
18841
18843
  };
18842
18844
  /**
18843
18845
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -18903,6 +18905,7 @@ var NgwLeaflet = (function () {
18903
18905
  */
18904
18906
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
18905
18907
  var _this = this;
18908
+ var _a;
18906
18909
  if (params_ === void 0) { params_ = {}; }
18907
18910
  if (requestOptions === void 0) { requestOptions = {}; }
18908
18911
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -18917,7 +18920,7 @@ var NgwLeaflet = (function () {
18917
18920
  withCredentials: withCredentials,
18918
18921
  responseType: responseType,
18919
18922
  baseUrl: this.options.baseUrl,
18920
- auth: this.options.auth,
18923
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
18921
18924
  })));
18922
18925
  }
18923
18926
  return makeApiRequest();
@@ -19126,6 +19129,19 @@ var NgwLeaflet = (function () {
19126
19129
  this.activeRequests.push(request);
19127
19130
  return request;
19128
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
+ };
19129
19145
  NgwConnector.prototype._cleanActiveRequests = function (request) {
19130
19146
  var activeRequestIndex = this.activeRequests.indexOf(request);
19131
19147
  if (activeRequestIndex !== -1) {
@@ -19457,14 +19473,14 @@ var NgwLeaflet = (function () {
19457
19473
  function createWktFromCoordArray(coord) {
19458
19474
  var polygon = coord.map(function (_a) {
19459
19475
  var lng = _a[0], lat = _a[1];
19460
- 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];
19461
19477
  return x + ' ' + y;
19462
19478
  });
19463
19479
  return "POLYGON((".concat(polygon.join(', '), "))");
19464
19480
  }
19465
19481
  function fetchNgwLayerItemsRequest(options) {
19466
19482
  var params = __assign({}, FEATURE_REQUEST_PARAMS);
19467
- 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;
19468
19484
  if (limit) {
19469
19485
  if (limit !== Number.POSITIVE_INFINITY) {
19470
19486
  params.limit = limit;
@@ -19477,6 +19493,9 @@ var NgwLeaflet = (function () {
19477
19493
  if (offset) {
19478
19494
  params.offset = offset;
19479
19495
  }
19496
+ if (geomFormat) {
19497
+ params.geom_format = geomFormat;
19498
+ }
19480
19499
  updateItemRequestParam(params, options);
19481
19500
  if (orderBy) {
19482
19501
  params.order_by = orderBy.join(',');
@@ -22383,14 +22402,6 @@ var NgwLeaflet = (function () {
22383
22402
  return options;
22384
22403
  }
22385
22404
 
22386
- function getIdentifyRadius(center, zoom, pixelRadius) {
22387
- pixelRadius = pixelRadius !== null && pixelRadius !== void 0 ? pixelRadius : 10;
22388
- var metresPerPixel = (40075016.686 * Math.abs(Math.cos((center[1] * 180) / Math.PI))) /
22389
- Math.pow(2, zoom + 8);
22390
- var radius = pixelRadius * metresPerPixel * 0.0005;
22391
- return radius;
22392
- }
22393
-
22394
22405
  /**
22395
22406
  * Base class containing the logic of interaction WebMap with NextGIS services.
22396
22407
  *
@@ -22739,7 +22750,7 @@ var NgwLeaflet = (function () {
22739
22750
  this.$$selectFromNgwRaster = function (ev) {
22740
22751
  var count = _this._getSelectListenersCount();
22741
22752
  if (count) {
22742
- _this._selectFromNgwRaster(ev);
22753
+ _this.selectFromNgwRaster(ev);
22743
22754
  }
22744
22755
  };
22745
22756
  this.$$selectFromNgwVector = function (ev) {
@@ -22811,6 +22822,72 @@ var NgwLeaflet = (function () {
22811
22822
  }
22812
22823
  });
22813
22824
  };
22825
+ NgwMap.prototype.selectFromNgwRaster = function (ev) {
22826
+ return __awaiter(this, void 0, void 0, function () {
22827
+ var promises, layers, _i, layers_1, l, layer, identFunc, getIdsPromise, getIds, ids, _a, getIds_1, x, pixelRadius, center, zoom, radius, selectPromise;
22828
+ var _this = this;
22829
+ return __generator(this, function (_b) {
22830
+ switch (_b.label) {
22831
+ case 0:
22832
+ this._emitStatusEvent('ngw:preselect');
22833
+ promises = [];
22834
+ layers = Object.values(this._ngwLayers);
22835
+ layers.sort(function (a, b) {
22836
+ if (a.layer.order && b.layer.order) {
22837
+ return b.layer.order - a.layer.order;
22838
+ }
22839
+ return 1;
22840
+ });
22841
+ for (_i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
22842
+ l = layers_1[_i];
22843
+ layer = l.layer;
22844
+ identFunc = typeof layer.getIdentificationIds === 'function'
22845
+ ? layer.getIdentificationIds
22846
+ : false;
22847
+ if (identFunc && layer.options.selectable && this.isLayerVisible(layer)) {
22848
+ promises.push(identFunc.call(layer));
22849
+ }
22850
+ }
22851
+ getIdsPromise = Promise.all(promises);
22852
+ return [4 /*yield*/, getIdsPromise];
22853
+ case 1:
22854
+ getIds = _b.sent();
22855
+ ids = [];
22856
+ for (_a = 0, getIds_1 = getIds; _a < getIds_1.length; _a++) {
22857
+ x = getIds_1[_a];
22858
+ if (x) {
22859
+ ids.push.apply(ids, x);
22860
+ }
22861
+ }
22862
+ if (!ids.length) {
22863
+ this._emitStatusEvent('ngw:select', null);
22864
+ return [2 /*return*/];
22865
+ }
22866
+ pixelRadius = this.options.pixelRadius || 10;
22867
+ center = this.getCenter();
22868
+ zoom = this.getZoom();
22869
+ zoom = zoom !== undefined ? zoom : 20;
22870
+ if (!center || !zoom) {
22871
+ this._emitStatusEvent('ngw:select', null);
22872
+ return [2 /*return*/];
22873
+ }
22874
+ radius = getIdentifyRadius(center, zoom, pixelRadius);
22875
+ selectPromise = sendIdentifyRequest(ev, {
22876
+ layers: ids,
22877
+ connector: this.connector,
22878
+ radius: radius,
22879
+ }).then(function (resp) {
22880
+ var identify = __assign(__assign({}, resp), { resources: ids, sourceType: 'raster', event: ev });
22881
+ var identifyEvent = _this._prepareToIdentify(identify);
22882
+ _this._emitStatusEvent('ngw:select', identify);
22883
+ return identifyEvent;
22884
+ });
22885
+ this._addPromise('select', selectPromise);
22886
+ return [2 /*return*/, selectPromise];
22887
+ }
22888
+ });
22889
+ });
22890
+ };
22814
22891
  NgwMap.prototype._addPromise = function (groupName, promise) {
22815
22892
  var group = this._promises[groupName];
22816
22893
  if (group && group.indexOf(promise) === -1) {
@@ -22946,70 +23023,6 @@ var NgwLeaflet = (function () {
22946
23023
  }
22947
23024
  }
22948
23025
  };
22949
- NgwMap.prototype._selectFromNgwRaster = function (ev) {
22950
- return __awaiter(this, void 0, void 0, function () {
22951
- var promises, layers, _i, layers_1, l, layer, identFunc, getIdsPromise, getIds, ids, _a, getIds_1, x, pixelRadius, center, zoom, radius, selectPromise;
22952
- var _this = this;
22953
- return __generator(this, function (_b) {
22954
- switch (_b.label) {
22955
- case 0:
22956
- this._emitStatusEvent('ngw:preselect');
22957
- promises = [];
22958
- layers = Object.values(this._ngwLayers);
22959
- layers.sort(function (a, b) {
22960
- if (a.layer.order && b.layer.order) {
22961
- return b.layer.order - a.layer.order;
22962
- }
22963
- return 1;
22964
- });
22965
- for (_i = 0, layers_1 = layers; _i < layers_1.length; _i++) {
22966
- l = layers_1[_i];
22967
- layer = l.layer;
22968
- identFunc = typeof layer.getIdentificationIds === 'function'
22969
- ? layer.getIdentificationIds
22970
- : false;
22971
- if (identFunc && layer.options.selectable && this.isLayerVisible(layer)) {
22972
- promises.push(identFunc.call(layer));
22973
- }
22974
- }
22975
- getIdsPromise = Promise.all(promises);
22976
- return [4 /*yield*/, getIdsPromise];
22977
- case 1:
22978
- getIds = _b.sent();
22979
- ids = [];
22980
- for (_a = 0, getIds_1 = getIds; _a < getIds_1.length; _a++) {
22981
- x = getIds_1[_a];
22982
- if (x) {
22983
- ids.push.apply(ids, x);
22984
- }
22985
- }
22986
- if (!ids.length) {
22987
- this._emitStatusEvent('ngw:select', null);
22988
- return [2 /*return*/];
22989
- }
22990
- pixelRadius = this.options.pixelRadius || 10;
22991
- center = this.getCenter();
22992
- zoom = this.getZoom();
22993
- zoom = zoom !== undefined ? zoom : 20;
22994
- if (!center || !zoom) {
22995
- this._emitStatusEvent('ngw:select', null);
22996
- return [2 /*return*/];
22997
- }
22998
- radius = getIdentifyRadius(center, zoom, pixelRadius);
22999
- selectPromise = sendIdentifyRequest(ev, {
23000
- layers: ids,
23001
- connector: this.connector,
23002
- radius: radius,
23003
- }).then(function (resp) {
23004
- _this._emitStatusEvent('ngw:select', _this._prepareToIdentify(__assign(__assign({}, resp), { resources: ids, sourceType: 'raster', event: ev })));
23005
- return resp;
23006
- });
23007
- this._addPromise('select', selectPromise);
23008
- return [2 /*return*/, selectPromise];
23009
- }
23010
- });
23011
- });
23012
- };
23013
23026
  NgwMap.prototype._prepareToIdentify = function (identify) {
23014
23027
  var _this = this;
23015
23028
  var getIdentifyItems_ = function () {