tampermonkey/src/75-map.js
2026-08-15 19:12:05 +03:00

45 lines
1.2 KiB
JavaScript

function hasMap() {
return document.querySelector(".leaflet-container") !== null
}
function initMapbox() {
addJs('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js')
addCss('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css')
}
function addFullscreenButton() {
$(async () => {
if (document.querySelector("#map") !== null) {
while (L.Control.Fullscreen === undefined) {
await sleep(500)
}
map.addControl(new L.Control.Fullscreen())
}
})
}
function isAllPointsSouthOfLat(lat) {
map.eachLayer(function (layer) {
if (layer instanceof L.Marker) {
let latLng = layer.getLatLng()
if (latLng.lat > lat) {
return false
}
}
})
}
function centerMap() {
if (map !== undefined && L !== undefined) {
let coords = mapsCenterByCompetition[getCompetition()]
if (coords == null) return
if (isAllPointsSouthOfLat(lat)) {
map.setView(new L.LatLng(coords.ifSouthern.lat, coords.ifSouthern.lon), 13)
}
else {
map.setView(new L.LatLng(coords.ifEverywhere.lat, coords.ifEverywhere.lon), 12)
}
}
}