No edit summary
No edit summary
Line 25: Line 25:
local DEFAULT_NOOP_OUTPUT = ""
local DEFAULT_NOOP_OUTPUT = ""


-- uncomment this when debugging
-- Uncomment this when debugging
-- DEFAULT_NOOP_OUTPUT = "debug: mapframe no-op: " .. info
-- DEFAULT_NOOP_OUTPUT = "debug: mapframe no-op: " .. info
-- mw.log(DEFAULT_NOOP_OUTPUT)
-- mw.log(DEFAULT_NOOP_OUTPUT)
Line 35: Line 35:
function util.trimArgs(argsTable)
function util.trimArgs(argsTable)
local cleanArgs = {}
local cleanArgs = {}
for key, val in pairs(argsTable) do
for key, val in pairs(argsTable) do
if type(val) == 'string' then
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
val = val:match('^%s*(.-)%s*$')
if val ~= '' then
if val ~= '' then
cleanArgs[key] = val
cleanArgs[key] = val
Line 45: Line 47:
end
end
end
end
return cleanArgs
return cleanArgs
end
end


function util.getBestStatement(item_id, property_id)
function util.shouldAutoRun(frame)
if not(item_id) or not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
-- Check if should be running
return false
local pargs = frame.getParent(frame).args
end
local statements = mw.wikibase.getBestStatements(item_id, property_id)
if not statements or #statements == 0 then
return false
end
local hasNoValue = ( statements[1].mainsnak and statements[1].mainsnak.snaktype == 'novalue' )
if hasNoValue then
return false
end
return statements[1]
end


function util.hasWikidataProperty(item_id, property_id)
local explicitlyOn = yesno(
return util.getBestStatement(item_id, property_id) and true or false
mw.text.trim(pargs.mapframe or "")
end
)


function util.getStatementValue(statement)
if pargs.coordinates == "{{{coordinates}}}" then
return statement and statement.mainsnak and statement.mainsnak.datavalue and statement.mainsnak.datavalue.value or nil
explicitlyOn = false
end
end


function util.relatedEntity(item_id, property_id)
if type(pargs.coordinates) == 'string'
local value = util.getStatementValue( util.getBestStatement(item_id, property_id) )
and string.match(pargs.coordinates, 'coord.missing') then
return value and value.id or false
explicitlyOn = false
end
end


function util.idType(id)
local onByDefault = (explicitlyOn == nil)
if not id then
and yesno(
return nil
mw.text.trim(frame.args.onByDefault or ""),
elseif mw.ustring.match(id, "[Pp]%d+") then
false
return "property"
)
elseif mw.ustring.match(id, "[Qq]%d+") then
return "item"
else
return nil
end
end


function util.shouldAutoRun(frame)
-- Check if should be running
local pargs = frame.getParent(frame).args
local explicitlyOn = yesno(mw.text.trim(pargs.mapframe or "")) -- true of false or nil
if pargs.coordinates == "{{{coordinates}}}" then explicitlyOn = false end
if type(pargs.coordinates) == 'string' and string.match(pargs.coordinates, 'coord.missing') then explicitlyOn = false end
local onByDefault = (explicitlyOn == nil) and yesno(mw.text.trim(frame.args.onByDefault or ""), false) -- true or false
return explicitlyOn or onByDefault
return explicitlyOn or onByDefault
end
end
Line 101: Line 80:
-- Get args from the frame (invoke call) and the parent (template call).
-- Get args from the frame (invoke call) and the parent (template call).
-- Frame arguments are default values which are overridden by parent values
-- Frame arguments are default values which are overridden by parent values
-- when both are present
-- when both are present.
local args = getArgs(frame, {parentFirst = true})
local args = getArgs(frame, {
parentFirst = true
})


-- Discard args not prefixed with "mapframe-", remove that prefix from those that remain
-- Discard args not prefixed with "mapframe-", remove that prefix
-- from those that remain.
local fixedArgs = {}
local fixedArgs = {}
for name, val in pairs(args) do
for name, val in pairs(args) do
local fixedName = string.match(name, "^mapframe%-(.+)$" )
local fixedName = string.match(
name,
"^mapframe%-(.+)$"
)
 
if fixedName then
if fixedName then
fixedArgs[fixedName] = val
fixedArgs[fixedName] = val
-- allow coord, coordinates, etc to be unprefixed
 
elseif name == "coordinates" or name == "coord" or name == "coordinate" and not fixedArgs.coord then
-- Allow coord, coordinates, etc. to be unprefixed.
elseif name == "coordinates"
or name == "coord"
or name == "coordinate"
and not fixedArgs.coord then
 
fixedArgs.coord = val
fixedArgs.coord = val
-- allow id, qid to be unprefixed, map to id (if not already present)
 
elseif name == "id" or name == "qid" and not fixedArgs.id then
-- Allow id/qid to be unprefixed.
-- Note: Bharatpedia does not resolve these through Wikibase.
elseif name == "id"
or name == "qid"
and not fixedArgs.id then
 
fixedArgs.id = val
fixedArgs.id = val
        -- allow captionstyle to be unprefixed, for compatibility with [[Module:Infobox]]
 
        elseif name == "captionstyle" and not fixedArgs.captionstyle then
-- Allow captionstyle to be unprefixed,
            fixedArgs.captionstyle = val
-- for compatibility with Module:Infobox.
elseif name == "captionstyle"
and not fixedArgs.captionstyle then
 
fixedArgs.captionstyle = val
end
end
end
end
return fixedArgs
return fixedArgs
end
end


function util.parseCustomWikitext(customWikitext)
function util.parseCustomWikitext(customWikitext)
-- infoboxImage will format an image if given wikitext containing an
-- infoboxImage will format an image if given wikitext containing
-- image, or else pass through the wikitext unmodified
-- an image, or else pass through the wikitext unmodified.
return infoboxImage({
return infoboxImage({
args = {
args = {
Line 136: Line 137:


function util.trackAndWarn(trackingCat, warning)
function util.trackAndWarn(trackingCat, warning)
    local title = mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()
    local results = title and title.namespace == 0 and trackingCat and '[[Category:'..trackingCat..']]' or ''
 
    if warning then
local results =
        local warn = require('Module:If preview')._warning
title
        results = results..warn({warning})
and title.namespace == 0
    end
and trackingCat
    return results
and '[[Category:' .. trackingCat .. ']]'
or ''
 
if warning then
local warn = require('Module:If preview')._warning
results = results .. warn({warning})
end
 
return results
end
end


function util.ternary(flag, other)
other = other or 'other'


function util.ternary(flag, other)
flag = flag == 'none' and 'no' or flag
    other = other or 'other'
 
    flag = flag == 'none' and 'no' or flag
local yesNoOut = yesno(flag, other)
    local yesNoOut = yesno(flag,other)
 
    local yes = (yesNoOut == true)
local yes = (yesNoOut == true)
    local no = (yesNoOut == false)
local no = (yesNoOut == false)
    return yes, no
 
return yes, no
end
end


local p = {}
local p = {}


p._caption = function(args)
p._caption = function(args)
if args.caption then
if args.caption then
return args.caption
return args.caption
elseif args.switcher then  
elseif args.switcher then
return util.noop("no caption or switcher")
return util.noop("no caption or switcher")
end
end
local maskItem
 
local maskType = util.idType(args.geomask)
-- Bharatpedia does not have Wikidata labels to generate
if maskType == 'item' then
-- automatic "Location in ..." captions.
maskItem = args.geomask
return util.noop("no caption")
elseif maskType == "property" then
maskItem = util.relatedEntity(args.id or mw.wikibase.getEntityIdForCurrentPage(), args.geomask)
end
local maskItemLabel = maskItem and mw.wikibase.getLabel( maskItem )
return maskItemLabel and "Location in "..maskItemLabel
or util.noop("missing maskItemLabel with type " .. (maskType or "nil") .. " and item " .. (maskItem or "nil"))
end
end


p._main = function(_config)
-- Bharatpedia does not use an external entity database.
-- All map positioning must therefore come from explicit
-- template parameters.


--A list of types for objects that are too small to allow Kartographer to take over zoom
local tracking = ''
local tinyType = {
    landmark=true,
    railwaystation=true,
    edu=true,
    pass=true,
    camera=true
}               


p._main = function(_config)
-- `config` is the args passed to this module.
    -- accumulate tracking cats
    local tracking = ''
-- `config` is the args passed to this module
local config = util.trimArgs(_config)
local config = util.trimArgs(_config)
    -- allow alias for config.coord
    config.coord = config.coord or config.coordinates


-- Require wikidata item, or specified coords
-- Allow aliases for coordinates.
local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage()
config.coord = config.coord or config.coordinates
if not(wikidataId) and not(config.coord) then
 
return false, util.trackAndWarn('Pages using infobox mapframe with missing coordinates')
----------------------------------------------------------------------
-- COORDINATES
--
-- Unlike the Wikimedia version, this module does not look up
-- coordinates from Wikidata.
----------------------------------------------------------------------
 
if not config.coord
and not (
config['frame-coord']
or config['frame-coordinates']
)
and not (
config['frame-lat']
and config['frame-long']
)
and not (
config['frame-latitude']
and config['frame-longitude']
) then
 
return false, util.trackAndWarn(
'Pages using infobox mapframe with missing coordinates'
)
end
end


-- Require coords (specified or from wikidata), so that map will be centred somewhere
----------------------------------------------------------------------
-- (P625 = coordinate location)
-- MAPFRAME ARGUMENTS
    local wdCoordinates = util.getStatementValue(util.getBestStatement(wikidataId, 'P625'))
----------------------------------------------------------------------
    if not (config.coord or wdCoordinates) then
return false, util.trackAndWarn('Pages using infobox mapframe with missing coordinates')
end


-- `args` is the arguments which will be passed to the mapframe module
local args = {}
local args = {}


-- Some defaults/overrides for infobox presentation
-- Defaults/overrides for infobox presentation.
args.display = "inline"
args.display = "inline"
args.frame = "yes"
args.frame = "yes"
args.plain = "yes"
args.plain = "yes"
args["frame-width"]  = config["frame-width"] or config.width or DEFAULT_FRAME_WIDTH
args["frame-height"] = config["frame-height"] or config.height or DEFAULT_FRAME_HEIGHT
args["frame-align"]  = "center"


args["frame-coord"] = config["frame-coordinates"] or config["frame-coord"]
args["frame-width"] =
-- Note: config["coordinates"] or config["coord"] should not be used for the alignment of the frame;
config["frame-width"]
-- see talk page ( https://en.wikipedia.org/wiki/Special:Diff/876492931 )
or config.width
or DEFAULT_FRAME_WIDTH
 
args["frame-height"] =
config["frame-height"]
or config.height
or DEFAULT_FRAME_HEIGHT
 
args["frame-align"] = "center"


-- deprecated lat and long parameters
args["frame-coord"] =
args["frame-lat"]   = config["frame-lat"] or config["frame-latitude"]
config["frame-coordinates"]
args["frame-long"]  = config["frame-long"] or config["frame-longitude"]
or config["frame-coord"]
or config.coord


    -- if zoom isn't specified from config, first check wikidata
-- Deprecated latitude/longitude parameters.
    local zoom = config.zoom or util.getStatementValue(util.getBestStatement(wikidataId, 'P6592'))
args["frame-lat"] =
    if not zoom then
config["frame-lat"]
    -- Calculate zoom from length or area (converted to km or km2)
or config["frame-latitude"]
    -- Zoom so that length or area is completely included in mapframe
    local getZoom = require('Module:Infobox dim')._zoom
    zoom = getZoom({length_km=config.length_km, length_mi=config.length_mi,
                        width_km=config.width_km, width_mi=config.width_mi,
                area_km2=config.area_km2, area_mi2=config.area_mi2,
                        area_ha=config.area_ha, area_acre=config.area_acre,
                        type=config.type, population=config.population,
                viewport_px=math.min(args["frame-width"],args["frame-height"]),
                        latitude=wdCoordinates and wdCoordinates.latitude})
    end
    args.zoom = zoom or DEFAULT_ZOOM


-- Use OSM relation ID if available; otherwise use geoshape if that is available
args["frame-long"] =
-- (geoshape is required for defunct entities, which are outside OSM's scope)
config["frame-long"]
local hasOsmRelationId = util.hasWikidataProperty(wikidataId, 'P402') -- P402 is OSM relation ID
or config["frame-longitude"]
local hasGeoshape = util.hasWikidataProperty(wikidataId, 'P3896') -- P3896 is geoshape
local wikidataProvidesGeo = hasOsmRelationId or hasGeoshape


    -- determine marker argument value, determine whether to show marker
----------------------------------------------------------------------
    local forcePoint, suppressPoint = util.ternary(config.point)
-- ZOOM
    local forceMarker, suppressMarker = util.ternary(config.marker,true)
--
-- Use an explicitly supplied zoom first.
-- If absent, calculate one from dimensions using Infobox dim.
-- No Wikidata lookup is performed.
----------------------------------------------------------------------


    forcePoint = forcePoint or forceMarker
local zoom = config.zoom
    suppressPoint = suppressPoint or suppressMarker


    local showMarker = not suppressPoint and (forcePoint or not wikidataProvidesGeo or config.coord)
if not zoom then
   
local getZoom = require('Module:Infobox dim')._zoom
    -- wikidata = "yes" turns on both shape and line
    -- wikidata = "no" turns off both shape and line
    -- otherwise show both if wikidata provides geo
    local forceWikidata, suppressWikidata = util.ternary(config.wikidata)
    local showShape = not suppressWikidata and (forceWikidata or wikidataProvidesGeo or not config.coord)
    local showLine = showShape


    -- determine shape parameter value, determine whether to show or suppress shape
zoom = getZoom({
    -- also determine whether to invert shape
length_km = config.length_km,
    local forceShape, suppressShape = util.ternary(config.shape)
length_mi = config.length_mi,
    showShape = wikidataId and not suppressShape and (forceShape or showShape)
local shapeType = config.shape == 'inverse' and 'shape-inverse' or 'shape'


    -- determine line parameter value, determine whether to show or suppress line
width_km = config.width_km,
    local forceLine, suppressLine = util.ternary(config.line)
width_mi = config.width_mi,
    showLine = wikidataId and not suppressLine and (forceLine or showLine)
 
area_km2 = config.area_km2,
area_mi2 = config.area_mi2,
 
area_ha = config.area_ha,
area_acre = config.area_acre,
 
type = config.type,
population = config.population,
 
viewport_px = math.min(
tonumber(args["frame-width"])
or tonumber(DEFAULT_FRAME_WIDTH),
 
tonumber(args["frame-height"])
or tonumber(DEFAULT_FRAME_HEIGHT)
)
})
end
 
args.zoom = zoom or DEFAULT_ZOOM
 
----------------------------------------------------------------------
-- MARKER
----------------------------------------------------------------------
 
local forcePoint, suppressPoint =
util.ternary(config.point)
 
local forceMarker, suppressMarker =
util.ternary(config.marker, true)
 
forcePoint = forcePoint or forceMarker
suppressPoint = suppressPoint or suppressMarker
 
-- With explicit coordinates, show a point marker by default
-- unless it is explicitly suppressed.
local showMarker =
not suppressPoint
and (
forcePoint
or config.coord ~= nil
)
 
----------------------------------------------------------------------
-- SHAPE / LINE
--
-- The Wikimedia version inferred these from Wikidata geometry.
-- Bharatpedia requires them to be explicitly requested.
----------------------------------------------------------------------
 
local showShape = false
local showLine = false
 
local forceShape, suppressShape =
util.ternary(config.shape)
 
if forceShape then
showShape = true
elseif suppressShape then
showShape = false
end
 
local forceLine, suppressLine =
util.ternary(config.line)
 
if forceLine then
showLine = true
elseif suppressLine then
showLine = false
end
 
local shapeType =
config.shape == 'inverse'
and 'shape-inverse'
or 'shape'
 
----------------------------------------------------------------------
-- GEOMASK / SWITCHER
----------------------------------------------------------------------
 
local maskItem


    local maskItem
-- Switcher
if config.switcher == "zooms" then
if config.switcher == "zooms" then
-- switching between zoom levels
 
local maxZoom = math.max(tonumber(args.zoom), 3) -- what zoom would have otherwise been (if 3 or more, otherwise 3)
-- Switch between zoom levels.
local minZoom = 1 -- completely zoomed out
local maxZoom =
local midZoom = math.floor((maxZoom + minZoom)/2) -- midway between maxn and min
math.max(
args.switch = "zoomed in, zoomed midway, zoomed out"
tonumber(args.zoom) or DEFAULT_ZOOM,
args.zoom = string.format("SWITCH:%d,%d,%d", maxZoom, midZoom, minZoom)
3
)
 
local minZoom = 1
 
local midZoom =
math.floor(
(maxZoom + minZoom) / 2
)
 
args.switch =
"zoomed in, zoomed midway, zoomed out"
 
args.zoom =
string.format(
"SWITCH:%d,%d,%d",
maxZoom,
midZoom,
minZoom
)
 
elseif config.switcher == "auto" then
elseif config.switcher == "auto" then
-- switching between P276 and P131 areas with recursive lookup, e.g. item's city,
 
-- that city's state, and that state's country
-- The Wikimedia version used Wikidata P276/P131
args.zoom = nil -- let kartographer determine the zoom
-- to determine this automatically.
local maskLabels = {}
--
local maskItems = {}
-- Bharatpedia has no such dependency, so this mode
local maskItemId = util.relatedEntity(wikidataId, "P276") or  util.relatedEntity(wikidataId, "P131")
-- is intentionally disabled.
local maskLabel = mw.wikibase.getLabel(maskItemId)
 
while maskItemId and maskLabel and mw.text.trim(maskLabel) ~= "" do
return false, util.trackAndWarn(
table.insert(maskLabels, maskLabel)
'Pages using infobox mapframe with unsupported automatic switcher'
table.insert(maskItems, maskItemId)
)
maskItemId = maskItemId and util.relatedEntity(maskItemId, "P131")
 
maskLabel = maskItemId and mw.wikibase.getLabel(maskItemId)
elseif config.switcher == "geomasks"
end
and config.geomask then
if #maskLabels > 1 then
 
args.switch = table.concat(maskLabels, "###")
-- Explicit geomask IDs are supported.
maskItem = "SWITCH:" .. table.concat(maskItems, ",")
args.zoom = nil
elseif #maskLabels == 1 then
 
maskItem = maskItemId[1]
local separator =
end
(
elseif config.switcher == "geomasks" and config.geomask then
mw.ustring.find(
-- switching between items in geomask parameter
config.geomask,
args.zoom = nil -- let kartographer determine the zoom
"###",
local separator = (mw.ustring.find(config.geomask, "###", 0, true ) and "###") or
0,
(mw.ustring.find(config.geomask, ";", 0, true ) and ";") or ","
true
local pattern = "%s*"..separator.."%s*"
)
local maskItems = mw.text.split(mw.ustring.gsub(config.geomask, "SWITCH:", ""), pattern)
and "###"
local maskLabels = {}
)
or
(
mw.ustring.find(
config.geomask,
";",
0,
true
)
and ";"
)
or ","
 
local pattern =
"%s*" .. separator .. "%s*"
 
local maskItems =
mw.text.split(
mw.ustring.gsub(
config.geomask,
"SWITCH:",
""
),
pattern
)
 
if #maskItems > 1 then
if #maskItems > 1 then
for i, item in ipairs(maskItems) do
 
table.insert(maskLabels, mw.wikibase.getLabel(item))
-- No external labels are available,
end
-- so use the supplied IDs as switch labels.
args.switch = table.concat(maskLabels, "###")
args.switch =
maskItem = "SWITCH:" .. table.concat(maskItems, ",")
table.concat(
maskItems,
"###"
)
 
maskItem =
"SWITCH:"
.. table.concat(
maskItems,
","
)
 
elseif #maskItems == 1 then
maskItem = maskItems[1]
end
end
end
end
 
-- resolve geomask item id (if not using geomask switcher)
----------------------------------------------------------------------
if not maskItem then -- 
-- EXPLICIT GEOMASK
local maskType = util.idType(config.geomask)
--
if maskType == 'item' then
-- Property-based geomasks such as P131 are not supported because
maskItem = config.geomask
-- they require an entity database.
elseif maskType == "property" then
----------------------------------------------------------------------
maskItem = util.relatedEntity(wikidataId, config.geomask)
 
if not maskItem and config.geomask then
 
local geomask =
mw.text.trim(
config.geomask
)
 
if geomask ~= ''
and not mw.ustring.match(
geomask,
"^[Pp]%d+$"
) then
 
maskItem = geomask
end
end
end
end


    -- if asking for shape or line from Wikidata
----------------------------------------------------------------------
    -- and if Wikidata actually has shape/line data (wikidataProvidesGeo=true)
-- ENSURE SOMETHING CAN BE DRAWN
    -- and if no geomask
----------------------------------------------------------------------
    -- and if zoom not explicitly set
 
    -- and if the object size inferred from its type is not too small
if not maskItem
    -- then let Kartographer "take over" zoom
and not showShape
    if (showLine or showShape) and wikidataProvidesGeo and not maskItem
and not showLine
      and not config.zoom and not (config.type and tinyType[config.type]) then
and not showMarker then
    args.zoom = nil
 
    end
return false, util.trackAndWarn(
'Pages using infobox mapframe with no geometry',
'No geometry specified for mapframe'
)
end
 
----------------------------------------------------------------------
-- ARGUMENT NUMBERING
----------------------------------------------------------------------


    if not maskItem and not showShape and not showLine and not showMarker then
        return false, util.trackAndWarn('Pages using infobox mapframe with no geometry','No geometry specified for mapframe')
    end
-- Keep track of arg numbering
local argNumber = ''
local argNumber = ''
local function incrementArgNumber()
local function incrementArgNumber()
if argNumber == '' then
if argNumber == '' then
argNumber = 2
argNumber = 2
Line 354: Line 513:
argNumber = argNumber + 1
argNumber = argNumber + 1
end
end
end
end
 
-- Geomask
----------------------------------------------------------------------
-- GEOMASK
----------------------------------------------------------------------
 
if maskItem then
if maskItem then
args["type"..argNumber] = "shape-inverse"
 
args["id"..argNumber] = maskItem
args["type" .. argNumber] =
args["stroke-width"..argNumber] = config["geomask-stroke-width"] or DEFAULT_GEOMASK_STROKE_WIDTH
"shape-inverse"
args["stroke-color"..argNumber] = config["geomask-stroke-color"] or config["geomask-stroke-colour"] or DEFAULT_GEOMASK_STROKE_COLOR
 
args["fill"..argNumber] = config["geomask-fill"] or DEFAULT_GEOMASK_FILL
args["id" .. argNumber] =
args["fill-opacity"..argNumber] = config["geomask-fill-opacity"] or DEFAULT_SHAPE_FILL_OPACITY
maskItem
-- Let kartographer determine zoom and position, unless it is explicitly set in config
 
if not config.zoom and not config.switcher then
args["stroke-width" .. argNumber] =
config["geomask-stroke-width"]
or DEFAULT_GEOMASK_STROKE_WIDTH
 
args["stroke-color" .. argNumber] =
config["geomask-stroke-color"]
or config["geomask-stroke-colour"]
or DEFAULT_GEOMASK_STROKE_COLOR
 
args["fill" .. argNumber] =
config["geomask-fill"]
or DEFAULT_GEOMASK_FILL
 
args["fill-opacity" .. argNumber] =
config["geomask-fill-opacity"]
or DEFAULT_SHAPE_FILL_OPACITY
 
-- Let Kartographer determine zoom and position
-- unless explicitly configured.
if not config.zoom
and not config.switcher then
 
args.zoom = nil
args.zoom = nil
args["frame-coord"] = nil
args["frame-coord"] = nil
args["frame-lat"] = nil
args["frame-lat"] = nil
args["frame-long"] = nil
args["frame-long"] = nil
local maskArea = util.getStatementValue( util.getBestStatement(maskItem, 'P2046') )
end
end
incrementArgNumber()
incrementArgNumber()
-- Hack to fix phab:T255932
 
-- Hack retained from the original module.
if not args.zoom then
if not args.zoom then
args["type"..argNumber] = "line"
 
args["id"..argNumber] = maskItem
args["type" .. argNumber] =
args["stroke-width"..argNumber] = 0
"line"
 
args["id" .. argNumber] =
maskItem
 
args["stroke-width" .. argNumber] =
0
 
incrementArgNumber()
incrementArgNumber()
end
end
end
end
 
-- Shape (or shape-inverse)
----------------------------------------------------------------------
-- SHAPE
----------------------------------------------------------------------
 
if showShape then
if showShape then
args["type"..argNumber] = shapeType
 
if hasGeoshape and not hasOsmRelationId then
args["type" .. argNumber] =
args["from"..argNumber] = string.sub( util.getStatementValue( util.getBestStatement(wikidataId, 'P3896') ), 6)
shapeType
elseif config.id then  
 
args["id"..argNumber] = config.id
-- Explicit ID only.
if config.id then
args["id" .. argNumber] =
config.id
 
elseif config.from then
args["from" .. argNumber] =
config.from
end
end
args["stroke-width"..argNumber] = config["shape-stroke-width"] or config["stroke-width"] or DEFAULT_SHAPE_STROKE_WIDTH
 
args["stroke-color"..argNumber] = config["shape-stroke-color"] or config["shape-stroke-colour"] or config["stroke-color"] or config["stroke-colour"] or DEFAULT_SHAPE_STROKE_COLOR
args["stroke-width" .. argNumber] =
args["fill"..argNumber] = config["shape-fill"] or DEFAULT_SHAPE_FILL
config["shape-stroke-width"]
args["fill-opacity"..argNumber] = config["shape-fill-opacity"] or DEFAULT_SHAPE_FILL_OPACITY
or config["stroke-width"]
or DEFAULT_SHAPE_STROKE_WIDTH
 
args["stroke-color" .. argNumber] =
config["shape-stroke-color"]
or config["shape-stroke-colour"]
or config["stroke-color"]
or config["stroke-colour"]
or DEFAULT_SHAPE_STROKE_COLOR
 
args["fill" .. argNumber] =
config["shape-fill"]
or DEFAULT_SHAPE_FILL
 
args["fill-opacity" .. argNumber] =
config["shape-fill-opacity"]
or DEFAULT_SHAPE_FILL_OPACITY
 
incrementArgNumber()
incrementArgNumber()
end
end
 
-- Line
----------------------------------------------------------------------
-- LINE
----------------------------------------------------------------------
 
if showLine then
if showLine then
args["type"..argNumber] = "line"
 
if hasGeoshape and not hasOsmRelationId then
args["type" .. argNumber] =
args["from"..argNumber] = string.sub( util.getStatementValue( util.getBestStatement(wikidataId, 'P3896') ), 6)
"line"
elseif config.id then  
 
args["id"..argNumber] = config.id
-- Explicit ID only.
if config.id then
args["id" .. argNumber] =
config.id
 
elseif config.from then
args["from" .. argNumber] =
config.from
end
end
args["stroke-width"..argNumber] = config["line-stroke-width"] or config["stroke-width"] or DEFAULT_LINE_STROKE_WIDTH
 
args["stroke-color"..argNumber] = config["line-stroke-color"] or config["line-stroke-colour"] or config["stroke-color"] or config["stroke-colour"] or DEFAULT_LINE_STROKE_COLOR
args["stroke-width" .. argNumber] =
config["line-stroke-width"]
or config["stroke-width"]
or DEFAULT_LINE_STROKE_WIDTH
 
args["stroke-color" .. argNumber] =
config["line-stroke-color"]
or config["line-stroke-colour"]
or config["stroke-color"]
or config["stroke-colour"]
or DEFAULT_LINE_STROKE_COLOR
 
incrementArgNumber()
incrementArgNumber()
end
end


-- Point marker
----------------------------------------------------------------------
-- POINT MARKER
----------------------------------------------------------------------
 
if showMarker then
if showMarker then
args["type"..argNumber] = "point"
 
if config.id then args["id"..argNumber] = config.id end
args["type" .. argNumber] =
if config.coord then args["coord"..argNumber] = config.coord end
"point"
if config.marker then args["marker"..argNumber] = config.marker end
 
args["marker-color"..argNumber] = config["marker-color"] or config["marker-colour"] or DEFAULT_MARKER_COLOR
if config.id then
args["id" .. argNumber] =
config.id
end
 
if config.coord then
args["coord" .. argNumber] =
config.coord
end
 
if config.marker then
args["marker" .. argNumber] =
config.marker
end
 
args["marker-color" .. argNumber] =
config["marker-color"]
or config["marker-colour"]
or DEFAULT_MARKER_COLOR
 
incrementArgNumber()
incrementArgNumber()
end
end


    -- if Wikidata doesn't link to OSM and the map has no mask or point,
----------------------------------------------------------------------
    -- then center the map on the coordinates either from the infobox or from wikidata
-- FRAME CENTERING
    if not maskItem and not showMarker and not wikidataProvidesGeo then
----------------------------------------------------------------------
        if config.coord then
            args["frame-coord"] = args["frame-coord"] or config.coord
        else
            args["frame-lat"] = args["frame-lat"] or wdCoordinates.latitude
            args["frame-long"] = args["frame-long"] or wdCoordinates.longitude
        end
        tracking = tracking..util.trackAndWarn('Pages using infobox mapframe with forced centering')
    end


    -- protect against nil frame arguments
if not maskItem
    args["frame-coord"] = args["frame-coord"] or ""
and not showShape
    args["frame-lat"] = args["frame-lat"] or ""
and not showLine
    args["frame-long"] = args["frame-long"] or ""
and showMarker then


local mapframe = args.switch and mf.multi(args) or mf._main(args)
if config.coord then
tracking = tracking..((showLine or showShape) and not wikidataProvidesGeo
 
                          and util.trackAndWarn('Pages using infobox mapframe without shape links in Wikidata')
args["frame-coord"] =
                          or '')
args["frame-coord"]
return true, mapframe.. tracking
or config.coord
 
end
end
 
----------------------------------------------------------------------
-- PROTECT AGAINST NIL FRAME ARGUMENTS
----------------------------------------------------------------------
 
args["frame-coord"] =
args["frame-coord"] or ""
 
args["frame-lat"] =
args["frame-lat"] or ""
 
args["frame-long"] =
args["frame-long"] or ""
 
----------------------------------------------------------------------
-- RENDER MAP
----------------------------------------------------------------------
 
local mapframe =
args.switch
and mf.multi(args)
or mf._main(args)
 
return true, mapframe .. tracking
end
end


-- Entry points
----------------------------------------------------------------------
-- ENTRY POINTS
----------------------------------------------------------------------


p.main = function(frame)
p.main = function(frame)
local parent = frame.getParent(frame)
 
local parentArgs = parent.args
local parent =
local _, mapframe = p._main(parentArgs)
frame.getParent(frame)
 
local parentArgs =
parent.args
 
local _, mapframe =
p._main(parentArgs)
 
return frame:preprocess(mapframe)
return frame:preprocess(mapframe)
end
end


p.auto = function(frame)
p.auto = function(frame)
if not util.shouldAutoRun(frame) then
if not util.shouldAutoRun(frame) then
return util.noop("auto should not autorun")
return util.noop(
"auto should not autorun"
)
end
end
local args = util.argsFromAuto(frame)
 
local args =
util.argsFromAuto(frame)
 
if args.custom then
if args.custom then
return frame:preprocess(util.parseCustomWikitext(args.custom))
return frame:preprocess(
util.parseCustomWikitext(
args.custom
)
)
end
end
local _, mapframe = p._main(args)
 
local _, mapframe =
p._main(args)
 
return frame:preprocess(mapframe)
return frame:preprocess(mapframe)
end
end


p.autocaption = function(frame)
p.autocaption = function(frame)
if not util.shouldAutoRun(frame) then
if not util.shouldAutoRun(frame) then
return util.noop("autocaption should not autorun")
return util.noop(
"autocaption should not autorun"
)
end
end
local args = util.argsFromAuto(frame)
 
    local caption = p._caption(args)
local args =
    return caption
util.argsFromAuto(frame)
 
local caption =
p._caption(args)
 
return caption
end
end


p.autoWithCaption = function(frame)
p.autoWithCaption = function(frame)
if not util.shouldAutoRun(frame) then
if not util.shouldAutoRun(frame) then
return util.noop("autoWithCaption should not autorun")
return util.noop(
"autoWithCaption should not autorun"
)
end
 
local args =
util.argsFromAuto(frame)
 
local wikitext
local caption
local ok
 
if args.custom then
 
ok = true
 
wikitext =
util.parseCustomWikitext(
args.custom
)
 
else
 
ok, wikitext =
p._main(args)
 
end
 
if not ok then
return wikitext
end
end
local args = util.argsFromAuto(frame)
 
    local wikitext
wikitext =
    local caption
frame:preprocess(
    local ok
wikitext
    if args.custom then
)
        ok = true
 
        wikitext = util.parseCustomWikitext(args.custom)
caption =
    else
p._caption(args)
        ok, wikitext = p._main(args)
 
    end
local data =
    if not ok then return wikitext end
mw.html.create()
    wikitext = frame:preprocess(wikitext)
:wikitext(wikitext)
    caption = p._caption(args)
 
    local data = mw.html.create():wikitext(wikitext)
data:tag('div')
    data:tag('div')
:addClass('infobox-caption')
    :addClass('infobox-caption')
:cssText(args.captionstyle)
:cssText(args.captionstyle)
:wikitext(caption)
:wikitext(caption)
    return tostring(data)
 
return tostring(data)
end
end
   
 
return p
return p

Revision as of 20:34, 28 September 2026

Documentation for this module may be created at Module:Infobox mapframe/doc

local mf = require('Module:Mapframe')
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local infoboxImage = require('Module:InfoboxImage').InfoboxImage

-- Defaults
local DEFAULT_FRAME_WIDTH = "270"
local DEFAULT_FRAME_HEIGHT = "200"
local DEFAULT_ZOOM = 10
local DEFAULT_GEOMASK_STROKE_WIDTH = "1"
local DEFAULT_GEOMASK_STROKE_COLOR = "#777777"
local DEFAULT_GEOMASK_FILL = "#888888"
local DEFAULT_GEOMASK_FILL_OPACITY = "0.25"
local DEFAULT_SHAPE_STROKE_WIDTH = "2"
local DEFAULT_SHAPE_STROKE_COLOR = "#FF0000"
local DEFAULT_SHAPE_FILL = "#606060"
local DEFAULT_SHAPE_FILL_OPACITY = "0.1"
local DEFAULT_LINE_STROKE_WIDTH = "5"
local DEFAULT_LINE_STROKE_COLOR = "#FF0000"
local DEFAULT_MARKER_COLOR = "#5E74F3"

local util = {}

function util.noop(info)
	local DEFAULT_NOOP_OUTPUT = ""

	-- Uncomment this when debugging
	-- DEFAULT_NOOP_OUTPUT = "debug: mapframe no-op: " .. info
	-- mw.log(DEFAULT_NOOP_OUTPUT)

	return DEFAULT_NOOP_OUTPUT
end

-- Trim whitespace from args, and remove empty args
function util.trimArgs(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 util.shouldAutoRun(frame)
	-- Check if should be running
	local pargs = frame.getParent(frame).args

	local explicitlyOn = yesno(
		mw.text.trim(pargs.mapframe or "")
	)

	if pargs.coordinates == "{{{coordinates}}}" then
		explicitlyOn = false
	end

	if type(pargs.coordinates) == 'string'
		and string.match(pargs.coordinates, 'coord.missing') then
		explicitlyOn = false
	end

	local onByDefault = (explicitlyOn == nil)
		and yesno(
			mw.text.trim(frame.args.onByDefault or ""),
			false
		)

	return explicitlyOn or onByDefault
end

function util.argsFromAuto(frame)
	-- Get args from the frame (invoke call) and the parent (template call).
	-- Frame arguments are default values which are overridden by parent values
	-- when both are present.
	local args = getArgs(frame, {
		parentFirst = true
	})

	-- Discard args not prefixed with "mapframe-", remove that prefix
	-- from those that remain.
	local fixedArgs = {}

	for name, val in pairs(args) do
		local fixedName = string.match(
			name,
			"^mapframe%-(.+)$"
		)

		if fixedName then
			fixedArgs[fixedName] = val

		-- Allow coord, coordinates, etc. to be unprefixed.
		elseif name == "coordinates"
			or name == "coord"
			or name == "coordinate"
			and not fixedArgs.coord then

			fixedArgs.coord = val

		-- Allow id/qid to be unprefixed.
		-- Note: Bharatpedia does not resolve these through Wikibase.
		elseif name == "id"
			or name == "qid"
			and not fixedArgs.id then

			fixedArgs.id = val

		-- Allow captionstyle to be unprefixed,
		-- for compatibility with Module:Infobox.
		elseif name == "captionstyle"
			and not fixedArgs.captionstyle then

			fixedArgs.captionstyle = val
		end
	end

	return fixedArgs
end

function util.parseCustomWikitext(customWikitext)
	-- infoboxImage will format an image if given wikitext containing
	-- an image, or else pass through the wikitext unmodified.
	return infoboxImage({
		args = {
			image = customWikitext
		}
	})
end

function util.trackAndWarn(trackingCat, warning)
	local title = mw.title.getCurrentTitle()

	local results =
		title
		and title.namespace == 0
		and trackingCat
		and '[[Category:' .. trackingCat .. ']]'
		or ''

	if warning then
		local warn = require('Module:If preview')._warning
		results = results .. warn({warning})
	end

	return results
end

function util.ternary(flag, other)
	other = other or 'other'

	flag = flag == 'none' and 'no' or flag

	local yesNoOut = yesno(flag, other)

	local yes = (yesNoOut == true)
	local no = (yesNoOut == false)

	return yes, no
end

local p = {}

p._caption = function(args)
	if args.caption then
		return args.caption
	elseif args.switcher then
		return util.noop("no caption or switcher")
	end

	-- Bharatpedia does not have Wikidata labels to generate
	-- automatic "Location in ..." captions.
	return util.noop("no caption")
end

p._main = function(_config)
	-- Bharatpedia does not use an external entity database.
	-- All map positioning must therefore come from explicit
	-- template parameters.

	local tracking = ''

	-- `config` is the args passed to this module.
	local config = util.trimArgs(_config)

	-- Allow aliases for coordinates.
	config.coord = config.coord or config.coordinates

	----------------------------------------------------------------------
	-- COORDINATES
	--
	-- Unlike the Wikimedia version, this module does not look up
	-- coordinates from Wikidata.
	----------------------------------------------------------------------

	if not config.coord
		and not (
			config['frame-coord']
			or config['frame-coordinates']
		)
		and not (
			config['frame-lat']
			and config['frame-long']
		)
		and not (
			config['frame-latitude']
			and config['frame-longitude']
		) then

		return false, util.trackAndWarn(
			'Pages using infobox mapframe with missing coordinates'
		)
	end

	----------------------------------------------------------------------
	-- MAPFRAME ARGUMENTS
	----------------------------------------------------------------------

	local args = {}

	-- Defaults/overrides for infobox presentation.
	args.display = "inline"
	args.frame = "yes"
	args.plain = "yes"

	args["frame-width"] =
		config["frame-width"]
		or config.width
		or DEFAULT_FRAME_WIDTH

	args["frame-height"] =
		config["frame-height"]
		or config.height
		or DEFAULT_FRAME_HEIGHT

	args["frame-align"] = "center"

	args["frame-coord"] =
		config["frame-coordinates"]
		or config["frame-coord"]
		or config.coord

	-- Deprecated latitude/longitude parameters.
	args["frame-lat"] =
		config["frame-lat"]
		or config["frame-latitude"]

	args["frame-long"] =
		config["frame-long"]
		or config["frame-longitude"]

	----------------------------------------------------------------------
	-- ZOOM
	--
	-- Use an explicitly supplied zoom first.
	-- If absent, calculate one from dimensions using Infobox dim.
	-- No Wikidata lookup is performed.
	----------------------------------------------------------------------

	local zoom = config.zoom

	if not zoom then
		local getZoom = require('Module:Infobox dim')._zoom

		zoom = getZoom({
			length_km = config.length_km,
			length_mi = config.length_mi,

			width_km = config.width_km,
			width_mi = config.width_mi,

			area_km2 = config.area_km2,
			area_mi2 = config.area_mi2,

			area_ha = config.area_ha,
			area_acre = config.area_acre,

			type = config.type,
			population = config.population,

			viewport_px = math.min(
				tonumber(args["frame-width"])
					or tonumber(DEFAULT_FRAME_WIDTH),

				tonumber(args["frame-height"])
					or tonumber(DEFAULT_FRAME_HEIGHT)
			)
		})
	end

	args.zoom = zoom or DEFAULT_ZOOM

	----------------------------------------------------------------------
	-- MARKER
	----------------------------------------------------------------------

	local forcePoint, suppressPoint =
		util.ternary(config.point)

	local forceMarker, suppressMarker =
		util.ternary(config.marker, true)

	forcePoint = forcePoint or forceMarker
	suppressPoint = suppressPoint or suppressMarker

	-- With explicit coordinates, show a point marker by default
	-- unless it is explicitly suppressed.
	local showMarker =
		not suppressPoint
		and (
			forcePoint
			or config.coord ~= nil
		)

	----------------------------------------------------------------------
	-- SHAPE / LINE
	--
	-- The Wikimedia version inferred these from Wikidata geometry.
	-- Bharatpedia requires them to be explicitly requested.
	----------------------------------------------------------------------

	local showShape = false
	local showLine = false

	local forceShape, suppressShape =
		util.ternary(config.shape)

	if forceShape then
		showShape = true
	elseif suppressShape then
		showShape = false
	end

	local forceLine, suppressLine =
		util.ternary(config.line)

	if forceLine then
		showLine = true
	elseif suppressLine then
		showLine = false
	end

	local shapeType =
		config.shape == 'inverse'
		and 'shape-inverse'
		or 'shape'

	----------------------------------------------------------------------
	-- GEOMASK / SWITCHER
	----------------------------------------------------------------------

	local maskItem

	if config.switcher == "zooms" then

		-- Switch between zoom levels.
		local maxZoom =
			math.max(
				tonumber(args.zoom) or DEFAULT_ZOOM,
				3
			)

		local minZoom = 1

		local midZoom =
			math.floor(
				(maxZoom + minZoom) / 2
			)

		args.switch =
			"zoomed in, zoomed midway, zoomed out"

		args.zoom =
			string.format(
				"SWITCH:%d,%d,%d",
				maxZoom,
				midZoom,
				minZoom
			)

	elseif config.switcher == "auto" then

		-- The Wikimedia version used Wikidata P276/P131
		-- to determine this automatically.
		--
		-- Bharatpedia has no such dependency, so this mode
		-- is intentionally disabled.

		return false, util.trackAndWarn(
			'Pages using infobox mapframe with unsupported automatic switcher'
		)

	elseif config.switcher == "geomasks"
		and config.geomask then

		-- Explicit geomask IDs are supported.
		args.zoom = nil

		local separator =
			(
				mw.ustring.find(
					config.geomask,
					"###",
					0,
					true
				)
				and "###"
			)
			or
			(
				mw.ustring.find(
					config.geomask,
					";",
					0,
					true
				)
				and ";"
			)
			or ","

		local pattern =
			"%s*" .. separator .. "%s*"

		local maskItems =
			mw.text.split(
				mw.ustring.gsub(
					config.geomask,
					"SWITCH:",
					""
				),
				pattern
			)

		if #maskItems > 1 then

			-- No external labels are available,
			-- so use the supplied IDs as switch labels.
			args.switch =
				table.concat(
					maskItems,
					"###"
				)

			maskItem =
				"SWITCH:"
				.. table.concat(
					maskItems,
					","
				)

		elseif #maskItems == 1 then
			maskItem = maskItems[1]
		end
	end

	----------------------------------------------------------------------
	-- EXPLICIT GEOMASK
	--
	-- Property-based geomasks such as P131 are not supported because
	-- they require an entity database.
	----------------------------------------------------------------------

	if not maskItem and config.geomask then

		local geomask =
			mw.text.trim(
				config.geomask
			)

		if geomask ~= ''
			and not mw.ustring.match(
				geomask,
				"^[Pp]%d+$"
			) then

			maskItem = geomask
		end
	end

	----------------------------------------------------------------------
	-- ENSURE SOMETHING CAN BE DRAWN
	----------------------------------------------------------------------

	if not maskItem
		and not showShape
		and not showLine
		and not showMarker then

		return false, util.trackAndWarn(
			'Pages using infobox mapframe with no geometry',
			'No geometry specified for mapframe'
		)
	end

	----------------------------------------------------------------------
	-- ARGUMENT NUMBERING
	----------------------------------------------------------------------

	local argNumber = ''

	local function incrementArgNumber()

		if argNumber == '' then
			argNumber = 2
		else
			argNumber = argNumber + 1
		end

	end

	----------------------------------------------------------------------
	-- GEOMASK
	----------------------------------------------------------------------

	if maskItem then

		args["type" .. argNumber] =
			"shape-inverse"

		args["id" .. argNumber] =
			maskItem

		args["stroke-width" .. argNumber] =
			config["geomask-stroke-width"]
			or DEFAULT_GEOMASK_STROKE_WIDTH

		args["stroke-color" .. argNumber] =
			config["geomask-stroke-color"]
			or config["geomask-stroke-colour"]
			or DEFAULT_GEOMASK_STROKE_COLOR

		args["fill" .. argNumber] =
			config["geomask-fill"]
			or DEFAULT_GEOMASK_FILL

		args["fill-opacity" .. argNumber] =
			config["geomask-fill-opacity"]
			or DEFAULT_SHAPE_FILL_OPACITY

		-- Let Kartographer determine zoom and position
		-- unless explicitly configured.
		if not config.zoom
			and not config.switcher then

			args.zoom = nil
			args["frame-coord"] = nil
			args["frame-lat"] = nil
			args["frame-long"] = nil
		end

		incrementArgNumber()

		-- Hack retained from the original module.
		if not args.zoom then

			args["type" .. argNumber] =
				"line"

			args["id" .. argNumber] =
				maskItem

			args["stroke-width" .. argNumber] =
				0

			incrementArgNumber()
		end
	end

	----------------------------------------------------------------------
	-- SHAPE
	----------------------------------------------------------------------

	if showShape then

		args["type" .. argNumber] =
			shapeType

		-- Explicit ID only.
		if config.id then
			args["id" .. argNumber] =
				config.id

		elseif config.from then
			args["from" .. argNumber] =
				config.from
		end

		args["stroke-width" .. argNumber] =
			config["shape-stroke-width"]
			or config["stroke-width"]
			or DEFAULT_SHAPE_STROKE_WIDTH

		args["stroke-color" .. argNumber] =
			config["shape-stroke-color"]
			or config["shape-stroke-colour"]
			or config["stroke-color"]
			or config["stroke-colour"]
			or DEFAULT_SHAPE_STROKE_COLOR

		args["fill" .. argNumber] =
			config["shape-fill"]
			or DEFAULT_SHAPE_FILL

		args["fill-opacity" .. argNumber] =
			config["shape-fill-opacity"]
			or DEFAULT_SHAPE_FILL_OPACITY

		incrementArgNumber()
	end

	----------------------------------------------------------------------
	-- LINE
	----------------------------------------------------------------------

	if showLine then

		args["type" .. argNumber] =
			"line"

		-- Explicit ID only.
		if config.id then
			args["id" .. argNumber] =
				config.id

		elseif config.from then
			args["from" .. argNumber] =
				config.from
		end

		args["stroke-width" .. argNumber] =
			config["line-stroke-width"]
			or config["stroke-width"]
			or DEFAULT_LINE_STROKE_WIDTH

		args["stroke-color" .. argNumber] =
			config["line-stroke-color"]
			or config["line-stroke-colour"]
			or config["stroke-color"]
			or config["stroke-colour"]
			or DEFAULT_LINE_STROKE_COLOR

		incrementArgNumber()
	end

	----------------------------------------------------------------------
	-- POINT MARKER
	----------------------------------------------------------------------

	if showMarker then

		args["type" .. argNumber] =
			"point"

		if config.id then
			args["id" .. argNumber] =
				config.id
		end

		if config.coord then
			args["coord" .. argNumber] =
				config.coord
		end

		if config.marker then
			args["marker" .. argNumber] =
				config.marker
		end

		args["marker-color" .. argNumber] =
			config["marker-color"]
			or config["marker-colour"]
			or DEFAULT_MARKER_COLOR

		incrementArgNumber()
	end

	----------------------------------------------------------------------
	-- FRAME CENTERING
	----------------------------------------------------------------------

	if not maskItem
		and not showShape
		and not showLine
		and showMarker then

		if config.coord then

			args["frame-coord"] =
				args["frame-coord"]
				or config.coord

		end
	end

	----------------------------------------------------------------------
	-- PROTECT AGAINST NIL FRAME ARGUMENTS
	----------------------------------------------------------------------

	args["frame-coord"] =
		args["frame-coord"] or ""

	args["frame-lat"] =
		args["frame-lat"] or ""

	args["frame-long"] =
		args["frame-long"] or ""

	----------------------------------------------------------------------
	-- RENDER MAP
	----------------------------------------------------------------------

	local mapframe =
		args.switch
		and mf.multi(args)
		or mf._main(args)

	return true, mapframe .. tracking
end

----------------------------------------------------------------------
-- ENTRY POINTS
----------------------------------------------------------------------

p.main = function(frame)

	local parent =
		frame.getParent(frame)

	local parentArgs =
		parent.args

	local _, mapframe =
		p._main(parentArgs)

	return frame:preprocess(mapframe)
end

p.auto = function(frame)

	if not util.shouldAutoRun(frame) then
		return util.noop(
			"auto should not autorun"
		)
	end

	local args =
		util.argsFromAuto(frame)

	if args.custom then
		return frame:preprocess(
			util.parseCustomWikitext(
				args.custom
			)
		)
	end

	local _, mapframe =
		p._main(args)

	return frame:preprocess(mapframe)
end

p.autocaption = function(frame)

	if not util.shouldAutoRun(frame) then
		return util.noop(
			"autocaption should not autorun"
		)
	end

	local args =
		util.argsFromAuto(frame)

	local caption =
		p._caption(args)

	return caption
end

p.autoWithCaption = function(frame)

	if not util.shouldAutoRun(frame) then
		return util.noop(
			"autoWithCaption should not autorun"
		)
	end

	local args =
		util.argsFromAuto(frame)

	local wikitext
	local caption
	local ok

	if args.custom then

		ok = true

		wikitext =
			util.parseCustomWikitext(
				args.custom
			)

	else

		ok, wikitext =
			p._main(args)

	end

	if not ok then
		return wikitext
	end

	wikitext =
		frame:preprocess(
			wikitext
		)

	caption =
		p._caption(args)

	local data =
		mw.html.create()
			:wikitext(wikitext)

	data:tag('div')
		:addClass('infobox-caption')
		:cssText(args.captionstyle)
		:wikitext(caption)

	return tostring(data)
end

return p