@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.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 2.4.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 2.5.0; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -18,7 +18,7 @@ class BaseGeocoder {
18
18
 
19
19
  var __defProp$3 = Object.defineProperty;
20
20
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
21
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
22
22
  let ID = 0;
23
23
  class Geocoder extends BaseGeocoder {
24
24
  constructor(options) {
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@nextgis/cancelable-promise"),r=require("@nextgis/utils"),t=require("@nextgis/ngw-connector"),s=require("@nextgis/ngw-kit");class o{constructor(e){e&&r.objectAssign(this,e)}}var n=Object.defineProperty,i=(e,r,t)=>((e,r,t)=>r in e?n(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);let a=0;class c extends o{constructor(e){super(e),i(this,"providers",[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}async*search(e){this.abort();let r=!0;const t=[];for(const o of this.providers)try{const t=o.search(e);for await(const e of t)r=!1,yield{...e,provider:o,_id:a++}}catch(s){"CancelError"!==s.name&&t.push(s)}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)}async*reverse(e){for(const t of this.providers)if(t.reverse)try{const r=t.reverse(e);for await(const e of r)yield{...e,provider:t,_id:a++}}catch(r){}}async reverseGeocodeFirstResult(e){for(const t of this.providers)if("function"==typeof t.reverse)try{for await(const r of t.reverse(e))return r}catch(r){console.error("Error in reverse geocoding:",r)}}}var l=Object.defineProperty,u=(e,r,t)=>((e,r,t)=>r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);class h extends o{constructor(){super(...arguments),u(this,"searchUrl"),u(this,"label")}}var d=Object.defineProperty,f=(e,r,t)=>((e,r,t)=>r in e?d(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);const p=class e extends h{constructor(e){var r;if(super(e),f(this,"searchResources",[]),f(this,"connector"),f(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 t({baseUrl:this.searchUrl,...e.connectorOptions}),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}async*search(r){var t,o;const n=this._makeSignal();for(const a of this.searchResources){if(n.aborted)break;const{searchMethod:c}=a,l=null!=(t=a.limit)?t:e.limit,u=null!=(o=a.id)?o:a.resourceId;try{const e=await this.connector.getResourceOrFail(u,{cache:!0}),t={connector:this.connector,resourceId:u,signal:n,limit:l};"like"===c?t.like=r:t.ilike=r;const o=s.fetchNgwLayerItems(t),i=await o;for(const s of this._items({entries:i,query:r,config:a,resourceItem:e}))s.result=()=>this.result(s),yield s}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]}}))}async*reverse(e){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:s}){var o;const n=[];let i;s.feature_layer&&(i=null==(o=s.feature_layer.fields.find((e=>e.label_field)))?void 0:o.keyname);return this.searchResources.find((e=>{var r;return null!=(r=e.id)?r:e.resourceId===s.resource.id}))&&e.forEach((e=>{let o=i?e.fields[i]:e.id;t.renderSearch?o=t.renderSearch({item:e,resourceItem:s}):i&&(o=e.fields[i]),n.push({query:r,text:o,featureId:e.id,resourceId:s.resource.id,item:e,resourceItem:s})})),n}};f(p,"limit",300);let m=p;var b=Object.defineProperty,v=(e,r,t)=>((e,r,t)=>r in e?b(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);exports.BaseProvider=h,exports.Geocoder=c,exports.NgwProvider=m,exports.NominatimProvider=class extends h{constructor(e){super(e),v(this,"searchUrl","https://nominatim.openstreetmap.org"),v(this,"_requests",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}async*search(t){const s=r.fixUrlStr(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${t}`),o=new e(((e,r,o)=>{const n=new XMLHttpRequest;n.open("GET",s,!0),n.onload=()=>{try{const r=JSON.parse(n.responseText).features.map((e=>({geom:e,extent:e.bbox,text:e.properties&&e.properties.display_name,query:t})));e(r)}catch(s){r(s)}},n.onerror=e=>{r(e)},o((()=>{n.abort()})),n.send()})).catch((e=>{throw e}));this._requests.push(o);const n=await o;if(n)for(const e of n)e.result=()=>this.result(e),yield e}result(r){return e.resolve({text:r.text,extent:r.extent||[],geom:r.geom})}async*reverse(t){const[s,o]=t,n=r.fixUrlStr(`${this.searchUrl}/reverse?format=geojson&lat=${o}&lon=${s}`),i=new e(((e,r,t)=>{const i=new XMLHttpRequest;i.open("GET",n,!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:`${o}, ${s}`})}catch(t){r(t)}},i.onerror=e=>{r(e)},t((()=>{i.abort()})),i.send()})).catch((e=>{throw e}));this._requests.push(i);const a=await i;a&&(a.result=()=>this.result(a),yield a)}},exports.create=function(e){return new c(e)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@nextgis/cancelable-promise"),r=require("@nextgis/utils"),t=require("@nextgis/ngw-connector"),s=require("@nextgis/ngw-kit");class o{constructor(e){e&&r.objectAssign(this,e)}}var n=Object.defineProperty,i=(e,r,t)=>((e,r,t)=>r in e?n(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,r+"",t);let a=0;class c extends o{constructor(e){super(e),i(this,"providers",[]),e&&e.providers&&(this.providers=e.providers)}abort(){this.providers.forEach((e=>{e.abort&&e.abort()}))}async*search(e){this.abort();let r=!0;const t=[];for(const o of this.providers)try{const t=o.search(e);for await(const e of t)r=!1,yield{...e,provider:o,_id:a++}}catch(s){"CancelError"!==s.name&&t.push(s)}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)}async*reverse(e){for(const t of this.providers)if(t.reverse)try{const r=t.reverse(e);for await(const e of r)yield{...e,provider:t,_id:a++}}catch(r){}}async reverseGeocodeFirstResult(e){for(const t of this.providers)if("function"==typeof t.reverse)try{for await(const r of t.reverse(e))return r}catch(r){console.error("Error in reverse geocoding:",r)}}}var l=Object.defineProperty,u=(e,r,t)=>((e,r,t)=>r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);class h extends o{constructor(){super(...arguments),u(this,"searchUrl"),u(this,"label")}}var d=Object.defineProperty,f=(e,r,t)=>((e,r,t)=>r in e?d(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);const p=class e extends h{constructor(e){var r;if(super(e),f(this,"searchResources",[]),f(this,"connector"),f(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 t({baseUrl:this.searchUrl,...e.connectorOptions}),this.searchResources=e.searchResources}abort(){this._abortControllers.forEach((e=>{e.abort()})),this._abortControllers.length=0}async*search(r){var t,o;const n=this._makeSignal();for(const a of this.searchResources){if(n.aborted)break;const{searchMethod:c}=a,l=null!=(t=a.limit)?t:e.limit,u=null!=(o=a.id)?o:a.resourceId;try{const e=await this.connector.getResourceOrFail(u,{cache:!0}),t={connector:this.connector,resourceId:u,signal:n,limit:l};"like"===c?t.like=r:t.ilike=r;const o=s.fetchNgwLayerItems(t),i=await o;for(const s of this._items({entries:i,query:r,config:a,resourceItem:e}))s.result=()=>this.result(s),yield s}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]}}))}async*reverse(e){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:s}){var o;const n=[];let i;s.feature_layer&&(i=null==(o=s.feature_layer.fields.find((e=>e.label_field)))?void 0:o.keyname);return this.searchResources.find((e=>{var r;return null!=(r=e.id)?r:e.resourceId===s.resource.id}))&&e.forEach((e=>{let o=i?e.fields[i]:e.id;t.renderSearch?o=t.renderSearch({item:e,resourceItem:s}):i&&(o=e.fields[i]),n.push({query:r,text:o,featureId:e.id,resourceId:s.resource.id,item:e,resourceItem:s})})),n}};f(p,"limit",300);let m=p;var b=Object.defineProperty,v=(e,r,t)=>((e,r,t)=>r in e?b(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t)(e,"symbol"!=typeof r?r+"":r,t);exports.BaseProvider=h,exports.Geocoder=c,exports.NgwProvider=m,exports.NominatimProvider=class extends h{constructor(e){super(e),v(this,"searchUrl","https://nominatim.openstreetmap.org"),v(this,"_requests",[]),e&&e.searchUrl&&(this.searchUrl=e.searchUrl)}abort(){this._requests.forEach((e=>e.cancel())),this._requests=[]}async*search(t){const s=r.fixUrlStr(`${this.searchUrl}/search?format=geojson&polygon_geojson=1&q=${t}`),o=new e(((e,r,o)=>{const n=new XMLHttpRequest;n.open("GET",s,!0),n.onload=()=>{try{const r=JSON.parse(n.responseText).features.map((e=>({geom:e,extent:e.bbox,text:e.properties&&e.properties.display_name,query:t})));e(r)}catch(s){r(s)}},n.onerror=e=>{r(e)},o((()=>{n.abort()})),n.send()})).catch((e=>{throw e}));this._requests.push(o);const n=await o;if(n)for(const e of n)e.result=()=>this.result(e),yield e}result(r){return e.resolve({text:r.text,extent:r.extent||[],geom:r.geom})}async*reverse(t){const[s,o]=t,n=r.fixUrlStr(`${this.searchUrl}/reverse?format=geojson&lat=${o}&lon=${s}`),i=new e(((e,r,t)=>{const i=new XMLHttpRequest;i.open("GET",n,!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:`${o}, ${s}`})}catch(t){r(t)}},i.onerror=e=>{r(e)},t((()=>{i.abort()})),i.send()})).catch((e=>{throw e}));this._requests.push(i);const a=await i;a&&(a.result=()=>this.result(a),yield a)}},exports.create=function(e){return new c(e)};
2
2
  //# sourceMappingURL=geocoder.cjs.prod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geocoder.cjs.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","__publicField","providers","abort","forEach","x","search","query","allProvidersFailed","errors","provider","results","r","_id","err","name","push","length","Error","map","e","message","join","result","item","CancelablePromise","resolve","reverse","coordinates","er","reverseGeocodeFirstResult","error","console","BaseProvider","arguments","_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","_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"],"mappings":"+MAYO,MAAeA,EAGpB,WAAAC,CAAYC,GACNA,GACFC,eAAaC,KAAMF,EAEvB,4JCVF,IAAIG,EAAK,EAEF,MAAMC,UAAiBN,EAG5B,WAAAC,CAAYC,GACVK,MAAML,GAHRM,EAAAJ,KAAA,YAA4B,IAItBF,GAAWA,EAAQO,YACrBL,KAAKK,UAAYP,EAAQO,UAE7B,CAEA,KAAAC,GACON,KAAAK,UAAUE,SAASC,IAClBA,EAAEF,OACJE,EAAEF,OACJ,GAEJ,CAEA,YAAOG,CAAOC,GACZV,KAAKM,QACL,IAAIK,GAAqB,EACzB,MAAMC,EAAkB,GAEb,IAAA,MAAAC,KAAYb,KAAKK,UACtB,IACI,MAAAS,EAAUD,EAASJ,OAAOC,GAEhC,UAAA,MAAiBK,KAAKD,EACCH,GAAA,OACf,IAAKI,EAAGF,WAAUG,IAAKf,WAExBgB,GAES,gBADLA,EACJC,MACLN,EAAOO,KAFEF,EAIb,CAGE,GAAAN,GAAs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EHhC,KAAA2F,UAAUxE,KAAK2C,GACpB,MAAMnC,QAAamC,EACfnC,IACFA,EAAKD,OAAS,IAAM1B,KAAK0B,OAAOC,SAC1BA,EAEV,kBC5HK,SAAgB7B,GACd,OAAA,IAAII,EAASJ,EACtB"}
1
+ {"version":3,"file":"geocoder.cjs.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","__publicField","providers","abort","forEach","x","search","query","allProvidersFailed","errors","provider","results","r","_id","err","name","push","length","Error","map","e","message","join","result","item","CancelablePromise","resolve","reverse","coordinates","er","reverseGeocodeFirstResult","error","console","BaseProvider","arguments","_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","_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"],"mappings":"+MAYO,MAAeA,EAGpB,WAAAC,CAAYC,GACNA,GACFC,eAAaC,KAAMF,EAEvB,uICVF,IAAIG,EAAK,EAEF,MAAMC,UAAiBN,EAG5B,WAAAC,CAAYC,GACVK,MAAML,GAHRM,EAAAJ,KAAA,YAA4B,IAItBF,GAAWA,EAAQO,YACrBL,KAAKK,UAAYP,E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GAAK,GACrBI,EAAIG,OAAS,KACP,IACF,MACMgB,EADUd,KAAKC,MAAMN,EAAIO,cACPH,SAAS,GAOjCzE,EAN2B,CACzB6E,KAAMW,EACN7C,OAAQ6C,EAAQV,KAChBlC,KAAM4C,EAAQT,YAAcS,EAAQT,WAAWC,aAC/CnG,MAAO,GAAG0G,MAAQD,YAGbnF,GACPgE,EAAOhE,EACT,GAEEkE,EAAAY,QAAW9E,IACbgE,EAAOhE,EAAE,EAGXiE,GAAS,KACPC,EAAI5F,OAAM,IAGZ4F,EAAIa,MAAK,IAEXC,OAAOhF,IAID,MAAAA,CAAA,IAEHhC,KAAA2F,UAAUxE,KAAK2C,GACpB,MAAMnC,QAAamC,EACfnC,IACFA,EAAKD,OAAS,IAAM1B,KAAK0B,OAAOC,SAC1BA,EAEV,kBC5HK,SAAgB7B,GACd,OAAA,IAAII,EAASJ,EACtB"}
@@ -1,7 +1,7 @@
1
- /** Bundle of @nextgis/geocoder; version: 2.4.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 2.5.0; author: NextGIS */
2
2
  var __defProp$g = Object.defineProperty;
3
3
  var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ var __publicField$e = (obj, key, value) => __defNormalProp$g(obj, key + "" , value);
5
5
  class CancelError extends Error {
6
6
  constructor() {
7
7
  super();
@@ -12,7 +12,7 @@ class CancelError extends Error {
12
12
 
13
13
  var __defProp$f = Object.defineProperty;
14
14
  var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
- var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var __publicField$d = (obj, key, value) => __defNormalProp$f(obj, key + "" , value);
16
16
  class PromiseControl {
17
17
  constructor(options = {}) {
18
18
  this.options = options;
@@ -94,7 +94,7 @@ class PromiseControl {
94
94
 
95
95
  var __defProp$e = Object.defineProperty;
96
96
  var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
97
- var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
97
+ var __publicField$c = (obj, key, value) => __defNormalProp$e(obj, key + "" , value);
98
98
  class TimeoutError extends Error {
99
99
  constructor() {
100
100
  super();
@@ -383,7 +383,7 @@ function objectRemoveEmpty(obj) {
383
383
  }
384
384
 
385
385
  function round(val, toFixed) {
386
- const n = toFixed ? Number("1e+" + toFixed) : 1;
386
+ const n = 1;
387
387
  return Math.round((val + Number.EPSILON) * n) / n;
388
388
  }
389
389
 
@@ -426,7 +426,7 @@ var __spreadValues$5 = (a, b) => {
426
426
  return a;
427
427
  };
428
428
  var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
429
- var __publicField$a = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
429
+ var __publicField$a = (obj, key, value) => __defNormalProp$c(obj, key + "" , value);
430
430
  var __async$1 = (__this, __arguments, generator) => {
431
431
  return new Promise((resolve, reject) => {
432
432
  var fulfilled = (value) => {
@@ -1663,7 +1663,7 @@ function apiRequest(opt) {
1663
1663
 
1664
1664
  var __defProp$5 = Object.defineProperty;
1665
1665
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1666
- var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1666
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
1667
1667
  class NetworkError extends Error {
1668
1668
  constructor(url) {
1669
1669
  super();
@@ -1782,6 +1782,7 @@ class NgwConnector {
1782
1782
  __publicField$2(this, "user");
1783
1783
  __publicField$2(this, "resources");
1784
1784
  __publicField$2(this, "cache");
1785
+ __publicField$2(this, "withCredentials");
1785
1786
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1786
1787
  __publicField$2(this, "activeRequests", []);
1787
1788
  __publicField$2(this, "requestTransform");
@@ -1790,11 +1791,15 @@ class NgwConnector {
1790
1791
  if (exist) {
1791
1792
  return exist;
1792
1793
  } else {
1793
- if (this.options.route) {
1794
- this.routeStr = this.options.route;
1794
+ const { route, requestTransform, withCredentials } = this.options;
1795
+ if (route) {
1796
+ this.routeStr = route;
1795
1797
  }
1796
- if (this.options.requestTransform) {
1797
- this.requestTransform = this.options.requestTransform;
1798
+ if (requestTransform) {
1799
+ this.requestTransform = requestTransform;
1800
+ }
1801
+ if (withCredentials !== void 0) {
1802
+ this.withCredentials = withCredentials;
1798
1803
  }
1799
1804
  this.resources = new ResourcesControl({
1800
1805
  connector: this,
@@ -1963,6 +1968,9 @@ class NgwConnector {
1963
1968
  */
1964
1969
  apiRequest(name, params_ = {}, requestOptions = {}) {
1965
1970
  var _a, _b;
1971
+ requestOptions = __spreadValues$3({
1972
+ withCredentials: this.withCredentials
1973
+ }, requestOptions);
1966
1974
  const { method, headers, withCredentials, responseType } = requestOptions;
1967
1975
  params_ = (_a = requestOptions.params) != null ? _a : params_;
1968
1976
  const params = objectRemoveEmpty(params_);