Modul:Wikidata/Formatters/globecoordinate
Vzhled
require 'Modul:No globals'
local p = {}
local lib = require 'Modul:Wikidata/lib'
function p.getRawValue(value, options)
if not options.field then
return error(lib.formatError('param-not-provided', 'field'))
elseif options.field == 'latitude' or options.field == 'longitude' or options.field == 'precision' or options.field == 'globe' then
return value[options.field]
else
return error(lib.formatError('invalid-field', options.field))
end
end
local function fastConvertDdToDms(ddValue)
local dmsArr = {
degrees = 0,
minutes = 0,
seconds = 0.0
}
if ddValue then
dmsArr.degrees = math.floor(tonumber(ddValue))
dmsArr.minutes = math.floor((tonumber(ddValue) - dmsArr["degrees"]) * 60)
dmsArr.seconds = (tonumber(ddValue) - dmsArr["degrees"] - dmsArr["minutes"]/60) * 3600
end
return dmsArr
end
function p.formatValue(value, options)
-- priklad pouze -- je tam asi X chyb (mimo jine N vs S a podobne)
local latDms = fastConvertDdToDms(value.latitude)
local lonDms = fastConvertDdToDms(value.longitude)
local latdmsText = mw.ustring.format('N %s° %s\' %s"', latDms["degrees"], latDms["minutes"], latDms["seconds"])
local londmsText = mw.ustring.format('E %s° %s\' %s"', lonDms["degrees"], lonDms["minutes"], lonDms["seconds"])
return latdmsText .. " " .. londmsText
end
return p