Skip to content

Commit

Permalink
Merge pull request #8701 from openstreetmap/check_china_source
Browse files Browse the repository at this point in the history
Add warning for some commercial mapservice in China
  • Loading branch information
mbrzakovic authored Sep 30, 2021
2 parents 021107c + 73f8737 commit a018d27
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 54 deletions.
10 changes: 6 additions & 4 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1761,10 +1761,12 @@ en:
incompatible_source:
title: Suspicious Sources
tip: "Find features with suspicious source tags"
google:
feature:
message: '{feature} lists Google as a data source'
reference: "Google products are proprietary and must not be used as references."
feature:
message: '{feature} lists "{value}" as a data source'
reference:
amap: "Amap products are proprietary and must not be used as references."
baidu: "Baidu products are proprietary and must not be used as references."
google: "Google products are proprietary and must not be used as references."
incorrect_name:
message: '{feature} has the mistaken name "{name}"'
message_language: '{feature} has the mistaken name "{name}" in {language}'
Expand Down
2 changes: 1 addition & 1 deletion dist/locales/en.min.json

Large diffs are not rendered by default.

106 changes: 57 additions & 49 deletions modules/validations/incompatible_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,73 @@ import { validationIssue, validationIssueFix } from '../core/validation';


export function validationIncompatibleSource() {
var type = 'incompatible_source';
var invalidSources = [
{
id:'google', regex:'google', exceptRegex: 'books.google|Google Books|drive.google|googledrive|Google Drive'
}
];
const type = 'incompatible_source';
const incompatibleRules = [
{
id: 'amap',
regex: /(amap|autonavi|mapabc|)/i
},
{
id: 'baidu',
regex: /(baidu|mapbar|)/i
},
{
id: 'google',
regex: /google/i,
exceptRegex: /((books|drive)\.google|google\s?(books|drive|plus))/i
}
];

var validation = function checkIncompatibleSource(entity) {

var entitySources = entity.tags && entity.tags.source && entity.tags.source.split(';');
const validation = function checkIncompatibleSource(entity) {
const entitySources = entity.tags && entity.tags.source && entity.tags.source.split(';');
if (!entitySources) return [];

if (!entitySources) return [];
const entityID = entity.id;

var issues = [];

invalidSources.forEach(function(invalidSource) {

var hasInvalidSource = entitySources.some(function(source) {
if (!source.match(new RegExp(invalidSource.regex, 'i'))) return false;
if (invalidSource.exceptRegex && source.match(new RegExp(invalidSource.exceptRegex, 'i'))) return false;
return true;
});
return entitySources
.map(source => {
const matchRule = incompatibleRules.find(rule => {
if (!rule.regex.test(source)) return false;
if (rule.exceptRegex && rule.exceptRegex.test(source)) return false;
return true;
});

if (!hasInvalidSource) return;
if (!matchRule) return null;

issues.push(new validationIssue({
type: type,
severity: 'warning',
message: function(context) {
var entity = context.hasEntity(this.entityIds[0]);
return entity ? t.html('issues.incompatible_source.' + invalidSource.id + '.feature.message', {
feature: utilDisplayLabel(entity, context.graph(), true /* verbose */)
}) : '';
},
reference: getReference(invalidSource.id),
entityIds: [entity.id],
dynamicFixes: function() {
return [
new validationIssueFix({
title: t.html('issues.fix.remove_proprietary_data.title')
})
];
}
}));
return new validationIssue({
type: type,
severity: 'warning',
message: (context) => {
const entity = context.hasEntity(entityID);
return entity ? t.html('issues.incompatible_source.feature.message', {
feature: utilDisplayLabel(entity, context.graph(), true /* verbose */),
value: source
}) : '';
},
reference: getReference(matchRule.id),
entityIds: [entityID],
hash: source,
dynamicFixes: () => {
return [
new validationIssueFix({ title: t.html('issues.fix.remove_proprietary_data.title') })
];
}
});

return issues;
}).filter(Boolean);


function getReference(id) {
return function showReference(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.html(t.html('issues.incompatible_source.' + id + '.reference'));
};
}
function getReference(id) {
return function showReference(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.html(t.html(`issues.incompatible_source.reference.${id}`));
};
}
};

validation.type = type;
Expand Down

0 comments on commit a018d27

Please sign in to comment.