Skip to content

Commit

Permalink
feat(icherche): can restrict by extent
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Jan 10, 2020
1 parent f78edaf commit ff828a0
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ export class IgoMap {

// TODO: Move to ViewController and update every place it's used
getCenter(projection?: string | OlProjection): [number, number] {
return this.viewController.getCenter();
return this.viewController.getCenter(projection);
}

// TODO: Move to ViewController and update every place it's used
getExtent(projection?: string | OlProjection): MapExtent {
return this.viewController.getExtent();
return this.viewController.getExtent(projection);
}

// TODO: Move to ViewController and update every place it's used
Expand Down
45 changes: 29 additions & 16 deletions packages/geo/src/lib/search/shared/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
} from './sources/source.interfaces';
import { SearchSourceService } from './search-source.service';
import { Research } from './search.interfaces';
import { sourceCanSearch, sourceCanReverseSearch, sourceCanReverseSearchAsSummary } from './search.utils';
import {
sourceCanSearch,
sourceCanReverseSearch,
sourceCanReverseSearchAsSummary
} from './search.utils';

/**
* This service perform researches in all the search sources enabled.
Expand All @@ -33,7 +37,7 @@ export class SearchService {
* @param term Any text
* @returns Researches
*/
search(term: string, options?: TextSearchOptions): Research[] {
search(term: string, options: TextSearchOptions = {}): Research[] {
if (!this.termIsValid(term)) {
return [];
}
Expand All @@ -45,31 +49,40 @@ export class SearchService {
console.log(response.message);
}

options.extent = this.mapService
.getMap()
.viewController.getExtent('EPSG:4326');

let sources = this.searchSourceService.getEnabledSources();

if (options) {
if (options.getEnabledOnly || options.getEnabledOnly === undefined) {
sources = this.searchSourceService.getEnabledSources();
} else {
sources = this.searchSourceService.getSources();
}
if (options.searchType) {
sources = sources.filter(
source => source.getType() === options.searchType
);
}
if (options.getEnabledOnly || options.getEnabledOnly === undefined) {
sources = this.searchSourceService.getEnabledSources();
} else {
sources = this.searchSourceService.getSources();
}
if (options.searchType) {
sources = sources.filter(
source => source.getType() === options.searchType
);
}

sources = sources.filter(sourceCanSearch);
return this.searchSources(sources, term, options || {});
return this.searchSources(sources, term, options);
}

/**
* Perform a research by lon/lat
* @param lonLat Any lon/lat coordinates
* @returns Researches
*/
reverseSearch(lonLat: [number, number], options?: ReverseSearchOptions, asPointerSummary: boolean = false) {
const reverseSourceFonction = asPointerSummary ? sourceCanReverseSearchAsSummary : sourceCanReverseSearch;
reverseSearch(
lonLat: [number, number],
options?: ReverseSearchOptions,
asPointerSummary: boolean = false
) {
const reverseSourceFonction = asPointerSummary
? sourceCanReverseSearchAsSummary
: sourceCanReverseSearch;
const sources = this.searchSourceService
.getEnabledSources()
.filter(reverseSourceFonction);
Expand Down
28 changes: 27 additions & 1 deletion packages/geo/src/lib/search/shared/sources/icherche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ export class IChercheSearchSource extends SearchSource implements TextSearch {
enabled: ecmax === 100
}
]
},
{
type: 'radiobutton',
title: 'restrictExtent',
name: 'loc',
values: [
{
title: 'igo.geo.search.icherche.restrictExtent.map',
value: 'true',
enabled: false
},
{
title: 'igo.geo.search.icherche.restrictExtent.quebec',
value: 'false',
enabled: true
}
]
}
]
};
Expand All @@ -275,7 +292,9 @@ export class IChercheSearchSource extends SearchSource implements TextSearch {
map((response: IChercheResponse) => this.extractResults(response)),
catchError(err => {
err.error.toDisplay = true;
err.error.title = this.getDefaultOptions().title;
err.error.title = this.languageService.translate.instant(
this.getDefaultOptions().title
);
throw err;
})
);
Expand Down Expand Up @@ -321,6 +340,13 @@ export class IChercheSearchSource extends SearchSource implements TextSearch {
this.computeOptionsParam(term, options || {}).params
);

if (queryParams.loc === 'true') {
const [xMin, yMin, xMax, yMax] = options.extent;
queryParams.loc = `${xMin},${yMin};${xMax},${yMin};${xMax},${yMax};${xMin},${yMax};${xMin},${yMin}`;
} else if (queryParams.loc === 'false') {
delete queryParams.loc;
}

if (queryParams.q.indexOf('#') !== -1) {
queryParams.type = 'lieux';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/search/shared/sources/nominatim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class NominatimSearchSource extends SearchSource implements TextSearch {
},
{
type: 'radiobutton',
title: 'country limitation',
title: 'restrictExtent',
name: 'countrycodes',
values: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface TextSearchOptions {
params?: { [key: string]: string };
searchType?: 'Feature' | 'Layer'; // refer to search.enum.ts SEARCH_TYPES = [FEATURE, LAYER];
getEnabledOnly?: boolean;
extent?: [number, number, number, number];
}

export interface ReverseSearchOptions {
Expand Down
6 changes: 5 additions & 1 deletion packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@
"sumi": "SUMI mark",
"km": "Mileage mark",
"entreprise": "Entreprise"
},
"restrictExtent": {
"map": "À l'étendue de la carte",
"quebec": "Au Québec"
}
},
"coordinates": {
Expand All @@ -296,7 +300,7 @@
"radius": "Search radius",
"results limit": "Number of results",
"multiple object": "Multiple object",
"country limitation": "Limitation (country)",
"restrictExtent": "Restrict the extent",
"selectAll": "Select All",
"unselectAll": "Unselect All",
"true": "Yes",
Expand Down
6 changes: 5 additions & 1 deletion packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@
"sumi": "Borne SUMI",
"km": "Repère kilométrique",
"entreprise": "Entreprise"
},
"restrictExtent": {
"map": "À l'étendue de la carte",
"quebec": "Au Québec"
}
},
"coordinates": {
Expand All @@ -296,7 +300,7 @@
"radius": "Rayon de recherche",
"results limit": "Nombre de résultats",
"multiple object": "Objet multiple",
"country limitation": "Limitation (pays)",
"restrictExtent": "Restreint l'étendue",
"selectAll": "Tout sélectionner",
"unselectAll": "Tout désélectionner",
"true": "Oui",
Expand Down

0 comments on commit ff828a0

Please sign in to comment.