Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 14: Line 14:


     // ====== EDIT THIS: exact filename (case-sensitive) ======
     // ====== EDIT THIS: exact filename (case-sensitive) ======
     var file='TreeverseMap.JPEG';
     var file='TreeverseMap.jpg';
     // ========================================================
     // ========================================================



Revision as of 23:12, 26 August 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Load Leaflet CSS
(function(){
  var lcss=document.createElement('link');
  lcss.rel='stylesheet';
  lcss.href='https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';
  document.head.appendChild(lcss);

  var s=document.createElement('script');
  s.src='https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
  s.onload=function initTreeverseMap(){
    var el=document.getElementById('treeverse-map');
    if(!el) return;

    // ====== EDIT THIS: exact filename (case-sensitive) ======
    var file='TreeverseMap.jpg';
    // ========================================================

    // Build an absolute URL to the file (follows Special:FilePath redirect)
    var relative = mw.util.getUrl('Special:FilePath/' + file);
    var url = new URL(relative, window.location.origin).href;

    // Load the image first to get accurate pixel size
    var img = new Image();
    img.onload = function(){
      var w = img.naturalWidth, h = img.naturalHeight;
      if(!w || !h){
        console.error('Treeverse map: could not read image size.');
        return;
      }

      var map = L.map(el, { crs: L.CRS.Simple, minZoom: -2, maxZoom: 5 });
      var bounds = [[0,0],[h,w]];

      L.imageOverlay(url, bounds).addTo(map);
      map.fitBounds(bounds);

      // Example annotations (y, x)
      L.marker([Math.floor(h/2), Math.floor(w/2)]).addTo(map)
        .bindPopup('<b>Center of the map</b>');

      // Add your own markers/shapes below...
    };

    img.onerror = function(){
      console.error('Treeverse map: image failed to load ->', url);
      alert('Map image could not load.\nCheck the filename and that Special:FilePath opens the image.');
    };

    // Bust cache once to avoid stale redirects
    img.src = url + (url.includes('?') ? '&' : '?') + 'v=' + Date.now();
  };
  document.head.appendChild(s);
})();