(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: | -- Module:OpenStreetMapFrame | ||
local p = {} | local p = {} | ||
-- | local getArgs = require('Module:Arguments').getArgs | ||
function p. | |||
-- Default settings | |||
local args = frame | local DEFAULT_WIDTH = 300 | ||
local DEFAULT_HEIGHT = 200 | |||
local DEFAULT_ZOOM = 10 | |||
local | -- Main function to render the map frame | ||
local zoom = args.zoom or | function p.main(frame) | ||
local width = args.width or | local args = getArgs(frame) | ||
local height = args.height or " | return p.renderMapFrame(args) | ||
end | |||
-- | |||
local | -- Function to generate the map frame HTML | ||
function p.renderMapFrame(args) | |||
-- Extract parameters | |||
local coord = args.coord or args.coordinates | |||
width = | 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 | |||
return | 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