@nextgis/geocoder 1.19.1 → 2.0.0-alpha.0
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/README.md +1 -1
- package/lib/geocoder.cjs.js +345 -315
- package/lib/geocoder.cjs.js.map +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +2475 -2348
- 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 +505 -309
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +2768 -3112
- 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/lib/index.d.ts +226 -241
- package/package.json +8 -8
|
@@ -1,357 +1,553 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version:
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 2.0.0-alpha.0; author: NextGIS */
|
|
2
2
|
import CancelablePromise from '@nextgis/cancelable-promise';
|
|
3
3
|
import { objectAssign, fixUrlStr } from '@nextgis/utils';
|
|
4
4
|
import NgwConnector from '@nextgis/ngw-connector';
|
|
5
5
|
import { fetchNgwLayerItems } from '@nextgis/ngw-kit';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Represents the base class for a geocoder.
|
|
9
|
-
* This abstract class provides the basic methods that every geocoder should implement.
|
|
10
|
-
*
|
|
11
|
-
* @template O - The type of options that can be passed to the geocoder.
|
|
12
|
-
*/
|
|
13
7
|
class BaseGeocoder {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
8
|
+
constructor(options) {
|
|
9
|
+
if (options) {
|
|
10
|
+
objectAssign(this, options);
|
|
18
11
|
}
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
14
|
|
|
15
|
+
var __defProp$3 = Object.defineProperty;
|
|
16
|
+
var __defProps = Object.defineProperties;
|
|
17
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
18
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
19
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
20
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
21
|
+
var __knownSymbol$2 = (name, symbol) => {
|
|
22
|
+
return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
23
|
+
};
|
|
24
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
25
|
+
var __spreadValues$1 = (a, b) => {
|
|
26
|
+
for (var prop in b || (b = {}))
|
|
27
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
28
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
29
|
+
if (__getOwnPropSymbols$1)
|
|
30
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
31
|
+
if (__propIsEnum$1.call(b, prop))
|
|
32
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
33
|
+
}
|
|
34
|
+
return a;
|
|
35
|
+
};
|
|
36
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
37
|
+
var __publicField$3 = (obj, key, value) => {
|
|
38
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
var __async = (__this, __arguments, generator) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
var fulfilled = (value) => {
|
|
44
|
+
try {
|
|
45
|
+
step(generator.next(value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var rejected = (value) => {
|
|
51
|
+
try {
|
|
52
|
+
step(generator.throw(value));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
reject(e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
58
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var __await$2 = function(promise, isYieldStar) {
|
|
62
|
+
this[0] = promise;
|
|
63
|
+
this[1] = isYieldStar;
|
|
64
|
+
};
|
|
65
|
+
var __asyncGenerator$2 = (__this, __arguments, generator) => {
|
|
66
|
+
var resume = (k, v, yes, no) => {
|
|
67
|
+
try {
|
|
68
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await$2, done = x.done;
|
|
69
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
no(e);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
|
|
75
|
+
var it = {};
|
|
76
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol$2("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
77
|
+
};
|
|
78
|
+
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol$2("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol$2("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
21
79
|
let ID = 0;
|
|
22
80
|
class Geocoder extends BaseGeocoder {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
81
|
+
constructor(options) {
|
|
82
|
+
super(options);
|
|
83
|
+
__publicField$3(this, "providers", []);
|
|
84
|
+
if (options && options.providers) {
|
|
85
|
+
this.providers = options.providers;
|
|
29
86
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
87
|
+
}
|
|
88
|
+
abort() {
|
|
89
|
+
this.providers.forEach((x) => {
|
|
90
|
+
if (x.abort) {
|
|
91
|
+
x.abort();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
search(query) {
|
|
96
|
+
return __asyncGenerator$2(this, null, function* () {
|
|
97
|
+
this.abort();
|
|
98
|
+
let allProvidersFailed = true;
|
|
99
|
+
const errors = [];
|
|
100
|
+
for (const provider of this.providers) {
|
|
101
|
+
try {
|
|
102
|
+
const results = provider.search(query);
|
|
103
|
+
try {
|
|
104
|
+
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
105
|
+
const r = temp.value;
|
|
106
|
+
allProvidersFailed = false;
|
|
107
|
+
yield __spreadProps(__spreadValues$1({}, r), { provider, _id: ID++ });
|
|
34
108
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.abort();
|
|
39
|
-
let allProvidersFailed = true;
|
|
40
|
-
const errors = [];
|
|
41
|
-
for (const provider of this.providers) {
|
|
109
|
+
} catch (temp) {
|
|
110
|
+
error = [temp];
|
|
111
|
+
} finally {
|
|
42
112
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
const er = err;
|
|
51
|
-
if (er.name !== 'CancelError') {
|
|
52
|
-
errors.push(er);
|
|
53
|
-
}
|
|
113
|
+
more && (temp = iter.return) && (yield new __await$2(temp.call(iter)));
|
|
114
|
+
} finally {
|
|
115
|
+
if (error)
|
|
116
|
+
throw error[0];
|
|
54
117
|
}
|
|
118
|
+
}
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const er = err;
|
|
121
|
+
if (er.name !== "CancelError") {
|
|
122
|
+
errors.push(er);
|
|
123
|
+
}
|
|
55
124
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
125
|
+
}
|
|
126
|
+
if (allProvidersFailed && errors.length) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`All providers failed: ${errors.map((e) => e.message).join("; ")}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
result(item) {
|
|
134
|
+
if (item.provider) {
|
|
135
|
+
return item.provider.result(item);
|
|
59
136
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
137
|
+
return CancelablePromise.resolve(void 0);
|
|
138
|
+
}
|
|
139
|
+
reverse(coordinates) {
|
|
140
|
+
return __asyncGenerator$2(this, null, function* () {
|
|
141
|
+
for (const provider of this.providers) {
|
|
142
|
+
if (!provider.reverse) {
|
|
143
|
+
continue;
|
|
63
144
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
145
|
+
try {
|
|
146
|
+
const results = provider.reverse(coordinates);
|
|
147
|
+
try {
|
|
148
|
+
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
149
|
+
const r = temp.value;
|
|
150
|
+
yield __spreadProps(__spreadValues$1({}, r), { provider, _id: ID++ });
|
|
70
151
|
}
|
|
152
|
+
} catch (temp) {
|
|
153
|
+
error = [temp];
|
|
154
|
+
} finally {
|
|
71
155
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
catch (er) {
|
|
78
|
-
// Handle or log errors as needed
|
|
156
|
+
more && (temp = iter.return) && (yield new __await$2(temp.call(iter)));
|
|
157
|
+
} finally {
|
|
158
|
+
if (error)
|
|
159
|
+
throw error[0];
|
|
79
160
|
}
|
|
161
|
+
}
|
|
162
|
+
} catch (er) {
|
|
80
163
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns the first reverse geocoding result for given coordinates from any provider.
|
|
169
|
+
*
|
|
170
|
+
* @param coordinates - The longitude and latitude values.
|
|
171
|
+
* @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
|
|
172
|
+
*/
|
|
173
|
+
reverseGeocodeFirstResult(coordinates) {
|
|
174
|
+
return __async(this, null, function* () {
|
|
175
|
+
for (const provider of this.providers) {
|
|
176
|
+
if (typeof provider.reverse === "function") {
|
|
177
|
+
try {
|
|
178
|
+
try {
|
|
179
|
+
for (var iter = __forAwait(provider.reverse(coordinates)), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
180
|
+
const result = temp.value;
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
} catch (temp) {
|
|
184
|
+
error = [temp];
|
|
185
|
+
} finally {
|
|
186
|
+
try {
|
|
187
|
+
more && (temp = iter.return) && (yield temp.call(iter));
|
|
188
|
+
} finally {
|
|
189
|
+
if (error)
|
|
190
|
+
throw error[0];
|
|
191
|
+
}
|
|
99
192
|
}
|
|
193
|
+
} catch (error2) {
|
|
194
|
+
console.error("Error in reverse geocoding:", error2);
|
|
195
|
+
}
|
|
100
196
|
}
|
|
101
|
-
|
|
102
|
-
|
|
197
|
+
}
|
|
198
|
+
return void 0;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
103
201
|
}
|
|
104
202
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
203
|
+
var __defProp$2 = Object.defineProperty;
|
|
204
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
205
|
+
var __publicField$2 = (obj, key, value) => {
|
|
206
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
207
|
+
return value;
|
|
208
|
+
};
|
|
110
209
|
class BaseProvider extends BaseGeocoder {
|
|
210
|
+
constructor() {
|
|
211
|
+
super(...arguments);
|
|
212
|
+
/**
|
|
213
|
+
* URL endpoint for the search service.
|
|
214
|
+
* This is where queries will be sent to obtain search results.
|
|
215
|
+
*/
|
|
216
|
+
__publicField$2(this, "searchUrl");
|
|
217
|
+
/**
|
|
218
|
+
* Label to represent the provider.
|
|
219
|
+
* Useful for user interfaces to display the source of search results.
|
|
220
|
+
*/
|
|
221
|
+
__publicField$2(this, "label");
|
|
222
|
+
}
|
|
111
223
|
}
|
|
112
224
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
abort() {
|
|
131
|
-
this._abortControllers.forEach((a) => {
|
|
132
|
-
a.abort();
|
|
133
|
-
});
|
|
134
|
-
this._abortControllers.length = 0;
|
|
135
|
-
}
|
|
136
|
-
async *search(query) {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
const signal = this._makeSignal();
|
|
139
|
-
for (const config of this.searchResources) {
|
|
140
|
-
if (signal.aborted) {
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
const { searchMethod } = config;
|
|
144
|
-
const limit = (_a = config.limit) !== null && _a !== void 0 ? _a : NgwProvider.limit;
|
|
145
|
-
//
|
|
146
|
-
const resourceId = (_b = config.id) !== null && _b !== void 0 ? _b : config.resourceId;
|
|
147
|
-
try {
|
|
148
|
-
const resource = await this.connector.getResourceOrFail(resourceId, {
|
|
149
|
-
cache: true,
|
|
150
|
-
});
|
|
151
|
-
const options = {
|
|
152
|
-
connector: this.connector,
|
|
153
|
-
resourceId,
|
|
154
|
-
signal,
|
|
155
|
-
limit,
|
|
156
|
-
};
|
|
157
|
-
if (searchMethod === 'like') {
|
|
158
|
-
options.like = query;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
options.ilike = query;
|
|
162
|
-
}
|
|
163
|
-
const request = fetchNgwLayerItems(options);
|
|
164
|
-
const entries = await request;
|
|
165
|
-
for (const item of this._items({
|
|
166
|
-
entries,
|
|
167
|
-
query,
|
|
168
|
-
config,
|
|
169
|
-
resourceItem: resource,
|
|
170
|
-
})) {
|
|
171
|
-
item.result = () => this.result(item);
|
|
172
|
-
yield item;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch (er) {
|
|
176
|
-
if (er &&
|
|
177
|
-
'name' in er &&
|
|
178
|
-
er.name !== 'CancelError') {
|
|
179
|
-
console.warn(er);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
225
|
+
var __defProp$1 = Object.defineProperty;
|
|
226
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
227
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
228
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
229
|
+
var __knownSymbol$1 = (name, symbol) => {
|
|
230
|
+
return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
231
|
+
};
|
|
232
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
233
|
+
var __spreadValues = (a, b) => {
|
|
234
|
+
for (var prop in b || (b = {}))
|
|
235
|
+
if (__hasOwnProp.call(b, prop))
|
|
236
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
237
|
+
if (__getOwnPropSymbols)
|
|
238
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
239
|
+
if (__propIsEnum.call(b, prop))
|
|
240
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
183
241
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
242
|
+
return a;
|
|
243
|
+
};
|
|
244
|
+
var __publicField$1 = (obj, key, value) => {
|
|
245
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
246
|
+
return value;
|
|
247
|
+
};
|
|
248
|
+
var __await$1 = function(promise, isYieldStar) {
|
|
249
|
+
this[0] = promise;
|
|
250
|
+
this[1] = isYieldStar;
|
|
251
|
+
};
|
|
252
|
+
var __asyncGenerator$1 = (__this, __arguments, generator) => {
|
|
253
|
+
var resume = (k, v, yes, no) => {
|
|
254
|
+
try {
|
|
255
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await$1, done = x.done;
|
|
256
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
257
|
+
} catch (e) {
|
|
258
|
+
no(e);
|
|
199
259
|
}
|
|
200
|
-
|
|
201
|
-
|
|
260
|
+
};
|
|
261
|
+
var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
|
|
262
|
+
var it = {};
|
|
263
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol$1("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
264
|
+
};
|
|
265
|
+
const _NgwProvider = class _NgwProvider extends BaseProvider {
|
|
266
|
+
constructor(options) {
|
|
267
|
+
var _a;
|
|
268
|
+
super(options);
|
|
269
|
+
__publicField$1(this, "searchResources", []);
|
|
270
|
+
__publicField$1(this, "connector");
|
|
271
|
+
__publicField$1(this, "_abortControllers", []);
|
|
272
|
+
if (!options.searchUrl && !((_a = options.connectorOptions) == null ? void 0 : _a.baseUrl)) {
|
|
273
|
+
throw new Error(
|
|
274
|
+
"The `searchUrl` of `connectorOptions.baseUrl` are required"
|
|
275
|
+
);
|
|
202
276
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
277
|
+
this.connector = options.connector || new NgwConnector(__spreadValues({
|
|
278
|
+
baseUrl: this.searchUrl
|
|
279
|
+
}, options.connectorOptions));
|
|
280
|
+
this.searchResources = options.searchResources;
|
|
281
|
+
}
|
|
282
|
+
abort() {
|
|
283
|
+
this._abortControllers.forEach((a) => {
|
|
284
|
+
a.abort();
|
|
285
|
+
});
|
|
286
|
+
this._abortControllers.length = 0;
|
|
287
|
+
}
|
|
288
|
+
search(query) {
|
|
289
|
+
return __asyncGenerator$1(this, null, function* () {
|
|
290
|
+
var _a, _b;
|
|
291
|
+
const signal = this._makeSignal();
|
|
292
|
+
for (const config of this.searchResources) {
|
|
293
|
+
if (signal.aborted) {
|
|
294
|
+
break;
|
|
214
295
|
}
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
296
|
+
const { searchMethod } = config;
|
|
297
|
+
const limit = (_a = config.limit) != null ? _a : _NgwProvider.limit;
|
|
298
|
+
const resourceId = (_b = config.id) != null ? _b : config.resourceId;
|
|
299
|
+
try {
|
|
300
|
+
const resource = yield new __await$1(this.connector.getResourceOrFail(resourceId, {
|
|
301
|
+
cache: true
|
|
302
|
+
}));
|
|
303
|
+
const options = {
|
|
304
|
+
connector: this.connector,
|
|
305
|
+
resourceId,
|
|
306
|
+
signal,
|
|
307
|
+
limit
|
|
308
|
+
};
|
|
309
|
+
if (searchMethod === "like") {
|
|
310
|
+
options.like = query;
|
|
311
|
+
} else {
|
|
312
|
+
options.ilike = query;
|
|
313
|
+
}
|
|
314
|
+
const request = fetchNgwLayerItems(options);
|
|
315
|
+
const entries = yield new __await$1(request);
|
|
316
|
+
for (const item of this._items({
|
|
317
|
+
entries,
|
|
318
|
+
query,
|
|
319
|
+
config,
|
|
320
|
+
resourceItem: resource
|
|
321
|
+
})) {
|
|
322
|
+
item.result = () => this.result(item);
|
|
323
|
+
yield item;
|
|
324
|
+
}
|
|
325
|
+
} catch (er) {
|
|
326
|
+
if (er && "name" in er && er.name !== "CancelError") {
|
|
327
|
+
console.warn(er);
|
|
328
|
+
}
|
|
237
329
|
}
|
|
238
|
-
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
result(item) {
|
|
334
|
+
const signal = this._makeSignal();
|
|
335
|
+
const req = this.connector.get(
|
|
336
|
+
"feature_layer.feature.item_extent",
|
|
337
|
+
{ signal },
|
|
338
|
+
{
|
|
339
|
+
id: item.resourceId,
|
|
340
|
+
fid: item.featureId
|
|
341
|
+
}
|
|
342
|
+
).then((x) => {
|
|
343
|
+
const e = x.extent;
|
|
344
|
+
return {
|
|
345
|
+
text: item.text,
|
|
346
|
+
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat]
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
return req;
|
|
350
|
+
}
|
|
351
|
+
reverse(coordinates) {
|
|
352
|
+
return __asyncGenerator$1(this, null, function* () {
|
|
353
|
+
throw new Error("Not implemented");
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
_makeSignal() {
|
|
357
|
+
const abortController = new AbortController();
|
|
358
|
+
this._abortControllers.push(abortController);
|
|
359
|
+
return abortController.signal;
|
|
360
|
+
}
|
|
361
|
+
_items({
|
|
362
|
+
entries,
|
|
363
|
+
query,
|
|
364
|
+
config,
|
|
365
|
+
resourceItem
|
|
366
|
+
}) {
|
|
367
|
+
var _a;
|
|
368
|
+
const items = [];
|
|
369
|
+
let labelField = void 0;
|
|
370
|
+
if (resourceItem.feature_layer) {
|
|
371
|
+
labelField = (_a = resourceItem.feature_layer.fields.find(
|
|
372
|
+
(f) => f.label_field
|
|
373
|
+
)) == null ? void 0 : _a.keyname;
|
|
239
374
|
}
|
|
240
|
-
|
|
241
|
-
|
|
375
|
+
const meta = this.searchResources.find(
|
|
376
|
+
(x) => {
|
|
377
|
+
var _a2;
|
|
378
|
+
return (_a2 = x.id) != null ? _a2 : x.resourceId === resourceItem.resource.id;
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
if (meta) {
|
|
382
|
+
entries.forEach((entry) => {
|
|
383
|
+
let text = labelField ? entry.fields[labelField] : entry.id;
|
|
384
|
+
if (config.renderSearch) {
|
|
385
|
+
text = config.renderSearch({
|
|
386
|
+
item: entry,
|
|
387
|
+
resourceItem
|
|
388
|
+
});
|
|
389
|
+
} else if (labelField) {
|
|
390
|
+
text = entry.fields[labelField];
|
|
391
|
+
}
|
|
392
|
+
items.push({
|
|
393
|
+
query,
|
|
394
|
+
text,
|
|
395
|
+
featureId: entry.id,
|
|
396
|
+
resourceId: resourceItem.resource.id,
|
|
397
|
+
item: entry,
|
|
398
|
+
resourceItem
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
return items;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
__publicField$1(_NgwProvider, "limit", 300);
|
|
406
|
+
let NgwProvider = _NgwProvider;
|
|
242
407
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
408
|
+
var __defProp = Object.defineProperty;
|
|
409
|
+
var __knownSymbol = (name, symbol) => {
|
|
410
|
+
return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
411
|
+
};
|
|
412
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
413
|
+
var __publicField = (obj, key, value) => {
|
|
414
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
415
|
+
return value;
|
|
416
|
+
};
|
|
417
|
+
var __await = function(promise, isYieldStar) {
|
|
418
|
+
this[0] = promise;
|
|
419
|
+
this[1] = isYieldStar;
|
|
420
|
+
};
|
|
421
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
422
|
+
var resume = (k, v, yes, no) => {
|
|
423
|
+
try {
|
|
424
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
425
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
426
|
+
} catch (e) {
|
|
427
|
+
no(e);
|
|
248
428
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
429
|
+
};
|
|
430
|
+
var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
|
|
431
|
+
var it = {};
|
|
432
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
433
|
+
};
|
|
434
|
+
class NominatimProvider extends BaseProvider {
|
|
435
|
+
constructor(options) {
|
|
436
|
+
super(options);
|
|
437
|
+
__publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
|
|
438
|
+
__publicField(this, "_requests", []);
|
|
439
|
+
if (options && options.searchUrl) {
|
|
440
|
+
this.searchUrl = options.searchUrl;
|
|
252
441
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
442
|
+
}
|
|
443
|
+
abort() {
|
|
444
|
+
this._requests.forEach((x) => x.cancel());
|
|
445
|
+
this._requests = [];
|
|
446
|
+
}
|
|
447
|
+
search(val) {
|
|
448
|
+
return __asyncGenerator(this, null, function* () {
|
|
449
|
+
const url = fixUrlStr(
|
|
256
450
|
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
257
|
-
`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
};
|
|
278
|
-
xhr.onerror = (er) => {
|
|
279
|
-
reject(er);
|
|
280
|
-
};
|
|
281
|
-
onCancel(() => {
|
|
282
|
-
xhr.abort();
|
|
283
|
-
});
|
|
284
|
-
xhr.send();
|
|
285
|
-
}).catch((er) => {
|
|
286
|
-
if (er.name === 'CancelError') ;
|
|
287
|
-
throw er;
|
|
288
|
-
});
|
|
289
|
-
this._requests.push(request);
|
|
290
|
-
const items = await request;
|
|
291
|
-
if (items) {
|
|
292
|
-
for (const i of items) {
|
|
293
|
-
i.result = () => this.result(i);
|
|
294
|
-
yield i;
|
|
451
|
+
`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`
|
|
452
|
+
);
|
|
453
|
+
const request = new CancelablePromise(
|
|
454
|
+
(resolve, reject, onCancel) => {
|
|
455
|
+
const xhr = new XMLHttpRequest();
|
|
456
|
+
xhr.open("GET", url, true);
|
|
457
|
+
xhr.onload = () => {
|
|
458
|
+
try {
|
|
459
|
+
const geojson = JSON.parse(xhr.responseText);
|
|
460
|
+
const features = geojson.features.map((x) => {
|
|
461
|
+
return {
|
|
462
|
+
geom: x,
|
|
463
|
+
extent: x.bbox,
|
|
464
|
+
text: x.properties && x.properties.display_name,
|
|
465
|
+
query: val
|
|
466
|
+
};
|
|
467
|
+
});
|
|
468
|
+
resolve(features);
|
|
469
|
+
} catch (er) {
|
|
470
|
+
reject(er);
|
|
295
471
|
}
|
|
472
|
+
};
|
|
473
|
+
xhr.onerror = (er) => {
|
|
474
|
+
reject(er);
|
|
475
|
+
};
|
|
476
|
+
onCancel(() => {
|
|
477
|
+
xhr.abort();
|
|
478
|
+
});
|
|
479
|
+
xhr.send();
|
|
296
480
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const url = fixUrlStr(`${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`);
|
|
308
|
-
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
309
|
-
const xhr = new XMLHttpRequest();
|
|
310
|
-
xhr.open('GET', url, true);
|
|
311
|
-
xhr.onload = () => {
|
|
312
|
-
try {
|
|
313
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
314
|
-
const feature = geojson.features[0];
|
|
315
|
-
const result = {
|
|
316
|
-
geom: feature,
|
|
317
|
-
extent: feature.bbox,
|
|
318
|
-
text: feature.properties && feature.properties.display_name,
|
|
319
|
-
query: `${lat}, ${lng}`,
|
|
320
|
-
};
|
|
321
|
-
resolve(result);
|
|
322
|
-
}
|
|
323
|
-
catch (er) {
|
|
324
|
-
reject(er);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
xhr.onerror = (er) => {
|
|
328
|
-
reject(er);
|
|
329
|
-
};
|
|
330
|
-
onCancel(() => {
|
|
331
|
-
xhr.abort();
|
|
332
|
-
});
|
|
333
|
-
xhr.send();
|
|
334
|
-
}).catch((er) => {
|
|
335
|
-
if (er.name === 'CancelError') ;
|
|
336
|
-
throw er;
|
|
337
|
-
});
|
|
338
|
-
this._requests.push(request);
|
|
339
|
-
const item = await request;
|
|
340
|
-
if (item) {
|
|
341
|
-
item.result = () => this.result(item);
|
|
342
|
-
yield item;
|
|
481
|
+
).catch((er) => {
|
|
482
|
+
if (er.name === "CancelError") ;
|
|
483
|
+
throw er;
|
|
484
|
+
});
|
|
485
|
+
this._requests.push(request);
|
|
486
|
+
const items = yield new __await(request);
|
|
487
|
+
if (items) {
|
|
488
|
+
for (const i of items) {
|
|
489
|
+
i.result = () => this.result(i);
|
|
490
|
+
yield i;
|
|
343
491
|
}
|
|
344
|
-
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
result(model) {
|
|
496
|
+
return CancelablePromise.resolve({
|
|
497
|
+
text: model.text,
|
|
498
|
+
extent: model.extent || [],
|
|
499
|
+
geom: model.geom
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
reverse(coordinates) {
|
|
503
|
+
return __asyncGenerator(this, null, function* () {
|
|
504
|
+
const [lng, lat] = coordinates;
|
|
505
|
+
const url = fixUrlStr(
|
|
506
|
+
`${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`
|
|
507
|
+
);
|
|
508
|
+
const request = new CancelablePromise(
|
|
509
|
+
(resolve, reject, onCancel) => {
|
|
510
|
+
const xhr = new XMLHttpRequest();
|
|
511
|
+
xhr.open("GET", url, true);
|
|
512
|
+
xhr.onload = () => {
|
|
513
|
+
try {
|
|
514
|
+
const geojson = JSON.parse(xhr.responseText);
|
|
515
|
+
const feature = geojson.features[0];
|
|
516
|
+
const result = {
|
|
517
|
+
geom: feature,
|
|
518
|
+
extent: feature.bbox,
|
|
519
|
+
text: feature.properties && feature.properties.display_name,
|
|
520
|
+
query: `${lat}, ${lng}`
|
|
521
|
+
};
|
|
522
|
+
resolve(result);
|
|
523
|
+
} catch (er) {
|
|
524
|
+
reject(er);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
xhr.onerror = (er) => {
|
|
528
|
+
reject(er);
|
|
529
|
+
};
|
|
530
|
+
onCancel(() => {
|
|
531
|
+
xhr.abort();
|
|
532
|
+
});
|
|
533
|
+
xhr.send();
|
|
534
|
+
}
|
|
535
|
+
).catch((er) => {
|
|
536
|
+
if (er.name === "CancelError") ;
|
|
537
|
+
throw er;
|
|
538
|
+
});
|
|
539
|
+
this._requests.push(request);
|
|
540
|
+
const item = yield new __await(request);
|
|
541
|
+
if (item) {
|
|
542
|
+
item.result = () => this.result(item);
|
|
543
|
+
yield item;
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
345
547
|
}
|
|
346
548
|
|
|
347
|
-
/**
|
|
348
|
-
* Modern geocoder on async generators. May use different data providers.
|
|
349
|
-
*
|
|
350
|
-
* @packageDocumentation
|
|
351
|
-
* @module geocoder
|
|
352
|
-
*/
|
|
353
549
|
function create(options) {
|
|
354
|
-
|
|
550
|
+
return new Geocoder(options);
|
|
355
551
|
}
|
|
356
552
|
|
|
357
553
|
export { BaseProvider, Geocoder, NgwProvider, NominatimProvider, create };
|