MediaWiki:CadreCarteOSM.js
Apparence
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./*
Adapté de https://fr.wikivoyage.org/wiki/MediaWiki:CadreCarte.js
Usage: insère une iframe dans un a div avec id "mapdiv", en conjonction avec le modèle Template:CadreCarteOSM
pour l'inclusion de cartes dinamyques. Utilises les paramètes "data" du HTML5.
*/
function insertIFrame(node){
if(!node) node = document;
var exhtml = 'https://tools.wmflabs.org/wikivoyage/w/poimap2.php?';
var maps = $.makeArray( $(node).find('div.mapdiv') );
alert(maps.length);
if(!maps.length) return;
for(var a=0,l=maps.length;a<l;a++){
var map = maps[a];
validateMap(map);
var exsrc = exhtml+'lat='+map.data("lat")+'&lon='+map.data("long")
+'&zoom='+map.data("zoom")+'&layer='+map.data("layer")+'&lang='+mw.config.get('wgContentLanguage')+'&name='+mw.config.get('wgPageName');
var ifstr = '<iframe src="'+exsrc+'" width="'+map.data("width")+'" height="'+map.data("height")
+'" style="border:0"></iframe>';
map.html(ifstr);
/*
if ( map.data("layer").indexOf('O') < 0 ) {
$('.vcard a').attr('href', function () { return this.href.replace('layer=O','layer='+map.data("layer")[0]) });
}
*/
}
}
function validateMap(map) {
if (!$.isNumeric(map.data("lat"))) map.data("lat", 51.47766);
if (!$.isNumeric(map.data("long"))) map.data("long", -0.00115);
if (!$.isNumeric(map.data("zoom")) && map.data("zoom") != 'auto') map.data("zoom", 14);
if (!$.isNumeric(map.data("height"))) map.data("height", 420);
if (!$.isNumeric(map.data("width"))) map.data("width", 420);
if (map.data("layer").length > 8) map.data("layer", 'O');
}
$(document).ready(insertIFrame);