From 0a0b1749dc8219d728a71b8805c90bba898c7443 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 16 Oct 2012 17:38:51 -0400 Subject: [PATCH] Move towards compatible with existing view/edit code. This throws no errors, but does not yet draw. --- js/iD/Connection.js | 47 +++++++++++---------------------- js/iD/Controller.js | 2 -- js/iD/Entity.js | 10 +++---- js/iD/Node.js | 3 ++- js/iD/Relation.js | 3 +-- js/iD/Way.js | 27 ++++++++++--------- js/iD/actions/UndoableAction.js | 4 +-- js/iD/renderer/NodeUI.js | 10 +++---- js/iD/renderer/WayUI.js | 40 +++++++++++++++------------- js/iD/styleparser/Rule.js | 4 +-- js/iD/styleparser/RuleChain.js | 4 +-- js/iD/styleparser/StyleList.js | 15 +++++------ test/spec/Way.js | 8 ++++++ 13 files changed, 84 insertions(+), 93 deletions(-) diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 698f1f19c..53633c72e 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -1,5 +1,3 @@ -// iD/Connection.js - define(["dojo/_base/xhr","dojo/_base/lang","dojox/xml/DomParser","dojo/_base/array",'dojo/_base/declare', "iD/Entity","iD/Node","iD/Way","iD/Relation","iD/actions/CreateEntityAction"], function(xhr,lang,DomParser,array,declare,Entity){ @@ -90,19 +88,6 @@ declare("iD.Connection", null, { return relation; }, - markClean:function() { - // summary: Mark the connection as clean (i.e. there's no new data to be saved). - this.modified=false; - }, - markDirty:function() { - // summary: Mark the connection as dirty (i.e. there's data to be saved). - this.modified=true; - }, - isDirty:function() { - // summary: Is the connection dirty? - return this.modified; - }, - getObjectsByBbox:function(left,right,top,bottom) { // summary: Find all drawable entities that are within a given bounding box. // returns: Object An object with four properties: .poisInside, .poisOutside, .waysInside, .waysOutside. @@ -149,7 +134,7 @@ declare("iD.Connection", null, { updatePOIs:function(nodelist) { // summary: Update the list of POIs (nodes not in ways) from a supplied array of nodes. for (var i in nodelist) { - if (nodelist[i].hasParentWays()) { + if (nodelist[i].entity.hasParentWays()) { this.pois.remove(nodelist[i]); } else { this.pois.put(nodelist[i],true); @@ -197,28 +182,28 @@ declare("iD.Connection", null, { switch(obj.nodeName) { case "node": - var node = new iD.Node(this, - getAttribute(obj,'id'), - getAttribute(obj,'lat'), - getAttribute(obj,'lon'), - getTags(obj)); - this._assign(node); + var node = new iD.Node(this, + +getAttribute(obj,'id'), + +getAttribute(obj,'lat'), + +getAttribute(obj,'lon'), + getTags(obj)); + this._assign(node); nodelist.push(node); break; case "way": - var way = new iD.Way(this, - getAttribute(obj,'id'), - getNodes(obj,this), - getTags(obj)); + var way = new iD.Way(this, + getAttribute(obj,'id'), + getNodes(obj,this), + getTags(obj)); this._assign(way); break; case "relation": - var relation = new iD.Relation(this, - getAttribute(obj,'id'), - getMembers(obj,this), - getTags(obj)); + var relation = new iD.Relation(this, + getAttribute(obj,'id'), + getMembers(obj,this), + getTags(obj)); this._assign(relation); break; } @@ -228,8 +213,6 @@ declare("iD.Connection", null, { if (this.callback) { this.callback(); } // Private functions to parse DOM created from XML file - - function filterNodeName(n) { return function(item) { return item.nodeName === n; diff --git a/js/iD/Controller.js b/js/iD/Controller.js index 26d60e5ba..399662ea2 100755 --- a/js/iD/Controller.js +++ b/js/iD/Controller.js @@ -1,5 +1,3 @@ -// iD/Controller.js - define(['dojo/_base/declare','dojo/on','iD/actions/UndoStack'], function(declare,on){ // ---------------------------------------------------------------------- diff --git a/js/iD/Entity.js b/js/iD/Entity.js index d90625fca..c4d3ccdc1 100755 --- a/js/iD/Entity.js +++ b/js/iD/Entity.js @@ -1,6 +1,5 @@ -// iD/Entity.js -// Entity classes for iD if (typeof iD === 'undefined') iD = {}; + iD.Entity = function() { this.tags = {}; this.parents = new Hashtable(); @@ -8,10 +7,9 @@ iD.Entity = function() { this.id = NaN; this.loaded = false; this.entityType = ''; - this.parents = null; - this.modified = false; - this.deleted = false; - this.MAINKEYS = ['highway','amenity','railway','waterway']; + this.modified = false; + this.deleted = false; + this.MAINKEYS = ['highway','amenity','railway','waterway']; }; iD.Entity.prototype = { diff --git a/js/iD/Node.js b/js/iD/Node.js index 946ad0bcd..3590a7ff9 100644 --- a/js/iD/Node.js +++ b/js/iD/Node.js @@ -1,10 +1,11 @@ -// iD/Node.js if (typeof iD === 'undefined') iD = {}; + iD.Node = function(conn, id, lat, lon, tags, loaded) { // summary: An OSM node. this.entityType = 'node'; this.connection = conn; this.id = id; + this.entity = new iD.Entity(); this.lat = lat; this.lon = lon; this.tags = tags; diff --git a/js/iD/Relation.js b/js/iD/Relation.js index 2c4c7b2f0..08f83e280 100644 --- a/js/iD/Relation.js +++ b/js/iD/Relation.js @@ -1,4 +1,3 @@ -// iD/Relation.js if (typeof iD === 'undefined') iD = {}; iD.Relation = function(conn, id, members, tags, loaded) { @@ -10,7 +9,7 @@ iD.Relation = function(conn, id, members, tags, loaded) { this.modified = this.id < 0; this.loaded = (loaded === undefined) ? true : loaded; _.each(members, _.bind(function(member) { - member.entity.addParent(this); + member.entity.entity.addParent(this); }, this)); }; diff --git a/js/iD/Way.js b/js/iD/Way.js index fa1251ca0..f4a22bc2e 100644 --- a/js/iD/Way.js +++ b/js/iD/Way.js @@ -1,17 +1,17 @@ -// iD/Way.js - if (typeof iD === 'undefined') iD = {}; + iD.Way = function(conn, id, nodes, tags, loaded) { // summary: An OSM way. this.connection = conn; this.entityType = 'way'; this.id = id; this.nodes = nodes || []; + this.entity = new iD.Entity(); this.tags = tags || {}; this.loaded = (loaded === undefined) ? true : loaded; this.modified = this.id < 0; _.each(nodes, _.bind(function(node) { - node.addParent(this); + node.entity.addParent(this); }, this)); this._calculateBbox(); }; @@ -19,16 +19,14 @@ iD.Way = function(conn, id, nodes, tags, loaded) { iD.Way.prototype = { 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 + return this.nodes[this.nodes.length - 1] === this.nodes[0]; // Boolean }, - isType:function(_type) { + isType:function(type) { // summary: Is this a 'way' (always true), an 'area' (closed) or a 'line' (unclosed)? - switch (_type) { - case 'way': return true; - case 'area': return this.isClosed; - case 'line': return !(this.isClosed); - } + if (type === 'way') return true; + if (type === 'area') return this.isClosed(); + if (type === 'line') return !(this.isClosed()); return false; // Boolean }, @@ -39,8 +37,11 @@ iD.Way.prototype = { (this.edgelright && this.edger>right ) || (this.edgebtop && this.edgeb>top ) || this.deleted) { return false; } + (this.edgeb>top && this.edgeb>top ) || this.deleted) { + return false; + } else { return true; + } }, _calculateBbox:function() { @@ -87,8 +88,8 @@ iD.Way.prototype = { // isSnap: Boolean Should the node position be snapped to be exactly on the segment? // returns: The index at which the node was inserted. var closestProportion = 1, - newIndex = 0, - snapped; + newIndex = 0, + snapped; for (var i = 0; i < this.nodes.length - 1; i++) { var node1 = this.nodes[i]; diff --git a/js/iD/actions/UndoableAction.js b/js/iD/actions/UndoableAction.js index ae0dd3edc..003c7557a 100644 --- a/js/iD/actions/UndoableAction.js +++ b/js/iD/actions/UndoableAction.js @@ -66,14 +66,14 @@ declare("iD.actions.UndoableEntityAction", [iD.actions.UndoableAction], { // summary: Mark a change to the entity ('dirtying' it). if (!this.initialised) this.init(); if (!this.wasDirty) this.entity._markDirty(); - if (!this.connectionWasDirty) this.entity.connection.markDirty(); + if (!this.connectionWasDirty) this.entity.connection.modified = true; }, markClean:function() { // summary: If the entity was clean before, revert the dirty flag to that state. if (!this.initialised) this.init(); if (!this.wasDirty) this.entity._markClean(); - if (!this.connectionWasDirty) this.entity.connection.markClean(); + if (!this.connectionWasDirty) this.entity.connection.modified = false; }, init:function() { diff --git a/js/iD/renderer/NodeUI.js b/js/iD/renderer/NodeUI.js index 4f3e36c75..e0251c95e 100755 --- a/js/iD/renderer/NodeUI.js +++ b/js/iD/renderer/NodeUI.js @@ -14,7 +14,7 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { }, getEnhancedTags:function() { var tags=this.inherited(arguments); - if (!this.entity.hasParentWays()) { tags[':poi']='yes'; } + if (!this.entity.entity.hasParentWays()) { tags[':poi']='yes'; } // add junction and dupe return tags; }, @@ -44,9 +44,9 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { // Draw icon var shape; switch (p.icon_image) { - case 'square': shape=this.targetGroup('stroke',p.sublayer).createRect({ x:x-w/2, y:y-h/2, width:w, height:h }); break; - case 'circle': shape=this.targetGroup('stroke',p.sublayer).createCircle({ cx:x, cy:y, r:w }); break; - default: shape=this.targetGroup('stroke',p.sublayer).createImage({ width:w, height:h, x: x-w/2, y: y-h/2, src:p.icon_image }); break; + case 'square':shape=this.targetGroup('stroke',p.sublayer).createRect({ x:x-w/2, y:y-h/2, width:w, height:h }); break; + case 'circle':shape=this.targetGroup('stroke',p.sublayer).createCircle({ cx:x, cy:y, r:w }); break; + default:shape=this.targetGroup('stroke',p.sublayer).createImage({ width:w, height:h, x: x-w/2, y: y-h/2, src:p.icon_image }); break; } switch (p.icon_image) { case 'square': @@ -71,7 +71,7 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { hit.connect("onmouseenter", lang.hitch(this,this.entityMouseEvent)); hit.connect("onmouseleave", lang.hitch(this,this.entityMouseEvent)); } - }, + } }); diff --git a/js/iD/renderer/WayUI.js b/js/iD/renderer/WayUI.js index ac26301c2..74327f04b 100755 --- a/js/iD/renderer/WayUI.js +++ b/js/iD/renderer/WayUI.js @@ -28,11 +28,12 @@ declare("iD.renderer.WayUI", [iD.renderer.EntityUI], { }, redraw:function() { // summary: Draw the object and add hitzone sprites. - var way=this.entity; - var maxwidth=4; - var i; + var way = this.entity, + maxwidth=4, + i; + this.removeSprites(); - if (way.length()==0) { return; } + if (!way.nodes.length) { return; } // Create tags and calculate styleList var tags=this.getEnhancedTags(); @@ -40,14 +41,17 @@ declare("iD.renderer.WayUI", [iD.renderer.EntityUI], { // List of co-ordinates var coords=[]; - for (i=0; i1) { sc.push('junction'); } + if (node.entity.parentWays().length>1) { sc.push('junction'); } this.map.createUI(node,sc); } }, - + entityMouseEvent:function(event) { this.inherited(arguments); - }, + } }); // ---------------------------------------------------------------------- diff --git a/js/iD/styleparser/Rule.js b/js/iD/styleparser/Rule.js index 4fc9a73e1..f09e2cbb6 100755 --- a/js/iD/styleparser/Rule.js +++ b/js/iD/styleparser/Rule.js @@ -29,13 +29,13 @@ declare("iD.styleparser.Rule", null, { test:function(entity,tags,zoom) { // summary: Evaluate the Rule on the given entity, tags and zoom level. // returns: true if the Rule passes, false if the conditions aren't fulfilled. - if (this.subject!='' && !entity.isType(this.subject)) { return false; } + if (this.subject !== '' && !entity.entity.isType(this.subject)) { return false; } if (zoomthis.maxZoom) { return false; } var v=true; var i=0; var isAnd=this.isAnd; array.forEach(this.conditions, function(condition) { var r=condition.test(tags); - if (i==0) { v=r; } + if (i === 0) { v=r; } else if (isAnd) { v=v && r; } else { v = v || r; } i++; diff --git a/js/iD/styleparser/RuleChain.js b/js/iD/styleparser/RuleChain.js index f8130ff59..8e21a7d01 100755 --- a/js/iD/styleparser/RuleChain.js +++ b/js/iD/styleparser/RuleChain.js @@ -69,10 +69,10 @@ declare("iD.styleparser.RuleChain", null, { if (!r.test(entity, tags, zoom)) { return false; } if (pos==0) { return true; } - var o=entity.parentObjects(); + var o = entity.entity.parentObjects(); for (var i=0; i