mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-27 02:12:24 +02:00
+31
-27
@@ -1,12 +1,9 @@
|
||||
import _flatten from 'lodash-es/flatten';
|
||||
import _flattenDeep from 'lodash-es/flattenDeep';
|
||||
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
|
||||
import { geoExtent } from '../geo';
|
||||
import { osmEntity } from '../osm';
|
||||
import { t } from '../util/locale';
|
||||
import { utilArrayUniq, utilRebind } from '../util';
|
||||
import { utilArrayFlatten, utilRebind } from '../util';
|
||||
import * as Validations from '../validations/index';
|
||||
|
||||
|
||||
@@ -37,9 +34,9 @@ export function coreValidator(context) {
|
||||
}
|
||||
}
|
||||
|
||||
var validationIDsToDisplay = Object.keys(validations).filter(function(rule) {
|
||||
return rule !== 'maprules';
|
||||
});
|
||||
var validationIDsToDisplay = Object.keys(validations)
|
||||
.filter(function(rule) { return rule !== 'maprules'; });
|
||||
|
||||
validationIDsToDisplay.sort(function(rule1, rule2) {
|
||||
return t('issues.' + rule1 + '.title') > t('issues.' + rule2 + '.title');
|
||||
});
|
||||
@@ -165,35 +162,44 @@ export function coreValidator(context) {
|
||||
|
||||
var history = context.history();
|
||||
var changes = history.changes();
|
||||
var entitiesToCheck = changes.created.concat(changes.modified);
|
||||
var changesToCheck = changes.created.concat(changes.modified);
|
||||
var graph = history.graph();
|
||||
|
||||
_issues = _flatten(changesValidationIDs.map(function(ruleID) {
|
||||
if (_disabledValidations[ruleID]) {
|
||||
return [];
|
||||
}
|
||||
_issues = utilArrayFlatten(changesValidationIDs.map(function(ruleID) {
|
||||
if (_disabledValidations[ruleID]) return [];
|
||||
var validation = validations[ruleID];
|
||||
return validation(changes, context);
|
||||
}));
|
||||
|
||||
entitiesToCheck = utilArrayUniq(_flattenDeep(entitiesToCheck.map(function(entity) {
|
||||
var entitiesToCheck = changesToCheck.reduce(function(acc, entity) {
|
||||
var entities = [entity];
|
||||
if (entity.type === 'node') { // validate ways if their nodes have changed
|
||||
entities = entities.concat(graph.parentWays(entity));
|
||||
acc.add(entity);
|
||||
|
||||
if (entity.type === 'node') {
|
||||
// check parent ways if their nodes have changed
|
||||
graph.parentWays(entity).forEach(function(parentWay) {
|
||||
entities.push(parentWay);
|
||||
acc.add(parentWay);
|
||||
});
|
||||
}
|
||||
entities = entities.map(function(entity) {
|
||||
if (entity.type !== 'relation') { // validate relations if their geometries have changed
|
||||
return [entity].concat(graph.parentRelations(entity));
|
||||
|
||||
entities.forEach(function(entity) {
|
||||
// check parent relations if their geometries have changed
|
||||
if (entity.type !== 'relation') {
|
||||
graph.parentRelations(entity).forEach(function(parentRel) {
|
||||
acc.add(parentRel);
|
||||
});
|
||||
}
|
||||
return entity;
|
||||
});
|
||||
return entities;
|
||||
})));
|
||||
|
||||
return acc;
|
||||
|
||||
}, new Set());
|
||||
|
||||
|
||||
var issuesByID = {};
|
||||
|
||||
for (var entityIndex in entitiesToCheck) {
|
||||
var entity = entitiesToCheck[entityIndex];
|
||||
entitiesToCheck.forEach(function(entity) {
|
||||
var entityIssues = validateEntity(entity);
|
||||
_issuesByEntityID[entity.id] = entityIssues;
|
||||
entityIssues.forEach(function(issue) {
|
||||
@@ -201,7 +207,7 @@ export function coreValidator(context) {
|
||||
// the ID to ensure that there are no duplicate issues.
|
||||
issuesByID[issue.id()] = issue;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
for (var issueID in issuesByID) {
|
||||
_issues.push(issuesByID[issueID]);
|
||||
@@ -231,9 +237,7 @@ export function validationIssue(attrs) {
|
||||
// A unique, deterministic string hash.
|
||||
// Issues with identical id values are considered identical.
|
||||
this.id = function() {
|
||||
if (_id) {
|
||||
return _id;
|
||||
}
|
||||
if (_id) return _id;
|
||||
|
||||
_id = this.type;
|
||||
|
||||
|
||||
+3
-4
@@ -1,4 +1,3 @@
|
||||
import _flatten from 'lodash-es/flatten';
|
||||
import _throttle from 'lodash-es/throttle';
|
||||
|
||||
import {
|
||||
@@ -20,7 +19,7 @@ import { geoExtent, geoPolygonIntersectsPolygon } from '../geo';
|
||||
import { services } from '../services';
|
||||
import { svgPath } from './index';
|
||||
import { utilDetect } from '../util/detect';
|
||||
import { utilArrayUnion, utilHashcode } from '../util';
|
||||
import { utilArrayFlatten, utilArrayUnion, utilHashcode } from '../util';
|
||||
|
||||
|
||||
var _initialized = false;
|
||||
@@ -516,10 +515,10 @@ export function svgData(projection, context, dispatch) {
|
||||
break;
|
||||
|
||||
case 'MultiPolygon':
|
||||
c = _flatten(c);
|
||||
c = utilArrayFlatten(c);
|
||||
case 'Polygon':
|
||||
case 'MultiLineString':
|
||||
c = _flatten(c);
|
||||
c = utilArrayFlatten(c);
|
||||
break;
|
||||
}
|
||||
/* eslint-enable no-fallthrough */
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import _flatten from 'lodash-es/flatten';
|
||||
import _map from 'lodash-es/map';
|
||||
|
||||
import { range as d3_range } from 'd3-array';
|
||||
|
||||
import {
|
||||
svgMarkerSegments, svgPath, svgRelationMemberTags,
|
||||
svgSegmentWay, svgTagClasses
|
||||
svgMarkerSegments, svgPath, svgRelationMemberTags, svgSegmentWay, svgTagClasses
|
||||
} from './index';
|
||||
|
||||
import { osmEntity, osmOldMultipolygonOuterMember } from '../osm';
|
||||
import { utilArrayGroupBy } from '../util';
|
||||
import { utilArrayFlatten, utilArrayGroupBy } from '../util';
|
||||
import { utilDetect } from '../util/detect';
|
||||
|
||||
|
||||
@@ -214,7 +210,7 @@ export function svgLines(projection, context) {
|
||||
return entity.tags.oneway === 'reversible' || entity.tags.oneway === 'alternating';
|
||||
}
|
||||
);
|
||||
onewaydata[k] = _flatten(_map(onewayArr, onewaySegments));
|
||||
onewaydata[k] = utilArrayFlatten(onewayArr.map(onewaySegments));
|
||||
|
||||
var sidedArr = v.filter(function(d) { return d.isSided(); });
|
||||
var sidedSegments = svgMarkerSegments(
|
||||
@@ -222,7 +218,7 @@ export function svgLines(projection, context) {
|
||||
function shouldReverse() { return false; },
|
||||
function bothDirections() { return false; }
|
||||
);
|
||||
sideddata[k] = _flatten(_map(sidedArr, sidedSegments));
|
||||
sideddata[k] = utilArrayFlatten(sidedArr.map(sidedSegments));
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,17 @@ export function utilArrayChunk(a, chunkSize) {
|
||||
}
|
||||
|
||||
|
||||
// Flattens two level array into a single level
|
||||
// var a = [[1,2,3],[4,5,6],[7]];
|
||||
// utilArrayFlatten(a);
|
||||
// [1,2,3,4,5,6,7];
|
||||
export function utilArrayFlatten(a) {
|
||||
return a.reduce(function(acc, val) {
|
||||
return acc.concat(val);
|
||||
}, []);
|
||||
}
|
||||
|
||||
|
||||
// Groups the items of the Array according to the given key
|
||||
// `key` can be passed as a property or as a key function
|
||||
//
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export { utilArrayChunk } from './array';
|
||||
export { utilArrayDifference } from './array';
|
||||
export { utilArrayFlatten } from './array';
|
||||
export { utilArrayGroupBy } from './array';
|
||||
export { utilArrayIntersection } from './array';
|
||||
export { utilArrayUnion } from './array';
|
||||
|
||||
Reference in New Issue
Block a user