Skip to content

Commit 7138704

Browse files
authored
Feature icon height for non-centered positioned icons (#670)
Followup on #657 Features with multiple icons did not output their icon height correctly for non-center-positioned icons. Now the feature icon height is calculated as ``` max(max(centered) + sum(top_bottom), left_right) ``` with centered the height of centered icons, `top_bottom` the height of the top/bottom positioned icons, and `left_right` the left/right positioned icons. Tested on http://localhost:8000/#view=18.5/45.5409841/11.5417528&style=signals: Before: <img width="1275" height="574" alt="image" src="https://github.com/user-attachments/assets/d99aa4fb-2f50-4ddd-86ae-00037074cc28" /> After: <img width="1196" height="586" alt="image" src="https://github.com/user-attachments/assets/5e6f79b9-99bc-4ced-8e20-7cda5f8e06ad" />
1 parent 138e0a8 commit 7138704

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

import/sql/signal_features.sql.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ function matchIconCase(tag, iconCase) {
138138

139139
function iconCaseSql(iconCase, matchTag, position) {
140140
if (iconCase.value.includes('{}')) {
141-
return `ARRAY[CONCAT('${iconCase.value.replace(/\{}.*$/, '{')}', ${stringSql(matchTag, iconCase)}, '${iconCase.value.replace(/^.*\{}/, '}')}${position ? `@${position}` : ''}'), ${stringSql(matchTag, iconCase)}, '${iconCase.dimensions.height}']`
141+
return `ARRAY[CONCAT('${iconCase.value.replace(/\{}.*$/, '{')}', ${stringSql(matchTag, iconCase)}, '${iconCase.value.replace(/^.*\{}/, '}')}${position ? `@${position}` : ''}'), ${stringSql(matchTag, iconCase)}, '${(position ?? 'center') === 'center' ? iconCase.dimensions.height : 0}', '${['top', 'bottom'].includes(position) ? iconCase.dimensions.height : 0}', '${['left', 'right'].includes(position) ? iconCase.dimensions.height : 0}']`
142142
} else {
143-
return `ARRAY['${iconCase.value}${position ? `@${position}` : ''}', NULL, '${iconCase.dimensions.height}']`
143+
return `ARRAY['${iconCase.value}${position ? `@${position}` : ''}', NULL, '${(position ?? 'center') === 'center' ? iconCase.dimensions.height : 0}', '${['top', 'bottom'].includes(position) ? iconCase.dimensions.height : 0}', '${['left', 'right'].includes(position) ? iconCase.dimensions.height : 0}']`
144144
}
145145
}
146146

147147
function featureIconSql(icon) {
148-
const defaultIconSql = icon.default ? `ARRAY['${icon.default}${icon.position ? `@${icon.position}` : ''}', NULL, '${icon.dimensions.height}']` : 'NULL'
148+
const defaultIconSql = icon.default ? `ARRAY['${icon.default}${icon.position ? `@${icon.position}` : ''}', NULL, '${(icon.position ?? 'center') === 'center' ? icon.dimensions.height : 0}', '${['top', 'bottom'].includes(icon.position) ? icon.dimensions.height : 0}', '${['left', 'right'].includes(icon.position) ? icon.dimensions.height : 0}']` : 'NULL'
149149

150150
if (icon.match) {
151151
return `CASE ${icon.cases.map(iconCase => `
@@ -163,7 +163,7 @@ function featureIconsSql(icons) {
163163
return featureIconSql(icons[0])
164164
} else {
165165
return `(
166-
SELECT ARRAY[string_agg(icon[1], '|'), string_agg(COALESCE(icon[2], ''), '|'), MAX(icon[3]::numeric)::text]
166+
SELECT ARRAY[string_agg(icon[1], '|'), string_agg(COALESCE(icon[2], ''), '|'), MAX(icon[3]::numeric)::text, SUM(icon[4]::numeric)::text, MAX(icon[5]::numeric)::text]
167167
FROM (
168168
${icons.map(icon => `SELECT ${featureIconSql(icon)} as icon`).join(`
169169
UNION ALL
@@ -229,7 +229,7 @@ CREATE OR REPLACE VIEW signal_features_view AS
229229
`).join('')}
230230
-- Unknown signal (${type.type})
231231
ELSE
232-
ARRAY['general/signal-unknown-${type.type}', NULL, '17.1', NULL, 'false', '${type.layer}', NULL]
232+
ARRAY['general/signal-unknown-${type.type}', NULL, '17.1', '0', '0', NULL, 'false', '${type.layer}', NULL]
233233
END
234234
END as feature_${type.type}`).join(',')}
235235
FROM signals s
@@ -244,11 +244,11 @@ CREATE OR REPLACE VIEW signal_features_view AS
244244
signal_id,
245245
feature_${type.type}[1] as feature,
246246
feature_${type.type}[2] as feature_variable,
247-
feature_${type.type}[3]::REAL as icon_height,
248-
feature_${type.type}[4] as type,
249-
feature_${type.type}[5]::boolean as deactivated,
250-
feature_${type.type}[6]::signal_layer as layer,
251-
feature_${type.type}[7]::INT as rank
247+
GREATEST(feature_${type.type}[3]::REAL + feature_${type.type}[4]::REAL, feature_${type.type}[5]::REAL) as icon_height,
248+
feature_${type.type}[6] as type,
249+
feature_${type.type}[7]::boolean as deactivated,
250+
feature_${type.type}[8]::signal_layer as layer,
251+
feature_${type.type}[9]::INT as rank
252252
FROM signals_with_features_0
253253
WHERE feature_${type.type} IS NOT NULL
254254
`).join(`

0 commit comments

Comments
 (0)