MediaWiki:Common.js

From Rise of Agon Wiki
Revision as of 09:12, 25 January 2026 by Admin (talk | contribs) (Revert to single image overlay (tiles problematic))

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Custom Agon World Map with Leaflet (single image overlay)
(function() {
    if (!document.getElementById('agon-map-container')) return;

    var link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';
    document.head.appendChild(link);

    var script = document.createElement('script');
    script.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
    script.onload = function() { initAgonMap(); };
    document.head.appendChild(script);
})();

function initAgonMap() {
    var mapContainer = document.getElementById('agon-map-container');
    if (!mapContainer) return;

    var imageWidth = 16384;
    var imageHeight = 16384;
    
    // Simple bounds matching image dimensions
    var bounds = [[0, 0], [imageHeight, imageWidth]];

    var map = L.map('agon-map-container', {
        crs: L.CRS.Simple,
        minZoom: -3,
        maxZoom: 2,
        center: [imageHeight/2, imageWidth/2],
        zoom: -2
    });

    // Single image overlay
    var imageUrl = mw.config.get('wgScriptPath') + '/resources/assets/AgonBigMap.png';
    L.imageOverlay(imageUrl, bounds).addTo(map);
    
    map.fitBounds(bounds);
    L.control.scale().addTo(map);

    // Click shows pixel coords (Y, X)
    map.on('click', function(e) {
        var y = e.latlng.lat.toFixed(2);
        var x = e.latlng.lng.toFixed(2);
        var text = 'Coordinates: ' + y + ', ' + x;
        console.log(text);
        L.popup().setLatLng(e.latlng).setContent(text).openOn(map);
    });

    // Markers use stored pixel coords 'Y, X'
    if (window.agonMapMarkers) {
        window.agonMapMarkers.forEach(function(marker) {
            var coords = marker.coordinates.split(',').map(parseFloat);
            var icon = L.icon({
                iconUrl: marker.icon || mw.config.get('wgScriptPath') + '/resources/assets/marker-icon.png',
                iconSize: [25, 41],
                iconAnchor: [12, 41],
                popupAnchor: [1, -34]
            });
            L.marker([coords[0], coords[1]], { icon: icon })
                .addTo(map)
                .bindPopup('<b>' + marker.name + '</b><br>' + marker.description);
        });
    }
}