mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-05 19:01:30 +00:00
Inject history dependency in map
This commit is contained in:
@@ -100,7 +100,7 @@ iD.modes.AddRoad = {
|
||||
if (t.data() && t.data()[0] && t.data()[0].type === 'node') {
|
||||
// continue an existing way
|
||||
var id = t.data()[0].id;
|
||||
var parents = this.map.history.graph().parents(id);
|
||||
var parents = this.map.history().graph().parents(id);
|
||||
if (parents.length && parents[0].nodes[0] === id) {
|
||||
way = parents[0];
|
||||
direction = 'backward';
|
||||
@@ -115,7 +115,7 @@ iD.modes.AddRoad = {
|
||||
var index = iD.modes.chooseIndex(t.data()[0], d3.mouse(surface.node()), this.map);
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
var connectedWay = this.map.history.graph().entity(t.data()[0].id);
|
||||
var connectedWay = this.map.history().graph().entity(t.data()[0].id);
|
||||
connectedWay.nodes.splice(index, 0, node.id);
|
||||
this.map.perform(iD.actions.addWayNode(connectedWay, node));
|
||||
} else {
|
||||
@@ -160,7 +160,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
nextnode = iD.modes._node([NaN, NaN]);
|
||||
var nextnode_id = nextnode.id;
|
||||
|
||||
var way = this.map.history.graph().entity(way_id),
|
||||
var way = this.map.history().graph().entity(way_id),
|
||||
firstNode = way.nodes[0],
|
||||
lastNode = _.last(way.nodes);
|
||||
way.nodes[push](nextnode_id);
|
||||
@@ -168,11 +168,11 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
|
||||
function mousemove() {
|
||||
var ll = this.map.projection.invert(d3.mouse(surface.node()));
|
||||
var way = this.map.history.graph().entity(way_id);
|
||||
var node = iD.Entity(this.map.history.graph().entity(nextnode_id), {
|
||||
var way = this.map.history().graph().entity(way_id);
|
||||
var node = iD.Entity(this.map.history().graph().entity(nextnode_id), {
|
||||
lon: ll[0], lat: ll[1]
|
||||
});
|
||||
this.map.history.replace(iD.actions.addWayNode(way, node));
|
||||
this.map.history().replace(iD.actions.addWayNode(way, node));
|
||||
var only = iD.Util.trueObj([way.id].concat(_.pluck(way.nodes, 'id')));
|
||||
this.map.redraw(only);
|
||||
}
|
||||
@@ -182,18 +182,18 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
d3.event.stopPropagation();
|
||||
if (t.data() && t.data()[0] && t.data()[0].type === 'node') {
|
||||
if (t.data()[0].id == firstNode || t.data()[0].id == lastNode) {
|
||||
var l = this.map.history.graph().entity(way.nodes[pop]());
|
||||
var l = this.map.history().graph().entity(way.nodes[pop]());
|
||||
this.map.perform(iD.actions.removeWayNode(way, l));
|
||||
// If this is drawing a loop and this is not the drawing
|
||||
// end of the stick, finish the circle
|
||||
if (direction === 'forward' && t.data()[0].id == firstNode) {
|
||||
way.nodes[push](firstNode);
|
||||
this.map.perform(iD.actions.addWayNode(way,
|
||||
this.map.history.graph().entity(firstNode)));
|
||||
this.map.history().graph().entity(firstNode)));
|
||||
} else if (direction === 'backward' && t.data()[0].id == lastNode) {
|
||||
way.nodes[push](lastNode);
|
||||
this.map.perform(iD.actions.addWayNode(way,
|
||||
this.map.history.graph().entity(lastNode)));
|
||||
this.map.history().graph().entity(lastNode)));
|
||||
}
|
||||
delete way.tags.elastic;
|
||||
this.map.perform(iD.actions.changeTags(way, way.tags));
|
||||
@@ -208,14 +208,14 @@ iD.modes.DrawRoad = function(way_id, direction) {
|
||||
var index = iD.modes.chooseIndex(t.data()[0], d3.mouse(surface.node()), this.map);
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
var connectedWay = this.map.history.graph().entity(t.data()[0].id);
|
||||
var connectedWay = this.map.history().graph().entity(t.data()[0].id);
|
||||
connectedWay.nodes.splice(1, 0, node.id);
|
||||
this.map.perform(iD.actions.addWayNode(connectedWay, node));
|
||||
} else {
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
}
|
||||
var old = this.map.history.graph().entity(way.nodes[pop]());
|
||||
var old = this.map.history().graph().entity(way.nodes[pop]());
|
||||
this.map.perform(iD.actions.removeWayNode(way, old));
|
||||
way.nodes[push](node.id);
|
||||
this.map.perform(iD.actions.addWayNode(way, node));
|
||||
@@ -304,7 +304,7 @@ iD.modes.DrawArea = function(way_id) {
|
||||
nextnode = iD.modes._node([NaN, NaN]);
|
||||
|
||||
var surface = this.map.surface,
|
||||
way = this.map.history.graph().entity(way_id),
|
||||
way = this.map.history().graph().entity(way_id),
|
||||
firstnode_id = _.first(way.nodes),
|
||||
nextnode_id = nextnode.id;
|
||||
|
||||
@@ -313,12 +313,12 @@ iD.modes.DrawArea = function(way_id) {
|
||||
|
||||
function mousemove() {
|
||||
var ll = this.map.projection.invert(d3.mouse(surface.node()));
|
||||
var way = this.map.history.graph().entity(way_id);
|
||||
var node = iD.Entity(this.map.history.graph().entity(nextnode_id), {
|
||||
var way = this.map.history().graph().entity(way_id);
|
||||
var node = iD.Entity(this.map.history().graph().entity(nextnode_id), {
|
||||
lon: ll[0],
|
||||
lat: ll[1]
|
||||
});
|
||||
this.map.history.replace(iD.actions.addWayNode(way, node));
|
||||
this.map.history().replace(iD.actions.addWayNode(way, node));
|
||||
var only = iD.Util.trueObj([way.id].concat(_.pluck(way.nodes, 'id')));
|
||||
this.map.redraw(only);
|
||||
}
|
||||
@@ -328,11 +328,11 @@ iD.modes.DrawArea = function(way_id) {
|
||||
d3.event.stopPropagation();
|
||||
if (t.data() && t.data()[0] && t.data()[0].type === 'node') {
|
||||
if (t.data()[0].id == firstnode_id) {
|
||||
var l = this.map.history.graph().entity(way.nodes.pop());
|
||||
var l = this.map.history().graph().entity(way.nodes.pop());
|
||||
this.map.perform(iD.actions.removeWayNode(way, l));
|
||||
way.nodes.push(way.nodes[0]);
|
||||
this.map.perform(iD.actions.addWayNode(way,
|
||||
this.map.history.graph().entity(way.nodes[0])));
|
||||
this.map.history().graph().entity(way.nodes[0])));
|
||||
delete way.tags.elastic;
|
||||
this.map.perform(iD.actions.changeTags(way, way.tags));
|
||||
// End by clicking on own tail
|
||||
@@ -345,7 +345,7 @@ iD.modes.DrawArea = function(way_id) {
|
||||
node = iD.modes._node(this.map.projection.invert(
|
||||
d3.mouse(surface.node())));
|
||||
}
|
||||
var old = this.map.history.graph().entity(way.nodes.pop());
|
||||
var old = this.map.history().graph().entity(way.nodes.pop());
|
||||
this.map.perform(iD.actions.removeWayNode(way, old));
|
||||
way.nodes.push(node.id);
|
||||
this.map.perform(iD.actions.addWayNode(way, node));
|
||||
|
||||
14
js/id/id.js
14
js/id/id.js
@@ -1,8 +1,10 @@
|
||||
var iD = function(container) {
|
||||
var connection = iD.Connection()
|
||||
.url('http://api06.dev.openstreetmap.org'),
|
||||
history = iD.History(),
|
||||
map = iD.Map()
|
||||
.connection(connection),
|
||||
.connection(connection)
|
||||
.history(history),
|
||||
controller = iD.Controller(map);
|
||||
|
||||
map.background.source(iD.Background.Bing);
|
||||
@@ -75,9 +77,9 @@ var iD = function(container) {
|
||||
function save(e) {
|
||||
d3.select('.shaded').remove();
|
||||
var l = iD.loading('uploading changes to openstreetmap');
|
||||
connection.putChangeset(map.history.changes(), e.comment, function() {
|
||||
connection.putChangeset(history.changes(), e.comment, function() {
|
||||
l.remove();
|
||||
map.history = iD.History();
|
||||
map.history(iD.History());
|
||||
map.flush().redraw();
|
||||
});
|
||||
}
|
||||
@@ -89,7 +91,7 @@ var iD = function(container) {
|
||||
});
|
||||
var modal = shaded.append('div')
|
||||
.attr('class', 'modal commit-pane')
|
||||
.datum(map.history.changes());
|
||||
.datum(history.changes());
|
||||
modal.call(iD.commit()
|
||||
.on('cancel', function() {
|
||||
shaded.remove();
|
||||
@@ -117,8 +119,8 @@ var iD = function(container) {
|
||||
"/ imagery <a href='http://opengeodata.org/microsoft-imagery-details'>© 2012</a> Bing, GeoEye, Getmapping, Intermap, Microsoft.</p>");
|
||||
|
||||
map.on('update', function() {
|
||||
var undo = map.history.undoAnnotation(),
|
||||
redo = map.history.redoAnnotation();
|
||||
var undo = history.undoAnnotation(),
|
||||
redo = history.redoAnnotation();
|
||||
|
||||
bar.select('#undo')
|
||||
.property('disabled', !undo)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
iD.Map = function() {
|
||||
var connection,
|
||||
var connection, history,
|
||||
dimensions = [],
|
||||
dispatch = d3.dispatch('move', 'update'),
|
||||
inspector = iD.Inspector(),
|
||||
@@ -33,12 +33,12 @@ iD.Map = function() {
|
||||
if (!dragging) {
|
||||
dragging = true;
|
||||
only = iD.Util.trueObj([entity.id].concat(
|
||||
_.pluck(map.history.graph().parents(entity.id), 'id')));
|
||||
map.history.perform(iD.actions.noop());
|
||||
_.pluck(history.graph().parents(entity.id), 'id')));
|
||||
history.perform(iD.actions.noop());
|
||||
}
|
||||
|
||||
var to = projection.invert([d3.event.x, d3.event.y]);
|
||||
map.history.replace(iD.actions.move(entity, to));
|
||||
history.replace(iD.actions.move(entity, to));
|
||||
|
||||
redraw(only);
|
||||
})
|
||||
@@ -132,8 +132,6 @@ iD.Map = function() {
|
||||
map.surface = surface;
|
||||
}
|
||||
|
||||
map.history = iD.History();
|
||||
|
||||
function prefixMatch(p) { // via mbostock
|
||||
var i = -1, n = p.length, s = document.body.style;
|
||||
while (++i < n) if (p[i] + 'Transform' in s) return '-' + p[i].toLowerCase() + '-';
|
||||
@@ -163,7 +161,7 @@ iD.Map = function() {
|
||||
if (surface.style(transformProp) != 'none') return;
|
||||
var all = [], ways = [], areas = [], points = [], waynodes = [],
|
||||
extent = map.extent(),
|
||||
graph = map.history.graph();
|
||||
graph = history.graph();
|
||||
|
||||
if (!only) {
|
||||
all = graph.intersects(extent);
|
||||
@@ -404,7 +402,7 @@ iD.Map = function() {
|
||||
if (result instanceof Error) {
|
||||
// TODO: handle
|
||||
} else {
|
||||
map.history.merge(result);
|
||||
history.merge(result);
|
||||
drawVector(iD.Util.trueObj(Object.keys(result.entities)));
|
||||
}
|
||||
});
|
||||
@@ -439,7 +437,7 @@ iD.Map = function() {
|
||||
selection = entity.id;
|
||||
d3.select('.inspector-wrap')
|
||||
.style('display', 'block')
|
||||
.datum(map.history.graph().fetch(entity.id))
|
||||
.datum(history.graph().fetch(entity.id))
|
||||
.call(inspector);
|
||||
redraw();
|
||||
}
|
||||
@@ -454,7 +452,7 @@ iD.Map = function() {
|
||||
|
||||
function removeEntity(entity) {
|
||||
// Remove this node from any ways that is a member of
|
||||
map.history.graph().parents(entity.id)
|
||||
history.graph().parents(entity.id)
|
||||
.filter(function(d) { return d.type === 'way'; })
|
||||
.forEach(function(parent) {
|
||||
parent.nodes = _.without(parent.nodes, entity.id);
|
||||
@@ -464,7 +462,7 @@ iD.Map = function() {
|
||||
}
|
||||
|
||||
inspector.on('changeTags', function(d, tags) {
|
||||
var entity = map.history.graph().entity(d.id);
|
||||
var entity = history.graph().entity(d.id);
|
||||
map.perform(iD.actions.changeTags(entity, tags));
|
||||
}).on('changeWayDirection', function(d) {
|
||||
map.perform(iD.actions.changeWayDirection(d));
|
||||
@@ -518,21 +516,21 @@ iD.Map = function() {
|
||||
}
|
||||
|
||||
map.perform = function(action) {
|
||||
map.history.perform(action);
|
||||
history.perform(action);
|
||||
map.update();
|
||||
redraw();
|
||||
return map;
|
||||
};
|
||||
|
||||
map.undo = function() {
|
||||
map.history.undo();
|
||||
history.undo();
|
||||
map.update();
|
||||
redraw();
|
||||
return map;
|
||||
};
|
||||
|
||||
map.redo = function() {
|
||||
map.history.redo();
|
||||
history.redo();
|
||||
map.update();
|
||||
redraw();
|
||||
return map;
|
||||
@@ -611,9 +609,15 @@ iD.Map = function() {
|
||||
};
|
||||
|
||||
map.connection = function(_) {
|
||||
if (!arguments.length) return connection;
|
||||
connection = _;
|
||||
return map;
|
||||
if (!arguments.length) return connection;
|
||||
connection = _;
|
||||
return map;
|
||||
};
|
||||
|
||||
map.history = function (_) {
|
||||
if (!arguments.length) return history;
|
||||
history = _;
|
||||
return map;
|
||||
};
|
||||
|
||||
map.background = background;
|
||||
|
||||
@@ -66,6 +66,11 @@ describe('Map', function() {
|
||||
|
||||
beforeEach(function () {
|
||||
spy = sinon.spy();
|
||||
map.history({
|
||||
perform: function () {},
|
||||
undo: function () {},
|
||||
redo: function () {}
|
||||
});
|
||||
map.on('update', spy);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user