diff --git a/js/iD/Connection.js b/js/iD/Connection.js index a414207f2..698f1f19c 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -24,7 +24,7 @@ declare("iD.Connection", null, { constructor:function(apiURL) { // summary: The data store, including methods to fetch data from (and, eventually, save data to) - // an OSM API server. + // an OSM API server. this.nodes={}; this.ways={}; this.relations={}; @@ -37,12 +37,12 @@ declare("iD.Connection", null, { _assign:function(obj) { // summary: Save an entity to the data store. switch (obj.entityType) { - case "node": this.nodes[obj.id]=obj; break; - case "way": this.ways[obj.id]=obj; break; - case "relation": this.relations[obj.id]=obj; break; + case "node": this.nodes[obj.id]=obj; break; + case "way": this.ways[obj.id]=obj; break; + case "relation": this.relations[obj.id]=obj; break; } }, - + getNode:function(id) { // summary: Return a node by id. return this.nodes[id]; // iD.Node diff --git a/js/iD/Relation.js b/js/iD/Relation.js index 7f2d23254..2c4c7b2f0 100644 --- a/js/iD/Relation.js +++ b/js/iD/Relation.js @@ -1,43 +1,20 @@ // iD/Relation.js +if (typeof iD === 'undefined') iD = {}; -define(['dojo/_base/declare','dojo/_base/array','dojo/_base/lang', - 'iD/Entity','iD/actions/AddNodeToWayAction','iD/actions/MoveNodeAction' - ], function(declare,array,lang){ +iD.Relation = function(conn, id, members, tags, loaded) { + this.entityType = 'relation'; + this.connection = conn; + this.id = id; + this.members = members; + this.tags = tags; + this.modified = this.id < 0; + this.loaded = (loaded === undefined) ? true : loaded; + _.each(members, _.bind(function(member) { + member.entity.addParent(this); + }, this)); +}; -// ---------------------------------------------------------------------- -// Relation class - -declare("iD.Relation", [iD.Entity], { - members:null, - entityType:"relation", - - constructor:function(conn,id,members,tags,loaded) { - // summary: An OSM relation. - this.connection=conn; - this.id=Number(id); - this.members=members; - this.tags=tags; - this.modified=this.id<0; - this.loaded=(loaded===undefined) ? true : loaded; - _.each(members, _.bind(function(member) { - member.entity.addParent(this); - }, this)); - } -}); - -// ---------------------------------------------------------------------- -// RelationMember class - -declare("iD.RelationMember", [], { - entity:null, - role:"", - constructor:function(entity,role) { - // summary: An object containing both the entity that is in the relation, and its role. - this.entity=entity; - this.role=role; - } -}); - -// ---------------------------------------------------------------------- -// End of module -}); +iD.RelationMember = function(entity, role) { + this.entity = entity; + this.role = role; +}; diff --git a/js/iD/Way.js b/js/iD/Way.js index a72d4fea9..fa1251ca0 100644 --- a/js/iD/Way.js +++ b/js/iD/Way.js @@ -17,11 +17,6 @@ iD.Way = function(conn, id, nodes, tags, loaded) { }; iD.Way.prototype = { - length:function() { - // summary: Return the number of nodes in the way. - return this.nodes.length; - }, - isClosed:function() { // summary: Is this a closed way (first and last nodes the same)? return this.nodes[this.nodes.length-1]==this.nodes[0]; // Boolean @@ -37,22 +32,8 @@ iD.Way.prototype = { return false; // Boolean }, - getNode:function(index) { - // summary: Return the node at the given position. - return this.nodes[index]; // iD.Node - }, - getFirstNode:function() { - // summary: Return the first node in the way. - return this.nodes[0]; // iD.Node - }, - getLastNode:function() { - // summary: Return the last node in the way. - return this.nodes[this.nodes.length-1]; // iD.Node - }, - // --------------------- // Bounding-box handling - within:function(left,right,top,bottom) { if (!this.edgel || (this.edgel 0 && this.getNode(index - 1)==node) return; - if (index < this.nodes.length - 1 && this.getNode(index)==node) return; + if (index > 0 && this.nodes[index - 1]==node) return; + if (index < this.nodes.length - 1 && this.nodes[index]==node) return; performAction(new iD.actions.AddNodeToWayAction(this, node, this.nodes, index, false)); }, @@ -110,8 +91,8 @@ iD.Way.prototype = { snapped; for (var i = 0; i < this.nodes.length - 1; i++) { - var node1 = this.getNode(i); - var node2 = this.getNode(i+1); + var node1 = this.nodes[i]; + var node2 = this.nodes[i + 1]; var directDist = this._pythagoras(node1, node2); var viaNewDist = this._pythagoras(node1, newNode) + this._pythagoras(node2, newNode); @@ -129,7 +110,11 @@ iD.Way.prototype = { return newIndex; // int }, - _pythagoras:function(node1, node2) { return (Math.sqrt(Math.pow(node1.lon-node2.lon,2)+Math.pow(node1.latp-node2.latp,2))); }, + _pythagoras:function(node1, node2) { + return (Math.sqrt(Math.pow(node1.lon-node2.lon,2) + + Math.pow(node1.latp-node2.latp,2))); + }, + _calculateSnappedPoint:function(node1, node2, newNode) { var w = node2.lon - node1.lon; var h = node2.latp - node1.latp; diff --git a/test/index.html b/test/index.html index 3b786e9d4..6892f0453 100644 --- a/test/index.html +++ b/test/index.html @@ -13,12 +13,14 @@ + +