@@ -22,7 +22,7 @@ export class Pelias implements IGeocoder {
2222 text : query
2323 } ) ;
2424 const data = await getJSON < any > ( this . options . serviceUrl + '/search' , params ) ;
25- return this . _parseResults ( data , 'bbox' ) ;
25+ return this . _parseResults ( data ) ;
2626 }
2727
2828 async suggest ( query : string ) : Promise < GeocodingResult [ ] > {
@@ -31,7 +31,7 @@ export class Pelias implements IGeocoder {
3131 text : query
3232 } ) ;
3333 const data = await getJSON < any > ( this . options . serviceUrl + '/autocomplete' , params ) ;
34- return this . _parseResults ( data , 'bbox' ) ;
34+ return this . _parseResults ( data ) ;
3535 }
3636
3737 async reverse ( location : L . LatLngLiteral , scale : number ) : Promise < GeocodingResult [ ] > {
@@ -41,42 +41,26 @@ export class Pelias implements IGeocoder {
4141 'point.lon' : location . lng
4242 } ) ;
4343 const data = await getJSON < any > ( this . options . serviceUrl + '/reverse' , params ) ;
44- return this . _parseResults ( data , 'bounds' ) ;
44+ return this . _parseResults ( data ) ;
4545 }
4646
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+ } ;
7863 } ) ;
79- return results ;
8064 }
8165}
8266
@@ -133,39 +117,130 @@ export type PeliasResponse = GeoJSON.FeatureCollection<GeoJSON.Geometry, Propert
133117 geocoding : Geocoding ;
134118} ;
135119
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 ;
154126}
155127
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+
156218interface Geocoding {
157- version : string ;
219+ version : string ;
158220 attribution : string ;
159- query : Query ;
160- warnings : string [ ] ;
161- engine : Engine ;
221+ query : Query ;
222+ warnings : string [ ] ;
223+ engine : Engine ;
162224}
163225
164226interface Engine {
165- name : string ;
166- author : string ;
227+ name : string ;
228+ author : string ;
167229 version : string ;
168230}
169231
170232interface 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 [ ] ;
171246}
0 commit comments