Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boundary Labels #37

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
},
"boundary_labels": {
"minzoom": 2,
"maxzoom": 14,
"source": "data/admin-points-4326/admin_points.shp",
"source_columns": true
"maxzoom": 14
},
"addresses": {
"minzoom": 14,
Expand Down
38 changes: 14 additions & 24 deletions process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,20 @@ function admin_level_valid(admin_level, is_unset_valid)
return (is_unset_valid and admin_level == "") or admin_level == "2" or admin_level == "3" or admin_level == "4"
end

-- Add boundary labels
function relation_function(relation)
local boundary = Find("boundary")
local admin_level = Find("admin_level")
local name = Find("name")

if boundary == "administrative" and (admin_level == "2" or admin_level == "3" or admin_level == "4") then
astridx marked this conversation as resolved.
Show resolved Hide resolved
LayerAsCentroid("boundary_labels")
MinZoom(2)
setNameAttributes()
Attribute("admin_level", admin_level)
astridx marked this conversation as resolved.
Show resolved Hide resolved
end
end

---- Accept boundary relations
function relation_scan_function()
if Find("type") ~= "boundary" then
Expand Down Expand Up @@ -1151,29 +1165,5 @@ function attribute_function(attr, layer)
attributes["y"] = 0
return attributes
end
if layer == "boundary_labels" then
attributes = {}
attributes["admin_level"] = attr["admin_leve"]
if attributes["admin_level"] == nil then
attributes["admin_level"] = attr["ADMIN_LEVE"]
end
attributes["admin_level"] = tonumber(attributes["admin_level"])
keys = {"name", "name_de", "name_en", "way_area"}
for index, value in ipairs(keys) do
if attr[value] == nil then
attributes[value] = attr[string.upper(value)]
else
attributes[value] = attr[value]
end
end
-- Fill with fallback values if empty
local name = attributes["name"]
local name_de = attributes["name_de"]
local name_en = attributes["name_en"]
attributes["name"] = fillWithFallback(name, name_en, name_de)
attributes["name_de"] = fillWithFallback(name_de, name, name_en)
attributes["name_en"] = fillWithFallback(name_en, name, name_de)
return attributes
end
return attr
end