diff --git a/modules/actions/split.js b/modules/actions/split.js index f5ac77660..c3625cdf6 100644 --- a/modules/actions/split.js +++ b/modules/actions/split.js @@ -1,5 +1,3 @@ -import _indexOf from 'lodash-es/indexOf'; - import { actionAddMember } from './add_member'; import { geoSphericalDistance } from '../geo'; import { osmIsOldMultipolygonOuterMember, osmRelation, osmWay } from '../osm'; @@ -53,16 +51,17 @@ export function actionSplit(nodeId, newWayIds) { // calculate lengths length = 0; - for (i = wrap(idxA+1); i !== idxA; i = wrap(i+1)) { - length += dist(nodes[i], nodes[wrap(i-1)]); + for (i = wrap(idxA + 1); i !== idxA; i = wrap(i + 1)) { + length += dist(nodes[i], nodes[wrap(i - 1)]); lengths[i] = length; } length = 0; - for (i = wrap(idxA-1); i !== idxA; i = wrap(i-1)) { - length += dist(nodes[i], nodes[wrap(i+1)]); - if (length < lengths[i]) + for (i = wrap(idxA - 1); i !== idxA; i = wrap(i - 1)) { + length += dist(nodes[i], nodes[wrap(i + 1)]); + if (length < lengths[i]) { lengths[i] = length; + } } // determine best opposite node to split @@ -88,7 +87,7 @@ export function actionSplit(nodeId, newWayIds) { if (wayA.isClosed()) { var nodes = wayA.nodes.slice(0, -1); - var idxA = _indexOf(nodes, nodeId); + var idxA = nodes.indexOf(nodeId); var idxB = splitArea(nodes, idxA, graph); if (idxB < idxA) { @@ -99,13 +98,13 @@ 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 = wayA.nodes.indexOf(nodeId, 1); nodesA = wayA.nodes.slice(0, idx + 1); nodesB = wayA.nodes.slice(idx); } - wayA = wayA.update({nodes: nodesA}); - wayB = wayB.update({nodes: nodesB}); + wayA = wayA.update({ nodes: nodesA }); + wayB = wayB.update({ nodes: nodesB }); graph = graph.replace(wayA); graph = graph.replace(wayB); @@ -166,8 +165,8 @@ export function actionSplit(nodeId, newWayIds) { } else { if (relation === isOuter) { graph = graph.replace(relation.mergeTags(wayA.tags)); - graph = graph.replace(wayA.update({tags: {}})); - graph = graph.replace(wayB.update({tags: {}})); + graph = graph.replace(wayA.update({ tags: {} })); + graph = graph.replace(wayB.update({ tags: {} })); } member = { @@ -190,14 +189,14 @@ export function actionSplit(nodeId, newWayIds) { var multipolygon = osmRelation({ tags: Object.assign({}, wayA.tags, { type: 'multipolygon' }), members: [ - {id: wayA.id, role: 'outer', type: 'way'}, - {id: wayB.id, role: 'outer', type: 'way'} + { id: wayA.id, role: 'outer', type: 'way' }, + { id: wayB.id, role: 'outer', type: 'way' } ] }); graph = graph.replace(multipolygon); - graph = graph.replace(wayA.update({tags: {}})); - graph = graph.replace(wayB.update({tags: {}})); + graph = graph.replace(wayA.update({ tags: {} })); + graph = graph.replace(wayB.update({ tags: {} })); } return graph; @@ -244,14 +243,15 @@ export function actionSplit(nodeId, newWayIds) { action.disabled = function(graph) { var candidates = action.ways(graph); - if (candidates.length === 0 || (_wayIDs && _wayIDs.length !== candidates.length)) + if (candidates.length === 0 || (_wayIDs && _wayIDs.length !== candidates.length)) { return 'not_eligible'; + } }; - action.limitWays = function(_) { + action.limitWays = function(val) { if (!arguments.length) return _wayIDs; - _wayIDs = _; + _wayIDs = val; return action; };