Module:Coordinates: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(comments and formatting)
(more formatting / comments)
Line 42: Line 42:


Transforms decimal format latitude and longitude into the a
Transforms decimal format latitude and longitude into the a
structure to used in displaying coordinates
structure to be used in displaying coordinates
]]
]]
function parseDec( lat, long, format )
function parseDec( lat, long, format )
Line 77: Line 77:
end
end


--[[
parseDec

Transforms degrees, minutes, seconds format latitude and longitude
into the a structure to be used in displaying coordinates
]]
function parseDMS( lat_d, lat_m, lat_s, lat_f, long_d, long_m, long_s, long_f, format )
function parseDMS( lat_d, lat_m, lat_s, lat_f, long_d, long_m, long_s, long_f, format )
local coordinateSpec = {}
local coordinateSpec = {}
Line 83: Line 89:
lat_f = lat_f:upper();
lat_f = lat_f:upper();
long_f = long_f:upper();
long_f = long_f:upper();
-- Specified backward
-- Check if specified backward
if lat_f == 'E' or lat_f == 'W' then
if lat_f == 'E' or lat_f == 'W' then
local t_d, t_m, t_s, t_f;
local t_d, t_m, t_s, t_f;
Line 133: Line 140:
end
end


--[[
--- A function that prints a table of coordinate specifications to HTML
specPrinter

Output formatter. Takes the structure generated by either parseDec
or parseDMS and formats it for inclusion on Wikipedia.
]]
function specPrinter(args, coordinateSpec)
function specPrinter(args, coordinateSpec)
local uriComponents = coordinateSpec["param"]
local uriComponents = coordinateSpec["param"]
Line 165: Line 177:
end
end
-- TODO requires DEC formatting
local geodechtml = '<span class="geo-dec" title="Maps, aerial photos, and other data for this location">'
local geodechtml = '<span class="geo-dec" title="Maps, aerial photos, and other data for this location">'
.. geodeclat .. ' '
.. geodeclat .. ' '
Line 176: Line 187:
.. '</span>'
.. '</span>'


local inner
local inner;
inner = '<span class="' .. displayDefault(coordinateSpec["default"], "dms" ) .. '">' .. geodmshtml .. '</span>'
if args["name"] == "" or args["name"] == nil then
inner = '<span class="' .. displayDefault(coordinateSpec["default"], "dms" ) .. '">' .. geodmshtml .. '</span>'
.. '<span class="geo-multi-punct">&#xfeff; / &#xfeff;</span>'
.. '<span class="geo-multi-punct">&#xfeff; / &#xfeff;</span>'
.. '<span class="' .. displayDefault(coordinateSpec["default"], "dec" ) .. '">' .. geodechtml
.. '<span class="' .. displayDefault(coordinateSpec["default"], "dec" ) .. '">';

if args["name"] == "" or args["name"] == nil then
inner = inner .. geodechtml
.. '<span style="display:none">&#xfeff; / ' .. geonumhtml .. '</span></span>'
.. '<span style="display:none">&#xfeff; / ' .. geonumhtml .. '</span></span>'
else
else
inner = '<span class="' .. displayDefault(coordinateSpec["default"], "dms" ) .. '">' .. geodmshtml .. '</span>'
inner = inner .. '<span class="vcard">' .. geodechtml
.. '<span class="geo-multi-punct">&#xfeff; / &#xfeff;</span>'
.. '<span class="' .. displayDefault(coordinateSpec["default"], "dec" ) .. '"><span class="vcard">' .. geodechtml
.. '<span style="display:none">&#xfeff; / ' .. geonumhtml .. '</span>'
.. '<span style="display:none">&#xfeff; / ' .. geonumhtml .. '</span>'
.. '<span style="display:none">&#xfeff; (<span class="fn org">'
.. '<span style="display:none">&#xfeff; (<span class="fn org">'
Line 196: Line 207:
end
end


--[[
Formats any error messages generated for display
]]
function errorPrinter(errors)
function errorPrinter(errors)
local result = ""
local result = ""
for i,v in ipairs(errors) do
for i,v in ipairs(errors) do
local errorHTML = '<strong class="error">' .. v[2] .. ' in Module:Coordinates.' .. v[1] .."()" .. '</strong>'
local errorHTML = '<strong class="error">Module:Coordinates: ' .. v[2] .. '</strong>'
result = result .. errorHTML .. "<br />"
result = result .. errorHTML .. "<br />"
end
end
Line 205: Line 219:
end
end


--[[
--- Determine the required CSS class to display coordinates
Determine the required CSS class to display coordinates
-- Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himself

-- default is the mode as specificied by the user when calling the {{coord}} template
Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himself
-- mode is the display mode (dec or dms) that we will need to determine the css class for
default is the mode as specificied by the user when calling the {{coord}} template
mode is the display mode (dec or dms) that we will need to determine the css class for
]]
function displayDefault(default, mode)
function displayDefault(default, mode)
if default == "" then
if default == "" then
Line 221: Line 238:
end
end


--- Check the arguments to determine what type of coordinates has been input
-- Check the arguments to determine what type of coordinates has been input
function formatTest(args)
function formatTest(args)
local result, errors;
local result, errors;