Improve poi finding performance, update map style

This commit is contained in:
Tom MacWright
2012-11-12 17:36:23 -05:00
parent c41cb34e23
commit 89dded9967
5 changed files with 22 additions and 61 deletions

View File

@@ -10,9 +10,9 @@ path, image.marker {
/* interactive elements */
circle.handle {
cursor: move;
stroke-width: 2;
stroke:#1DCAFF;
fill:#D3F5FF;
stroke-width: 3;
fill:#000;
stroke:#FFF694;
}
circle.teaser-point {

View File

@@ -15,7 +15,7 @@
+&nbsp;Place</button><button id='road'>
+&nbsp;Road</button><button id='area'>
+&nbsp;Area</button><button class='mini' id='undo'>
&larr; <small></small></button><button class='mini' id='redo'>
&larr;<small></small></button><button class='mini' id='redo'>
&rarr;</button><input type='text' id='geocode-location' placeholder='find a place' />
<div class='zoombuttons'>
<button class='zoom-in'>+</button><button class='zoom-out'>&ndash;</button>
@@ -30,7 +30,7 @@
Imagery <a href='http://opengeodata.org/microsoft-imagery-details'>&copy; 2012</a> Bing, GeoEye, Getmapping, Intermap, Microsoft.</p>
</div>
<script type='text/javascript' src='js/lib/underscore-min.js'></script>
<script type='text/javascript' src='js/lib/lodash.js'></script>
<script type='text/javascript' src='js/lib/d3.v2.js'></script>
<script type='text/javascript' src='js/lib/jxon.js'></script>

View File

@@ -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;
};

View File

@@ -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);

View File

@@ -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