Support more tags, cardinal and numeric directions

This commit is contained in:
Bryan Housel
2017-12-08 16:23:35 -05:00
parent 9c649b74cd
commit 42043b2ce1

View File

@@ -72,13 +72,60 @@ export function svgVertices(projection, context) {
return icons[entity.id];
}
function getDirections(entity) {
if (entity.id in directions) return directions[entity.id];
var dir = (entity.tags['traffic_signals:direction'] || entity.tags.direction || '').toLowerCase();
var stop = ((entity.isHighwayIntersection(graph) && entity.tags.stop) || '').toLowerCase();
var goBackward = (dir === 'backward' || dir === 'both' || dir === 'all' || stop === 'all');
var goForward = (dir === 'forward' || dir === 'both' || dir === 'all' || stop === 'all');
var dir = '';
if (entity.isHighwayIntersection(graph) && (entity.tags.stop || '').toLowerCase() === 'all') {
// all-way stop tag on a highway intersection
dir = 'all';
} else {
// direction tag
dir = (
entity.tags['railway:signal:direction'] ||
entity.tags['traffic_signals:direction'] ||
entity.tags.direction ||
''
).toLowerCase();
}
// swap cardinal for numeric directions
var cardinal = {
north: 0, n: 0,
northnortheast: 22, nne: 22,
northeast: 45, ne: 45,
eastnortheast: 67, ene: 67,
east: 90, e: 90,
eastsoutheast: 112, ese: 112,
southeast: 135, se: 135,
southsoutheast: 157, sse: 157,
south: 180, s: 180,
southsouthwest: 202, ssw: 202,
southwest: 225, sw: 225,
westsouthwest: 247, wsw: 247,
west: 270, w: 270,
westnorthwest: 292, wnw: 292,
northwest: 315, nw: 315,
northnorthwest: 337, nnw: 337
};
if (cardinal[dir] !== undefined) {
dir = cardinal[dir];
}
// if direction tag is numeric, return early
if (dir !== '' && !isNaN(+dir)) {
directions[entity.id] = [(+dir) - 90]; // -90 because marker is oriented along Y not X
return directions[entity.id];
}
// determine which direction(s) this feature points
var goBackward =
(entity.tags['traffic_sign:backward'] || dir === 'backward' || dir === 'both' || dir === 'all');
var goForward =
(entity.tags['traffic_sign:forward'] || dir === 'forward' || dir === 'both' || dir === 'all');
if (!goForward && !goBackward) return;
var nodeIds = {};
@@ -87,10 +134,10 @@ export function svgVertices(projection, context) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] === entity.id) { // match current entity
if (goForward && i > 0) {
nodeIds[nodes[i - 1]] = true; // viewfield point back to prev node
nodeIds[nodes[i - 1]] = true; // viewfield points back to prev node
}
if (goBackward && i < nodes.length - 1) {
nodeIds[nodes[i + 1]] = true; // viewfield point ahead to next node
nodeIds[nodes[i + 1]] = true; // viewfield points ahead to next node
}
}
}
@@ -99,6 +146,7 @@ export function svgVertices(projection, context) {
var dirAngles = Object.keys(nodeIds).map(function (nodeId) {
return geoAngle(entity, graph.entity(nodeId), projection) * (180 / Math.PI);
});
directions[entity.id] = dirAngles;
return directions[entity.id];
}