From 1a5bc723277c63ed4ee0b31d8b477dd12010b95e Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Wed, 23 Apr 2025 11:57:47 +0200 Subject: [PATCH] be a bit more lenient when determining if a node is an address node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit consider some additional tags as "not interesting"/non-POI-like: * check_date/fixme/note/note:*/survey:* — mapping related tags * layer/level/level:ref — can be considered attributes of the address * ref:* – often used to indicate a source ID on imported data --- modules/svg/labels.js | 33 +++++++++++++++++++++------------ modules/svg/points.js | 14 ++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/modules/svg/labels.js b/modules/svg/labels.js index 52c0f2284..bc48b1fde 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -75,11 +75,6 @@ export function svgLabels(projection, context) { } - function get(array, prop) { - return function(d, i) { return array[i][prop]; }; - } - - function drawLinePaths(selection, labels, filter, classes) { var paths = selection.selectAll('path:not(.debug)') .filter(d => filter(d.entity)) @@ -374,12 +369,6 @@ export function svgLabels(projection, context) { } - function isAddressPoint(tags) { - const keys = Object.keys(tags); - return keys.length > 0 && keys.every(key => - key.startsWith('addr:') || !osmIsInterestingTag(key)); - } - function getPointLabel(entity, width, height, style) { var y = (style.geometry === 'point' ? -12 : 0); var pointOffsets = { @@ -775,7 +764,7 @@ export function svgLabels(projection, context) { } -var _textWidthCache = {}; +const _textWidthCache = {}; export function textWidth(text, size, container) { let c = _textWidthCache[size]; if (!c) c = _textWidthCache[size] = {}; @@ -791,3 +780,23 @@ export function textWidth(text, size, container) { elem.remove(); return c[text]; } + + +const nonPrimaryKeys = new Set([ + 'check_date', + 'fixme', + 'layer', + 'level', + 'level:ref', + 'note' +]); +const nonPrimaryKeysRegex = /^(ref|survey|note):/; +export function isAddressPoint(tags) { + const keys = Object.keys(tags); + return keys.length > 0 && keys.every(key => + key.startsWith('addr:') || + !osmIsInterestingTag(key) || + nonPrimaryKeys.has(key) || + nonPrimaryKeysRegex.test(key) + ); +} diff --git a/modules/svg/points.js b/modules/svg/points.js index ed6b71c25..286cd109a 100644 --- a/modules/svg/points.js +++ b/modules/svg/points.js @@ -2,32 +2,26 @@ import deepEqual from 'fast-deep-equal'; import { clamp } from 'lodash-es'; import { geoScaleToZoom } from '../geo'; -import { osmEntity, osmIsInterestingTag } from '../osm'; +import { osmEntity } from '../osm'; import { svgPointTransform } from './helpers'; import { svgTagClasses } from './tag_classes'; import { presetManager } from '../presets'; -import { textWidth } from './labels'; +import { textWidth, isAddressPoint } from './labels'; export function svgPoints(projection, context) { function markerPath(selection, klass) { - const isHousenumber = d => { - const tagKeys = Object.keys(d.tags); - if (tagKeys.length === 0) return false; - return Object.keys(d.tags).every(key => - key.startsWith('addr:') || !osmIsInterestingTag(key)); - }; const addressShieldWidth = d => { const width = textWidth(d.tags['addr:housenumber'] || d.tags['addr:housename'] || '', 10, selection.node().parentElement); return clamp(width, 10, 34) + 8; }; selection .attr('class', klass) - .attr('transform', d => isHousenumber(d) + .attr('transform', d => isAddressPoint(d.tags) ? `translate(-${addressShieldWidth(d)/2}, -8)` : 'translate(-8, -23)') .attr('d', d => { - if (!isHousenumber(d)) { + if (!isAddressPoint(d.tags)) { return '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'; } const shieldWidth = addressShieldWidth(d);