diff --git a/index.html b/index.html index 1cd411c53..7ccffdd23 100755 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@
- + diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 24e99d7ee..ea3111e64 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -40,10 +40,12 @@ iD.Connection = function(apiURL) { function getOrCreate(id, type) { // summary: Return an entity if it exists: if not, create an empty one with the given id, and return that. if (type === 'node') { - if (!entities[id]) assign(new iD.Node(connection, id, NaN, NaN, {}, false)); + if (!entities[id]) assign(new iD.Node(id, NaN, NaN, {}, false)); return entities[id]; } else if (type === 'way') { - if (!entities[id]) assign(new iD.Way(connection, id, [], {}, false)); + if (!entities[id]) { + assign(new iD.Way(connection, id, [], {}, false)); + } return entities[id]; } else if (type === 'relation') { if (!relations[id]) assign(new iD.Relation(connection, id, [], {}, false)); @@ -53,7 +55,7 @@ iD.Connection = function(apiURL) { function doCreateNode(tags, lat, lon, perform) { // summary: Create a new node and save it in the data store, using an undo stack. - var node = new iD.Node(connection, nextNode--, lat, lon, tags, true); + var node = new iD.Node(nextNode--, lat, lon, tags, true); perform(new iD.actions.CreateEntityAction(node, assign)); return node; // iD.Node } @@ -72,11 +74,11 @@ iD.Connection = function(apiURL) { return relation; } - function getObjectsByBbox(extent) { + function intersects(extent) { // summary: Find all drawable entities that are within a given bounding box. // Each one is an array of entities. return d3.values(entities).filter(function(e, id) { - return e.within(extent); + return e.intersects(extent); }); } @@ -94,14 +96,6 @@ iD.Connection = function(apiURL) { return function(item) { return item.nodeName === n; }; } - function attributeObject(obj) { - var o = {}; - for (var i = 0; i < obj.attributes.length; i++) { - o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue; - } - return o; - } - function getAttribute(obj, name) { return obj.attributes[name].nodeValue; } @@ -155,24 +149,21 @@ iD.Connection = function(apiURL) { for (var i = 0; i < dom.childNodes[0].childNodes.length; i++) { var obj = dom.childNodes[0].childNodes[i], attrib; if (obj.nodeName === 'node') { - attrib = attributeObject(obj); - var node = new iD.Node(connection, - +attrib.id, - +attrib.lat, - +attrib.lon, + var node = new iD.Node( + +getAttribute(obj, 'id'), + +getAttribute(obj, 'lat'), + +getAttribute(obj, 'lon'), getTags(obj)); assign(node); } else if (obj.nodeName === 'way') { - attrib = attributeObject(obj); var way = new iD.Way(connection, - attrib.id, + getAttribute(obj, 'id'), getNodes(obj, connection), getTags(obj)); assign(way); } else if (obj.nodeName === 'relation') { - attrib = attributeObject(obj); var relation = new iD.Relation(connection, - attrib.id, + getAttribute(obj, 'id'), getMembers(obj, connection), getTags(obj)); assign(relation); @@ -187,7 +178,7 @@ iD.Connection = function(apiURL) { connection.relations = relations; connection.loadFromAPI = loadFromAPI; connection.loadFromURL = loadFromURL; - connection.getObjectsByBbox = getObjectsByBbox; + connection.intersects = intersects; connection.doCreateNode = doCreateNode; connection.doCreateWay = doCreateWay; connection.doCreateRelation = doCreateRelation; diff --git a/js/iD/Node.js b/js/iD/Node.js index 0216addc3..7986e6055 100644 --- a/js/iD/Node.js +++ b/js/iD/Node.js @@ -1,10 +1,9 @@ if (typeof iD === 'undefined') iD = {}; // [Node](http://wiki.openstreetmap.org/wiki/Node) -iD.Node = function(connection, id, lat, lon, tags, loaded) { +iD.Node = function(id, lat, lon, tags, loaded) { // summary: An OSM node. this.entityType = 'node'; - this.connection = connection; this.id = id; this._id = iD.Util.id(); this.entity = iD.Entity(); @@ -30,7 +29,7 @@ iD.Node.prototype = { }; }, - within: function(extent) { + intersects: function(extent) { return (this.lon >= extent[0][0]) && (this.lon <= extent[1][0]) && (this.lat <= extent[0][1]) && diff --git a/js/iD/Way.js b/js/iD/Way.js index c7b1ccb4b..b350b5b7f 100644 --- a/js/iD/Way.js +++ b/js/iD/Way.js @@ -65,23 +65,26 @@ iD.Way.prototype = { }, bounds: function() { + // TODO: cache return d3.geo.bounds(this.toGeoJSON()); }, // --------------------- // Bounding-box handling - within: function(left,right,top,bottom) { + intersects: function(extent) { + // No-node ways are inside of nothing. + if (!this.nodes.length) return false; var bounds = this.bounds(); - // TODO invert and just return - if (!this.extent.west || - (this.extent.west < left && this.extent.east < left ) || - (this.extent.west > right && this.extent.east > right ) || - (this.extent.south < bottom && this.extent.north < bottom) || - (this.extent.south > top && this.extent.south > top)) { - return false; - } else { - return true; - } + // left + return !( + // the bottom right is to the top-left + // of the top-left + bounds[1][0] < extent[0][0] && + bounds[1][1] < extent[0][1] || + // The top left is to the bottom-right + // of the top-left + bounds[0][0] > extent[1][0] && + bounds[0][1] > extent[1][1]); }, // -------------- diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 889bbb269..0e140cb6c 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -207,7 +207,7 @@ iD.Map = function(obj) { } function drawVector() { - var all = connection.all(); + var all = connection.intersects(extent()); var ways = all.filter(function(a) { return a.entityType === 'way' && !a.isClosed();