Skip to content

Commit

Permalink
Add render_height and render_min_height to buildings for 3d rendering (
Browse files Browse the repository at this point in the history
  • Loading branch information
keichan34 authored Jul 9, 2021
1 parent 3bba891 commit 083c639
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions resources/process-openmaptiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ZRES11 = 76.4
ZRES12 = 38.2
ZRES13 = 19.1

-- The height of one floor, in meters
BUILDING_FLOOR_HEIGHT = 3.66

-- Process node/way tags
aerodromeValues = Set { "international", "public", "regional", "military", "private" }

Expand Down Expand Up @@ -403,6 +406,7 @@ function way_function(way)
-- Set 'building' and associated
if building~="" then
way:Layer("building", true)
SetBuildingHeightAttributes(way)
SetMinZoomByArea(way)
end

Expand Down Expand Up @@ -572,6 +576,30 @@ function GetPOIRank(obj)
return nil,nil,nil
end

function SetBuildingHeightAttributes(way)
local height = tonumber(way:Find("height"), 10)
local minHeight = tonumber(way:Find("min_height"), 10)
local levels = tonumber(way:Find("building:levels"), 10)
local minLevel = tonumber(way:Find("building:min_level"), 10)

local renderHeight = BUILDING_FLOOR_HEIGHT
if height or levels then
renderHeight = height or (levels * BUILDING_FLOOR_HEIGHT)
end
local renderMinHeight = 0
if minHeight or minLevel then
renderMinHeight = minHeight or (minLevel * BUILDING_FLOOR_HEIGHT)
end

-- Fix upside-down buildings
if renderHeight < renderMinHeight then
renderHeight = renderHeight + renderMinHeight
end

way:AttributeNumeric("render_height", renderHeight)
way:AttributeNumeric("render_min_height", renderMinHeight)
end

-- ==========================================================
-- Lua utility functions

Expand Down

0 comments on commit 083c639

Please sign in to comment.