@nextgis/geocoder 3.0.0-alpha.8 → 3.0.0-alpha.9
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 +85 -72
- 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 +85 -72
- 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 +85 -72
- 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 +85 -72
- 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 +21 -3
- package/package.json +2 -2
package/lib/geocoder.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.9; author: NextGIS */
|
|
2
2
|
var Geocoder = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -3128,56 +3128,69 @@ var Geocoder = (function (exports) {
|
|
|
3128
3128
|
};
|
|
3129
3129
|
class NominatimProvider extends BaseProvider {
|
|
3130
3130
|
constructor(options) {
|
|
3131
|
-
super(
|
|
3131
|
+
super();
|
|
3132
|
+
this.options = options;
|
|
3132
3133
|
__publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
|
|
3133
|
-
__publicField(this, "
|
|
3134
|
+
__publicField(this, "_abortControllers", []);
|
|
3134
3135
|
if (options && options.searchUrl) {
|
|
3135
3136
|
this.searchUrl = options.searchUrl;
|
|
3136
3137
|
}
|
|
3137
3138
|
}
|
|
3138
3139
|
abort() {
|
|
3139
|
-
this.
|
|
3140
|
-
|
|
3140
|
+
this._abortControllers.forEach((controller) => {
|
|
3141
|
+
controller.abort();
|
|
3142
|
+
});
|
|
3143
|
+
this._abortControllers = [];
|
|
3141
3144
|
}
|
|
3142
3145
|
search(val) {
|
|
3143
3146
|
return __asyncGenerator(this, null, function* () {
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
xhr.open("GET", url, true);
|
|
3151
|
-
xhr.onload = () => {
|
|
3152
|
-
try {
|
|
3153
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
3154
|
-
const features = geojson.features.map((x) => {
|
|
3155
|
-
return {
|
|
3156
|
-
geom: x,
|
|
3157
|
-
extent: x.bbox,
|
|
3158
|
-
text: x.properties && x.properties.display_name,
|
|
3159
|
-
query: val
|
|
3160
|
-
};
|
|
3161
|
-
});
|
|
3162
|
-
resolve(features);
|
|
3163
|
-
} catch (er) {
|
|
3164
|
-
reject(er);
|
|
3165
|
-
}
|
|
3166
|
-
};
|
|
3167
|
-
xhr.onerror = (er) => {
|
|
3168
|
-
reject(er);
|
|
3169
|
-
};
|
|
3170
|
-
this._abort.push(xhr.abort);
|
|
3171
|
-
xhr.send();
|
|
3172
|
-
}).catch((er) => {
|
|
3173
|
-
if (er.name === "CancelError") ;
|
|
3174
|
-
throw er;
|
|
3147
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3148
|
+
const params = new URLSearchParams({
|
|
3149
|
+
format: "geojson",
|
|
3150
|
+
polygon_geojson: "1",
|
|
3151
|
+
q: val,
|
|
3152
|
+
limit: ((_b = (_a = this.options) == null ? void 0 : _a.limit) == null ? void 0 : _b.toString()) || "10"
|
|
3175
3153
|
});
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3154
|
+
if ((_c = this.options) == null ? void 0 : _c.countrycodes) {
|
|
3155
|
+
params.append("countrycodes", this.options.countrycodes);
|
|
3156
|
+
}
|
|
3157
|
+
if ((_d = this.options) == null ? void 0 : _d.addressdetails) {
|
|
3158
|
+
params.append("addressdetails", "1");
|
|
3159
|
+
}
|
|
3160
|
+
if ((_e = this.options) == null ? void 0 : _e.language) {
|
|
3161
|
+
params.append("accept-language", this.options.language);
|
|
3162
|
+
}
|
|
3163
|
+
if ((_f = this.options) == null ? void 0 : _f.bounded) {
|
|
3164
|
+
params.append("bounded", "1");
|
|
3165
|
+
}
|
|
3166
|
+
if ((_g = this.options) == null ? void 0 : _g.viewbox) {
|
|
3167
|
+
const [minLon, minLat, maxLon, maxLat] = this.options.viewbox;
|
|
3168
|
+
params.append("viewbox", `${minLon},${minLat},${maxLon},${maxLat}`);
|
|
3169
|
+
}
|
|
3170
|
+
const url = fixUrlStr(`${this.searchUrl}/search?${params.toString()}`);
|
|
3171
|
+
const controller = new AbortController();
|
|
3172
|
+
this._abortControllers.push(controller);
|
|
3173
|
+
try {
|
|
3174
|
+
const response = yield new __await(fetch(url, { signal: controller.signal }));
|
|
3175
|
+
if (!response.ok) {
|
|
3176
|
+
throw new Error(`Network response was not ok: ${response.statusText}`);
|
|
3177
|
+
}
|
|
3178
|
+
const geojson = yield new __await(response.json());
|
|
3179
|
+
const features = geojson.features.map((x) => {
|
|
3180
|
+
return {
|
|
3181
|
+
geom: x,
|
|
3182
|
+
extent: x.bbox,
|
|
3183
|
+
text: x.properties && x.properties.display_name,
|
|
3184
|
+
query: val
|
|
3185
|
+
};
|
|
3186
|
+
});
|
|
3187
|
+
for (const item of features) {
|
|
3188
|
+
item.result = () => this.result(item);
|
|
3189
|
+
yield item;
|
|
3190
|
+
}
|
|
3191
|
+
} catch (error) {
|
|
3192
|
+
if (error.name === "AbortError") ; else {
|
|
3193
|
+
throw error;
|
|
3181
3194
|
}
|
|
3182
3195
|
}
|
|
3183
3196
|
});
|
|
@@ -3191,41 +3204,41 @@ var Geocoder = (function (exports) {
|
|
|
3191
3204
|
}
|
|
3192
3205
|
reverse(coordinates) {
|
|
3193
3206
|
return __asyncGenerator(this, null, function* () {
|
|
3207
|
+
var _a, _b;
|
|
3194
3208
|
const [lng, lat] = coordinates;
|
|
3195
|
-
const
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
const xhr = new XMLHttpRequest();
|
|
3200
|
-
xhr.open("GET", url, true);
|
|
3201
|
-
xhr.onload = () => {
|
|
3202
|
-
try {
|
|
3203
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
3204
|
-
const feature = geojson.features[0];
|
|
3205
|
-
const result = {
|
|
3206
|
-
geom: feature,
|
|
3207
|
-
extent: feature.bbox,
|
|
3208
|
-
text: feature.properties && feature.properties.display_name,
|
|
3209
|
-
query: `${lat}, ${lng}`
|
|
3210
|
-
};
|
|
3211
|
-
resolve(result);
|
|
3212
|
-
} catch (er) {
|
|
3213
|
-
reject(er);
|
|
3214
|
-
}
|
|
3215
|
-
};
|
|
3216
|
-
xhr.onerror = (er) => {
|
|
3217
|
-
reject(er);
|
|
3218
|
-
};
|
|
3219
|
-
this._abort.push(xhr.abort);
|
|
3220
|
-
xhr.send();
|
|
3221
|
-
}).catch((er) => {
|
|
3222
|
-
if (er.name === "CancelError") ;
|
|
3223
|
-
throw er;
|
|
3209
|
+
const params = new URLSearchParams({
|
|
3210
|
+
format: "geojson",
|
|
3211
|
+
lat: lat.toString(),
|
|
3212
|
+
lon: lng.toString()
|
|
3224
3213
|
});
|
|
3225
|
-
|
|
3226
|
-
|
|
3214
|
+
if ((_a = this.options) == null ? void 0 : _a.addressdetails) {
|
|
3215
|
+
params.append("addressdetails", "1");
|
|
3216
|
+
}
|
|
3217
|
+
if ((_b = this.options) == null ? void 0 : _b.language) {
|
|
3218
|
+
params.append("accept-language", this.options.language);
|
|
3219
|
+
}
|
|
3220
|
+
const url = fixUrlStr(`${this.searchUrl}/reverse?${params.toString()}`);
|
|
3221
|
+
const controller = new AbortController();
|
|
3222
|
+
this._abortControllers.push(controller);
|
|
3223
|
+
try {
|
|
3224
|
+
const response = yield new __await(fetch(url, { signal: controller.signal }));
|
|
3225
|
+
if (!response.ok) {
|
|
3226
|
+
throw new Error(`Network response was not ok: ${response.statusText}`);
|
|
3227
|
+
}
|
|
3228
|
+
const geojson = yield new __await(response.json());
|
|
3229
|
+
const feature = geojson.features[0];
|
|
3230
|
+
const item = {
|
|
3231
|
+
geom: feature,
|
|
3232
|
+
extent: feature.bbox,
|
|
3233
|
+
text: feature.properties && feature.properties.display_name,
|
|
3234
|
+
query: `${lat}, ${lng}`
|
|
3235
|
+
};
|
|
3227
3236
|
item.result = () => this.result(item);
|
|
3228
3237
|
yield item;
|
|
3238
|
+
} catch (error) {
|
|
3239
|
+
if (error.name === "AbortError") ; else {
|
|
3240
|
+
throw error;
|
|
3241
|
+
}
|
|
3229
3242
|
}
|
|
3230
3243
|
});
|
|
3231
3244
|
}
|