mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
Make controller dependency one-way
This commit is contained in:
+5
-9
@@ -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
@@ -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
@@ -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); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user