| Modul Lua ini digunakan pada sekitar 143.000 halaman. Untuk mencegah suntingan mengganggu skala besar dan beban peladen, setiap perubahan harus diuji di subhalaman /bak pasir atau /kasus uji Modul:Infobox mapframe, atau bak pasir modul Anda. Perubahan yang telah diuji kemudian dapat ditambahkan ke halaman ini dalam satu suntingan. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya. |
| Modul ini dinilai sebagai modul beta, dan siap digunakan secara luas. Modul ini masih baru dan harus digunakan dengan hati-hati untuk memastikan bahwa hasilnya sesuai dengan yang diharapkan. |
| Halaman terkait |
|---|
PenggunaanPenggunaan
Modul yang otomatis membuat mapframe dalam kotak info dengan masukan pengguna minimum
Penggunaan umumPenggunaan umum
Tempatkan templat {{Infobox mapframe}}, mengikuti dokumentasinya. Modul ini dapat diimpor ke modul lua lainnya.
Peta otomatis di kotak infoPeta otomatis di kotak info
Sunting templat kotak infonya (atau bak pasirnya). Tambah baris seperti contoh di bawah pada kotak info Anda. Ganti angka (4, atau 97 ke 99), dengan angka yang sesuai dengan jumlah parameter yang Anda rencanakan.
| Jika ditempatkan di atas kotak info | Jika ditempatkan di bawah kotak info |
|---|---|
| image4 = {{#invoke:Infobox mapframe|auto}}
| caption4 = {{#invoke:Infobox mapframe|autocaption}}
|
| header97 = {{#if:{{{mapframe|}}}|Location}}
| data98 = {{#invoke:Infobox mapframe|auto}}
| data99 = {{#invoke:Infobox mapframe|autocaption}}
|
Jika templat tersebut mengandung{{#invoke:Check for unknown parameters}}, tambah parameter berikut:
| mapframe | mapframe-caption | mapframe-custom | mapframe-id | mapframe-coord | mapframe-wikidata | mapframe-point | mapframe-shape | mapframe-frame-width | mapframe-frame-height | mapframe-shape-fill | mapframe-shape-fill-opacity | mapframe-stroke-color | mapframe-stroke-colour | mapframe-stroke-width | mapframe-marker | mapframe-marker-color | mapframe-marker-colour | mapframe-geomask | mapframe-geomask-stroke-color | mapframe-geomask-stroke-colour | mapframe-geomask-stroke-width | mapframe-geomask-fill | mapframe-geomask-fill-opacity | mapframe-zoom | mapframe-length_km | mapframe-length_mi | mapframe-area_km2 | mapframe-area_mi2 | mapframe-frame-coordinates | mapframe-frame-coord | mapframe-switcher | mapframe-height | mapframe-width
Begitu selesai, parameter di atas akan tersedia kepada pengguna.
- Nilai bawaan parameter-parameter ini dapat ditentukan dengan menyebut #invoke, contohnya
{{#invoke:Infobox mapframe|auto|mapframe-marker=library}}berarti library marker digunakan kecuali nilai yang berbeda diberikan. - Secara bawaan peta tidak ditampilkan, kecuali menyebutkan
|mapframe=yes. Untuk menyalakannya, pada sebutan #invoke tambahkan|onByDefault=yes– yang berarti peta tersebut akan ditampilkan kecuali menyebutkan|mapframe=no. onByDefault dapat kondisional, seperti jika parameter lainnya muncul, misal|onByDefault={{#if:{{{pushpin_map|}}}|no|yes}} - Tambah parameter baru ke dokumentasi. Gunakan
{{Infobox mapframe/doc/parameters}}. Tentukan nilai bawaan (jika menggunakan penyebutan #invoke) dengan menambahkan parameter |nama parameter=nilai. Luaran otomatisnya ditunjukkan di bawah:
Konten tambahan
|
|---|
- Parameter dapat juga ditambahkan ke TemplateData dapat ditambahkan dengan menyalin-tempel: Template:Infobox mapframe/doc/templatedata
Lihat pulaLihat pula
Dokumentasi di atas ditransklusikan dari Modul:Infobox mapframe/doc. (sunting | riwayat)
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
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 iftype(pargs.coordinates)=='string'andstring.match(pargs.coordinates,'coord.missing')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 -- allow captionstyle to be unprefixed, for compatibility with [[Module:Infobox]] elseifname=="captionstyle"andnotfixedArgs.captionstylethen fixedArgs.captionstyle=val end end returnfixedArgs 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 functionutil.trackAndWarn(trackingCat,warning) localtitle=mw.title.getCurrentTitle() localresults=titleandtitle.namespace==0andtrackingCatand'[[Category:'..trackingCat..']]'or'' ifwarningthen localwarn=require('Module:If preview')._warning results=results..warn({warning}) end returnresults end functionutil.ternary(flag,other) other=otheror'other' flag=flag=='none'and'no'orflag localyesNoOut=yesno(flag,other) localyes=(yesNoOut==true) localno=(yesNoOut==false) returnyes,no end localp={} p._caption=function(args) 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) returnmaskItemLabeland"Location in "..maskItemLabel orutil.noop("missing maskItemLabel with type "..(maskTypeor"nil").." and item "..(maskItemor"nil")) 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) -- accumulate tracking cats localtracking='' -- `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 returnfalse,util.trackAndWarn('Pages using infobox mapframe with missing coordinates') end -- Require coords (specified or from wikidata), so that map will be centred somewhere -- (P625 = coordinate location) localwdCoordinates=util.getStatementValue(util.getBestStatement(wikidataId,'P625')) ifnot(config.coordorwdCoordinates)then returnfalse,util.trackAndWarn('Pages using infobox mapframe with missing coordinates') 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"] -- 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"] args["frame-long"]=config["frame-long"]orconfig["frame-longitude"] -- if zoom isn't specified from config, first check wikidata localzoom=config.zoomorutil.getStatementValue(util.getBestStatement(wikidataId,'P6592')) 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"]), latitude=wdCoordinatesandwdCoordinates.latitude}) 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 -- determine marker argument value, determine whether to show marker localforcePoint,suppressPoint=util.ternary(config.point) localforceMarker,suppressMarker=util.ternary(config.marker,true) forcePoint=forcePointorforceMarker suppressPoint=suppressPointorsuppressMarker localshowMarker=notsuppressPointand(forcePointornotwikidataProvidesGeoorconfig.coord) -- wikidata = "yes" turns on both shape and line -- wikidata = "no" turns off both shape and line -- otherwise show both if wikidata provides geo localforceWikidata,suppressWikidata=util.ternary(config.wikidata) localshowShape=notsuppressWikidataand(forceWikidataorwikidataProvidesGeoornotconfig.coord) localshowLine=showShape -- determine shape parameter value, determine whether to show or suppress shape -- also determine whether to invert shape localforceShape,suppressShape=util.ternary(config.shape) showShape=wikidataIdandnotsuppressShapeand(forceShapeorshowShape) localshapeType=config.shape=='inverse'and'shape-inverse'or'shape' -- determine line parameter value, determine whether to show or suppress line localforceLine,suppressLine=util.ternary(config.line) showLine=wikidataIdandnotsuppressLineand(forceLineorshowLine) localmaskItem -- 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(showLineorshowShape)andwikidataProvidesGeoandnotmaskItem andnotconfig.zoomandnot(config.typeandtinyType[config.type])then args.zoom=nil end ifnotmaskItemandnotshowShapeandnotshowLineandnotshowMarkerthen returnfalse,util.trackAndWarn('Pages using infobox mapframe with no geometry','No geometry specified for mapframe') 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) ifshowShapethen 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 ifshowLinethen 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 marker ifshowMarkerthen 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 -- 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 ifnotmaskItemandnotshowMarkerandnotwikidataProvidesGeothen ifconfig.coordthen args["frame-coord"]=args["frame-coord"]orconfig.coord else args["frame-lat"]=args["frame-lat"]orwdCoordinates.latitude args["frame-long"]=args["frame-long"]orwdCoordinates.longitude end tracking=tracking..util.trackAndWarn('Pages using infobox mapframe with forced centering') 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"" localmapframe=args.switchandmf.multi(args)ormf._main(args) tracking=tracking..((showLineorshowShape)andnotwikidataProvidesGeo andutil.trackAndWarn('Pages using infobox mapframe without shape links in Wikidata') or'') returntrue,mapframe..tracking end -- Entry points p.main=function(frame) localparent=frame.getParent(frame) localparentArgs=parent.args local_,mapframe=p._main(parentArgs) returnframe:preprocess(mapframe) 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 local_,mapframe=p._main(args) returnframe:preprocess(mapframe) end p.autocaption=function(frame) ifnotutil.shouldAutoRun(frame)then returnutil.noop("autocaption should not autorun") end localargs=util.argsFromAuto(frame) localcaption=p._caption(args) returncaption end p.autoWithCaption=function(frame) ifnotutil.shouldAutoRun(frame)then returnutil.noop("autoWithCaption should not autorun") end localargs=util.argsFromAuto(frame) localwikitext localcaption localok ifargs.customthen ok=true wikitext=util.parseCustomWikitext(args.custom) else ok,wikitext=p._main(args) end ifnotokthenreturnwikitextend wikitext=frame:preprocess(wikitext) caption=p._caption(args) localdata=mw.html.create():wikitext(wikitext) data:tag('div') :addClass('infobox-caption') :cssText(args.captionstyle) :wikitext(caption) returntostring(data) end returnp