diff --git a/modules/actions/move.js b/modules/actions/move.js index d6964a94a..f7b1498eb 100644 --- a/modules/actions/move.js +++ b/modules/actions/move.js @@ -1,15 +1,8 @@ import _isEqual from 'lodash-es/isEqual'; -import _map from 'lodash-es/map'; import { - geoAngle, - geoChooseEdge, - geoPathIntersections, - geoPathLength, - geoVecAdd, - geoVecEqual, - geoVecInterp, - geoVecSubtract + geoAngle, geoChooseEdge, geoPathIntersections, geoPathLength, + geoVecAdd, geoVecEqual, geoVecInterp, geoVecSubtract } from '../geo'; import { osmNode } from '../osm'; @@ -18,21 +11,21 @@ import { utilArrayIntersection } from '../util'; // https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as -export function actionMove(moveIds, tryDelta, projection, cache) { +export function actionMove(moveIDs, tryDelta, projection, cache) { var _delta = tryDelta; function setupCache(graph) { - function canMove(nodeId) { + function canMove(nodeID) { // Allow movement of any node that is in the selectedIDs list.. - if (moveIds.indexOf(nodeId) !== -1) return true; + 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 = graph.parentWays(graph.entity(nodeID)); if (parents.length < 3) return true; // Restrict movement of a vertex where >2 ways meet, unless all parentWays are moving too.. - var parentsMoving = parents.every(function(id) { return cache.moving[id]; }); - if (!parentsMoving) delete cache.moving[nodeId]; + var parentsMoving = parents.every(function(way) { return cache.moving[way.id]; }); + if (!parentsMoving) delete cache.moving[nodeID]; return parentsMoving; } @@ -113,7 +106,7 @@ export function actionMove(moveIds, tryDelta, projection, cache) { cache.nodes = []; cache.ways = []; - cacheEntities(moveIds); + cacheEntities(moveIDs); cacheIntersections(cache.ways); cache.nodes = cache.nodes.filter(canMove); @@ -331,9 +324,9 @@ export function actionMove(moveIds, tryDelta, projection, cache) { var start = projection(node.loc); var end = geoVecAdd(start, _delta); var movedNodes = graph.childNodes(graph.entity(obj.movedId)); - var movedPath = _map(_map(movedNodes, 'loc'), moveNode); + var movedPath = movedNodes.map(function(n) { return moveNode(n.loc); }); var unmovedNodes = graph.childNodes(graph.entity(obj.unmovedId)); - var unmovedPath = _map(_map(unmovedNodes, 'loc'), projection); + var unmovedPath = unmovedNodes.map(function(n) { return projection(n.loc); }); var hits = geoPathIntersections(movedPath, unmovedPath); for (var j = 0; i < hits.length; i++) { diff --git a/modules/behavior/lasso.js b/modules/behavior/lasso.js index bc4a808b1..9c9af45bf 100644 --- a/modules/behavior/lasso.js +++ b/modules/behavior/lasso.js @@ -1,15 +1,6 @@ -import _map from 'lodash-es/map'; - -import { - event as d3_event, - select as d3_select -} from 'd3-selection'; - -import { - geoExtent, - geoPointInPolygon -} from '../geo'; +import { event as d3_event, select as d3_select } from 'd3-selection'; +import { geoExtent, geoPointInPolygon } from '../geo'; import { modeSelect } from '../modes'; import { uiLasso } from '../ui'; @@ -47,7 +38,8 @@ export function behaviorLasso(context) { function normalize(a, b) { return [ [Math.min(a[0], b[0]), Math.min(a[1], b[1])], - [Math.max(a[0], b[0]), Math.max(a[1], b[1])]]; + [Math.max(a[0], b[0]), Math.max(a[1], b[1])] + ]; } @@ -58,11 +50,13 @@ export function behaviorLasso(context) { var bounds = lasso.extent().map(context.projection.invert); var extent = geoExtent(normalize(bounds[0], bounds[1])); - return _map(context.intersects(extent).filter(function(entity) { + var intersects = context.intersects(extent).filter(function(entity) { return entity.type === 'node' && geoPointInPolygon(context.projection(entity.loc), lasso.coordinates) && !context.features().isHidden(entity, graph, entity.geometry(graph)); - }), 'id'); + }); + + return intersects.map(function(entity) { return entity.id; }); } diff --git a/modules/core/context.js b/modules/core/context.js index 2fcf29a77..28339f2e9 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -19,7 +19,6 @@ import { utilDetect } from '../util/detect'; import { utilCallWhenIdle, utilKeybinding, utilRebind, utilStringQs } from '../util'; - export var areaKeys = {}; export function setAreaKeys(value) { diff --git a/modules/core/tree.js b/modules/core/tree.js index 839f51125..8ee81e6a1 100644 --- a/modules/core/tree.js +++ b/modules/core/tree.js @@ -1,13 +1,12 @@ -import _map from 'lodash-es/map'; import rbush from 'rbush'; import { coreDifference } from './difference'; export function coreTree(head) { - var rtree = rbush(), - bboxes = {}, - tree = {}; + var rtree = rbush(); + var bboxes = {}; + var tree = {}; function entityBBox(entity) { @@ -44,9 +43,7 @@ export function coreTree(head) { for (var i = 0; i < entities.length; i++) { var entity = entities[i]; - - if (!entity.visible) - continue; + if (!entity.visible) continue; if (head.entities.hasOwnProperty(entity.id) || bboxes[entity.id]) { if (!force) { @@ -60,7 +57,7 @@ export function coreTree(head) { updateParents(entity, insertions, {}); } - rtree.load(_map(insertions, entityBBox)); + rtree.load(Object.values(insertions).map(entityBBox)); return tree; }; @@ -68,8 +65,8 @@ export function coreTree(head) { tree.intersects = function(extent, graph) { if (graph !== head) { - var diff = coreDifference(head, graph), - insertions = {}; + var diff = coreDifference(head, graph); + var insertions = {}; head = graph; @@ -88,12 +85,11 @@ export function coreTree(head) { insertions[entity.id] = entity; }); - rtree.load(_map(insertions, entityBBox)); + rtree.load(Object.values(insertions).map(entityBBox)); } - return rtree.search(extent.bbox()).map(function(bbox) { - return head.entity(bbox.id); - }); + return rtree.search(extent.bbox()) + .map(function(bbox) { return head.entity(bbox.id); }); }; diff --git a/modules/modes/save.js b/modules/modes/save.js index 04d52e211..bf3022c85 100644 --- a/modules/modes/save.js +++ b/modules/modes/save.js @@ -1,11 +1,4 @@ -import _map from 'lodash-es/map'; -import _reduce from 'lodash-es/reduce'; - -import { - event as d3_event, - select as d3_select -} from 'd3-selection'; - +import { event as d3_event, select as d3_select } from 'd3-selection'; import { t } from '../util/locale'; import { actionDiscardTags, actionMergeRemoteChanges, actionNoop, actionRevert } from '../actions'; @@ -132,22 +125,19 @@ export function modeSave(context) { function withChildNodes(ids, graph) { - return utilArrayUniq(_reduce(ids, function(result, id) { + var s = new Set(ids); + ids.forEach(function(id) { var entity = graph.entity(id); - if (entity.type === 'way') { - try { - var children = graph.childNodes(entity) - .filter(function(child) { return child.version !== undefined; }); + if (entity.type !== 'way') return; - result.push.apply(result, _map(children, 'id')); - } catch (err) { - /* eslint-disable no-console */ - if (typeof console !== 'undefined') console.error(err); - /* eslint-enable no-console */ + graph.childNodes(entity).forEach(function(child) { + if (child.version !== undefined) { + s.add(child.id); } - } - return result; - }, ids.slice())); // shallow copy + }); + }); + + return Array.from(s); } diff --git a/modules/osm/changeset.js b/modules/osm/changeset.js index 122a31d05..29cd214d5 100644 --- a/modules/osm/changeset.js +++ b/modules/osm/changeset.js @@ -1,5 +1,3 @@ -import _map from 'lodash-es/map'; - import { osmEntity } from './entity'; import { geoExtent } from '../geo'; @@ -36,9 +34,9 @@ Object.assign(osmChangeset.prototype, { return { osm: { changeset: { - tag: _map(this.tags, function(value, key) { - return { '@k': key, '@v': value }; - }), + tag: Object.keys(this.tags).map(function(k) { + return { '@k': k, '@v': this.tags[k] }; + }, this), '@version': 0.6, '@generator': 'iD' } diff --git a/modules/osm/node.js b/modules/osm/node.js index ff38afd12..59e51c8c6 100644 --- a/modules/osm/node.js +++ b/modules/osm/node.js @@ -1,5 +1,3 @@ -import _map from 'lodash-es/map'; - import { osmEntity } from './entity'; import { geoAngle, geoExtent } from '../geo'; import { utilArrayUniq } from '../util'; @@ -221,9 +219,9 @@ Object.assign(osmNode.prototype, { '@lon': this.loc[0], '@lat': this.loc[1], '@version': (this.version || 0), - tag: _map(this.tags, function(v, k) { - return { keyAttributes: { k: k, v: v } }; - }) + tag: Object.keys(this.tags).map(function(k) { + return { keyAttributes: { k: k, v: this.tags[k] } }; + }, this) } }; if (changeset_id) r.node['@changeset'] = changeset_id; diff --git a/modules/osm/relation.js b/modules/osm/relation.js index 2cd954cbe..a02f761d6 100644 --- a/modules/osm/relation.js +++ b/modules/osm/relation.js @@ -1,5 +1,3 @@ -import _map from 'lodash-es/map'; - import { geoArea as d3_geoArea } from 'd3-geo'; import { osmEntity } from './entity'; @@ -173,8 +171,7 @@ Object.assign(osmRelation.prototype, { // By default, adding a duplicate member (by id and role) is prevented. // Return an updated relation. replaceMember: function(needle, replacement, keepDuplicates) { - if (!this.memberById(needle.id)) - return this; + if (!this.memberById(needle.id)) return this; var members = []; @@ -183,11 +180,11 @@ Object.assign(osmRelation.prototype, { if (member.id !== needle.id) { members.push(member); } else if (keepDuplicates || !this.memberByIdAndRole(replacement.id, member.role)) { - members.push({id: replacement.id, type: replacement.type, role: member.role}); + members.push({ id: replacement.id, type: replacement.type, role: member.role }); } } - return this.update({members: members}); + return this.update({ members: members }); }, @@ -196,7 +193,7 @@ Object.assign(osmRelation.prototype, { relation: { '@id': this.osmId(), '@version': this.version || 0, - member: _map(this.members, function(member) { + member: this.members.map(function(member) { return { keyAttributes: { type: member.type, @@ -204,13 +201,15 @@ Object.assign(osmRelation.prototype, { ref: osmEntity.id.toOSM(member.id) } }; - }), - tag: _map(this.tags, function(v, k) { - return { keyAttributes: { k: k, v: v } }; - }) + }, this), + tag: Object.keys(this.tags).map(function(k) { + return { keyAttributes: { k: k, v: this.tags[k] } }; + }, this) } }; - if (changeset_id) r.relation['@changeset'] = changeset_id; + if (changeset_id) { + r.relation['@changeset'] = changeset_id; + } return r; }, @@ -299,8 +298,12 @@ Object.assign(osmRelation.prototype, { outers = osmJoinWays(outers, resolver); inners = osmJoinWays(inners, resolver); - outers = outers.map(function(outer) { return _map(outer.nodes, 'loc'); }); - inners = inners.map(function(inner) { return _map(inner.nodes, 'loc'); }); + outers = outers.map(function(outer) { + return outer.nodes.map(function(node) { return node.loc; }); + }); + inners = inners.map(function(inner) { + return inner.nodes.map(function(node) { return node.loc; }); + }); var result = outers.map(function(o) { // Heuristic for detecting counterclockwise winding order. Assumes @@ -332,10 +335,11 @@ Object.assign(osmRelation.prototype, { } var o = findOuter(inners[i]); - if (o !== undefined) + if (o !== undefined) { result[o].push(inners[i]); - else + } else { result.push([inners[i]]); // Invalid geometry + } } return result; diff --git a/modules/osm/way.js b/modules/osm/way.js index 2b6c29880..9dbdcabac 100644 --- a/modules/osm/way.js +++ b/modules/osm/way.js @@ -1,5 +1,3 @@ -import _map from 'lodash-es/map'; - import { geoArea as d3_geoArea } from 'd3-geo'; import { geoExtent, geoVecCross } from '../geo'; @@ -437,10 +435,10 @@ Object.assign(osmWay.prototype, { '@version': this.version || 0, nd: this.nodes.map(function(id) { return { keyAttributes: { ref: osmEntity.id.toOSM(id) } }; - }), - tag: _map(this.tags, function(v, k) { - return { keyAttributes: { k: k, v: v } }; - }) + }, this), + tag: Object.keys(this.tags).map(function(k) { + return { keyAttributes: { k: k, v: this.tags[k] } }; + }, this) } }; if (changeset_id) { diff --git a/modules/renderer/map.js b/modules/renderer/map.js index 6995b82fd..64f360483 100644 --- a/modules/renderer/map.js +++ b/modules/renderer/map.js @@ -1,20 +1,10 @@ -import _map from 'lodash-es/map'; import _throttle from 'lodash-es/throttle'; -import { set as d3_set } from 'd3-collection'; import { dispatch as d3_dispatch } from 'd3-dispatch'; import { interpolate as d3_interpolate } from 'd3-interpolate'; import { scaleLinear as d3_scaleLinear } from 'd3-scale'; - -import { - event as d3_event, - select as d3_select -} from 'd3-selection'; - -import { - zoom as d3_zoom, - zoomIdentity as d3_zoomIdentity -} from 'd3-zoom'; +import { event as d3_event, select as d3_select } from 'd3-selection'; +import { zoom as d3_zoom, zoomIdentity as d3_zoomIdentity } from 'd3-zoom'; import { t } from '../util/locale'; import { geoExtent, geoRawMercator, geoScaleToZoom, geoZoomToScale } from '../geo'; @@ -280,12 +270,14 @@ export function rendererMap(context) { var all = context.intersects(map.extent()); var fullRedraw = false; var data; + var set; var filter; if (difference) { var complete = difference.complete(map.extent()); data = Object.values(complete).filter(Boolean); - filter = function(d) { return d.id in complete; }; + set = new Set(data.map(function(entity) { return entity.id; })); + filter = function(d) { return set.has(d.id); }; features.clear(data); } else { @@ -297,7 +289,7 @@ export function rendererMap(context) { if (extent) { data = context.intersects(map.extent().intersection(extent)); - var set = d3_set(_map(data, 'id')); + set = new Set(data.map(function(entity) { return entity.id; })); filter = function(d) { return set.has(d.id); }; } else { diff --git a/modules/svg/areas.js b/modules/svg/areas.js index 2145024e8..5f2c19bbc 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -1,5 +1,3 @@ -import _map from 'lodash-es/map'; - import { bisector as d3_bisector } from 'd3-array'; import { osmEntity, osmIsOldMultipolygonOuterMember } from '../osm'; @@ -213,19 +211,17 @@ export function svgAreas(projection, context) { } } - areas = Object.values(areas).filter(function hasPath(a) { return path(a.entity); }); - areas.sort(function areaSort(a, b) { return b.area - a.area; }); - areas = _map(areas, 'entity'); + var fills = Object.values(areas).filter(function hasPath(a) { return path(a.entity); }); + fills.sort(function areaSort(a, b) { return b.area - a.area; }); + fills = fills.map(function(a) { return a.entity; }); - var strokes = areas.filter(function(area) { - return area.type === 'way'; - }); + var strokes = fills.filter(function(area) { return area.type === 'way'; }); var data = { - clip: areas, + clip: fills, shadow: strokes, stroke: strokes, - fill: areas + fill: fills }; var clipPaths = context.surface().selectAll('defs').selectAll('.clipPath-osm') @@ -269,15 +265,13 @@ export function svgAreas(projection, context) { paths.exit() .remove(); - var fills = selection.selectAll('.area-fill path.area').nodes(); - var bisect = d3_bisector(function(node) { - return -node.__data__.area(graph); - }).left; + var fillpaths = selection.selectAll('.area-fill path.area').nodes(); + var bisect = d3_bisector(function(node) { return -node.__data__.area(graph); }).left; function sortedByArea(entity) { if (this._parent.__data__ === 'fill') { - return fills[bisect(fills, -entity.area(graph))]; + return fillpaths[bisect(fillpaths, -entity.area(graph))]; } } diff --git a/modules/svg/labels.js b/modules/svg/labels.js index 569cc4f6e..c6fdaf9cb 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -1,28 +1,20 @@ -import _map from 'lodash-es/map'; import _throttle from 'lodash-es/throttle'; import { geoPath as d3_geoPath } from 'd3-geo'; - import rbush from 'rbush'; import { textDirection } from '../util/locale'; import { - geoExtent, - geoPolygonIntersectsPolygon, - geoPathLength, - geoScaleToZoom, - geoVecInterp, - geoVecLength + geoExtent, geoPolygonIntersectsPolygon, geoPathLength, + geoScaleToZoom, geoVecInterp, geoVecLength } from '../geo'; import { osmEntity } from '../osm'; import { utilDetect } from '../util/detect'; import { - utilDisplayName, - utilDisplayNameForPath, - utilEntitySelector, - utilCallWhenIdle + utilDisplayName, utilDisplayNameForPath, + utilEntitySelector, utilCallWhenIdle } from '../util'; @@ -449,7 +441,8 @@ export function svgLabels(projection, context) { function getLineLabel(entity, width, height) { var viewport = geoExtent(context.projection.clipExtent()).polygon(); - var points = _map(graph.childNodes(entity), 'loc').map(projection); + var points = graph.childNodes(entity) + .map(function(node) { return projection(node.loc); }); var length = geoPathLength(points); if (length < width + 20) return; @@ -722,7 +715,8 @@ export function svgLabels(projection, context) { if (mouse) { pad = 20; bbox = { minX: mouse[0] - pad, minY: mouse[1] - pad, maxX: mouse[0] + pad, maxY: mouse[1] + pad }; - ids.push.apply(ids, _map(_rdrawn.search(bbox), 'id')); + var nearMouse = _rdrawn.search(bbox).map(function(entity) { return entity.id; }); + ids.push.apply(ids, nearMouse); } // hide labels on selected nodes (they look weird when dragging / haloed) diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 1d3317c0c..fb6a6f427 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -1,11 +1,5 @@ -import _map from 'lodash-es/map'; - import { dispatch as d3_dispatch } from 'd3-dispatch'; - -import { - event as d3_event, - select as d3_select -} from 'd3-selection'; +import { event as d3_event, select as d3_select } from 'd3-selection'; import { osmEntity } from '../../osm/entity'; import { t } from '../../util/locale'; @@ -204,7 +198,7 @@ export function uiFieldCombo(field, context) { // hide the caret if there are no suggestions container.classed('empty-combobox', data.length === 0); - _comboData = _map(data, function(d) { + _comboData = data.map(function(d) { var k = d.value; if (isMulti) k = k.replace(field.key, ''); var v = snake_case ? unsnake(k) : k; @@ -221,14 +215,17 @@ export function uiFieldCombo(field, context) { } - function setPlaceholder(d) { + function setPlaceholder(values) { var ph; if (isMulti || isSemi) { ph = field.placeholder() || t('inspector.add'); } else { - var vals = _map(d, 'value').filter(function(s) { return s.length < 20; }), - placeholders = vals.length > 1 ? vals : _map(d, 'key'); + var vals = values + .map(function(d) { return d.value; }) + .filter(function(s) { return s.length < 20; }); + + var placeholders = vals.length > 1 ? vals : values.map(function(d) { return d.key; }); ph = field.placeholder() || placeholders.slice(0, 3).join(', '); } @@ -407,7 +404,7 @@ export function uiFieldCombo(field, context) { } // Set keys for form-field modified (needed for undo and reset buttons).. - field.keys = _map(_multiData, 'key'); + field.keys = _multiData.map(function(d) { return d.key; }); } else if (isSemi) { var arr = utilArrayUniq((tags[field.key] || '').split(';')).filter(Boolean); diff --git a/modules/ui/map_in_map.js b/modules/ui/map_in_map.js index 55b9b4ed7..ed130973f 100644 --- a/modules/ui/map_in_map.js +++ b/modules/ui/map_in_map.js @@ -1,24 +1,9 @@ import { geoPath as d3_geoPath } from 'd3-geo'; - -import { - event as d3_event, - select as d3_select -} from 'd3-selection'; - -import { - zoom as d3_zoom, - zoomIdentity as d3_zoomIdentity -} from 'd3-zoom'; +import { event as d3_event, select as d3_select } from 'd3-selection'; +import { zoom as d3_zoom, zoomIdentity as d3_zoomIdentity } from 'd3-zoom'; import { t } from '../util/locale'; -import { - geoRawMercator, - geoScaleToZoom, - geoVecSubtract, - geoVecScale, - geoZoomToScale, -} from '../geo'; - +import { geoRawMercator, geoScaleToZoom, geoVecSubtract, geoVecScale, geoZoomToScale } from '../geo'; import { rendererTileLayer } from '../renderer'; import { svgDebug, svgData } from '../svg'; import { utilSetTransform } from '../util'; @@ -27,7 +12,7 @@ import { utilGetDimensions } from '../util/dimensions'; export function uiMapInMap(context) { - function map_in_map(selection) { + function mapInMap(selection) { var backgroundLayer = rendererTileLayer(context); var overlayLayers = {}; var projection = geoRawMercator(); @@ -338,5 +323,5 @@ export function uiMapInMap(context) { .on(t('background.minimap.key'), toggle); } - return map_in_map; + return mapInMap; }