mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-31 01:09:22 +02:00
Convert lodah-es and d3 to named imports for actions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { osmJoinWays } from '../osm/index';
|
||||
import { osmJoinWays } from '../osm';
|
||||
|
||||
|
||||
export function actionAddMember(relationId, member, memberIndex) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import _ from 'lodash';
|
||||
import { geoEdgeEqual } from '../geo/index';
|
||||
import _intersection from 'lodash-es/intersection';
|
||||
import { geoEdgeEqual } from '../geo';
|
||||
|
||||
|
||||
export function actionAddMidpoint(midpoint, node) {
|
||||
return function(graph) {
|
||||
graph = graph.replace(node.move(midpoint.loc));
|
||||
|
||||
var parents = _.intersection(
|
||||
var parents = _intersection(
|
||||
graph.parentWays(graph.entity(midpoint.edge[0])),
|
||||
graph.parentWays(graph.entity(midpoint.edge[1])));
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
import * as d3 from 'd3';
|
||||
import _ from 'lodash';
|
||||
import { geoEuclideanDistance, geoInterp } from '../geo/index';
|
||||
import { osmNode } from '../osm/index';
|
||||
import _each from 'lodash-es/each';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
import _without from 'lodash-es/without';
|
||||
|
||||
import { median as d3_median } from 'd3-array';
|
||||
|
||||
import {
|
||||
polygonArea as d3polygonArea,
|
||||
polygonHull as d3polygonHull,
|
||||
polygonCentroid as d3polygonCentroid
|
||||
} from 'd3';
|
||||
polygonArea as d3_polygonArea,
|
||||
polygonHull as d3_polygonHull,
|
||||
polygonCentroid as d3_polygonCentroid
|
||||
} from 'd3-polygon';
|
||||
|
||||
import {
|
||||
geoEuclideanDistance,
|
||||
geoInterp
|
||||
} from '../geo';
|
||||
|
||||
import { osmNode } from '../osm';
|
||||
|
||||
|
||||
export function actionCircularize(wayId, projection, maxAngle) {
|
||||
@@ -29,13 +37,13 @@ export function actionCircularize(wayId, projection, maxAngle) {
|
||||
graph = action.makeConvex(graph);
|
||||
}
|
||||
|
||||
var nodes = _.uniq(graph.childNodes(way)),
|
||||
var nodes = _uniq(graph.childNodes(way)),
|
||||
keyNodes = nodes.filter(function(n) { return graph.parentWays(n).length !== 1; }),
|
||||
points = nodes.map(function(n) { return projection(n.loc); }),
|
||||
keyPoints = keyNodes.map(function(n) { return projection(n.loc); }),
|
||||
centroid = (points.length === 2) ? geoInterp(points[0], points[1], 0.5) : d3polygonCentroid(points),
|
||||
radius = d3.median(points, function(p) { return geoEuclideanDistance(centroid, p); }),
|
||||
sign = d3polygonArea(points) > 0 ? 1 : -1,
|
||||
centroid = (points.length === 2) ? geoInterp(points[0], points[1], 0.5) : d3_polygonCentroid(points),
|
||||
radius = d3_median(points, function(p) { return geoEuclideanDistance(centroid, p); }),
|
||||
sign = d3_polygonArea(points) > 0 ? 1 : -1,
|
||||
ids;
|
||||
|
||||
// we need atleast two key nodes for the algorithm to work
|
||||
@@ -154,7 +162,7 @@ export function actionCircularize(wayId, projection, maxAngle) {
|
||||
if (wayDirection1 < -1) { wayDirection1 = 1; }
|
||||
|
||||
/* eslint-disable no-loop-func */
|
||||
_.each(_.without(graph.parentWays(keyNodes[i]), way), function(sharedWay) {
|
||||
_each(_without(graph.parentWays(keyNodes[i]), way), function(sharedWay) {
|
||||
if (sharedWay.areAdjacent(startNode.id, endNode.id)) {
|
||||
var startIndex2 = sharedWay.nodes.lastIndexOf(startNode.id),
|
||||
endIndex2 = sharedWay.nodes.lastIndexOf(endNode.id),
|
||||
@@ -190,10 +198,10 @@ export function actionCircularize(wayId, projection, maxAngle) {
|
||||
|
||||
action.makeConvex = function(graph) {
|
||||
var way = graph.entity(wayId),
|
||||
nodes = _.uniq(graph.childNodes(way)),
|
||||
nodes = _uniq(graph.childNodes(way)),
|
||||
points = nodes.map(function(n) { return projection(n.loc); }),
|
||||
sign = d3polygonArea(points) > 0 ? 1 : -1,
|
||||
hull = d3polygonHull(points);
|
||||
sign = d3_polygonArea(points) > 0 ? 1 : -1,
|
||||
hull = d3_polygonHull(points);
|
||||
|
||||
// D3 convex hulls go counterclockwise..
|
||||
if (sign === -1) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import _ from 'lodash';
|
||||
import { actionDeleteNode } from './delete_node';
|
||||
|
||||
|
||||
@@ -18,7 +17,8 @@ import { actionDeleteNode } from './delete_node';
|
||||
//
|
||||
export function actionConnect(nodeIds) {
|
||||
return function(graph) {
|
||||
var survivor = graph.entity(_.last(nodeIds));
|
||||
var last = nodeIds[nodeIds.length - 1];
|
||||
var survivor = graph.entity(last);
|
||||
|
||||
for (var i = 0; i < nodeIds.length - 1; i++) {
|
||||
var node = graph.entity(nodeIds[i]);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import _map from 'lodash-es/map';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
import { actionDeleteMultiple } from './delete_multiple';
|
||||
|
||||
|
||||
@@ -26,7 +27,7 @@ export function actionDeleteRelation(relationId) {
|
||||
}
|
||||
});
|
||||
|
||||
_.uniq(_.map(relation.members, 'id')).forEach(function(memberId) {
|
||||
_uniq(_map(relation.members, 'id')).forEach(function(memberId) {
|
||||
graph = graph.replace(relation.removeMembersWithID(memberId));
|
||||
|
||||
var entity = graph.entity(memberId);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
import { actionDeleteRelation } from './delete_relation';
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export function actionDeleteWay(wayId) {
|
||||
}
|
||||
});
|
||||
|
||||
_.uniq(way.nodes).forEach(function(nodeId) {
|
||||
_uniq(way.nodes).forEach(function(nodeId) {
|
||||
graph = graph.replace(way.removeNode(nodeId));
|
||||
|
||||
var node = graph.entity(nodeId);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import _ from 'lodash';
|
||||
import { dataDeprecated } from '../../data/index';
|
||||
import _assign from 'lodash-es/assign';
|
||||
import _clone from 'lodash-es/clone';
|
||||
import _omit from 'lodash-es/omit';
|
||||
import _toPairs from 'lodash-es/toPairs';
|
||||
|
||||
import { dataDeprecated } from '../../data';
|
||||
|
||||
|
||||
export function actionDeprecateTags(entityId) {
|
||||
|
||||
return function(graph) {
|
||||
var entity = graph.entity(entityId),
|
||||
newtags = _.clone(entity.tags),
|
||||
newtags = _clone(entity.tags),
|
||||
change = false,
|
||||
rule;
|
||||
|
||||
@@ -14,8 +18,8 @@ export function actionDeprecateTags(entityId) {
|
||||
for (var i = 0; i < dataDeprecated.length; i++) {
|
||||
|
||||
rule = dataDeprecated[i];
|
||||
var match = _.toPairs(rule.old)[0],
|
||||
replacements = rule.replace ? _.toPairs(rule.replace) : null;
|
||||
var match = _toPairs(rule.old)[0],
|
||||
replacements = rule.replace ? _toPairs(rule.replace) : null;
|
||||
|
||||
if (entity.tags[match[0]] && match[1] === '*') {
|
||||
|
||||
@@ -27,7 +31,7 @@ export function actionDeprecateTags(entityId) {
|
||||
change = true;
|
||||
|
||||
} else if (entity.tags[match[0]] === match[1]) {
|
||||
newtags = _.assign({}, rule.replace || {}, _.omit(newtags, match[0]));
|
||||
newtags = _assign({}, rule.replace || {}, _omit(newtags, match[0]));
|
||||
change = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import _ from 'lodash';
|
||||
import { dataDiscarded } from '../../data/index';
|
||||
import _each from 'lodash-es/each';
|
||||
import _isEmpty from 'lodash-es/isEmpty';
|
||||
import _omit from 'lodash-es/omit';
|
||||
|
||||
import { dataDiscarded } from '../../data';
|
||||
|
||||
|
||||
export function actionDiscardTags(difference) {
|
||||
|
||||
return function(graph) {
|
||||
function discardTags(entity) {
|
||||
if (!_.isEmpty(entity.tags)) {
|
||||
if (!_isEmpty(entity.tags)) {
|
||||
var tags = {};
|
||||
_.each(entity.tags, function(v, k) {
|
||||
_each(entity.tags, function(v, k) {
|
||||
if (v) tags[k] = v;
|
||||
});
|
||||
|
||||
graph = graph.replace(entity.update({
|
||||
tags: _.omit(tags, dataDiscarded)
|
||||
tags: _omit(tags, dataDiscarded)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import _ from 'lodash';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _groupBy from 'lodash-es/groupBy';
|
||||
import _map from 'lodash-es/map';
|
||||
|
||||
import { actionDeleteWay } from './delete_way';
|
||||
import { osmIsInterestingTag, osmJoinWays } from '../osm/index';
|
||||
|
||||
import {
|
||||
osmIsInterestingTag,
|
||||
osmJoinWays
|
||||
} from '../osm';
|
||||
|
||||
|
||||
// Join ways at the end node they share.
|
||||
@@ -15,7 +22,7 @@ export function actionJoin(ids) {
|
||||
|
||||
function groupEntitiesByGeometry(graph) {
|
||||
var entities = ids.map(function(id) { return graph.entity(id); });
|
||||
return _.extend({line: []}, _.groupBy(entities, function(entity) { return entity.geometry(graph); }));
|
||||
return _extend({line: []}, _groupBy(entities, function(entity) { return entity.geometry(graph); }));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +40,7 @@ export function actionJoin(ids) {
|
||||
|
||||
var joined = osmJoinWays(ways, graph)[0];
|
||||
|
||||
survivor = survivor.update({nodes: _.map(joined.nodes, 'id')});
|
||||
survivor = survivor.update({nodes: _map(joined.nodes, 'id')});
|
||||
graph = graph.replace(survivor);
|
||||
|
||||
joined.forEach(function(way) {
|
||||
@@ -63,7 +70,7 @@ export function actionJoin(ids) {
|
||||
if (joined.length > 1)
|
||||
return 'not_adjacent';
|
||||
|
||||
var nodeIds = _.map(joined[0].nodes, 'id').slice(1, -1),
|
||||
var nodeIds = _map(joined[0].nodes, 'id').slice(1, -1),
|
||||
relation,
|
||||
tags = {},
|
||||
conflicting = false;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import _ from 'lodash';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _groupBy from 'lodash-es/groupBy';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
|
||||
export function actionMerge(ids) {
|
||||
|
||||
function groupEntitiesByGeometry(graph) {
|
||||
var entities = ids.map(function(id) { return graph.entity(id); });
|
||||
return _.extend({point: [], area: [], line: [], relation: []},
|
||||
_.groupBy(entities, function(entity) { return entity.geometry(graph); }));
|
||||
return _extend({point: [], area: [], line: [], relation: []},
|
||||
_groupBy(entities, function(entity) { return entity.geometry(graph); }));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +25,7 @@ export function actionMerge(ids) {
|
||||
graph = graph.replace(parent.replaceMember(point, target));
|
||||
});
|
||||
|
||||
var nodes = _.uniq(graph.childNodes(target)),
|
||||
var nodes = _uniq(graph.childNodes(target)),
|
||||
removeNode = point;
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
import _ from 'lodash';
|
||||
import { geoPolygonContainsPolygon } from '../geo/index';
|
||||
import { osmJoinWays, osmRelation } from '../osm/index';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _groupBy from 'lodash-es/groupBy';
|
||||
import _map from 'lodash-es/map';
|
||||
import _omit from 'lodash-es/omit';
|
||||
import _some from 'lodash-es/some';
|
||||
|
||||
import { geoPolygonContainsPolygon } from '../geo';
|
||||
|
||||
import {
|
||||
osmJoinWays,
|
||||
osmRelation
|
||||
} from '../osm';
|
||||
|
||||
|
||||
export function actionMergePolygon(ids, newRelationId) {
|
||||
|
||||
function groupEntities(graph) {
|
||||
var entities = ids.map(function (id) { return graph.entity(id); });
|
||||
return _.extend({
|
||||
return _extend({
|
||||
closedWay: [],
|
||||
multipolygon: [],
|
||||
other: []
|
||||
}, _.groupBy(entities, function(entity) {
|
||||
}, _groupBy(entities, function(entity) {
|
||||
if (entity.type === 'way' && entity.isClosed()) {
|
||||
return 'closedWay';
|
||||
} else if (entity.type === 'relation' && entity.isMultipolygon()) {
|
||||
@@ -45,8 +54,8 @@ export function actionMergePolygon(ids, newRelationId) {
|
||||
return polygons.map(function(d, n) {
|
||||
if (i === n) return null;
|
||||
return geoPolygonContainsPolygon(
|
||||
_.map(d.nodes, 'loc'),
|
||||
_.map(w.nodes, 'loc'));
|
||||
_map(d.nodes, 'loc'),
|
||||
_map(w.nodes, 'loc'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -61,7 +70,7 @@ export function actionMergePolygon(ids, newRelationId) {
|
||||
}
|
||||
|
||||
function isContained(d, i) {
|
||||
return _.some(contained[i]);
|
||||
return _some(contained[i]);
|
||||
}
|
||||
|
||||
function filterContained(d) {
|
||||
@@ -104,7 +113,7 @@ export function actionMergePolygon(ids, newRelationId) {
|
||||
|
||||
return graph.replace(relation.update({
|
||||
members: members,
|
||||
tags: _.omit(relation.tags, 'area')
|
||||
tags: _omit(relation.tags, 'area')
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import _ from 'lodash';
|
||||
import _clone from 'lodash-es/clone';
|
||||
import _includes from 'lodash-es/includes';
|
||||
import _isEqual from 'lodash-es/isEqual';
|
||||
import _isFunction from 'lodash-es/isFunction';
|
||||
import _keys from 'lodash-es/keys';
|
||||
import _map from 'lodash-es/map';
|
||||
import _reject from 'lodash-es/reject';
|
||||
import _union from 'lodash-es/union';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
import _without from 'lodash-es/without';
|
||||
|
||||
import { t } from '../util/locale';
|
||||
import { actionDeleteMultiple } from './delete_multiple';
|
||||
import { osmEntity } from '../osm/index';
|
||||
import { osmEntity } from '../osm';
|
||||
import { diff3_merge } from '../util/diff3';
|
||||
import { dataDiscarded } from '../../data/index';
|
||||
import { dataDiscarded } from '../../data';
|
||||
|
||||
|
||||
export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser) {
|
||||
@@ -12,7 +22,7 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
|
||||
|
||||
function user(d) {
|
||||
return _.isFunction(formatUser) ? formatUser(d) : d;
|
||||
return _isFunction(formatUser) ? formatUser(d) : d;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +45,7 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
|
||||
|
||||
function mergeNodes(base, remote, target) {
|
||||
if (option === 'force_local' || _.isEqual(target.nodes, remote.nodes)) {
|
||||
if (option === 'force_local' || _isEqual(target.nodes, remote.nodes)) {
|
||||
return target;
|
||||
}
|
||||
if (option === 'force_remote') {
|
||||
@@ -57,9 +67,9 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
// for all conflicts, we can assume c.a !== c.b
|
||||
// because `diff3_merge` called with `true` option to exclude false conflicts..
|
||||
var c = hunk.conflict;
|
||||
if (_.isEqual(c.o, c.a)) { // only changed remotely
|
||||
if (_isEqual(c.o, c.a)) { // only changed remotely
|
||||
nodes.push.apply(nodes, c.b);
|
||||
} else if (_.isEqual(c.o, c.b)) { // only changed locally
|
||||
} else if (_isEqual(c.o, c.b)) { // only changed locally
|
||||
nodes.push.apply(nodes, c.a);
|
||||
} else { // changed both locally and remotely
|
||||
conflicts.push(t('merge_remote_changes.conflict.nodelist', { user: user(remote.user) }));
|
||||
@@ -74,9 +84,9 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
|
||||
function mergeChildren(targetWay, children, updates, graph) {
|
||||
function isUsed(node, targetWay) {
|
||||
var parentWays = _.map(graph.parentWays(node), 'id');
|
||||
var parentWays = _map(graph.parentWays(node), 'id');
|
||||
return node.hasInterestingTags() ||
|
||||
_.without(parentWays, targetWay.id).length > 0 ||
|
||||
_without(parentWays, targetWay.id).length > 0 ||
|
||||
graph.parentRelations(node).length > 0;
|
||||
}
|
||||
|
||||
@@ -138,7 +148,7 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
|
||||
|
||||
function mergeMembers(remote, target) {
|
||||
if (option === 'force_local' || _.isEqual(target.members, remote.members)) {
|
||||
if (option === 'force_local' || _isEqual(target.members, remote.members)) {
|
||||
return target;
|
||||
}
|
||||
if (option === 'force_remote') {
|
||||
@@ -152,10 +162,10 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
|
||||
function mergeTags(base, remote, target) {
|
||||
function ignoreKey(k) {
|
||||
return _.includes(dataDiscarded, k);
|
||||
return _includes(dataDiscarded, k);
|
||||
}
|
||||
|
||||
if (option === 'force_local' || _.isEqual(target.tags, remote.tags)) {
|
||||
if (option === 'force_local' || _isEqual(target.tags, remote.tags)) {
|
||||
return target;
|
||||
}
|
||||
if (option === 'force_remote') {
|
||||
@@ -166,8 +176,8 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
o = base.tags || {},
|
||||
a = target.tags || {},
|
||||
b = remote.tags || {},
|
||||
keys = _.reject(_.union(_.keys(o), _.keys(a), _.keys(b)), ignoreKey),
|
||||
tags = _.clone(a),
|
||||
keys = _reject(_union(_keys(o), _keys(a), _keys(b)), ignoreKey),
|
||||
tags = _clone(a),
|
||||
changed = false;
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
@@ -217,7 +227,7 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
|
||||
} else if (option === 'force_local') {
|
||||
if (target.type === 'way') {
|
||||
target = mergeChildren(target, _.uniq(local.nodes), updates, graph);
|
||||
target = mergeChildren(target, _uniq(local.nodes), updates, graph);
|
||||
graph = updateChildren(updates, graph);
|
||||
}
|
||||
return graph.replace(target);
|
||||
@@ -236,7 +246,7 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser
|
||||
// pull in any child nodes that may not be present locally..
|
||||
graph.rebase(remoteGraph.childNodes(remote), [graph], false);
|
||||
target = mergeNodes(base, remote, target);
|
||||
target = mergeChildren(target, _.union(local.nodes, remote.nodes), updates, graph);
|
||||
target = mergeChildren(target, _union(local.nodes, remote.nodes), updates, graph);
|
||||
|
||||
} else if (target.type === 'relation') {
|
||||
target = mergeMembers(remote, target);
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import _ from 'lodash';
|
||||
import { osmNode } from '../osm/index';
|
||||
import _each from 'lodash-es/each';
|
||||
import _every from 'lodash-es/every';
|
||||
import _filter from 'lodash-es/filter';
|
||||
import _find from 'lodash-es/find';
|
||||
import _intersection from 'lodash-es/intersection';
|
||||
import _isEqual from 'lodash-es/isEqual';
|
||||
import _isEmpty from 'lodash-es/isEmpty';
|
||||
import _map from 'lodash-es/map';
|
||||
import _without from 'lodash-es/without';
|
||||
|
||||
import { osmNode } from '../osm';
|
||||
|
||||
import {
|
||||
geoChooseEdge,
|
||||
geoAngle,
|
||||
@@ -7,7 +17,7 @@ import {
|
||||
geoPathIntersections,
|
||||
geoPathLength,
|
||||
geoSphericalDistance
|
||||
} from '../geo/index';
|
||||
} from '../geo';
|
||||
|
||||
|
||||
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
|
||||
@@ -24,11 +34,11 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
if (moveIds.indexOf(nodeId) !== -1) return true;
|
||||
|
||||
// Allow movement of a vertex where 2 ways meet..
|
||||
var parents = _.map(graph.parentWays(graph.entity(nodeId)), 'id');
|
||||
var parents = _map(graph.parentWays(graph.entity(nodeId)), 'id');
|
||||
if (parents.length < 3) return true;
|
||||
|
||||
// Restrict movement of a vertex where >2 ways meet, unless all parentWays are moving too..
|
||||
var parentsMoving = _.every(parents, function(id) { return cache.moving[id]; });
|
||||
var parentsMoving = _every(parents, function(id) { return cache.moving[id]; });
|
||||
if (!parentsMoving) delete cache.moving[nodeId];
|
||||
|
||||
return parentsMoving;
|
||||
@@ -67,11 +77,11 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
if (parents.length !== 2) return;
|
||||
|
||||
var moved = graph.entity(id),
|
||||
unmoved = _.find(parents, function(way) { return !cache.moving[way.id]; });
|
||||
unmoved = _find(parents, function(way) { return !cache.moving[way.id]; });
|
||||
if (!unmoved) return;
|
||||
|
||||
// exclude ways that are overly connected..
|
||||
if (_.intersection(moved.nodes, unmoved.nodes).length > 2) return;
|
||||
if (_intersection(moved.nodes, unmoved.nodes).length > 2) return;
|
||||
|
||||
if (moved.isArea() || unmoved.isArea()) return;
|
||||
|
||||
@@ -100,7 +110,7 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
|
||||
cacheEntities(moveIds);
|
||||
cacheIntersections(cache.ways);
|
||||
cache.nodes = _.filter(cache.nodes, canMove);
|
||||
cache.nodes = _filter(cache.nodes, canMove);
|
||||
|
||||
cache.ok = true;
|
||||
}
|
||||
@@ -183,8 +193,8 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
// don't move the vertex if it is the endpoint of both ways.
|
||||
if (isEP1 && isEP2) return graph;
|
||||
|
||||
var nodes1 = _.without(graph.childNodes(way1), vertex),
|
||||
nodes2 = _.without(graph.childNodes(way2), vertex);
|
||||
var nodes1 = _without(graph.childNodes(way1), vertex),
|
||||
nodes2 = _without(graph.childNodes(way2), vertex);
|
||||
|
||||
if (way1.isClosed() && way1.first() === vertex.id) nodes1.push(nodes1[0]);
|
||||
if (way2.isClosed() && way2.first() === vertex.id) nodes2.push(nodes2[0]);
|
||||
@@ -225,7 +235,7 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
|
||||
|
||||
function cleanupIntersections(graph) {
|
||||
_.each(cache.intersection, function(obj) {
|
||||
_each(cache.intersection, function(obj) {
|
||||
graph = replaceMovedVertex(obj.nodeId, obj.movedId, graph, delta);
|
||||
graph = replaceMovedVertex(obj.nodeId, obj.unmovedId, graph, null);
|
||||
graph = unZorroIntersection(obj, graph);
|
||||
@@ -237,7 +247,7 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
|
||||
// check if moving way endpoint can cross an unmoved way, if so limit delta..
|
||||
function limitDelta(graph) {
|
||||
_.each(cache.intersection, function(obj) {
|
||||
_each(cache.intersection, function(obj) {
|
||||
// Don't limit movement if this is vertex joins 2 endpoints..
|
||||
if (obj.movedIsEP && obj.unmovedIsEP) return;
|
||||
// Don't limit movement if this vertex is not an endpoint anyway..
|
||||
@@ -247,14 +257,14 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
start = projection(node.loc),
|
||||
end = vecAdd(start, delta),
|
||||
movedNodes = graph.childNodes(graph.entity(obj.movedId)),
|
||||
movedPath = _.map(_.map(movedNodes, 'loc'),
|
||||
movedPath = _map(_map(movedNodes, 'loc'),
|
||||
function(loc) { return vecAdd(projection(loc), delta); }),
|
||||
unmovedNodes = graph.childNodes(graph.entity(obj.unmovedId)),
|
||||
unmovedPath = _.map(_.map(unmovedNodes, 'loc'), projection),
|
||||
unmovedPath = _map(_map(unmovedNodes, 'loc'), projection),
|
||||
hits = geoPathIntersections(movedPath, unmovedPath);
|
||||
|
||||
for (var i = 0; i < hits.length; i++) {
|
||||
if (_.isEqual(hits[i], end)) continue;
|
||||
if (_isEqual(hits[i], end)) continue;
|
||||
var edge = geoChooseEdge(unmovedNodes, end, projection);
|
||||
delta = vecSub(projection(edge.loc), start);
|
||||
}
|
||||
@@ -267,18 +277,18 @@ export function actionMove(moveIds, tryDelta, projection, cache) {
|
||||
|
||||
setupCache(graph);
|
||||
|
||||
if (!_.isEmpty(cache.intersection)) {
|
||||
if (!_isEmpty(cache.intersection)) {
|
||||
limitDelta(graph);
|
||||
}
|
||||
|
||||
_.each(cache.nodes, function(id) {
|
||||
_each(cache.nodes, function(id) {
|
||||
var node = graph.entity(id),
|
||||
start = projection(node.loc),
|
||||
end = vecAdd(start, delta);
|
||||
graph = graph.replace(node.move(projection.invert(end)));
|
||||
});
|
||||
|
||||
if (!_.isEmpty(cache.intersection)) {
|
||||
if (!_isEmpty(cache.intersection)) {
|
||||
graph = cleanupIntersections(graph);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import _ from 'lodash';
|
||||
import _clone from 'lodash-es/clone';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
import { actionDeleteNode } from './delete_node';
|
||||
import { geoEuclideanDistance, geoInterp } from '../geo/index';
|
||||
import {
|
||||
geoEuclideanDistance,
|
||||
geoInterp
|
||||
} from '../geo';
|
||||
|
||||
|
||||
/*
|
||||
* Based on https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/potlatch2/tools/Quadrilateralise.as
|
||||
@@ -17,7 +23,7 @@ export function actionOrthogonalize(wayId, projection) {
|
||||
|
||||
var way = graph.entity(wayId),
|
||||
nodes = graph.childNodes(way),
|
||||
points = _.uniq(nodes).map(function(n) { return projection(n.loc); }),
|
||||
points = _uniq(nodes).map(function(n) { return projection(n.loc); }),
|
||||
corner = {i: 0, dotp: 1},
|
||||
epsilon = 1e-4,
|
||||
node, loc, score, motions, i, j;
|
||||
@@ -38,7 +44,7 @@ export function actionOrthogonalize(wayId, projection) {
|
||||
|
||||
} else {
|
||||
var best,
|
||||
originalPoints = _.clone(points);
|
||||
originalPoints = _clone(points);
|
||||
score = Infinity;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
@@ -48,7 +54,7 @@ export function actionOrthogonalize(wayId, projection) {
|
||||
}
|
||||
var newScore = squareness(points);
|
||||
if (newScore < score) {
|
||||
best = _.clone(points);
|
||||
best = _clone(points);
|
||||
score = newScore;
|
||||
}
|
||||
if (score < epsilon) {
|
||||
@@ -176,7 +182,7 @@ export function actionOrthogonalize(wayId, projection) {
|
||||
action.disabled = function(graph) {
|
||||
var way = graph.entity(wayId),
|
||||
nodes = graph.childNodes(way),
|
||||
points = _.uniq(nodes).map(function(n) { return projection(n.loc); });
|
||||
points = _uniq(nodes).map(function(n) { return projection(n.loc); });
|
||||
|
||||
if (squareness(points)) {
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
polygonHull as d3polygonHull,
|
||||
polygonCentroid as d3polygonCentroid
|
||||
} from 'd3';
|
||||
polygonHull as d3_polygonHull,
|
||||
polygonCentroid as d3_polygonCentroid
|
||||
} from 'd3-polygon';
|
||||
|
||||
import {
|
||||
geoEuclideanDistance,
|
||||
@@ -22,8 +22,8 @@ export function actionReflect(reflectIds, projection) {
|
||||
// http://gis.stackexchange.com/questions/3739/generalisation-strategies-for-building-outlines/3756#3756
|
||||
function getSmallestSurroundingRectangle(graph, nodes) {
|
||||
var points = nodes.map(function(n) { return projection(n.loc); }),
|
||||
hull = d3polygonHull(points),
|
||||
centroid = d3polygonCentroid(hull),
|
||||
hull = d3_polygonHull(points),
|
||||
centroid = d3_polygonCentroid(hull),
|
||||
minArea = Infinity,
|
||||
ssrExtent = [],
|
||||
ssrAngle = 0,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
osmInferRestriction,
|
||||
osmRelation,
|
||||
osmWay
|
||||
} from '../osm/index';
|
||||
} from '../osm';
|
||||
|
||||
|
||||
// Create a restriction relation for `turn`, which must have the following structure:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import _transform from 'lodash-es/transform';
|
||||
|
||||
|
||||
/*
|
||||
Order the nodes of a way in reverse order and reverse any direction dependent tags
|
||||
other than `oneway`. (We assume that correcting a backwards oneway is the primary
|
||||
@@ -83,7 +85,7 @@ export function actionReverse(wayId, options) {
|
||||
|
||||
function reverseDirectionTags(node) {
|
||||
// Update the direction based tags as appropriate then return an updated node
|
||||
return node.update({tags: _.transform(node.tags, function(acc, tagValue, tagKey) {
|
||||
return node.update({tags: _transform(node.tags, function(acc, tagValue, tagKey) {
|
||||
// See if this is a direction tag and reverse (or use existing value if not recognised)
|
||||
if (tagKey === 'direction') {
|
||||
acc[tagKey] = {forward: 'backward', backward: 'forward', left: 'right', right: 'left'}[tagValue] || tagValue;
|
||||
@@ -99,7 +101,7 @@ export function actionReverse(wayId, options) {
|
||||
|
||||
function reverseTagsOnNodes(graph, nodeIds) {
|
||||
// Reverse the direction of appropriate tags attached to the nodes (#3076)
|
||||
return _(nodeIds)
|
||||
return nodeIds
|
||||
// Get each node from the graph
|
||||
.map(function(nodeId) { return graph.entity(nodeId);})
|
||||
// Check tags on the node, if there aren't any, we can skip
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { geoRotate } from '../geo';
|
||||
import { utilGetAllNodes } from '../util';
|
||||
|
||||
|
||||
export function actionRotate(rotateIds, pivot, angle, projection) {
|
||||
|
||||
var action = function(graph) {
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
import _ from 'lodash';
|
||||
import { osmIsSimpleMultipolygonOuterMember, osmRelation, osmWay } from '../osm/index';
|
||||
import { geoSphericalDistance } from '../geo/index';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _indexOf from 'lodash-es/indexOf';
|
||||
import _some from 'lodash-es/some';
|
||||
|
||||
import { actionAddMember } from './add_member';
|
||||
import { utilWrap } from '../util/index';
|
||||
import { geoSphericalDistance } from '../geo';
|
||||
|
||||
import {
|
||||
osmIsSimpleMultipolygonOuterMember,
|
||||
osmRelation,
|
||||
osmWay
|
||||
} from '../osm';
|
||||
|
||||
import { utilWrap } from '../util';
|
||||
|
||||
|
||||
// Split a way at the given node.
|
||||
@@ -83,7 +92,7 @@ export function actionSplit(nodeId, newWayIds) {
|
||||
|
||||
if (wayA.isClosed()) {
|
||||
var nodes = wayA.nodes.slice(0, -1),
|
||||
idxA = _.indexOf(nodes, nodeId),
|
||||
idxA = _indexOf(nodes, nodeId),
|
||||
idxB = splitArea(nodes, idxA, graph);
|
||||
|
||||
if (idxB < idxA) {
|
||||
@@ -94,7 +103,7 @@ export function actionSplit(nodeId, newWayIds) {
|
||||
nodesB = nodes.slice(idxB).concat(nodes.slice(0, idxA + 1));
|
||||
}
|
||||
} else {
|
||||
var idx = _.indexOf(wayA.nodes, nodeId, 1);
|
||||
var idx = _indexOf(wayA.nodes, nodeId, 1);
|
||||
nodesA = wayA.nodes.slice(0, idx + 1);
|
||||
nodesB = wayA.nodes.slice(idx);
|
||||
}
|
||||
@@ -131,7 +140,7 @@ export function actionSplit(nodeId, newWayIds) {
|
||||
|
||||
if (!isOuter && isArea) {
|
||||
var multipolygon = osmRelation({
|
||||
tags: _.extend({}, wayA.tags, {type: 'multipolygon'}),
|
||||
tags: _extend({}, wayA.tags, {type: 'multipolygon'}),
|
||||
members: [
|
||||
{id: wayA.id, role: 'outer', type: 'way'},
|
||||
{id: wayB.id, role: 'outer', type: 'way'}
|
||||
@@ -158,7 +167,7 @@ export function actionSplit(nodeId, newWayIds) {
|
||||
action.ways = function(graph) {
|
||||
var node = graph.entity(nodeId),
|
||||
parents = graph.parentWays(node),
|
||||
hasLines = _.some(parents, function(parent) { return parent.geometry(graph) === 'line'; });
|
||||
hasLines = _some(parents, function(parent) { return parent.geometry(graph) === 'line'; });
|
||||
|
||||
return parents.filter(function(parent) {
|
||||
if (wayIds && wayIds.indexOf(parent.id) === -1)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { actionDeleteNode } from './delete_node';
|
||||
import { geoEuclideanDistance, geoInterp } from '../geo/index';
|
||||
|
||||
import {
|
||||
geoEuclideanDistance,
|
||||
geoInterp
|
||||
} from '../geo';
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -42,7 +42,6 @@ export { uiPresetEditor as uiPreset } from './ui/preset_editor';
|
||||
export var debug = false;
|
||||
|
||||
import * as d3 from 'd3';
|
||||
import * as _ from 'lodash';
|
||||
import * as lib from './lib/index';
|
||||
|
||||
export { d3, _, lib };
|
||||
export { d3, lib };
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"diacritics": "1.3.0",
|
||||
"lodash": "4.17.4",
|
||||
"lodash-es": "4.17.4",
|
||||
"marked": "0.3.6",
|
||||
"osm-auth": "1.0.2",
|
||||
"rbush": "2.0.1",
|
||||
|
||||
Reference in New Issue
Block a user