X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/59416178bd3962aab53e87f3582c58e1361db801..e1e8182c72d00fd1d66b38e7e49662ae0532fc15:/lib-lua/themes/nominatim/init.lua diff --git a/lib-lua/themes/nominatim/init.lua b/lib-lua/themes/nominatim/init.lua index c2dfb130..6d3804e2 100644 --- a/lib-lua/themes/nominatim/init.lua +++ b/lib-lua/themes/nominatim/init.lua @@ -40,12 +40,6 @@ if type(themepark) ~= 'table' then themepark = nil end --- tables required for taginfo -module.TAGINFO_MAIN = {keys = {}, delete_tags = {}} -module.TAGINFO_NAME_KEYS = {} -module.TAGINFO_ADDRESS_KEYS = {} - - -- The single place table. local place_table_definition = { name = "place", @@ -65,6 +59,8 @@ local place_table_definition = { } local insert_row +local script_path = debug.getinfo(1, "S").source:match("@?(.*/)") +local PRESETS = loadfile(script_path .. 'presets.lua')() if themepark then themepark:add_table(place_table_definition) @@ -636,10 +632,10 @@ function module.process_tags(o) end -- name keys - local fallback = o:grab_name_parts{groups=NAMES} + local fallback = o:grab_name_parts{groups=NAME_FILTER} -- address keys - if o:grab_address_parts{groups=ADDRESS_TAGS} > 0 and fallback == nil then + if o:grab_address_parts{groups=ADDRESS_FILTER} > 0 and fallback == nil then fallback = {'place', 'house', PlaceTransform.always} end if o.address.country ~= nil and #o.address.country ~= 2 then @@ -686,13 +682,27 @@ function module.set_prefilters(data) end -function module.ignore_tags(data) +function module.ignore_keys(data) + if type(data) == 'string' then + local preset = data + data = PRESETS.IGNORE_KEYS[data] + if data == nil then + error('Unknown preset for ignored keys: ' .. preset) + end + end merge_filters_into_main('delete', data) add_pre_filter{delete = data} end function module.add_for_extratags(data) + if type(data) == 'string' then + local preset = data + data = PRESETS.EXTRATAGS[data] or PRESETS.IGNORE_KEYS[data] + if data == nil then + error('Unknown preset for extratags: ' .. preset) + end + end merge_filters_into_main('extra', data) add_pre_filter{extra = data} end @@ -709,11 +719,25 @@ function module.set_main_tags(data) MAIN_KEYS[key] = nil end end - module.add_main_tags(data) + module.modify_main_tags(data) end -function module.add_main_tags(data) +function module.modify_main_tags(data) + if type(data) == 'string' then + local preset = data + if data:sub(1, 7) == 'street/' then + data = PRESETS.MAIN_TAGS_STREETS[data:sub(8)] + elseif data:sub(1, 4) == 'poi/' then + data = PRESETS.MAIN_TAGS_POIS(data:sub(5)) + else + data = PRESETS.MAIN_TAGS[data] + end + if data == nil then + error('Unknown preset for main tags: ' .. preset) + end + end + for k, v in pairs(data) do if MAIN_KEYS[k] == nil then MAIN_KEYS[k] = {} @@ -735,47 +759,87 @@ function module.add_main_tags(data) end -function module.set_name_tags(data) - NAMES = module.tag_group(data) +function module.modify_name_tags(data) + if type(data) == 'string' then + local preset = data + data = PRESETS.NAME_TAGS[data] + if data == nil then + error('Unknown preset for name keys: ' .. preset) + end + end - for _, lst in pairs(data) do - for _, k in ipairs(lst) do - local key = process_key(k) - if key ~= nil then - module.TAGINFO_NAME_KEYS[key] = true - end + for k,v in pairs(data) do + if next(v) then + NAMES[k] = v + else + NAMES[k] = nil end end + NAME_FILTER = module.tag_group(NAMES) remove_group_from_main('fallback:name') - merge_filters_into_main('fallback:name', data.house) + if data.house ~= nil then + merge_filters_into_main('fallback:name', data.house) + end +end + + +function module.set_name_tags(data) + NAMES = {} + module.modify_name_tags(data) end function module.set_address_tags(data) - if data.postcode_fallback ~= nil then - POSTCODE_FALLBACK = data.postcode_fallback - data.postcode_fallback = nil - end - ADDRESS_TAGS = module.tag_group(data) - - for _, lst in pairs(data) do - if lst ~= nil then - for _, k in ipairs(lst) do - local key = process_key(k) - if key ~= nil then - module.TAGINFO_ADDRESS_KEYS[key] = true - end - end + ADDRESS_TAGS = {} + module.modify_address_tags(data) +end + + +function module.modify_address_tags(data) + if type(data) == 'string' then + local preset = data + data = PRESETS.ADDRESS_TAGS[data] + if data == nil then + error('Unknown preset for address keys: ' .. preset) + end + end + + for k, v in pairs(data) do + if k == 'postcode_fallback' then + POSTCODE_FALLBACK = v + elseif next(v) == nil then + ADDRESS_TAGS[k] = nil + else + ADDRESS_TAGS[k] = v end end + ADDRESS_FILTER = module.tag_group(ADDRESS_TAGS) + remove_group_from_main('fallback:address') - remove_group_from_main('fallback:postcode') merge_filters_into_main('fallback:address', data.main) + merge_filters_into_main('fallback:address', data.interpolation) + remove_group_from_main('fallback:postcode') if POSTCODE_FALLBACK then merge_filters_into_main('fallback:postcode', data.postcode) end - merge_filters_into_main('fallback:address', data.interpolation) +end + + +function module.set_address_tags(data) + ADDRESS_TAGS_SOURCE = {} + module.modify_address_tags(data) +end + + +function module.set_postcode_fallback(enable) + if POSTCODE_FALLBACK ~= enable then + remove_group_from_main('fallback:postcode') + if enable then + merge_filters_into_main('fallback:postcode', ADDRESS_TAGS.postcode) + end + end + POSTCODE_FALLBACK = enable end @@ -834,4 +898,9 @@ function module.set_relation_types(data) end end + +function module.get_taginfo() + return {main = MAIN_KEYS, name = NAMES, address = ADDRESS_TAGS} +end + return module