Merge pull request #8701 from openstreetmap/check_china_source

Add warning for some commercial mapservice in China
This commit is contained in:
Milos Brzakovic
2021-09-30 12:06:36 +02:00
committed by GitHub
3 changed files with 66 additions and 56 deletions

View File

@@ -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}'

File diff suppressed because one or more lines are too long

View File

@@ -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;
});
if (!hasInvalidSource) return;
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 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;
});
return issues;
if (!matchRule) return null;
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') })
];
}
});
}).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;