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.
Edit the infobox template (or its sandbox).
Add lines like the following examples to the infobox. Replace numbers (4, or 97 to 99), with the appropriate number based on how many other image or data parameters are already present.
Once this is done, the above parameters will be available to users of the template.
Defaults values for these parameters can also be specified in the #invoke calls above, e.g. {{#invoke:Infobox mapframe|auto|mapframe-marker=library}} means that the library marker will be used, unless a different value is passed in to the template.
The maps are off by default, which means maps will not be displayed unless |mapframe=yes is present in the template call. To turn maps on by default, in the #invoke calls above add |onByDefault=yes – which means maps will be displayed unless |mapframe=no is present in the template call. onByDefault can also be set to a conditional, such as if another parameters is present, e.g. |onByDefault={{#if:{{{pushpin_map|}}}|no|yes}}
Add the new parameters to the document. You can use {{Infobox mapframe/doc/parameters}}. Specify default values (if any are used in the #invoke calls) using by adding parameters in the form |parameter-name=value. The default output is shown here collapsed:
mapframe – Specify yes or no to show or hide the map, overriding the default. Default: no
mapframe-caption – Caption for the map. Default: blank (or if |mapframe-geomask= is set, "Location in geomask's label")
mapframe-custom – Use a custom map instead of the automatic mapframe. Specify either a {{maplink}} template, or another template that generates a mapframe map, or an image name. If used, the subsequent mapframe parameters will be ignored. Default: not specified
mapframe-id or id or qid – Id (Q-number) of Wikidata item to use. Default:item for current page
mapframe-coordinates or mapframe-coord or coordinates or coord – Coordinates to use, instead of any on Wikidata. Use the {{Coord}} template, e.g. |coord={{Coord|12.34|N|56.78|E}}. Default:coordinates from Wikidata
mapframe-wikidata – Set to yes to show shape/line features from the wikidata item, if any, when |coord= is set. Default:not specified
Customise which features are displayed:
mapframe-shape – Turn off display of shape feature by setting to none. Use an inverse shape (geomask) instead of a regular shape by setting to inverse. Default:not specified
mapframe-point – Turn off display of point feature by setting to none. Force point marker to be displayed by setting to on. Default:not specified
mapframe-line – Turn off display of line feature by setting to none. Default:not specified
mapframe-geomask – Wikidata item to use as a geomask (everything outside the boundary is shaded darker). Can either be a specific Wikidata item (Q-number), or a property that specifies the item to use (e.g. P17 for
Script error: No such module "Redirect template".Script error: No such module "Redirect template".
When appropriate, protection levels are automatically sensed, described and categorized.
statements on the page's Wikidata item, searching recursively. E.g. an item's city, that city's state, and that state's country.
geomasks – switch between the geomasks specified as a comma-separated list of Wikidata items (Q-numbers) in the mapframe-geomask parameter
zooms – switch between "zoomed in"/"zoomed midway"/"zoomed out", where "zoomed in" is the default zoom (with a minimum of 3), "zoomed out" is 1, and "zoomed midway" is the average
Other optional parameters:
mapframe-frame-width or mapframe-width – Frame width. Default: 270
mapframe-frame-height or mapframe-height – Frame height. Default: 200
mapframe-shape-fill – Color used to fill shape features. Default: #606060
mapframe-shape-fill-opacity – Opacity level of shape fill, a number between 0 and 1. Default: 0.5
mapframe-stroke-color or mapframe-stroke-colour – Color of line features, and outlines of shape features. Default: #ff0000
mapframe-stroke-width – Width of line features, and outlines of shape features; default is "5". Default: 5
mapframe-marker – Marker symbol to use for coordinates; see mw:Help:Extension:Kartographer/Icons for options. Default:not specified (i.e. blank)
Can also be set to blank to override any default marker symbol
mapframe-marker-color or mapframe-marker-colour – Background color for the marker. Default: #5E74F3
mapframe-geomask-stroke-color or mapframe-geomask-stroke-colour – Color of outline of geomask shape. Default: #555555
mapframe-geomask-stroke-width – Width of outline of geomask shape. Default: 2
mapframe-geomask-fill – Color used to fill outside geomask features. Default: #606060
mapframe-geomask-fill-opacity – Opacity level of fill outside geomask features, a number between 0 and 1. Default: 0.5
mapframe-zoom – Set the zoom level, from "1" (map of earth) to "18" (maximum zoom in), to be used if the zoom level cannot be determined automatically from object length or area. Default: 10
mapframe-length_km or mapframe-length_mi or mapframe-area_km2 or mapframe-area_mi2 – Determine zoom level by passing in object's length (in kilometres or miles) or area (in square kilometres or square miles). Default:not specified
mapframe-frame-coordinates or mapframe-frame-coord – Alternate latitude and longitude coordinates for initial placement of map, using {{coord}}. Default:derived from item coordinates
localmf=require('Module:Mapframe')localgetArgs=require('Module:Arguments').getArgslocalyesno=require('Module:Yesno')localinfoboxImage=require('Module:InfoboxImage').InfoboxImage-- DefaultslocalDEFAULT_FRAME_WIDTH="270"localDEFAULT_FRAME_HEIGHT="200"localDEFAULT_ZOOM=10localDEFAULT_GEOMASK_STROKE_WIDTH="1"localDEFAULT_GEOMASK_STROKE_COLOR="#777777"localDEFAULT_GEOMASK_FILL="#888888"localDEFAULT_GEOMASK_FILL_OPACITY="0.5"localDEFAULT_SHAPE_STROKE_WIDTH="3"localDEFAULT_SHAPE_STROKE_COLOR="#FF0000"localDEFAULT_SHAPE_FILL="#606060"localDEFAULT_SHAPE_FILL_OPACITY="0.5"localDEFAULT_LINE_STROKE_WIDTH="5"localDEFAULT_LINE_STROKE_COLOR="#FF0000"localDEFAULT_MARKER_COLOR="#5E74F3"-- Trim whitespace from args, and remove empty argsfunctiontrimArgs(argsTable)localcleanArgs={}forkey,valinpairs(argsTable)doiftype(val)=='string'thenval=val:match('^%s*(.-)%s*$')ifval~=''thencleanArgs[key]=valendelsecleanArgs[key]=valendendreturncleanArgsendfunctiongetBestStatement(item_id,property_id)ifnot(item_id)ornot(mw.wikibase.isValidEntityId(item_id))ornot(mw.wikibase.entityExists(item_id))thenreturnfalseendlocalstatements=mw.wikibase.getBestStatements(item_id,property_id)ifnotstatementsor#statements==0thenreturnfalseendlocalhasNoValue=(statements[1].mainsnakandstatements[1].mainsnak.snaktype=='novalue')ifhasNoValuethenreturnfalseendreturnstatements[1]endfunctionhasWikidataProperty(item_id,property_id)returngetBestStatement(item_id,property_id)andtrueorfalseendfunctiongetStatementValue(statement)returnstatementandstatement.mainsnakandstatement.mainsnak.datavalueandstatement.mainsnak.datavalue.valueornilendfunctionrelatedEntity(item_id,property_id)localvalue=getStatementValue(getBestStatement(item_id,property_id))returnvalueandvalue.idorfalseendfunctionidType(id)ifnotidthenreturnnilelseifmw.ustring.match(id,"[Pp]%d+")thenreturn"property"elseifmw.ustring.match(id,"[Qq]%d+")thenreturn"item"elsereturnnilendendfunctiongetZoom(value,unit)locallength_kmifunit=='km'thenlength_km=tonumber(value)elseifunit=='mi'thenlength_km=tonumber(value)*1.609344elseifunit=='km2'thenlength_km=math.sqrt(tonumber(value))elseifunit=='mi2'thenlength_km=math.sqrt(tonumber(value))*1.609344end-- max for zoom 2 is 6400km, for zoom 3 is 3200km, for zoom 4 is 1600km, etclocalzoom=math.floor(8-(math.log10(length_km)-2)/(math.log10(2)))-- limit to values below 17zoom=math.min(17,zoom)-- take off 1 when calculated from area, to account for unusual shapesifunit=='km2'orunit=='mi2'thenzoom=zoom-1end-- minimum value is 1returnmath.max(1,zoom)endfunctionshouldAutoRun(frame)-- Check if should be runninglocalexplicitlyOn=yesno(mw.text.trim(frame.getParent(frame).args.mapframeor""))-- true of false or nillocalonByDefault=(explicitlyOn==nil)andyesno(mw.text.trim(frame.args.onByDefaultor""),false)-- true or falsereturnexplicitlyOnoronByDefaultendfunctionargsFromAuto(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 presentlocalargs=getArgs(frame,{parentFirst=true})-- Discard args not prefixed with "mapframe-", remove that prefix from those that remainlocalfixedArgs={}forname,valinpairs(args)dolocalfixedName=string.match(name,"^mapframe%-(.+)$")iffixedNamethenfixedArgs[fixedName]=val-- allow coord, coordinates, etc to be unprefixedelseifname=="coordinates"orname=="coord"orname=="coordinate"andnotfixedArgs.coordthenfixedArgs.coord=val-- allow id, qid to be unprefixed, map to id (if not already present)elseifname=="id"orname=="qid"andnotfixedArgs.idthenfixedArgs.id=valendendreturnfixedArgsendlocalp={}p.autocaption=function(frame)ifnotshouldAutoRun(frame)thenreturn""endlocalargs=argsFromAuto(frame)ifargs.captionthenreturnargs.captionelseifargs.switcherthenreturn""endlocalmaskItemlocalmaskType=idType(args.geomask)ifmaskType=='item'thenmaskItem=args.geomaskelseifmaskType=="property"thenmaskItem=relatedEntity(args.idormw.wikibase.getEntityIdForCurrentPage(),args.geomask)endlocalmaskItemLabel=maskItemandmw.wikibase.getLabel(maskItem)returnmaskItemLabeland"Location in "..maskItemLabelor""endfunctionparseCustomWikitext(customWikitext)-- infoboxImage will format an image if given wikitext containing an-- image, or else pass through the wikitext unmodifiedreturninfoboxImage({args={image=customWikitext}})endp.auto=function(frame)ifnotshouldAutoRun(frame)thenreturn""endlocalargs=argsFromAuto(frame)ifargs.customthenreturnframe:preprocess(parseCustomWikitext(args.custom))endlocalmapframe=p._main(args)returnframe:preprocess(mapframe)endp.main=function(frame)localparent=frame.getParent(frame)localparentArgs=parent.argslocalmapframe=p._main(parentArgs)returnframe:preprocess(mapframe)endp._main=function(_config)-- `config` is the args passed to this modulelocalconfig=trimArgs(_config)-- Require wikidata item, or specified coordslocalwikidataId=config.idormw.wikibase.getEntityIdForCurrentPage()ifnot(wikidataId)andnot(config.coord)thenreturn''end-- Require coords (specified or from wikidata), so that map will be centred somewhere-- (P625 = coordinate location)localhasCoordinates=hasWikidataProperty(wikidataId,'P625')orconfig.coordinatesorconfig.coordifnothasCoordinatesthenreturn''end-- `args` is the arguments which will be passed to the mapframe modulelocalargs={}-- Some defaults/overrides for infobox presentationargs.display="inline"args.frame="yes"args.plain="yes"args["frame-width"]=config["frame-width"]orconfig.widthorDEFAULT_FRAME_WIDTHargs["frame-height"]=config["frame-height"]orconfig.heightorDEFAULT_FRAME_HEIGHTargs["frame-align"]="center"args["frame-coord"]=config["frame-coordinates"]orconfig["frame-coord"]or""-- Note: config["coordinates"] or config["coord"] should not be used for the alignment of the frame;-- see talk page ( https://en.wikipedia.org/wiki/Special:Diff/876492931 )-- deprecated lat and long parametersargs["frame-lat"]=config["frame-lat"]orconfig["frame-latitude"]or""args["frame-long"]=config["frame-long"]orconfig["frame-longitude"]or""-- Calculate zoom from length or area (converted to km or km2)ifconfig.length_kmthenargs.zoom=getZoom(config.length_km,'km')elseifconfig.length_mithenargs.zoom=getZoom(config.length_mi,'mi')elseifconfig.area_km2thenargs.zoom=getZoom(config.area_km2,'km2')elseifconfig.area_mi2thenargs.zoom=getZoom(config.area_mi2,'mi2')elseargs.zoom=config.zoomorDEFAULT_ZOOMend-- Conditionals: whether point, geomask should be shownlocalhasOsmRelationId=hasWikidataProperty(wikidataId,'P402')-- P402 is OSM relation IDlocalshouldShowPointMarker;ifconfig.point=="on"thenshouldShowPointMarker=trueelseifconfig.point=="none"thenshouldShowPointMarker=falseelseshouldShowPointMarker=not(hasOsmRelationId)or(config.markerandconfig.marker~='none')or(config.coordinatesorconfig.coord)endlocalshouldShowShape=config.shape~='none'localshapeType=config.shape=='inverse'and'shape-inverse'or'shape'localshouldShowLine=config.line~='none'localmaskItemlocaluseWikidata=wikidataIdandtrueorfalse-- Use shapes/lines based on wikidata id, if there is one-- But do not use wikidata when local coords are specified (and not turned off), unless explicitly setifuseWikidataandconfig.coordandshouldShowPointMarkerthenuseWikidata=config.wikidataandtrueorfalseend-- Switcherifconfig.switcher=="zooms"then-- switching between zoom levelslocalmaxZoom=math.max(tonumber(args.zoom),3)-- what zoom would have otherwise been (if 3 or more, otherwise 3)localminZoom=1-- completely zoomed outlocalmidZoom=math.floor((maxZoom+minZoom)/2)-- midway between maxn and minargs.switch="zoomed in, zoomed midway, zoomed out"args.zoom=string.format("SWITCH:%d,%d,%d",maxZoom,midZoom,minZoom)elseifconfig.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 countryargs.zoom=nil-- let kartographer determine the zoomlocalmaskLabels={}localmaskItems={}localmaskItemId=relatedEntity(wikidataId,"P276")orrelatedEntity(wikidataId,"P131")localmaskLabel=mw.wikibase.getLabel(maskItemId)whilemaskItemIdandmaskLabelandmw.text.trim(maskLabel)~=""dotable.insert(maskLabels,maskLabel)table.insert(maskItems,maskItemId)maskItemId=maskItemIdandrelatedEntity(maskItemId,"P131")maskLabel=maskItemIdandmw.wikibase.getLabel(maskItemId)endif#maskLabels>1thenargs.switch=table.concat(maskLabels,"###")maskItem="SWITCH:"..table.concat(maskItems,",")elseif#maskLabels==1thenmaskItem=maskItemId[1]endelseifconfig.switcher=="geomasks"andconfig.geomaskthen-- switching between items in geomask parameterargs.zoom=nil-- let kartographer determine the zoomlocalseparator=(mw.ustring.find(config.geomask,"###",0,true)and"###")or(mw.ustring.find(config.geomask,";",0,true)and";")or","localpattern="%s*"..separator.."%s*"localmaskItems=mw.text.split(mw.ustring.gsub(config.geomask,"SWITCH:",""),pattern)localmaskLabels={}if#maskItems>1thenfori,iteminipairs(maskItems)dotable.insert(maskLabels,mw.wikibase.getLabel(item))endargs.switch=table.concat(maskLabels,"###")maskItem="SWITCH:"..table.concat(maskItems,",")endend-- resolve geomask item id (if not using geomask switcher)ifnotmaskItemthen-- localmaskType=idType(config.geomask)ifmaskType=='item'thenmaskItem=config.geomaskelseifmaskType=="property"thenmaskItem=relatedEntity(wikidataId,config.geomask)endend-- Keep track of arg numberinglocalargNumber=''localfunctionincrementArgNumber()ifargNumber==''thenargNumber=2elseargNumber=argNumber+1endend-- GeomaskifmaskItemthenargs["type"..argNumber]="shape-inverse"args["id"..argNumber]=maskItemargs["stroke-width"..argNumber]=config["geomask-stroke-width"]orDEFAULT_GEOMASK_STROKE_WIDTHargs["stroke-color"..argNumber]=config["geomask-stroke-color"]orconfig["geomask-stroke-colour"]orDEFAULT_GEOMASK_STROKE_COLORargs["fill"..argNumber]=config["geomask-fill"]orDEFAULT_GEOMASK_FILLargs["fill-opacity"..argNumber]=config["geomask-fill-opacity"]orDEFAULT_SHAPE_FILL_OPACITY-- Let kartographer determine zoom and position, unless it is explicitly set in configifnotconfig.zoomandnotconfig.switcherthenargs.zoom=nilargs["frame-coord"]=nilargs["frame-lat"]=nilargs["frame-long"]=nillocalmaskArea=getStatementValue(getBestStatement(maskItem,'P2046'))endincrementArgNumber()-- Hack to fix phab:T255932ifnotargs.zoomthenargs["type"..argNumber]="line"args["id"..argNumber]=maskItemargs["stroke-width"..argNumber]=0incrementArgNumber()endend-- Shape (or shape-inverse)ifuseWikidataandshouldShowShapethenargs["type"..argNumber]=shapeTypeifconfig.idthenargs["id"..argNumber]=config.idendargs["stroke-width"..argNumber]=config["shape-stroke-width"]orconfig["stroke-width"]orDEFAULT_SHAPE_STROKE_WIDTHargs["stroke-color"..argNumber]=config["shape-stroke-color"]orconfig["shape-stroke-colour"]orconfig["stroke-color"]orconfig["stroke-colour"]orDEFAULT_SHAPE_STROKE_COLORargs["fill"..argNumber]=config["shape-fill"]orDEFAULT_SHAPE_FILLargs["fill-opacity"..argNumber]=config["shape-fill-opacity"]orDEFAULT_SHAPE_FILL_OPACITYincrementArgNumber()end-- LineifuseWikidataandshouldShowLinethenargs["type"..argNumber]="line"ifconfig.idthenargs["id"..argNumber]=config.idendargs["stroke-width"..argNumber]=config["line-stroke-width"]orconfig["stroke-width"]orDEFAULT_LINE_STROKE_WIDTHargs["stroke-color"..argNumber]=config["line-stroke-color"]orconfig["line-stroke-colour"]orconfig["stroke-color"]orconfig["stroke-colour"]orDEFAULT_LINE_STROKE_COLORincrementArgNumber()end-- PointifshouldShowPointMarkerthenargs["type"..argNumber]="point"ifconfig.idthenargs["id"..argNumber]=config.idendifconfig.coordthenargs["coord"..argNumber]=config.coordendifconfig.markerthenargs["marker"..argNumber]=config.markerendargs["marker-color"..argNumber]=config["marker-color"]orconfig["marker-colour"]orDEFAULT_MARKER_COLORincrementArgNumber()endlocalmapframe=args.switchandmf.multi(args)ormf._main(args)localtracking=hasOsmRelationIdand''or'[[Category:Infobox mapframe without OSM relation ID on Wikidata]]'returnmapframe..trackingendreturnp