Skip to content

Commit f91ee1d

Browse files
committed
Shortbread style: Improve z-order calculation for streets layer
1 parent c518a38 commit f91ee1d

File tree

2 files changed

+78
-124
lines changed

2 files changed

+78
-124
lines changed

themes/shortbread_v1/topics/streets.lua

Lines changed: 42 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,34 @@ themepark:add_table{
159159

160160
-- ---------------------------------------------------------------------------
161161

162-
local Z_STEP = 14
162+
local Z_STEP_PER_LAYER = 100
163163

164164
local highway_lookup = {
165165
-- highway tag z minzoom
166-
motorway = { 10, 5 },
167-
trunk = { 9, 6 },
168-
primary = { 8, 8 },
169-
secondary = { 7, 9 },
170-
tertiary = { 6, 10 },
171-
172-
tertiary_link = { 5, 12 },
173-
secondary_link = { 5, 12 },
174-
primary_link = { 5, 12 },
175-
trunk_link = { 5, 12 },
176-
motorway_link = { 5, 12 },
177-
178-
unclassified = { 5, 12 },
179-
residential = { 5, 12 },
180-
busway = { 5, 12 },
181-
busway_guideway = { 5, 12 },
182-
road = { 5, 12 },
166+
motorway = { 34, 5 },
167+
trunk = { 33, 6 },
168+
primary = { 32, 8 },
169+
secondary = { 31, 9 },
170+
tertiary = { 30, 10 },
171+
172+
unclassified = { 20, 12 },
173+
residential = { 20, 12 },
174+
busway = { 20, 12 },
175+
busway_guideway = { 20, 12 },
176+
road = { 20, 12 },
177+
178+
tertiary_link = { 10, 12 },
179+
secondary_link = { 10, 12 },
180+
primary_link = { 10, 12 },
181+
trunk_link = { 10, 12 },
182+
motorway_link = { 10, 12 },
183183

184184
living_street = { 4, 13 },
185185
pedestrian = { 4, 13 },
186+
186187
service = { 3, 13 },
188+
track = { 3, 13 },
187189

188-
track = { 2, 13 },
189190
footway = { 2, 13 },
190191
path = { 2, 13 },
191192
cycleway = { 2, 13 },
@@ -196,13 +197,13 @@ local highway_lookup = {
196197
}
197198

198199
local railway_lookup = {
199-
rail = { 12, 8 },
200-
narrow_gauge = { 11, 8 },
201-
tram = { 11, 10 },
202-
light_rail = { 11, 10 },
203-
funicular = { 11, 10 },
204-
subway = { 11, 10 },
205-
monorail = { 11, 10 },
200+
rail = { 52, 8 },
201+
narrow_gauge = { 51, 8 },
202+
tram = { 51, 10 },
203+
light_rail = { 51, 10 },
204+
funicular = { 51, 10 },
205+
subway = { 51, 10 },
206+
monorail = { 51, 10 },
206207
}
207208

208209
local aeroway_lookup = {
@@ -246,8 +247,7 @@ themepark:add_proc('node', function(object, data)
246247
geom = object:as_point()
247248
}
248249
themepark.themes.core.add_name(a, object)
249-
themepark:add_debug_info(a, t)
250-
themepark:insert('streets_labels_points', a)
250+
themepark:insert('streets_labels_points', a, t)
251251
end
252252
end)
253253

@@ -260,7 +260,7 @@ local process_as_area = function(object, data)
260260
local a = {
261261
layer = data.core.layer,
262262
}
263-
a.z_order = Z_STEP * a.layer
263+
a.z_order = Z_STEP_PER_LAYER * a.layer
264264

265265
if t.highway == 'pedestrian' or t.highway == 'service' then
266266
a.kind = t.highway
@@ -272,25 +272,13 @@ local process_as_area = function(object, data)
272272

273273
a.surface = t.surface
274274

275-
if as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes' then
276-
a.tunnel = true
277-
a.z_order = a.z_order - Z_STEP
278-
else
279-
a.tunnel = false
280-
end
281-
282-
if as_bool(t.bridge) then
283-
a.bridge = true
284-
a.z_order = a.z_order + Z_STEP
285-
else
286-
a.bridge = false
287-
end
275+
a.tunnel = as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes'
276+
a.bridge = as_bool(t.bridge)
288277

289278
a.geom = object:as_polygon()
290279

291280
themepark.themes.core.add_name(a, object)
292-
themepark:add_debug_info(a, t)
293-
themepark:insert('street_polygons', a)
281+
themepark:insert('street_polygons', a, t)
294282
end
295283

296284
themepark:add_proc('way', function(object, data)
@@ -339,7 +327,7 @@ themepark:add_proc('way', function(object, data)
339327
a.bicycle = t.bicycle
340328
a.horse = t.horse
341329

342-
a.z_order = Z_STEP * a.layer + hwinfo[1]
330+
a.z_order = Z_STEP_PER_LAYER * a.layer + hwinfo[1]
343331
a.minzoom = hwinfo[2]
344332
elseif t.railway then
345333
local rwinfo = railway_lookup[t.railway]
@@ -349,56 +337,43 @@ themepark:add_proc('way', function(object, data)
349337
a.kind = t.railway
350338
a.rail = true
351339
a.service = t.service
352-
a.z_order = Z_STEP * a.layer + rwinfo[1]
340+
a.z_order = Z_STEP_PER_LAYER * a.layer + rwinfo[1]
353341
a.minzoom = rwinfo[2]
354342
if a.minzoom == 8 and t.service then
355343
a.minzoom = 10
356-
a.z_order = a.z_order + 1
344+
a.z_order = a.z_order - 2
357345
end
358346
elseif t.aeroway then
359347
local awinfo = aeroway_lookup[t.aeroway]
360348
if not awinfo then
361349
return
362350
end
363351
a.kind = t.aeroway
364-
a.z_order = Z_STEP * a.layer
352+
a.z_order = Z_STEP_PER_LAYER * a.layer
365353
a.minzoom = awinfo
366354
else
367355
return
368356
end
369357

370-
if as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes' then
371-
a.tunnel = true
372-
a.z_order = a.z_order - Z_STEP
373-
else
374-
a.tunnel = false
375-
end
376-
377-
if as_bool(t.bridge) then
378-
a.bridge = true
379-
a.z_order = a.z_order + Z_STEP
380-
else
381-
a.bridge = false
382-
end
358+
a.tunnel = as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes'
359+
a.bridge = as_bool(t.bridge)
383360

384361
set_ref_attributes(a, t)
385362

386363
a.geom = object:as_linestring()
387364

388365
themepark.themes.core.add_name(a, object)
389-
themepark:add_debug_info(a, t)
390-
391-
themepark:insert('streets', a)
366+
themepark:insert('streets', a, t)
392367

393368
if a.name or a.ref then
394-
themepark:insert('street_labels', a)
369+
themepark:insert('street_labels', a, t)
395370
end
396371

397372
if a.minzoom < 13 then -- XXX TODO some kind of off-by-one error here?
398-
themepark:insert('streets_med', a)
373+
themepark:insert('streets_med', a, t)
399374
end
400375
if a.minzoom < 10 then -- XXX TODO some kind of off-by-one error here?
401-
themepark:insert('streets_low', a)
376+
themepark:insert('streets_low', a, t)
402377
end
403378
end)
404379

themes/shortbread_v1_gen/topics/streets.lua

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -196,33 +196,34 @@ themepark:add_table{
196196

197197
-- ---------------------------------------------------------------------------
198198

199-
local Z_STEP = 14
199+
local Z_STEP_PER_LAYER = 100
200200

201201
local highway_lookup = {
202202
-- highway tag z minzoom
203-
motorway = { 10, 5 },
204-
trunk = { 9, 6 },
205-
primary = { 8, 8 },
206-
secondary = { 7, 9 },
207-
tertiary = { 6, 10 },
208-
209-
tertiary_link = { 5, 12 },
210-
secondary_link = { 5, 12 },
211-
primary_link = { 5, 12 },
212-
trunk_link = { 5, 12 },
213-
motorway_link = { 5, 12 },
214-
215-
unclassified = { 5, 12 },
216-
residential = { 5, 12 },
217-
busway = { 5, 12 },
218-
busway_guideway = { 5, 12 },
219-
road = { 5, 12 },
203+
motorway = { 34, 5 },
204+
trunk = { 33, 6 },
205+
primary = { 32, 8 },
206+
secondary = { 31, 9 },
207+
tertiary = { 30, 10 },
208+
209+
unclassified = { 20, 12 },
210+
residential = { 20, 12 },
211+
busway = { 20, 12 },
212+
busway_guideway = { 20, 12 },
213+
road = { 20, 12 },
214+
215+
tertiary_link = { 10, 12 },
216+
secondary_link = { 10, 12 },
217+
primary_link = { 10, 12 },
218+
trunk_link = { 10, 12 },
219+
motorway_link = { 10, 12 },
220220

221221
living_street = { 4, 13 },
222222
pedestrian = { 4, 13 },
223+
223224
service = { 3, 13 },
225+
track = { 3, 13 },
224226

225-
track = { 2, 13 },
226227
footway = { 2, 13 },
227228
path = { 2, 13 },
228229
cycleway = { 2, 13 },
@@ -233,13 +234,13 @@ local highway_lookup = {
233234
}
234235

235236
local railway_lookup = {
236-
rail = { 12, 8 },
237-
narrow_gauge = { 11, 8 },
238-
tram = { 11, 10 },
239-
light_rail = { 11, 10 },
240-
funicular = { 11, 10 },
241-
subway = { 11, 10 },
242-
monorail = { 11, 10 },
237+
rail = { 52, 8 },
238+
narrow_gauge = { 51, 8 },
239+
tram = { 51, 10 },
240+
light_rail = { 51, 10 },
241+
funicular = { 51, 10 },
242+
subway = { 51, 10 },
243+
monorail = { 51, 10 },
243244
}
244245

245246
local aeroway_lookup = {
@@ -296,7 +297,7 @@ local process_as_area = function(object, data)
296297
local a = {
297298
layer = data.core.layer,
298299
}
299-
a.z_order = Z_STEP * a.layer
300+
a.z_order = Z_STEP_PER_LAYER * a.layer
300301

301302
if t.highway == 'pedestrian' or t.highway == 'service' then
302303
a.kind = t.highway
@@ -308,19 +309,8 @@ local process_as_area = function(object, data)
308309

309310
a.surface = t.surface
310311

311-
if as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes' then
312-
a.tunnel = true
313-
a.z_order = a.z_order - Z_STEP
314-
else
315-
a.tunnel = false
316-
end
317-
318-
if as_bool(t.bridge) then
319-
a.bridge = true
320-
a.z_order = a.z_order + Z_STEP
321-
else
322-
a.bridge = false
323-
end
312+
a.tunnel = as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes'
313+
a.bridge = as_bool(t.bridge)
324314

325315
a.geom = object:as_polygon()
326316

@@ -374,7 +364,7 @@ themepark:add_proc('way', function(object, data)
374364
a.bicycle = t.bicycle
375365
a.horse = t.horse
376366

377-
a.z_order = Z_STEP * a.layer + hwinfo[1]
367+
a.z_order = Z_STEP_PER_LAYER * a.layer + hwinfo[1]
378368
a.minzoom = hwinfo[2]
379369
elseif t.railway then
380370
local rwinfo = railway_lookup[t.railway]
@@ -384,37 +374,26 @@ themepark:add_proc('way', function(object, data)
384374
a.kind = t.railway
385375
a.rail = true
386376
a.service = t.service
387-
a.z_order = Z_STEP * a.layer + rwinfo[1]
377+
a.z_order = Z_STEP_PER_LAYER * a.layer + rwinfo[1]
388378
a.minzoom = rwinfo[2]
389379
if a.minzoom == 8 and t.service then
390380
a.minzoom = 10
391-
a.z_order = a.z_order + 1
381+
a.z_order = a.z_order - 2
392382
end
393383
elseif t.aeroway then
394384
local awinfo = aeroway_lookup[t.aeroway]
395385
if not awinfo then
396386
return
397387
end
398388
a.kind = t.aeroway
399-
a.z_order = Z_STEP * a.layer
389+
a.z_order = Z_STEP_PER_LAYER * a.layer
400390
a.minzoom = awinfo
401391
else
402392
return
403393
end
404394

405-
if as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes' then
406-
a.tunnel = true
407-
a.z_order = a.z_order - Z_STEP
408-
else
409-
a.tunnel = false
410-
end
411-
412-
if as_bool(t.bridge) then
413-
a.bridge = true
414-
a.z_order = a.z_order + Z_STEP
415-
else
416-
a.bridge = false
417-
end
395+
a.tunnel = as_bool(t.tunnel) or t.tunnel == 'building_passage' or t.covered == 'yes'
396+
a.bridge = as_bool(t.bridge)
418397

419398
set_ref_attributes(a, t)
420399

0 commit comments

Comments
 (0)