Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning for some commercial mapservice in China #8701

Merged
merged 2 commits into from
Sep 30, 2021
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
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