Module:Infobox mapframe: Difference between revisions

Content deleted Content added
Use getZoom from Module:Infobox dim
Let line=yes or shape=yes force use of Wikidata for that type + let Kartographer set zoom. Also: parse point, marker, shape, and line with yesno to allow more general yes/no arguments
 
(8 intermediate revisions by 2 users not shown)
Line 81:
function shouldAutoRun(frame)
-- Check if should be running
local explicitlyOnpargs = yesno(mw.text.trim(frame.getParent(frame).args.mapframe or "")) -- true of false or nil
local explicitlyOn = yesno(mw.text.trim(pargs.mapframe or "")) -- true of false or nil
if pargs.coordinates == "{{{coordinates}}}" 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
Line 156 ⟶ 158:
return frame:preprocess(mapframe)
end
 
--A list of types for objects that are too small to allow Kartographer to take over zoom
local tinyType = {
landmark=true,
railwaystation=true,
edu=true,
pass=true,
camera=true
}
 
p._main = function(_config)
Line 161 ⟶ 172:
local config = trimArgs(_config)
-- allow alias for config.coord
config.coord = config.coord or config.coordinates
 
-- Require wikidata item, or specified coords
local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage()
Line 169 ⟶ 183:
-- Require coords (specified or from wikidata), so that map will be centred somewhere
-- (P625 = coordinate ___location)
local hasCoordinates = hasWikidataProperty(wikidataId, 'P625') or config.coordinates or config.coord
if not hasCoordinates then
return ''
Line 193 ⟶ 207:
args["frame-long"] = config["frame-long"] or config["frame-longitude"] or ""
 
-- if zoom isn't specified from config:
-- Calculate zoom from length or area (converted to km or km2)
local zoom = config.zoom
-- Zoom so that length or area is completely included in mapframe
if not zoom then
local getZoom = require('Module:Infobox dim')._zoom
-- Calculate zoom from length or area (converted to km or km2)
local zoom = getZoom({length_km=config.length_km, length_mi=config.length_mi,
-- Zoom so that length or area is completely included in mapframe
area_km2=config.area_km2, area_mi2=config.area_mi2,
local getZoom = require('Module:Infobox dim')._zoom
viewport_px=math.min(args["frame-width"],args["frame-height"])})
args.zoom = zoom orgetZoom({length_km=config.length_km, length_mi=config.zoom or DEFAULT_ZOOMlength_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 = zoom or DEFAULT_ZOOM
 
-- Conditionals: whether point, geomask should be shown
local hasOsmRelationId = hasWikidataProperty(wikidataId, 'P402') -- P402 is OSM relation ID
local shouldShowPointMarker;
 
if config.point == "on" then
-- determine marker argument value, determine whether to show marker
local pointValue = config.point
if pointValue == 'none' then
pointValue = 'no'
end
pointValue = yesno(pointValue,'other')
local markerValue = config.marker
if markerValue == 'none' then
markerValue = 'no'
end
markerValue = yesno(markerValue,true)
 
if config.pointpointValue == "on"true then
shouldShowPointMarker = true
elseif config.pointpointValue == "none"false then
shouldShowPointMarker = false
else
shouldShowPointMarker = not(hasOsmRelationId) or (config.marker and config.marker ~= 'none') or (config.coordinatesmarkerValue or config.coord)
end
 
local shouldShowShape = config.shape ~= 'none'
-- determine shape parameter value, determine whether to show or suppress shape
-- also determine whether to invert shape
local shouldShowShapeshapeValue = config.shape ~= 'none'
if shapeValue == 'none' then
shapeValue = 'no'
end
shapeValue = yesno(shapeValue,'other')
 
local forceShape = shapeValue == true and hasOsmRelationId
local suppressShape = shapeValue == false
local shapeType = config.shape == 'inverse' and 'shape-inverse' or 'shape'
 
local shouldShowLine = config.line ~= 'none'
-- determine line parameter value, determine whether to show or suppress line
local shouldShowLinelineValue = config.line ~= 'none'
if lineValue == 'none' then
lineValue = 'no'
end
local lineValue = yesno(lineValue,'other')
 
local forceLine = lineValue == true and hasOsmRelationId
local suppressLine = lineValue == false
 
-- determine whether to use wikidata (independent of shape/line)
local maskItem
local useWikidata = wikidataId and true or false -- Useby shapes/linesdefault, based onif wikidata idis supplied, ifuse there is onewikidata
-- But do not use wikidata when local coords are specified (and not turned off), unless explicitly set
if useWikidata and config.coord and shouldShowPointMarker then
useWikidata = yesno(config.wikidata and ,true or false)
end
Line 275 ⟶ 330:
end
end
 
-- if asking for shape or line from Wikidata
-- and if Wikidata actually has shape/line data (hasOsmRelationId=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 (forceLine or forceShape or (useWikidata and not (suppressShape and suppressLine)))
and hasOsmRelationId and not maskItem and not config.zoom
and not (config.type and tinyType[config.type]) then
args.zoom = nil
end
-- Keep track of arg numbering
Line 313 ⟶ 380:
-- Shape (or shape-inverse)
if forceShape or (useWikidata and shouldShowShapenot suppressShape) then
args["type"..argNumber] = shapeType
if config.id then args["id"..argNumber] = config.id end
Line 324 ⟶ 391:
-- Line
if forceLine or (useWikidata and shouldShowLinenot suppressLine) then
args["type"..argNumber] = "line"
if config.id then args["id"..argNumber] = config.id end