Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/autoscale
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
p = {} function p.main(frame) if frame.args.item == nil then return "no item given" elseif mw.wikibase.entityExists(frame.args.item) == nil then return "not a valid item" end local coordtable = {} local usecoordy = nil local usecoordx = nil local cminy = nil local cmaxy = nil local closetag = nil local i = 0 -- if far east, west, north, south if mw.wikibase.getBestStatements(frame.args.item, "P1334")[1] and mw.wikibase.getBestStatements(frame.args.item, "P1334")[1].mainsnak.datavalue and mw.wikibase.getBestStatements(frame.args.item, "P1335")[1] and mw.wikibase.getBestStatements(frame.args.item, "P1335")[1].mainsnak.datavalue and mw.wikibase.getBestStatements(frame.args.item, "P1332")[1] and mw.wikibase.getBestStatements(frame.args.item, "P1332")[1].mainsnak.datavalue and mw.wikibase.getBestStatements(frame.args.item, "P1333")[1] and mw.wikibase.getBestStatements(frame.args.item, "P1333")[1].mainsnak.datavalue then -- getting locations of farthest points in each direction in the area local statementa = mw.wikibase.getBestStatements(frame.args.item, "P1334")[1].mainsnak table.insert(coordtable, statementa.datavalue.value.longitude) local statementb = mw.wikibase.getBestStatements(frame.args.item, "P1335")[1].mainsnak table.insert(coordtable, statementb.datavalue.value.longitude) local statementc = mw.wikibase.getBestStatements(frame.args.item, "P1332")[1].mainsnak table.insert(coordtable, statementc.datavalue.value.latitude) local statementd = mw.wikibase.getBestStatements(frame.args.item, "P1333")[1].mainsnak table.insert(coordtable, statementd.datavalue.value.latitude) -- figuring out the center position of the map, but also used for zoom levels local cminx = math.min(tonumber(coordtable[1]), tonumber(coordtable[2])) local sizex = math.max(tonumber(coordtable[1]), tonumber(coordtable[2])) - cminx usecoordx = tonumber(cminx + (sizex / 2)) cminy = math.min(tonumber(coordtable[3]), tonumber(coordtable[4])) cmaxy = math.max(tonumber(coordtable[3]), tonumber(coordtable[4])) local sizey = cmaxy - cminy usecoordy = tonumber(cminy + (sizey / 2)) -- Zoom level: each zoom level is half of the previous zoom level, with the highest being 360 degress (full circle) local x = 360 while math.max(sizex, sizey) < x do x = x / 2 i = i + 1 end -- if either central coordinate or basic coordinate along with instance of elseif mw.wikibase.getBestStatements(frame.args.item, "P31")[1] and mw.wikibase.getBestStatements(frame.args.item, "P31")[1].mainsnak.datavalue then if mw.wikibase.getBestStatements(frame.args.item, "P15140")[1] and mw.wikibase.getBestStatements(frame.args.item, "P15140")[1].mainsnak.datavalue then local statementa = mw.wikibase.getBestStatements(frame.args.item, "P15140")[1].mainsnak usecoordx = statementa.datavalue.value.longitude usecoordy = statementa.datavalue.value.latitude cminy = tonumber(usecoordy) cmaxy = tonumber(usecoordy) elseif mw.wikibase.getBestStatements(frame.args.item, "P625")[1] and mw.wikibase.getBestStatements(frame.args.item, "P625")[1].mainsnak.datavalue then local statementa = mw.wikibase.getBestStatements(frame.args.item, "P625")[1].mainsnak usecoordx = statementa.datavalue.value.longitude usecoordy = statementa.datavalue.value.latitude cminy = tonumber(usecoordy) cmaxy = tonumber(usecoordy) end local statementb = mw.wikibase.getBestStatements(frame.args.item, "P31")[1].mainsnak if statementb.datavalue.value.id == "Q6256" then -- Country i = 3 elseif statementb.datavalue.value.id == "Q515" then -- City i = 11 end end -- northern and southern hemisphere have different scaling, due to the earth being round. -- in other cases the calculated zoom is a bit tight, so easing that up. if cmaxy > 60 or cminy < -30 then i = i - 2 else i = i - 1 end if frame.args.closetag then closetag = " >" else closetag = " />" end return frame:preprocess("<mapframe width=250 height=250 zoom=" .. i .. " longitude=" .. usecoordx .. " latitude=" .. usecoordy .. closetag) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/autoscale/doc
(
edit
)