Module:SaintMap: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "local p = {} function p.getCoordinates(frame) local result = {} local queries = { {field = 'SaintBirthCoordinates__full', label = 'SaintBirthPlace'}, {field = 'SaintDeathCoordinates__full', label = 'DeathPlace'}, {field = 'NotableCoordinates1__full', label = 'NotableLabel1'}, {field = 'NotableCoordinates2__full', label = 'NotableLabel2'}, {field = 'NotableCoordinates3__full', label = 'NotableLabel3'}, {field = 'Not...")
 
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


function p.getCoordinates(frame)
function p.getMapData(frame)
     local result = {}
     local result = {}
     local queries = {
     local queries = {
         {field = 'SaintBirthCoordinates__full', label = 'SaintBirthPlace'},
         {field = 'SaintBirthCoordinates__full', label = 'SaintBirthPlace'},
         {field = 'SaintDeathCoordinates__full', label = 'DeathPlace'},
         {field = 'SaintDeathCoordinates__full', label = 'DeathPlace', offset = true},
         {field = 'NotableCoordinates1__full', label = 'NotableLabel1'},
         {field = 'NotableCoordinates1__full', label = 'NotableLabel1'},
         {field = 'NotableCoordinates2__full', label = 'NotableLabel2'},
         {field = 'NotableCoordinates2__full', label = 'NotableLabel2'},
Line 12: Line 12:
     }
     }
     for _, q in ipairs(queries) do
     for _, q in ipairs(queries) do
         local queryResult = frame:preprocess('{{#cargo_query:tables=Saints|fields=' .. q.field .. '=Coordinates,' .. q.label .. '=Label|where=SaintName="Saint Bridget of Sweden" AND ' .. q.field .. ' IS NOT NULL AND ' .. q.label .. ' IS NOT NULL|format=template|template=SaintMapPoint|default=}}')
         local query = '{{#cargo_query:tables=Saints|fields=' .. q.field .. '=Coordinates,' .. q.label .. '=Label|where=SaintName="' .. frame.args.saintName .. '" AND ' .. q.field .. ' IS NOT NULL AND ' .. q.label .. ' IS NOT NULL|format=template|template=SaintMapPoint|default=}}'
         if queryResult ~= '' then
        local queryResult = frame:preprocess(query)
         if queryResult and queryResult ~= '' then
            if q.offset then
                -- Extract latitude and longitude
                local lat, lon = queryResult:match('^(%-?%d+%.%d+),(%-?%d+%.%d+)~(.+)$')
                if lat and lon then
                    -- Add 0.0001 to latitude
                    lat = tonumber(lat) + 0.0001
                    queryResult = string.format('%.6f,%.6f~%s', lat, tonumber(lon), queryResult:match('~(.+)$'))
                end
            end
             table.insert(result, queryResult)
             table.insert(result, queryResult)
         end
         end

Navigation menu