Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Mapframe: Difference between revisions

From Alternative Lifestyle Wiki
More languages
More actions
(Replaced content with "-- Module:SimpleMapframe local p = {} -- Function to generate the mapframe function p.map(frame) -- Retrieve the parameters from the parent frame local args = frame:getParent().args -- Default values local lat = args.lat or "0" -- Latitude local lon = args.lon or "0" -- Longitude local zoom = args.zoom or "10" -- Default zoom level local width = args.width or "300" -- Width in pixels local height = args.height or "200" -- Height...")
Tag: Replaced
No edit summary
 
Line 1: Line 1:
-- Module:SimpleMapframe
-- Module:OpenStreetMapFrame
local p = {}
local p = {}


-- Function to generate the mapframe
local getArgs = require('Module:Arguments').getArgs
function p.map(frame)
 
    -- Retrieve the parameters from the parent frame
-- Default settings
     local args = frame:getParent().args
local DEFAULT_WIDTH = 300
   
local DEFAULT_HEIGHT = 200
    -- Default values
local DEFAULT_ZOOM = 10
     local lat = args.lat or "0" -- Latitude
 
     local lon = args.lon or "0" -- Longitude
-- Main function to render the map frame
     local zoom = args.zoom or "10" -- Default zoom level
function p.main(frame)
     local width = args.width or "300" -- Width in pixels
     local args = getArgs(frame)
     local height = args.height or "200" -- Height in pixels
    return p.renderMapFrame(args)
      
end
     -- Generate the mapframe HTML
 
     local mapframe = mw.text.tag('mapframe', {
-- Function to generate the map frame HTML
        latitude = lat,
function p.renderMapFrame(args)
        longitude = lon,
     -- Extract parameters
        zoom = zoom,
     local coord = args.coord or args.coordinates
         width = width .. "px",
     local zoom = tonumber(args.zoom) or DEFAULT_ZOOM
        height = height .. "px",
     local width = tonumber(args.width) or DEFAULT_WIDTH
         align = "center"
     local height = tonumber(args.height) or DEFAULT_HEIGHT
     })
 
   
    -- Validate coordinates
     return mapframe
    if not coord or not coord:match("^[%d.-]+,[%d.-]+$") then
        return '<strong class="error">Error: Invalid coordinates provided.</strong>'
    end
 
    -- Extract latitude and longitude
     local lat, lon = coord:match("^([%d.-]+),([%d.-]+)$")
 
     -- Construct the OpenStreetMap tile URL
     local osmTileUrl = string.format("https://tile.openstreetmap.org/%d/%s/%s.png", zoom, lon, lat)
 
    -- Construct the HTML for the image
    local html = string.format(
         '<img src="%s" alt="Map at coordinates %s" width="%d" height="%d" />',
         osmTileUrl, coord, width, height
     )
 
     return html
end
end


-- Export the module's functions
return p
return p

Latest revision as of 14:21, 27 June 2024

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

-- Module:OpenStreetMapFrame
local p = {}

local getArgs = require('Module:Arguments').getArgs

-- Default settings
local DEFAULT_WIDTH = 300
local DEFAULT_HEIGHT = 200
local DEFAULT_ZOOM = 10

-- Main function to render the map frame
function p.main(frame)
    local args = getArgs(frame)
    return p.renderMapFrame(args)
end

-- Function to generate the map frame HTML
function p.renderMapFrame(args)
    -- Extract parameters
    local coord = args.coord or args.coordinates
    local zoom = tonumber(args.zoom) or DEFAULT_ZOOM
    local width = tonumber(args.width) or DEFAULT_WIDTH
    local height = tonumber(args.height) or DEFAULT_HEIGHT

    -- Validate coordinates
    if not coord or not coord:match("^[%d.-]+,[%d.-]+$") then
        return '<strong class="error">Error: Invalid coordinates provided.</strong>'
    end

    -- Extract latitude and longitude
    local lat, lon = coord:match("^([%d.-]+),([%d.-]+)$")

    -- Construct the OpenStreetMap tile URL
    local osmTileUrl = string.format("https://tile.openstreetmap.org/%d/%s/%s.png", zoom, lon, lat)

    -- Construct the HTML for the image
    local html = string.format(
        '<img src="%s" alt="Map at coordinates %s" width="%d" height="%d" />',
        osmTileUrl, coord, width, height
    )

    return html
end

-- Export the module's functions
return p