Inject connection dependency in map

This commit is contained in:
John Firebaugh
2012-11-24 13:07:23 -04:00
parent 2d861507b9
commit 22e9eb39cc
2 changed files with 7 additions and 13 deletions
+6 -4
View File
@@ -4,8 +4,10 @@ var iD = function(container) {
var m = container.append('div')
.attr('id', 'map');
var map = iD.Map(m.node())
.setAPI('http://api06.dev.openstreetmap.org/api/0.6/');
var connection = iD.Connection()
.url('http://api06.dev.openstreetmap.org/api/0.6/');
var map = iD.Map(m.node(), connection);
var controller = iD.Controller(map);
@@ -137,12 +139,12 @@ var iD = function(container) {
if (oauth.authenticated()) {
oauth.xhr({ method: 'GET', path: '/user/details' }, function(user_details) {
var u = user_details.getElementsByTagName('user')[0];
map.connection.user({
connection.user({
display_name: u.attributes.display_name.nodeValue,
id: u.attributes.id.nodeValue
});
d3.select('.messages').text('logged in as ' +
map.connection.user().display_name);
connection.user().display_name);
});
}
};
+1 -9
View File
@@ -1,4 +1,4 @@
iD.Map = function(elem) {
iD.Map = function(elem, connection) {
if (!iD.supported()) {
elem.innerHTML = 'This editor is supported in Firefox, Chrome, Safari, Opera, ' +
@@ -12,7 +12,6 @@ iD.Map = function(elem) {
dimensions = { width: null, height: null },
dispatch = d3.dispatch('move', 'update'),
history = iD.History(),
connection = iD.Connection(),
inspector = iD.Inspector(),
parent = d3.select(elem),
selection = null,
@@ -535,11 +534,6 @@ iD.Map = function(elem) {
return map;
}
function setAPI(x) {
connection.url(x);
return map;
}
function commit() {
var modified = _.filter(history.graph().entities, function(e) {
return e.modified;
@@ -583,10 +577,8 @@ iD.Map = function(elem) {
map.zoomIn = zoomIn;
map.zoomOut = zoomOut;
map.connection = connection;
map.projection = projection;
map.setSize = setSize;
map.setAPI = setAPI;
map.history = history;
map.surface = surface;