"ഘടകം:Slippymap/sandbox" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

Schoolwiki സംരംഭത്തിൽ നിന്ന്
No edit summary
No edit summary
വരി 1: വരി 1:
local p = {}
local p = {}


-- Function to clean input values by trimming spaces and handling nil values
function p.slippymap(frame)
local function clean(input)
    -- Get arguments from the template or directly from the page
return input and mw.text.trim(input) or nil
    local args = frame:getParent().args
end
    local lat = args["lat"] or "0"  -- Default latitude
    local lon = args["lon"] or "0"  -- Default longitude
    local text = args["text"] or "Location"  -- Default marker text
    local logo = args["logo"] or "File:63rd state kalolsavam logo.png"  -- Default logo image


function p.slippymap(frame)
    -- Generate the HTML for the map
local args = (frame:getParent() or frame).args
    local mapHtml = mw.html.create("div")
    mapHtml:addClass("leaflet-map")
    mapHtml:attr("style", "width: 100%; height: 400px;")
    mapHtml:attr("id", "map")
 
    local script = mw.html.create("script")
    script:wikitext([[
        mw.loader.using(['ext.kartographer.static']).then(function() {
            var map = L.map('map').setView([]] .. lat .. [[, ]] .. lon .. [[], 13);
           
            // Add OpenStreetMap tile layer
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                maxZoom: 19
            }).addTo(map);


-- Extract and process map options from arguments
            // Add marker
local options = {
            L.marker([]] .. lat .. [[, ]] .. lon .. [[]).addTo(map)
latitude = tonumber(clean(args.lat)) or 51.3432699,
                .bindPopup("]] .. text .. [[")
longitude = tonumber(clean(args.lon)) or 0.52700328,
                .openPopup();
height = tonumber(clean(args.height)) or 400,
width = clean(args.width) == "full" and "full" or tonumber(clean(args.width)) or 400,
zoom = tonumber(clean(args.zoom)) or 12,
align = clean(args.alignment) or "center",
text = clean(args.text), -- Use provided text, no default value here
marker = clean(args.marker) ~= "no",
}


-- Generate GeoJSON content if the marker is enabled
            // Add logo image as a custom control
local content = nil
            var logoControl = L.control({position: 'bottomleft'});
if options.marker then
            logoControl.onAdd = function() {
content = mw.text.jsonEncode({
                var div = L.DomUtil.create('div', 'logo');
type = "FeatureCollection",
                div.innerHTML = '<img src="]] .. mw.uri.fullUrl(logo) .. [[" style="width: 100px; height: auto;" />';
features = {
                return div;
{
            };
type = "Feature",
            logoControl.addTo(map);
geometry = {
        });
type = "Point",
    ]])
coordinates = { options.longitude, options.latitude },
},
properties = {
title = options.text or "Marker", -- Popup text set to `args.text`, fallback is "Marker"
icon = {
iconUrl = "//schoolwiki.in/images/5/5f/63rd_state_kalolsavam_logo.png", -- Custom marker image
iconSize = { 50, 50 }, -- Width and height of the icon
iconAnchor = { 25, 50 }, -- Anchor point (center bottom of the icon)
popupAnchor = { 0, -50 }, -- Popup anchor position
},
},
},
},
})
end


-- Return the mapframe tag with content and options
    -- Combine HTML and script
return frame:extensionTag {
    return tostring(mapHtml) .. tostring(script)
name = "mapframe",
content = content,
args = {
latitude = options.latitude,
longitude = options.longitude,
height = options.height,
width = options.width,
zoom = options.zoom,
align = options.align,
},
}
end
end


return p
return p

18:05, 6 ജനുവരി 2025-നു നിലവിലുണ്ടായിരുന്ന രൂപം

ഈ ഘടകത്തിന്റെ വിവരണം ഘടകം:Slippymap/sandbox/വിവരണം എന്ന താളിൽ നിർമ്മിക്കാവുന്നതാണ്

local p = {}

function p.slippymap(frame)
    -- Get arguments from the template or directly from the page
    local args = frame:getParent().args
    local lat = args["lat"] or "0"  -- Default latitude
    local lon = args["lon"] or "0"  -- Default longitude
    local text = args["text"] or "Location"  -- Default marker text
    local logo = args["logo"] or "File:63rd state kalolsavam logo.png"  -- Default logo image

    -- Generate the HTML for the map
    local mapHtml = mw.html.create("div")
    mapHtml:addClass("leaflet-map")
    mapHtml:attr("style", "width: 100%; height: 400px;")
    mapHtml:attr("id", "map")

    local script = mw.html.create("script")
    script:wikitext([[
        mw.loader.using(['ext.kartographer.static']).then(function() {
            var map = L.map('map').setView([]] .. lat .. [[, ]] .. lon .. [[], 13);
            
            // Add OpenStreetMap tile layer
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                maxZoom: 19
            }).addTo(map);

            // Add marker
            L.marker([]] .. lat .. [[, ]] .. lon .. [[]).addTo(map)
                .bindPopup("]] .. text .. [[")
                .openPopup();

            // Add logo image as a custom control
            var logoControl = L.control({position: 'bottomleft'});
            logoControl.onAdd = function() {
                var div = L.DomUtil.create('div', 'logo');
                div.innerHTML = '<img src="]] .. mw.uri.fullUrl(logo) .. [[" style="width: 100px; height: auto;" />';
                return div;
            };
            logoControl.addTo(map);
        });
    ]])

    -- Combine HTML and script
    return tostring(mapHtml) .. tostring(script)
end

return p
"https://schoolwiki.in/index.php?title=ഘടകം:Slippymap/sandbox&oldid=2624367" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്