Skip to content

Commit

Permalink
fix(search-recent): no more recent searches
Browse files Browse the repository at this point in the history
  • Loading branch information
azarz committed Apr 15, 2024
1 parent e1c09c7 commit fe81a4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/js/event-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ function addListeners() {
var geocode = false;
/* Résultats autocompletion ou recherche récente */
let coords = null;
let save = true;
if ( evt.target.classList.contains("autocompresult") || evt.target.classList.contains("recentresult")) {
geocode = true;
save = !evt.target.classList.contains("recentresult");
evt.target.classList.add("autocompresultselected");
DOM.$rech.value = evt.target.getAttribute("fulltext");
coords = JSON.parse(evt.target.dataset.coordinates);
Expand All @@ -36,21 +38,21 @@ function addListeners() {
if (geocode) {
if (Globals.backButtonState === "searchDirections") {
setTimeout(() => {
Geocode.search(DOM.$rech.value, coords);
Geocode.search(DOM.$rech.value, coords, save);
Globals.menu.open("directions");
}, 250);
} else if(Globals.backButtonState === "searchIsochrone") {
setTimeout(() => {
Geocode.search(DOM.$rech.value, coords);
Geocode.search(DOM.$rech.value, coords, save);
Globals.menu.open("isochrone");
}, 250);
} else if(Globals.backButtonState === "searchLandmark") {
setTimeout(() => {
Geocode.search(DOM.$rech.value, coords);
Geocode.search(DOM.$rech.value, coords, save);
Globals.menu.open("landmark");
}, 250);
} else {
Geocode.searchAndMoveTo(DOM.$rech.value, coords);
Geocode.searchAndMoveTo(DOM.$rech.value, coords, save);
setTimeout(() => Globals.menu.close("search"), 250);
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/js/services/geocode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DOM from "../dom";
import Globals from "../globals";
import RecentSearch from "../search-recent";


/**
* Interface pour les evenements
* @example
Expand Down Expand Up @@ -53,14 +52,23 @@ function moveTo(coords, zoom=Globals.map.getZoom(), panTo=true) {
* @returns
* @fire search
*/
async function search (text, coords) {
async function search (text, coords, save = true) {
/**
* Recherche un texte et le géocode à l'aide de look4,
* puis va à sa position en ajoutant un marqueur
*/
if (text === "") {
return;
}
if (save) {
RecentSearch.add({
text: text,
coordinates: {
lat: coords.lat,
lon: coords.lon
}
});
}
DOM.$rech.value = text;
const geocode_result = {
fulltext: text,
Expand Down Expand Up @@ -91,8 +99,8 @@ async function search (text, coords) {
* recherche et deplacement sur la carte
* @param {*} text
*/
async function searchAndMoveTo(text, coord = null) {
var coords = await search(text, coord);
async function searchAndMoveTo(text, coord = null, save = true) {
var coords = await search(text, coord, save);
moveTo(coords, 14);
}

Expand Down

0 comments on commit fe81a4e

Please sign in to comment.