mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Detail slider affects turns, but not geometry
(I decided that the larger context of the intersection is important and shouldn't be hidden from the user) Also - show detail slider only if the intersection is complex - hide the restriction editor completely if there is no real intersection (e.g. junction of `highway=path`)
This commit is contained in:
@@ -29,12 +29,7 @@ export function osmTurn(turn) {
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// detail = 0 - via node only
|
||||
// detail = 1 - via node / 1 via way
|
||||
// detail = 2 - via node / up to 2 via ways
|
||||
//
|
||||
export function osmIntersection(graph, startVertexId, detail) {
|
||||
export function osmIntersection(graph, startVertexId) {
|
||||
var vgraph = coreGraph(); // virtual graph
|
||||
var i, j, k;
|
||||
|
||||
@@ -106,7 +101,6 @@ export function osmIntersection(graph, startVertexId, detail) {
|
||||
|
||||
ways.push(way); // it's a road, or it's already in a turn restriction
|
||||
hasWays = true;
|
||||
if (!detail) continue;
|
||||
|
||||
// check the way's children for more key vertices
|
||||
nodes = _uniq(graph.childNodes(way));
|
||||
@@ -380,8 +374,13 @@ export function osmIntersection(graph, startVertexId, detail) {
|
||||
//
|
||||
// For each path found, generate and return a `osmTurn` datastructure.
|
||||
//
|
||||
intersection.turns = function(fromWayId) {
|
||||
// detail = 0 - via node only
|
||||
// detail = 1 - via node / 1 via way
|
||||
// detail = 2 - via node / up to 2 via ways
|
||||
//
|
||||
intersection.turns = function(fromWayId, detail) {
|
||||
if (!fromWayId) return [];
|
||||
if (!detail) detail = 0;
|
||||
|
||||
var vgraph = intersection.graph;
|
||||
var keyVertexIds = intersection.vertices.map(function(v) { return v.id; });
|
||||
|
||||
@@ -63,13 +63,34 @@ export function uiFieldRestrictions(field, context) {
|
||||
|
||||
|
||||
function restrictions(selection) {
|
||||
// try to reuse the intersection, but always rebuild it if the graph has changed
|
||||
if (_vertexID && (context.graph() !== _graph || !_intersection)) {
|
||||
_graph = context.graph();
|
||||
_intersection = osmIntersection(_graph, _vertexID);
|
||||
}
|
||||
|
||||
// It's possible for there to be no actual intersection here.
|
||||
// for example, a vertex of two `highway=path`
|
||||
// In this case, hide the field.
|
||||
var isOK = (_intersection && _intersection.vertices.length && _intersection.ways.length);
|
||||
d3_select(selection.node().parentNode).classed('hide', !isOK)
|
||||
|
||||
// if form field is hidden or has detached from dom, clean up.
|
||||
if (!d3_select('.inspector-wrap.inspector-hidden').empty() ||
|
||||
!selection.node().parentNode || !selection.node().parentNode.parentNode) {
|
||||
if (!isOK ||
|
||||
!d3_select('.inspector-wrap.inspector-hidden').empty() ||
|
||||
!selection.node().parentNode ||
|
||||
!selection.node().parentNode.parentNode) {
|
||||
selection.call(restrictions.off);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var isComplex = (isOK && _intersection.vertices.length > 1);
|
||||
|
||||
|
||||
|
||||
var wrap = selection.selectAll('.preset-input-wrap')
|
||||
.data([0]);
|
||||
|
||||
@@ -78,18 +99,22 @@ export function uiFieldRestrictions(field, context) {
|
||||
.attr('class', 'preset-input-wrap')
|
||||
.merge(wrap);
|
||||
|
||||
var detailEnter = wrap.selectAll('.restriction-detail')
|
||||
.data([0])
|
||||
.enter()
|
||||
var detailControl = wrap.selectAll('.restriction-detail')
|
||||
.data(isComplex ? [0]: []);
|
||||
|
||||
detailControl.exit()
|
||||
.remove();
|
||||
|
||||
var detailControlEnter = detailControl.enter()
|
||||
.append('div')
|
||||
.attr('class', 'restriction-detail');
|
||||
|
||||
detailEnter
|
||||
detailControlEnter
|
||||
.append('span')
|
||||
.attr('class', 'restriction-detail-label')
|
||||
.text('Max Detail: ');
|
||||
|
||||
detailEnter
|
||||
detailControlEnter
|
||||
.append('input')
|
||||
.attr('class', 'restriction-detail-input')
|
||||
.attr('type', 'range')
|
||||
@@ -99,13 +124,12 @@ export function uiFieldRestrictions(field, context) {
|
||||
.on('input', function() {
|
||||
var val = d3_select(this).property('value');
|
||||
_detail = +val;
|
||||
_intersection = null;
|
||||
_container.selectAll('.layer-osm *').remove();
|
||||
_container.selectAll('.layer-osm .layer-turns *').remove();
|
||||
context.storage('turn-restriction-detail', _detail);
|
||||
selection.call(restrictions);
|
||||
});
|
||||
|
||||
detailEnter
|
||||
detailControlEnter
|
||||
.append('span')
|
||||
.attr('class', 'restriction-detail-text');
|
||||
|
||||
@@ -132,14 +156,6 @@ export function uiFieldRestrictions(field, context) {
|
||||
_container = containerEnter
|
||||
.merge(container);
|
||||
|
||||
// try to reuse the intersection, but always rebuild it if the graph has changed
|
||||
if (context.graph() !== _graph || !_intersection) {
|
||||
_graph = context.graph();
|
||||
_intersection = osmIntersection(_graph, _vertexID, _detail);
|
||||
}
|
||||
|
||||
var ok = (_intersection.vertices.length && _intersection.ways.length);
|
||||
|
||||
_container
|
||||
.call(renderViewer);
|
||||
}
|
||||
@@ -177,7 +193,7 @@ export function uiFieldRestrictions(field, context) {
|
||||
projection.scale(geoZoomToScale(z));
|
||||
}
|
||||
|
||||
var padTop = 30; // reserve top space for hints
|
||||
var padTop = 30; // reserve top space for hint text
|
||||
var extentCenter = projection(extent.center());
|
||||
extentCenter[1] = extentCenter[1] - padTop;
|
||||
|
||||
@@ -222,7 +238,7 @@ export function uiFieldRestrictions(field, context) {
|
||||
.call(utilSetDimensions, d)
|
||||
.call(drawVertices, vgraph, _intersection.vertices, filter, extent, z)
|
||||
.call(drawLines, vgraph, _intersection.ways, filter)
|
||||
.call(drawTurns, vgraph, _intersection.turns(_fromWayID));
|
||||
.call(drawTurns, vgraph, _intersection.turns(_fromWayID, _detail));
|
||||
|
||||
surface
|
||||
.on('click.restrictions', click)
|
||||
|
||||
Reference in New Issue
Block a user