mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-23 12:30:29 +01:00
Improve poi finding performance, update map style
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
iD.Connection = function() {
|
||||
var apiURL = 'http://www.openstreetmap.org/api/0.6/';
|
||||
|
||||
var connection = {};
|
||||
var connection = {}, refNodes = {};
|
||||
|
||||
// Request data within the bbox from an external OSM server.
|
||||
function bboxFromAPI(box, callback) {
|
||||
@@ -22,6 +22,7 @@ iD.Connection = function() {
|
||||
var nodes = [], nelems = obj.getElementsByTagName('nd');
|
||||
for (var i = 0, l = nelems.length; i < l; i++) {
|
||||
nodes[i] = 'n' + nelems[i].attributes.ref.nodeValue;
|
||||
refNodes['n' + nelems[i].attributes.ref.nodeValue] = true;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
@@ -86,8 +87,10 @@ iD.Connection = function() {
|
||||
if (!dom.childNodes) return callback(new Error('Bad request'));
|
||||
var root = dom.childNodes[0];
|
||||
var entities = {};
|
||||
refNodes = {};
|
||||
var addEntity = function (obj) {
|
||||
var o = objectData(obj);
|
||||
if (o.type === 'node') o._poi = !refNodes[o.id];
|
||||
entities[o.id] = o;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,24 +9,6 @@ iD.Graph.prototype = {
|
||||
return this.entities[id];
|
||||
},
|
||||
|
||||
// get all points that are not part of a way. this is an expensive
|
||||
// call that needs to be optimized.
|
||||
pois: function() {
|
||||
var included = [], pois = [], idx = {};
|
||||
for (var i in this.entities) {
|
||||
if (this.entities[i].nodes) {
|
||||
included = included.concat(this.entities[i].nodes);
|
||||
}
|
||||
}
|
||||
for (var j = 0; j < included.length; j++) { idx[included[j]] = true; }
|
||||
for (var k in this.entities) {
|
||||
if (this.entities[k].type === 'node' && !idx[this.entities[k].id]) {
|
||||
pois.push(this.entities[k]);
|
||||
}
|
||||
}
|
||||
return pois;
|
||||
},
|
||||
|
||||
merge: function(graph) {
|
||||
var entities = _.clone(this.entities);
|
||||
_.defaults(entities, graph.entities);
|
||||
|
||||
@@ -108,16 +108,18 @@ iD.Map = function(elem) {
|
||||
var graph = history.graph(),
|
||||
all = graph.intersects(getExtent());
|
||||
|
||||
var ways = all.filter(function(a) {
|
||||
return a.type === 'way' && !iD.Way.isClosed(a);
|
||||
}).map(function(x) {
|
||||
x._line = nodeline(x);
|
||||
return x;
|
||||
}).sort(iD.Style.waystack),
|
||||
areas = all.filter(function(a) {
|
||||
return a.type === 'way' && iD.Way.isClosed(a);
|
||||
}),
|
||||
points = graph.pois();
|
||||
var ways = [], areas = [], points = [];
|
||||
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var a = all[i];
|
||||
if (a.type === 'way') {
|
||||
a._line = nodeline(a);
|
||||
if (!iD.Way.isClosed(a)) ways.push(a);
|
||||
else areas.push(a);
|
||||
} else if (a._poi) {
|
||||
points.push(a);
|
||||
}
|
||||
}
|
||||
|
||||
var fills = fill_g.selectAll('path.area').data(areas, key),
|
||||
casings = casing_g.selectAll('path.casing').data(ways, key),
|
||||
@@ -229,44 +231,18 @@ iD.Map = function(elem) {
|
||||
map.operate(iD.operations.remove(d));
|
||||
});
|
||||
|
||||
var fastTranslate = [0,0];
|
||||
|
||||
function zoomPan() {
|
||||
var translate;
|
||||
var fast = projection.scale() === d3.event.scale;
|
||||
if (fast) {
|
||||
fastTranslate[0] -= projection.translate()[0] - d3.event.translate[0];
|
||||
fastTranslate[1] -= projection.translate()[1] - d3.event.translate[1];
|
||||
}
|
||||
projection
|
||||
.translate(d3.event.translate)
|
||||
.scale(d3.event.scale);
|
||||
if (fast) {
|
||||
fastRedraw();
|
||||
} else {
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
// Slow redraw - going out of turbo mode.
|
||||
var slowDraw = _.debounce(function() {
|
||||
fastTranslate = [0,0];
|
||||
redraw();
|
||||
r.attr('transform', '');
|
||||
}, 500);
|
||||
|
||||
function fastRedraw(translate) {
|
||||
dispatch.move(map);
|
||||
tileclient.redraw();
|
||||
r.attr('transform', 'translate(' + fastTranslate + ')');
|
||||
slowDraw();
|
||||
download();
|
||||
}
|
||||
|
||||
function redraw() {
|
||||
dispatch.move(map);
|
||||
tileclient.redraw();
|
||||
if (getZoom() > 13) {
|
||||
download();
|
||||
drawVector();
|
||||
} else {
|
||||
// TODO: hide vector features
|
||||
|
||||
Reference in New Issue
Block a user