Skip to content

Commit 98a1f4e

Browse files
Merge pull request #100 from digipolisantwerp/feature/GIS-677
Feature/gis 677
2 parents e4936d5 + b857d53 commit 98a1f4e

16 files changed

+102
-43
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file.
1313

1414
## [Unreleased]
1515

16+
### Changed
17+
- [BREAKING] Use of Location Picker API V3
18+
1619
## [5.5.0] - 2022-10-10
1720

1821
### Added

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ The BFF should function solely as a pass-through layer where the API KEY gets ad
5858

5959
> We're using axios for handling requests in the example below. Feel free to use any other library.
6060
61-
Step 1: Create a contract with the "LOCATIONPICKER" on the api-store.
62-
![screenshot](api-store.png)
61+
Step 1: Create a contract with the "LOCATIONPICKER" on the marketplace.
62+
![screenshot](marketplace.png)
6363

6464
Step 2: Copy the api key and api url
6565

6666
Step 3: In your BFF create a .env file and add:
6767
```
6868
API_KEY=00000000-0000-0000-0000-000000000000
69-
LOCATION_PICKER_URL=https://api-gw-o.antwerpen.be/gis/locationpicker/v1
69+
LOCATION_PICKER_URL=https://api-gw-o.antwerpen.be/gis/locationpicker/v3
7070
```
7171

7272
Step 4: Create a new file **locations.routes.js** in **/routes** and add the following contents:
@@ -94,7 +94,7 @@ const locationModel = require('../models/location.model');
9494
* @param res {Response}
9595
*/
9696
exports.proxyLocationRequest = (req, res) => {
97-
const requestPath = req.originalUrl.replace('/api/v1/locations', '');
97+
const requestPath = req.originalUrl.replace('/api/v3/locations', '');
9898

9999
locationModel.handleLocationRequest(requestPath)
100100
.then((response) => {
@@ -140,7 +140,7 @@ Step 7: Add your newly created route to **app.js**
140140
const locationProxy = require('./routes/location.routes');
141141

142142
// Add this after const app = express(); and before any error handler routes
143-
app.use('/api/v1/locations', locationProxy);
143+
app.use('/api/v3/locations', locationProxy);
144144
```
145145

146146
**That's it!** 🎉
@@ -223,6 +223,8 @@ selectedLocation: InitialLocationModel = {
223223
[prioritizeLayers]="prioritizeLayer"
224224
[showClearInputButton]="showClearInputButton"
225225
[sortBy]="sortBy"
226+
[onlyAntwerp]="onlyAntwerp"
227+
[countryCodes]="countryCodes"
226228
[coordinateErrorNotification]="coordinateErrorNotification"
227229
[locateMeNotAllowedNotification]="locateMeNotAllowedNotification"
228230
[locateMeNotSupportedNotification]="locateMeNotSupportedNotification"
@@ -325,6 +327,10 @@ class ExampleComponent {
325327
@Input() prioritizeLayers = ['straatnaam'];
326328
/* Sort locations by certain key. */
327329
@Input() sortBy = '';
330+
/* Search locations and addresses inside Antwerp otherwise will search in provided countries ==> countryCodes */
331+
@Input() onlyAntwerp = true;
332+
/* Search locations and addresses in provided country codes if 'onlyAntwerp' is false*/
333+
@Input() countryCodes = ['be','nl','lu'];
328334
/* Use geolocation when the component finished loading */
329335
@Input() locateUserOnInit = false;
330336
/* Set time to wait after user stops typing before triggering a search */

api-store.png

-115 KB
Binary file not shown.

desktop-view.png

-837 KB
Loading

marketplace.png

21.6 KB
Loading

projects/ngx-location-picker/src/lib/components/ngx-location-picker.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export class NgxLocationPickerComponent implements OnInit, OnDestroy, ControlVal
106106
@Input() prioritizeLayers = ['straatnaam'];
107107
/* Sort locations by certain key. */
108108
@Input() sortBy = '';
109+
/* Search locations and addresses inside Antwerp otherwise will search in provided countries ==> countryCodes */
110+
@Input() onlyAntwerp = true;
111+
/* Search locations and addresses in provided country codes if 'onlyAntwerp' is false*/
112+
@Input() countryCodes = ['be','nl','lu'];
109113
/* Use geolocation when the component finished loading */
110114
@Input() locateUserOnInit = false;
111115
/* Set time to wait after user stops typing before triggering a search */
@@ -509,8 +513,10 @@ export class NgxLocationPickerComponent implements OnInit, OnDestroy, ControlVal
509513
cascadingCoordinateRules: this.cascadingCoordinateRules,
510514
selectedLocation: this.previousLocation,
511515
locationKeywords: this.locationKeywords,
512-
searchStreetNameForAddress: this.searchStreetNameForAddress
513-
};
516+
searchStreetNameForAddress: this.searchStreetNameForAddress,
517+
onlyAntwerp: this.onlyAntwerp,
518+
countryCodes: this.countryCodes
519+
}
514520

515521
this.locationServiceSubscription = this.locationPickerService.delegateSearch(
516522
delegateSearch

projects/ngx-location-picker/src/lib/services/ngx-location-picker.helper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ export class NgxLocationPickerHelper {
178178
*
179179
* @return streetAndNumber
180180
*/
181-
buildAddressQuery(query: string, selectedLocation: LocationModel | AddressModel | CoordinateModel): AddressQueryModel {
181+
buildAddressQuery(query: string, selectedLocation: LocationModel | AddressModel | CoordinateModel, onlyAntwerp: boolean, countryCodes: string[]): AddressQueryModel {
182182
const streetAndNumber: AddressQueryModel = {
183183
streetname: '',
184184
streetids: [],
185-
housenumber: ''
185+
housenumber: '',
186+
onlyAntwerp: onlyAntwerp,
187+
countries: countryCodes
186188
};
187189

188190
const addressParts: Array<string> = (query && query.trim().length > 0) ? query.split(' ') : null;

projects/ngx-location-picker/src/lib/services/ngx-location-picker.service.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Injectable } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
33
import { Observable } from 'rxjs';
4+
import { map } from 'rxjs/operators';
45
import { NgxLocationPickerHelper } from './ngx-location-picker.helper';
56
import { LambertModel, LocationModel } from '../types/location.model';
67
import { AddressQueryModel } from '../types/address-query.model';
78
import { LocationQueryModel } from '../types/location-query.model';
8-
import { LayerQueryModel } from '../types/layer-query.model';
9-
import { LayerModel } from '../types/layer.model';
109
import { AddressIdQueryModel } from '../types/address-id-query.model';
1110
import { CoordinateQueryModel } from '../types/coordinate-query.model';
1211
import { 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';
1513
import { 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
}

projects/ngx-location-picker/src/lib/types/address-query.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export interface AddressQueryModel {
22
streetname: string;
33
streetids: number[];
44
housenumber: string;
5+
onlyAntwerp: boolean;
6+
countries: string[];
57
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { CascadingCoordinateRulesModel } from './cascading-rules.model';
2+
13
export interface CoordinateQueryModel {
24
xcoord: number;
35
ycoord: number;
46
returnsingle?: boolean;
57
totalresults?: number;
8+
cascadingRules: Array<CascadingCoordinateRulesModel>
69
}

0 commit comments

Comments
 (0)