Module:SaintMap: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
Line 2: Line 2:


function p.getMapData(frame)
function p.getMapData(frame)
    local saintName = frame.args.saintName or frame:getParent().args.saintName
     local result = {}
     local result = {}
     local queries = {
     local queries = {
Line 12: Line 13:
     }
     }
     for _, q in ipairs(queries) do
     for _, q in ipairs(queries) do
         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=}}'
         local query = '{{#cargo_query:tables=Saints|fields=' .. q.field .. '=Coordinates,' .. q.label .. '=Label|where=SaintName="' .. saintName .. '" AND ' .. q.field .. ' IS NOT NULL AND ' .. q.label .. ' IS NOT NULL|format=template|template=SaintMapPoint|default=}}'
         local queryResult = frame:preprocess(query)
         local queryResult = frame:preprocess(query)
         if queryResult and queryResult ~= '' then
         if queryResult and queryResult ~= '' then
             if q.offset then
             if q.offset then
                -- Extract latitude and longitude
                 local lat, lon, label = queryResult:match('^(%-?%d+%.%d+),(%-?%d+%.%d+)~(.+)$')
                 local lat, lon = queryResult:match('^(%-?%d+%.%d+),(%-?%d+%.%d+)~(.+)$')
                 if lat and lon then
                 if lat and lon then
                    -- Add 0.0001 to latitude
                     lat = tonumber(lat) + 0.0001
                     lat = tonumber(lat) + 0.0001
                     queryResult = string.format('%.6f,%.6f~%s', lat, tonumber(lon), queryResult:match('~(.+)$'))
                     queryResult = string.format('%.6f,%.6f~%s', lat, tonumber(lon), label)
                 end
                 end
             end
             end

Navigation menu