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


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


  var el=document.getElementById('treeverse-map');
    // ====== EDIT THIS: exact filename (case-sensitive) ======
  if(!el) return;
    var file='TreeverseMap.jpeg';
    // ========================================================


  // === CONFIGURE THESE ===
    // Build an absolute URL to the file (follows Special:FilePath redirect)
  var file='TreeverseMap.jpeg'; // must match your uploaded filename
    var relative = mw.util.getUrl('Special:FilePath/' + file);
  var w=1000, h=856;         // pixel size of your map image
    var url = new URL(relative, window.location.origin).href;
  // ========================


  var url=mw.util.getUrl('Special:FilePath/'+file);
    // Load the image first to get accurate pixel size
  var map=L.map(el,{crs:L.CRS.Simple,minZoom:-2,maxZoom:4});
    var img = new Image();
  var bounds=[[0,0],[h,w]];
    img.onload = function(){
  L.imageOverlay(url,bounds).addTo(map);
      var w = img.naturalWidth, h = img.naturalHeight;
  map.fitBounds(bounds);
      if(!w || !h){
        console.error('Treeverse map: could not read image size.');
        return;
      }


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


  // Marker with popup
      L.imageOverlay(url, bounds).addTo(map);
  L.marker([1000,1500]).addTo(map)
      map.fitBounds(bounds);
  .bindPopup('<b>Crystal Cave</b><br>Rare ores spawn here.');


  // Circle annotation
      // Example annotations (y, x)
  L.circle([800,500], {radius:50, color:'red'}).addTo(map)
      L.marker([Math.floor(h/2), Math.floor(w/2)]).addTo(map)
  .bindPopup('⚠ Danger Zone');
        .bindPopup('<b>Center of the map</b>');


  // Polygon annotation (guild land)
      // Add your own markers/shapes below...
  L.polygon([[1200,400],[1300,450],[1250,600]], {color:'blue'}).addTo(map)
    };
  .bindPopup('Guild Territory');


  // Polyline (path/route)
    img.onerror = function(){
  L.polyline([[600,300],[700,400],[800,420]], {color:'green'}).addTo(map)
      console.error('Treeverse map: image failed to load ->', url);
  .bindPopup('Quest Route');
      alert('Map image could not load.\nCheck the filename and that Special:FilePath opens the image.');
    };


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

Revision as of 23:05, 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.jpeg';
    // ========================================================

    // 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);
})();