@@ -22,7 +22,7 @@ export class Pelias implements IGeocoder {
22
22
text : query
23
23
} ) ;
24
24
const data = await getJSON < any > ( this . options . serviceUrl + '/search' , params ) ;
25
- return this . _parseResults ( data , 'bbox' ) ;
25
+ return this . _parseResults ( data ) ;
26
26
}
27
27
28
28
async suggest ( query : string ) : Promise < GeocodingResult [ ] > {
@@ -31,7 +31,7 @@ export class Pelias implements IGeocoder {
31
31
text : query
32
32
} ) ;
33
33
const data = await getJSON < any > ( this . options . serviceUrl + '/autocomplete' , params ) ;
34
- return this . _parseResults ( data , 'bbox' ) ;
34
+ return this . _parseResults ( data ) ;
35
35
}
36
36
37
37
async reverse ( location : L . LatLngLiteral , scale : number ) : Promise < GeocodingResult [ ] > {
@@ -41,42 +41,26 @@ export class Pelias implements IGeocoder {
41
41
'point.lon' : location . lng
42
42
} ) ;
43
43
const data = await getJSON < any > ( this . options . serviceUrl + '/reverse' , params ) ;
44
- return this . _parseResults ( data , 'bounds' ) ;
44
+ return this . _parseResults ( data ) ;
45
45
}
46
46
47
- _parseResults ( data , bboxname ) : GeocodingResult [ ] {
48
- const results : GeocodingResult [ ] = [ ] ;
49
- new L . GeoJSON ( data , {
50
- pointToLayer ( feature , latlng ) {
51
- return new L . CircleMarker ( latlng , { radius : 10 } ) ;
52
- } ,
53
- onEachFeature ( feature , layer : any ) {
54
- const result = { } as GeocodingResult ;
55
- let bbox ;
56
- let center ;
57
-
58
- if ( layer . getBounds ) {
59
- bbox = layer . getBounds ( ) ;
60
- center = bbox . getCenter ( ) ;
61
- } else if ( layer . feature . bbox ) {
62
- center = layer . getLatLng ( ) ;
63
- bbox = new L . LatLngBounds (
64
- L . GeoJSON . coordsToLatLng ( layer . feature . bbox . slice ( 0 , 2 ) ) ,
65
- L . GeoJSON . coordsToLatLng ( layer . feature . bbox . slice ( 2 , 4 ) )
66
- ) ;
67
- } else {
68
- center = layer . getLatLng ( ) ;
69
- bbox = new L . LatLngBounds ( center , center ) ;
70
- }
71
-
72
- result . name = layer . feature . properties . label ;
73
- result . center = center ;
74
- result [ bboxname ] = bbox ;
75
- result . properties = layer . feature . properties ;
76
- results . push ( result ) ;
77
- }
47
+ _parseResults ( data : GeoJSON . FeatureCollection < GeoJSON . Point > ) : GeocodingResult [ ] {
48
+ return ( data . features || [ ] ) . map ( ( f ) : GeocodingResult => {
49
+ const c = f . geometry . coordinates ;
50
+ const center = new L . LatLng ( c [ 1 ] , c [ 0 ] ) ;
51
+
52
+ const bbox =
53
+ Array . isArray ( f . bbox ) && f . bbox . length === 4
54
+ ? new L . LatLngBounds ( [ f . bbox [ 1 ] , f . bbox [ 0 ] ] , [ f . bbox [ 3 ] , f . bbox [ 2 ] ] )
55
+ : new L . LatLngBounds ( center , center ) ;
56
+
57
+ return {
58
+ name : f . properties ! . label ,
59
+ center,
60
+ bbox,
61
+ properties : f . properties
62
+ } ;
78
63
} ) ;
79
- return results ;
80
64
}
81
65
}
82
66
@@ -133,39 +117,130 @@ export type PeliasResponse = GeoJSON.FeatureCollection<GeoJSON.Geometry, Propert
133
117
geocoding : Geocoding ;
134
118
} ;
135
119
136
- interface Properties {
137
- id : string ;
138
- layer : string ;
139
- source_id : string ;
140
- name : string ;
141
- confidence : number ;
142
- match_type : string ;
143
- accuracy : string ;
144
- country : string ;
145
- country_a : string ;
146
- region : string ;
147
- region_a : string ;
148
- county : string ;
149
- county_a : string ;
150
- localadmin : string ;
151
- locality : string ;
152
- continent : string ;
153
- label : string ;
120
+ interface Identity {
121
+ id : string ;
122
+ gid : string ;
123
+ layer : string ;
124
+ source : string ;
125
+ source_id : string ;
154
126
}
155
127
128
+ interface Labels {
129
+ name : string ;
130
+ label : string ;
131
+ category ?: string [ ] ;
132
+ }
133
+
134
+ interface Hierarchy {
135
+ country_code ?: string ;
136
+
137
+ ocean ?: string ;
138
+ ocean_gid ?: string ;
139
+ ocean_a ?: string ;
140
+
141
+ marinearea ?: string ;
142
+ marinearea_gid ?: string ;
143
+ marinearea_a ?: string ;
144
+
145
+ continent ?: string ;
146
+ continent_gid ?: string ;
147
+ continent_a ?: string ;
148
+
149
+ empire ?: string ;
150
+ empire_gid ?: string ;
151
+ empire_a ?: string ;
152
+
153
+ country ?: string ;
154
+ country_gid ?: string ;
155
+ country_a ?: string ;
156
+
157
+ dependency ?: string ;
158
+ dependency_gid ?: string ;
159
+ dependency_a ?: string ;
160
+
161
+ macroregion ?: string ;
162
+ macroregion_gid ?: string ;
163
+ macroregion_a ?: string ;
164
+
165
+ region ?: string ;
166
+ region_gid ?: string ;
167
+ region_a ?: string ;
168
+
169
+ macrocounty ?: string ;
170
+ macrocounty_gid ?: string ;
171
+ macrocounty_a ?: string ;
172
+
173
+ county ?: string ;
174
+ county_gid ?: string ;
175
+ county_a ?: string ;
176
+
177
+ localadmin ?: string ;
178
+ localadmin_gid ?: string ;
179
+ localadmin_a ?: string ;
180
+
181
+ locality ?: string ;
182
+ locality_gid ?: string ;
183
+ locality_a ?: string ;
184
+
185
+ borough ?: string ;
186
+ borough_gid ?: string ;
187
+ borough_a ?: string ;
188
+
189
+ neighbourhood ?: string ;
190
+ neighbourhood_gid ?: string ;
191
+ neighbourhood_a ?: string ;
192
+
193
+ postalcode ?: string ;
194
+ postalcode_gid ?: string ;
195
+ postalcode_a ?: string ;
196
+ }
197
+
198
+ interface Address {
199
+ unit ?: string ;
200
+ housenumber ?: string ;
201
+ street ?: string ;
202
+ postalcode ?: string ;
203
+ }
204
+
205
+ interface Scoring {
206
+ accuracy : string ;
207
+ confidence ?: number ;
208
+ distance ?: number ;
209
+ match_type ?: string ;
210
+ }
211
+
212
+ interface Addendum {
213
+ addendum ?: Record < string , Object > ;
214
+ }
215
+
216
+ interface Properties extends Identity , Labels , Scoring , Address , Hierarchy , Addendum { }
217
+
156
218
interface Geocoding {
157
- version : string ;
219
+ version : string ;
158
220
attribution : string ;
159
- query : Query ;
160
- warnings : string [ ] ;
161
- engine : Engine ;
221
+ query : Query ;
222
+ warnings : string [ ] ;
223
+ engine : Engine ;
162
224
}
163
225
164
226
interface Engine {
165
- name : string ;
166
- author : string ;
227
+ name : string ;
228
+ author : string ;
167
229
version : string ;
168
230
}
169
231
170
232
interface Query {
233
+ size : number ;
234
+ lang : {
235
+ name : string ;
236
+ iso6391 : string ;
237
+ iso6393 : string ;
238
+ via : string ;
239
+ defaulted : boolean
240
+ }
241
+ text ?: string ;
242
+ parser ?: string ;
243
+ parsed_text ?: Record < string , string > ;
244
+ sources ?: string [ ] ;
245
+ layers ?: string [ ] ;
171
246
}
0 commit comments