@nextgis/geocoder 1.9.3 → 1.11.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.
- package/lib/geocoder.cjs.js +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.esm-browser.js +92 -33
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +1 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.global.js +107 -43
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/package.json +6 -6
package/lib/geocoder.cjs.js
CHANGED
package/lib/geocoder.cjs.prod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@nextgis/cancelable-promise"),t=require("@nextgis/utils"),s=require("@nextgis/ngw-connector");function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o=r(e),c=r(s);class i{constructor(e){e&&t.objectAssign(this,e)}}let n=0;class a extends i{constructor(e){super(e),this.providers=[],e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}async*search(e){for(const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@nextgis/cancelable-promise"),t=require("@nextgis/utils"),s=require("@nextgis/ngw-connector");function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o=r(e),c=r(s);class i{constructor(e){e&&t.objectAssign(this,e)}}let n=0;class a extends i{constructor(e){super(e),this.providers=[],e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}async*search(e){for(const s of this.providers)try{const t=s.search(e);for await(const e of t)yield{...e,provider:s,_id:n++}}catch(t){}}result(e){return e.provider?e.provider.result(e):o.resolve(void 0)}}class u extends i{}exports.BaseProvider=u,exports.Geocoder=a,exports.NgwProvider=class extends u{constructor(e){super(e),this.caseInsensitive=!0,this.searchUrl="https://maxim.nextgis.com",this.searchResources=[],this.requests=[],this.connector=e.connector||new c({baseUrl:this.searchUrl}),this.searchResources=e.searchResources}abort(){this.requests.forEach((e=>{e.cancel()})),this.requests=[]}async*search(e){for(const t of this.searchResources){const s=this.connector.get("feature_layer.store",{headers:{RANGE:`items=0-${t.limit||300}`}},{id:t.id,like:e});this.requests.push(s),s.catch((e=>{console.warn(e)}));const r=await s,o=[];r&&r.forEach((s=>{o.push({query:e,resourceId:t.id,...s})}));for(const e of this._items(o))e.result=()=>this.result(e),yield e}}result(e){const t=this.connector.get("feature_layer.feature.item_extent",null,{id:e.resourceId,fid:e.featureId}).then((t=>{const s=t.extent;return{text:e.text,extent:[s.minLon,s.minLat,s.maxLon,s.maxLat]}}));return this.requests.push(t),t}_items(e){const t=[];return e.forEach((e=>{this.searchResources.find((t=>t.id===e.resourceId))&&t.push({query:e.query,text:e.label,featureId:e.id,resourceId:e.resourceId})})),t}},exports.NominatimProvider=class extends u{constructor(e){super(e),this.searchUrl="https://nominatim.openstreetmap.org",this._requests=[]}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}async*search(e){const s=t.fixUrlStr(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${e}`),r=new o(((t,r,o)=>{const c=new XMLHttpRequest;c.open("GET",s,!0),c.onload=()=>{try{const s=JSON.parse(c.responseText).features.map((t=>({geom:t,extent:t.bbox,text:t.properties&&t.properties.display_name,query:e})));t(s)}catch(s){r(s)}},c.onerror=e=>{r(e)},o((()=>{c.abort()})),c.send()})).catch((e=>{throw e}));this._requests.push(r);const c=await r;if(c)for(const t of c)t.result=()=>this.result(t),yield t}result(e){return o.resolve({text:e.text,extent:e.extent||[],geom:e.geom})}},exports.create=function(e){return new a(e)};
|
|
2
2
|
//# sourceMappingURL=geocoder.cjs.prod.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 1.11.3; author: NextGIS */
|
|
2
2
|
class CancelError extends Error {
|
|
3
3
|
constructor() {
|
|
4
4
|
super();
|
|
@@ -979,13 +979,45 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
979
979
|
}
|
|
980
980
|
}
|
|
981
981
|
|
|
982
|
+
/**
|
|
983
|
+
* @example
|
|
984
|
+
* ```javascript
|
|
985
|
+
* const cache1 = new Cache();
|
|
986
|
+
* cache1.add('foo', 'value');
|
|
987
|
+
*
|
|
988
|
+
* const cache2 = new Cache();
|
|
989
|
+
* cache2.match('foo'); // value
|
|
990
|
+
*
|
|
991
|
+
* const cache3 = new Cache({ namespace: 'foo' });
|
|
992
|
+
* cache3.match('foo'); // undefined
|
|
993
|
+
* ```
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* ```javascript
|
|
997
|
+
* let COUNTER = 0;
|
|
998
|
+
* const createPromise = () => new Promise((res) => {
|
|
999
|
+
* COUNTER++
|
|
1000
|
+
* setTimeout(() => res('Ok'), 300)
|
|
1001
|
+
* });
|
|
1002
|
+
*
|
|
1003
|
+
* const cache = new Cache();
|
|
1004
|
+
* for (let i = 0; i < 10; i++) {
|
|
1005
|
+
* cache.add('foo', createPromise).then((data) => {
|
|
1006
|
+
* console.log(data); // 'Ok'
|
|
1007
|
+
* });
|
|
1008
|
+
* }
|
|
1009
|
+
* console.log(COUNTER); // 1
|
|
1010
|
+
* ```
|
|
1011
|
+
*/
|
|
982
1012
|
class Cache$1 {
|
|
983
|
-
constructor() {
|
|
1013
|
+
constructor(options = {}) {
|
|
1014
|
+
var _a;
|
|
984
1015
|
this.cache = [];
|
|
985
|
-
|
|
986
|
-
|
|
1016
|
+
const namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
1017
|
+
if (Cache$1.instance[namespace]) {
|
|
1018
|
+
return Cache$1.instance[namespace];
|
|
987
1019
|
}
|
|
988
|
-
Cache$1.instance = this;
|
|
1020
|
+
Cache$1.instance[namespace] = this;
|
|
989
1021
|
return this;
|
|
990
1022
|
}
|
|
991
1023
|
clean() {
|
|
@@ -994,11 +1026,33 @@ class Cache$1 {
|
|
|
994
1026
|
all() {
|
|
995
1027
|
return this.cache;
|
|
996
1028
|
}
|
|
997
|
-
|
|
998
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* Caching only a non-empty value.
|
|
1031
|
+
*
|
|
1032
|
+
* Useful for get or create strategy
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```javascript
|
|
1035
|
+
* const cache = new Cache();
|
|
1036
|
+
* const getItemFunc = () => fetch(url).then((data) => {
|
|
1037
|
+
* return data.json(); // undefined
|
|
1038
|
+
* });
|
|
1039
|
+
* const item = await cache.addFull('foo', getItemFunc);
|
|
1040
|
+
* if (!item) {
|
|
1041
|
+
* await createItem(); // 'New item'
|
|
1042
|
+
* }
|
|
1043
|
+
*
|
|
1044
|
+
* // somewhere else in the code
|
|
1045
|
+
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
1046
|
+
* console.log(resp); // 'New item'
|
|
1047
|
+
* })
|
|
1048
|
+
*
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
addFull(key, valueToSet, props) {
|
|
1052
|
+
return this.add(key, valueToSet, props, true);
|
|
999
1053
|
}
|
|
1000
|
-
add(key, valueToSet,
|
|
1001
|
-
const exist = this._find(key,
|
|
1054
|
+
add(key, valueToSet, props, onlyFull) {
|
|
1055
|
+
const exist = this._find(key, props);
|
|
1002
1056
|
if (!exist) {
|
|
1003
1057
|
let value;
|
|
1004
1058
|
if (valueToSet instanceof Function) {
|
|
@@ -1007,11 +1061,13 @@ class Cache$1 {
|
|
|
1007
1061
|
else {
|
|
1008
1062
|
value = valueToSet;
|
|
1009
1063
|
}
|
|
1010
|
-
const
|
|
1064
|
+
const props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
1011
1065
|
const cacheItem = {
|
|
1012
1066
|
key,
|
|
1013
1067
|
value,
|
|
1014
|
-
|
|
1068
|
+
props: props_,
|
|
1069
|
+
// TODO: remove backward compatibility use only props
|
|
1070
|
+
options: props_,
|
|
1015
1071
|
};
|
|
1016
1072
|
if (onlyFull && !full(value)) {
|
|
1017
1073
|
return value;
|
|
@@ -1019,13 +1075,13 @@ class Cache$1 {
|
|
|
1019
1075
|
this.cache.push(cacheItem);
|
|
1020
1076
|
if (value instanceof Promise) {
|
|
1021
1077
|
value.catch((er) => {
|
|
1022
|
-
this.delete(key,
|
|
1078
|
+
this.delete(key, props);
|
|
1023
1079
|
throw er;
|
|
1024
1080
|
});
|
|
1025
1081
|
if (onlyFull) {
|
|
1026
1082
|
value.then((x) => {
|
|
1027
1083
|
if (!full(x)) {
|
|
1028
|
-
this.delete(key,
|
|
1084
|
+
this.delete(key, props);
|
|
1029
1085
|
}
|
|
1030
1086
|
return x;
|
|
1031
1087
|
});
|
|
@@ -1038,24 +1094,24 @@ class Cache$1 {
|
|
|
1038
1094
|
return exist.value;
|
|
1039
1095
|
}
|
|
1040
1096
|
}
|
|
1041
|
-
match(key,
|
|
1042
|
-
const cacheRecord = this._find(key,
|
|
1097
|
+
match(key, props) {
|
|
1098
|
+
const cacheRecord = this._find(key, props);
|
|
1043
1099
|
if (cacheRecord) {
|
|
1044
1100
|
return cacheRecord.value;
|
|
1045
1101
|
}
|
|
1046
1102
|
}
|
|
1047
|
-
matchAll(key,
|
|
1103
|
+
matchAll(key, props) {
|
|
1048
1104
|
if (key) {
|
|
1049
1105
|
return this.cache
|
|
1050
|
-
.filter((x) => this._filter(x, key,
|
|
1106
|
+
.filter((x) => this._filter(x, key, props))
|
|
1051
1107
|
.map((x) => x.value);
|
|
1052
1108
|
}
|
|
1053
1109
|
return this.cache.map((x) => x.value);
|
|
1054
1110
|
}
|
|
1055
|
-
delete(keyOrItem,
|
|
1111
|
+
delete(keyOrItem, props) {
|
|
1056
1112
|
let exist = [];
|
|
1057
1113
|
if (typeof keyOrItem === 'string') {
|
|
1058
|
-
exist = this.cache.filter((x) => this._filter(x, keyOrItem,
|
|
1114
|
+
exist = this.cache.filter((x) => this._filter(x, keyOrItem, props));
|
|
1059
1115
|
}
|
|
1060
1116
|
else {
|
|
1061
1117
|
exist.push(keyOrItem);
|
|
@@ -1065,19 +1121,22 @@ class Cache$1 {
|
|
|
1065
1121
|
this.cache.splice(index, 1);
|
|
1066
1122
|
}
|
|
1067
1123
|
}
|
|
1068
|
-
_find(key,
|
|
1069
|
-
return this.cache.find((x) => this._filter(x, key,
|
|
1124
|
+
_find(key, props) {
|
|
1125
|
+
return this.cache.find((x) => this._filter(x, key, props));
|
|
1070
1126
|
}
|
|
1071
|
-
_filter(item, key,
|
|
1127
|
+
_filter(item, key, props) {
|
|
1072
1128
|
if (item.key === key) {
|
|
1073
|
-
if (
|
|
1074
|
-
|
|
1129
|
+
if (props) {
|
|
1130
|
+
// TODO: remove backward compatibility
|
|
1131
|
+
const itemProps = item.props || item.options;
|
|
1132
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
1075
1133
|
}
|
|
1076
1134
|
return true;
|
|
1077
1135
|
}
|
|
1078
1136
|
return false;
|
|
1079
1137
|
}
|
|
1080
|
-
}
|
|
1138
|
+
}
|
|
1139
|
+
Cache$1.instance = {};
|
|
1081
1140
|
|
|
1082
1141
|
/**
|
|
1083
1142
|
* Caching for asynchronous functions
|
|
@@ -1112,6 +1171,10 @@ class NetworkError extends Error {
|
|
|
1112
1171
|
}
|
|
1113
1172
|
}
|
|
1114
1173
|
|
|
1174
|
+
function isObject(val) {
|
|
1175
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1115
1178
|
let loadData;
|
|
1116
1179
|
// @ts-ignore
|
|
1117
1180
|
{
|
|
@@ -1145,7 +1208,7 @@ let loadData;
|
|
|
1145
1208
|
}
|
|
1146
1209
|
};
|
|
1147
1210
|
xhr.onload = () => {
|
|
1148
|
-
if ([401, 403, 404, 500].indexOf(xhr.status) !== -1) {
|
|
1211
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1149
1212
|
error(new NgwError(getResponseText()));
|
|
1150
1213
|
}
|
|
1151
1214
|
processingResponse();
|
|
@@ -1200,7 +1263,7 @@ let loadData;
|
|
|
1200
1263
|
data = new FormData();
|
|
1201
1264
|
data.append('file', options.file);
|
|
1202
1265
|
if (options.data) {
|
|
1203
|
-
for (const d in data) {
|
|
1266
|
+
for (const d in options.data) {
|
|
1204
1267
|
data.append(d, data[d]);
|
|
1205
1268
|
}
|
|
1206
1269
|
}
|
|
@@ -1286,10 +1349,6 @@ function removeConnector(connector) {
|
|
|
1286
1349
|
}
|
|
1287
1350
|
}
|
|
1288
1351
|
|
|
1289
|
-
function isObject(val) {
|
|
1290
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
1352
|
const exclude = ['description'];
|
|
1294
1353
|
/**
|
|
1295
1354
|
* @remarks
|
|
@@ -1514,7 +1573,7 @@ class ResourcesControl {
|
|
|
1514
1573
|
}
|
|
1515
1574
|
}
|
|
1516
1575
|
_fetchResourceById(id, requestOptions) {
|
|
1517
|
-
const promise = () => this.connector.get('resource.item', requestOptions, { id })
|
|
1576
|
+
const promise = () => this.connector.get('resource.item', requestOptions, { id });
|
|
1518
1577
|
return this.cache
|
|
1519
1578
|
.add('resource.item', promise, {
|
|
1520
1579
|
id,
|
|
@@ -1716,7 +1775,7 @@ class NgwConnector$1 {
|
|
|
1716
1775
|
headers: this.getAuthorizationHeaders(credentials),
|
|
1717
1776
|
// withCredentials: true
|
|
1718
1777
|
};
|
|
1719
|
-
// Do not use
|
|
1778
|
+
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
1720
1779
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
1721
1780
|
.then((data) => {
|
|
1722
1781
|
this.user = data;
|