feat: make marker not hardcoded

This commit is contained in:
TheClashFruit 2024-01-13 23:12:46 +01:00
parent 3a17988114
commit 8bcebc7069
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
13 changed files with 196 additions and 103 deletions

1
css/map.min.css vendored Normal file
View file

@ -0,0 +1 @@
*{padding:0;margin:0;box-sizing:border-box}#map{height:100vh}#homeLink{position:absolute;bottom:10px;left:10px;padding:5px 10px;z-index:400;background-color:#fff;background-clip:padding-box;border:2px solid rgba(0,0,0,.2);border-radius:5px;text-decoration:none;color:#000}img.leaflet-tile{image-rendering:pixelated}.leaflet-control{color:#333}.leaflet-control-mouseposition{background:rgba(255,255,255,.8);margin:0 !important;padding:6px;width:calc(100% - 12px);text-align:end;border-top-left-radius:5px}.leaflet-marker-icon{transition:300ms}/*# sourceMappingURL=map.min.css.map */

1
css/map.min.css.map Normal file
View file

@ -0,0 +1 @@
{"version":3,"sourceRoot":"","sources":["src/map.scss"],"names":[],"mappings":"AAAA,EACE,UACA,SAEA,sBAKF,kBAEA,UACE,kBACA,YACA,UACA,iBACA,YAEA,sBACA,4BAEA,gCACA,kBAEA,qBACA,WAGF,iBACE,0BAGF,iBACE,WAGF,+BACE,gCAEA,oBACA,YAEA,wBAEA,eAEA,2BAGF,qBACE","file":"map.min.css"}

52
css/src/map.scss Normal file
View file

@ -0,0 +1,52 @@
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
/// old
#map { height: 100vh; }
#homeLink {
position: absolute;
bottom: 10px;
left: 10px;
padding: 5px 10px;
z-index: 400;
background-color: #fff;
background-clip: padding-box;
border: 2px solid rgba(0,0,0,0.2);
border-radius: 5px;
text-decoration: none;
color: #000;
}
img.leaflet-tile {
image-rendering: pixelated;
}
.leaflet-control {
color: #333;
}
.leaflet-control-mouseposition {
background: rgba(255, 255, 255, 0.8);
margin: 0 !important;
padding: 6px;
width: calc(100% - 2 * 6px);
text-align: end;
border-top-left-radius: 5px;
}
.leaflet-marker-icon {
transition: 300ms;
}

View file

@ -314,7 +314,7 @@ a {
&, > * { transition: 0.16s }
&:not(.openned) {
&:not(.opened) {
opacity: 0;
pointer-events: none;

2
css/style.min.css vendored

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["src/_fonts.scss","src/style.scss","src/colors/_light.scss","src/colors/_dark.scss"],"names":[],"mappings":"CAEQ,qKAER,WACE,sDAGF,kBACE,mDACA,gBAIF,UACE,uECXF,EACC,0CAGD,4BAEA,KACE,SAEA,WCXO,KDYP,MCXO,KDaP,mCANF,KAOI,WEfK,QFgBL,MEfK,MFmBT,KACC,gBAEA,eACC,sBACA,gBACA,WACA,oBACA,iBAGD,gBACC,sBACA,gBACA,UAIF,WACE,gBAEA,WAEA,cAEA,aACA,sBAGF,MACE,2BAGF,EACE,gBACA,YAGF,IACE,eAGF,OACC,aACA,eACA,QACA,WAEA,yBAND,OAOE,UAIF,MACC,kBACA,aACA,sBACA,sBACA,eACA,aACC,qBACA,kBACA,iBACA,eACA,gBAED,0BACC,WCzEa,QD0Eb,MCvFO,KD+FP,gBAsBD,iCA5BC,mCAjBF,MAkBI,cE3Ee,QF4Ef,WE9EW,QF+EZ,ME5FM,MFiGP,YACC,kBACA,cCxFS,QDyFT,WC1FK,QD2FL,MCnGM,QD2GP,gBANC,mCAND,YAOG,cE7FO,QF8FP,WE/FG,QFgGJ,MEvGQ,SF4GT,kBACC,gBACA,qBAMF,yBA/CF,MAgDE,uBAGD,yBAnDD,MAoDG,kBACD,YAGA,SACC,SACA,gBACA,gBAGD,YACC,kBACA,MACA,QACA,YACA,iBACA,iBAEA,wEAKA,gBAJA,mCATD,YAUE,yEAMF,QACC,aAIH,EACE,MC1JO,QD4JP,mCAHF,EAII,ME5JQ,SF+JV,UACE,WAIJ,UACE,iBACE,uGASF,2BACA,sBAEA,aATA,mCALF,UAMI,iBACA,kGASF,qBACE,YAEA,aACA,mBAEA,mBACA,8BAEA,yBATF,qBAUI,wBAGF,yBACE,aACA,sBAEA,SAEA,kCACE,uBAEA,yBAHF,kCAII,oBAGF,mCACE,wDAGF,uCACE,eACA,YAIJ,4CAKE,mBACA,QALA,yBADF,4CAEI,cAMF,kDACE,kBACA,eAEA,qEACE,cACA,2BACA,yBAQZ,WAIE,WAEA,eACA,QACA,UACA,eAEA,WC3PO,QD4PP,MCxPY,KD+PZ,iBAEA,mBAEA,iBACA,iBAEA,eAzBA,yBADF,WAEI,cAYF,mCAdF,WAeG,WE/PM,QFgQN,ME5PW,MFyQd,SACE,WAEA,qBACA,uBAEA,WC3QM,QD6QN,mCARF,SASI,aE7QQ,QF8QR,WE/QI,SFkRN,oBACE,kBAEA,aACA,eAEA,mBACA,8BAEA,yBATF,oBAUI,eACA,MACA,OACA,WACA,YACA,UAEF,2BACC,iCAKA,uBACC,sBACA,UANF,yDAnBF,oBAoBI,8BAXF,yBAkBE,0DAEA,kCACE,UACA,oBAGA,gEAIJ,wBACE,SAEA,aACA,eACA,qBAEA,QAEA,yBATF,wBAUG,WACC,uBAGF,0BACE,mBACA,iBAEA,eACA,sBACA,MC7Ta,QD4Ub,qBAEA,iBAEA,mBAEA,gCAEA,gBAtBA,mCAPF,0BAOwC,MElUzB,SFoUb,yBATF,0BAUI,eACA,aACA,iBACA,eAEA,yCACC,aAeH,iCACC,oBAGD,iEAEE,MCnXD,QDoXC,cC9VY,QDsWZ,gBANA,mCALF,iEAMI,MEnWS,QFoWT,cEtWU,SF6Wd,yBACC,wCACE,WCjYF,QDkYE,MC9XG,KDqYH,4BALA,yDAJF,wCAKI,WErYJ,QFsYI,MElYC,MFiZd,YACE,WAEA,uBACE,aACA,eACA,SAEA,yBACE,aACA,QAEA,eAEA,cAEA,6BACE,UAEA,mCAHF,6BAII,kBAIJ,4CACE","file":"style.min.css"}
{"version":3,"sourceRoot":"","sources":["src/_fonts.scss","src/style.scss","src/colors/_light.scss","src/colors/_dark.scss"],"names":[],"mappings":"CAEQ,qKAER,WACE,sDAGF,kBACE,mDACA,gBAIF,UACE,uECXF,EACC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PM,QFgQN,ME5PW,MFyQd,SACE,WAEA,qBACA,uBAEA,WC3QM,QD6QN,mCARF,SASI,aE7QQ,QF8QR,WE/QI,SFkRN,oBACE,kBAEA,aACA,eAEA,mBACA,8BAEA,yBATF,oBAUI,eACA,MACA,OACA,WACA,YACA,UAEF,2BACC,iCAKA,uBACC,sBACA,UANF,yDAnBF,oBAoBI,8BAXF,yBAkBE,0DAEA,iCACE,UACA,oBAGA,+DAIJ,wBACE,SAEA,aACA,eACA,qBAEA,QAEA,yBATF,wBAUG,WACC,uBAGF,0BACE,mBACA,iBAEA,eACA,sBACA,MC7Ta,QD4Ub,qBAEA,iBAEA,mBAEA,gCAEA,gBAtBA,mCAPF,0BAOwC,MElUzB,SFoUb,yBATF,0BAUI,eACA,aACA,iBACA,eAEA,yCACC,aAeH,iCACC,oBAGD,iEAEE,MCnXD,QDoXC,cC9VY,QDsWZ,gBANA,mCALF,iEAMI,MEnWS,QFoWT,cEtWU,SF6Wd,yBACC,wCACE,WCjYF,QDkYE,MC9XG,KDqYH,4BALA,yDAJF,wCAKI,WErYJ,QFsYI,MElYC,MFiZd,YACE,WAEA,uBACE,aACA,eACA,SAEA,yBACE,aACA,QAEA,eAEA,cAEA,6BACE,UAEA,mCAHF,6BAII,kBAIJ,4CACE","file":"style.min.css"}

View file

@ -33,9 +33,10 @@
$json = json_decode($res->body, true);
if($json != null) {
if($json != null)
$twig->addGlobal('playerCount', count($json));
}
else
$twig->addGlobal('playerCount', $json);
$twig->addGlobal('nations', $nations);
@ -66,9 +67,10 @@
});
$router->get('/map', function() {
global $twig;
global $twig, $mysql;
$twig->addGlobal('pageUri', '/map');
$twig->addGlobal('markers', json_encode($mysql->getMarkers()));
if(isset($_GET['center']))
$twig->addGlobal('center', $_GET['center']);
@ -124,6 +126,26 @@
}
});
// ---------------- Admin ---------------- //
$router->get('/admin', function() {
global $twig, $mysql;
$twig->addGlobal('pageUri', '/admin');
$user = $mysql->getUserRecordFromId($_SESSION['user']['id']);
if($user == null && $user['admin'] == 0) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('admin/index.twig', array('db_data' => $user));
}
});
// ----------------- 404 ----------------- //
$router->set404(function() {
global $twig;

View file

@ -36,21 +36,40 @@ let mapLayer = L.tileLayer.crssLayer('https://cdn.theclashfruit.me/crss/map_new/
zoomOffset: -8
});
let ropMarkers = L.layerGroup([
L.marker([-75.5, 49.5])
.bindPopup('Info Centre')
]);
let ropMarkers = L.layerGroup([]);
let drrMarkers = L.layerGroup([
let drrMarkers = L.layerGroup([]);
]);
let miscMarkers = L.layerGroup([]);
let miscMarkers = L.layerGroup([
L.marker([0.5, 0.5])
.bindPopup('0; 0'),
L.marker([1302.5, -661.5])
.bindPopup('The Dropper'),
]);
markers.forEach(marker => {
const coords = marker.data.split(';');
switch (marker.category) {
case 'rop':
ropMarkers
.addLayer(
L.marker([
parseInt(coords[0]), parseInt(coords[1])
]).bindPopup(marker.name)
);
break;
case 'drr':
drrMarkers.addLayer(
L.marker([
parseInt(coords[0]), parseInt(coords[1])
]).bindPopup(marker.name)
);
break;
default:
miscMarkers.addLayer(
L.marker([
parseInt(coords[0]), parseInt(coords[1])
]).bindPopup(marker.name)
);
break;
}
});
let playerMarkers = L.layerGroup([

View file

@ -4,15 +4,15 @@ const navToggle = $(".navToggle");
const menu = $(".pageNav > .container");
navToggle.onclick = () => {
const menuToggled = menu.classList.contains("openned");
const menuToggled = menu.classList.contains("opened");
if (menuToggled) {
menu.classList.remove("openned");
menu.classList.remove("opened");
} else {
menu.classList.add("openned");
menu.classList.add("opened");
}
navToggle.innerHTML = menuToggled ? "Menu" : "Close";
}
window.addEventListener("transitionBuffering", () => menu.classList.remove("openned"));
window.addEventListener("transitionBuffering", () => menu.classList.remove("opened"));

19
template/admin/index.twig Normal file
View file

@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<title>Admin Panel</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<h1 class="text-center">soon</h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View file

@ -1,13 +1,14 @@
{% if reduced %} <title>{{ pageTitle }} &nbsp;&bull;&nbsp; Clyde's Real Survival SMP</title> {% endif %}
{% if not reduced %}
<!doctype html>
<html lang="en">
{% if reduced %}
<title>{{ pageTitle }} &bull; Clyde's Real Survival SMP</title>
{% else %}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>{{ pageTitle }} &nbsp;&bull;&nbsp; Clyde's Real Survival SMP</title>
<title>{{ pageTitle }} &bull; Clyde's Real Survival SMP</title>
<meta name="name" content="Clyde's Real Survival SMP &bull; {{ pageTitle }}" />
<meta name="description" content="A very cool minecraft SMP that updates to every version starting from b1.0." />
@ -31,59 +32,17 @@
<script src="/js/main.js" type="module"></script>
{% if pageTitle == 'Map' %}
{% if pageUri == '/map' %}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
<link rel="stylesheet" href="/css/map.min.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet-mouse-position@1.2.0/src/L.Control.MousePosition.min.js"></script>
<style>
#map { height: 100vh; }
#homeLink {
position: absolute;
bottom: 10px;
left: 10px;
padding: 5px 10px;
z-index: 400;
background-color: #fff;
background-clip: padding-box;
border: 2px solid rgba(0,0,0,0.2);
border-radius: 5px;
text-decoration: none;
color: #000;
}
img.leaflet-tile {
image-rendering: pixelated;
}
.leaflet-control {
color: #333;
}
.leaflet-control-mouseposition {
background: rgba(255, 255, 255, 0.8);
margin: 0 !important;
padding: 6px;
width: calc(100% - 2 * 6px);
text-align: end;
border-top-left-radius: 5px;
}
.leaflet-marker-icon {
transition: 300ms;
}
</style>
{% endif %}
<link rel="icon" href="/favicon.ico">
<link rel="stylesheet" href="/css/style.min.css">
</head>
<body> {% endif %}
<body>
{% endif %}

View file

@ -1,9 +1,13 @@
{% include 'includes/head.twig' with {'pageTitle': 'Map'} %}
<div id="map"></div>
<a id="homeLink" href="/">Go Home</a>
<script>const center = "{{ center }}";</script>
<script>
const center = "{{ center }}";
const markers = {{ markers|raw }};
</script>
<script src="js/map.js"></script>
{% include 'includes/foot.twig' %}

View file

@ -57,4 +57,20 @@
return null;
}
}
function getMarkers() {
$sql = 'SELECT * FROM markers';
$stmt = $this->conn->prepare($sql);
$stmt->execute();
$res = $stmt->get_result();
if($res->num_rows > 0) {
return $res->fetch_all(MYSQLI_ASSOC);
} else {
return null;
}
}
}