Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Use qwant_id param for poi #1470

Merged
merged 5 commits into from
Oct 17, 2023
Merged
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
2 changes: 2 additions & 0 deletions @types/idunn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,8 @@ export interface components {
type: string;
/** Id */
id?: string;
/** Qwant Id */
qwant_id?: string;
/** Name */
name?: string;
/** Local Name */
Expand Down
1 change: 1 addition & 0 deletions src/adapters/poi/bragi_poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class BragiPoi extends Poi {
}

super(
id,
id,
name,
type,
Expand Down
13 changes: 11 additions & 2 deletions src/adapters/poi/idunn_poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ export default class IdunnPoi extends Poi {
lng: (rawPoi?.geometry?.coordinates as number[])[0],
} as TPoi['latLon'];

super(rawPoi.id, rawPoi.name, rawPoi.type, latLng, rawPoi.class_name, rawPoi.subclass_name);
super(
rawPoi.id,
rawPoi.id,
rawPoi.name,
rawPoi.type,
latLng,
rawPoi.class_name,
rawPoi.subclass_name
);
this.blocks = rawPoi.blocks;
this.localName = rawPoi.local_name;
this.bbox = rawPoi?.geometry?.bbox as [number, number, number, number]; // TODO: Check if there is always a bbox on Idunn Place
Expand Down Expand Up @@ -115,11 +123,12 @@ export default class IdunnPoi extends Poi {
static async poiApiLoad(
obj: {
id?: string;
qwant_id?: string;
queryContext?: TQueryContext;
},
options: { simple?: boolean } = {}
) {
const url = `${serviceConfig.idunn.url}/v1/places/${obj.id}`;
const url = `${serviceConfig.idunn.url}/v1/places/${obj.qwant_id}`;
let requestParams = {};
if (options.simple) {
requestParams = { verbosity: 'list' };
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/poi/latlon_poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class LatLonPoi extends Poi {
if (!label) {
label = `${lnglat.lat.toFixed(5)} : ${lnglat.lng.toFixed(5)}`;
}
super(id, label, undefined, lnglat, undefined, undefined);
super(id, id, label, undefined, lnglat, undefined, undefined);
this.type = 'latlon';
}
}
10 changes: 8 additions & 2 deletions src/adapters/poi/map_poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import Poi, { POI_TYPE } from './poi';

export default class MapPoi extends Poi {
constructor(feature) {
const { global_id, ['class']: className, subclass: subClassName, name } = feature.properties;
const {
global_id,
['class']: className,
subclass: subClassName,
name,
qwant_id,
} = feature.properties;
const ll = LngLat.convert(feature.geometry.coordinates);
super(global_id || feature.id, name, POI_TYPE, ll, className, subClassName);
super(global_id || feature.id, qwant_id, name, POI_TYPE, ll, className, subClassName);
}
}
8 changes: 6 additions & 2 deletions src/adapters/poi/poi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const POI_TYPE = 'poi';

export type TPoi = {
id?: string;
qwant_id?: string;
name?: string;
type?: string;
latLon?: LngLat;
Expand All @@ -17,6 +18,7 @@ export type TPoi = {

export default class Poi {
id: TPoi['id'];
qwant_id: TPoi['qwant_id'];
name: TPoi['name'];
type: TPoi['type'];
latLon: TPoi['latLon'];
Expand All @@ -26,6 +28,7 @@ export default class Poi {

constructor(
id: TPoi['id'],
qwant_id: TPoi['qwant_id'],
name: TPoi['name'],
type: TPoi['type'],
latLon: TPoi['latLon'],
Expand All @@ -34,6 +37,7 @@ export default class Poi {
bbox?: TPoi['bbox']
) {
this.id = id;
this.qwant_id = qwant_id;
this.name = name;
this.type = type;
this.latLon = latLon;
Expand All @@ -43,7 +47,7 @@ export default class Poi {
}

static deserialize(raw: TPoi) {
const { id, name, type, latLon, className, subClassName, bbox } = raw;
return new Poi(id, name, type, latLon, className, subClassName, bbox);
const { id, qwant_id, name, type, latLon, className, subClassName, bbox } = raw;
return new Poi(id, qwant_id, name, type, latLon, className, subClassName, bbox);
}
}
2 changes: 1 addition & 1 deletion src/adapters/poi/specials/navigator_geolocalisation_poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const navigatorGeolocationStatus = {
};
export default class NavigatorGeolocalisationPoi extends Poi {
constructor() {
super('geolocalisation', _('Your position', 'direction'), 'geoloc');
super('geolocalisation', 'geolocalisation', _('Your position', 'direction'), 'geoloc');
this.status = navigatorGeolocationStatus.UNKNOWN;
}

Expand Down
5 changes: 4 additions & 1 deletion src/adapters/poi_popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ PoiPopup.prototype.addListener = function (layer) {
};

PoiPopup.prototype.createOSMPopup = async function (layerPoi, event) {
const poi = await ApiPoi.poiApiLoad({ id: layerPoi.properties.global_id }, { simple: true });
const poi = await ApiPoi.poiApiLoad(
{ id: layerPoi.properties.global_id, qwant_id: layerPoi.properties.qwant_id },
{ simple: true }
);
if (poi) {
this.showPopup(poi, event);
}
Expand Down
1 change: 0 additions & 1 deletion src/adapters/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ Scene.prototype.initMapBox = function ({ locationHash, bbox }) {
Scene.prototype.clickOnMap = function (lngLat, clickedFeature, { longTouch = false } = {}) {
// Instantiate the place clicked as a PoI
const poi = clickedFeature ? new MapPoi(clickedFeature) : new LatLonPoi(lngLat);

if (document.querySelector('.directions-open')) {
// If Direction panel is open, tell it to fill its fields with this PoI
fire('set_direction_point', poi);
Expand Down
4 changes: 2 additions & 2 deletions src/libs/pois.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function toUrl(poi) {
if (poi.id === 'geolocalisation' || poi.type === 'latlon') {
return `latlon:${poi.latLon.lat.toFixed(5)}:${poi.latLon.lng.toFixed(5)}`;
}
return poi.name ? `${poi.id}@${slug(poi.name)}` : poi.id;
return poi.name ? `${poi.qwant_id}@${slug(poi.name)}` : poi.qwant_id;
}

export function toAbsoluteUrl(poi) {
Expand All @@ -36,7 +36,7 @@ export function fromUrl(urlParam) {
urlData = urlParam.match(/^(.*?)(@(.*))?$/);
if (urlData) {
const idunnId = urlData[1];
return IdunnPoi.poiApiLoad({ id: idunnId });
return IdunnPoi.poiApiLoad({ id: idunnId, qwant_id: idunnId });
}
return Promise.reject();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/favorites_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export async function toggleFavoritePanel(page) {

export async function storePoi(
page,
{ id = 'A', title = 'poi', coords = { lat: 43, lng: 2 } } = {}
{ id = 'A', qwant_id = 'A', title = 'poi', coords = { lat: 43, lng: 2 } } = {}
) {
const poi = new Poi(id, title, 'poi', coords, '', '');
const poi = new Poi(id, qwant_id, title, 'poi', coords, '', '');
await page.evaluate(
(storageKey, serializedPoi) => {
window.localStorage.setItem(storageKey, serializedPoi);
Expand Down
1 change: 1 addition & 0 deletions tests/integration/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export async function simulateClickOnMapPoi(page, poi) {
const mapPoiMock = {
properties: {
global_id: poi.id,
qwant_id: poi.id,
name: poi.name,
},
geometry: poi.geometry,
Expand Down