Make sure points/vertices render the right things at different zooms

This commit is contained in:
Bryan Housel
2017-12-13 08:57:43 -05:00
parent 899abc7ef5
commit 789f1e5f6f
2 changed files with 22 additions and 9 deletions
+14 -3
View File
@@ -3,6 +3,10 @@ import { osmEntity } from '../osm';
import { svgPointTransform, svgTagClasses } from './index';
var TAU = 2 * Math.PI;
function ktoz(k) { return Math.log(k * TAU) / Math.LN2 - 8; }
export function svgPoints(projection, context) {
function markerPath(selection, klass) {
@@ -19,9 +23,16 @@ export function svgPoints(projection, context) {
return function drawPoints(selection, graph, entities, filter) {
var wireframe = context.surface().classed('fill-wireframe');
var points = wireframe ? [] : entities.filter(function(e) {
return e.geometry(graph) === 'point' && !e.directions(graph, projection).length;
});
var zoom = ktoz(projection.scale());
// points with a direction will render as vertices at higher zooms
function renderAsPoint(entity) {
return entity.geometry(graph) === 'point' &&
!(zoom >= 18 && entity.directions(graph, projection).length);
}
// all points will render as vertices in wireframe mode too
var points = wireframe ? [] : entities.filter(renderAsPoint);
points.sort(sortY);
+8 -6
View File
@@ -83,9 +83,6 @@ export function svgVertices(projection, context) {
selection.selectAll('use')
.attr('visibility', (z === 0 ? 'hidden' : null));
selection.selectAll('.viewfieldgroup')
.attr('visibility', (zoom < 18 ? 'hidden' : null));
}
@@ -141,7 +138,7 @@ export function svgVertices(projection, context) {
// Directional vertices get viewfields
var dgroups = groups.filter(function(d) { return getDirections(d); })
.selectAll('.viewfieldgroup')
.data(function(d) { return /*klass === 'vertex-hover' ? [] : */[d]; }, osmEntity.key);
.data(function data(d) { return zoom < 18 ? [] : [d]; }, osmEntity.key);
// exit
dgroups.exit()
@@ -173,6 +170,7 @@ export function svgVertices(projection, context) {
function drawVertices(selection, graph, entities, filter, extent) {
var wireframe = context.surface().classed('fill-wireframe');
var zoom = ktoz(projection.scale());
var siblings = {};
getSiblingAndChildVertices(context.selectedIDs(), graph, extent);
@@ -202,10 +200,14 @@ export function svgVertices(projection, context) {
// drawHover(selection, graph, extent, true);
// Points can also render as vertices:
// 1. in wireframe mode or
// 2. at higher zooms if they have a direction
function renderAsVertex(entity) {
var geometry = entity.geometry(graph);
return (geometry === 'vertex') ||
(geometry === 'point' && (wireframe || entity.directions(graph, projection).length));
return geometry === 'vertex' || (geometry === 'point' && (
wireframe || (zoom > 18 && entity.directions(graph, projection).length)
));
}