11import { Injectable } from '@angular/core' ;
22import { HttpClient } from '@angular/common/http' ;
33import { Observable } from 'rxjs' ;
4+ import { map } from 'rxjs/operators' ;
45import { NgxLocationPickerHelper } from './ngx-location-picker.helper' ;
56import { LambertModel , LocationModel } from '../types/location.model' ;
67import { AddressQueryModel } from '../types/address-query.model' ;
78import { LocationQueryModel } from '../types/location-query.model' ;
8- import { LayerQueryModel } from '../types/layer-query.model' ;
9- import { LayerModel } from '../types/layer.model' ;
109import { AddressIdQueryModel } from '../types/address-id-query.model' ;
1110import { CoordinateQueryModel } from '../types/coordinate-query.model' ;
1211import { AddressModel } from '../types/address.model' ;
13- import { CoordinateModel } from '../types/coordinate.model' ;
14- import { CascadingCoordinateRulesModel } from '../types/cascading-rules.model' ;
12+ import { CoordinateModel , CoordinateSearchResponse } from '../types/coordinate.model' ;
1513import { DelegateSearchModel } from '../types/delegate-search.model' ;
14+ import { PagedResult } from '../types/pagedresult.model'
1615
1716@Injectable ( {
1817 providedIn : 'root'
@@ -57,22 +56,27 @@ export class NgxLocationPickerService {
5756 xcoord : coordinate . x ,
5857 ycoord : coordinate . y ,
5958 returnsingle : delegateSearch . cascadingCoordinateReturnSingle ,
60- totalresults : delegateSearch . cascadingCoordinateLimit
59+ totalresults : delegateSearch . cascadingCoordinateLimit ,
60+ cascadingRules : delegateSearch . cascadingCoordinateRules
6161 } ;
6262
63- return this . searchLocationsByCoordinates ( requestQuery , delegateSearch . cascadingCoordinateRules ) ;
63+ return this . searchLocationsByCoordinates ( requestQuery ) ;
6464 } else if ( this . locationPickerHelper . isAddress ( delegateSearch . search , delegateSearch . locationKeywords ) ) {
6565 const addressQuery : AddressQueryModel = this . locationPickerHelper . buildAddressQuery (
6666 delegateSearch . search ,
67- delegateSearch . selectedLocation
67+ delegateSearch . selectedLocation ,
68+ delegateSearch . onlyAntwerp ,
69+ delegateSearch . countryCodes
6870 ) ;
6971 if ( delegateSearch . searchStreetNameForAddress ) {
7072 const locationQuery : LocationQueryModel = {
7173 layers : [ 'straatnaam' ] ,
72- limit : delegateSearch . limit ,
74+ pagesize : delegateSearch . limit ,
7375 search : addressQuery . streetname ,
7476 prioritizelayer : delegateSearch . prioritizelayer ,
75- sort : delegateSearch . sort
77+ sort : delegateSearch . sort ,
78+ onlyAntwerp : delegateSearch . onlyAntwerp ,
79+ countries : delegateSearch . countryCodes
7680 } ;
7781
7882 return this . searchLocations ( locationQuery ) ;
@@ -82,27 +86,27 @@ export class NgxLocationPickerService {
8286 } else {
8387 const locationQuery : LocationQueryModel = {
8488 layers : delegateSearch . layers ,
85- limit : delegateSearch . limit ,
89+ pagesize : delegateSearch . limit ,
8690 search : delegateSearch . search ,
8791 prioritizelayer : delegateSearch . prioritizelayer ,
88- sort : delegateSearch . sort
92+ sort : delegateSearch . sort ,
93+ onlyAntwerp : delegateSearch . onlyAntwerp ,
94+ countries : delegateSearch . countryCodes
8995 } ;
9096
9197 return this . searchLocations ( locationQuery ) ;
9298 }
9399 }
94100
95101 /**
96- * Returns a list of layers based on the provided map service.
97- *
98- * @param query (the map service to load layers from)
102+ * Returns a list of layers present in elastic.
99103 *
100104 * @return Observable<LayerModel[]>
101105 */
102- getMapLayers ( query : LayerQueryModel ) : Observable < LayerModel [ ] > {
103- const parameters = this . locationPickerHelper . toHttpParams ( query ) ;
104-
105- return this . httpClient . get < LayerModel [ ] > ( ` ${ this . locationPickerApi } / layers` , { params : parameters } ) ;
106+ getLayers ( ) : Observable < string [ ] > {
107+ return this . httpClient
108+ . get < PagedResult < 'layers' , string > > ( ` ${ this . locationPickerApi } /layers` )
109+ . pipe ( map ( ( pagedResult : PagedResult < ' layers' , string > ) => pagedResult . _embedded . layers ) ) ;
106110 }
107111
108112 /**
@@ -115,7 +119,9 @@ export class NgxLocationPickerService {
115119 private searchLocations ( query : LocationQueryModel ) : Observable < LocationModel [ ] > {
116120 const parameters = this . locationPickerHelper . toHttpParams ( query ) ;
117121
118- return this . httpClient . get < LocationModel [ ] > ( `${ this . locationPickerApi } /locations` , { params : parameters } ) ;
122+ return this . httpClient
123+ . get < PagedResult < 'locations' , LocationModel > > ( `${ this . locationPickerApi } /locations` , { params : parameters } )
124+ . pipe ( map ( ( pagedResult : PagedResult < 'locations' , LocationModel > ) => pagedResult . _embedded . locations ) ) ;
119125 }
120126
121127 /**
@@ -128,7 +134,9 @@ export class NgxLocationPickerService {
128134 private searchAddresses ( query : AddressQueryModel ) : Observable < AddressModel [ ] > {
129135 const parameters = this . locationPickerHelper . toHttpParams ( query ) ;
130136
131- return this . httpClient . get < AddressModel [ ] > ( `${ this . locationPickerApi } /addresses` , { params : parameters } ) ;
137+ return this . httpClient
138+ . get < PagedResult < 'addresses' , AddressModel > > ( `${ this . locationPickerApi } /addresses` , { params : parameters } )
139+ . pipe ( map ( ( pagedResult : PagedResult < 'addresses' , AddressModel > ) => pagedResult . _embedded . addresses ) ) ;
132140 }
133141
134142 /**
@@ -152,12 +160,11 @@ export class NgxLocationPickerService {
152160 * @return Observable<CoordinateModel[]>
153161 */
154162 private searchLocationsByCoordinates (
155- query : CoordinateQueryModel ,
156- cascadingCoordinateRules : Array < CascadingCoordinateRulesModel >
163+ query : CoordinateQueryModel
157164 ) : Observable < CoordinateModel [ ] > {
158- const parameters = this . locationPickerHelper . toHttpParams ( query ) ;
159-
160- return this . httpClient . post < CoordinateModel [ ] > ( ` ${ this . locationPickerApi } /coordinates` ,
161- cascadingCoordinateRules , { params : parameters } ) ;
165+ return this . httpClient
166+ . post < CoordinateSearchResponse > ( ` ${ this . locationPickerApi } /coordinates/search` ,
167+ query )
168+ . pipe ( map ( ( result : CoordinateSearchResponse ) => result . results ) ) ;
162169 }
163170}
0 commit comments