MediaWiki:Common.js: Difference between revisions
From Rise of Agon Wiki
Clamp map to z6 only and downward-positive CRS |
Revert to single image overlay (tiles problematic) |
||
| Line 1: | Line 1: | ||
// Custom Agon World Map with Leaflet ( | // Custom Agon World Map with Leaflet (single image overlay) | ||
(function() { | (function() { | ||
if (!document.getElementById('agon-map-container')) return; | if (!document.getElementById('agon-map-container')) return; | ||
| Line 20: | Line 20: | ||
var imageWidth = 16384; | var imageWidth = 16384; | ||
var imageHeight = 16384; | var imageHeight = 16384; | ||
// Simple bounds matching image dimensions | |||
var bounds = [[0, 0], [imageHeight, imageWidth]]; | |||
var | |||
var map = L.map('agon-map-container', { | var map = L.map('agon-map-container', { | ||
crs: | crs: L.CRS.Simple, | ||
minZoom: | minZoom: -3, | ||
maxZoom: | maxZoom: 2, | ||
center: | center: [imageHeight/2, imageWidth/2], | ||
zoom: | zoom: -2 | ||
}); | }); | ||
var | // Single image overlay | ||
L. | var imageUrl = mw.config.get('wgScriptPath') + '/resources/assets/AgonBigMap.png'; | ||
L.imageOverlay(imageUrl, bounds).addTo(map); | |||
map.fitBounds(bounds); | map.fitBounds(bounds); | ||
L.control.scale().addTo(map); | L.control.scale().addTo(map); | ||
// Click shows pixel coords (Y, X) | // Click shows pixel coords (Y, X) | ||
map.on('click', function(e) { | map.on('click', function(e) { | ||
var | var y = e.latlng.lat.toFixed(2); | ||
var x = e.latlng.lng.toFixed(2); | |||
var x = | |||
var text = 'Coordinates: ' + y + ', ' + x; | var text = 'Coordinates: ' + y + ', ' + x; | ||
console.log(text); | console.log(text); | ||
| Line 71: | Line 51: | ||
if (window.agonMapMarkers) { | if (window.agonMapMarkers) { | ||
window.agonMapMarkers.forEach(function(marker) { | window.agonMapMarkers.forEach(function(marker) { | ||
var coords = marker.coordinates.split(',').map(parseFloat); | var coords = marker.coordinates.split(',').map(parseFloat); | ||
var icon = L.icon({ | var icon = L.icon({ | ||
iconUrl: marker.icon || mw.config.get('wgScriptPath') + '/resources/assets/marker-icon.png', | iconUrl: marker.icon || mw.config.get('wgScriptPath') + '/resources/assets/marker-icon.png', | ||
| Line 79: | Line 58: | ||
popupAnchor: [1, -34] | popupAnchor: [1, -34] | ||
}); | }); | ||
L.marker( | L.marker([coords[0], coords[1]], { icon: icon }) | ||
.addTo(map) | .addTo(map) | ||
.bindPopup('<b>' + marker.name + '</b><br>' + marker.description); | .bindPopup('<b>' + marker.name + '</b><br>' + marker.description); | ||
Revision as of 09:12, 25 January 2026
// 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);
});
}
}
