From e229c913319eadbe5b2a41b7ad052e3bc6b53ac8 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 23 Oct 2012 23:32:36 -0400 Subject: [PATCH] Continue. Speed improvements, simplicity --- js/iD/Node.js | 10 +++------ js/iD/renderer/Map.js | 46 ++++++++++++++-------------------------- js/iD/renderer/NodeUI.js | 2 +- js/iD/renderer/WayUI.js | 12 ++--------- 4 files changed, 22 insertions(+), 48 deletions(-) diff --git a/js/iD/Node.js b/js/iD/Node.js index c2bb6dbb6..68200f47e 100644 --- a/js/iD/Node.js +++ b/js/iD/Node.js @@ -9,19 +9,15 @@ iD.Node = function(connection, id, lat, lon, tags, loaded) { this.entity = new iD.Entity(); this.lat = lat; this.lon = lon; + // TODO: keep or trash this custom + this[0] = lon; + this[1] = lat; this.tags = tags; this.loaded = (loaded === undefined) ? true : loaded; - this.project(); this.modified = this.id < 0; }; 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)); - }, - toGeoJSON: function() { return { type: 'Feature', diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 8cce6df10..28c02c063 100755 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -16,6 +16,14 @@ iD.renderer.Map = function(obj) { this.projection = d3.geo.mercator() .scale(512).translate([512, 512]); + + // List of co-ordinates + var proj = this.projection; + + this.linegen = d3.svg.line() + .x(function(d) { return proj(d)[0]; }) + .y(function(d) { return proj(d)[1]; }); + this.zoombehavior = d3.behavior.zoom() .translate(this.projection.translate()) .scale(this.projection.scale()) @@ -67,14 +75,6 @@ iD.renderer.Map.prototype = { tiles: {}, // index of tile objects tilebaseURL: 'http://ecn.t0.tiles.virtualearth.net/tiles/a$quadkey.jpeg?g=587&mkt=en-gb&n=z', // Bing imagery URL - dragging: false, // current drag state - dragged: false, // was most recent click a drag? - dragtime: NaN, // timestamp of mouseup (compared to stop resulting click from firing) - dragconnect: null, // event listener for endDrag - - containerx: 0, // screen co-ordinates of container - containery: 0, // | - height: NaN, // size of map object in pixels width: NaN, // | @@ -209,21 +209,18 @@ iD.renderer.Map.prototype = { // ------------- // Zoom handling - zoomIn: function() { - // summary: Zoom in by one level (unless maximum reached). + // summary: Zoom in by one level (unless maximum reached). return this.setZoom(this.zoom + 1); }, zoomOut: function() { - // summary: Zoom out by one level (unless minimum reached). - this.setZoom(this.zoom - 1); - this.download(); - return this; + // summary: Zoom out by one level (unless minimum reached). + return this.setZoom(this.zoom - 1); }, setZoom: function(zoom) { - // summary: Redraw the map at a new zoom level. + // summary: Redraw the map at a new zoom level. this.projection.scale(256 * Math.pow(2, zoom - 1)); this.zoombehavior.scale(this.projection.scale()); this.updateUIs(true, true); @@ -231,21 +228,16 @@ iD.renderer.Map.prototype = { return this; }, - _setScaleFactor: function() { - // summary: Calculate the scaling factor for this zoom level. - this.zoomfactor = this.MASTERSCALE/Math.pow(2, 13 - this.zoom); - }, - // ---------------------- // Elastic band redrawing clearElastic: function() { - // summary: Remove the elastic band used to draw new ways. + // summary: Remove the elastic band used to draw new ways. this.elastic.clear(); }, drawElastic: function(x1,y1,x2,y2) { - // summary: Draw the elastic band (for new ways) between two points. + // summary: Draw the elastic band (for new ways) between two points. this.elastic.clear(); // **** Next line is SVG-specific this.elastic.rawNode.setAttribute("pointer-events","none"); @@ -282,9 +274,7 @@ iD.renderer.Map.prototype = { }, redraw: function() { - var projection = this.projection, - width = this.width, - height = this.height; + var projection = this.projection; if (d3.event) { projection @@ -349,9 +339,5 @@ iD.renderer.Map.prototype = { // summary: Handle a click on an empty area of the map. if (this.dragged && e.timeStamp==this.dragtime) { return; } this.controller.entityMouseEvent(e,null); - }, - - // Turn event co-ordinates into map co-ordinates - mouseX: function(e) { return e.clientX - this.marginBox.l - this.containerx; }, - mouseY: function(e) { return e.clientY - this.marginBox.t - this.containery; } + } }; diff --git a/js/iD/renderer/NodeUI.js b/js/iD/renderer/NodeUI.js index 2311f688b..af861fa17 100755 --- a/js/iD/renderer/NodeUI.js +++ b/js/iD/renderer/NodeUI.js @@ -16,7 +16,7 @@ iD.renderer.NodeUI.prototype = { var x = Math.floor(this.map.lon2coord(this.node.lon)); var y = Math.floor(this.map.latp2coord(this.node.latp)); var tags = this.getEnhancedTags(); - + var im = this.map.layers[0].hit.append("image") .attr('class', 'poi') .attr('x', x) diff --git a/js/iD/renderer/WayUI.js b/js/iD/renderer/WayUI.js index 694924227..6a4793c00 100755 --- a/js/iD/renderer/WayUI.js +++ b/js/iD/renderer/WayUI.js @@ -32,21 +32,13 @@ iD.renderer.WayUI.prototype = { // Create tags and calculate styleList var tags = this.getEnhancedTags(); - // List of co-ordinates - var proj = this.map.projection; - - var line = d3.svg.line() - .x(function(d) { return proj([d.lon, d.lat])[0]; }) - .y(function(d) { return proj([d.lon, d.lat])[1]; }) - .interpolate("linear"); - if (!this.casing) { this.casing = this.map.layers[0].casing.append("path") .data([way.nodes]) .attr('class', 'casing'); } - this.casing.attr("d", line); + this.casing.attr("d", this.map.linegen); if (!this.stroke) { this.stroke = this.map.layers[0].stroke.append("path") @@ -54,7 +46,7 @@ iD.renderer.WayUI.prototype = { .attr('class', 'stroke'); } - this.stroke.attr("d", line); + this.stroke.attr("d", this.map.linegen); return this; },