Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(magnifying glass): use the magnifying glass to find the first choice to see on the map #1600

Open
wants to merge 13 commits into
base: release/16.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/geo/src/lib/search/search-bar/search-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,33 @@
: undefined
"
[value]="term$ | async"
(keydown.enter)="selectFirstElement()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que le keydown.enter ne devrait pas re-trigger la recherche également?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • sélectionner le 1er résultat?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui sélectionner le résultat avec le score le plus élevé

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je crois que enter devrait redéclancher la recherche.

(keyup)="onKeyup($event)"
(touchend)="onKeyup($event)"
/>
</mat-form-field>

<button
*ngIf="(empty$ | async) === false"
mat-icon-button
matSuffix
[color]="color"
(click)="onClearButtonClick()"
[matTooltip]="'igo.geo.search.clearSearch' | translate"
>
[matTooltip]="'igo.geo.search.clearSearch' | translate">
<mat-icon svgIcon="close"></mat-icon>
</button>
</mat-form-field>

<mat-divider *ngIf="withDivider" [vertical]="true"></mat-divider>

<div class="search-bar-buttons">
<button *ngIf="showSearchButton" mat-icon-button [color]="color">
<mat-divider *ngIf="withDivider" [vertical]="true"></mat-divider>
<div class="search-bar-buttons">

<button *ngIf="showSearchButton" mat-icon-button [color]="color"
(click)="selectFirstElement()"
[matTooltip]="'igo.geo.search.search'|translate">
<mat-icon svgIcon="magnify"></mat-icon>
</button>



<igo-search-selector
*ngIf="searchSelector"
[searchTypes]="searchTypes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ mat-divider {
.search-bar-buttons {
position: relative;
display: inline-flex;
align-items: center;

& > button:nth-child(2)::before {
content: '';
border-right: 1px solid #ddd;
Expand Down
58 changes: 57 additions & 1 deletion packages/geo/src/lib/search/search-bar/search-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { ConfigService } from '@igo2/core';
import { BehaviorSubject, Subscription, timer } from 'rxjs';
import { debounce, distinctUntilChanged } from 'rxjs/operators';

import { FEATURE, Feature, FeatureMotion } from '../../feature';
import { LAYER, LayerOptions, LayerService } from '../../layer';
import { IgoMap } from '../../map';
import { SearchSourceService } from '../shared/search-source.service';
import { SEARCH_TYPES } from '../shared/search.enums';
import { Research, SearchResult } from '../shared/search.interfaces';
Expand Down Expand Up @@ -120,6 +123,11 @@ export class SearchBarComponent implements OnInit, OnDestroy {
*/
@Output() reverseSearchCoordsFormatStatus = new EventEmitter<boolean>();

/**
* Map to add layer
*/
@Input() map: IgoMap;

/**
* Search term
*/
Expand Down Expand Up @@ -253,7 +261,8 @@ export class SearchBarComponent implements OnInit, OnDestroy {
constructor(
private configService: ConfigService,
private searchService: SearchService,
private searchSourceService: SearchSourceService
private searchSourceService: SearchSourceService,
private layerService: LayerService
) {}

/**
Expand Down Expand Up @@ -485,4 +494,51 @@ export class SearchBarComponent implements OnInit, OnDestroy {
this.store.updateMany(newResults);
}
}

/**
* When the user clicks on the magnifying glass and
* this find the first object on the map
*/
selectFirstElement() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qu'est-ce qui arrive si les résultats ne sont pas tous arrivés lorsque l'utilisateur clique le bouton?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rien ne s'est passé, s'il y a un résultat, le résultat avec le score le plus élevé sera mis en évidence

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mais disons q'un utilisateur clique sur le boutin ou fait enter, mais que seul des résultats partiels sont disponible?

Quelle est l'échelle relative comparable entre les résultats? Comment comparer des résultats? Regarde computeTermSimilarity

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chaque résultat a un score donc en utilise le score pour la comparaison

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le score est-il comparable entre les services de recherche?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il faudrait idéalement que ce soit sur une échelle absolue et non pas relative, comme pour iCherche

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le code existant bien tester avec iCherche, le résultats de recherche donne le même objet, donc le score existe si le résultat est une couche ou Feature.
existe-t-il un autre service où je peux tester?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nominatim?

const results = this.store.all();
if (results.length === 0) {
return;
}

// find the highest result score
const result = results.reduce(
(highest, current) =>
current.meta.score > highest.meta.score ? current : highest,
results[0]
);

this.store.state.update(result, { focused: true, selected: true }, true);

if (this.map) {
this.handleMap(this.map, result);
}
}

private handleMap(
map: IgoMap,
result: SearchResult<Record<string, any>>
): void {
const { dataType } = result.meta;

if (dataType === FEATURE) {
const feature = (result as SearchResult<Feature>).data;
map.searchResultsOverlay.setFeatures(
[feature] satisfies Feature[],
FeatureMotion.Default
);
} else if (dataType === LAYER) {
const layerOptions = (result as SearchResult<LayerOptions>).data;
if (layerOptions.sourceOptions.optionsFromApi === undefined) {
layerOptions.sourceOptions.optionsFromApi = true;
}
this.layerService.createAsyncLayer(layerOptions).subscribe((layer) => {
map.addLayer(layer);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ export class SearchResultAddButtonComponent implements OnInit, OnDestroy {
this.isMobile = true;
}
});
if (this.layer.meta.dataType === 'Layer') {
this.added =
this.map.layers.findIndex(
(lay) => lay.id === this.layer.data.sourceOptions.id
) !== -1;
}
this.layers$$ = this.map.layers$.subscribe(() => {
if (this.layer.meta.dataType === 'Layer') {
this.added =
this.map.layers.findIndex(
(lay) => lay.id === this.layer.data.sourceOptions.id
) !== -1;
}
this.isVisible();
});
this.resolution$$ = this.map.viewController.resolution$.subscribe(
Expand Down
1 change: 1 addition & 0 deletions packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@
"layer.placeholder": "Search for a layer",
"ichercheReverse.name": "Search by coordinates",
"clearSearch": "Clear search",
"search":"Search",
"addToLayer": "Add to layer",
"ilayer": {
"name": "Layers",
Expand Down
1 change: 1 addition & 0 deletions packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@
"layer.placeholder": "Rechercher une couche de données.",
"ichercheReverse.name": "Recherche par coordonnées",
"clearSearch": "Effacer la recherche",
"search": "Faire une recherche",
"addToLayer": "Ajouter à une couche",
"ilayer": {
"name": "Couches",
Expand Down
3 changes: 2 additions & 1 deletion projects/demo/src/app/geo/search/search.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IgoContextMenuModule,
IgoPanelModule
} from '@igo2/common';
import { IgoMessageModule } from '@igo2/core';
import { IgoMessageModule, IgoLanguageModule } from '@igo2/core';
import {
IgoFeatureModule,
IgoMapModule,
Expand Down Expand Up @@ -38,6 +38,7 @@ import { AppSearchComponent } from './search.component';
IgoAppSearchModule,
IgoActionbarModule,
IgoContextMenuModule,
IgoLanguageModule,
IgoFeatureModule
],
exports: [AppSearchComponent],
Expand Down