Skip to content

Commit aab9609

Browse files
authored
Do not render short bridges for medium zoom levels (#123)
Fixes #115 Changes: - store way length of railway lines - interpolate zoom level for a minimum length to render bridges - tunnels are always rendered, unrelated to length Before ![image](https://github.com/user-attachments/assets/e9a35218-6007-4837-867e-bcbf80090d59) After ![image](https://github.com/user-attachments/assets/193633a2-8402-488c-9362-2ca0ac08ca28)
1 parent d462268 commit aab9609

File tree

4 files changed

+68
-50
lines changed

4 files changed

+68
-50
lines changed

import/openrailwaymap.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ local railway_line = osm2pgsql.define_table({
6767
columns = {
6868
{ column = 'id', sql_type = 'serial', create_only = true },
6969
{ column = 'way', type = 'linestring' },
70+
{ column = 'way_length', type = 'real' },
7071
{ column = 'railway', type = 'text' },
7172
-- TODO build feature column
7273
{ column = 'feature', type = 'text' },
@@ -519,8 +520,10 @@ function osm2pgsql.process_way(object)
519520
end
520521
end
521522

523+
local way = object:as_linestring()
522524
railway_line:insert({
523-
way = object:as_linestring(),
525+
way = way,
526+
way_length = way:length(),
524527
railway = tags['railway'],
525528
service = tags['service'],
526529
usage = tags['usage'],

import/sql/tile_views.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CREATE OR REPLACE VIEW railway_line_high AS
44
SELECT
55
id,
66
way,
7+
way_length,
78
railway,
89
CASE
910
WHEN railway = 'proposed' THEN COALESCE(proposed_railway, 'rail')
@@ -68,6 +69,7 @@ CREATE OR REPLACE VIEW railway_line_high AS
6869
(SELECT
6970
id,
7071
way,
72+
way_length,
7173
railway,
7274
usage,
7375
service,

martin/configuration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ postgres:
113113
properties:
114114
# TODO calculate labels in frontend
115115
id: integer
116+
way_length: number
116117
railway: string
117118
feature: string
118119
usage: string

proxy/js/styles.mjs

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,55 +1213,6 @@ const layers = {
12131213
'line-gap-width': railway_tunnel_casing_add,
12141214
}
12151215
},
1216-
{
1217-
id: 'railway_tunnel_fill',
1218-
type: 'line',
1219-
minzoom: 8,
1220-
source: 'high',
1221-
'source-layer': 'railway_line_high',
1222-
filter: ['all',
1223-
['get', 'tunnel'],
1224-
['!=', ['get', 'railway'], 'construction'],
1225-
['!=', ['get', 'railway'], 'proposed'],
1226-
['!=', ['get', 'railway'], 'abandoned'],
1227-
['!=', ['get', 'railway'], 'razed'],
1228-
],
1229-
layout: {
1230-
'line-join': 'round',
1231-
'line-cap': 'round',
1232-
},
1233-
paint: standardFillPaint([1]),
1234-
},
1235-
{
1236-
id: 'railway_tunnel_bright',
1237-
type: 'line',
1238-
minzoom: 8,
1239-
source: 'high',
1240-
'source-layer': 'railway_line_high',
1241-
filter: ['all',
1242-
['get', 'tunnel'],
1243-
['!=', ['get', 'railway'], 'construction'],
1244-
['!=', ['get', 'railway'], 'proposed'],
1245-
['!=', ['get', 'railway'], 'abandoned'],
1246-
['!=', ['get', 'railway'], 'razed'],
1247-
],
1248-
layout: {
1249-
'line-join': 'round',
1250-
'line-cap': 'round',
1251-
},
1252-
paint: {
1253-
...standardFillPaint([1]),
1254-
'line-color': 'rgba(255, 255, 255, 50%)',
1255-
}
1256-
},
1257-
preferredDirectionLayer('railway_tunnel_preferred_direction', ['all',
1258-
['get', 'tunnel'],
1259-
['any',
1260-
['==', ['get', 'preferred_direction'], 'forward'],
1261-
['==', ['get', 'preferred_direction'], 'backward'],
1262-
['==', ['get', 'preferred_direction'], 'both'],
1263-
]
1264-
]),
12651216
{
12661217
id: 'railway_line_casing',
12671218
type: 'line',
@@ -1358,6 +1309,55 @@ const layers = {
13581309
'line-dasharray': razed_dasharray,
13591310
}
13601311
},
1312+
{
1313+
id: 'railway_tunnel_fill',
1314+
type: 'line',
1315+
minzoom: 8,
1316+
source: 'high',
1317+
'source-layer': 'railway_line_high',
1318+
filter: ['all',
1319+
['get', 'tunnel'],
1320+
['!=', ['get', 'railway'], 'construction'],
1321+
['!=', ['get', 'railway'], 'proposed'],
1322+
['!=', ['get', 'railway'], 'abandoned'],
1323+
['!=', ['get', 'railway'], 'razed'],
1324+
],
1325+
layout: {
1326+
'line-join': 'round',
1327+
'line-cap': 'round',
1328+
},
1329+
paint: standardFillPaint([1]),
1330+
},
1331+
{
1332+
id: 'railway_tunnel_bright',
1333+
type: 'line',
1334+
minzoom: 8,
1335+
source: 'high',
1336+
'source-layer': 'railway_line_high',
1337+
filter: ['all',
1338+
['get', 'tunnel'],
1339+
['!=', ['get', 'railway'], 'construction'],
1340+
['!=', ['get', 'railway'], 'proposed'],
1341+
['!=', ['get', 'railway'], 'abandoned'],
1342+
['!=', ['get', 'railway'], 'razed'],
1343+
],
1344+
layout: {
1345+
'line-join': 'round',
1346+
'line-cap': 'round',
1347+
},
1348+
paint: {
1349+
...standardFillPaint([1]),
1350+
'line-color': 'rgba(255, 255, 255, 50%)',
1351+
}
1352+
},
1353+
preferredDirectionLayer('railway_tunnel_preferred_direction', ['all',
1354+
['get', 'tunnel'],
1355+
['any',
1356+
['==', ['get', 'preferred_direction'], 'forward'],
1357+
['==', ['get', 'preferred_direction'], 'backward'],
1358+
['==', ['get', 'preferred_direction'], 'both'],
1359+
]
1360+
]),
13611361
{
13621362
id: 'railway_construction_fill',
13631363
type: 'line',
@@ -1447,6 +1447,12 @@ const layers = {
14471447
'source-layer': 'railway_line_high',
14481448
filter: ['all',
14491449
['get', 'bridge'],
1450+
['>=', ['get', 'way_length'],
1451+
['interpolate', ["exponential", .5], ['zoom'],
1452+
8, 0.008,
1453+
16, 0
1454+
],
1455+
],
14501456
['!=', ['get', 'railway'], 'construction'],
14511457
['!=', ['get', 'railway'], 'proposed'],
14521458
['!=', ['get', 'railway'], 'abandoned'],
@@ -1466,6 +1472,12 @@ const layers = {
14661472
'source-layer': 'railway_line_high',
14671473
filter: ['all',
14681474
['get', 'bridge'],
1475+
['>=', ['get', 'way_length'],
1476+
['interpolate', ["exponential", .5], ['zoom'],
1477+
8, 0.008,
1478+
16, 0
1479+
],
1480+
],
14691481
['!=', ['get', 'railway'], 'construction'],
14701482
['!=', ['get', 'railway'], 'proposed'],
14711483
['!=', ['get', 'railway'], 'abandoned'],

0 commit comments

Comments
 (0)