Make controller dependency one-way

This commit is contained in:
Tom MacWright
2012-10-24 12:16:22 -04:00
parent 9d93b2ec64
commit 609f4efa41
3 changed files with 9 additions and 27 deletions
+5 -9
View File
@@ -91,31 +91,27 @@
map.setZoom(18);
map.setCentre({ lat: 40.796, lon: -74.691 });
// Initialise controller
var controller = new iD.Controller(map);
map.setController(controller);
// ----------------------------------------------------
// Data is loaded and app ready to go
// Set initial controllerState
controller.setState(new iD.controller.edit.NoSelection());
map.controller.setState(new iD.controller.edit.NoSelection());
// ----------------------------------------------------
// Mode button handlers
$('#add-place').click(function() {
controller.setState(new iD.controller.shape.NoSelection('node'));
map.controller.setState(new iD.controller.shape.NoSelection('node'));
});
$('#add-road').click(function() {
controller.setState(new iD.controller.shape.NoSelection('way'));
map.controller.setState(new iD.controller.shape.NoSelection('way'));
});
$('#add-area').click(function() {
controller.setState(new iD.controller.shape.NoSelection());
map.controller.setState(new iD.controller.shape.NoSelection());
});
$('#undo').click(function() {
controller.undoStack.undo();
map.controller.undoStack.undo();
map.updateUIs(true, true);
});
+1 -1
View File
@@ -2,7 +2,7 @@
// Controller base class
if (typeof iD === 'undefined') iD = {};
iD.Controller = function(map) {
iD.Controller = function() {
var controller = {},
state = null;
+3 -17
View File
@@ -11,6 +11,8 @@ iD.renderer.Map = function(obj) {
this.width = obj.width ? obj.width : 800;
this.height = obj.height ? obj.height : 400;
this.controller = iD.Controller();
// Initialise variables
this.uis = {};
@@ -69,9 +71,6 @@ iD.renderer.Map = function(obj) {
// Create group for elastic band
this.elastic = this.container.append('g');
// Make draggable
this.surface.on('onclick', _.bind(this.clickSurface, this));
this.redraw();
};
@@ -81,7 +80,6 @@ iD.renderer.Map.prototype = {
surface: null, // <div>.surface containing the rendering
container: null, // root-level group within the surface
connection: null, // data store
controller: null, // UI controller
tilegroup: null, // group within container for adding bitmap tiles
tilebaseURL: 'http://ecn.t0.tiles.virtualearth.net/tiles/a$quadkey.jpeg?g=587&mkt=en-gb&n=z', // Bing imagery URL
@@ -96,11 +94,6 @@ iD.renderer.Map.prototype = {
elastic: null, // Group for drawing elastic band
ruleset: null, // map style
setController:function(controller) {
// summary: Set the controller that will handle events on the map (e.g. mouse clicks).
this.controller = controller;
},
download: _.debounce(function() {
// summary: Ask the connection to download data for the current viewport.
this.connection.loadFromAPI(this.extent(), _.bind(this.updateUIs, this));
@@ -315,12 +308,5 @@ iD.renderer.Map.prototype = {
this.redraw();
return this;
},
setCenter: function(loc) { this.setCentre(loc); },
clickSurface:function(e) {
// summary: Handle a click on an empty area of the map.
if (this.dragged && e.timeStamp==this.dragtime) { return; }
this.controller.entityMouseEvent(e,null);
}
setCenter: function(loc) { this.setCentre(loc); }
};