From 07fa5fcc3416f4eda12bdf04ea395e7744435b29 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 11 Oct 2016 22:41:24 -0400 Subject: [PATCH] Refactor Entity, Node, Relation, Tags, Way from `core` to `osm` --- modules/actions/circularize.js | 4 +-- modules/actions/disconnect.js | 4 +-- modules/actions/join.js | 4 +-- modules/actions/merge_polygon.js | 4 +-- modules/actions/merge_remote_changes.js | 8 ++--- modules/actions/move.js | 4 +-- modules/actions/restrict_turn.js | 6 ++-- modules/actions/split.js | 6 ++-- modules/behavior/draw_way.js | 16 +++++----- modules/behavior/hover.js | 4 +-- modules/behavior/select.js | 4 +-- modules/core/connection.js | 37 ++++++++++------------ modules/core/graph.js | 2 +- modules/core/history.js | 14 ++++----- modules/core/index.js | 5 --- modules/geo/intersection.js | 10 +++--- modules/index.js | 11 ++++--- modules/modes/add_area.js | 12 +++---- modules/modes/add_line.js | 12 +++---- modules/modes/add_point.js | 6 ++-- modules/modes/drag_node.js | 4 +-- modules/modes/select.js | 10 +++--- modules/{core => osm}/entity.js | 38 +++++++++++------------ modules/osm/index.js | 10 ++++++ modules/{core => osm}/node.js | 14 ++++----- modules/{core => osm}/relation.js | 24 +++++++------- modules/{core => osm}/tags.js | 6 ++-- modules/{core => osm}/way.js | 24 +++++++------- modules/renderer/features.js | 10 +++--- modules/svg/areas.js | 8 ++--- modules/svg/labels.js | 14 ++++----- modules/svg/lines.js | 8 ++--- modules/svg/points.js | 4 +-- modules/svg/tag_classes.js | 6 ++-- modules/svg/vertices.js | 4 +-- modules/ui/feature_list.js | 4 +-- modules/ui/fields/check.js | 4 +-- modules/ui/fields/restrictions.js | 4 +-- modules/ui/intro/intro.js | 5 +-- modules/ui/raw_member_editor.js | 6 ++-- modules/ui/raw_membership_editor.js | 8 ++--- modules/ui/selection_list.js | 6 ++-- package.json | 2 +- test/index.html | 12 +++---- test/rendering.html | 9 +++--- test/spec/actions/merge_remote_changes.js | 33 ++------------------ test/spec/{id.js => core/context.js} | 2 +- test/spec/{core => osm}/entity.js | 0 test/spec/{core => osm}/node.js | 0 test/spec/{core => osm}/relation.js | 0 test/spec/{core => osm}/way.js | 0 test/spec/spec_helpers.js | 2 +- 52 files changed, 215 insertions(+), 239 deletions(-) rename modules/{core => osm}/entity.js (77%) create mode 100644 modules/osm/index.js rename modules/{core => osm}/node.js (89%) rename modules/{core => osm}/relation.js (93%) rename modules/{core => osm}/tags.js (89%) rename modules/{core => osm}/way.js (96%) rename test/spec/{id.js => core/context.js} (99%) rename test/spec/{core => osm}/entity.js (100%) rename test/spec/{core => osm}/node.js (100%) rename test/spec/{core => osm}/relation.js (100%) rename test/spec/{core => osm}/way.js (100%) diff --git a/modules/actions/circularize.js b/modules/actions/circularize.js index 71b805ea0..283cd829e 100644 --- a/modules/actions/circularize.js +++ b/modules/actions/circularize.js @@ -1,7 +1,7 @@ import * as d3 from 'd3'; import _ from 'lodash'; import { geoEuclideanDistance, geoInterp } from '../geo/index'; -import { coreNode } from '../core/index'; +import { osmNode } from '../osm/index'; import { polygonArea as d3polygonArea, @@ -105,7 +105,7 @@ export function actionCircularize(wayId, projection, maxAngle) { centroid[0] + Math.cos(angle) * radius, centroid[1] + Math.sin(angle) * radius]); - node = coreNode({loc: loc}); + node = osmNode({loc: loc}); graph = graph.replace(node); nodes.splice(endNodeIndex + j, 0, node); diff --git a/modules/actions/disconnect.js b/modules/actions/disconnect.js index 7cebcf54d..85f9ce454 100644 --- a/modules/actions/disconnect.js +++ b/modules/actions/disconnect.js @@ -1,4 +1,4 @@ -import { coreNode } from '../core/index'; +import { osmNode } from '../osm/node'; // Disconect the ways at the given node. @@ -25,7 +25,7 @@ export function actionDisconnect(nodeId, newNodeId) { connections.forEach(function(connection) { var way = graph.entity(connection.wayID), - newNode = coreNode({id: newNodeId, loc: node.loc, tags: node.tags}); + newNode = osmNode({id: newNodeId, loc: node.loc, tags: node.tags}); graph = graph.replace(newNode); if (connection.index === 0 && way.isArea()) { diff --git a/modules/actions/join.js b/modules/actions/join.js index 6f5bd5384..0b2f36def 100644 --- a/modules/actions/join.js +++ b/modules/actions/join.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import { actionDeleteWay } from './delete_way'; -import { coreInterestingTag } from '../core/index'; +import { osmIsInterestingTag } from '../osm/index'; import { geoJoinWays } from '../geo/index'; @@ -79,7 +79,7 @@ export function actionJoin(ids) { for (var k in way.tags) { if (!(k in tags)) { tags[k] = way.tags[k]; - } else if (tags[k] && coreInterestingTag(k) && tags[k] !== way.tags[k]) { + } else if (tags[k] && osmIsInterestingTag(k) && tags[k] !== way.tags[k]) { conflicting = true; } } diff --git a/modules/actions/merge_polygon.js b/modules/actions/merge_polygon.js index 1e162f60f..a4e6f2d6d 100644 --- a/modules/actions/merge_polygon.js +++ b/modules/actions/merge_polygon.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import { geoJoinWays, geoPolygonContainsPolygon } from '../geo/index'; -import { coreRelation } from '../core/index'; +import { osmRelation } from '../osm/index'; export function actionMergePolygon(ids, newRelationId) { @@ -85,7 +85,7 @@ export function actionMergePolygon(ids, newRelationId) { // Move all tags to one relation var relation = entities.multipolygon[0] || - coreRelation({ id: newRelationId, tags: { type: 'multipolygon' }}); + osmRelation({ id: newRelationId, tags: { type: 'multipolygon' }}); entities.multipolygon.slice(1).forEach(function(m) { relation = relation.mergeTags(m.tags); diff --git a/modules/actions/merge_remote_changes.js b/modules/actions/merge_remote_changes.js index 3b5b5aa54..c4a7289b1 100644 --- a/modules/actions/merge_remote_changes.js +++ b/modules/actions/merge_remote_changes.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import { t } from '../util/locale'; import { actionDeleteMultiple } from './delete_multiple'; -import { coreEntity } from '../core/index'; +import { osmEntity } from '../osm/index'; import { diff3_merge } from '../util/diff3'; import { dataDiscarded } from '../../data/index'; @@ -103,14 +103,14 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser updates.replacements.push(remote); } else if (option === 'force_local' && local) { - target = coreEntity(local); + target = osmEntity(local); if (remote) { target = target.update({ version: remote.version }); } updates.replacements.push(target); } else if (option === 'safe' && local && remote && local.version !== remote.version) { - target = coreEntity(local, { version: remote.version }); + target = osmEntity(local, { version: remote.version }); if (remote.visible) { target = mergeLocation(remote, target); } else { @@ -208,7 +208,7 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser base = graph.base().entities[id], local = localGraph.entity(id), remote = remoteGraph.entity(id), - target = coreEntity(local, { version: remote.version }); + target = osmEntity(local, { version: remote.version }); // delete/undelete if (!remote.visible) { diff --git a/modules/actions/move.js b/modules/actions/move.js index e07f93e26..70c203f36 100644 --- a/modules/actions/move.js +++ b/modules/actions/move.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { coreNode } from '../core/index'; +import { osmNode } from '../osm/index'; import { geoChooseEdge, geoAngle, @@ -133,7 +133,7 @@ export function actionMove(moveIds, tryDelta, projection, cache) { var key = wayId + '_' + nodeId, orig = cache.replacedVertex[key]; if (!orig) { - orig = coreNode(); + orig = osmNode(); cache.replacedVertex[key] = orig; cache.startLoc[orig.id] = cache.startLoc[nodeId]; } diff --git a/modules/actions/restrict_turn.js b/modules/actions/restrict_turn.js index 88644b05d..32c308d8f 100644 --- a/modules/actions/restrict_turn.js +++ b/modules/actions/restrict_turn.js @@ -1,6 +1,6 @@ -import { coreRelation, coreWay } from '../core/index'; import { actionSplit } from './split'; import { geoInferRestriction } from '../geo/index'; +import { osmRelation, osmWay } from '../osm/index'; // Create a restriction relation for `turn`, which must have the following structure: @@ -39,7 +39,7 @@ export function actionRestrictTurn(turn, projection, restrictionId) { } function split(toOrFrom) { - var newID = toOrFrom.newID || coreWay().id; + var newID = toOrFrom.newID || osmWay().id; graph = actionSplit(via.id, [newID]) .limitWays([toOrFrom.way])(graph); @@ -72,7 +72,7 @@ export function actionRestrictTurn(turn, projection, restrictionId) { to = split(turn.to)[0]; } - return graph.replace(coreRelation({ + return graph.replace(osmRelation({ id: restrictionId, tags: { type: 'restriction', diff --git a/modules/actions/split.js b/modules/actions/split.js index 95b7217d6..e549850e1 100644 --- a/modules/actions/split.js +++ b/modules/actions/split.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { coreRelation, coreWay } from '../core/index'; +import { osmRelation, osmWay } from '../osm/index'; import { geoIsSimpleMultipolygonOuterMember, geoSphericalDistance } from '../geo/index'; import { actionAddMember } from './add_member'; import { utilWrap } from '../util/index'; @@ -75,7 +75,7 @@ export function actionSplit(nodeId, newWayIds) { function split(graph, wayA, newWayId) { - var wayB = coreWay({id: newWayId, tags: wayA.tags}), + var wayB = osmWay({id: newWayId, tags: wayA.tags}), nodesA, nodesB, isArea = wayA.isArea(), @@ -130,7 +130,7 @@ export function actionSplit(nodeId, newWayIds) { }); if (!isOuter && isArea) { - var multipolygon = coreRelation({ + var multipolygon = osmRelation({ tags: _.extend({}, wayA.tags, {type: 'multipolygon'}), members: [ {id: wayA.id, role: 'outer', type: 'way'}, diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 011613d5f..db3081177 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -14,9 +14,9 @@ import { } from '../modes/index'; import { - coreNode, - coreWay -} from '../core/index'; + osmNode, + osmWay +} from '../osm/index'; import { geoChooseEdge, @@ -44,9 +44,9 @@ export function behaviorDrawWay(context, wayId, index, mode, baseGraph) { draw = behaviorDraw(context); var startIndex = typeof index === 'undefined' ? way.nodes.length - 1 : 0, - start = coreNode({loc: context.graph().entity(way.nodes[startIndex]).loc}), - end = coreNode({loc: context.map().mouseCoordinates()}), - segment = coreWay({ + start = osmNode({loc: context.graph().entity(way.nodes[startIndex]).loc}), + end = osmNode({loc: context.map().mouseCoordinates()}), + segment = osmWay({ nodes: typeof index === 'undefined' ? [start.id, end.id] : [end.id, start.id], tags: _.clone(way.tags) }); @@ -165,7 +165,7 @@ export function behaviorDrawWay(context, wayId, index, mode, baseGraph) { var last = context.hasEntity(way.nodes[way.nodes.length - (isArea ? 2 : 1)]); if (last && last.loc[0] === loc[0] && last.loc[1] === loc[1]) return; - var newNode = coreNode({loc: loc}); + var newNode = osmNode({loc: loc}); context.replace( actionAddEntity(newNode), @@ -188,7 +188,7 @@ export function behaviorDrawWay(context, wayId, index, mode, baseGraph) { if (!isArea && geoEdgeEqual(edge, previousEdge)) return; - var newNode = coreNode({ loc: loc }); + var newNode = osmNode({ loc: loc }); context.perform( actionAddMidpoint({ loc: loc, edge: edge}, newNode), diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index 5f4ec963d..bc1297c4e 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -1,6 +1,6 @@ import * as d3 from 'd3'; import { d3keybinding } from '../lib/d3.keybinding.js'; -import { coreEntity } from '../core/index'; +import { osmEntity } from '../osm/index'; import { utilRebind } from '../util/rebind'; @@ -54,7 +54,7 @@ export function behaviorHover() { selection.selectAll('.hover-suppressed') .classed('hover-suppressed', false); - if (target instanceof coreEntity) { + if (target instanceof osmEntity) { var selector = '.' + target.id; if (target.type === 'relation') { diff --git a/modules/behavior/select.js b/modules/behavior/select.js index bf3b7f104..cf5c8d139 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -1,7 +1,7 @@ import * as d3 from 'd3'; import _ from 'lodash'; import { modeBrowse, modeSelect } from '../modes/index'; -import { coreEntity } from '../core/index'; +import { osmEntity } from '../osm/index'; export function behaviorSelect(context) { @@ -27,7 +27,7 @@ export function behaviorSelect(context) { lasso = d3.select('#surface .lasso').node(), mode = context.mode(); - if (!(datum instanceof coreEntity)) { + if (!(datum instanceof osmEntity)) { if (!d3.event.shiftKey && !lasso && mode.id !== 'browse') context.enter(modeBrowse(context)); diff --git a/modules/core/connection.js b/modules/core/connection.js index 69cddaf41..1a5cbd603 100644 --- a/modules/core/connection.js +++ b/modules/core/connection.js @@ -1,16 +1,13 @@ import * as d3 from 'd3'; import _ from 'lodash'; -import { utilRebind } from '../util/rebind'; -import { utilFunctor } from '../util/index'; +import osmAuth from 'osm-auth'; +import { JXON } from '../util/jxon'; import { d3geoTile } from '../lib/d3.geo.tile'; import { geoExtent } from '../geo/index'; +import { osmEntity, osmNode, osmRelation, osmWay } from '../osm/index'; import { utilDetect } from '../util/detect'; -import { coreEntity } from './entity'; -import { coreNode } from './node'; -import { coreRelation } from './relation'; -import { coreWay } from './way'; -import { JXON } from '../util/jxon'; -import osmAuth from 'osm-auth'; +import { utilRebind } from '../util/rebind'; +import { utilFunctor } from '../util/index'; export function coreConnection(useHttps) { @@ -75,8 +72,8 @@ export function coreConnection(useHttps) { connection.loadEntity = function(id, callback) { - var type = coreEntity.id.type(id), - osmID = coreEntity.id.toOSM(id); + var type = osmEntity.id.type(id), + osmID = osmEntity.id.toOSM(id); connection.loadFromURL( url + '/api/0.6/' + type + '/' + osmID + (type !== 'node' ? '/full' : ''), @@ -87,8 +84,8 @@ export function coreConnection(useHttps) { connection.loadEntityVersion = function(id, version, callback) { - var type = coreEntity.id.type(id), - osmID = coreEntity.id.toOSM(id); + var type = osmEntity.id.type(id), + osmID = osmEntity.id.toOSM(id); connection.loadFromURL( url + '/api/0.6/' + type + '/' + osmID + '/' + version, @@ -99,9 +96,9 @@ export function coreConnection(useHttps) { connection.loadMultiple = function(ids, callback) { - _.each(_.groupBy(_.uniq(ids), coreEntity.id.type), function(v, k) { + _.each(_.groupBy(_.uniq(ids), osmEntity.id.type), function(v, k) { var type = k + 's', - osmIDs = _.map(v, coreEntity.id.toOSM); + osmIDs = _.map(v, osmEntity.id.toOSM); _.each(_.chunk(osmIDs, 150), function(arr) { connection.loadFromURL( @@ -175,8 +172,8 @@ export function coreConnection(useHttps) { var parsers = { node: function nodeData(obj) { var attrs = obj.attributes; - return new coreNode({ - id: coreEntity.id.fromOSM(nodeStr, attrs.id.value), + return new osmNode({ + id: osmEntity.id.fromOSM(nodeStr, attrs.id.value), loc: getLoc(attrs), version: attrs.version.value, user: attrs.user && attrs.user.value, @@ -187,8 +184,8 @@ export function coreConnection(useHttps) { way: function wayData(obj) { var attrs = obj.attributes; - return new coreWay({ - id: coreEntity.id.fromOSM(wayStr, attrs.id.value), + return new osmWay({ + id: osmEntity.id.fromOSM(wayStr, attrs.id.value), version: attrs.version.value, user: attrs.user && attrs.user.value, tags: getTags(obj), @@ -199,8 +196,8 @@ export function coreConnection(useHttps) { relation: function relationData(obj) { var attrs = obj.attributes; - return new coreRelation({ - id: coreEntity.id.fromOSM(relationStr, attrs.id.value), + return new osmRelation({ + id: osmEntity.id.fromOSM(relationStr, attrs.id.value), version: attrs.version.value, user: attrs.user && attrs.user.value, tags: getTags(obj), diff --git a/modules/core/graph.js b/modules/core/graph.js index ebbcf8b57..27b575164 100644 --- a/modules/core/graph.js +++ b/modules/core/graph.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { utilGetPrototypeOf } from '../util/index'; import { debug } from '../index'; +import { utilGetPrototypeOf } from '../util/index'; export function coreGraph(other, mutable) { diff --git a/modules/core/history.js b/modules/core/history.js index f8e6dd3d5..a9ced8604 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -2,9 +2,9 @@ import * as d3 from 'd3'; import _ from 'lodash'; import * as Validations from '../validations/index'; import { coreDifference } from './difference'; -import { coreEntity } from './entity'; import { coreGraph } from './graph'; import { coreTree } from './tree'; +import { osmEntity } from '../osm/entity'; import { uiLoading } from '../ui/index'; import { utilSessionMutex } from '../util/index'; import { utilRebind } from '../util/rebind'; @@ -244,7 +244,7 @@ export function coreHistory(context) { _.forEach(i.graph.entities, function(entity, id) { if (entity) { - var key = coreEntity.key(entity); + var key = osmEntity.key(entity); allEntities[key] = entity; modified.push(key); } else { @@ -279,7 +279,7 @@ export function coreHistory(context) { entities: _.values(allEntities), baseEntities: _.values(baseEntities), stack: s, - nextIDs: coreEntity.id.next, + nextIDs: osmEntity.id.next, index: index }); }, @@ -289,21 +289,21 @@ export function coreHistory(context) { var h = JSON.parse(json), loadComplete = true; - coreEntity.id.next = h.nextIDs; + osmEntity.id.next = h.nextIDs; index = h.index; if (h.version === 2 || h.version === 3) { var allEntities = {}; h.entities.forEach(function(entity) { - allEntities[coreEntity.key(entity)] = coreEntity(entity); + allEntities[osmEntity.key(entity)] = osmEntity(entity); }); if (h.version === 3) { // This merges originals for changed entities into the base of // the stack even if the current stack doesn't have them (for // example when iD has been restarted in a different region) - var baseEntities = h.baseEntities.map(function(d) { return coreEntity(d); }); + var baseEntities = h.baseEntities.map(function(d) { return osmEntity(d); }); stack[0].graph.rebase(baseEntities, _.map(stack, 'graph'), true); tree.rebase(baseEntities, true); @@ -382,7 +382,7 @@ export function coreHistory(context) { for (var i in d.entities) { var entity = d.entities[i]; - entities[i] = entity === 'undefined' ? undefined : coreEntity(entity); + entities[i] = entity === 'undefined' ? undefined : osmEntity(entity); } d.graph = coreGraph(stack[0].graph).load(entities); diff --git a/modules/core/index.js b/modules/core/index.js index 47e3175c3..8e6edf3fe 100644 --- a/modules/core/index.js +++ b/modules/core/index.js @@ -1,11 +1,6 @@ export { coreConnection } from './connection'; export { coreContext } from './context'; export { coreDifference } from './difference'; -export { coreEntity } from './entity'; export { coreGraph } from './graph'; export { coreHistory } from './history'; -export { coreNode } from './node'; -export { coreRelation } from './relation'; -export { coreOneWayTags, corePavedTags, coreInterestingTag } from './tags'; export { coreTree } from './tree'; -export { coreWay } from './way'; diff --git a/modules/geo/intersection.js b/modules/geo/intersection.js index ce4401009..7d017bb4d 100644 --- a/modules/geo/intersection.js +++ b/modules/geo/intersection.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { coreWay } from '../core/index'; import { geoAngle } from './index'; +import { osmWay } from '../osm/index'; export function geoTurn(turn) { @@ -44,14 +44,14 @@ export function geoIntersection(graph, vertexId) { var splitIndex, wayA, wayB, indexA, indexB; if (isClosingNode) { splitIndex = Math.ceil(way.nodes.length / 2); // split at midpoint - wayA = coreWay({id: way.id + '-a', tags: way.tags, nodes: way.nodes.slice(0, splitIndex)}); - wayB = coreWay({id: way.id + '-b', tags: way.tags, nodes: way.nodes.slice(splitIndex)}); + wayA = osmWay({id: way.id + '-a', tags: way.tags, nodes: way.nodes.slice(0, splitIndex)}); + wayB = osmWay({id: way.id + '-b', tags: way.tags, nodes: way.nodes.slice(splitIndex)}); indexA = 1; indexB = way.nodes.length - 2; } else { splitIndex = _.indexOf(way.nodes, vertex.id, 1); // split at vertexid - wayA = coreWay({id: way.id + '-a', tags: way.tags, nodes: way.nodes.slice(0, splitIndex + 1)}); - wayB = coreWay({id: way.id + '-b', tags: way.tags, nodes: way.nodes.slice(splitIndex)}); + wayA = osmWay({id: way.id + '-a', tags: way.tags, nodes: way.nodes.slice(0, splitIndex + 1)}); + wayB = osmWay({id: way.id + '-b', tags: way.tags, nodes: way.nodes.slice(splitIndex)}); indexA = splitIndex - 1; indexB = splitIndex + 1; } diff --git a/modules/index.js b/modules/index.js index a469f7668..fadce1059 100644 --- a/modules/index.js +++ b/modules/index.js @@ -1,10 +1,11 @@ export * from './actions/index'; export * from './behavior/index'; export * from './core/index'; -export * from '../data/index.js'; +export * from '../data/index'; export * from './geo/index'; export * from './modes/index'; export * from './operations/index'; +export * from './osm/index'; export * from './presets/index'; export * from './renderer/index'; export * from './services/index'; @@ -20,13 +21,13 @@ export * from './validations/index'; export { coreConnection as Connection } from './core/connection'; export { coreContext as Context, setAreaKeys } from './core/context'; export { coreDifference as Difference } from './core/difference'; -export { coreEntity as Entity } from './core/entity'; export { coreGraph as Graph } from './core/graph'; export { coreHistory as History } from './core/history'; -export { coreNode as Node } from './core/node'; -export { coreRelation as Relation } from './core/relation'; export { coreTree as Tree } from './core/tree'; -export { coreWay as Way } from './core/way'; +export { osmEntity as Entity } from './osm/entity'; +export { osmNode as Node } from './osm/node'; +export { osmRelation as Relation } from './osm/relation'; +export { osmWay as Way } from './osm/way'; export { rendererBackgroundSource as BackgroundSource } from './renderer/background_source'; export { rendererBackground as Background } from './renderer/background'; export { rendererFeatures as Features } from './renderer/features'; diff --git a/modules/modes/add_area.js b/modules/modes/add_area.js index 67cb02f52..cf92eab68 100644 --- a/modules/modes/add_area.js +++ b/modules/modes/add_area.js @@ -5,9 +5,9 @@ import { actionAddVertex } from '../actions/index'; -import { coreNode, coreWay } from '../core/index'; import { behaviorAddWay } from '../behavior/index'; import { modeDrawArea } from './index'; +import { osmNode, osmWay } from '../osm/index'; export function modeAddArea(context) { @@ -29,8 +29,8 @@ export function modeAddArea(context) { function start(loc) { var graph = context.graph(), - node = coreNode({ loc: loc }), - way = coreWay({ tags: defaultTags }); + node = osmNode({ loc: loc }), + way = osmWay({ tags: defaultTags }); context.perform( actionAddEntity(node), @@ -45,8 +45,8 @@ export function modeAddArea(context) { function startFromWay(loc, edge) { var graph = context.graph(), - node = coreNode({ loc: loc }), - way = coreWay({ tags: defaultTags }); + node = osmNode({ loc: loc }), + way = osmWay({ tags: defaultTags }); context.perform( actionAddEntity(node), @@ -62,7 +62,7 @@ export function modeAddArea(context) { function startFromNode(node) { var graph = context.graph(), - way = coreWay({ tags: defaultTags }); + way = osmWay({ tags: defaultTags }); context.perform( actionAddEntity(way), diff --git a/modules/modes/add_line.js b/modules/modes/add_line.js index bfdca0b2f..9faf30f4b 100644 --- a/modules/modes/add_line.js +++ b/modules/modes/add_line.js @@ -5,9 +5,9 @@ import { actionAddVertex } from '../actions/index'; -import { coreNode, coreWay } from '../core/index'; import { behaviorAddWay } from '../behavior/index'; import { modeDrawLine } from './index'; +import { osmNode, osmWay } from '../osm/index'; export function modeAddLine(context) { @@ -28,8 +28,8 @@ export function modeAddLine(context) { function start(loc) { var baseGraph = context.graph(), - node = coreNode({ loc: loc }), - way = coreWay(); + node = osmNode({ loc: loc }), + way = osmWay(); context.perform( actionAddEntity(node), @@ -43,8 +43,8 @@ export function modeAddLine(context) { function startFromWay(loc, edge) { var baseGraph = context.graph(), - node = coreNode({ loc: loc }), - way = coreWay(); + node = osmNode({ loc: loc }), + way = osmWay(); context.perform( actionAddEntity(node), @@ -59,7 +59,7 @@ export function modeAddLine(context) { function startFromNode(node) { var baseGraph = context.graph(), - way = coreWay(); + way = osmWay(); context.perform( actionAddEntity(way), diff --git a/modules/modes/add_point.js b/modules/modes/add_point.js index beecd8804..90d4046f2 100644 --- a/modules/modes/add_point.js +++ b/modules/modes/add_point.js @@ -1,8 +1,8 @@ import { t } from '../util/locale'; -import { modeBrowse, modeSelect } from './index'; import { actionAddEntity } from '../actions/index'; import { behaviorDraw } from '../behavior/index'; -import { coreNode } from '../core/index'; +import { modeBrowse, modeSelect } from './index'; +import { osmNode } from '../osm/index'; export function modeAddPoint(context) { @@ -24,7 +24,7 @@ export function modeAddPoint(context) { function add(loc) { - var node = coreNode({ loc: loc }); + var node = osmNode({ loc: loc }); context.perform( actionAddEntity(node), diff --git a/modules/modes/drag_node.js b/modules/modes/drag_node.js index 02eaaa77c..0eea5533b 100644 --- a/modules/modes/drag_node.js +++ b/modules/modes/drag_node.js @@ -19,8 +19,8 @@ import { modeSelect } from './index'; -import { coreNode } from '../core/index'; import { geoChooseEdge } from '../geo/index'; +import { osmNode } from '../osm/index'; import { utilEntitySelector } from '../util/index'; @@ -87,7 +87,7 @@ export function modeDragNode(context) { wasMidpoint = entity.type === 'midpoint'; if (wasMidpoint) { var midpoint = entity; - entity = coreNode(); + entity = osmNode(); context.perform(actionAddMidpoint(midpoint, entity)); var vertex = context.surface().selectAll('.' + entity.id); diff --git a/modules/modes/select.js b/modules/modes/select.js index 0a74fba82..064f197df 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -21,9 +21,9 @@ import { } from '../geo/index'; import { - coreNode, - coreWay -} from '../core/index'; + osmNode, + osmWay +} from '../osm/index'; import { modeBrowse } from './browse'; import { modeDragNode } from './drag_node'; @@ -154,9 +154,9 @@ export function modeSelect(context, selectedIDs) { var target = d3.select(d3.event.target), datum = target.datum(); - if (datum instanceof coreWay && !target.classed('fill')) { + if (datum instanceof osmWay && !target.classed('fill')) { var choice = geoChooseEdge(context.childNodes(datum), context.mouse(), context.projection), - node = coreNode(); + node = osmNode(); var prev = datum.nodes[choice.index - 1], next = datum.nodes[choice.index]; diff --git a/modules/core/entity.js b/modules/osm/entity.js similarity index 77% rename from modules/core/entity.js rename to modules/osm/entity.js index b4452659e..5034c8f43 100644 --- a/modules/core/entity.js +++ b/modules/osm/entity.js @@ -1,57 +1,57 @@ import _ from 'lodash'; import { debug } from '../index'; -import { coreInterestingTag } from './tags'; +import { osmIsInterestingTag } from './tags'; import { dataDeprecated } from '../../data/index'; -export function coreEntity(attrs) { +export function osmEntity(attrs) { // For prototypal inheritance. - if (this instanceof coreEntity) return; + if (this instanceof osmEntity) return; // Create the appropriate subtype. if (attrs && attrs.type) { - return coreEntity[attrs.type].apply(this, arguments); + return osmEntity[attrs.type].apply(this, arguments); } else if (attrs && attrs.id) { - return coreEntity[coreEntity.id.type(attrs.id)].apply(this, arguments); + return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments); } // Initialize a generic Entity (used only in tests). - return (new coreEntity()).initialize(arguments); + return (new osmEntity()).initialize(arguments); } -coreEntity.id = function(type) { - return coreEntity.id.fromOSM(type, coreEntity.id.next[type]--); +osmEntity.id = function(type) { + return osmEntity.id.fromOSM(type, osmEntity.id.next[type]--); }; -coreEntity.id.next = { +osmEntity.id.next = { node: -1, way: -1, relation: -1 }; -coreEntity.id.fromOSM = function(type, id) { +osmEntity.id.fromOSM = function(type, id) { return type[0] + id; }; -coreEntity.id.toOSM = function(id) { +osmEntity.id.toOSM = function(id) { return id.slice(1); }; -coreEntity.id.type = function(id) { +osmEntity.id.type = function(id) { return { 'n': 'node', 'w': 'way', 'r': 'relation' }[id[0]]; }; // A function suitable for use as the second argument to d3.selection#data(). -coreEntity.key = function(entity) { +osmEntity.key = function(entity) { return entity.id + 'v' + (entity.v || 0); }; -coreEntity.prototype = { +osmEntity.prototype = { tags: {}, @@ -71,7 +71,7 @@ coreEntity.prototype = { } if (!this.id && this.type) { - this.id = coreEntity.id(this.type); + this.id = osmEntity.id(this.type); } if (!this.hasOwnProperty('visible')) { this.visible = true; @@ -94,7 +94,7 @@ coreEntity.prototype = { if (copies[this.id]) return copies[this.id]; - var copy = coreEntity(this, {id: undefined, user: undefined, version: undefined}); + var copy = osmEntity(this, {id: undefined, user: undefined, version: undefined}); copies[this.id] = copy; return copy; @@ -102,7 +102,7 @@ coreEntity.prototype = { osmId: function() { - return coreEntity.id.toOSM(this.id); + return osmEntity.id.toOSM(this.id); }, @@ -112,7 +112,7 @@ coreEntity.prototype = { update: function(attrs) { - return coreEntity(this, attrs, {v: 1 + (this.v || 0)}); + return osmEntity(this, attrs, {v: 1 + (this.v || 0)}); }, @@ -145,7 +145,7 @@ coreEntity.prototype = { hasInterestingTags: function() { - return _.keys(this.tags).some(coreInterestingTag); + return _.keys(this.tags).some(osmIsInterestingTag); }, diff --git a/modules/osm/index.js b/modules/osm/index.js new file mode 100644 index 000000000..50135ed66 --- /dev/null +++ b/modules/osm/index.js @@ -0,0 +1,10 @@ +export { osmEntity } from './entity'; +export { osmNode } from './node'; +export { osmRelation } from './relation'; +export { osmWay } from './way'; + +export { + osmOneWayTags, + osmPavedTags, + osmIsInterestingTag +} from './tags'; diff --git a/modules/core/node.js b/modules/osm/node.js similarity index 89% rename from modules/core/node.js rename to modules/osm/node.js index 0d5433e9d..c5dd104cd 100644 --- a/modules/core/node.js +++ b/modules/osm/node.js @@ -1,20 +1,20 @@ import _ from 'lodash'; -import { coreEntity } from './entity'; +import { osmEntity } from './entity'; import { geoExtent } from '../geo/index'; -export function coreNode() { - if (!(this instanceof coreNode)) { - return (new coreNode()).initialize(arguments); +export function osmNode() { + if (!(this instanceof osmNode)) { + return (new osmNode()).initialize(arguments); } else if (arguments.length) { this.initialize(arguments); } } -coreEntity.node = coreNode; +osmEntity.node = osmNode; -coreNode.prototype = Object.create(coreEntity.prototype); +osmNode.prototype = Object.create(osmEntity.prototype); -_.extend(coreNode.prototype, { +_.extend(osmNode.prototype, { type: 'node', diff --git a/modules/core/relation.js b/modules/osm/relation.js similarity index 93% rename from modules/core/relation.js rename to modules/osm/relation.js index b02e0754e..60efe35c8 100644 --- a/modules/core/relation.js +++ b/modules/osm/relation.js @@ -1,6 +1,6 @@ import * as d3 from 'd3'; import _ from 'lodash'; -import { coreEntity } from './entity'; +import { osmEntity } from './entity'; import { geoExtent, geoJoinWays, @@ -9,30 +9,30 @@ import { } from '../geo/index'; -export function coreRelation() { - if (!(this instanceof coreRelation)) { - return (new coreRelation()).initialize(arguments); +export function osmRelation() { + if (!(this instanceof osmRelation)) { + return (new osmRelation()).initialize(arguments); } else if (arguments.length) { this.initialize(arguments); } } -coreEntity.relation = coreRelation; +osmEntity.relation = osmRelation; -coreRelation.prototype = Object.create(coreEntity.prototype); +osmRelation.prototype = Object.create(osmEntity.prototype); -coreRelation.creationOrder = function(a, b) { - var aId = parseInt(coreEntity.id.toOSM(a.id), 10); - var bId = parseInt(coreEntity.id.toOSM(b.id), 10); +osmRelation.creationOrder = function(a, b) { + var aId = parseInt(osmEntity.id.toOSM(a.id), 10); + var bId = parseInt(osmEntity.id.toOSM(b.id), 10); if (aId < 0 || bId < 0) return aId - bId; return bId - aId; }; -_.extend(coreRelation.prototype, { +_.extend(osmRelation.prototype, { type: 'relation', members: [], @@ -41,7 +41,7 @@ _.extend(coreRelation.prototype, { if (copies[this.id]) return copies[this.id]; - var copy = coreEntity.prototype.copy.call(this, resolver, copies); + var copy = osmEntity.prototype.copy.call(this, resolver, copies); var members = this.members.map(function(member) { return _.extend({}, member, { id: resolver.entity(member.id).copy(resolver, copies).id }); @@ -188,7 +188,7 @@ _.extend(coreRelation.prototype, { keyAttributes: { type: member.type, role: member.role, - ref: coreEntity.id.toOSM(member.id) + ref: osmEntity.id.toOSM(member.id) } }; }), diff --git a/modules/core/tags.js b/modules/osm/tags.js similarity index 89% rename from modules/core/tags.js rename to modules/osm/tags.js index 9bea007f1..b28d45a11 100644 --- a/modules/core/tags.js +++ b/modules/osm/tags.js @@ -1,4 +1,4 @@ -export function coreInterestingTag(key) { +export function osmIsInterestingTag(key) { return key !== 'attribution' && key !== 'created_by' && key !== 'source' && @@ -8,7 +8,7 @@ export function coreInterestingTag(key) { } -export var coreOneWayTags = { +export var osmOneWayTags = { 'aerialway': { 'chair_lift': true, 'mixed_lift': true, @@ -41,7 +41,7 @@ export var coreOneWayTags = { }; -export var corePavedTags = { +export var osmPavedTags = { 'surface': { 'paved': true, 'asphalt': true, diff --git a/modules/core/way.js b/modules/osm/way.js similarity index 96% rename from modules/core/way.js rename to modules/osm/way.js index 4ca9b9dcb..aa6ef190c 100644 --- a/modules/core/way.js +++ b/modules/osm/way.js @@ -1,26 +1,26 @@ import * as d3 from 'd3'; import _ from 'lodash'; import { geoExtent, geoCross } from '../geo/index'; -import { coreEntity } from './entity'; -import { coreOneWayTags } from './tags'; -import { areaKeys } from './context'; +import { osmEntity } from './entity'; +import { osmOneWayTags } from './tags'; +import { areaKeys } from '../core/context'; -export function coreWay() { - if (!(this instanceof coreWay)) { - return (new coreWay()).initialize(arguments); +export function osmWay() { + if (!(this instanceof osmWay)) { + return (new osmWay()).initialize(arguments); } else if (arguments.length) { this.initialize(arguments); } } -coreEntity.way = coreWay; +osmEntity.way = osmWay; -coreWay.prototype = Object.create(coreEntity.prototype); +osmWay.prototype = Object.create(osmEntity.prototype); -_.extend(coreWay.prototype, { +_.extend(osmWay.prototype, { type: 'way', nodes: [], @@ -29,7 +29,7 @@ _.extend(coreWay.prototype, { if (copies[this.id]) return copies[this.id]; - var copy = coreEntity.prototype.copy.call(this, resolver, copies); + var copy = osmEntity.prototype.copy.call(this, resolver, copies); var nodes = this.nodes.map(function(id) { return resolver.entity(id).copy(resolver, copies).id; @@ -108,7 +108,7 @@ _.extend(coreWay.prototype, { // implied oneway tag.. for (var key in this.tags) { - if (key in coreOneWayTags && (this.tags[key] in coreOneWayTags[key])) + if (key in osmOneWayTags && (this.tags[key] in osmOneWayTags[key])) return true; } return false; @@ -466,7 +466,7 @@ _.extend(coreWay.prototype, { '@id': this.osmId(), '@version': this.version || 0, nd: _.map(this.nodes, function(id) { - return { keyAttributes: { ref: coreEntity.id.toOSM(id) } }; + return { keyAttributes: { ref: osmEntity.id.toOSM(id) } }; }), tag: _.map(this.tags, function(v, k) { return { keyAttributes: { k: k, v: v } }; diff --git a/modules/renderer/features.js b/modules/renderer/features.js index ad640069c..947d70205 100644 --- a/modules/renderer/features.js +++ b/modules/renderer/features.js @@ -1,7 +1,7 @@ import * as d3 from 'd3'; import _ from 'lodash'; +import { osmEntity } from '../osm/index'; import { utilRebind } from '../util/rebind'; -import { coreEntity } from '../core/index'; export function rendererFeatures(context) { @@ -293,7 +293,7 @@ export function rendererFeatures(context) { features.clearEntity = function(entity) { - delete _cache[coreEntity.key(entity)]; + delete _cache[osmEntity.key(entity)]; }; @@ -305,7 +305,7 @@ export function rendererFeatures(context) { features.getMatches = function(entity, resolver, geometry) { if (geometry === 'vertex' || geometry === 'relation') return {}; - var ent = coreEntity.key(entity); + var ent = osmEntity.key(entity); if (!_cache[ent]) { _cache[ent] = {}; } @@ -331,7 +331,7 @@ export function rendererFeatures(context) { if (entity.type === 'way') { var parents = features.getParents(entity, resolver, geometry); if (parents.length === 1 && parents[0].isMultipolygon()) { - var pkey = coreEntity.key(parents[0]); + var pkey = osmEntity.key(parents[0]); if (_cache[pkey] && _cache[pkey].matches) { matches = _.clone(_cache[pkey].matches); continue; @@ -354,7 +354,7 @@ export function rendererFeatures(context) { features.getParents = function(entity, resolver, geometry) { if (geometry === 'point') return []; - var ent = coreEntity.key(entity); + var ent = osmEntity.key(entity); if (!_cache[ent]) { _cache[ent] = {}; } diff --git a/modules/svg/areas.js b/modules/svg/areas.js index 9d39c35ee..30ba44905 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -1,8 +1,8 @@ import * as d3 from 'd3'; import _ from 'lodash'; -import { svgPath, svgTagClasses } from './index'; -import { coreEntity } from '../core/index'; import { geoIsSimpleMultipolygonOuterMember } from '../geo/index'; +import { osmEntity } from '../osm/index'; +import { svgPath, svgTagClasses } from './index'; export function svgAreas(projection, context) { @@ -76,7 +76,7 @@ export function svgAreas(projection, context) { var clipPaths = context.surface().selectAll('defs').selectAll('.clipPath') .filter(filter) - .data(data.clip, coreEntity.key); + .data(data.clip, osmEntity.key); clipPaths.exit() .remove(); @@ -108,7 +108,7 @@ export function svgAreas(projection, context) { var paths = areagroup .selectAll('path') .filter(filter) - .data(function(layer) { return data[layer]; }, coreEntity.key); + .data(function(layer) { return data[layer]; }, osmEntity.key); // Remove exiting areas first, so they aren't included in the `fills` // array used for sorting below (https://github.com/openstreetmap/iD/issues/1903). diff --git a/modules/svg/labels.js b/modules/svg/labels.js index 89d156de3..30e8719ff 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -1,9 +1,9 @@ import * as d3 from 'd3'; import _ from 'lodash'; import rbush from 'rbush'; -import { utilDisplayName, utilGetStyle } from '../util/index'; -import { coreEntity } from '../core/index'; import { geoPathLength } from '../geo/index'; +import { osmEntity } from '../osm/index'; +import { utilDisplayName, utilGetStyle } from '../util/index'; export function svgLabels(projection, context) { @@ -104,7 +104,7 @@ export function svgLabels(projection, context) { function drawLinePaths(selection, entities, filter, classes, labels) { var paths = selection.selectAll('path') .filter(filter) - .data(entities, coreEntity.key); + .data(entities, osmEntity.key); paths.exit() .remove(); @@ -122,7 +122,7 @@ export function svgLabels(projection, context) { function drawLineLabels(selection, entities, filter, classes, labels) { var texts = selection.selectAll('text.' + classes) .filter(filter) - .data(entities, coreEntity.key); + .data(entities, osmEntity.key); texts.exit() .remove(); @@ -137,7 +137,7 @@ export function svgLabels(projection, context) { texts.selectAll('.textpath') .filter(filter) - .data(entities, coreEntity.key) + .data(entities, osmEntity.key) .attr('startOffset', '50%') .attr('xlink:href', function(d) { return '#labelpath-' + d.id; }) .text(utilDisplayName); @@ -147,7 +147,7 @@ export function svgLabels(projection, context) { function drawPointLabels(selection, entities, filter, classes, labels) { var texts = selection.selectAll('text.' + classes) .filter(filter) - .data(entities, coreEntity.key); + .data(entities, osmEntity.key); texts.exit() .remove(); @@ -184,7 +184,7 @@ export function svgLabels(projection, context) { function drawAreaIcons(selection, entities, filter, classes, labels) { var icons = selection.selectAll('use') .filter(filter) - .data(entities, coreEntity.key); + .data(entities, osmEntity.key); icons.exit() .remove(); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index 09d8e4803..35ff1952a 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -7,9 +7,9 @@ import { svgTagClasses } from './index'; -import { utilDetect } from '../util/detect'; -import { coreEntity } from '../core/index'; import { geoSimpleMultipolygonOuterMember } from '../geo/index'; +import { osmEntity } from '../osm/index'; +import { utilDetect } from '../util/detect'; export function svgLines(projection) { @@ -90,14 +90,14 @@ export function svgLines(projection) { .filter(filter) .data( function() { return pathdata[this.parentNode.__data__] || []; }, - coreEntity.key + osmEntity.key ); lines.exit() .remove(); // Optimization: call simple TagClasses only on enter selection. This - // works because coreEntity.key is defined to include the entity v attribute. + // works because osmEntity.key is defined to include the entity v attribute. lines.enter() .append('path') .attr('class', function(d) { return 'way line ' + this.parentNode.__data__ + ' ' + d.id; }) diff --git a/modules/svg/points.js b/modules/svg/points.js index 150f8d609..a47de75f6 100644 --- a/modules/svg/points.js +++ b/modules/svg/points.js @@ -1,6 +1,6 @@ import _ from 'lodash'; +import { osmEntity } from '../osm/index'; import { svgPointTransform, svgTagClasses } from './index'; -import { coreEntity } from '../core/index'; export function svgPoints(projection, context) { @@ -29,7 +29,7 @@ export function svgPoints(projection, context) { var groups = layer.selectAll('g.point') .filter(filter) - .data(points, coreEntity.key); + .data(points, osmEntity.key); groups.exit() .remove(); diff --git a/modules/svg/tag_classes.js b/modules/svg/tag_classes.js index ab501a5e7..f359dd9e7 100644 --- a/modules/svg/tag_classes.js +++ b/modules/svg/tag_classes.js @@ -1,5 +1,5 @@ import * as d3 from 'd3'; -import { corePavedTags } from '../core/tags'; +import { osmPavedTags } from '../osm/tags'; export function svgTagClasses() { @@ -89,8 +89,8 @@ export function svgTagClasses() { var paved = (t.highway !== 'track'); for (k in t) { v = t[k]; - if (k in corePavedTags) { - paved = !!corePavedTags[k][v]; + if (k in osmPavedTags) { + paved = !!osmPavedTags[k][v]; break; } } diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 9038446fd..df8643786 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -1,5 +1,5 @@ import * as d3 from 'd3'; -import { coreEntity } from '../core/index'; +import { osmEntity } from '../osm/index'; import { svgPointTransform } from './index'; @@ -102,7 +102,7 @@ export function svgVertices(projection, context) { z = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2); var groups = selection - .data(vertices, coreEntity.key); + .data(vertices, osmEntity.key); groups.exit() .remove(); diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index a906e6f5e..e9f37dd55 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -1,9 +1,9 @@ import * as d3 from 'd3'; import * as sexagesimal from 'sexagesimal'; import { t } from '../util/locale'; -import { coreEntity } from '../core/index'; import { geoExtent, geoChooseEdge } from '../geo/index'; import { modeSelect } from '../modes/index'; +import { osmEntity } from '../osm/index'; import { svgIcon } from '../svg/index'; import { utilDisplayName, utilEntityOrMemberSelector } from '../util/index'; @@ -134,7 +134,7 @@ export function uiFeatureList(context) { // https://github.com/openstreetmap/iD/issues/1890 if (d.osm_type && d.osm_id) { result.push({ - id: coreEntity.id.fromOSM(d.osm_type, d.osm_id), + id: osmEntity.id.fromOSM(d.osm_type, d.osm_id), geometry: d.osm_type === 'relation' ? 'relation' : d.osm_type === 'way' ? 'line' : 'point', type: d.type !== 'yes' ? (d.type.charAt(0).toUpperCase() + d.type.slice(1)).replace('_', ' ') : (d.class.charAt(0).toUpperCase() + d.class.slice(1)).replace('_', ' '), diff --git a/modules/ui/fields/check.js b/modules/ui/fields/check.js index e2baefa71..618481627 100644 --- a/modules/ui/fields/check.js +++ b/modules/ui/fields/check.js @@ -1,7 +1,7 @@ import * as d3 from 'd3'; import { utilRebind } from '../../util/rebind'; import { t } from '../../util/locale'; -import { coreOneWayTags } from '../../core/index'; +import { osmOneWayTags } from '../../osm/index'; export { uiFieldCheck as uiFieldDefaultcheck }; @@ -36,7 +36,7 @@ export function uiFieldCheck(field) { // where implied oneway tag exists (e.g. `junction=roundabout`) #2220, #1841 if (field.id === 'oneway') { for (var key in entity.tags) { - if (key in coreOneWayTags && (entity.tags[key] in coreOneWayTags[key])) { + if (key in osmOneWayTags && (entity.tags[key] in osmOneWayTags[key])) { texts[0] = t('presets.fields.oneway_yes.options.undefined'); break; } diff --git a/modules/ui/fields/restrictions.js b/modules/ui/fields/restrictions.js index 872b72038..35ecdc6bc 100644 --- a/modules/ui/fields/restrictions.js +++ b/modules/ui/fields/restrictions.js @@ -2,7 +2,7 @@ import * as d3 from 'd3'; import { t } from '../../util/locale'; import { behaviorHover } from '../../behavior/index'; -import { coreEntity } from '../../core/index'; +import { osmEntity } from '../../osm/index'; import { actionRestrictTurn, @@ -128,7 +128,7 @@ export function uiFieldRestrictions(field, context) { function click() { var datum = d3.event.target.__data__; - if (datum instanceof coreEntity) { + if (datum instanceof osmEntity) { fromNodeID = intersection.adjacentNodeId(datum.id); render(); } else if (datum instanceof geoTurn) { diff --git a/modules/ui/intro/intro.js b/modules/ui/intro/intro.js index b1c8eb4e9..6c759d3b6 100644 --- a/modules/ui/intro/intro.js +++ b/modules/ui/intro/intro.js @@ -1,7 +1,8 @@ import * as d3 from 'd3'; import { t } from '../../util/locale'; -import { coreEntity, coreGraph } from '../../core/index'; +import { coreGraph } from '../../core/graph'; import { modeBrowse } from '../../modes/index'; +import { osmEntity } from '../../osm/entity'; import { d3curtain } from '../../util/curtain'; import { default as introGraphRaw } from '../../../data/intro_graph.json'; @@ -76,7 +77,7 @@ export function uiIntro(context) { var introGraph = {}; for (var key in introGraphRaw) { - introGraph[key] = coreEntity(introGraphRaw[key]); + introGraph[key] = osmEntity(introGraphRaw[key]); var name = localizedName(key); if (name) { introGraph[key].tags.name = name; diff --git a/modules/ui/raw_member_editor.js b/modules/ui/raw_member_editor.js index 2a99b28d9..a706213db 100644 --- a/modules/ui/raw_member_editor.js +++ b/modules/ui/raw_member_editor.js @@ -2,8 +2,8 @@ import * as d3 from 'd3'; import { d3combobox } from '../lib/d3.combobox.js'; import { t } from '../util/locale'; import { actionChangeMember, actionDeleteMember } from '../actions/index'; -import { coreEntity } from '../core/index'; import { modeBrowse, modeSelect } from '../modes/index'; +import { osmEntity } from '../osm/index'; import { svgIcon } from '../svg/index'; import { uiDisclosure } from './disclosure'; import { utilDisplayName } from '../util/index'; @@ -81,8 +81,8 @@ export function uiRawMemberEditor(context) { var items = list.selectAll('li') .data(memberships, function(d) { - return coreEntity.key(d.relation) + ',' + d.index + ',' + - (d.member ? coreEntity.key(d.member) : 'incomplete'); + return osmEntity.key(d.relation) + ',' + d.index + ',' + + (d.member ? osmEntity.key(d.member) : 'incomplete'); }); items.exit() diff --git a/modules/ui/raw_membership_editor.js b/modules/ui/raw_membership_editor.js index 41e8179b9..21368dd48 100644 --- a/modules/ui/raw_membership_editor.js +++ b/modules/ui/raw_membership_editor.js @@ -10,8 +10,8 @@ import { actionDeleteMember } from '../actions/index'; -import { coreEntity, coreRelation } from '../core/index'; import { modeSelect } from '../modes/index'; +import { osmEntity, osmRelation } from '../osm/index'; import { svgIcon } from '../svg/index'; import { uiDisclosure } from './disclosure'; import { utilDisplayName } from '../util/index'; @@ -46,7 +46,7 @@ export function uiRawMembershipEditor(context) { ); } else { - var relation = coreRelation(); + var relation = osmRelation(); context.perform( actionAddEntity(relation), actionAddMember(relation.id, { id: id, type: context.entity(id).type, role: role }), @@ -92,7 +92,7 @@ export function uiRawMembershipEditor(context) { }); result.sort(function(a, b) { - return coreRelation.creationOrder(a.relation, b.relation); + return osmRelation.creationOrder(a.relation, b.relation); }); // Dedupe identical names by appending relation id - see #2891 @@ -151,7 +151,7 @@ export function uiRawMembershipEditor(context) { var items = list.selectAll('li.member-row-normal') .data(memberships, function(d) { - return coreEntity.key(d.relation) + ',' + d.index; + return osmEntity.key(d.relation) + ',' + d.index; }); items.exit() diff --git a/modules/ui/selection_list.js b/modules/ui/selection_list.js index 8ddc522b5..aaede3035 100644 --- a/modules/ui/selection_list.js +++ b/modules/ui/selection_list.js @@ -1,8 +1,8 @@ import * as d3 from 'd3'; import { t } from '../util/locale'; -import { coreEntity } from '../core/index'; -import { svgIcon } from '../svg/index'; import { modeSelect } from '../modes/index'; +import { osmEntity } from '../osm/index'; +import { svgIcon } from '../svg/index'; import { utilDisplayName } from '../util/index'; @@ -52,7 +52,7 @@ export function uiSelectionList(context, selectedIDs) { .filter(function(entity) { return entity; }); var items = list.selectAll('.feature-list-item') - .data(entities, coreEntity.key); + .data(entities, osmEntity.key); items.exit() .remove(); diff --git a/package.json b/package.json index 30b77c1c9..ab40abbf6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iD", - "version": "2.0.0-alpha.1", + "version": "2.0.0-alpha.2", "description": "A friendly editor for OpenStreetMap", "main": "iD.js", "directories": { diff --git a/test/index.html b/test/index.html index bd026e4be..642ed64df 100644 --- a/test/index.html +++ b/test/index.html @@ -28,8 +28,6 @@ - - @@ -67,14 +65,11 @@ + - - - - @@ -88,6 +83,11 @@ + + + + + diff --git a/test/rendering.html b/test/rendering.html index a1bcb00b6..7573a3a0d 100644 --- a/test/rendering.html +++ b/test/rendering.html @@ -15,12 +15,13 @@ - - - - + + + + +
diff --git a/test/spec/actions/merge_remote_changes.js b/test/spec/actions/merge_remote_changes.js index ee4c97ffb..edf90ef58 100644 --- a/test/spec/actions/merge_remote_changes.js +++ b/test/spec/actions/merge_remote_changes.js @@ -1,5 +1,3 @@ -/* global locale: true */ -/* eslint no-console: 0 */ describe('iD.actionMergeRemoteChanges', function () { var base = iD.Graph([ iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}), @@ -55,36 +53,8 @@ describe('iD.actionMergeRemoteChanges', function () { nodes: ['s1', 's2', 's3', 's4', 's1'], version: '1', tags: {foo: 'foo_new', area: 'yes'} - }), + }); - saved, error; - - // setup mock locale object.. - beforeEach(function() { - saved = locale; - error = console.error; - console.error = function () {}; - locale = { - _current: 'en', - en: { - 'merge_remote_changes': { - 'annotation': 'Merged remote changes from server.', - 'conflict': { - 'deleted': 'This object has been deleted by {user}.', - 'location': 'This object was moved by both you and {user}.', - 'nodelist': 'Nodes were changed by both you and {user}.', - 'memberlist': 'Relation members were changed by both you and {user}.', - 'tags': 'You changed the {tag} tag to \"{local}\" and {user} changed it to \"{remote}\".' - } - } - } - }; - }); - - afterEach(function() { - locale = saved; - console.error = error; - }); function makeGraph(entities) { return _.reduce(entities, function(graph, entity) { @@ -92,6 +62,7 @@ describe('iD.actionMergeRemoteChanges', function () { }, iD.Graph(base)); } + describe('non-destuctive merging', function () { describe('tags', function() { it('doesn\'t merge tags if conflict (local change, remote change)', function () { diff --git a/test/spec/id.js b/test/spec/core/context.js similarity index 99% rename from test/spec/id.js rename to test/spec/core/context.js index 098a5d61e..e5b7fb3a0 100644 --- a/test/spec/id.js +++ b/test/spec/core/context.js @@ -1,4 +1,4 @@ -describe('iD', function() { +describe('iD.Context', function() { var assets = { 'iD/img/loader.gif': '/assets/iD/img/loader-b66184b5c4afbccc25f.gif' }; diff --git a/test/spec/core/entity.js b/test/spec/osm/entity.js similarity index 100% rename from test/spec/core/entity.js rename to test/spec/osm/entity.js diff --git a/test/spec/core/node.js b/test/spec/osm/node.js similarity index 100% rename from test/spec/core/node.js rename to test/spec/osm/node.js diff --git a/test/spec/core/relation.js b/test/spec/osm/relation.js similarity index 100% rename from test/spec/core/relation.js rename to test/spec/osm/relation.js diff --git a/test/spec/core/way.js b/test/spec/osm/way.js similarity index 100% rename from test/spec/core/way.js rename to test/spec/osm/way.js diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index a8ba6cea7..816232d37 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -1,6 +1,6 @@ /* globals chai:false */ -// iD.debug = true; +iD.debug = true; mocha.setup({ ui: 'bdd',