Skip to content

Commit

Permalink
fix(reverseSearch): fix coordinates and feature selection with revers…
Browse files Browse the repository at this point in the history
…e search (#553)
  • Loading branch information
PhilippeLafreniere18 authored and mbarbeau committed Jan 21, 2020
1 parent e600188 commit 85c931b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/geo/src/lib/map/shared/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu
let isXYCoords = false;

str = str.toLocaleUpperCase().trim();
str = str.replace(' ', '');
// Extract projection
if (projectionRegex.test(str)) {
[coordStr, projectionStr] = str.split(';').map(s => s.trim());
} else {
coordStr = str;
}

if (lonLatRegex.test(coordStr)) {

[,
Expand Down Expand Up @@ -228,8 +228,7 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu
}

// Reproject the coordinate if projection parameter have been set and coord is not 4326
if ((projectionStr !== undefined && projectionStr !== toProjection) || (lonLat[0] > 180 || lonLat[0] < -180)) {

if ((projectionStr !== undefined && projectionStr !== toProjection) || (lonLat[0] > 180 || lonLat[0] < -180) || (lonLat[1] > 90 || lonLat[1] < -90)) {
const source = projectionStr ? 'EPSG:' + projectionStr : mapProjection;
const dest = 'EPSG:' + toProjection;

Expand All @@ -239,7 +238,6 @@ export function stringToLonLat(str: string, mapProjection: string): {lonLat: [nu
return {lonLat: undefined, message: 'Projection ' + source + ' not supported', radius: undefined, conf: undefined};
}
}

return {lonLat, message: '', radius: radius ? parseInt(radius, 10) : undefined, conf: conf ? parseInt(conf, 10) : undefined};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ export class SearchResultsComponent implements OnInit, OnDestroy {
* @internal
*/
onResultFocus(result: SearchResult) {
if (this.store.state.get(result)) {
if (this.store.state.get(result).focused === true) {
return;
}
}
this.store.state.update(result, {focused: true}, true);
this.resultFocus.emit(result);
}
Expand Down Expand Up @@ -184,6 +189,11 @@ export class SearchResultsComponent implements OnInit, OnDestroy {
* @internal
*/
onResultSelect(result: SearchResult) {
if (this.store.state.get(result)) {
if (this.store.state.get(result).selected === true) {
return;
}
}
this.store.state.update(result, {focused: true, selected: true}, true);
this.resultSelect.emit(result);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/geo/src/lib/search/shared/sources/coordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export class CoordinatesReverseSearchSource extends SearchSource
OpenStreetMap: OsmLinks.getOpenStreetMapLink(data[0], data[1], 14)
}),
meta: {
id: '1',
id: data[0].toString() + ',' + data[1].toString(),
title: roundedCoordString
}
},
meta: {
dataType: FEATURE,
id: '1',
id: data[0].toString() + ',' + data[1].toString(),
title: roundedCoordString,
icon: 'map-marker'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/search/shared/sources/icherche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export class IChercheReverseSearchSource extends SearchSource
t => t.value === data.properties.type
);
if (type) {
subtitle = type.title;
subtitle = this.languageService.translate.instant(type.title);
}
}
return subtitle;
Expand Down

0 comments on commit 85c931b

Please sign in to comment.