Skip to content

Commit b9ff3ef

Browse files
committed
DT-6107 fix coarse admin labeling
Neigbourhood should not be added to label, if the labeled item is supposedly larger than the neigbourhood.
1 parent 9d7a6a8 commit b9ff3ef

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

helper/labelGenerator.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ var stringUtils = require('../helper/stringUtils');
55
var normalize = stringUtils.normalize;
66
var removeSpaces = stringUtils.removeSpaces;
77

8+
const areaLikes = ['venue', 'neighbourhood', 'localadmin'];
9+
810
module.exports = function( record, req ){
911
var schemaId = _.get(record, ['parent', 'country_a', 0 ], 'FIN');
1012
var schema = getSchema(schemaId);
1113

1214
// in virtually all cases, this will be the `name` field
1315
var labelParts = getInitialLabel(record);
14-
16+
// do not add neighbourhood to largish area-like items
17+
const skip = record.category?.includes('populated area') ? 'neighbourhood' : null;
1518
// iterate the schema
1619
for (var field in schema) {
1720
var valueFunction = schema[field];
18-
var value = valueFunction(record, req);
21+
var value = valueFunction(record, req, skip);
1922
if(value) {
2023
labelParts.push(value);
2124
}
@@ -25,18 +28,21 @@ module.exports = function( record, req ){
2528
labelParts = _.compact(labelParts);
2629

2730
// third, dedupe and join with a comma and return
28-
return dedupeNameAndFirstLabelElement(labelParts).join(', ');
29-
31+
const candDropMinorAdmin = areaLikes.includes(record.layer);
32+
return dedupeNameAndFirstLabelElement(labelParts, candDropMinorAdmin).join(', ');
3033
};
3134

32-
function dedupeNameAndFirstLabelElement(labelParts) {
35+
function dedupeNameAndFirstLabelElement(labelParts, dropMinorAdmin) {
3336
// only dedupe if a result has more than a name (the first label part)
3437
if (labelParts.length > 1) {
3538
// first, dedupe the name and 1st label array elements
36-
// this is used to ensure that the `name` and first admin hierarchy elements aren't repeated
37-
// eg - `["Lancaster", "Lancaster", "PA", "United States"]` -> `["Lancaster", "PA", "United States"]`
38-
39-
if (labelParts[0].toLowerCase() === labelParts[1].toLowerCase()) {
39+
// this is used to ensure that the `name` and first admin hierarchy elements aren't repeated
40+
// eg - `["Lancaster", "Lancaster", "PA", "United States"]` -> `["Lancaster", "PA", "United States"]`
41+
// also, do not add a minor admin to a name of coarser admin, e.g. helsinki, kaartinkaupunki, helsinki
42+
if (
43+
labelParts[0].toLowerCase() === labelParts[1].toLowerCase() ||
44+
dropMinorAdmin && labelParts.length > 2 && labelParts[0].toLowerCase() === labelParts[2].toLowerCase()
45+
) {
4046
labelParts.splice(1, 1);
4147
}
4248
}

helper/labelSchema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function baseVal(val) {
3636

3737
// find the first field of record that has a non-empty value that's not already in labelParts
3838
function getFirstProperty(fields, matchType, targets) {
39-
return function(record, req) {
39+
return function(record, req, skip) {
4040

4141
if (targets && targets.indexOf(record.layer)===-1) {
4242
return null; // not applicable to this kind of record
@@ -50,6 +50,9 @@ function getFirstProperty(fields, matchType, targets) {
5050
var bestField;
5151
for (var i = 0; i < fields.length; i++) {
5252
var field = fields[i];
53+
if (field === skip) {
54+
continue;
55+
}
5356
var fieldValue;
5457
if (Array.isArray(field)) { // chain multi parts
5558
var parts = [];

0 commit comments

Comments
 (0)