Continue. Speed improvements, simplicity

This commit is contained in:
Tom MacWright
2012-10-23 23:32:36 -04:00
parent 30f9e08a87
commit e229c91331
4 changed files with 22 additions and 48 deletions
+3 -7
View File
@@ -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',
+16 -30
View File
@@ -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; }
}
};
+1 -1
View File
@@ -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)
+2 -10
View File
@@ -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;
},