mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-16 22:03:37 +02:00
b9e48d1682
This is more work to further isolate the layers that entities draw to. It makes it easier to debug what is going on, and can eventually lead to deferred drawing, if each draw function is in its own place and not dependant on anything else. I've started to replace the vertex-hover with an explicit layer for touch targets. Also had to change a lot of the svg tests, which are really brittle. Things would happen like - the surface would be created, it would kick of a deferred redraw, which would notice that the zoom was 0 and call editOff, which would remove the osm layers that were just created and that the tests were trying to draw to. These tests need proper zoom and projection otherwise nothing works.
100 lines
2.9 KiB
JavaScript
100 lines
2.9 KiB
JavaScript
import { dataFeatureIcons } from '../../data';
|
|
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) {
|
|
selection
|
|
.attr('class', klass)
|
|
.attr('transform', 'translate(-8, -23)')
|
|
.attr('d', 'M 17,8 C 17,13 11,21 8.5,23.5 C 6,21 0,13 0,8 C 0,4 4,-0.5 8.5,-0.5 C 13,-0.5 17,4 17,8 z');
|
|
}
|
|
|
|
function sortY(a, b) {
|
|
return b.loc[1] - a.loc[1];
|
|
}
|
|
|
|
|
|
return function drawPoints(selection, graph, entities, filter) {
|
|
var wireframe = context.surface().classed('fill-wireframe');
|
|
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);
|
|
|
|
|
|
var layer = selection.selectAll('.layer-points .layer-points-points');
|
|
|
|
var groups = layer.selectAll('g.point')
|
|
.filter(filter)
|
|
.data(points, osmEntity.key);
|
|
|
|
groups.exit()
|
|
.remove();
|
|
|
|
var enter = groups.enter()
|
|
.append('g')
|
|
.attr('class', function(d) { return 'node point ' + d.id; })
|
|
.order();
|
|
|
|
enter
|
|
.append('path')
|
|
.call(markerPath, 'shadow');
|
|
|
|
enter
|
|
.append('ellipse')
|
|
.attr('cx', 0.5)
|
|
.attr('cy', 1)
|
|
.attr('rx', 6.5)
|
|
.attr('ry', 3)
|
|
.attr('class', 'stroke');
|
|
|
|
enter
|
|
.append('path')
|
|
.call(markerPath, 'stroke');
|
|
|
|
enter
|
|
.append('use')
|
|
.attr('transform', 'translate(-5, -19)')
|
|
.attr('class', 'icon')
|
|
.attr('width', '11px')
|
|
.attr('height', '11px');
|
|
|
|
groups = groups
|
|
.merge(enter)
|
|
.attr('transform', svgPointTransform(projection))
|
|
.call(svgTagClasses());
|
|
|
|
// Selecting the following implicitly
|
|
// sets the data (point entity) on the element
|
|
groups.select('.shadow');
|
|
groups.select('.stroke');
|
|
groups.select('.icon')
|
|
.attr('xlink:href', function(entity) {
|
|
var preset = context.presets().match(entity, graph);
|
|
var picon = preset && preset.icon;
|
|
|
|
if (!picon)
|
|
return '';
|
|
else {
|
|
var isMaki = dataFeatureIcons.indexOf(picon) !== -1;
|
|
return '#' + picon + (isMaki ? '-11' : '');
|
|
}
|
|
});
|
|
};
|
|
}
|