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

Update lat/lon precision according to the zoom level #1408

Merged
merged 3 commits into from
Oct 5, 2022
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
8 changes: 6 additions & 2 deletions @types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ export interface Geocoder {
useLang: boolean;
maxItems: number;
useFocus: boolean;
focusPrecision: string;
focusPrecision: Array<ZoomPrecision>;
focusZoomPrecision: string;
focusMinZoom: number;
useNlu: boolean;
}

export interface ZoomPrecision {
zoom: string;
precision: string;
}

export interface Idunn {
url: string;
}
Expand Down
3 changes: 1 addition & 2 deletions config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ services:
useLang: true
maxItems: 7
useFocus: true
focusPrecision: '0.1' # lat/lon degrees
focusPrecision: '[{"zoom":"7","precision":"0.1"},{"zoom":"11","precision":"0.01"},{"zoom":"14","precision":"0.001"}]' # lat/lon degrees
focusZoomPrecision: '1.0'
focusMinZoom: 7
useNlu: false
idunn:
url: override_by_environment
Expand Down
15 changes: 11 additions & 4 deletions src/adapters/geocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Intention from './intention';

const serviceConfigs = nconf.get().services;
const {
focusMinZoom,
focusPrecision,
focusZoomPrecision,
maxItems,
Expand All @@ -30,12 +29,20 @@ function getFocusParams({ lat, lon, zoom }) {
if (lat === undefined || lon === undefined || zoom === undefined) {
return null;
}
if (zoom < Number(focusMinZoom)) {

// Get the precision specific to a zoom level
const zoomFocusPrecision = JSON.parse(focusPrecision)
.filter(zp => zoom > zp.zoom)
.map(zp => zp.precision)
.sort()
.shift();

if (zoomFocusPrecision === undefined) {
return null;
}
return {
lat: roundWithPrecision(lat, focusPrecision),
lon: roundWithPrecision(lon, focusPrecision),
lat: roundWithPrecision(lat, zoomFocusPrecision),
lon: roundWithPrecision(lon, zoomFocusPrecision),
zoom: roundWithPrecision(zoom, focusZoomPrecision),
};
}
Expand Down