Difference between revisions of "MediaWiki:Common.js"

From Medivia Online Wiki
Line 1: Line 1:
// Load Leaflet JS and CSS
$(document).ready(function () {
mw.loader.using(['mediawiki.util'], function () {
   const maps = document.querySelectorAll('.medivia-map');
   var leafletScript = mw.loader.getScript('https://unpkg.com/[email protected]/dist/leaflet.js');
   if (!maps.length) return;
   mw.loader.load('https://unpkg.com/[email protected].4/dist/leaflet.css', 'text/css');


   leafletScript.then(function () {
   // Load Leaflet CSS
    // Only runs after Leaflet (L) is defined
  mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.css', 'text/css');
    $('.medivia-map').each(function () {
 
      const el = this;
  // Load Leaflet JS
       const x = parseInt(el.dataset.x);
  $.getScript('https://unpkg.com/[email protected]/dist/leaflet.js', function () {
       const y = parseInt(el.dataset.y);
    maps.forEach(function (el) {
       const z = parseInt(el.dataset.z);
       const x = parseInt(el.dataset.x || 2048, 10);
       const zoom = parseInt(el.dataset.zoom);
       const y = parseInt(el.dataset.y || -2047, 10);
       const z = parseInt(el.dataset.z || 7, 10);
       const zoom = parseInt(el.dataset.zoom || 2, 10);


       const map = L.map(el, {
       const map = L.map(el, {
         crs: L.CRS.Simple,
         crs: L.CRS.Simple,
        zoomSnap: 1,
         minZoom: 0,
         minZoom: 0,
         maxZoom: 7,
         maxZoom: 5
        center: [y, x],
        zoom: zoom
       });
       });
      const bounds = [[0, 0], [4096, 4096]];
      map.setView([x, y], zoom);


       L.tileLayer('https://tafonath.github.io/medivia-mapper/tiles/{z}/{x}/{y}.png', {
       L.tileLayer('https://tafonath.github.io/medivia-mapper/tiles/{z}/{x}/{y}.png', {
        attribution: '© Medivia',
         tileSize: 256,
         tileSize: 256,
         noWrap: true
         noWrap: true,
        bounds: bounds,
        maxZoom: 5,
        minZoom: 0,
        attribution: '© Tafonath'
       }).addTo(map);
       }).addTo(map);
      map.setView([y, x], zoom);
     });
     });
   });
   });
});
});

Revision as of 11:04, 5 July 2025

$(document).ready(function () {
  const maps = document.querySelectorAll('.medivia-map');
  if (!maps.length) return;

  // Load Leaflet CSS
  mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.css', 'text/css');

  // Load Leaflet JS
  $.getScript('https://unpkg.com/[email protected]/dist/leaflet.js', function () {
    maps.forEach(function (el) {
      const x = parseInt(el.dataset.x || 2048, 10);
      const y = parseInt(el.dataset.y || -2047, 10);
      const z = parseInt(el.dataset.z || 7, 10);
      const zoom = parseInt(el.dataset.zoom || 2, 10);

      const map = L.map(el, {
        crs: L.CRS.Simple,
        zoomSnap: 1,
        minZoom: 0,
        maxZoom: 5
      });

      const bounds = [[0, 0], [4096, 4096]];
      map.setView([x, y], zoom);

      L.tileLayer('https://tafonath.github.io/medivia-mapper/tiles/{z}/{x}/{y}.png', {
        tileSize: 256,
        noWrap: true,
        bounds: bounds,
        maxZoom: 5,
        minZoom: 0,
        attribution: '© Tafonath'
      }).addTo(map);
    });
  });
});