From 9343719737c26b9ea6081bab003db5c267cb4e78 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 16 Oct 2012 18:08:12 -0400 Subject: [PATCH] More cleanup --- js/iD/Node.js | 5 ++-- js/iD/Way.js | 6 +++-- js/iD/renderer/EntityUI.js | 2 +- js/iD/renderer/Map.js | 41 +++++++++++++++++-------------- js/iD/renderer/NodeUI.js | 11 ++++----- js/iD/styleparser/StyleChooser.js | 2 +- js/iD/styleparser/StyleList.js | 15 ++++++----- 7 files changed, 44 insertions(+), 38 deletions(-) diff --git a/js/iD/Node.js b/js/iD/Node.js index 3590a7ff9..9eb255229 100644 --- a/js/iD/Node.js +++ b/js/iD/Node.js @@ -17,12 +17,13 @@ iD.Node = function(conn, id, lat, lon, tags, loaded) { iD.Node.prototype = { project: function() { // summary: Update the projected latitude value (this.latp) from the latitude (this.lat). - this.latp = 180/Math.PI * Math.log(Math.tan(Math.PI/4+this.lat*(Math.PI/180)/2)); + this.latp = 180/Math.PI * + Math.log(Math.tan(Math.PI/4+this.lat*(Math.PI/180)/2)); }, latp2lat: function(a) { // summary: Get a latitude from a projected latitude. // returns: Latitude. - return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2); // Number + return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2); }, within: function(left, right, top, bottom) { diff --git a/js/iD/Way.js b/js/iD/Way.js index f4a22bc2e..5ed0c82dc 100644 --- a/js/iD/Way.js +++ b/js/iD/Way.js @@ -6,6 +6,7 @@ iD.Way = function(conn, id, nodes, tags, loaded) { this.entityType = 'way'; this.id = id; this.nodes = nodes || []; + this.deleted = false; this.entity = new iD.Entity(); this.tags = tags || {}; this.loaded = (loaded === undefined) ? true : loaded; @@ -33,11 +34,12 @@ iD.Way.prototype = { // --------------------- // Bounding-box handling within:function(left,right,top,bottom) { + // TODO invert and just return if (!this.edgel || (this.edgelright && this.edger>right ) || (this.edgebtop && this.edgeb>top ) || this.deleted) { + (this.edgeb>top && this.edgeb>top )) { return false; } else { return true; @@ -47,7 +49,7 @@ iD.Way.prototype = { _calculateBbox:function() { this.edgel = 999999; this.edger = -999999; this.edgeb = 999999; this.edget = -999999; - for (var i in this.nodes) { this.expandBbox(this.nodes[i]); } + _.each(this.nodes, _.bind(function(n) { this.expandBbox(n); }, this)); }, expandBbox:function(node) { diff --git a/js/iD/renderer/EntityUI.js b/js/iD/renderer/EntityUI.js index a89aa23d2..48e62a890 100755 --- a/js/iD/renderer/EntityUI.js +++ b/js/iD/renderer/EntityUI.js @@ -50,7 +50,7 @@ declare("iD.renderer.EntityUI", null, { }, refreshStyleList:function(tags) { // summary: Calculate the list of styles that apply to this UI at this zoom level. - if (!this.styleList || !this.styleList.isValidAt(this.map.scale)) { + if (!this.styleList || !this.styleList.isValidAt(this.map.scale)) { this.styleList=this.map.ruleset.getStyles(this.entity,tags,this.map.scale); } this.layer=this.styleList.layerOverride(); diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 879b8c659..344ff553f 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -53,7 +53,7 @@ declare("iD.renderer.Map", null, { edgeb: NaN, // | mapheight: NaN, // size of map object in pixels mapwidth: NaN, // | - + layers: null, // array-like object of Groups, one for each OSM layer minlayer: -5, // minimum OSM layer supported maxlayer: 5, // maximum OSM layer supported @@ -61,7 +61,7 @@ declare("iD.renderer.Map", null, { elastic: null, // Group for drawing elastic band ruleset: null, // map style - + constructor:function(obj) { // summary: The main map display, containing the individual sprites (UIs) for each entity. // obj: Object An object containing .lat, .lon, .scale, .div (the name of the
to be used), @@ -111,7 +111,7 @@ declare("iD.renderer.Map", null, { this.surface.connect("onmousedown", lang.hitch(this,"_mouseEvent")); this.surface.connect("onmouseup", lang.hitch(this,"_mouseEvent")); }, - + setController:function(controller) { // summary: Set the controller that will handle events on the map (e.g. mouse clicks). this.controller=controller; @@ -170,21 +170,26 @@ declare("iD.renderer.Map", null, { sub.sublayer=sublayer; return sub; // dojox.gfx.Group }, - + createUI:function(entity,stateClasses) { // summary: Create a UI (sprite) for an entity, assigning any specified state classes // (temporary attributes such as ':hover' or ':selected') - var id=entity.id; - switch (entity.entityType) { - case 'node': - if (!this.nodeuis[id]) { this.nodeuis[id]=new iD.renderer.NodeUI(entity,this,stateClasses); } - else { this.nodeuis[id].setStateClasses(stateClasses).redraw(); } - return this.nodeuis[id]; // iD.renderer.EntityUI - case 'way': - if (!this.wayuis[id]) { this.wayuis[id]=new iD.renderer.WayUI(entity,this,stateClasses); } - else { this.wayuis[id].setStateClasses(stateClasses).redraw(); } - return this.wayuis[id]; // iD.renderer.EntityUI - } + var id = entity.id; + if (entity.entityType === 'node') { + if (!this.nodeuis[id]) { + this.nodeuis[id] = new iD.renderer.NodeUI(entity,this,stateClasses); + } else { + this.nodeuis[id].setStateClasses(stateClasses).redraw(); + } + return this.nodeuis[id]; // iD.renderer.EntityUI + } else if (entity.entityType === 'way') { + if (!this.wayuis[id]) { + this.wayuis[id] = new iD.renderer.WayUI(entity,this,stateClasses); + } else { + this.wayuis[id].setStateClasses(stateClasses).redraw(); + } + return this.wayuis[id]; // iD.renderer.EntityUI + } }, getUI:function(entity) { @@ -195,7 +200,7 @@ declare("iD.renderer.Map", null, { } return null; }, - + refreshUI:function(entity) { // summary: Redraw the UI for an entity. switch (entity.entityType) { @@ -203,7 +208,7 @@ declare("iD.renderer.Map", null, { case 'way': if (this.wayuis[entity.id] ) { this.wayuis[entity.id].redraw(); } break; } }, - + deleteUI:function(entity) { // summary: Delete the UI for an entity. switch (entity.entityType) { @@ -211,7 +216,7 @@ declare("iD.renderer.Map", null, { case 'way': if (this.wayuis[entity.id] ) { this.wayuis[entity.id].removeSprites(); delete this.wayuis[entity.id]; } break; } }, - + download:function() { // summary: Ask the connection to download data for the current viewport. this.conn.loadFromAPI(this.edgel, this.edger, this.edget, this.edgeb); diff --git a/js/iD/renderer/NodeUI.js b/js/iD/renderer/NodeUI.js index e0251c95e..2baae13e5 100755 --- a/js/iD/renderer/NodeUI.js +++ b/js/iD/renderer/NodeUI.js @@ -20,19 +20,19 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { }, redraw:function() { // summary: Draw the object (mostly icons) and add hitzone sprites. - var node=this.entity; + var node = this.entity; this.removeSprites(); // Tags, position and styleList - var x=this.map.lon2coord(this.entity.lon); - var y=this.map.latp2coord(this.entity.latp); - var tags=this.getEnhancedTags(); + var x= this.map.lon2coord(this.entity.lon); + var y= this.map.latp2coord(this.entity.latp); + var tags = this.getEnhancedTags(); this.refreshStyleList(tags); // Iterate through each subpart, drawing any styles on that layer var drawn=false; var s,p,t,w,h; - for (i=0; i