Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7e96c36

Browse files
committedSep 1, 2022
feat(pip_verbose): add support for lang query parameter
1 parent d0dfbd8 commit 7e96c36

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
 

‎module/pip/StatementPointInPolygonVerbose.js

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ class StatementPeliasView extends SqliteStatement {
2727
AND abbr = 0
2828
LIMIT 1
2929
) AS name,
30+
(
31+
SELECT name
32+
FROM name
33+
WHERE source = place.source
34+
AND id = place.id
35+
AND lang = @lang
36+
AND tag IN ('default', 'preferred')
37+
AND abbr = 0
38+
LIMIT 1
39+
) AS name_localized,
3040
(
3141
SELECT GROUP_CONCAT(name, CHAR(30))
3242
FROM (

‎server/routes/pip_verbose.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const util = require('./util')
2+
const iso6393 = require('iso-639-3')
3+
const language = {}
4+
iso6393.filter(i => !!i.iso6391 && !!i.iso6393).forEach(i => { language[i.iso6391] = i.iso6393 })
25

36
/**
47
* a verbose view of the PIP data
@@ -9,13 +12,15 @@ const util = require('./util')
912
module.exports = function (req, res) {
1013
var service = req.app.locals.service
1114

15+
const lang = util.flatten(req.query.lang)
1216
// inputs
1317
let query = {
1418
lon: parseFloat(util.flatten(req.query.lon)),
1519
lat: parseFloat(util.flatten(req.query.lat)),
1620
limit: 1000,
1721
aliaslimit: parseInt(util.flatten(req.query.aliaslimit), 10) || 0,
18-
wofonly: util.flatten(req.query.wofonly) ? 1 : 0
22+
wofonly: util.flatten(req.query.wofonly) ? 1 : 0,
23+
lang: language[lang] || lang || 'und'
1924
}
2025

2126
// perform query
@@ -27,20 +32,21 @@ module.exports = function (req, res) {
2732
let resp = {}
2833
rows.forEach(row => {
2934
let centroid = row.centroid.split(',').map(util.floatPrecision7)
35+
let name = row.name_localized || row.name || undefined
3036

3137
let nameAlias = []
3238
if (query.aliaslimit > 0) { nameAlias = (row.names || '').split(String.fromCharCode(30)) }
33-
nameAlias = (nameAlias.length > 1) ? nameAlias.filter(n => n !== row.name).slice(0, query.aliaslimit) : undefined
39+
nameAlias = (nameAlias.length > 1) ? nameAlias.filter(n => n !== name).slice(0, query.aliaslimit) : undefined
3440

3541
let abbrAlias = []
3642
if (query.aliaslimit > 0) { abbrAlias = (row.abbrs || '').split(String.fromCharCode(30)) }
37-
abbrAlias = (abbrAlias.length > 1) ? abbrAlias.filter(n => n !== row.name).slice(0, query.aliaslimit) : undefined
43+
abbrAlias = (abbrAlias.length > 1) ? abbrAlias.filter(n => n !== name).slice(0, query.aliaslimit) : undefined
3844

3945
if (!Array.isArray(resp[row.type])) { resp[row.type] = [] }
4046
resp[row.type].push({
4147
id: row.id,
4248
source: row.source,
43-
name: row.name || undefined,
49+
name: name,
4450
name_alias: nameAlias,
4551
abbr: row.abbr || undefined,
4652
abbr_alias: abbrAlias,

0 commit comments

Comments
 (0)
Please sign in to comment.