Difference between revisions of "MediaWiki:Common.js"

From Medivia Online Wiki
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.css', 'text/css'); mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.js'); $(function () { $('.medivia-map').each(function () { const el = this; const x = parseInt(el.dataset.x); const y = parseInt(el.dataset.y); const z = parseInt(el.dataset.z); const zoom = parseInt(el.dataset.zoom); const map = L...")
 
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
// Load Leaflet JS and CSS
mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.css', 'text/css');
mw.loader.using(['mediawiki.util'], function () {
mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.js');
  var leafletScript = mw.loader.getScript('https://unpkg.com/[email protected]/dist/leaflet.js');
  mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.css', 'text/css');


$(function () {
  leafletScript.then(function () {
  $('.medivia-map').each(function () {
    // Only runs after Leaflet (L) is defined
    const el = this;
    $('.medivia-map').each(function () {
    const x = parseInt(el.dataset.x);
      const el = this;
    const y = parseInt(el.dataset.y);
      const x = parseInt(el.dataset.x);
    const z = parseInt(el.dataset.z);
      const y = parseInt(el.dataset.y);
    const zoom = parseInt(el.dataset.zoom);
      const z = parseInt(el.dataset.z);
      const zoom = parseInt(el.dataset.zoom);


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


    // Define the tile URL pattern based on Medivia Mapper structure
      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',
      attribution: '© Medivia',
        tileSize: 256,
      tileSize: 256,
        noWrap: true
      noWrap: true
      }).addTo(map);
    }).addTo(map);


    map.setView([y, x], zoom);
      map.setView([y, x], zoom);
    });
   });
   });
});
});

Revision as of 10:59, 5 July 2025

// Load Leaflet JS and CSS
mw.loader.using(['mediawiki.util'], function () {
  var leafletScript = mw.loader.getScript('https://unpkg.com/[email protected]/dist/leaflet.js');
  mw.loader.load('https://unpkg.com/[email protected]/dist/leaflet.css', 'text/css');

  leafletScript.then(function () {
    // Only runs after Leaflet (L) is defined
    $('.medivia-map').each(function () {
      const el = this;
      const x = parseInt(el.dataset.x);
      const y = parseInt(el.dataset.y);
      const z = parseInt(el.dataset.z);
      const zoom = parseInt(el.dataset.zoom);

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

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

      map.setView([y, x], zoom);
    });
  });
});