mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
Cleaning
This commit is contained in:
@@ -11,10 +11,6 @@ export default function useAdmin() {
|
||||
return teams.find(team => team.id === teamId);
|
||||
}
|
||||
|
||||
function reorderTeams(newOrder) {
|
||||
adminSocket.emit("reorder_teams", newOrder);
|
||||
}
|
||||
|
||||
function addTeam(teamName) {
|
||||
adminSocket.emit("add_team", teamName);
|
||||
}
|
||||
@@ -23,6 +19,10 @@ export default function useAdmin() {
|
||||
adminSocket.emit("remove_team", teamId);
|
||||
}
|
||||
|
||||
function reorderTeams(newOrder) {
|
||||
adminSocket.emit("reorder_teams", newOrder);
|
||||
}
|
||||
|
||||
function captureTeam(teamId) {
|
||||
adminSocket.emit("capture_team", teamId);
|
||||
}
|
||||
|
||||
@@ -2,42 +2,34 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function useMapCircleDraw(circle, setCircle) {
|
||||
const [drawing, setDrawing] = useState(false);
|
||||
const [center, setCenter] = useState(circle?.center || null);
|
||||
const [radius, setRadius] = useState(circle?.radius || null);
|
||||
const [drawingCircle, setDrawingCircle] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
setDrawing(false);
|
||||
setCenter(circle?.center || null);
|
||||
setRadius(circle?.radius || null);
|
||||
}, [circle])
|
||||
setDrawingCircle(null);
|
||||
}, [circle]);
|
||||
|
||||
function handleLeftClick(e) {
|
||||
if (!drawing) {
|
||||
setCenter(e.latlng);
|
||||
setRadius(null);
|
||||
setDrawing(true);
|
||||
if (drawingCircle) {
|
||||
setCircle(drawingCircle);
|
||||
setDrawingCircle(null);
|
||||
} else {
|
||||
setDrawing(false);
|
||||
setCircle({center, radius});
|
||||
setDrawingCircle({center: e.latlng, radius: 0});
|
||||
}
|
||||
}
|
||||
|
||||
function handleRightClick(e) {
|
||||
if (drawing) {
|
||||
setDrawing(false);
|
||||
setCenter(circle?.center || null);
|
||||
setRadius(circle?.radius || null);
|
||||
} else {
|
||||
if (drawingCircle) {
|
||||
setDrawingCircle(null);
|
||||
} else if (e.latlng.distanceTo(circle.center) < circle.radius) {
|
||||
setCircle(null);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMouseMove(e) {
|
||||
if (drawing) {
|
||||
setRadius(e.latlng.distanceTo(center));
|
||||
if (drawingCircle) {
|
||||
setDrawingCircle({center: drawingCircle.center, radius: e.latlng.distanceTo(drawingCircle.center)});
|
||||
}
|
||||
}
|
||||
|
||||
return { center, radius, handleLeftClick, handleRightClick, handleMouseMove };
|
||||
return { drawingCircle, handleLeftClick, handleRightClick, handleMouseMove };
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function useLocation(interval) {
|
||||
const [location, setLocation] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!navigator.geolocation) {
|
||||
console.log('Geolocation not supported');
|
||||
return;
|
||||
}
|
||||
|
||||
if (interval < 1000 || interval == Infinity) {
|
||||
console.log('Localisation interval no supported');
|
||||
return;
|
||||
}
|
||||
|
||||
const watchId = navigator.geolocation.watchPosition(
|
||||
(pos) => {
|
||||
setLocation({
|
||||
lat: pos.coords.latitude,
|
||||
lng: pos.coords.longitude,
|
||||
accuracy: pos.coords.accuracy,
|
||||
timestamp: pos.timestamp
|
||||
});
|
||||
},
|
||||
(err) => console.log("Error :", err),
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
timeout: 10000,
|
||||
maximumAge: interval,
|
||||
}
|
||||
);
|
||||
|
||||
return () => navigator.geolocation.clearWatch(watchId);
|
||||
}, []);
|
||||
|
||||
return location;
|
||||
}
|
||||
@@ -2,32 +2,16 @@
|
||||
|
||||
export default function useMultipleCircleDraw(circles, addCircle, removeCircle, radius) {
|
||||
|
||||
function getDistanceFromLatLon({ lat: lat1, lng: lon1 }, { lat: lat2, lng: lon2 }) {
|
||||
const degToRad = (deg) => deg * (Math.PI / 180);
|
||||
var R = 6371; // Radius of the earth in km
|
||||
var dLat = degToRad(lat2 - lat1);
|
||||
var dLon = degToRad(lon2 - lon1);
|
||||
var a =
|
||||
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
||||
Math.cos(degToRad(lat1)) * Math.cos(degToRad(lat2)) *
|
||||
Math.sin(dLon / 2) * Math.sin(dLon / 2)
|
||||
;
|
||||
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
var d = R * c; // Distance in km
|
||||
return d * 1000;
|
||||
}
|
||||
|
||||
function isBaddlyPlaced(latlng) {
|
||||
return circles.some(circle => getDistanceFromLatLon(latlng, circle.center) < 2 * circle.radius);
|
||||
return circles.some(circle => latlng.distanceTo(circle.center) < 2 * circle.radius);
|
||||
}
|
||||
|
||||
function getCircleFromLatlng(latlng) {
|
||||
return circles.find(circle => getDistanceFromLatLon(latlng, circle.center) < circle.radius);
|
||||
return circles.find(circle => latlng.distanceTo(circle.center) < circle.radius);
|
||||
}
|
||||
|
||||
function handleLeftClick(e) {
|
||||
if (isBaddlyPlaced(e.latlng)) return;
|
||||
addCircle(e.latlng, radius);
|
||||
if (!isBaddlyPlaced(e.latlng)) addCircle(e.latlng, radius);
|
||||
}
|
||||
|
||||
function handleRightClick(e) {
|
||||
|
||||
Reference in New Issue
Block a user