Merge branch 'master' of github.com:systemed/iD

This commit is contained in:
Saman Bemel-Benrud
2013-01-02 14:30:36 -05:00
17 changed files with 108 additions and 85 deletions

View File

@@ -123,7 +123,7 @@ iD.behavior.drag = function () {
return mousedown.call(target, target.__data__);
}
}
}
};
}
selection.on("mousedown.drag" + selector, delegate)

View File

@@ -13,9 +13,9 @@ iD.Connection = function() {
return url + '/api/0.6/map?bbox=' + [b[0][0],b[1][1],b[1][0],b[0][1]];
}
function bboxFromAPI(box, callback) {
function bboxFromAPI(box, tile, callback) {
loadFromURL(bboxUrl(box), function(err, parsed) {
loadedTiles[box] = true;
loadedTiles[tile.toString()] = true;
callback(err, parsed);
});
}
@@ -138,24 +138,14 @@ iD.Connection = function() {
});
}
connection.userUrl = function(username) {
return url + "/user/" + username;
};
function tileAlreadyLoaded(c) { return !loadedTiles[c.toString()]; }
function tileAtZoom(t, distance) {
var power = Math.pow(2, distance);
return [
Math.floor(t[0] * power),
Math.floor(t[1] * power),
t[2] + distance];
}
function abortRequest(i) { i.abort(); }
function tileAlreadyLoaded(c) {
if (loadedTiles[c]) return false;
for (var i = 0; i < 4; i++) {
if (loadedTiles[tileAtZoom(c, -i)]) return false;
}
return true;
function loadTile(e) {
bboxFromAPI(e.box, e.tile, function(err, g) {
event.load(err, g);
});
}
function loadTiles(projection) {
@@ -175,26 +165,27 @@ iD.Connection = function() {
function apiExtentBox(c) {
var x = (c[0] * ts) - tile_origin[0];
var y = (c[1] * ts) - tile_origin[1];
return [
projection.invert([x, y]),
projection.invert([x + ts, y + ts])];
return {
box: [
projection.invert([x, y]),
projection.invert([x + ts, y + ts])],
tile: c
};
}
inflight.map(function(i) {
i.abort();
});
inflight.map(abortRequest);
inflight = [];
tiles
.map(apiExtentBox)
.filter(tileAlreadyLoaded)
.forEach(function(e) {
bboxFromAPI(e, function(err, g) {
event.load(err, g);
});
});
.map(apiExtentBox)
.forEach(loadTile);
}
connection.userUrl = function(username) {
return url + "/user/" + username;
};
connection.url = function(_) {
if (!arguments.length) return url;
url = _;

View File

@@ -170,7 +170,7 @@ window.iD = function(container) {
.attr('class', 'inspector-wrap fillL')
.style('display', 'none');
var about = container.append('div')
var about = container.append('div');
about.append('ul')
.attr('id','about')
@@ -226,7 +226,7 @@ window.iD = function(container) {
if (!hash.hadHash) {
map.zoom(20)
.center([-77.02405, 38.87952]);
.center([-77.02271,38.90085]);
}
d3.select('.user-container').call(iD.userpanel(connection)

View File

@@ -12,6 +12,7 @@ iD.modes.AddArea = function() {
controller = mode.controller;
map.dblclickEnable(false)
.hoverEnable(false)
.hint('Click on the map to start drawing an area, like a park, lake, or building.');
map.surface.on('click.addarea', function() {
@@ -47,7 +48,8 @@ iD.modes.AddArea = function() {
mode.exit = function() {
window.setTimeout(function() {
mode.map.dblclickEnable(true);
mode.map.dblclickEnable(true)
.hoverEnable(true);
}, 1000);
mode.map.hint(false);
mode.map.surface.on('click.addarea', null);

View File

@@ -13,6 +13,8 @@ iD.modes.AddLine = function() {
controller = mode.controller;
map.dblclickEnable(false)
.hoverEnable(false)
.hoverEnable(false)
.hint('Click on the map to start drawing an road, path, or route.');
map.surface.on('click.addline', function() {
@@ -68,7 +70,7 @@ iD.modes.AddLine = function() {
};
mode.exit = function() {
mode.map.dblclickEnable(true);
mode.map.dblclickEnable(true).hoverEnable(true);
mode.map.hint(false);
mode.map.surface.on('click.addline', null);
mode.map.keybinding().on('⎋.addline', null);

View File

@@ -10,6 +10,8 @@ iD.modes.AddPoint = function() {
history = mode.history,
controller = mode.controller;
map.hoverEnable(false);
map.hint('Click on the map to add a point.');
map.surface.on('click.addpoint', function() {
@@ -28,6 +30,7 @@ iD.modes.AddPoint = function() {
};
mode.exit = function() {
map.hoverEnable(true);
mode.map.hint(false);
mode.map.surface.on('click.addpoint', null);
mode.map.keybinding().on('⎋.addpoint', null);

View File

@@ -16,6 +16,7 @@ iD.modes.DrawArea = function(wayId) {
node = iD.Node({loc: map.mouseCoordinates()});
map.dblclickEnable(false)
.hoverEnable(false)
.fastEnable(false);
map.hint('Click on the map to add points to your area. Finish the ' +
'area by clicking on your first point');
@@ -125,7 +126,8 @@ iD.modes.DrawArea = function(wayId) {
mode.exit = function() {
mode.map.hint(false);
mode.map.fastEnable(true);
mode.map.fastEnable(true)
.hoverEnable(true);
mode.map.surface
.on('mousemove.drawarea', null)

View File

@@ -16,6 +16,7 @@ iD.modes.DrawLine = function(wayId, direction) {
map.dblclickEnable(false)
.fastEnable(false)
.hoverEnable(false)
.hint('Click to add more points to the line. ' +
'Click on other lines to connect to them, and double-click to ' +
'end the line.');
@@ -121,7 +122,8 @@ iD.modes.DrawLine = function(wayId, direction) {
mode.exit = function() {
mode.map.hint(false);
mode.map.fastEnable(true);
mode.map.fastEnable(true)
.hoverEnable(true);
mode.map.surface
.on('mousemove.drawline', null)

View File

@@ -12,6 +12,7 @@ iD.Map = function() {
.scaleExtent([1024, 256 * Math.pow(2, 24)])
.on('zoom', zoomPan),
dblclickEnabled = true,
hoverEnabled = true,
fastEnabled = true,
notice,
background = iD.Background()
@@ -20,7 +21,6 @@ iD.Map = function() {
class_casing = iD.Style.styleClasses('way line casing'),
class_area = iD.Style.styleClasses('way area'),
transformProp = iD.util.prefixCSSProperty('Transform'),
support3d = iD.util.support3d(),
supersurface, surface, defs, tilegroup, r, g, alength;
function map() {
@@ -141,16 +141,16 @@ iD.Map = function() {
function drawVertices(vertices, parentStructure, filter) {
function shared(d) { return parentStructure[d.id] > 1; }
var vertices = g.hit.selectAll('circle.vertex')
var circles = g.hit.selectAll('circle.vertex')
.filter(filter)
.data(vertices, key);
vertices.exit().remove();
circles.exit().remove();
vertices.enter().insert('circle', ':first-child')
circles.enter().insert('circle', ':first-child')
.attr('class', 'node vertex');
vertices.attr('transform', function(entity) {
circles.attr('transform', function(entity) {
var p = projection(entity.loc);
return 'translate(' + [~~p[0], ~~p[1]] +
')';
@@ -158,7 +158,7 @@ iD.Map = function() {
.classed('shared', shared)
.classed('hover', classHover);
vertices.transition().duration(50).attr('r', function(d) {
circles.transition().duration(50).attr('r', function(d) {
return d.id === hover ? 8: 4;
});
}
@@ -209,22 +209,22 @@ iD.Map = function() {
}
function drawPoints(points, filter) {
var points = g.hit.selectAll('g.point')
var groups = g.hit.selectAll('g.point')
.filter(filter)
.data(points, key);
points.exit().remove();
var group = points.enter().append('g')
groups.exit().remove();
var group = groups.enter().append('g')
.attr('class', 'node point');
group.append('circle')
.attr({ r: 10, cx: 8, cy: 8 });
group.append('image')
.attr({ width: 16, height: 16 });
points.attr('transform', function(d) {
groups.attr('transform', function(d) {
var pt = projection(d.loc);
return 'translate(' + [~~pt[0], ~~pt[1]] + ') translate(-8, -8)';
});
points.classed('hover', classHover);
points.select('image').attr('xlink:href', iD.Style.pointImage);
groups.classed('hover', classHover);
groups.select('image').attr('xlink:href', iD.Style.pointImage);
}
function drawStrokes(ways, filter) {
@@ -266,6 +266,7 @@ iD.Map = function() {
}
function hoverIn() {
if (!hoverEnabled) return;
var datum = d3.select(d3.event.target).datum();
if (datum instanceof iD.Entity) {
hover = datum.id;
@@ -275,7 +276,7 @@ iD.Map = function() {
}
function hoverOut() {
if (hover) {
if (hoverEnabled && hover) {
var oldHover = hover;
hover = null;
redraw([oldHover]);
@@ -299,17 +300,10 @@ iD.Map = function() {
if (!translateStart) translateStart = d3.event.translate.slice();
var a = d3.event.translate,
b = translateStart;
if (support3d) {
tilegroup.style(transformProp,
'translate3d(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px, 0px)');
surface.style(transformProp,
'translate3d(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px, 0px)');
} else {
tilegroup.style(transformProp,
'translate(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px)');
surface.style(transformProp,
'translate(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px)');
}
tilegroup.style(transformProp,
'translate(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px)');
surface.style(transformProp,
'translate(' + ~~(a[0] - b[0]) + 'px,' + ~~(a[1] - b[1]) + 'px)');
} else {
redraw();
translateStart = null;
@@ -358,6 +352,12 @@ iD.Map = function() {
return map;
};
map.hoverEnable = function(_) {
if (!arguments.length) return hoverEnabled;
hoverEnabled = _;
return map;
};
map.fastEnable = function(_) {
if (!arguments.length) return fastEnabled;
fastEnabled = _;

View File

@@ -24,15 +24,15 @@ iD.commit = function() {
comment: d3.select('textarea.changeset-comment').node().value
});
});
savebutton.append('span').attr('class','icon save icon-pre-text')
savebutton.append('span').attr('class','label').text('Save')
savebutton.append('span').attr('class','icon save icon-pre-text');
savebutton.append('span').attr('class','label').text('Save');
var cancelbutton = buttonwrap.append('button')
.attr('class', 'cancel wide')
.on('click.cancel', function() {
event.cancel();
});
cancelbutton.append('span').attr('class','icon close icon-pre-text')
cancelbutton.append('span').attr('class','label').text('Cancel')
cancelbutton.append('span').attr('class','icon close icon-pre-text');
cancelbutton.append('span').attr('class','label').text('Cancel');
var section = body.selectAll('div.commit-section')
.data(['modified', 'deleted', 'created'].filter(function(d) {

View File

@@ -6,8 +6,9 @@ iD.geocoder = function() {
function keydown() {
if (d3.event.keyCode !== 13) return;
d3.event.preventDefault();
d3.json('http://api.tiles.mapbox.com/v3/mapbox/geocode/' +
d3.json('http://api.tiles.mapbox.com/v3/openstreetmap.map-hn253zqn/geocode/' +
encodeURIComponent(this.value) + '.json', function(err, resp) {
if (err) return hide();
hide();
map.center([resp.results[0][0].lon, resp.results[0][0].lat]);
});

View File

@@ -3,7 +3,7 @@ iD.notice = function(selection) {
notice = {};
notice.message = function(_) {
selection.attr('class','inner')
selection.attr('class','inner');
if (!arguments.length) return _;
if (!message && _) {
selection

View File

@@ -23,7 +23,7 @@ iD.tagReference = function(selection) {
.attr('class','modal-section');
referenceBody
.append('h5')
.text('Description')
.text('Description');
referenceBody
.append('p')
.text(g('description'));
@@ -36,4 +36,4 @@ iD.tagReference = function(selection) {
return d.title + ' on wiki.osm.org';
});
});
};
};

View File

@@ -7,7 +7,7 @@ iD.userpanel = function(connection) {
if (connection.authenticated()) {
selection.style('display', 'block');
connection.userDetails(function(user_details) {
selection.append('span').attr('class','icon avatar icon-pre-text')
selection.append('span').attr('class','icon avatar icon-pre-text');
selection.append('span')
.append('a')
.attr('href', connection.url() + '/user/' +

View File

@@ -45,7 +45,9 @@ iD.util.tagText = function(entity) {
iD.util.stringQs = function(str) {
return str.split('&').reduce(function(obj, pair){
var parts = pair.split('=');
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);
if (parts.length === 2) {
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);
}
return obj;
}, {});
};
@@ -90,20 +92,6 @@ iD.util.prefixCSSProperty = function(property) {
return false;
};
iD.util.support3d = function() {
// test for translate3d support. Based on https://gist.github.com/3794226 by lorenzopolidori and webinista
var transformProp = iD.util.prefixCSSProperty('Transform');
var el = document.createElement('div'),
has3d = false;
document.body.insertBefore(el, null);
if (el.style[transformProp] !== undefined) {
el.style[transformProp] = 'translate3d(1px,1px,1px)';
has3d = window.getComputedStyle(el).getPropertyValue(transformProp);
}
document.body.removeChild(el);
return (has3d && has3d.length>0 && has3d!=="none");
};
iD.util.geo = {};
iD.util.geo.roundCoords = function(c) {

View File

@@ -69,6 +69,14 @@ describe('iD.Entity', function () {
});
});
describe("#osmId", function () {
it("returns a numeric osm id", function () {
expect(iD.Entity({id: 'w1234'}).osmId()).to.eql(1234);
expect(iD.Entity({id: 'n1234'}).osmId()).to.eql(1234);
expect(iD.Entity({id: 'r1234'}).osmId()).to.eql(1234);
});
});
describe("#created", function () {
it("returns falsy by default", function () {
expect(iD.Entity({id: 'w1234'}).created()).not.to.be.ok;

View File

@@ -6,6 +6,24 @@ describe('Util', function() {
expect(iD.util.trueObj([])).to.eql({});
});
it('#tagText', function() {
expect(iD.util.tagText({})).to.eql('');
expect(iD.util.tagText({tags:{foo:'bar'}})).to.eql('foo: bar');
expect(iD.util.tagText({tags:{foo:'bar',two:'three'}})).to.eql('foo: bar\ntwo: three');
});
it('#stringQs', function() {
expect(iD.util.stringQs('foo=bar')).to.eql({foo: 'bar'});
expect(iD.util.stringQs('foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.util.stringQs('')).to.eql({});
});
it('#qsString', function() {
expect(iD.util.qsString({ foo: 'bar' })).to.eql('foo=bar');
expect(iD.util.qsString({ foo: 'bar', one: 2 })).to.eql('foo=bar&one=2');
expect(iD.util.qsString({})).to.eql('');
});
it('#friendlyName', function() {
expect(iD.util.friendlyName({ tags: { name: 'hi' }})).to.equal('hi');
expect(iD.util.friendlyName({ tags: { highway: 'Route 5' }})).to.equal('Route 5');
@@ -13,6 +31,12 @@ describe('Util', function() {
});
describe('geo', function() {
describe('#roundCoords', function() {
expect(iD.util.geo.roundCoords([0.1, 1])).to.eql([0, 1]);
expect(iD.util.geo.roundCoords([0, 1])).to.eql([0, 1]);
expect(iD.util.geo.roundCoords([0, 1.1])).to.eql([0, 1]);
});
describe('#interp', function() {
it('interpolates halfway', function() {
var a = [0, 0],