--coord }} : General function formatting and displayingcoordinate values.
: Simple function for converting decimaldegree values to DMS format.
: Simple function for converting DMS formatto decimal degree format.
: Export the link used to reach the tools
require('strict')
local math_mod = require("Module:Math")local mTemplateInvocation = require('Module:Template invocation')local mTableTools = require('Module:TableTools')local coordinates =
local current_page = mw.title.getCurrentTitlelocal page_name = mw.uri.encode(current_page.prefixedText, 'WIKI')local coord_link = '//geohack.toolforge.org/geohack.php?pagename=' .. page_name .. '¶ms='local templatestyles = 'Module:Coordinates/styles.css'
--Helper function, replacement for local function displaytitle(s, notes) local l = "Coordinates: " .. s local co = '
' .. l .. notes .. ''; return mw.getCurrentFrame:extensionTag;end--Helper function, Replacement for local function displayinline(s, notes) return s .. notesend
--Helper function, used in detecting DMS formatting local function dmsTest(first, second) if type(first) ~= 'string' or type(second) ~= 'string' then return nil end local s = (first .. second):upper return s:find('^[NS][EW]$') or s:find('^[EW][NS]$')end
--local function makeInvokeFunc(funcName) return function (frame) local args = require('Module:Arguments').getArgs(frame,) return coordinates[funcName](args, frame) endend
--Helper function, handle optional args. local function optionalArg(arg, supplement) return arg and arg .. supplement or end
--Formats any error messages generated for displaylocal function errorPrinter(errors) local result = "" for i,v in ipairs(errors) do local errorHTML = 'Coordinates: ' .. v[2] .. '' result = result .. errorHTML .. "
" end return resultend
--Determine the required CSS class to display coordinates
Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himselfdefault is the mode as specificied by the user when calling the templatemode is the display mode (dec or dms) that we will need to determine the css class for
local function displayDefault(default, mode) if defaultif default
--JSON doesn't handle .78 values, only 0.78we do want to keep our precision though, so tonumber is bad.local function jsonSafeNumber(numberString) numberString = numberString:gsub('^(%.)', '0.', 1) return numberString:gsub('^(-%.)', '-0.', 1)end
--local function addHemisphereToDec(latitude, longitude) local lat = tonumber(latitude) or 0 local returnLat if lat < 0 then -- FIXME this breaks the pre-existing precision returnLat = tostring(latitude):sub(2) .. "°S" else returnLat = (latitude or 0) .. "°N" end
local long = tonumber(longitude) or 0 local returnLong if long < 0 then -- FIXME does not handle unicode minus returnLong = tostring(longitude):sub(2) .. "°W" else returnLong = (longitude or 0) .. "°E" end return returnLat, returnLongend
--splitParam
Split the Geohack parameter string and convert it into an object.
local function splitParam(param) local out = for pair in mw.text.gsplit(param, '_', true) do local keyValue = mw.text.split(pair, ':', true) if #keyValue--geohackTypeToMarkerSymbol
Convert from Geohack's type to a Kartographer marker symbol
local function geohackTypeToMarkerSymbol(type, population) -- https://en.wikipedia.org/wiki/Template:Coord#type:T -- https://www.mediawiki.org/wiki/Extension:GeoData -- https://www.mediawiki.org/wiki/Help:Extension:Kartographer/Icons local maplinkMarkerSymbol = 'circle' local markerSymbols = if markerSymbols[type] then maplinkMarkerSymbol = markerSymbols[type] end -- https://meta.wikimedia.org/wiki/WikiMiniAtlas population = tonumber(population) if type--geohackTypeToScale
Convert from Geohack's types to Geohack's scale levels
local function geohackTypeToScale(type, population) local typeScale = local scale if typeScale[type] then scale = typeScale[type] end population = tonumber(population) if typelocal log2 = 0.693147181
--geohackTypeToScale
Convert from Geohack's scale levels to OSM style zoom levels as used by
local function geohackDimToMapZoom(dim, units) dim = tonumber(dim) if not dim or dim <= 0 then return end if units and string.lower(units)
local function labelForQID(qid) local entity = mw.wikibase and qid and (mw.wikibase.getEntityObject(qid) or mw.wikibase.getEntityObject) if entity then return entity:getLabel end return nilend
--coordLinkRenderer
Render a traditional coord-style geohacklink based on the provided information
local function coordLinkRenderer(args, coordinateSpec) local uriComponents = coordinateSpec["param"] if uriComponentslocal geodmshtml = '
' .. '' .. coordinateSpec["dms-lat"] .. ' ' .. '' ..coordinateSpec["dms-long"] .. '' .. ''local geodeclat, geodeclong = addHemisphereToDec(coordinateSpec['dec-lat'], coordinateSpec['dec-long']) local geodechtml = '
' .. geodeclat .. ' ' .. geodeclong .. ''local geonumhtml = '
' .. coordinateSpec["dec-lat"] .. '; ' .. coordinateSpec["dec-long"] .. ''local inner = '
' .. geodmshtml .. '' .. ' / ' .. ''if not args["name"] then inner = inner .. geodechtml .. '
' else inner = inner .. '' .. geodechtml .. ' ' .. '