@@ -30,6 +30,11 @@ function Set(list)
3030end
3131
3232-- Meters per pixel if tile is 256x256
33+ ZRES0 = 156542.97
34+ ZRES1 = 78271.48
35+ ZRES2 = 39135.74
36+ ZRES3 = 19567.87
37+ ZRES4 = 9783.94
3338ZRES5 = 4891.97
3439ZRES6 = 2445.98
3540ZRES7 = 1222.99
@@ -47,8 +52,8 @@ INVALID_ZOOM = 99
4752
4853-- Process node/way tags
4954aerodromeValues = Set { " international" , " public" , " regional" , " military" , " private" }
50- pavedValues = Set { " paved " , " asphalt " , " cobblestone " , " concrete " , " concrete:lanes " , " concrete:plates " , " metal " , " paving_stones " , " sett " , " unhewn_cobblestone " , " wood " }
51- unpavedValues = Set { " unpaved " , " compacted " , " dirt " , " earth " , " fine_gravel " , " grass " , " grass_paver " , " gravel " , " gravel_turf " , " ground " , " ice " , " mud " , " pebblestone " , " salt " , " sand " , " snow " , " woodchips " }
55+ unpavedValues = Set { " unpaved " , " artificial_turf " , " clay " , " compacted " , " crushed_limestone " , " dirt " , " dirt/sand " , " earth " , " fine_gravel " , " grass " , " grass_paver " , " gravel " , " gravel_turf " , " ground " , " ice " , " mud " , " pebblestone " , " rock " , " rocky " , " rocks " , " salt " , " sand " , " shells " , " snow " , " soil " , " stepping_stones " , " stone " , " woodchips " }
56+ pavedValues = Set { " paved " , " acrylic " , " asphalt " , " brick " , " bricks " , " cement " , " chipseal " , " cobblestone " , " concrete " , " concrete:lanes " , " concrete:plates " , " granite " , " interlock " , " metal " , " metal_grid " , " paving_stones " , " plastic " , " rubber " , " sett " , " tartan " , " unhewn_cobblestone " , " wood " , " grade1 " }
5257
5358-- Process node tags
5459
@@ -64,7 +69,7 @@ function capitalLevel(capital)
6469 if capital_al == 0 then
6570 return nil
6671 end
67- return capital_al
72+ return capital_al
6873end
6974
7075-- Calculate rank for place nodes
@@ -96,7 +101,7 @@ function calcRank(place, population, capital_al)
96101 end
97102 if place ~= " city" and place ~= " town" then
98103 return nil
99- end
104+ end
100105 if population > 3 * 10 ^ 6 then
101106 return 1
102107 elseif population > 1 * 10 ^ 6 then
@@ -217,19 +222,19 @@ end
217222
218223-- Process way tags
219224
220- majorRoadValues = Set { " motorway" , " trunk" , " primary" }
221- z9RoadValues = Set { " secondary" , " motorway_link" , " trunk_link" }
222- z10RoadValues = Set { " primary_link" , " secondary_link" }
223- z11RoadValues = Set { " tertiary" , " tertiary_link" , " busway" , " bus_guideway" }
225+ z4RoadValues = Set { " motorway" }
226+ z5RoadValues = Set { " trunk" }
227+ z7RoadValues = Set { " primary" }
228+ z9RoadValues = Set { " secondary" , " motorway_link" , " trunk_link" }
229+ z10RoadValues = Set { " primary_link" , " secondary_link" }
230+ z11RoadValues = Set { " tertiary" , " tertiary_link" , " busway" , " bus_guideway" }
224231-- On zoom 12, various road classes are merged into "minor"
225232z12MinorRoadValues = Set { " unclassified" , " residential" , " road" , " living_street" }
226233z12OtherRoadValues = Set { " raceway" }
227234z13RoadValues = Set { " track" , " service" }
228235manMadeRoadValues = Set { " pier" , " bridge" }
229236pathValues = Set { " footway" , " cycleway" , " bridleway" , " path" , " steps" , " pedestrian" , " platform" }
230237linkValues = Set { " motorway_link" , " trunk_link" , " primary_link" , " secondary_link" , " tertiary_link" }
231- pavedValues = Set { " paved" , " asphalt" , " cobblestone" , " concrete" , " concrete:lanes" , " concrete:plates" , " metal" , " paving_stones" , " sett" , " unhewn_cobblestone" , " wood" }
232- unpavedValues = Set { " unpaved" , " compacted" , " dirt" , " earth" , " fine_gravel" , " grass" , " grass_paver" , " gravel" , " gravel_turf" , " ground" , " ice" , " mud" , " pebblestone" , " salt" , " sand" , " snow" , " woodchips" }
233238railwayClasses = { rail = " rail" , narrow_gauge = " rail" , preserved = " rail" , funicular = " rail" , subway = " transit" , light_rail = " transit" , monorail = " transit" , tram = " transit" }
234239
235240aerowayBuildings = Set { " terminal" , " gate" , " tower" }
@@ -314,6 +319,7 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s
314319 if subclass and subclass ~= " " then
315320 Attribute (" subclass" , subclass )
316321 end
322+ local accessMinzoom = 9
317323 local layer = tonumber (Find (" layer" )) or 0
318324 AttributeInteger (" layer" , math.floor (layer ), accessMinzoom )
319325 SetBrunnelAttributes ()
@@ -328,7 +334,6 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s
328334 -- Service
329335 if (is_rail or highway_class == " service" ) and (service and service ~= " " ) then Attribute (" service" , service ) end
330336
331- local accessMinzoom = 9
332337 if is_road then
333338 local oneway = Find (" oneway" )
334339 if oneway == " yes" or oneway == " 1" then
@@ -337,13 +342,9 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s
337342 if oneway == " -1" then
338343 -- **** TODO
339344 end
340- local surface = Find (" surface" )
341- local surfaceMinzoom = 12
342- if pavedValues [surface ] then
343- Attribute (" surface" , " paved" , surfaceMinzoom )
344- elseif unpavedValues [surface ] then
345- Attribute (" surface" , " unpaved" , surfaceMinzoom )
346- end
345+ local surfaceMinzoom = 4
346+ local surface = GetSurface ()
347+ if surface ~= " " then Attribute (" surface" , surface , surfaceMinzoom ) end
347348 if Holds (" access" ) then Attribute (" access" , Find (" access" ), accessMinzoom ) end
348349 if Holds (" bicycle" ) then Attribute (" bicycle" , Find (" bicycle" ), accessMinzoom ) end
349350 if Holds (" foot" ) then Attribute (" foot" , Find (" foot" ), accessMinzoom ) end
@@ -354,6 +355,18 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s
354355 end
355356end
356357
358+ function GetSurface ()
359+ local surface = split (Find (" surface" ), " ;" )
360+ -- prioritize unpaved
361+ for _ , surfaceEntry in ipairs (surface ) do
362+ if unpavedValues [surfaceEntry ] then return " unpaved" end
363+ end
364+ for _ , surfaceEntry in ipairs (surface ) do
365+ if pavedValues [surfaceEntry ] then return " paved" end
366+ end
367+ return " "
368+ end
369+
357370-- Process way tags
358371
359372function way_function ()
@@ -424,7 +437,7 @@ function way_function()
424437 -- https://openmaptiles.org/schema/#boundary
425438 if isBoundary and not (Find (" maritime" )== " yes" ) then
426439 local mz = 0
427- if admin_level >= 3 and admin_level < 5 then mz = 4
440+ if admin_level >= 3 and admin_level < 5 then mz = 3
428441 elseif admin_level >= 5 and admin_level < 7 then mz = 8
429442 elseif admin_level == 7 then mz = 10
430443 elseif admin_level >= 8 then mz = 12
@@ -457,7 +470,7 @@ function way_function()
457470 -- Roads ('transportation' and 'transportation_name')
458471 if highway ~= " " or public_transport == " platform" then
459472 local access = Find (" access" )
460- local surface = Find ( " surface " )
473+ local surface = GetSurface ( )
461474 local is_area = (public_transport == " platform" or Find (" area" )== " yes" ) and is_closed
462475
463476 local h = highway
@@ -473,20 +486,23 @@ function way_function()
473486 under_construction = true
474487 end
475488 local minzoom = INVALID_ZOOM
476- if majorRoadValues [h ] then minzoom = 4
477- elseif h == " trunk " then minzoom = 5
478- elseif highway == " primary " then minzoom = 7
489+ if z4RoadValues [h ] then minzoom = 4
490+ elseif z5RoadValues [ h ] then minzoom = 5
491+ elseif z7RoadValues [ h ] then minzoom = 7
479492 elseif z9RoadValues [h ] then minzoom = 9
480493 elseif z10RoadValues [h ] then minzoom = 10
481494 elseif z11RoadValues [h ] then minzoom = 11
482- elseif z12MinorRoadValues [h ] then
483- minzoom = 12
484- subclass = h
485- h = " minor"
495+ elseif z12MinorRoadValues [h ] then minzoom = 12
486496 elseif z12OtherRoadValues [h ] then minzoom = 12
487497 elseif z13RoadValues [h ] then minzoom = 13
488- elseif pathValues [h ] then
489- minzoom = 14
498+ elseif pathValues [h ] then minzoom = 14
499+ end
500+
501+ if z12MinorRoadValues [h ] then
502+ subclass = h
503+ h = " minor"
504+ end
505+ if pathValues [h ] then
490506 subclass = h
491507 h = " path"
492508 end
@@ -605,16 +621,16 @@ function way_function()
605621
606622 -- 'aerodrome_label'
607623 if aeroway == " aerodrome" then
608- LayerAsCentroid (" aerodrome_label" )
609- SetNameAttributes ()
610- Attribute (" iata" , Find (" iata" ))
611- SetEleAttributes ()
612- Attribute (" icao" , Find (" icao" ))
624+ LayerAsCentroid (" aerodrome_label" )
625+ SetNameAttributes ()
626+ Attribute (" iata" , Find (" iata" ))
627+ SetEleAttributes ()
628+ Attribute (" icao" , Find (" icao" ))
613629
614- local aerodrome = Find (aeroway )
615- local class
616- if aerodromeValues [aerodrome ] then class = aerodrome else class = " other" end
617- Attribute (" class" , class )
630+ local aerodrome = Find (aeroway )
631+ local class
632+ if aerodromeValues [aerodrome ] then class = aerodrome else class = " other" end
633+ Attribute (" class" , class )
618634 end
619635
620636 -- Set 'waterway' and associated
@@ -663,7 +679,7 @@ function way_function()
663679 local class = " lake" ; if waterway ~= " " then class = " river" end
664680 if class == " lake" and Find (" wikidata" )== " Q192770" then return end
665681 Layer (" water" ,true )
666- SetMinZoomByArea (way )
682+ SetMinZoomByArea ()
667683 Attribute (" class" ,class )
668684
669685 if Find (" intermittent" )== " yes" then Attribute (" intermittent" ,1 ) end
@@ -791,26 +807,26 @@ function SetNameAttributes()
791807 if iname ~= name and default_language_attribute then
792808 Attribute (default_language_attribute , name )
793809 else main_written = iname end
794- else
810+ elseif name ~= " " then
795811 Attribute (preferred_language_attribute , name )
796812 end
797813 -- then set any additional languages
798814 for i ,lang in ipairs (additional_languages ) do
799815 iname = Find (" name:" .. lang )
800816 if iname == " " then iname = name end
801- if iname ~= main_written then Attribute (" name:" .. lang , iname ) end
817+ if iname ~= main_written and iname ~= " " then Attribute (" name:" .. lang , iname ) end
802818 end
803819end
804820
805821-- Set ele and ele_ft on any object
806822function SetEleAttributes ()
807- local ele = Find (" ele" )
823+ local ele = Find (" ele" )
808824 if ele ~= " " then
809825 local meter = math.floor (tonumber (ele ) or 0 )
810826 local feet = math.floor (meter * 3.2808399 )
811827 AttributeNumeric (" ele" , meter )
812828 AttributeNumeric (" ele_ft" , feet )
813- end
829+ end
814830end
815831
816832function SetBrunnelAttributes ()
828844-- Set minimum zoom level by area but not below given minzoom
829845function SetMinZoomByAreaWithLimit (minzoom )
830846 local area = Area ()
831- if minzoom <= 6 and area > ZRES5 ^ 2 then MinZoom (6 )
847+ if minzoom <= 1 and area > ZRES0 ^ 2 then MinZoom (1 )
848+ elseif minzoom <= 2 and area > ZRES1 ^ 2 then MinZoom (2 )
849+ elseif minzoom <= 3 and area > ZRES2 ^ 2 then MinZoom (3 )
850+ elseif minzoom <= 4 and area > ZRES3 ^ 2 then MinZoom (4 )
851+ elseif minzoom <= 5 and area > ZRES4 ^ 2 then MinZoom (5 )
852+ elseif minzoom <= 6 and area > ZRES5 ^ 2 then MinZoom (6 )
832853 elseif minzoom <= 7 and area > ZRES6 ^ 2 then MinZoom (7 )
833854 elseif minzoom <= 8 and area > ZRES7 ^ 2 then MinZoom (8 )
834855 elseif minzoom <= 9 and area > ZRES8 ^ 2 then MinZoom (9 )
0 commit comments