diff --git a/index.html b/index.html
index 6de582c0f..4fcfc6f90 100755
--- a/index.html
+++ b/index.html
@@ -12,6 +12,7 @@
+
@@ -29,6 +30,7 @@
+
@@ -36,6 +38,7 @@
+
diff --git a/js/iD/Connection.js b/js/iD/Connection.js
index 93b275a5a..1693dde37 100755
--- a/js/iD/Connection.js
+++ b/js/iD/Connection.js
@@ -1,15 +1,12 @@
-if (typeof iD === 'undefined') iD = {};
-
iD.Connection = function() {
- // summary: The data store, including methods to fetch data from (and, eventually, save data to)
+ // summary: The data store, including methods to fetch data from (and, eventually, save data to)
// an OSM API server.
- var nextNode = -1, // next negative ids
- nextWay = -1, // |
- nextRelation = -1, // |
+ var nextNode = -1,
+ nextWay = -1,
+ nextRelation = -1,
entities = {},
relations = {},
- pois = {},
- apiURL = 'http://www.openstreetmap.org/api/0.6/map?bbox=',
+ apiURL = 'http://www.openstreetmap.org/api/0.6/',
modified = false;
var connection = {};
@@ -20,7 +17,7 @@ iD.Connection = function() {
function assign(obj) {
// summary: Save an entity to the data store.
- if (obj.entityType === 'relation') {
+ if (obj.type === 'relation') {
if (!relations[obj.id]) relations[obj.id] = obj;
} else if (!entities[obj.id] || !entities[obj.id].loaded) {
entities[obj.id] = obj;
@@ -74,7 +71,7 @@ iD.Connection = function() {
// Request data within the bbox from an external OSM server.
function loadFromAPI(box, callback) {
- loadFromURL(apiURL +
+ loadFromURL(apiURL + 'map?bbox=' +
[box[0][0], box[1][1], box[1][0], box[0][1]], callback);
}
diff --git a/js/iD/Controller.js b/js/iD/Controller.js
index 9d6b3b791..bd7d83fa6 100755
--- a/js/iD/Controller.js
+++ b/js/iD/Controller.js
@@ -1,5 +1,3 @@
-if (typeof iD === 'undefined') iD = {};
-
iD.Controller = function() {
var controller = {},
state = null;
diff --git a/js/iD/Entity.js b/js/iD/Entity.js
index e3dc1334c..49806a0fa 100755
--- a/js/iD/Entity.js
+++ b/js/iD/Entity.js
@@ -1,11 +1,9 @@
-if (typeof iD === 'undefined') iD = {};
-
iD.Entity = function () {
this.parents = {};
this._id = iD.Util.id();
this.id = NaN;
this.loaded = false;
- this.entityType = '';
+ this.type = '';
this.modified = false;
this.deleted = false;
};
@@ -36,7 +34,7 @@ iD.Entity.prototype = {
// summary: Does this entity have any parents which are ways?
var parentObjects = this.parentObjects();
for (var i = 0; i < parentObjects.length; i++) {
- if (parentObjects[i].entityType === 'way') return true;
+ if (parentObjects[i].type === 'way') return true;
}
},
parentWays: function () {
@@ -49,7 +47,7 @@ iD.Entity.prototype = {
var poc = [];
var parentObjects = this.parentObjects();
for (var i = 0; i < parentObjects.length; i++) {
- if (parentObjects[i].entityType === _class) {
+ if (parentObjects[i].type === _class) {
poc.push(parentObjects[i]);
}
}
diff --git a/js/iD/GeoJSON.js b/js/iD/GeoJSON.js
new file mode 100644
index 000000000..312e6e520
--- /dev/null
+++ b/js/iD/GeoJSON.js
@@ -0,0 +1,31 @@
+iD.GeoJSON = {
+ mapping: function(entity) {
+ if (this.mappings[entity.type]) {
+ return this.mappings[entity.type](entity);
+ }
+ },
+ mappings: {
+ node: function(entity) {
+ return {
+ type: 'Feature',
+ properties: entity.tags,
+ geometry: {
+ type: 'Point',
+ coordinates: [entity.lon, entity.lat]
+ }
+ };
+ },
+ way: function(entity) {
+ return {
+ type: 'Feature',
+ properties: entity.tags,
+ geometry: {
+ 'type': 'LineString',
+ 'coordinates': _.map(entity.nodes, function(node) {
+ return [node.lon, node.lat];
+ })
+ }
+ };
+ }
+ }
+};
diff --git a/js/iD/Graph.js b/js/iD/Graph.js
new file mode 100644
index 000000000..d36b3fece
--- /dev/null
+++ b/js/iD/Graph.js
@@ -0,0 +1,2 @@
+iD.Graph = function() {
+};
diff --git a/js/iD/Node.js b/js/iD/Node.js
index 27f27cd44..8b3a2cc9c 100644
--- a/js/iD/Node.js
+++ b/js/iD/Node.js
@@ -1,9 +1,7 @@
-if (typeof iD === 'undefined') iD = {};
-
// [Node](http://wiki.openstreetmap.org/wiki/Node)
iD.Node = function(id, lat, lon, tags, loaded) {
// summary: An OSM node.
- this.entityType = 'node';
+ this.type = 'node';
this.id = id;
this._id = iD.Util.id();
this.entity = new iD.Entity();
@@ -18,17 +16,6 @@ iD.Node = function(id, lat, lon, tags, loaded) {
};
iD.Node.prototype = {
- toGeoJSON: function() {
- return {
- type: 'Feature',
- properties: this.tags,
- geometry: {
- type: 'Point',
- coordinates: [this.lon, this.lat]
- }
- };
- },
-
intersects: function(extent) {
return (this.lon >= extent[0][0]) &&
(this.lon <= extent[1][0]) &&
diff --git a/js/iD/Relation.js b/js/iD/Relation.js
index 260be1e32..6f9511f1a 100644
--- a/js/iD/Relation.js
+++ b/js/iD/Relation.js
@@ -1,7 +1,5 @@
-if (typeof iD === 'undefined') iD = {};
-
iD.Relation = function(id, members, tags, loaded) {
- this.entityType = 'relation';
+ this.type = 'relation';
this.id = id;
this._id = iD.Util.id();
this.entity = new iD.Entity();
diff --git a/js/iD/Taginfo.js b/js/iD/Taginfo.js
index eb65a6234..b8f82b9ac 100644
--- a/js/iD/Taginfo.js
+++ b/js/iD/Taginfo.js
@@ -1,5 +1,3 @@
-if (typeof iD === 'undefined') iD = {};
-
// Taginfo service singleton
iD.Taginfo = (function() {
diff --git a/js/iD/Util.js b/js/iD/Util.js
index 9382bc6c0..8955dcefb 100644
--- a/js/iD/Util.js
+++ b/js/iD/Util.js
@@ -1,5 +1,3 @@
-if (typeof iD === 'undefined') iD = {};
-
iD.Util = {};
iD.Util._id = 0;
diff --git a/js/iD/Way.js b/js/iD/Way.js
index 3259d3529..5faaf2423 100644
--- a/js/iD/Way.js
+++ b/js/iD/Way.js
@@ -1,5 +1,3 @@
-if (typeof iD === 'undefined') iD = {};
-
// Way
// wiki: http://wiki.openstreetmap.org/wiki/Way
//
@@ -10,7 +8,7 @@ if (typeof iD === 'undefined') iD = {};
// `highway` or `barrier` tag and is not also tagged `area`.
iD.Way = function(id, nodes, tags, loaded) {
// summary: An OSM way.
- this.entityType = 'way';
+ this.type = 'way';
this.id = id;
this._id = iD.Util.id();
this.deleted = false;
@@ -52,21 +50,8 @@ iD.Way.prototype = {
return false; // Boolean
},
- toGeoJSON: function() {
- return {
- type: 'Feature',
- properties: this.tags,
- geometry: {
- 'type': 'LineString',
- 'coordinates': _.map(this.nodes, function(node) {
- return [node.lon, node.lat];
- })
- }
- };
- },
-
updateBounds: function() {
- this._bounds = d3.geo.bounds(this.toGeoJSON());
+ this._bounds = d3.geo.bounds(iD.GeoJSON.mapping(this));
},
bounds: function() {
@@ -91,69 +76,5 @@ iD.Way.prototype = {
// of the top-left
bounds[0][0] > extent[1][0] &&
bounds[0][1] > extent[1][1]);
- },
-
- // --------------
- // Action callers
-
- doAppendNode: function(node, performAction) {
- // summary: Add a node to the end of the way, using an undo stack.
- // returns: New length of the way.
- if (node!=this.getLastNode()) performAction(new iD.actions.AddNodeToWayAction(this, node, this.nodes, -1, true));
- return this.nodes.length + 1; // int
- },
-
- doPrependNode: function(node, performAction) {
- // summary: Add a node to the start of the way, using an undo stack.
- // returns: New length of the way.
- if (node!=this.nodes[0]) performAction(new iD.actions.AddNodeToWayAction(this, node, this.nodes, 0, true));
- return this.nodes.length + 1; // int
- },
-
- doInsertNode:function(index, node, performAction) {
- // summary: Add a node at a given index within the way, using an undo stack.
- if (index > 0 && this.nodes[index - 1]==node) return;
- if (index < this.nodes.length - 1 && this.nodes[index]==node) return;
- performAction(new iD.actions.AddNodeToWayAction(this, node, this.nodes, index, false));
- },
-
- doInsertNodeAtClosestPosition:function(newNode, isSnap, performAction) {
- // summary: Add a node into whichever segment of the way is nearest, using an undo stack.
- // isSnap: Boolean Should the node position be snapped to be exactly on the segment?
- // returns: The index at which the node was inserted.
- var closestProportion = 1,
- newIndex = 0,
- snapped;
-
- for (var i = 0; i < this.nodes.length - 1; i++) {
- var node1 = this.nodes[i],
- node2 = this.nodes[i + 1],
- directDist = this._pythagoras(node1, node2),
- viaNewDist = this._pythagoras(node1, newNode) +
- this._pythagoras(node2, newNode),
- proportion = Math.abs(viaNewDist/directDist - 1);
- if (proportion < closestProportion) {
- newIndex = i+1;
- closestProportion = proportion;
- snapped = this._calculateSnappedPoint(node1, node2, newNode);
- }
- }
-
- // splice in new node
- if (isSnap) { newNode.doSetLonLatp(snapped.x, snapped.y, performAction); }
- this.doInsertNode(newIndex, newNode, performAction);
- return newIndex; // int
- },
-
- _pythagoras:function(node1, node2) {
- return (Math.sqrt(Math.pow(node1.lon-node2.lon,2) +
- Math.pow(node1.latp-node2.latp,2)));
- },
-
- _calculateSnappedPoint:function(node1, node2, newNode) {
- var w = node2.lon - node1.lon;
- var h = node2.latp - node1.latp;
- var u = ((newNode.lon-node1.lon) * w + (newNode.latp-node1.latp) * h) / (w*w + h*h);
- return { x: node1.lon + u*w, y: node1.latp + u*h };
}
};
diff --git a/js/iD/controller/shape/NoSelection.js b/js/iD/controller/shape/NoSelection.js
index 7d6cc6765..b9b45e8fa 100644
--- a/js/iD/controller/shape/NoSelection.js
+++ b/js/iD/controller/shape/NoSelection.js
@@ -45,7 +45,7 @@ declare("iD.controller.shape.NoSelection", null, {
processMouseEvent: function(event, entityUI) {
var entity = entityUI ? entityUI.entity : null;
- var entityType = entity ? entity.entityType : null;
+ var entityType = entity ? entity.type : null;
var map = this.controller.map;
var connection = map.connection;
diff --git a/js/iD/controller/shape/SelectedWay.js b/js/iD/controller/shape/SelectedWay.js
index c85469826..2fb26371a 100644
--- a/js/iD/controller/shape/SelectedWay.js
+++ b/js/iD/controller/shape/SelectedWay.js
@@ -41,7 +41,7 @@ define(['dojo/_base/declare',
processMouseEvent: function(event, entityUI) {
var entity = entityUI ? entityUI.entity : null;
- var entityType = entity ? entity.entityType : null;
+ var entityType = entity ? entity.type : null;
var way;
if (event.type === 'click') {
diff --git a/js/iD/id.js b/js/iD/id.js
new file mode 100644
index 000000000..73b11b555
--- /dev/null
+++ b/js/iD/id.js
@@ -0,0 +1 @@
+if (typeof iD === 'undefined') var iD = {};
diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js
index 31d7ecb58..e02ab7fbe 100755
--- a/js/iD/renderer/Map.js
+++ b/js/iD/renderer/Map.js
@@ -179,13 +179,13 @@ iD.Map = function(obj) {
var all = connection.intersects(extent());
var ways = all.filter(function(a) {
- return a.entityType === 'way' && !a.isClosed();
+ return a.type === 'way' && !a.isClosed();
}).sort(waystack),
areas = all.filter(function(a) {
- return a.entityType === 'way' && a.isClosed();
+ return a.type === 'way' && a.isClosed();
}),
points = all.filter(function(a) {
- return a.entityType === 'node';
+ return a.type === 'node';
});
var fills = layers[0].fill.selectAll('path.area')
diff --git a/js/iD/ui/Inspector.js b/js/iD/ui/Inspector.js
index 73cabd149..737a2b139 100644
--- a/js/iD/ui/Inspector.js
+++ b/js/iD/ui/Inspector.js
@@ -17,7 +17,7 @@ iD.Inspector = function(selection) {
head.append('a')
.attr('class', 'permalink')
.attr('href', 'http://www.openstreetmap.org/browse/' +
- d.entityType + '/' + d.id)
+ d.type + '/' + d.id)
.text('#' + d.id);
var table = d3.select(this)
diff --git a/test/index.html b/test/index.html
index 81296a1f8..f474120a5 100644
--- a/test/index.html
+++ b/test/index.html
@@ -12,16 +12,21 @@
+
+
+
+
+
@@ -31,6 +36,8 @@
+
+