@nextgis/geocoder 1.18.21 → 1.19.1

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/geocoder; version: 1.18.21; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.19.1; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -1590,21 +1590,6 @@ var Geocoder = (function (exports) {
1590
1590
  */
1591
1591
  var Cache = Cache$1;
1592
1592
 
1593
- /**
1594
- * Thrown when...
1595
- */
1596
- var NetworkError = /** @class */ (function (_super) {
1597
- __extends(NetworkError, _super);
1598
- function NetworkError(url) {
1599
- var _this = _super.call(this) || this;
1600
- _this.name = 'NetworkError';
1601
- Object.setPrototypeOf(_this, NetworkError.prototype);
1602
- _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
1603
- return _this;
1604
- }
1605
- return NetworkError;
1606
- }(Error));
1607
-
1608
1593
  /**
1609
1594
  * Thrown when...
1610
1595
  */
@@ -1620,195 +1605,6 @@ var Geocoder = (function (exports) {
1620
1605
  return NgwError;
1621
1606
  }(Error));
1622
1607
 
1623
- function isObject(val) {
1624
- return Object.prototype.toString.call(val) === '[object Object]';
1625
- }
1626
-
1627
- var loadData;
1628
- // @ts-ignore
1629
- {
1630
- loadData = function (url, callback, options, error, onCancel) {
1631
- if (options === void 0) { options = {}; }
1632
- options.method = options.method || 'GET';
1633
- var xhr = new XMLHttpRequest();
1634
- xhr.open(options.method || 'GET', url, true); // true for asynchronous
1635
- if (options.responseType === 'blob') {
1636
- xhr.responseType = options.responseType;
1637
- }
1638
- var getResponseText = function () {
1639
- try {
1640
- return JSON.parse(xhr.responseText);
1641
- }
1642
- catch (er) {
1643
- return xhr.responseText;
1644
- }
1645
- };
1646
- var processingResponse = function (forError) {
1647
- if (forError === void 0) { forError = false; }
1648
- var cb = forError ? error : callback;
1649
- if (options.responseType === 'blob') {
1650
- cb(xhr.response);
1651
- }
1652
- else {
1653
- if (xhr.responseText) {
1654
- cb(getResponseText());
1655
- }
1656
- else {
1657
- error({ message: '' });
1658
- }
1659
- }
1660
- };
1661
- xhr.onload = function () {
1662
- if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
1663
- error(new NgwError(getResponseText()));
1664
- }
1665
- processingResponse();
1666
- };
1667
- // xhr.onreadystatechange = () => {
1668
- // if (
1669
- // (xhr.readyState === 4 && xhr.status === 200) ||
1670
- // (xhr.readyState === 3 && xhr.status === 201)
1671
- // ) {
1672
- // processingResponse();
1673
- // } else if (xhr.readyState === 3 && xhr.status === 400) {
1674
- // processingResponse();
1675
- // } else if (xhr.readyState === 4 && xhr.status === 500) {
1676
- // processingResponse();
1677
- // } else if (xhr.readyState === 4 && xhr.status === 401) {
1678
- // error(xhr.statusText);
1679
- // } else if (xhr.readyState === 4) {
1680
- // error('request error');
1681
- // }
1682
- // };
1683
- xhr.onerror = function (er) {
1684
- if (xhr.status === 0) {
1685
- error(new NetworkError(url));
1686
- }
1687
- else {
1688
- error(er);
1689
- }
1690
- };
1691
- xhr.upload.onprogress = function (e) {
1692
- if (e.lengthComputable) {
1693
- var percentComplete = (e.loaded / e.total) * 100;
1694
- if (options.onProgress) {
1695
- options.onProgress(percentComplete, e);
1696
- }
1697
- // console.log(percentComplete + '% uploaded');
1698
- }
1699
- };
1700
- var headers = options.headers;
1701
- if (headers) {
1702
- for (var h in headers) {
1703
- var header = headers[h];
1704
- if (typeof header === 'string') {
1705
- xhr.setRequestHeader(h, header);
1706
- }
1707
- }
1708
- }
1709
- if (options.withCredentials !== undefined) {
1710
- xhr.withCredentials = options.withCredentials;
1711
- }
1712
- var data;
1713
- if (options.file) {
1714
- data = new FormData();
1715
- data.append('file', options.file);
1716
- if (options.data) {
1717
- for (var d in options.data) {
1718
- data.append(d, data[d]);
1719
- }
1720
- }
1721
- }
1722
- else {
1723
- data = options.data
1724
- ? typeof options.data === 'string'
1725
- ? options.data
1726
- : JSON.stringify(options.data)
1727
- : null;
1728
- }
1729
- if (onCancel) {
1730
- onCancel(function () {
1731
- xhr.abort();
1732
- });
1733
- }
1734
- xhr.send(data);
1735
- };
1736
- }
1737
-
1738
- // https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
1739
- var templateRe = /\{ *([\w_-]+) *\}/g;
1740
- function template(str, data) {
1741
- return str.replace(templateRe, function (s, key) {
1742
- var value = data[key];
1743
- if (value === undefined) {
1744
- throw new Error('No value provided for letiable ' + s);
1745
- }
1746
- else if (typeof value === 'function') {
1747
- value = value(data);
1748
- }
1749
- return value;
1750
- });
1751
- }
1752
-
1753
- function apiRequest(opt) {
1754
- var params = opt.params;
1755
- return new CancelablePromise(function (resolve, reject) {
1756
- opt.connector
1757
- .connect()
1758
- .then(function (apiItems) {
1759
- var apiItem = apiItems && apiItems[opt.name];
1760
- if (apiItem) {
1761
- apiItem = __spreadArray([], apiItem, true);
1762
- var url = apiItem.shift();
1763
- if (apiItem.length) {
1764
- var replaceParams = {};
1765
- for (var fry = 0; fry < apiItem.length; fry++) {
1766
- var arg = apiItem[fry];
1767
- replaceParams[fry] = '{' + arg + '}';
1768
- if (params[arg] === undefined) {
1769
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
1770
- }
1771
- }
1772
- if (url) {
1773
- url = template(url, replaceParams);
1774
- }
1775
- }
1776
- // Transfer part of the parameters from `params` to the URL string
1777
- if (params) {
1778
- var paramArray_1 = [];
1779
- var paramList = params.paramList;
1780
- if (Array.isArray(paramList)) {
1781
- delete params.paramList;
1782
- paramList.forEach(function (x) {
1783
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1784
- });
1785
- }
1786
- for (var p in params) {
1787
- if (apiItem.indexOf(p) === -1) {
1788
- paramArray_1.push("".concat(p, "=").concat(params[p]));
1789
- }
1790
- }
1791
- if (paramArray_1.length) {
1792
- url = url + '?' + paramArray_1.join('&');
1793
- }
1794
- }
1795
- if (url) {
1796
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1797
- }
1798
- else {
1799
- reject(new Error('request url is not set'));
1800
- }
1801
- }
1802
- else {
1803
- resolve(undefined);
1804
- }
1805
- })
1806
- .catch(function (er) {
1807
- reject(er);
1808
- });
1809
- });
1810
- }
1811
-
1812
1608
  /**
1813
1609
  * Thrown when ...
1814
1610
  */
@@ -1824,45 +1620,12 @@ var Geocoder = (function (exports) {
1824
1620
  return ResourceNotFoundError;
1825
1621
  }(NgwError));
1826
1622
 
1827
- /**
1828
- * Thrown when ...
1829
- */
1830
- var InsufficientPermissionsError = /** @class */ (function (_super) {
1831
- __extends(InsufficientPermissionsError, _super);
1832
- function InsufficientPermissionsError(obj) {
1833
- var _this = _super.call(this, obj) || this;
1834
- _this.name = 'InsufficientPermissionsError';
1835
- _this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
1836
- Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
1837
- return _this;
1838
- }
1839
- return InsufficientPermissionsError;
1840
- }(NgwError));
1841
-
1842
- var CONNECTORS = [];
1843
- function addConnector(connector) {
1844
- CONNECTORS.push(connector);
1845
- }
1846
- function findConnector(options) {
1847
- return CONNECTORS.find(function (x) {
1848
- if (x.options.baseUrl === options.baseUrl) {
1849
- if (options.auth) {
1850
- if (x.options.auth) {
1851
- return objectDeepEqual(x.options.auth, options.auth);
1852
- }
1853
- }
1854
- else {
1855
- // if auth not in find options; use first connector with same url
1856
- return true;
1857
- }
1858
- }
1859
- });
1623
+ function isObject(val) {
1624
+ return Object.prototype.toString.call(val) === '[object Object]';
1860
1625
  }
1861
- function removeConnector(connector) {
1862
- var index = CONNECTORS.indexOf(connector);
1863
- if (index !== -1) {
1864
- CONNECTORS.splice(index, 1);
1865
- }
1626
+
1627
+ function resourceCompare(res1, res2) {
1628
+ return objectDeepEqual(res1, res2);
1866
1629
  }
1867
1630
 
1868
1631
  var exclude = ['description'];
@@ -1900,10 +1663,6 @@ var Geocoder = (function (exports) {
1900
1663
  return query;
1901
1664
  }
1902
1665
 
1903
- function resourceCompare(res1, res2) {
1904
- return objectDeepEqual(res1, res2);
1905
- }
1906
-
1907
1666
  var ResourcesControl = /** @class */ (function () {
1908
1667
  function ResourcesControl(connector) {
1909
1668
  this.connector = connector;
@@ -2174,6 +1933,247 @@ var Geocoder = (function (exports) {
2174
1933
  return ResourcesControl;
2175
1934
  }());
2176
1935
 
1936
+ var CONNECTORS = [];
1937
+ function addConnector(connector) {
1938
+ CONNECTORS.push(connector);
1939
+ }
1940
+ function findConnector(options) {
1941
+ return CONNECTORS.find(function (x) {
1942
+ if (x.options.baseUrl === options.baseUrl) {
1943
+ if (options.auth) {
1944
+ if (x.options.auth) {
1945
+ return objectDeepEqual(x.options.auth, options.auth);
1946
+ }
1947
+ }
1948
+ else {
1949
+ // if auth not in find options; use first connector with same url
1950
+ return true;
1951
+ }
1952
+ }
1953
+ });
1954
+ }
1955
+ function removeConnector(connector) {
1956
+ var index = CONNECTORS.indexOf(connector);
1957
+ if (index !== -1) {
1958
+ CONNECTORS.splice(index, 1);
1959
+ }
1960
+ }
1961
+
1962
+ /**
1963
+ * Thrown when ...
1964
+ */
1965
+ var InsufficientPermissionsError = /** @class */ (function (_super) {
1966
+ __extends(InsufficientPermissionsError, _super);
1967
+ function InsufficientPermissionsError(obj) {
1968
+ var _this = _super.call(this, obj) || this;
1969
+ _this.name = 'InsufficientPermissionsError';
1970
+ _this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
1971
+ Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
1972
+ return _this;
1973
+ }
1974
+ return InsufficientPermissionsError;
1975
+ }(NgwError));
1976
+
1977
+ // https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
1978
+ var templateRe = /\{ *([\w_-]+) *\}/g;
1979
+ function template(str, data) {
1980
+ return str.replace(templateRe, function (s, key) {
1981
+ var value = data[key];
1982
+ if (value === undefined) {
1983
+ throw new Error('No value provided for letiable ' + s);
1984
+ }
1985
+ else if (typeof value === 'function') {
1986
+ value = value(data);
1987
+ }
1988
+ return value;
1989
+ });
1990
+ }
1991
+
1992
+ function apiRequest(opt) {
1993
+ var params = opt.params;
1994
+ return new CancelablePromise(function (resolve, reject) {
1995
+ opt.connector
1996
+ .connect()
1997
+ .then(function (apiItems) {
1998
+ var apiItem = apiItems && apiItems[opt.name];
1999
+ if (apiItem) {
2000
+ apiItem = __spreadArray([], apiItem, true);
2001
+ var url = apiItem.shift();
2002
+ if (apiItem.length) {
2003
+ var replaceParams = {};
2004
+ for (var fry = 0; fry < apiItem.length; fry++) {
2005
+ var arg = apiItem[fry];
2006
+ replaceParams[fry] = '{' + arg + '}';
2007
+ if (params[arg] === undefined) {
2008
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
2009
+ }
2010
+ }
2011
+ if (url) {
2012
+ url = template(url, replaceParams);
2013
+ }
2014
+ }
2015
+ // Transfer part of the parameters from `params` to the URL string
2016
+ if (params) {
2017
+ var paramArray_1 = [];
2018
+ var paramList = params.paramList;
2019
+ if (Array.isArray(paramList)) {
2020
+ delete params.paramList;
2021
+ paramList.forEach(function (x) {
2022
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
2023
+ });
2024
+ }
2025
+ for (var p in params) {
2026
+ if (apiItem.indexOf(p) === -1) {
2027
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
2028
+ }
2029
+ }
2030
+ if (paramArray_1.length) {
2031
+ url = url + '?' + paramArray_1.join('&');
2032
+ }
2033
+ }
2034
+ if (url) {
2035
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
2036
+ }
2037
+ else {
2038
+ reject(new Error('request url is not set'));
2039
+ }
2040
+ }
2041
+ else {
2042
+ resolve(undefined);
2043
+ }
2044
+ })
2045
+ .catch(function (er) {
2046
+ reject(er);
2047
+ });
2048
+ });
2049
+ }
2050
+
2051
+ /**
2052
+ * Thrown when...
2053
+ */
2054
+ var NetworkError = /** @class */ (function (_super) {
2055
+ __extends(NetworkError, _super);
2056
+ function NetworkError(url) {
2057
+ var _this = _super.call(this) || this;
2058
+ _this.name = 'NetworkError';
2059
+ Object.setPrototypeOf(_this, NetworkError.prototype);
2060
+ _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
2061
+ return _this;
2062
+ }
2063
+ return NetworkError;
2064
+ }(Error));
2065
+
2066
+ var loadData;
2067
+ // @ts-ignore
2068
+ {
2069
+ loadData = function (url, callback, options, error, onCancel) {
2070
+ if (options === void 0) { options = {}; }
2071
+ options.method = options.method || 'GET';
2072
+ var xhr = new XMLHttpRequest();
2073
+ xhr.open(options.method || 'GET', url, true); // true for asynchronous
2074
+ if (options.responseType === 'blob') {
2075
+ xhr.responseType = options.responseType;
2076
+ }
2077
+ var getResponseText = function () {
2078
+ try {
2079
+ return JSON.parse(xhr.responseText);
2080
+ }
2081
+ catch (er) {
2082
+ return xhr.responseText;
2083
+ }
2084
+ };
2085
+ var processingResponse = function (forError) {
2086
+ if (forError === void 0) { forError = false; }
2087
+ var cb = forError ? error : callback;
2088
+ if (options.responseType === 'blob') {
2089
+ cb(xhr.response);
2090
+ }
2091
+ else {
2092
+ if (xhr.responseText) {
2093
+ cb(getResponseText());
2094
+ }
2095
+ else {
2096
+ error({ message: '' });
2097
+ }
2098
+ }
2099
+ };
2100
+ xhr.onload = function () {
2101
+ if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
2102
+ error(new NgwError(getResponseText()));
2103
+ }
2104
+ processingResponse();
2105
+ };
2106
+ // xhr.onreadystatechange = () => {
2107
+ // if (
2108
+ // (xhr.readyState === 4 && xhr.status === 200) ||
2109
+ // (xhr.readyState === 3 && xhr.status === 201)
2110
+ // ) {
2111
+ // processingResponse();
2112
+ // } else if (xhr.readyState === 3 && xhr.status === 400) {
2113
+ // processingResponse();
2114
+ // } else if (xhr.readyState === 4 && xhr.status === 500) {
2115
+ // processingResponse();
2116
+ // } else if (xhr.readyState === 4 && xhr.status === 401) {
2117
+ // error(xhr.statusText);
2118
+ // } else if (xhr.readyState === 4) {
2119
+ // error('request error');
2120
+ // }
2121
+ // };
2122
+ xhr.onerror = function (er) {
2123
+ if (xhr.status === 0) {
2124
+ error(new NetworkError(url));
2125
+ }
2126
+ else {
2127
+ error(er);
2128
+ }
2129
+ };
2130
+ xhr.upload.onprogress = function (e) {
2131
+ if (e.lengthComputable) {
2132
+ var percentComplete = (e.loaded / e.total) * 100;
2133
+ if (options.onProgress) {
2134
+ options.onProgress(percentComplete, e);
2135
+ }
2136
+ // console.log(percentComplete + '% uploaded');
2137
+ }
2138
+ };
2139
+ var headers = options.headers;
2140
+ if (headers) {
2141
+ for (var h in headers) {
2142
+ var header = headers[h];
2143
+ if (typeof header === 'string') {
2144
+ xhr.setRequestHeader(h, header);
2145
+ }
2146
+ }
2147
+ }
2148
+ if (options.withCredentials !== undefined) {
2149
+ xhr.withCredentials = options.withCredentials;
2150
+ }
2151
+ var data;
2152
+ if (options.file) {
2153
+ data = new FormData();
2154
+ data.append('file', options.file);
2155
+ if (options.data) {
2156
+ for (var d in options.data) {
2157
+ data.append(d, data[d]);
2158
+ }
2159
+ }
2160
+ }
2161
+ else {
2162
+ data = options.data
2163
+ ? typeof options.data === 'string'
2164
+ ? options.data
2165
+ : JSON.stringify(options.data)
2166
+ : null;
2167
+ }
2168
+ if (onCancel) {
2169
+ onCancel(function () {
2170
+ xhr.abort();
2171
+ });
2172
+ }
2173
+ xhr.send(data);
2174
+ };
2175
+ }
2176
+
2177
2177
  var ID = 0;
2178
2178
  var NgwConnector$1 = /** @class */ (function () {
2179
2179
  function NgwConnector(options) {
@@ -3067,7 +3067,13 @@ var Geocoder = (function (exports) {
3067
3067
  NgwProvider.prototype.reverse = function (coordinates) {
3068
3068
  return __asyncGenerator(this, arguments, function reverse_1() {
3069
3069
  return __generator(this, function (_a) {
3070
- throw new Error('Not implemented');
3070
+ switch (_a.label) {
3071
+ case 0: throw new Error('Not implemented');
3072
+ case 1: return [4 /*yield*/, _a.sent()];
3073
+ case 2:
3074
+ _a.sent();
3075
+ return [2 /*return*/];
3076
+ }
3071
3077
  });
3072
3078
  });
3073
3079
  };