Module:LocationMap

From The Seven Sages of Rome
Revision as of 12:46, 16 February 2026 by Noeth (talk | contribs)

Documentation for this module may be created at Module:LocationMap/doc

local p = {}

function p.displayMap(frame)
    local mw = require('mw')
    local smw = mw.smw or mw.ext.smw
    
    local pageName = frame.args.pageName or mw.title.getCurrentTitle().text
    local hasCoordinates = frame.args.hasCoordinates or ''
    local hasGeoJson = frame.args.hasGeoJson or ''
    
    -- Start building the display_map query
    local mapQuery = ''
    
    -- Add current location coordinates
    if hasCoordinates ~= '' then
        mapQuery = hasCoordinates
    end
    
    -- Add child locations using inline query
    local childQuery = string.format('[[Is Located In::%s]]', pageName)
    mapQuery = mapQuery .. '{{#ask:' .. childQuery .. '|?Has Coordinates|format=list|sep=;|propsep=;}}'
    
    -- Build parameters
    local params = 'zoom=6|service=leaflet|height=250px'
    
    if hasCoordinates ~= '' then
        params = params .. '|center=' .. hasCoordinates
    end
    
    if hasGeoJson ~= '' then
        params = params .. '|geojson=' .. hasGeoJson
    end
    
    -- Return the complete map call
    local result = '{{#display_map:' .. mapQuery .. '|' .. params .. '}}'
    
    return frame:preprocess(result)
end

return p