Module:Coordinates: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
(comments and formatting)
Line 1: Line 1:
--[[
-- A module that mimics the functionality of Template:Coord and its sub templates
This module is intended to replace the functionality of {{Coord}} and related
-- The attempt is to actually mimic a conversion of an often used en.wp template in the way
tmeplates. It provides several methods, including
-- that most templates will actually be converted by the wiki users.
-- Attempt is not really to write a nice and proper module from scratch :D
local math_mod = require "Module:Math";


{{#Invoke:Coordinates | coord }}

Which provides the functionality to generate a coordinate link equivalent to
{{Coord}}

]]

math_mod = require( "Module:Math" );
globalFrame = nil
globalFrame = nil

coordinates = {};
coordinates = {};


--- Replacement for {{coord/display/title}}
--[[ Helper function, replacement for {{coord/display/title}} ]]
function displaytitle (s)
function displaytitle (s)
local l = "[[Geographic coordinate system|Coordinates]]: " .. s
local l = "[[Geographic coordinate system|Coordinates]]: " .. s
Line 15: Line 22:
end
end


--- Replacement for {{coord/display/inline}}
--[[ Helper function, Replacement for {{coord/display/inline}} ]]
function displayinline (s)
function displayinline (s)
return s
return s
end
end


--[[ Helper function, used in detecting DMS formatting ]]
--- Test if the arguments imply that DMS might be in use
local dmsTest = function(first, second)
local dmsTest = function(first, second)
local concatenated = first:upper() .. second:upper();
local concatenated = first:upper() .. second:upper();
Line 31: Line 38:
end
end


--[[
--- Parse the frame assuming that it is in dec format.
parseDec
-- @frame

-- @returns a table with all information needed to display coordinates
Transforms decimal format latitude and longitude into the a
structure to used in displaying coordinates
]]
function parseDec( lat, long, format )
function parseDec( lat, long, format )
local coordinateSpec = {}
local coordinateSpec = {}
Line 59: Line 69:
end
end


--[[ Helper function, handle optional args. ]]
function optionalArg(arg, suplement)
function optionalArg(arg, suplement)
if arg ~= nil and arg ~= "" then
if arg ~= nil and arg ~= "" then
Line 64: Line 75:
end
end
return ""
return ""
end

function isEmpty(arg)
if arg == nil or arg == "" then
return true
end
return false
end
end


Line 97: Line 101:
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS', true );
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS', true );
if isEmpty(long_d) then
if long_d == nil or long_d == "" then
table.insert(errors, {"parseDMS", "Missing longitude" })
table.insert(errors, {"parseDMS", "Missing longitude" })
end
end
Line 345: Line 349:
local precision = 0
local precision = 0
if not isEmpty(seconds_str) then
if seconds_str ~= nil and seconds_str ~= '' then
precision = 5 + math.max( math_mod._precision(seconds_str), 0 );
precision = 5 + math.max( math_mod._precision(seconds_str), 0 );
elseif not isEmpty(minutes_str) then
elseif minutes_str ~= nil and minutes_str ~= '' then
precision = 3 + math.max( math_mod._precision(minutes_str), 0 );
precision = 3 + math.max( math_mod._precision(minutes_str), 0 );
else
else