MediaWiki:Common.js
Page de l’interface de MediaWiki
Autres actions
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
/* Carte du Mùndì
Remplace tout <div class="carte-mundi"></div> par une carte Leaflet : fond de
relief 4K, zones et villes lues dans GeoJson:CarteMundi, calques à cocher et
bulles avec liens vers le wiki.
Leaflet vient de l'extension Maps (module ext.maps.leaflet.library).
Repère : celui de Maps, que la page GeoJson:CarteMundi utilise aussi. L'image
occupe [0..100] en longitude et [0..56,25] en latitude, latitude vers le haut.
Depuis un pixel (x, y) du rendu 3840×2160 : lng = x / 38,4 ; lat = (2160 − y) / 38,4. */
( function () {
'use strict';
var FOND = 'Map Mundi - Relief.webp';
var SOURCE = 'GeoJson:CarteMundi';
var BORNES = [ [ 0, 0 ], [ 56.25, 100 ] ];
// Ordre d'empilement et d'affichage dans le sélecteur
var GROUPES = [
{ id: 'bazinn', nom: 'Bàʒìnn', visible: true },
{ id: 'capitale', nom: 'Capitales', visible: true },
{ id: 'ville', nom: 'Villes', visible: true }
];
var STYLE_POINT = {
capitale: { radius: 7, color: '#1a0c14', weight: 3, fillColor: '#f53da2', fillOpacity: 1 },
ville: { radius: 4.5, color: '#1a0c14', weight: 2, fillColor: '#ffffff', fillOpacity: 1 }
};
function lien( titre, texte ) {
return $( '<a>' ).attr( 'href', mw.util.getUrl( titre ) ).text( texte );
}
function bulle( p ) {
var $b = $( '<div>' ).addClass( 'carte-mundi-bulle' );
$( '<strong>' ).append( p.page ? lien( p.page, p.title ) : document.createTextNode( p.title ) ).appendTo( $b );
if ( p.description ) {
$( '<div>' ).text( p.description ).appendTo( $b );
}
// Ville sans page : on renvoie au moins vers son Bàʒìnn
if ( !p.page && p.bazinn ) {
$( '<div>' ).append( lien( p.bazinn, 'Voir le ' + p.bazinn + ' →' ) ).appendTo( $b );
} else if ( p.page ) {
$( '<div>' ).append( lien( p.page, 'Voir la page →' ) ).appendTo( $b );
}
return $b[ 0 ];
}
function pastille( id ) {
var s = id === 'bazinn' ?
'background:linear-gradient(135deg,#c0392b,#2980b9);border-radius:2px' :
'background:' + STYLE_POINT[ id ].fillColor + ';border:2px solid ' + STYLE_POINT[ id ].color + ';border-radius:50%';
return '<span class="carte-mundi-pastille" style="' + s + '"></span>';
}
function construire( el, geojson ) {
var carte = L.map( el, {
crs: L.CRS.Simple,
zoomSnap: 0.25,
maxZoom: 6,
maxBounds: L.latLngBounds( BORNES ).pad( 0.15 ),
fullscreenControl: true,
attributionControl: false
} );
L.imageOverlay( mw.util.getUrl( 'Special:FilePath/' + FOND ), BORNES ).addTo( carte );
carte.fitBounds( BORNES );
carte.setMinZoom( carte.getZoom() - 0.5 );
var calques = {};
GROUPES.forEach( function ( g ) {
calques[ g.id ] = L.featureGroup();
} );
L.geoJSON( geojson, {
style: function ( f ) {
var p = f.properties;
return {
color: p.stroke, weight: p[ 'stroke-width' ], opacity: p[ 'stroke-opacity' ],
fillColor: p.fill, fillOpacity: p[ 'fill-opacity' ]
};
},
pointToLayer: function ( f, latlng ) {
return L.circleMarker( latlng, STYLE_POINT[ f.properties.groupe ] || STYLE_POINT.ville );
},
onEachFeature: function ( f, couche ) {
var p = f.properties;
couche.bindPopup( bulle( p ) );
couche.bindTooltip( p.title, { direction: 'top', sticky: !( couche instanceof L.CircleMarker ) } );
( calques[ p.groupe ] || calques.ville ).addLayer( couche );
}
} );
var selecteur = {};
GROUPES.forEach( function ( g ) {
selecteur[ pastille( g.id ) + g.nom ] = calques[ g.id ];
if ( g.visible ) {
calques[ g.id ].addTo( carte );
}
} );
L.control.layers( null, selecteur, { collapsed: false } ).addTo( carte );
// Les points restent toujours au-dessus des zones, même après un décochage
carte.on( 'overlayadd', function () {
calques.capitale.bringToFront();
calques.ville.bringToFront();
} );
}
mw.hook( 'wikipage.content' ).add( function ( $contenu ) {
$contenu.find( '.carte-mundi' ).each( function () {
var el = this;
if ( $( el ).data( 'carte-mundi' ) ) {
return;
}
$( el ).data( 'carte-mundi', true );
$.when(
mw.loader.using( [ 'mediawiki.util', 'ext.maps.leaflet.library', 'ext.maps.leaflet.fullscreen' ] ),
$.getJSON( mw.config.get( 'wgScript' ), { title: SOURCE, action: 'raw', ctype: 'application/json' } )
).then( function ( _, reponse ) {
$( el ).empty();
construire( el, reponse[ 0 ] );
}, function () {
$( el ).text( 'La carte n’a pas pu être chargée.' );
} );
} );
} );
}() );