@@ -66,25 +66,20 @@ export class HERE implements IGeocoder {
6666
6767 async getJSON ( url : string , params : any ) : Promise < GeocodingResult [ ] > {
6868 const data = await getJSON < any > ( url , params ) ;
69- const results : GeocodingResult [ ] = [ ] ;
70-
71- if ( data . response . view && data . response . view . length ) {
72- for ( let i = 0 ; i <= data . response . view [ 0 ] . result . length - 1 ; i ++ ) {
73- const loc = data . response . view [ 0 ] . result [ i ] . location ;
74- const center = L . latLng ( loc . displayPosition . latitude , loc . displayPosition . longitude ) ;
75- const bbox = L . latLngBounds (
76- L . latLng ( loc . mapView . topLeft . latitude , loc . mapView . topLeft . longitude ) ,
77- L . latLng ( loc . mapView . bottomRight . latitude , loc . mapView . bottomRight . longitude )
78- ) ;
79- results [ i ] = {
80- name : loc . address . label ,
81- properties : loc . address ,
82- bbox : bbox ,
83- center : center
84- } ;
85- }
86- }
87- return results ;
69+ return ( data . response . view ?. [ 0 ] ?. result || [ ] ) . map ( ( result ) : GeocodingResult => {
70+ const loc = result . location ;
71+ const center = L . latLng ( loc . displayPosition . latitude , loc . displayPosition . longitude ) ;
72+ const bbox = L . latLngBounds (
73+ L . latLng ( loc . mapView . topLeft . latitude , loc . mapView . topLeft . longitude ) ,
74+ L . latLng ( loc . mapView . bottomRight . latitude , loc . mapView . bottomRight . longitude )
75+ ) ;
76+ return {
77+ name : loc . address . label ,
78+ properties : loc . address ,
79+ bbox,
80+ center
81+ } ;
82+ } ) ;
8883 }
8984}
9085
@@ -131,34 +126,28 @@ export class HEREv2 implements IGeocoder {
131126
132127 async getJSON ( url : string , params : any ) : Promise < GeocodingResult [ ] > {
133128 const data = await getJSON < HEREv2Response > ( url , params ) ;
134- const results : GeocodingResult [ ] = [ ] ;
135-
136- if ( data . items && data . items . length ) {
137- for ( let i = 0 ; i <= data . items . length - 1 ; i ++ ) {
138- const item = data . items [ i ] ;
139- const latLng = L . latLng ( item . position . lat , item . position . lng ) ;
140- let bbox : L . LatLngBounds ;
141- if ( item . mapView ) {
142- bbox = L . latLngBounds (
143- L . latLng ( item . mapView . south , item . mapView . west ) ,
144- L . latLng ( item . mapView . north , item . mapView . east )
145- ) ;
146- } else {
147- // Using only position when not provided
148- bbox = L . latLngBounds (
149- L . latLng ( item . position . lat , item . position . lng ) ,
150- L . latLng ( item . position . lat , item . position . lng )
151- ) ;
152- }
153- results [ i ] = {
154- name : item . address . label ,
155- properties : item . address ,
156- bbox : bbox ,
157- center : latLng
158- } ;
129+ return ( data . items || [ ] ) . map ( ( item ) : GeocodingResult => {
130+ const center = L . latLng ( item . position . lat , item . position . lng ) ;
131+ let bbox : L . LatLngBounds ;
132+ if ( item . mapView ) {
133+ bbox = L . latLngBounds (
134+ L . latLng ( item . mapView . south , item . mapView . west ) ,
135+ L . latLng ( item . mapView . north , item . mapView . east )
136+ ) ;
137+ } else {
138+ // Using only position when not provided
139+ bbox = L . latLngBounds (
140+ L . latLng ( item . position . lat , item . position . lng ) ,
141+ L . latLng ( item . position . lat , item . position . lng )
142+ ) ;
159143 }
160- }
161- return results ;
144+ return {
145+ name : item . address . label ,
146+ properties : item . address ,
147+ bbox,
148+ center
149+ } ;
150+ } ) ;
162151 }
163152}
164153
0 commit comments