Logo Voyage

Module:VisitedMap Voyage Tips and guide

You can check the original Wikivoyage article Here

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

local p = {}

function p.render(frame)
    local qids_str = frame.args[1] or ""
    
    local map_params = {
        latitude = "15",
        longitude = "13.5",
        zoom = "2",
        width = "1100", 
        height = "500",
        align = "center"
    }

    if qids_str == "" or qids_str == nil then
        return frame:extensionTag('mapframe', '', map_params)
    end

    local shapes = {}
    for qid in string.gmatch(qids_str, '([^,]+)') do
        local clean_qid = mw.text.trim(qid)
        
        local sitelink = mw.wikibase.getSitelink(clean_qid)
        local label = mw.wikibase.getLabel(clean_qid) or clean_qid
        
        local display_title
        if sitelink then
            display_title = "[[" .. sitelink .. "|" .. label .. "]]"
        else
            display_title = label
        end

        table.insert(shapes, {
            type = "ExternalData",
            service = "geoshape",
            ids = clean_qid,
            properties = {
                fill = "#3366cc",
                ["fill-opacity"] = 0.5,
                stroke = "#ffffff",
                ["stroke-width"] = 1,
                title = display_title
            }
        })
    end

    local json_data = mw.text.jsonEncode(shapes)
    
    return frame:extensionTag('mapframe', json_data, map_params)
end

function mw.text.trim(s)
    return s:match("^%s*(.-)%s*$")
end

return p


Discover



Powered by GetYourGuide