@nextgis/geocoder 2.4.1 → 2.5.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/lib/geocoder.cjs.js +2 -2
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +19 -11
- 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 +2 -2
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +19 -11
- 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 +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 2.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 2.5.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';
|
|
@@ -32,7 +32,7 @@ var __spreadValues$1 = (a, b) => {
|
|
|
32
32
|
return a;
|
|
33
33
|
};
|
|
34
34
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
35
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj,
|
|
35
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
|
|
36
36
|
var __async = (__this, __arguments, generator) => {
|
|
37
37
|
return new Promise((resolve, reject) => {
|
|
38
38
|
var fulfilled = (value) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"@nextgis/cancelable-promise";import{objectAssign as r,fixUrlStr as t}from"@nextgis/utils";import o from"@nextgis/ngw-connector";import{fetchNgwLayerItems as n}from"@nextgis/ngw-kit";class s{constructor(e){e&&r(this,e)}}var i=Object.defineProperty,l=Object.defineProperties,a=Object.getOwnPropertyDescriptors,c=Object.getOwnPropertySymbols,u=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,f=(e,r)=>(r=Symbol[e])?r:Symbol.for("Symbol."+e),d=(e,r,t)=>r in e?i(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,
|
|
1
|
+
import e from"@nextgis/cancelable-promise";import{objectAssign as r,fixUrlStr as t}from"@nextgis/utils";import o from"@nextgis/ngw-connector";import{fetchNgwLayerItems as n}from"@nextgis/ngw-kit";class s{constructor(e){e&&r(this,e)}}var i=Object.defineProperty,l=Object.defineProperties,a=Object.getOwnPropertyDescriptors,c=Object.getOwnPropertySymbols,u=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,f=(e,r)=>(r=Symbol[e])?r:Symbol.for("Symbol."+e),d=(e,r,t)=>r in e?i(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,p=(e,r)=>{for(var t in r||(r={}))u.call(r,t)&&d(e,t,r[t]);if(c)for(var t of c(r))h.call(r,t)&&d(e,t,r[t]);return e},y=(e,r)=>l(e,a(r)),m=function(e,r){this[0]=e,this[1]=r},v=(e,r,t)=>{var o=(e,r,n,s)=>{try{var i=t[e](r),l=(r=i.value)instanceof m,a=i.done;Promise.resolve(l?r[0]:r).then((t=>l?o("return"===e?e:"next",r[1]?{done:t.done,value:t.value}:t,n,s):n({value:t,done:a}))).catch((e=>o("throw",e,n,s)))}catch(c){s(c)}},n=e=>s[e]=r=>new Promise(((t,n)=>o(e,r,t,n))),s={};return t=t.apply(e,r),s[f("asyncIterator")]=()=>s,n("next"),n("throw"),n("return"),s},b=(e,r,t)=>(r=e[f("asyncIterator")])?r.call(e):(e=e[f("iterator")](),r={},(t=(t,o)=>(o=e[t])&&(r[t]=r=>new Promise(((t,n,s)=>(r=o.call(e,r),s=r.done,Promise.resolve(r.value).then((e=>t({value:e,done:s})),n))))))("next"),t("return"),r);let w=0;class x extends s{constructor(e){super(e),d(this,"providers"+"",[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}search(e){return v(this,null,(function*(){this.abort();let r=!0;const t=[];for(const a of this.providers)try{const t=a.search(e);try{for(var o,n,s,i=b(t);o=!(n=yield new m(i.next())).done;o=!1){const e=n.value;r=!1,yield y(p({},e),{provider:a,_id:w++})}}catch(n){s=[n]}finally{try{o&&(n=i.return)&&(yield new m(n.call(i)))}finally{if(s)throw s[0]}}}catch(l){"CancelError"!==l.name&&t.push(l)}if(r&&t.length)throw new Error(`All providers failed: ${t.map((e=>e.message)).join("; ")}`)}))}result(r){return r.provider?r.provider.result(r):e.resolve(void 0)}reverse(e){return v(this,null,(function*(){for(const i of this.providers)if(i.reverse)try{const s=i.reverse(e);try{for(var r,t,o,n=b(s);r=!(t=yield new m(n.next())).done;r=!1){const e=t.value;yield y(p({},e),{provider:i,_id:w++})}}catch(t){o=[t]}finally{try{r&&(t=n.return)&&(yield new m(t.call(n)))}finally{if(o)throw o[0]}}}catch(s){}}))}reverseGeocodeFirstResult(e){return r=this,t=null,o=function*(){for(const i of this.providers)if("function"==typeof i.reverse)try{try{for(var r,t,o,n=b(i.reverse(e));r=!(t=yield n.next()).done;r=!1)return t.value}catch(t){o=[t]}finally{try{r&&(t=n.return)&&(yield t.call(n))}finally{if(o)throw o[0]}}}catch(s){console.error("Error in reverse geocoding:",s)}},new Promise(((e,n)=>{var s=e=>{try{l(o.next(e))}catch(r){n(r)}},i=e=>{try{l(o.throw(e))}catch(r){n(r)}},l=r=>r.done?e(r.value):Promise.resolve(r.value).then(s,i);l((o=o.apply(r,t)).next())}));var r,t,o}}var g=Object.defineProperty,_=(e,r,t)=>((e,r,t)=>r in e?g(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);class O extends s{constructor(){super(...arguments),_(this,"searchUrl"),_(this,"label")}}var P=Object.defineProperty,S=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,q=(e,r,t)=>r in e?P(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,E=(e,r,t)=>q(e,"symbol"!=typeof r?r+"":r,t),U=function(e,r){this[0]=e,this[1]=r},k=(e,r,t)=>{var o,n,s=(e,r,o,n)=>{try{var i=t[e](r),l=(r=i.value)instanceof U,a=i.done;Promise.resolve(l?r[0]:r).then((t=>l?s("return"===e?e:"next",r[1]?{done:t.done,value:t.value}:t,o,n):o({value:t,done:a}))).catch((e=>s("throw",e,o,n)))}catch(c){n(c)}},i=e=>l[e]=r=>new Promise(((t,o)=>s(e,r,t,o))),l={};return t=t.apply(e,r),l[(o="asyncIterator",(n=Symbol[o])?n:Symbol.for("Symbol."+o))]=()=>l,i("next"),i("throw"),i("return"),l};const R=class e extends O{constructor(e){var r;if(super(e),E(this,"searchResources",[]),E(this,"connector"),E(this,"_abortControllers",[]),!e.searchUrl&&!(null==(r=e.connectorOptions)?void 0:r.baseUrl))throw new Error("The `searchUrl` of `connectorOptions.baseUrl` are required");this.connector=e.connector||new o(((e,r)=>{for(var t in r||(r={}))I.call(r,t)&&q(e,t,r[t]);if(S)for(var t of S(r))j.call(r,t)&&q(e,t,r[t]);return e})({baseUrl:this.searchUrl},e.connectorOptions)),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}search(r){return k(this,null,(function*(){var t,o;const s=this._makeSignal();for(const l of this.searchResources){if(s.aborted)break;const{searchMethod:a}=l,c=null!=(t=l.limit)?t:e.limit,u=null!=(o=l.id)?o:l.resourceId;try{const e=yield new U(this.connector.getResourceOrFail(u,{cache:!0})),t={connector:this.connector,resourceId:u,signal:s,limit:c};"like"===a?t.like=r:t.ilike=r;const o=n(t),i=yield new U(o);for(const n of this._items({entries:i,query:r,config:l,resourceItem:e}))n.result=()=>this.result(n),yield n}catch(i){i&&"name"in i&&"CancelError"!==i.name&&console.warn(i)}}}))}result(e){const r=this._makeSignal();return this.connector.get("feature_layer.feature.item_extent",{signal:r},{id:e.resourceId,fid:e.featureId}).then((r=>{const t=r.extent;return{text:e.text,extent:[t.minLon,t.minLat,t.maxLon,t.maxLat]}}))}reverse(e){return k(this,null,(function*(){throw new Error("Not implemented")}))}_makeSignal(){const e=new AbortController;return this._abortControllers.push(e),e.signal}_items({entries:e,query:r,config:t,resourceItem:o}){var n;const s=[];let i;o.feature_layer&&(i=null==(n=o.feature_layer.fields.find((e=>e.label_field)))?void 0:n.keyname);return this.searchResources.find((e=>{var r;return null!=(r=e.id)?r:e.resourceId===o.resource.id}))&&e.forEach((e=>{let n=i?e.fields[i]:e.id;t.renderSearch?n=t.renderSearch({item:e,resourceItem:o}):i&&(n=e.fields[i]),s.push({query:r,text:n,featureId:e.id,resourceId:o.resource.id,item:e,resourceItem:o})})),s}};E(R,"limit",300);let $=R;var C=Object.defineProperty,L=(e,r,t)=>((e,r,t)=>r in e?C(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t),T=function(e,r){this[0]=e,this[1]=r},G=(e,r,t)=>{var o,n,s=(e,r,o,n)=>{try{var i=t[e](r),l=(r=i.value)instanceof T,a=i.done;Promise.resolve(l?r[0]:r).then((t=>l?s("return"===e?e:"next",r[1]?{done:t.done,value:t.value}:t,o,n):o({value:t,done:a}))).catch((e=>s("throw",e,o,n)))}catch(c){n(c)}},i=e=>l[e]=r=>new Promise(((t,o)=>s(e,r,t,o))),l={};return t=t.apply(e,r),l[(o="asyncIterator",(n=Symbol[o])?n:Symbol.for("Symbol."+o))]=()=>l,i("next"),i("throw"),i("return"),l};class M extends O{constructor(e){super(e),L(this,"searchUrl","https://nominatim.openstreetmap.org"),L(this,"_requests",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}search(r){return G(this,null,(function*(){const o=t(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${r}`),n=new e(((e,t,n)=>{const s=new XMLHttpRequest;s.open("GET",o,!0),s.onload=()=>{try{const t=JSON.parse(s.responseText).features.map((e=>({geom:e,extent:e.bbox,text:e.properties&&e.properties.display_name,query:r})));e(t)}catch(o){t(o)}},s.onerror=e=>{t(e)},n((()=>{s.abort()})),s.send()})).catch((e=>{throw e}));this._requests.push(n);const s=yield new T(n);if(s)for(const e of s)e.result=()=>this.result(e),yield e}))}result(r){return e.resolve({text:r.text,extent:r.extent||[],geom:r.geom})}reverse(r){return G(this,null,(function*(){const[o,n]=r,s=t(`${this.searchUrl}/reverse?format=geojson&lat=${n}&lon=${o}`),i=new e(((e,r,t)=>{const i=new XMLHttpRequest;i.open("GET",s,!0),i.onload=()=>{try{const r=JSON.parse(i.responseText).features[0];e({geom:r,extent:r.bbox,text:r.properties&&r.properties.display_name,query:`${n}, ${o}`})}catch(t){r(t)}},i.onerror=e=>{r(e)},t((()=>{i.abort()})),i.send()})).catch((e=>{throw e}));this._requests.push(i);const l=yield new T(i);l&&(l.result=()=>this.result(l),yield l)}))}}function N(e){return new x(e)}export{O as BaseProvider,x as Geocoder,$ as NgwProvider,M as NominatimProvider,N as create};
|
|
2
2
|
//# sourceMappingURL=geocoder.esm-bundler.prod.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geocoder.esm-bundler.prod.js","sources":["../src/BaseGeocoder.ts","../src/Geocoder.ts","../src/providers/BaseProvider.ts","../src/providers/NgwProvider.ts","../src/providers/NominatimProvider.ts","../src/index.ts"],"sourcesContent":["import { objectAssign } from '@nextgis/utils';\n\nimport type { SearchItem } from './types/SearchItem';\nimport type CancelablePromise from '@nextgis/cancelable-promise';\nimport type { LngLatArray } from '@nextgis/utils';\n\n/**\n * Represents the base class for a geocoder.\n * This abstract class provides the basic methods that every geocoder should implement.\n *\n * @template O - The type of options that can be passed to the geocoder.\n */\nexport abstract class BaseGeocoder<\n O extends Record<string, any> = Record<string, any>,\n> {\n constructor(options?: O) {\n if (options) {\n objectAssign(this, options);\n }\n }\n\n /**\n * Search method to retrieve geocoding results.\n *\n * @abstract\n * @param query - The search string to geocode.\n * @yields An async generator that yields search results.\n */\n abstract search(query: string): AsyncGenerator<SearchItem>;\n\n /**\n * Method to retrieve detailed result for a specific search item.\n *\n * @abstract\n * @param item - The search item to get detailed result for.\n * @returns A promise that resolves to the detailed result.\n */\n abstract result(item: SearchItem): CancelablePromise<any>;\n\n /**\n * Method for reverse geocoding.\n * Takes coordinates and returns the corresponding address or location information.\n *\n * @abstract\n * @param coordinates - The longitude and latitude values.\n * @returns An async generator that yields reverse geocoding results.\n */\n abstract reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem>;\n\n /**\n * Optional method to abort any ongoing geocoding requests.\n *\n * @abstract\n */\n abstract abort?(): void;\n}\n","import CancelablePromise from '@nextgis/cancelable-promise';\n\nimport { BaseGeocoder } from './BaseGeocoder';\n\nimport type { GeocoderOptions } from './GeocoderOptions';\nimport type { BaseProvider } from './providers/BaseProvider';\nimport type { SearchItem } from './types/SearchItem';\nimport type { LngLatArray } from '@nextgis/utils';\n\nlet ID = 0;\n\nexport class Geocoder extends BaseGeocoder<GeocoderOptions> {\n providers: BaseProvider[] = [];\n\n constructor(options: GeocoderOptions) {\n super(options);\n if (options && options.providers) {\n this.providers = options.providers;\n }\n }\n\n abort(): void {\n this.providers.forEach((x) => {\n if (x.abort) {\n x.abort();\n }\n });\n }\n\n async *search(query: string): AsyncGenerator<SearchItem, void, unknown> {\n this.abort();\n let allProvidersFailed = true;\n const errors: Error[] = [];\n\n for (const provider of this.providers) {\n try {\n const results = provider.search(query);\n\n for await (const r of results) {\n allProvidersFailed = false;\n yield { ...r, provider, _id: ID++ };\n }\n } catch (err) {\n const er = err as Error;\n if (er.name !== 'CancelError') {\n errors.push(er);\n }\n }\n }\n\n if (allProvidersFailed && errors.length) {\n throw new Error(\n `All providers failed: ${errors.map((e) => e.message).join('; ')}`,\n );\n }\n }\n\n result(item: SearchItem): CancelablePromise<any> {\n if (item.provider) {\n return item.provider.result(item);\n }\n return CancelablePromise.resolve(undefined);\n }\n\n async *reverse(\n coordinates: LngLatArray,\n ): AsyncGenerator<SearchItem, void, unknown> {\n for (const provider of this.providers) {\n if (!provider.reverse) {\n continue;\n }\n\n try {\n const results = provider.reverse(coordinates);\n\n for await (const r of results) {\n yield { ...r, provider, _id: ID++ };\n }\n } catch (er) {\n // Handle or log errors as needed\n }\n }\n }\n\n /**\n * Returns the first reverse geocoding result for given coordinates from any provider.\n *\n * @param coordinates - The longitude and latitude values.\n * @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.\n */\n async reverseGeocodeFirstResult(\n coordinates: LngLatArray,\n ): Promise<SearchItem | undefined> {\n for (const provider of this.providers) {\n if (typeof provider.reverse === 'function') {\n try {\n for await (const result of provider.reverse(coordinates)) {\n return result;\n }\n } catch (error) {\n console.error('Error in reverse geocoding:', error);\n }\n }\n }\n return undefined;\n }\n}\n","import { BaseGeocoder } from '../BaseGeocoder';\n\nimport type { BaseProviderOptions } from './BaseProviderOptions';\n\n/**\n * Abstract base class representing a search provider.\n * It builds upon the BaseGeocoder functionalities with provider-specific properties.\n * @template O - Options type which extends BaseProviderOptions.\n */\nexport abstract class BaseProvider<\n O extends BaseProviderOptions = BaseProviderOptions,\n> extends BaseGeocoder<O> {\n /**\n * URL endpoint for the search service.\n * This is where queries will be sent to obtain search results.\n */\n searchUrl?: string;\n\n /**\n * Label to represent the provider.\n * Useful for user interfaces to display the source of search results.\n */\n label?: string;\n}\n","import NgwConnector from '@nextgis/ngw-connector';\nimport { fetchNgwLayerItems } from '@nextgis/ngw-kit';\n\nimport { BaseProvider } from './BaseProvider';\n\nimport type { BaseProviderOptions } from './BaseProviderOptions';\nimport type { ResultItem } from '../types/ResultItem';\nimport type { SearchItem } from '../types/SearchItem';\nimport type CancelablePromise from '@nextgis/cancelable-promise';\nimport type {\n FeatureItem,\n NgwConnectorOptions,\n ResourceItem,\n} from '@nextgis/ngw-connector';\nimport type { FetchNgwItemsOptions } from '@nextgis/ngw-kit';\nimport type { LngLatArray } from '@nextgis/utils';\n\n/**\n * Extends the basic search item with NGW-specific properties.\n */\ninterface NgwSearchItem extends SearchItem {\n /** ID of the NGW resource */\n resourceId: number;\n /** ID of the feature in the NGW resource */\n featureId: number;\n /** The specific feature item from NGW */\n item: FeatureItem;\n /** The NGW resource item */\n resourceItem: ResourceItem;\n}\n\n/**\n * Defines the structure for a rendered search item.\n */\ninterface RenderSearchItem {\n /** The specific feature item */\n item: FeatureItem;\n /** The NGW resource item */\n resourceItem: ResourceItem;\n}\n\n/**\n * Options for searching within a NGW resource.\n */\ninterface SearchResource extends FetchNgwItemsOptions {\n /** The search method used ('ilike' is case-insensitive) */\n searchMethod?: 'ilike' | 'like';\n /** Custom rendering function for search results */\n renderSearch?: (item: RenderSearchItem) => string | HTMLElement;\n}\n\n/**\n * Options required to initialize an NGW provider.\n */\ninterface NgwProviderOptions extends BaseProviderOptions {\n /** Connector instance for NGW. If not provided, will be created internally */\n connector?: NgwConnector;\n /** List of NGW resources to search within */\n searchResources: SearchResource[];\n /** Options for the internal NgwConnector (if one needs to be created) */\n connectorOptions?: NgwConnectorOptions;\n}\n\nexport class NgwProvider extends BaseProvider<NgwProviderOptions> {\n static limit = 300;\n\n searchResources: SearchResource[] = [];\n\n private connector: NgwConnector;\n private _abortControllers: AbortController[] = [];\n\n constructor(options: NgwProviderOptions) {\n super(options);\n if (!options.searchUrl && !options.connectorOptions?.baseUrl) {\n throw new Error(\n 'The `searchUrl` of `connectorOptions.baseUrl` are required',\n );\n }\n\n this.connector =\n options.connector ||\n new NgwConnector({\n baseUrl: this.searchUrl,\n ...options.connectorOptions,\n });\n this.searchResources = options.searchResources;\n }\n\n abort(): void {\n this._abortControllers.forEach((a) => {\n a.abort();\n });\n this._abortControllers.length = 0;\n }\n\n async *search(query: string): AsyncGenerator<NgwSearchItem, void, unknown> {\n const signal = this._makeSignal();\n for (const config of this.searchResources) {\n if (signal.aborted) {\n break;\n }\n const { searchMethod } = config;\n\n const limit = config.limit ?? NgwProvider.limit;\n //\n const resourceId = (config as any).id ?? config.resourceId;\n\n try {\n const resource = await this.connector.getResourceOrFail(resourceId, {\n cache: true,\n });\n\n const options: FetchNgwItemsOptions = {\n connector: this.connector,\n resourceId,\n signal,\n limit,\n };\n\n if (searchMethod === 'like') {\n options.like = query;\n } else {\n options.ilike = query;\n }\n\n const request = fetchNgwLayerItems(options);\n\n const entries = await request;\n\n for (const item of this._items({\n entries,\n query,\n config,\n resourceItem: resource,\n })) {\n item.result = () => this.result(item);\n yield item;\n }\n } catch (er) {\n if (\n er &&\n 'name' in (er as Error) &&\n (er as Error).name !== 'CancelError'\n ) {\n console.warn(er);\n }\n }\n }\n }\n\n result(item: NgwSearchItem): CancelablePromise<ResultItem> {\n const signal = this._makeSignal();\n const req = this.connector\n .get(\n 'feature_layer.feature.item_extent',\n { signal },\n {\n id: item.resourceId,\n fid: item.featureId,\n },\n )\n .then((x) => {\n const e = x.extent;\n return {\n text: item.text,\n extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],\n };\n });\n return req;\n }\n\n async *reverse(\n coordinates: LngLatArray,\n ): AsyncGenerator<SearchItem, void, unknown> {\n throw new Error('Not implemented');\n yield undefined as any;\n }\n\n private _makeSignal() {\n const abortController = new AbortController();\n this._abortControllers.push(abortController);\n return abortController.signal;\n }\n\n private _items({\n entries,\n query,\n config,\n resourceItem,\n }: {\n config: SearchResource;\n entries: FeatureItem[];\n query: string;\n resourceItem: ResourceItem;\n }): NgwSearchItem[] {\n const items: NgwSearchItem[] = [];\n\n let labelField: string | undefined = undefined;\n\n if (resourceItem.feature_layer) {\n labelField = resourceItem.feature_layer.fields.find(\n (f) => f.label_field,\n )?.keyname;\n }\n\n const meta = this.searchResources.find(\n (x) => (x as any).id ?? x.resourceId === resourceItem.resource.id,\n );\n if (meta) {\n entries.forEach((entry) => {\n let text = labelField ? entry.fields[labelField] : entry.id;\n if (config.renderSearch) {\n text = config.renderSearch({\n item: entry,\n resourceItem,\n });\n } else if (labelField) {\n text = entry.fields[labelField];\n }\n\n items.push({\n query: query,\n text,\n featureId: entry.id,\n resourceId: resourceItem.resource.id,\n item: entry,\n resourceItem,\n });\n });\n }\n return items;\n }\n}\n","import CancelablePromise from '@nextgis/cancelable-promise';\nimport { fixUrlStr } from '@nextgis/utils';\n\nimport { BaseProvider } from './BaseProvider';\n\nimport type { BaseProviderOptions } from './BaseProviderOptions';\nimport type { ResultItem } from '../types/ResultItem';\nimport type { SearchItem } from '../types/SearchItem';\nimport type { LngLatArray } from '@nextgis/utils';\nimport type { FeatureCollection } from 'geojson';\n\nexport class NominatimProvider extends BaseProvider {\n searchUrl = 'https://nominatim.openstreetmap.org';\n\n private _requests: CancelablePromise[] = [];\n\n constructor(options?: BaseProviderOptions) {\n super(options);\n if (options && options.searchUrl) {\n this.searchUrl = options.searchUrl;\n }\n }\n\n abort(): void {\n this._requests.forEach((x) => x.cancel());\n this._requests = [];\n }\n\n async *search(val: string): AsyncGenerator<SearchItem, void, unknown> {\n // RFC2616 accept - language string\n const url = fixUrlStr(\n // `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`\n `${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`,\n );\n const request = new CancelablePromise<SearchItem[]>(\n (resolve, reject, onCancel) => {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', url, true);\n xhr.onload = () => {\n try {\n const geojson = JSON.parse(xhr.responseText) as FeatureCollection;\n const features: SearchItem[] = geojson.features.map((x) => {\n return {\n geom: x,\n extent: x.bbox,\n text: x.properties && x.properties.display_name,\n query: val,\n };\n });\n resolve(features);\n } catch (er) {\n reject(er);\n }\n };\n\n xhr.onerror = (er) => {\n reject(er);\n };\n\n onCancel(() => {\n xhr.abort();\n });\n\n xhr.send();\n },\n ).catch((er) => {\n if (er.name === 'CancelError') {\n //\n }\n throw er;\n });\n this._requests.push(request);\n const items = await request;\n if (items) {\n for (const i of items) {\n i.result = () => this.result(i);\n yield i;\n }\n }\n }\n\n result(model: SearchItem): CancelablePromise<ResultItem> {\n return CancelablePromise.resolve({\n text: model.text,\n extent: model.extent || [],\n geom: model.geom,\n });\n }\n\n async *reverse(\n coordinates: LngLatArray,\n ): AsyncGenerator<SearchItem, void, unknown> {\n const [lng, lat] = coordinates;\n const url = fixUrlStr(\n `${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`,\n );\n const request = new CancelablePromise<SearchItem>(\n (resolve, reject, onCancel) => {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', url, true);\n xhr.onload = () => {\n try {\n const geojson = JSON.parse(xhr.responseText) as FeatureCollection;\n const feature = geojson.features[0];\n const result: SearchItem = {\n geom: feature,\n extent: feature.bbox,\n text: feature.properties && feature.properties.display_name,\n query: `${lat}, ${lng}`,\n };\n resolve(result);\n } catch (er) {\n reject(er);\n }\n };\n xhr.onerror = (er) => {\n reject(er);\n };\n\n onCancel(() => {\n xhr.abort();\n });\n\n xhr.send();\n },\n ).catch((er) => {\n if (er.name === 'CancelError') {\n //\n }\n throw er;\n });\n this._requests.push(request);\n const item = await request;\n if (item) {\n item.result = () => this.result(item);\n yield item;\n }\n }\n}\n","import { Geocoder } from './Geocoder';\n\nimport type { GeocoderOptions } from './GeocoderOptions';\n\nexport { Geocoder, GeocoderOptions };\nexport { BaseProvider } from './providers/BaseProvider';\nexport { NgwProvider } from './providers/NgwProvider';\nexport { NominatimProvider } from './providers/NominatimProvider';\n\nexport * from './providers/BaseProviderOptions';\nexport * from './types/ResultItem';\nexport * from './types/SearchItem';\n\nexport function create(options: GeocoderOptions): Geocoder {\n return new Geocoder(options);\n}\n"],"names":["BaseGeocoder","constructor","options","objectAssign","this","ID","Geocoder","super","providers","abort","forEach","x","search","query","__asyncGenerator","allProvidersFailed","errors","provider","results","more","temp","error","iter","__forAwait","__await","next","done","r","value","__spreadProps","__spreadValues","_id","return","call","err","name","push","length","Error","map","e","message","join","result","item","CancelablePromise","resolve","reverse","coordinates","er","reverseGeocodeFirstResult","console","BaseProvider","arguments","__publicField","_NgwProvider","_a","searchUrl","connectorOptions","baseUrl","connector","NgwConnector","searchResources","_abortControllers","a","_b","signal","_makeSignal","config","aborted","searchMethod","limit","resourceId","id","resource","getResourceOrFail","cache","like","ilike","request","fetchNgwLayerItems","entries","_items","resourceItem","warn","get","fid","featureId","then","extent","text","minLon","minLat","maxLon","maxLat","abortController","AbortController","items","labelField","feature_layer","fields","find","f","label_field","keyname","entry","renderSearch","NgwProvider","NominatimProvider","_requests","cancel","val","url","fixUrlStr","reject","onCancel","xhr","XMLHttpRequest","open","onload","features","JSON","parse","responseText","geom","bbox","properties","display_name","onerror","send","catch","i","model","lng","lat","feature","create"],"mappings":"oMAYO,MAAeA,EAGpB,WAAAC,CAAYC,GACNA,GACFC,EAAaC,KAAMF,EAEvB,omCCVF,IAAIG,EAAK,EAEF,MAAMC,UAAiBN,EAG5B,WAAAC,CAAYC,SACVK,MAAML,KAHRE,wBAAA,oBAA4B,IAItBF,GAAWA,EAAQM,YACrBJ,KAAKI,UAAYN,EAAQM,UAE7B,CAEA,KAAAC,GACOL,KAAAI,UAAUE,SAASC,IAClBA,EAAEF,OACJE,EAAEF,OACJ,GAEJ,CAEO,MAAAG,CAAOC,GAA0D,OAAAC,EAAAV,KAAA,MAAA,YACtEA,KAAKK,QACL,IAAIM,GAAqB,EACzB,MAAMC,EAAkB,GAEb,IAAA,MAAAC,KAAYb,KAAKI,UACtB,IACI,MAAAU,EAAUD,EAASL,OAAOC,GAEhC,IAAA,IAAA,IAAAM,EAA+BC,EAAAC,EAA/BC,EAAAC,EAAsBL,GAASC,IAAAC,QAAA,IAAAI,EAAAF,EAAAG,SAAAC,KAAAP,GAA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,EAAIa,MAAK,IAEXC,OAAOjF,IAID,MAAAA,CAAA,IAEH7C,KAAAyG,UAAUzE,KAAK2C,GACpB,MAAMnC,QAAa,IAAApB,EAAAuD,GACfnC,IACFA,EAAKD,OAAS,IAAMvC,KAAKuC,OAAOC,SAC1BA,EACR,GACF,EC5HK,SAAS4F,EAAOtI,GACd,OAAA,IAAII,EAASJ,EACtB"}
|
|
1
|
+
{"version":3,"file":"geocoder.esm-bundler.prod.js","sources":["../src/BaseGeocoder.ts","../src/Geocoder.ts","../src/providers/BaseProvider.ts","../src/providers/NgwProvider.ts","../src/providers/NominatimProvider.ts","../src/index.ts"],"sourcesContent":["import { objectAssign } from '@nextgis/utils';\n\nimport type { SearchItem } from './types/SearchItem';\nimport type CancelablePromise from '@nextgis/cancelable-promise';\nimport type { LngLatArray } from '@nextgis/utils';\n\n/**\n * Represents the base class for a geocoder.\n * This abstract class provides the basic methods that every geocoder should implement.\n *\n * @template O - The type of options that can be passed to the geocoder.\n */\nexport abstract class BaseGeocoder<\n O extends Record<string, any> = Record<string, any>,\n> {\n constructor(options?: O) {\n if (options) {\n objectAssign(this, options);\n }\n }\n\n /**\n * Search method to retrieve geocoding results.\n *\n * @abstract\n * @param query - The search string to geocode.\n * @yields An async generator that yields search results.\n */\n abstract search(query: string): AsyncGenerator<SearchItem>;\n\n /**\n * Method to retrieve detailed result for a specific search item.\n *\n * @abstract\n * @param item - The search item to get detailed result for.\n * @returns A promise that resolves to the detailed result.\n */\n abstract result(item: SearchItem): CancelablePromise<any>;\n\n /**\n * Method for reverse geocoding.\n * Takes coordinates and returns the corresponding address or location information.\n *\n * @abstract\n * @param coordinates - The longitude and latitude values.\n * @returns An async generator that yields reverse geocoding results.\n */\n abstract reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem>;\n\n /**\n * Optional method to abort any ongoing geocoding requests.\n *\n * @abstract\n */\n abstract abort?(): void;\n}\n","import CancelablePromise from '@nextgis/cancelable-promise';\n\nimport { BaseGeocoder } from './BaseGeocoder';\n\nimport type { GeocoderOptions } from './GeocoderOptions';\nimport type { BaseProvider } from './providers/BaseProvider';\nimport type { SearchItem } from './types/SearchItem';\nimport type { LngLatArray } from '@nextgis/utils';\n\nlet ID = 0;\n\nexport class Geocoder extends BaseGeocoder<GeocoderOptions> {\n providers: BaseProvider[] = [];\n\n constructor(options: GeocoderOptions) {\n super(options);\n if (options && options.providers) {\n this.providers = options.providers;\n }\n }\n\n abort(): void {\n this.providers.forEach((x) => {\n if (x.abort) {\n x.abort();\n }\n });\n }\n\n async *search(query: string): AsyncGenerator<SearchItem, void, unknown> {\n this.abort();\n let allProvidersFailed = true;\n const errors: Error[] = [];\n\n for (const provider of this.providers) {\n try {\n const results = provider.search(query);\n\n for await (const r of results) {\n allProvidersFailed = false;\n yield { ...r, provider, _id: ID++ };\n }\n } catch (err) {\n const er = err as Error;\n if (er.name !== 'CancelError') {\n errors.push(er);\n }\n }\n }\n\n if (allProvidersFailed && errors.length) {\n throw new Error(\n `All providers failed: ${errors.map((e) => e.message).join('; ')}`,\n );\n }\n }\n\n result(item: SearchItem): CancelablePromise<any> {\n if (item.provider) {\n return item.provider.result(item);\n }\n return CancelablePromise.resolve(undefined);\n }\n\n async *reverse(\n coordinates: LngLatArray,\n ): AsyncGenerator<SearchItem, void, unknown> {\n for (const provider of this.providers) {\n if (!provider.reverse) {\n continue;\n }\n\n try {\n const results = provider.reverse(coordinates);\n\n for await (const r of results) {\n yield { ...r, provider, _id: ID++ };\n }\n } catch (er) {\n // Handle or log errors as needed\n }\n }\n }\n\n /**\n * Returns the first reverse geocoding result for given coordinates from any provider.\n *\n * @param coordinates - The longitude and latitude values.\n * @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.\n */\n async reverseGeocodeFirstResult(\n coordinates: LngLatArray,\n ): Promise<SearchItem | undefined> {\n for (const provider of this.providers) {\n if (typeof provider.reverse === 'function') {\n try {\n for await (const result of provider.reverse(coordinates)) {\n return result;\n }\n } catch (error) {\n console.error('Error in reverse geocoding:', error);\n }\n }\n }\n return undefined;\n }\n}\n","import { BaseGeocoder } from '../BaseGeocoder';\n\nimport type { BaseProviderOptions } from './BaseProviderOptions';\n\n/**\n * Abstract base class representing a search provider.\n * It builds upon the BaseGeocoder functionalities with provider-specific properties.\n * @template O - Options type which extends BaseProviderOptions.\n */\nexport abstract class BaseProvider<\n O extends BaseProviderOptions = BaseProviderOptions,\n> extends BaseGeocoder<O> {\n /**\n * URL endpoint for the search service.\n * This is where queries will be sent to obtain search results.\n */\n searchUrl?: string;\n\n /**\n * Label to represent the provider.\n * Useful for user interfaces to display the source of search results.\n */\n label?: string;\n}\n","import NgwConnector from '@nextgis/ngw-connector';\nimport { fetchNgwLayerItems } from '@nextgis/ngw-kit';\n\nimport { BaseProvider } from './BaseProvider';\n\nimport type { BaseProviderOptions } from './BaseProviderOptions';\nimport type { ResultItem } from '../types/ResultItem';\nimport type { SearchItem } from '../types/SearchItem';\nimport type CancelablePromise from '@nextgis/cancelable-promise';\nimport type {\n FeatureItem,\n NgwConnectorOptions,\n ResourceItem,\n} from '@nextgis/ngw-connector';\nimport type { FetchNgwItemsOptions } from '@nextgis/ngw-kit';\nimport type { LngLatArray } from '@nextgis/utils';\n\n/**\n * Extends the basic search item with NGW-specific properties.\n */\ninterface NgwSearchItem extends SearchItem {\n /** ID of the NGW resource */\n resourceId: number;\n /** ID of the feature in the NGW resource */\n featureId: number;\n /** The specific feature item from NGW */\n item: FeatureItem;\n /** The NGW resource item */\n resourceItem: ResourceItem;\n}\n\n/**\n * Defines the structure for a rendered search item.\n */\ninterface RenderSearchItem {\n /** The specific feature item */\n item: FeatureItem;\n /** The NGW resource item */\n resourceItem: ResourceItem;\n}\n\n/**\n * Options for searching within a NGW resource.\n */\ninterface SearchResource extends FetchNgwItemsOptions {\n /** The search method used ('ilike' is case-insensitive) */\n searchMethod?: 'ilike' | 'like';\n /** Custom rendering function for search results */\n renderSearch?: (item: RenderSearchItem) => string | HTMLElement;\n}\n\n/**\n * Options required to initialize an NGW provider.\n */\ninterface NgwProviderOptions extends BaseProviderOptions {\n /** Connector instance for NGW. If not provided, will be created internally */\n connector?: NgwConnector;\n /** List of NGW resources to search within */\n searchResources: SearchResource[];\n /** Options for the internal NgwConnector (if one needs to be created) */\n connectorOptions?: NgwConnectorOptions;\n}\n\nexport class NgwProvider extends BaseProvider<NgwProviderOptions> {\n static limit = 300;\n\n searchResources: SearchResource[] = [];\n\n private connector: NgwConnector;\n private _abortControllers: AbortController[] = [];\n\n constructor(options: NgwProviderOptions) {\n super(options);\n if (!options.searchUrl && !options.connectorOptions?.baseUrl) {\n throw new Error(\n 'The `searchUrl` of `connectorOptions.baseUrl` are required',\n );\n }\n\n this.connector =\n options.connector ||\n new NgwConnector({\n baseUrl: this.searchUrl,\n ...options.connectorOptions,\n });\n this.searchResources = options.searchResources;\n }\n\n abort(): void {\n this._abortControllers.forEach((a) => {\n a.abort();\n });\n this._abortControllers.length = 0;\n }\n\n async *search(query: string): AsyncGenerator<NgwSearchItem, void, unknown> {\n const signal = this._makeSignal();\n for (const config of this.searchResources) {\n if (signal.aborted) {\n break;\n }\n const { searchMethod } = config;\n\n const limit = config.limit ?? NgwProvider.limit;\n //\n const resourceId = (config as any).id ?? config.resourceId;\n\n try {\n const resource = await this.connector.getResourceOrFail(resourceId, {\n cache: true,\n });\n\n const options: FetchNgwItemsOptions = {\n connector: this.connector,\n resourceId,\n signal,\n limit,\n };\n\n if (searchMethod === 'like') {\n options.like = query;\n } else {\n options.ilike = query;\n }\n\n const request = fetchNgwLayerItems(options);\n\n const entries = await request;\n\n for (const item of this._items({\n entries,\n query,\n config,\n resourceItem: resource,\n })) {\n item.result = () => this.result(item);\n yield item;\n }\n } catch (er) {\n if (\n er &&\n 'name' in (er as Error) &&\n (er as Error).name !== 'CancelError'\n ) {\n console.warn(er);\n }\n }\n }\n }\n\n result(item: NgwSearchItem): CancelablePromise<ResultItem> {\n const signal = this._makeSignal();\n const req = this.connector\n .get(\n 'feature_layer.feature.item_extent',\n { signal },\n {\n id: item.resourceId,\n fid: item.featureId,\n },\n )\n .then((x) => {\n const e = x.extent;\n return {\n text: item.text,\n extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],\n };\n });\n return req;\n }\n\n async *reverse(\n coordinates: LngLatArray,\n ): AsyncGenerator<SearchItem, void, unknown> {\n throw new Error('Not implemented');\n yield undefined as any;\n }\n\n private _makeSignal() {\n const abortController = new AbortController();\n this._abortControllers.push(abortController);\n return abortController.signal;\n }\n\n private _items({\n entries,\n query,\n config,\n resourceItem,\n }: {\n config: SearchResource;\n entries: FeatureItem[];\n query: string;\n resourceItem: ResourceItem;\n }): NgwSearchItem[] {\n const items: NgwSearchItem[] = [];\n\n let labelField: string | undefined = undefined;\n\n if (resourceItem.feature_layer) {\n labelField = resourceItem.feature_layer.fields.find(\n (f) => f.label_field,\n )?.keyname;\n }\n\n const meta = this.searchResources.find(\n (x) => (x as any).id ?? x.resourceId === resourceItem.resource.id,\n );\n if (meta) {\n entries.forEach((entry) => {\n let text = labelField ? entry.fields[labelField] : entry.id;\n if (config.renderSearch) {\n text = config.renderSearch({\n item: entry,\n resourceItem,\n });\n } else if (labelField) {\n text = entry.fields[labelField];\n }\n\n items.push({\n query: query,\n text,\n featureId: entry.id,\n resourceId: resourceItem.resource.id,\n item: entry,\n resourceItem,\n });\n });\n }\n return items;\n }\n}\n","import CancelablePromise from '@nextgis/cancelable-promise';\nimport { fixUrlStr } from '@nextgis/utils';\n\nimport { BaseProvider } from './BaseProvider';\n\nimport type { BaseProviderOptions } from './BaseProviderOptions';\nimport type { ResultItem } from '../types/ResultItem';\nimport type { SearchItem } from '../types/SearchItem';\nimport type { LngLatArray } from '@nextgis/utils';\nimport type { FeatureCollection } from 'geojson';\n\nexport class NominatimProvider extends BaseProvider {\n searchUrl = 'https://nominatim.openstreetmap.org';\n\n private _requests: CancelablePromise[] = [];\n\n constructor(options?: BaseProviderOptions) {\n super(options);\n if (options && options.searchUrl) {\n this.searchUrl = options.searchUrl;\n }\n }\n\n abort(): void {\n this._requests.forEach((x) => x.cancel());\n this._requests = [];\n }\n\n async *search(val: string): AsyncGenerator<SearchItem, void, unknown> {\n // RFC2616 accept - language string\n const url = fixUrlStr(\n // `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`\n `${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${val}`,\n );\n const request = new CancelablePromise<SearchItem[]>(\n (resolve, reject, onCancel) => {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', url, true);\n xhr.onload = () => {\n try {\n const geojson = JSON.parse(xhr.responseText) as FeatureCollection;\n const features: SearchItem[] = geojson.features.map((x) => {\n return {\n geom: x,\n extent: x.bbox,\n text: x.properties && x.properties.display_name,\n query: val,\n };\n });\n resolve(features);\n } catch (er) {\n reject(er);\n }\n };\n\n xhr.onerror = (er) => {\n reject(er);\n };\n\n onCancel(() => {\n xhr.abort();\n });\n\n xhr.send();\n },\n ).catch((er) => {\n if (er.name === 'CancelError') {\n //\n }\n throw er;\n });\n this._requests.push(request);\n const items = await request;\n if (items) {\n for (const i of items) {\n i.result = () => this.result(i);\n yield i;\n }\n }\n }\n\n result(model: SearchItem): CancelablePromise<ResultItem> {\n return CancelablePromise.resolve({\n text: model.text,\n extent: model.extent || [],\n geom: model.geom,\n });\n }\n\n async *reverse(\n coordinates: LngLatArray,\n ): AsyncGenerator<SearchItem, void, unknown> {\n const [lng, lat] = coordinates;\n const url = fixUrlStr(\n `${this.searchUrl}/reverse?format=geojson&lat=${lat}&lon=${lng}`,\n );\n const request = new CancelablePromise<SearchItem>(\n (resolve, reject, onCancel) => {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', url, true);\n xhr.onload = () => {\n try {\n const geojson = JSON.parse(xhr.responseText) as FeatureCollection;\n const feature = geojson.features[0];\n const result: SearchItem = {\n geom: feature,\n extent: feature.bbox,\n text: feature.properties && feature.properties.display_name,\n query: `${lat}, ${lng}`,\n };\n resolve(result);\n } catch (er) {\n reject(er);\n }\n };\n xhr.onerror = (er) => {\n reject(er);\n };\n\n onCancel(() => {\n xhr.abort();\n });\n\n xhr.send();\n },\n ).catch((er) => {\n if (er.name === 'CancelError') {\n //\n }\n throw er;\n });\n this._requests.push(request);\n const item = await request;\n if (item) {\n item.result = () => this.result(item);\n yield item;\n }\n }\n}\n","import { Geocoder } from './Geocoder';\n\nimport type { GeocoderOptions } from './GeocoderOptions';\n\nexport { Geocoder, GeocoderOptions };\nexport { BaseProvider } from './providers/BaseProvider';\nexport { NgwProvider } from './providers/NgwProvider';\nexport { NominatimProvider } from './providers/NominatimProvider';\n\nexport * from './providers/BaseProviderOptions';\nexport * from './types/ResultItem';\nexport * from './types/SearchItem';\n\nexport function create(options: GeocoderOptions): Geocoder {\n return new Geocoder(options);\n}\n"],"names":["BaseGeocoder","constructor","options","objectAssign","this","ID","Geocoder","super","providers","abort","forEach","x","search","query","__asyncGenerator","allProvidersFailed","errors","provider","results","more","temp","error","iter","__forAwait","__await","next","done","r","value","__spreadProps","__spreadValues","_id","return","call","err","name","push","length","Error","map","e","message","join","result","item","CancelablePromise","resolve","reverse","coordinates","er","reverseGeocodeFirstResult","console","BaseProvider","arguments","__publicField","_NgwProvider","_a","searchUrl","connectorOptions","baseUrl","connector","NgwConnector","searchResources","_abortControllers","a","_b","signal","_makeSignal","config","aborted","searchMethod","limit","resourceId","id","resource","getResourceOrFail","cache","like","ilike","request","fetchNgwLayerItems","entries","_items","resourceItem","warn","get","fid","featureId","then","extent","text","minLon","minLat","maxLon","maxLat","abortController","AbortController","items","labelField","feature_layer","fields","find","f","label_field","keyname","entry","renderSearch","NgwProvider","NominatimProvider","_requests","cancel","val","url","fixUrlStr","reject","onCancel","xhr","XMLHttpRequest","open","onload","features","JSON","parse","responseText","geom","bbox","properties","display_name","onerror","send","catch","i","model","lng","lat","feature","create"],"mappings":"oMAYO,MAAeA,EAGpB,WAAAC,CAAYC,GACNA,GACFC,EAAaC,KAAM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C2C,OAAAlC,EAAAV,KAAA,MAAA,YACrC,MAACiI,EAAKC,GAAOtF,EACbgE,EAAMC,EACV,GAAG7G,KAAKqD,wCAAwC6E,SAAWD,KAEvDtD,EAAU,IAAIlC,GAClB,CAACC,EAASoE,EAAQC,KACV,MAAAC,EAAM,IAAIC,eACZD,EAAAE,KAAK,MAAON,GAAK,GACrBI,EAAIG,OAAS,KACP,IACF,MACMgB,EADUd,KAAKC,MAAMN,EAAIO,cACPH,SAAS,GAOjC1E,EAN2B,CACzB8E,KAAMW,EACN9C,OAAQ8C,EAAQV,KAChBnC,KAAM6C,EAAQT,YAAcS,EAAQT,WAAWC,aAC/ClH,MAAO,GAAGyH,MAAQD,YAGbpF,GACPiE,EAAOjE,EACT,GAEEmE,EAAAY,QAAW/E,IACbiE,EAAOjE,EAAE,EAGXkE,GAAS,KACPC,EAAI3G,OAAM,IAGZ2G,EAAIa,MAAK,IAEXC,OAAOjF,IAID,MAAAA,CAAA,IAEH7C,KAAAyG,UAAUzE,KAAK2C,GACpB,MAAMnC,QAAa,IAAApB,EAAAuD,GACfnC,IACFA,EAAKD,OAAS,IAAMvC,KAAKuC,OAAOC,SAC1BA,EACR,GACF,EC5HK,SAAS4F,EAAOtI,GACd,OAAA,IAAII,EAASJ,EACtB"}
|
package/lib/geocoder.global.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 2.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 2.5.0; author: NextGIS */
|
|
2
2
|
var Geocoder = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
var __defProp$g = Object.defineProperty;
|
|
6
6
|
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField$e = (obj, key, value) => __defNormalProp$g(obj,
|
|
7
|
+
var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
|
|
8
8
|
class CancelError extends Error {
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
@@ -15,7 +15,7 @@ var Geocoder = (function (exports) {
|
|
|
15
15
|
|
|
16
16
|
var __defProp$f = Object.defineProperty;
|
|
17
17
|
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
-
var __publicField$d = (obj, key, value) => __defNormalProp$f(obj,
|
|
18
|
+
var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
|
|
19
19
|
class PromiseControl {
|
|
20
20
|
constructor(options = {}) {
|
|
21
21
|
this.options = options;
|
|
@@ -97,7 +97,7 @@ var Geocoder = (function (exports) {
|
|
|
97
97
|
|
|
98
98
|
var __defProp$e = Object.defineProperty;
|
|
99
99
|
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
100
|
-
var __publicField$c = (obj, key, value) => __defNormalProp$e(obj,
|
|
100
|
+
var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
|
|
101
101
|
class TimeoutError extends Error {
|
|
102
102
|
constructor() {
|
|
103
103
|
super();
|
|
@@ -386,7 +386,7 @@ var Geocoder = (function (exports) {
|
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
function round(val, toFixed) {
|
|
389
|
-
const n =
|
|
389
|
+
const n = 1;
|
|
390
390
|
return Math.round((val + Number.EPSILON) * n) / n;
|
|
391
391
|
}
|
|
392
392
|
|
|
@@ -429,7 +429,7 @@ var Geocoder = (function (exports) {
|
|
|
429
429
|
return a;
|
|
430
430
|
};
|
|
431
431
|
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
432
|
-
var __publicField$a = (obj, key, value) => __defNormalProp$c(obj,
|
|
432
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$c(obj, key + "" , value);
|
|
433
433
|
var __async$1 = (__this, __arguments, generator) => {
|
|
434
434
|
return new Promise((resolve, reject) => {
|
|
435
435
|
var fulfilled = (value) => {
|
|
@@ -1666,7 +1666,7 @@ var Geocoder = (function (exports) {
|
|
|
1666
1666
|
|
|
1667
1667
|
var __defProp$5 = Object.defineProperty;
|
|
1668
1668
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1669
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj,
|
|
1669
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
|
|
1670
1670
|
class NetworkError extends Error {
|
|
1671
1671
|
constructor(url) {
|
|
1672
1672
|
super();
|
|
@@ -1785,6 +1785,7 @@ var Geocoder = (function (exports) {
|
|
|
1785
1785
|
__publicField$2(this, "user");
|
|
1786
1786
|
__publicField$2(this, "resources");
|
|
1787
1787
|
__publicField$2(this, "cache");
|
|
1788
|
+
__publicField$2(this, "withCredentials");
|
|
1788
1789
|
__publicField$2(this, "routeStr", "/api/component/pyramid/route");
|
|
1789
1790
|
__publicField$2(this, "activeRequests", []);
|
|
1790
1791
|
__publicField$2(this, "requestTransform");
|
|
@@ -1793,11 +1794,15 @@ var Geocoder = (function (exports) {
|
|
|
1793
1794
|
if (exist) {
|
|
1794
1795
|
return exist;
|
|
1795
1796
|
} else {
|
|
1796
|
-
|
|
1797
|
-
|
|
1797
|
+
const { route, requestTransform, withCredentials } = this.options;
|
|
1798
|
+
if (route) {
|
|
1799
|
+
this.routeStr = route;
|
|
1798
1800
|
}
|
|
1799
|
-
if (
|
|
1800
|
-
this.requestTransform =
|
|
1801
|
+
if (requestTransform) {
|
|
1802
|
+
this.requestTransform = requestTransform;
|
|
1803
|
+
}
|
|
1804
|
+
if (withCredentials !== void 0) {
|
|
1805
|
+
this.withCredentials = withCredentials;
|
|
1801
1806
|
}
|
|
1802
1807
|
this.resources = new ResourcesControl({
|
|
1803
1808
|
connector: this,
|
|
@@ -1966,6 +1971,9 @@ var Geocoder = (function (exports) {
|
|
|
1966
1971
|
*/
|
|
1967
1972
|
apiRequest(name, params_ = {}, requestOptions = {}) {
|
|
1968
1973
|
var _a, _b;
|
|
1974
|
+
requestOptions = __spreadValues$3({
|
|
1975
|
+
withCredentials: this.withCredentials
|
|
1976
|
+
}, requestOptions);
|
|
1969
1977
|
const { method, headers, withCredentials, responseType } = requestOptions;
|
|
1970
1978
|
params_ = (_a = requestOptions.params) != null ? _a : params_;
|
|
1971
1979
|
const params = objectRemoveEmpty(params_);
|