Module:Carte Loto du Patrimoine

 Documentationcréerpurger
local p = {}

function p.carte(frame)
    local args = frame:getParent().args
    local qid = args[1] or error('Paramètre QID manquant (ex: Q133861957)')

    if not qid:match('^Q%d+$') then
        error('Paramètre invalide : doit être un identifiant Wikidata comme Q133861957')
    end

    local query = table.concat({
        'SELECT DISTINCT ?id ?geo ?title',
        '(IF(BOUND(?image), CONCAT(?typeLabel, "\\n", "[[File:", SUBSTR(STR(?image), 52, 400), "|200px]]"), ?typeLabel) AS ?description)',
        "?marker_color ('small' AS ?marker_size)",
        'WHERE { ?id wdt:P1435/wdt:P279* wd:' .. qid .. '; wdt:P625 ?geo; wdt:P31 ?type.',
        'OPTIONAL { ?id wdt:P18 ?image. }',
        'OPTIONAL { ?article schema:about ?id ; schema:inLanguage "fr" ; schema:isPartOf <https://fr.wikipedia.org/> ; schema:name ?wpTitle . }',
        'BIND(EXISTS{?type wdt:P279* wd:Q24398318} AS ?rel)',
        'BIND(EXISTS{?type wdt:P279* wd:Q751876} AS ?cha)',
        'BIND(EXISTS{?type wdt:P279* wd:Q1662011} AS ?ind)',
        'BIND(EXISTS{?type wdt:P279* wd:Q57821} AS ?fort)',
        'BIND(EXISTS{?type wdt:P279* wd:Q10480682} AS ?agr)',
        'BIND(EXISTS{?type wdt:P279* wd:Q114961210} AS ?cul)',
        'BIND(EXISTS{?type wdt:P279* wd:Q11755880} AS ?hab)',
        'BIND(EXISTS{?type wdt:P279* wd:Q294422} AS ?pub)',
        'BIND(EXISTS{?type wdt:P279* wd:Q1107656} AS ?jar)',
        'BIND(EXISTS{?type wdt:P279* wd:Q12280} AS ?eau1)',
        'BIND(EXISTS{?type wdt:P279* wd:Q1690211} AS ?eau2)',
        'BIND(EXISTS{?type wdt:P279* wd:Q2466889} AS ?eau3)',
        'BIND(IF(?pub, "#edb537", IF(?jar, "#1f893f", IF((?eau1 || ?eau2 || ?eau3), "#b6d4fb",',
        'IF(?rel, "#bf3c2c", IF(?cha, "#4b77d6", IF(?ind, "#bb5c26",',
        'IF(?fort, "#534fa3", IF(?agr, "#196551", IF(?cul, "#ac5c90",',
        'IF(?hab, "#f54739", "#54595d")))))))))) AS ?marker_color)',
        'SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,mul,en". ?id rdfs:label ?idLabel. ?type rdfs:label ?typeLabel. }',
        'BIND(IF(BOUND(?wpTitle), CONCAT("[[", ?wpTitle, "|", ?idLabel, "]]"), ?idLabel) AS ?title) } ORDER BY ?id'
    }, ' ')

    local json = mw.text.jsonEncode({
        type    = 'ExternalData',
        service = 'geopoint',
        query   = query
    })

    local legende = table.concat({
        "'''Carte des sites par type de patrimoine''' ''(utiliser le zoom pour afficher les sites ultramarins)'' :",
        '{{Début de colonnes|taille=15}}',
        '{{Légende/Début}}',
        '{{Légende|#196551 |Agricole}}',
        '{{Légende|#edb537 |Architecture civile}}',
        '{{Légende|#4b77d6 |Châteaux}}',
        '{{Légende|#ac5c90 |Culturel}}',
        '{{Légende|#f54739 |Habitation}}',
        '{{Légende|#bb5c26 |Industriel}}',
        "{{Légende|#b6d4fb |Lié à l'eau}}",
        '{{Légende|#534fa3 |Militaire}}',
        '{{Légende|#1f893f |Parc et jardin}}',
        '{{Légende|#bf3c2c |Religieux}}',
        '{{Légende|#54595d |Autre}}',
        '{{Légende/Fin}}',
        '{{Fin de colonnes}}'
    }, '\n')

    return frame:extensionTag({
        name    = 'mapframe',
        content = json,
        args    = {
            width     = 'full',
            height    = '500',
            zoom      = '5',
            longitude = '1.875293',
            latitude  = '46.606109',
            text      = legende
        }
    })
end

return p