mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Push to d3 v3, remove mins, reuse more functions.
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@
|
||||
</div>
|
||||
|
||||
<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/d3.v3.js'></script>
|
||||
<script type='text/javascript' src='js/lib/jxon.js'></script>
|
||||
|
||||
<script type='text/javascript' src='js/iD/id.js'></script>
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ iD.Connection = function() {
|
||||
}
|
||||
|
||||
function parse(callback) {
|
||||
return function(dom) {
|
||||
return function(err, dom) {
|
||||
if (!dom.childNodes) return callback(new Error('Bad request'));
|
||||
var root = dom.childNodes[0];
|
||||
var entities = {};
|
||||
|
||||
+16
-14
@@ -44,28 +44,30 @@ iD.Graph.prototype = {
|
||||
return iD.Graph(entities, annotation);
|
||||
},
|
||||
|
||||
nodeIntersect: function(entity, extent) {
|
||||
return entity.lon > extent[0][0] &&
|
||||
entity.lon < extent[1][0] &&
|
||||
entity.lat < extent[0][1] &&
|
||||
entity.lat > extent[1][1];
|
||||
},
|
||||
|
||||
wayIntersect: function(entity, extent) {
|
||||
return entity._extent[0][0] > extent[0][0] &&
|
||||
entity._extent[1][0] < extent[1][0] &&
|
||||
entity._extent[0][1] < extent[0][1] &&
|
||||
entity._extent[1][1] > extent[1][1];
|
||||
},
|
||||
|
||||
// get all objects that intersect an extent.
|
||||
intersects: function(extent) {
|
||||
var items = [];
|
||||
function nodeIntersect(entity) {
|
||||
return entity.lon > extent[0][0] &&
|
||||
entity.lon < extent[1][0] &&
|
||||
entity.lat < extent[0][1] &&
|
||||
entity.lat > extent[1][1];
|
||||
}
|
||||
function wayIntersect(entity) {
|
||||
return entity._extent[0][0] > extent[0][0] &&
|
||||
entity._extent[1][0] < extent[1][0] &&
|
||||
entity._extent[0][1] < extent[0][1] &&
|
||||
entity._extent[1][1] > extent[1][1];
|
||||
}
|
||||
for (var i in this.entities) {
|
||||
var entity = this.entities[i];
|
||||
if (entity.type === 'node' && nodeIntersect(entity)) {
|
||||
if (entity.type === 'node' && this.nodeIntersect(entity, extent)) {
|
||||
items.push(entity);
|
||||
} else if (entity.type === 'way') {
|
||||
var w = this.fetch(entity.id);
|
||||
if (wayIntersect(w)) items.push(w);
|
||||
if (this.wayIntersect(w, extent)) items.push(w);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
+32
-28
@@ -109,6 +109,13 @@ iD.Map = function(elem) {
|
||||
|
||||
function classActive(d) { return d.id === selection; }
|
||||
|
||||
function nodeIntersect(entity, extent) {
|
||||
return entity.lon > extent[0][0] &&
|
||||
entity.lon < extent[1][0] &&
|
||||
entity.lat < extent[0][1] &&
|
||||
entity.lat > extent[1][1];
|
||||
}
|
||||
|
||||
function drawVector() {
|
||||
// don't redraw vectors while the map is in fast mode
|
||||
if (surface.style(transformProp) != 'none') return;
|
||||
@@ -121,13 +128,6 @@ iD.Map = function(elem) {
|
||||
points = [],
|
||||
waynodes = [];
|
||||
|
||||
function nodeIntersect(entity) {
|
||||
return entity.lon > extent[0][0] &&
|
||||
entity.lon < extent[1][0] &&
|
||||
entity.lat < extent[0][1] &&
|
||||
entity.lat > extent[1][1];
|
||||
}
|
||||
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var a = all[i];
|
||||
if (a.type === 'way') {
|
||||
@@ -139,7 +139,7 @@ iD.Map = function(elem) {
|
||||
}
|
||||
} else if (a._poi) {
|
||||
points.push(a);
|
||||
} else if (!a._poi && a.type === 'node' && nodeIntersect(a)) {
|
||||
} else if (!a._poi && a.type === 'node' && nodeIntersect(a, extent)) {
|
||||
waynodes.push(a);
|
||||
}
|
||||
}
|
||||
@@ -191,14 +191,17 @@ iD.Map = function(elem) {
|
||||
.classed('active', classActive);
|
||||
}
|
||||
|
||||
function nameHoverIn(d) { messages.text(d.tags.name || '(unknown)'); }
|
||||
function nameHoverOut(d) { messages.text(''); }
|
||||
|
||||
function drawMarkers(points) {
|
||||
var markers = hit_g.selectAll('g.marker').data(points, key);
|
||||
markers.exit().remove();
|
||||
var marker = markers.enter().append('g')
|
||||
.attr('class', 'marker')
|
||||
.on('click', selectClick)
|
||||
.on('mouseover', function(d) { messages.text(d.tags.name || '(unknown)'); })
|
||||
.on('mouseout', function(d) { messages.text(''); })
|
||||
.on('mouseover', nameHoverIn)
|
||||
.on('mouseout', nameHoverOut)
|
||||
.call(dragbehavior);
|
||||
marker.append('circle')
|
||||
.attr({ r: 10, cx: 8, cy: 8 });
|
||||
@@ -219,8 +222,8 @@ iD.Map = function(elem) {
|
||||
strokes.exit().remove();
|
||||
strokes.enter().append('path')
|
||||
.on('click', selectClick)
|
||||
.on('mouseover', function(d) { messages.text(d.tags.name || '(unknown)'); })
|
||||
.on('mouseout', function(d) { messages.text(''); })
|
||||
.on('mouseover', nameHoverIn)
|
||||
.on('mouseout', nameHoverOut)
|
||||
.attr('class', class_stroke)
|
||||
.classed('active', classActive);
|
||||
strokes.order()
|
||||
@@ -265,8 +268,8 @@ iD.Map = function(elem) {
|
||||
casings.exit().remove();
|
||||
casings.enter().append('path')
|
||||
.on('click', selectClick)
|
||||
.on('mouseover', function(d) { messages.text(d.tags.name || '(unknown)'); })
|
||||
.on('mouseout', function(d) { messages.text(''); })
|
||||
.on('mouseover', nameHoverIn)
|
||||
.on('mouseout', nameHoverOut)
|
||||
.attr('class', class_casing)
|
||||
.classed('active', classActive);
|
||||
casings.order()
|
||||
@@ -300,16 +303,23 @@ iD.Map = function(elem) {
|
||||
|
||||
var apiTilesLoaded = {};
|
||||
|
||||
function apiTiles() {
|
||||
function tileAtZoom(t, distance) {
|
||||
var power = Math.pow(2, distance);
|
||||
return [
|
||||
Math.floor(t[0] * power),
|
||||
Math.floor(t[1] * power),
|
||||
t[2] + distance];
|
||||
}
|
||||
|
||||
function tileAtZoom(t, distance) {
|
||||
var power = Math.pow(2, distance);
|
||||
return [
|
||||
Math.floor(t[0] * power),
|
||||
Math.floor(t[1] * power),
|
||||
t[2] + distance];
|
||||
function tileAlreadyLoaded(c) {
|
||||
if (apiTilesLoaded[c]) return false;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (apiTilesLoaded[tileAtZoom(c, -i)]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function apiTiles() {
|
||||
var t = projection.translate(),
|
||||
s = projection.scale(),
|
||||
z = Math.max(Math.log(s) / Math.log(2) - 8, 0),
|
||||
@@ -330,13 +340,7 @@ iD.Map = function(elem) {
|
||||
});
|
||||
});
|
||||
|
||||
return coords.filter(function(c) {
|
||||
if (apiTilesLoaded[c]) return false;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (apiTilesLoaded[tileAtZoom(c, -i)]) return false;
|
||||
}
|
||||
return true;
|
||||
}).map(function(c) {
|
||||
return coords.filter(tileAlreadyLoaded).map(function(c) {
|
||||
var x = (c[0] * ts) - tile_origin[0];
|
||||
var y = (c[1] * ts) - tile_origin[1];
|
||||
apiTilesLoaded[c] = true;
|
||||
|
||||
Vendored
-4
File diff suppressed because one or more lines are too long
Vendored
+7604
File diff suppressed because it is too large
Load Diff
Vendored
-5
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user