@nextgis/geocoder 1.19.2 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,241 +1,226 @@
1
- /**
2
- * Modern geocoder on async generators. May use different data providers.
3
- *
4
- * @packageDocumentation
5
- * @module geocoder
6
- */
7
-
8
- import CancelablePromise from '@nextgis/cancelable-promise';
9
- import type { FeatureItem } from '@nextgis/ngw-connector';
10
- import type { FetchNgwItemsOptions } from '@nextgis/ngw-kit';
11
- import type { GeoJsonObject } from 'geojson';
12
- import type { LngLatArray } from '@nextgis/utils';
13
- import type { LngLatBoundsArray } from '@nextgis/utils';
14
- import NgwConnector from '@nextgis/ngw-connector';
15
- import type { NgwConnectorOptions } from '@nextgis/ngw-connector';
16
- import type { ResourceItem } from '@nextgis/ngw-connector';
17
-
18
- /**
19
- * Represents the base class for a geocoder.
20
- * This abstract class provides the basic methods that every geocoder should implement.
21
- *
22
- * @template O - The type of options that can be passed to the geocoder.
23
- */
24
- declare abstract class BaseGeocoder<O extends Record<string, any> = Record<string, any>> {
25
- constructor(options?: O);
26
- /**
27
- * Search method to retrieve geocoding results.
28
- *
29
- * @abstract
30
- * @param query - The search string to geocode.
31
- * @yields An async generator that yields search results.
32
- */
33
- abstract search(query: string): AsyncGenerator<SearchItem>;
34
- /**
35
- * Method to retrieve detailed result for a specific search item.
36
- *
37
- * @abstract
38
- * @param item - The search item to get detailed result for.
39
- * @returns A promise that resolves to the detailed result.
40
- */
41
- abstract result(item: SearchItem): CancelablePromise<any>;
42
- /**
43
- * Method for reverse geocoding.
44
- * Takes coordinates and returns the corresponding address or location information.
45
- *
46
- * @abstract
47
- * @param coordinates - The longitude and latitude values.
48
- * @returns An async generator that yields reverse geocoding results.
49
- */
50
- abstract reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem>;
51
- /**
52
- * Optional method to abort any ongoing geocoding requests.
53
- *
54
- * @abstract
55
- */
56
- abstract abort?(): void;
57
- }
58
-
59
- /**
60
- * Abstract base class representing a search provider.
61
- * It builds upon the BaseGeocoder functionalities with provider-specific properties.
62
- * @template O - Options type which extends BaseProviderOptions.
63
- */
64
- export declare abstract class BaseProvider<O extends BaseProviderOptions = BaseProviderOptions> extends BaseGeocoder<O> {
65
- /**
66
- * URL endpoint for the search service.
67
- * This is where queries will be sent to obtain search results.
68
- */
69
- searchUrl?: string;
70
- /**
71
- * Label to represent the provider.
72
- * Useful for user interfaces to display the source of search results.
73
- */
74
- label?: string;
75
- }
76
-
77
- /**
78
- * Options for initializing a basic search provider.
79
- */
80
- export declare interface BaseProviderOptions {
81
- /**
82
- * URL endpoint for the search service.
83
- * This is where queries will be sent to obtain search results.
84
- */
85
- searchUrl?: string;
86
- /**
87
- * Label to represent the provider.
88
- * This could be used for user interfaces to display the source of search results.
89
- */
90
- label?: string;
91
- }
92
-
93
- export declare function create(options: GeocoderOptions): Geocoder;
94
-
95
- export declare class Geocoder extends BaseGeocoder<GeocoderOptions> {
96
- providers: BaseProvider[];
97
- constructor(options: GeocoderOptions);
98
- abort(): void;
99
- search(query: string): AsyncGenerator<SearchItem, void, unknown>;
100
- result(item: SearchItem): CancelablePromise<any>;
101
- reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem, void, unknown>;
102
- /**
103
- * Returns the first reverse geocoding result for given coordinates from any provider.
104
- *
105
- * @param coordinates - The longitude and latitude values.
106
- * @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
107
- */
108
- reverseGeocodeFirstResult(coordinates: LngLatArray): Promise<SearchItem | undefined>;
109
- }
110
-
111
- /**
112
- * Defines the options for creating a Geocoder instance.
113
- */
114
- export declare interface GeocoderOptions {
115
- /**
116
- * An array of providers to be used for geocoding.
117
- */
118
- providers: BaseProvider[];
119
- }
120
-
121
- export declare class NgwProvider extends BaseProvider<NgwProviderOptions> {
122
- static limit: number;
123
- searchResources: SearchResource[];
124
- private connector;
125
- private _abortControllers;
126
- constructor(options: NgwProviderOptions);
127
- abort(): void;
128
- search(query: string): AsyncGenerator<NgwSearchItem, void, unknown>;
129
- result(item: NgwSearchItem): CancelablePromise<ResultItem>;
130
- reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem, void, unknown>;
131
- private _makeSignal;
132
- private _items;
133
- }
134
-
135
- /**
136
- * Options required to initialize an NGW provider.
137
- */
138
- declare interface NgwProviderOptions extends BaseProviderOptions {
139
- /** Connector instance for NGW. If not provided, will be created internally */
140
- connector?: NgwConnector;
141
- /** List of NGW resources to search within */
142
- searchResources: SearchResource[];
143
- /** Options for the internal NgwConnector (if one needs to be created) */
144
- connectorOptions?: NgwConnectorOptions;
145
- }
146
-
147
- /**
148
- * Extends the basic search item with NGW-specific properties.
149
- */
150
- declare interface NgwSearchItem extends SearchItem {
151
- /** ID of the NGW resource */
152
- resourceId: number;
153
- /** ID of the feature in the NGW resource */
154
- featureId: number;
155
- /** The specific feature item from NGW */
156
- item: FeatureItem;
157
- /** The NGW resource item */
158
- resourceItem: ResourceItem;
159
- }
160
-
161
- export declare class NominatimProvider extends BaseProvider {
162
- searchUrl: string;
163
- private _requests;
164
- constructor(options?: BaseProviderOptions);
165
- abort(): void;
166
- search(val: string): AsyncGenerator<SearchItem, void, unknown>;
167
- result(model: SearchItem): CancelablePromise<ResultItem>;
168
- reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem, void, unknown>;
169
- }
170
-
171
- /**
172
- * Defines the structure for a rendered search item.
173
- */
174
- declare interface RenderSearchItem {
175
- /** The specific feature item */
176
- item: FeatureItem;
177
- /** The NGW resource item */
178
- resourceItem: ResourceItem;
179
- }
180
-
181
- export declare interface ResultItem {
182
- /**
183
- * Display text of the result item.
184
- */
185
- text: string;
186
- /**
187
- * Bounding box of the result item in [west, south, east, north] format.
188
- */
189
- extent: LngLatBoundsArray;
190
- /**
191
- * Optional GeoJSON geometry associated with this result item.
192
- */
193
- geom?: GeoJsonObject;
194
- }
195
-
196
- export declare interface SearchItem {
197
- /**
198
- * A dynamic property bucket for the `SearchItem`.
199
- */
200
- [prop: string]: any;
201
- /**
202
- * An optional unique identifier for the search result.
203
- */
204
- _id?: number | string;
205
- /**
206
- * Display text of the search result.
207
- */
208
- text: string;
209
- /**
210
- * The original query string that resulted in this search result.
211
- */
212
- query: string;
213
- /**
214
- * An optional bounding box of the search result in [west, south, east, north] format.
215
- */
216
- extent?: LngLatBoundsArray;
217
- /**
218
- * The provider that sourced this search result.
219
- */
220
- provider?: BaseProvider;
221
- /**
222
- * Optional GeoJSON geometry associated with this search result.
223
- */
224
- geom?: GeoJsonObject;
225
- /**
226
- * An optional function that can be called to retrieve detailed result for this search item.
227
- */
228
- result?: () => CancelablePromise<ResultItem>;
229
- }
230
-
231
- /**
232
- * Options for searching within a NGW resource.
233
- */
234
- declare interface SearchResource extends FetchNgwItemsOptions {
235
- /** The search method used ('ilike' is case-insensitive) */
236
- searchMethod?: 'ilike' | 'like';
237
- /** Custom rendering function for search results */
238
- renderSearch?: (item: RenderSearchItem) => string | HTMLElement;
239
- }
240
-
241
- export { }
1
+ import CancelablePromise from '@nextgis/cancelable-promise';
2
+ import { LngLatBoundsArray, LngLatArray } from '@nextgis/utils';
3
+ import { GeoJsonObject } from 'geojson';
4
+ import NgwConnector, { FeatureItem, ResourceItem, NgwConnectorOptions } from '@nextgis/ngw-connector';
5
+ import { FetchNgwItemsOptions } from '@nextgis/ngw-kit';
6
+
7
+ interface ResultItem {
8
+ /**
9
+ * Display text of the result item.
10
+ */
11
+ text: string;
12
+ /**
13
+ * Bounding box of the result item in [west, south, east, north] format.
14
+ */
15
+ extent: LngLatBoundsArray;
16
+ /**
17
+ * Optional GeoJSON geometry associated with this result item.
18
+ */
19
+ geom?: GeoJsonObject;
20
+ }
21
+
22
+ /**
23
+ * Options for initializing a basic search provider.
24
+ */
25
+ interface BaseProviderOptions {
26
+ /**
27
+ * URL endpoint for the search service.
28
+ * This is where queries will be sent to obtain search results.
29
+ */
30
+ searchUrl?: string;
31
+ /**
32
+ * Label to represent the provider.
33
+ * This could be used for user interfaces to display the source of search results.
34
+ */
35
+ label?: string;
36
+ }
37
+
38
+ /**
39
+ * Abstract base class representing a search provider.
40
+ * It builds upon the BaseGeocoder functionalities with provider-specific properties.
41
+ * @template O - Options type which extends BaseProviderOptions.
42
+ */
43
+ declare abstract class BaseProvider<O extends BaseProviderOptions = BaseProviderOptions> extends BaseGeocoder<O> {
44
+ /**
45
+ * URL endpoint for the search service.
46
+ * This is where queries will be sent to obtain search results.
47
+ */
48
+ searchUrl?: string;
49
+ /**
50
+ * Label to represent the provider.
51
+ * Useful for user interfaces to display the source of search results.
52
+ */
53
+ label?: string;
54
+ }
55
+
56
+ interface SearchItem {
57
+ /**
58
+ * A dynamic property bucket for the `SearchItem`.
59
+ */
60
+ [prop: string]: any;
61
+ /**
62
+ * An optional unique identifier for the search result.
63
+ */
64
+ _id?: number | string;
65
+ /**
66
+ * Display text of the search result.
67
+ */
68
+ text: string;
69
+ /**
70
+ * The original query string that resulted in this search result.
71
+ */
72
+ query: string;
73
+ /**
74
+ * An optional bounding box of the search result in [west, south, east, north] format.
75
+ */
76
+ extent?: LngLatBoundsArray;
77
+ /**
78
+ * The provider that sourced this search result.
79
+ */
80
+ provider?: BaseProvider;
81
+ /**
82
+ * Optional GeoJSON geometry associated with this search result.
83
+ */
84
+ geom?: GeoJsonObject;
85
+ /**
86
+ * An optional function that can be called to retrieve detailed result for this search item.
87
+ */
88
+ result?: () => CancelablePromise<ResultItem>;
89
+ }
90
+
91
+ /**
92
+ * Represents the base class for a geocoder.
93
+ * This abstract class provides the basic methods that every geocoder should implement.
94
+ *
95
+ * @template O - The type of options that can be passed to the geocoder.
96
+ */
97
+ declare abstract class BaseGeocoder<O extends Record<string, any> = Record<string, any>> {
98
+ constructor(options?: O);
99
+ /**
100
+ * Search method to retrieve geocoding results.
101
+ *
102
+ * @abstract
103
+ * @param query - The search string to geocode.
104
+ * @yields An async generator that yields search results.
105
+ */
106
+ abstract search(query: string): AsyncGenerator<SearchItem>;
107
+ /**
108
+ * Method to retrieve detailed result for a specific search item.
109
+ *
110
+ * @abstract
111
+ * @param item - The search item to get detailed result for.
112
+ * @returns A promise that resolves to the detailed result.
113
+ */
114
+ abstract result(item: SearchItem): CancelablePromise<any>;
115
+ /**
116
+ * Method for reverse geocoding.
117
+ * Takes coordinates and returns the corresponding address or location information.
118
+ *
119
+ * @abstract
120
+ * @param coordinates - The longitude and latitude values.
121
+ * @returns An async generator that yields reverse geocoding results.
122
+ */
123
+ abstract reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem>;
124
+ /**
125
+ * Optional method to abort any ongoing geocoding requests.
126
+ *
127
+ * @abstract
128
+ */
129
+ abstract abort?(): void;
130
+ }
131
+
132
+ /**
133
+ * Defines the options for creating a Geocoder instance.
134
+ */
135
+ interface GeocoderOptions {
136
+ /**
137
+ * An array of providers to be used for geocoding.
138
+ */
139
+ providers: BaseProvider[];
140
+ }
141
+
142
+ declare class Geocoder extends BaseGeocoder<GeocoderOptions> {
143
+ providers: BaseProvider[];
144
+ constructor(options: GeocoderOptions);
145
+ abort(): void;
146
+ search(query: string): AsyncGenerator<SearchItem, void, unknown>;
147
+ result(item: SearchItem): CancelablePromise<any>;
148
+ reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem, void, unknown>;
149
+ /**
150
+ * Returns the first reverse geocoding result for given coordinates from any provider.
151
+ *
152
+ * @param coordinates - The longitude and latitude values.
153
+ * @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
154
+ */
155
+ reverseGeocodeFirstResult(coordinates: LngLatArray): Promise<SearchItem | undefined>;
156
+ }
157
+
158
+ /**
159
+ * Extends the basic search item with NGW-specific properties.
160
+ */
161
+ interface NgwSearchItem extends SearchItem {
162
+ /** ID of the NGW resource */
163
+ resourceId: number;
164
+ /** ID of the feature in the NGW resource */
165
+ featureId: number;
166
+ /** The specific feature item from NGW */
167
+ item: FeatureItem;
168
+ /** The NGW resource item */
169
+ resourceItem: ResourceItem;
170
+ }
171
+ /**
172
+ * Defines the structure for a rendered search item.
173
+ */
174
+ interface RenderSearchItem {
175
+ /** The specific feature item */
176
+ item: FeatureItem;
177
+ /** The NGW resource item */
178
+ resourceItem: ResourceItem;
179
+ }
180
+ /**
181
+ * Options for searching within a NGW resource.
182
+ */
183
+ interface SearchResource extends FetchNgwItemsOptions {
184
+ /** The search method used ('ilike' is case-insensitive) */
185
+ searchMethod?: 'ilike' | 'like';
186
+ /** Custom rendering function for search results */
187
+ renderSearch?: (item: RenderSearchItem) => string | HTMLElement;
188
+ }
189
+ /**
190
+ * Options required to initialize an NGW provider.
191
+ */
192
+ interface NgwProviderOptions extends BaseProviderOptions {
193
+ /** Connector instance for NGW. If not provided, will be created internally */
194
+ connector?: NgwConnector;
195
+ /** List of NGW resources to search within */
196
+ searchResources: SearchResource[];
197
+ /** Options for the internal NgwConnector (if one needs to be created) */
198
+ connectorOptions?: NgwConnectorOptions;
199
+ }
200
+ declare class NgwProvider extends BaseProvider<NgwProviderOptions> {
201
+ static limit: number;
202
+ searchResources: SearchResource[];
203
+ private connector;
204
+ private _abortControllers;
205
+ constructor(options: NgwProviderOptions);
206
+ abort(): void;
207
+ search(query: string): AsyncGenerator<NgwSearchItem, void, unknown>;
208
+ result(item: NgwSearchItem): CancelablePromise<ResultItem>;
209
+ reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem, void, unknown>;
210
+ private _makeSignal;
211
+ private _items;
212
+ }
213
+
214
+ declare class NominatimProvider extends BaseProvider {
215
+ searchUrl: string;
216
+ private _requests;
217
+ constructor(options?: BaseProviderOptions);
218
+ abort(): void;
219
+ search(val: string): AsyncGenerator<SearchItem, void, unknown>;
220
+ result(model: SearchItem): CancelablePromise<ResultItem>;
221
+ reverse(coordinates: LngLatArray): AsyncGenerator<SearchItem, void, unknown>;
222
+ }
223
+
224
+ declare function create(options: GeocoderOptions): Geocoder;
225
+
226
+ export { BaseProvider, type BaseProviderOptions, Geocoder, type GeocoderOptions, NgwProvider, NominatimProvider, type ResultItem, type SearchItem, create };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextgis/geocoder",
3
- "version": "1.19.2",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "lib/geocoder.esm-bundler.js",
@@ -8,16 +8,16 @@
8
8
  "jsdelivr": "lib/geocoder.global.prod.js",
9
9
  "types": "lib/index.d.ts",
10
10
  "dependencies": {
11
- "@nextgis/cancelable-promise": "^1.19.0",
12
- "@nextgis/ngw-connector": "^1.19.0",
13
- "@nextgis/ngw-kit": "^1.19.2",
14
- "@nextgis/utils": "^1.19.0",
11
+ "@nextgis/cancelable-promise": "^2.0.0-alpha.0",
12
+ "@nextgis/ngw-connector": "^2.0.0-alpha.0",
13
+ "@nextgis/ngw-kit": "^2.0.0-alpha.0",
14
+ "@nextgis/utils": "^2.0.0-alpha.0",
15
15
  "@types/events": "^3.0.0",
16
16
  "@types/geojson": "^7946.0.8",
17
- "events": "^3.3.0"
17
+ "events": "*"
18
18
  },
19
19
  "devDependencies": {
20
- "@nextgis/build-tools": "^1.19.0"
20
+ "@nextgis/build-tools": "^2.0.0-alpha.0"
21
21
  },
22
22
  "buildOptions": {
23
23
  "name": "Geocoder",
@@ -53,5 +53,5 @@
53
53
  "bugs": {
54
54
  "url": "https://github.com/nextgis/nextgis_frontend/issues"
55
55
  },
56
- "gitHead": "c7eb5509183484ef5d30e50e67e9d669e5845c9e"
56
+ "gitHead": "6a4a43d17a08e468d2362f1ae9590094e39aa6cc"
57
57
  }