![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 1,150,000 pages, or roughly 2% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
On English Wikipedia, this module is called by {{Maplink}}
, see that template's documentation for usage instructions.
Usage
- Standard usage
- Just use {{Maplink}}, which passes its parameters to this module's main function as default.
- If a page has a rendering time by Lua of between 5 seconds and 10 seconds using {{Maplink}} the use of the direct module call by syntax like:
{{#tag:mapframe|[raw GeoJSON]|frameless=[1 for frame]|align=[left/right/center]|text=[caption]|width=[in px]|height=[in px]|latitude=[decimal degrees]|longitude=[decimal degrees]|zoom=[zoom factor]}}
saves Lua over-head. An example of this substitution is at https://en.wikipedia.org/w/index.php?diff=970846012. Such code minimises the chances of hitting the ten second Lua timeout if the back-end servers are busy.
- If a page has a rendering time by Lua of between 5 seconds and 10 seconds using {{Maplink}} the use of the direct module call by syntax like:
- From another module
-
- Import this module, e.g.
local mf = require('Module:Mapframe')
- Pass a table of parameter names/values to the _main function. See {{Maplink}} documentation for parameter names and descriptions. E.g.
local mapframe = mf._main(parameters)
- Preprocess _main's output before returning it, e.g.
return frame:preprocess(mapframe)
- Import this module, e.g.
Set up on another wiki
- Create template and module:
- Import this module and its template to that wiki (or copy the code over, giving attribution in the edit summary). Optionally, give them a name that makes sense in that wiki's language
- On Wikidata, add them to the items Module:Mapframe (Q52554979) and Template:Maplink (Q27882107)
- Localise the module
- Edit the top bits of the module, between the comments
-- ##### Localisation (L10n) settings #####
and-- #### End of L10n settings ####
, replacing values between"
"
symbols with local values (when necessary)
- Edit the top bits of the module, between the comments
- Add documentation
- to the template (e.g. by translating Template:Maplink/doc, adjusting as necessary per any localisations made in the previous step)
- to the module (please transfer/translate these instructions so that wikimedians who read your wiki but not the English Wikipedia can also set up the module and template on another wiki).
--Parameter for cleaned-up parent.args (whitespace trimmed, blanks removed)
local Args = {}
local defaults = {}
function setCleanArgs(argsTable)
local cleanArgs = {}
for key, val in pairs(argsTable) do
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
if val ~= '' then
cleanArgs[key] = val
end
else
cleanArgs[key] = val
end
end
return cleanArgs
end
function makeContent(args)
if args.raw then
return args.raw
end
local content = {};
local contentIndex = '';
while Args['type'..contentIndex] do
local contentArgs = {}
contentArgs['type'] = Args['type'..contentIndex]
--todo: Add other relevant args
content[contentIndex or 1] = makeContentJson(contentArgs)
if contentIndex == '' then
contentIndex = 1
else
contentIndex = contentIndex + 1
end
end
--Single item, no array needed
if #content==1 then
return content[1]
end
--Multiple items get placed in an array
local contentArray = '[\n' .. table.concat( content, ',\n') .. '\n]'
return contentArray
end
function makeContentJson(contentArgs)
local data = {}
if contentArgs.type == 'point' then
data.type = "Feature"
else
data.type = "ExternalData"
end
--todo: fill out rest of data
return mw.text.jsonEncode(data)
end
function makeTagAttribs(args, isTitle)
local attribs = {}
if args.zoom then
attribs.zoom = args.zoom
end
-- todo: all the others
return attribs
end
function makeTitleOutput(args, tagContent)
local titleTag = mw.text.tag('maplink', makeTagAttribs(args, true), tagContent)
local spanAttribs = {
style = "font-size: small;",
id = "coordinates"
}
return mw.text.tag('span', spanAttribs, titleTag)
end
function makeInlineOutput(args, tagContent)
local tagName = 'maplink'
if args.frame then
tagName = 'mapframe'
end
return mw.text.tag(tagName, makeTagAttribs(args), tagContent)
end
local p = {}
function p.main(frame)
local parent = frame.getParent(frame)
Args = setCleanArgs(parent.args)
local tagContent = makeContent(Args)
local display = mw.text.split(Args.display, '%s*,%s*')
local displayInTitle = display[1] == 'title' or display[2] == 'title'
local displayInline = display[1] == 'inline' or display[2] == 'inline'
if displayInTitle and displayInline then
return makeTitleOutput(args, tagContent) .. makeInlineOutput(args, tagContent)
elseif displayInTitle then
return makeTitleOutput(args, tagContent)
elseif displayInline then
return makeInlineOutput(args, tagContent)
else
error( 'Invalid display parameter')
end
end
return p