Module:Infobox mapframe
- Afrikaans
- Ænglisc
- Аԥсшәа
- العربية
- অসমীয়া
- Asturianu
- Авар
- Azərbaycanca
- تۆرکجه
- Basa Bali
- বাংলা
- Banjar
- 閩南語 / Bân-lâm-gí
- Basa Banyumasan
- भोजपुरी
- Bikol Central
- Bosanski
- Буряад
- Cebuano
- Dansk
- Ελληνικά
- Esperanto
- فارسی
- Français
- Gĩkũyũ
- ગુજરાતી
- गोंयची कोंकणी / Gõychi Konknni
- 客家語 / Hak-kâ-ngî
- 한국어
- Hausa
- हिन्दी
- Hrvatski
- Bahasa Hulontalo
- Ilokano
- Bahasa Indonesia
- Ирон
- Íslenska
- Jawa
- ಕನ್ನಡ
- ქართული
- Kurdî
- Ladin
- Latviešu
- Lietuvių
- Li Niha
- Magyar
- Madhurâ
- मैथिली
- Македонски
- മലയാളം
- मराठी
- ဘာသာမန်
- Bahasa Melayu
- Minangkabau
- 閩東語 / Mìng-dĕ̤ng-ngṳ̄
- Мокшень
- Монгол
- မြန်မာဘာသာ
- Nederlands
- नेपाली
- 日本語
- Нохчийн
- Олык марий
- ଓଡ଼ିଆ
- ਪੰਜਾਬੀ
- پښتو
- ភាសាខ្មែរ
- Português
- Română
- Русский
- سرائیکی
- Scots
- Sesotho sa Leboa
- Shqip
- සිංහල
- Simple English
- سنڌي
- Slovenščina
- کوردی
- Српски / srpski
- Sunda
- Tagalog
- தமிழ்
- တႆး
- ไทย
- ትግርኛ
- ತುಳು
- Türkçe
- Türkmençe
- Українська
- اردو
- ئۇيغۇرچە / Uyghurche
- Tiếng Việt
- 吴语
- Yorùbá
- 粵語
- 中文
- Batak Toba
- Batak Mandailing
- Ghanaian Pidgin
- Kumoring
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
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.
Related pages |
---|
This module implements {{Infobox mapframe }}.
See Template:Infobox mapframe/testcases for tests.
Usage
Module that automatically makes a mapframe suitable for an infobox automatically, with minimal user input.
Generic usage
Just use the template {{Infobox mapframe }}, following the documentation there. This module may also be imported to another Lua module.
Automatic maps in infoboxes
- Example edits: Template:Infobox prison, Template:Infobox prison/doc
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.
If placing near the top of infobox | If placing at/near the bottom of the infobox |
---|---|
| image4 = {{#invoke:Infobox mapframe|auto}} | caption4 = {{#invoke:Infobox mapframe|autocaption}} |
| header97 = {{#if:{{{mapframe|}}}|Location}} | data98 = {{#invoke:Infobox mapframe|auto}} | data99 = {{#invoke:Infobox mapframe|autocaption}} |
If the template has a call to {{#invoke:Check for unknown parameters|check}}
, simply add |mapframe_args=y
to the call and the various mapframe args will automatically be included.
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}}
- Both the auto and autocaption functions take the onByDefault value into account.
- To turn maps on by default, in the #invoke calls above add
- Add the new parameters to the template documentation.
- You can use
{{Infobox mapframe/doc/parameters}}
. - If any default values are modified in the #invoke calls, add them as parameters in the form |parameter-name=value.
- The default output is shown here collapsed:
- You can use
Extended content
|
---|
|
- Parameters can also be added to the TemplateData, which can be copied and pasted from the relevant parts of Template:Infobox mapframe/doc
See also
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
localmf=require('Module:Mapframe') localgetArgs=require('Module:Arguments').getArgs localyesno=require('Module:Yesno') localinfoboxImage=require('Module:InfoboxImage').InfoboxImage -- Defaults localDEFAULT_FRAME_WIDTH="270" localDEFAULT_FRAME_HEIGHT="200" localDEFAULT_ZOOM=10 localDEFAULT_GEOMASK_STROKE_WIDTH="1" localDEFAULT_GEOMASK_STROKE_COLOR="#777777" localDEFAULT_GEOMASK_FILL="#888888" localDEFAULT_GEOMASK_FILL_OPACITY="0.25" localDEFAULT_SHAPE_STROKE_WIDTH="2" localDEFAULT_SHAPE_STROKE_COLOR="#FF0000" localDEFAULT_SHAPE_FILL="#606060" localDEFAULT_SHAPE_FILL_OPACITY="0.1" localDEFAULT_LINE_STROKE_WIDTH="5" localDEFAULT_LINE_STROKE_COLOR="#FF0000" localDEFAULT_MARKER_COLOR="#5E74F3" localutil={} functionutil.noop(info) localDEFAULT_NOOP_OUTPUT="" -- uncomment this when debugging -- DEFAULT_NOOP_OUTPUT = "debug: mapframe no-op: " .. info -- mw.log(DEFAULT_NOOP_OUTPUT) returnDEFAULT_NOOP_OUTPUT end -- Trim whitespace from args, and remove empty args functionutil.trimArgs(argsTable) localcleanArgs={} forkey,valinpairs(argsTable)do iftype(val)=='string'then val=val:match('^%s*(.-)%s*$') ifval~=''then cleanArgs[key]=val end else cleanArgs[key]=val end end returncleanArgs end functionutil.getBestStatement(item_id,property_id) ifnot(item_id)ornot(mw.wikibase.isValidEntityId(item_id))ornot(mw.wikibase.entityExists(item_id))then returnfalse end localstatements=mw.wikibase.getBestStatements(item_id,property_id) ifnotstatementsor#statements==0then returnfalse end localhasNoValue=(statements[1].mainsnakandstatements[1].mainsnak.snaktype=='novalue') ifhasNoValuethen returnfalse end returnstatements[1] end functionutil.hasWikidataProperty(item_id,property_id) returnutil.getBestStatement(item_id,property_id)andtrueorfalse end functionutil.getStatementValue(statement) returnstatementandstatement.mainsnakandstatement.mainsnak.datavalueandstatement.mainsnak.datavalue.valueornil end functionutil.relatedEntity(item_id,property_id) localvalue=util.getStatementValue(util.getBestStatement(item_id,property_id)) returnvalueandvalue.idorfalse end functionutil.idType(id) ifnotidthen returnnil elseifmw.ustring.match(id,"[Pp]%d+")then return"property" elseifmw.ustring.match(id,"[Qq]%d+")then return"item" else returnnil end end functionutil.shouldAutoRun(frame) -- Check if should be running localpargs=frame.getParent(frame).args localexplicitlyOn=yesno(mw.text.trim(pargs.mapframeor""))-- true of false or nil ifpargs.coordinates=="{{{coordinates}}}"thenexplicitlyOn=falseend localonByDefault=(explicitlyOn==nil)andyesno(mw.text.trim(frame.args.onByDefaultor""),false)-- true or false returnexplicitlyOnoronByDefault end functionutil.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 localargs=getArgs(frame,{parentFirst=true}) -- Discard args not prefixed with "mapframe-", remove that prefix from those that remain localfixedArgs={} forname,valinpairs(args)do localfixedName=string.match(name,"^mapframe%-(.+)$") iffixedNamethen fixedArgs[fixedName]=val -- allow coord, coordinates, etc to be unprefixed elseifname=="coordinates"orname=="coord"orname=="coordinate"andnotfixedArgs.coordthen fixedArgs.coord=val -- allow id, qid to be unprefixed, map to id (if not already present) elseifname=="id"orname=="qid"andnotfixedArgs.idthen fixedArgs.id=val end end returnfixedArgs end localp={} p.autocaption=function(frame) ifnotutil.shouldAutoRun(frame)then returnutil.noop("autocaption should not autorun") end localargs=util.argsFromAuto(frame) ifargs.captionthen returnargs.caption elseifargs.switcherthen returnutil.noop("no caption or switcher") end localmaskItem localmaskType=util.idType(args.geomask) ifmaskType=='item'then maskItem=args.geomask elseifmaskType=="property"then maskItem=util.relatedEntity(args.idormw.wikibase.getEntityIdForCurrentPage(),args.geomask) end localmaskItemLabel=maskItemandmw.wikibase.getLabel(maskItem) returnmaskItemLabel and"Location in "..maskItemLabel orutil.noop("missing maskItemLabel with type "..(maskTypeor"nil").." and item "..(maskItemor"nil")) end functionutil.parseCustomWikitext(customWikitext) -- infoboxImage will format an image if given wikitext containing an -- image, or else pass through the wikitext unmodified returninfoboxImage({ args={ image=customWikitext } }) end p.auto=function(frame) ifnotutil.shouldAutoRun(frame)then returnutil.noop("auto should not autorun") end localargs=util.argsFromAuto(frame) ifargs.customthen returnframe:preprocess(util.parseCustomWikitext(args.custom)) end localmapframe=p._main(args) returnframe:preprocess(mapframe) end p.main=function(frame) localparent=frame.getParent(frame) localparentArgs=parent.args localmapframe=p._main(parentArgs) returnframe:preprocess(mapframe) end --A list of types for objects that are too small to allow Kartographer to take over zoom localtinyType={ landmark=true, railwaystation=true, edu=true, pass=true, camera=true } p._main=function(_config) -- `config` is the args passed to this module localconfig=util.trimArgs(_config) -- allow alias for config.coord config.coord=config.coordorconfig.coordinates -- Require wikidata item, or specified coords localwikidataId=config.idormw.wikibase.getEntityIdForCurrentPage() ifnot(wikidataId)andnot(config.coord)then return'' end -- Require coords (specified or from wikidata), so that map will be centred somewhere -- (P625 = coordinate location) localhasCoordinates=util.hasWikidataProperty(wikidataId,'P625')orconfig.coord ifnothasCoordinatesthen return'' end -- `args` is the arguments which will be passed to the mapframe module localargs={} -- Some defaults/overrides for infobox presentation args.display="inline" args.frame="yes" args.plain="yes" args["frame-width"]=config["frame-width"]orconfig.widthorDEFAULT_FRAME_WIDTH args["frame-height"]=config["frame-height"]orconfig.heightorDEFAULT_FRAME_HEIGHT args["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 parameters args["frame-lat"]=config["frame-lat"]orconfig["frame-latitude"]or"" args["frame-long"]=config["frame-long"]orconfig["frame-longitude"]or"" -- if zoom isn't specified from config: localzoom=config.zoom ifnotzoomthen -- Calculate zoom from length or area (converted to km or km2) -- Zoom so that length or area is completely included in mapframe localgetZoom=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"])}) end args.zoom=zoomorDEFAULT_ZOOM -- Use OSM relation ID if available; otherwise use geoshape if that is available -- (geoshape is required for defunct entities, which are outside OSM's scope) localhasOsmRelationId=util.hasWikidataProperty(wikidataId,'P402')-- P402 is OSM relation ID localhasGeoshape=util.hasWikidataProperty(wikidataId,'P3896')-- P3896 is geoshape localwikidataProvidesGeo=hasOsmRelationIdorhasGeoshape localshouldShowPointMarker; -- determine marker argument value, determine whether to show marker localpointValue=config.point ifpointValue=='none'then pointValue='no' end pointValue=yesno(pointValue,'other') localmarkerValue=config.marker ifmarkerValue=='none'then markerValue='no' end markerValue=yesno(markerValue,true) ifpointValue==truethen shouldShowPointMarker=true elseifpointValue==falsethen shouldShowPointMarker=false else shouldShowPointMarker=not(wikidataProvidesGeo)ormarkerValueorconfig.coord end -- determine shape parameter value, determine whether to show or suppress shape -- also determine whether to invert shape localshapeValue=config.shape ifshapeValue=='none'then shapeValue='no' end shapeValue=yesno(shapeValue,'other') localforceShape=shapeValue==trueandwikidataProvidesGeo localsuppressShape=shapeValue==false localshapeType=config.shape=='inverse'and'shape-inverse'or'shape' -- determine line parameter value, determine whether to show or suppress line locallineValue=config.line iflineValue=='none'then lineValue='no' end locallineValue=yesno(lineValue,'other') localforceLine=lineValue==trueandwikidataProvidesGeo localsuppressLine=lineValue==false -- determine whether to use wikidata (independent of shape/line) localmaskItem localuseWikidata=wikidataId-- by default, if wikidata is supplied, use wikidata -- But do not use wikidata when local coords are specified (and not turned off), unless explicitly set ifuseWikidataandconfig.coordandshouldShowPointMarkerthen useWikidata=yesno(config.wikidata,true) end -- Switcher ifconfig.switcher=="zooms"then -- switching between zoom levels localmaxZoom=math.max(tonumber(args.zoom),3)-- what zoom would have otherwise been (if 3 or more, otherwise 3) localminZoom=1-- completely zoomed out localmidZoom=math.floor((maxZoom+minZoom)/2)-- midway between maxn and min args.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 country args.zoom=nil-- let kartographer determine the zoom localmaskLabels={} localmaskItems={} localmaskItemId=util.relatedEntity(wikidataId,"P276")orutil.relatedEntity(wikidataId,"P131") localmaskLabel=mw.wikibase.getLabel(maskItemId) whilemaskItemIdandmaskLabelandmw.text.trim(maskLabel)~=""do table.insert(maskLabels,maskLabel) table.insert(maskItems,maskItemId) maskItemId=maskItemIdandutil.relatedEntity(maskItemId,"P131") maskLabel=maskItemIdandmw.wikibase.getLabel(maskItemId) end if#maskLabels>1then args.switch=table.concat(maskLabels,"###") maskItem="SWITCH:"..table.concat(maskItems,",") elseif#maskLabels==1then maskItem=maskItemId[1] end elseifconfig.switcher=="geomasks"andconfig.geomaskthen -- switching between items in geomask parameter args.zoom=nil-- let kartographer determine the zoom localseparator=(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>1then fori,iteminipairs(maskItems)do table.insert(maskLabels,mw.wikibase.getLabel(item)) end args.switch=table.concat(maskLabels,"###") maskItem="SWITCH:"..table.concat(maskItems,",") end end -- resolve geomask item id (if not using geomask switcher) ifnotmaskItemthen-- localmaskType=util.idType(config.geomask) ifmaskType=='item'then maskItem=config.geomask elseifmaskType=="property"then maskItem=util.relatedEntity(wikidataId,config.geomask) end end -- if asking for shape or line from Wikidata -- and if Wikidata actually has shape/line data (wikidataProvidesGeo=true) -- and if no geomask -- and if zoom not explicitly set -- and if the object size inferred from its type is not too small -- then let Kartographer "take over" zoom if(forceLineorforceShapeor(useWikidataandnot(suppressShapeandsuppressLine))) andwikidataProvidesGeoandnotmaskItemandnotconfig.zoom andnot(config.typeandtinyType[config.type])then args.zoom=nil end -- Keep track of arg numbering localargNumber='' localfunctionincrementArgNumber() ifargNumber==''then argNumber=2 else argNumber=argNumber+1 end end -- Geomask ifmaskItemthen args["type"..argNumber]="shape-inverse" args["id"..argNumber]=maskItem args["stroke-width"..argNumber]=config["geomask-stroke-width"]orDEFAULT_GEOMASK_STROKE_WIDTH args["stroke-color"..argNumber]=config["geomask-stroke-color"]orconfig["geomask-stroke-colour"]orDEFAULT_GEOMASK_STROKE_COLOR args["fill"..argNumber]=config["geomask-fill"]orDEFAULT_GEOMASK_FILL args["fill-opacity"..argNumber]=config["geomask-fill-opacity"]orDEFAULT_SHAPE_FILL_OPACITY -- Let kartographer determine zoom and position, unless it is explicitly set in config ifnotconfig.zoomandnotconfig.switcherthen args.zoom=nil args["frame-coord"]=nil args["frame-lat"]=nil args["frame-long"]=nil localmaskArea=util.getStatementValue(util.getBestStatement(maskItem,'P2046')) end incrementArgNumber() -- Hack to fix phab:T255932 ifnotargs.zoomthen args["type"..argNumber]="line" args["id"..argNumber]=maskItem args["stroke-width"..argNumber]=0 incrementArgNumber() end end -- Shape (or shape-inverse) ifforceShapeor(useWikidataandnotsuppressShape)then args["type"..argNumber]=shapeType ifhasGeoshapeandnothasOsmRelationIdthen args["from"..argNumber]=string.sub(util.getStatementValue(util.getBestStatement(wikidataId,'P3896')),6) elseifconfig.idthen args["id"..argNumber]=config.id end args["stroke-width"..argNumber]=config["shape-stroke-width"]orconfig["stroke-width"]orDEFAULT_SHAPE_STROKE_WIDTH args["stroke-color"..argNumber]=config["shape-stroke-color"]orconfig["shape-stroke-colour"]orconfig["stroke-color"]orconfig["stroke-colour"]orDEFAULT_SHAPE_STROKE_COLOR args["fill"..argNumber]=config["shape-fill"]orDEFAULT_SHAPE_FILL args["fill-opacity"..argNumber]=config["shape-fill-opacity"]orDEFAULT_SHAPE_FILL_OPACITY incrementArgNumber() end -- Line ifforceLineor(useWikidataandnotsuppressLine)then args["type"..argNumber]="line" ifhasGeoshapeandnothasOsmRelationIdthen args["from"..argNumber]=string.sub(util.getStatementValue(util.getBestStatement(wikidataId,'P3896')),6) elseifconfig.idthen args["id"..argNumber]=config.id end args["stroke-width"..argNumber]=config["line-stroke-width"]orconfig["stroke-width"]orDEFAULT_LINE_STROKE_WIDTH args["stroke-color"..argNumber]=config["line-stroke-color"]orconfig["line-stroke-colour"]orconfig["stroke-color"]orconfig["stroke-colour"]orDEFAULT_LINE_STROKE_COLOR incrementArgNumber() end -- Point ifshouldShowPointMarkerthen args["type"..argNumber]="point" ifconfig.idthenargs["id"..argNumber]=config.idend ifconfig.coordthenargs["coord"..argNumber]=config.coordend ifconfig.markerthenargs["marker"..argNumber]=config.markerend args["marker-color"..argNumber]=config["marker-color"]orconfig["marker-colour"]orDEFAULT_MARKER_COLOR incrementArgNumber() end localmapframe=args.switchandmf.multi(args)ormf._main(args) localtracking=hasOsmRelationIdand''or'[[Category:Infobox mapframe without OSM relation ID on Wikidata]]' returnmapframe..tracking end returnp