MediaWiki:Common.js:修订间差异
来自AG1444
无编辑摘要 |
无编辑摘要 |
||
| 第22行: | 第22行: | ||
const mapMaxZoom = 5; | const mapMaxZoom = 5; | ||
const tileExtent = [0, -7045, 14090, 0]; | const tileExtent = [0, -7045, 14090, 0]; | ||
const crs = L.CRS.Simple; | const crs = L.CRS.Simple; | ||
| 第46行: | 第45行: | ||
tms: false | tms: false | ||
}).addTo(map); | }).addTo(map); | ||
map.fitBounds([ | |||
crs.unproject(L.point(mapExtent[2], mapExtent[3])), | |||
crs.unproject(L.point(mapExtent[0], mapExtent[1])) | |||
]); | |||
L.control.mousePosition().addTo(map); | |||
} | |||
$(initMap); | |||
}); | |||
// 设置地图视野 | // 设置地图视野 | ||
2026年2月4日 (三) 04:18的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 全站加载 Leaflet 地图 */
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css', 'text/css');
mw.loader.load('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/master/src/L.Control.MousePosition.css', 'text/css');
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js');
mw.loader.load('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/master/src/L.Control.MousePosition.js');
mw.loader.using('mediawiki.util', function() {
function initMap() {
const mapDiv = document.getElementById('map');
if (!mapDiv) return;
if (typeof L === 'undefined') {
setTimeout(initMap, 100);
return;
}
// 地图参数
const mapExtent = [0, -7045, 14090, 0];
const mapMinZoom = 0;
const mapMaxZoom = 5;
const tileExtent = [0, -7045, 14090, 0];
const crs = L.CRS.Simple;
crs.transformation = new L.Transformation(1, -tileExtent[0], -1, tileExtent[3]);
crs.scale = function(zoom) {
return Math.pow(2, zoom) / Math.pow(2, mapMaxZoom);
};
crs.zoom = function(scale) {
return Math.log(scale * Math.pow(2, mapMaxZoom)) / Math.LN2;
};
const map = L.map('map', {
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
crs: crs
});
const layer = L.tileLayer('/map/tiles/{z}/{x}/{y}.jpg', {
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
tileSize: L.point(512, 512),
noWrap: true,
tms: false
}).addTo(map);
map.fitBounds([
crs.unproject(L.point(mapExtent[2], mapExtent[3])),
crs.unproject(L.point(mapExtent[0], mapExtent[1]))
]);
L.control.mousePosition().addTo(map);
}
$(initMap);
});
// 设置地图视野
const fitBounds = [
crs.unproject(L.point(mapExtent[2], mapExtent[3])),
crs.unproject(L.point(mapExtent[0], mapExtent[1]))
];
map.fitBounds(fitBounds);
// 设置最大拖动范围
const maxBounds = L.latLngBounds(
crs.unproject(L.point(mapExtent[0], mapExtent[1])),
crs.unproject(L.point(mapExtent[2], mapExtent[3]))
);
map.setMaxBounds(maxBounds);
map.options.maxBoundsViscosity = 1.0;
// 鼠标位置
L.control.mousePosition().addTo(map);
$(initMap);
});
//BGM
mw.loader.using('mediawiki.util', function () {
const bgm = new Audio('/bgm/英雄主义pt.2.mp3');
bgm.loop = true;
bgm.volume = 0.5;
//按钮
const btn = document.createElement('button');
btn.textContent = '🎵';
btn.style.position = 'fixed';
btn.style.right = '12px';
btn.style.bottom = '12px';
btn.style.zIndex = '9999';
btn.style.padding = '6px 10px';
btn.style.background = '#333';
btn.style.color = '#fff';
btn.style.border = 'none';
btn.style.borderRadius = '6px';
btn.style.cursor = 'pointer';
//点击逻辑
btn.onclick = function () {
if (bgm.paused) {
bgm.play();
btn.textContent = '🎵';
} else {
bgm.pause();
btn.textContent = '⏸';
}
};
document.body.appendChild(btn);
});