2024-09-21 01:11:50 +02:00
|
|
|
const formatDate = (date) => {
|
|
|
|
const day = date.getDate();
|
|
|
|
const month = date.getMonth() + 1;
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
|
|
|
return `${day}/${month}/${year}`;
|
|
|
|
};
|
|
|
|
const formatTime = (date) => {
|
|
|
|
return date.toTimeString().split(" ")[0];
|
|
|
|
};
|
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
export function initMarkers(markerList, L, map) {
|
|
|
|
markerList.forEach((customMarker) => {
|
2024-09-21 01:11:50 +02:00
|
|
|
const marker = L.marker([customMarker.x, customMarker.y]).addTo(map);
|
|
|
|
const popUpContentTitle = "<h1>" + customMarker.title + "</h1>";
|
|
|
|
const popUpContentdescription = "<p>" + customMarker.description + "</p>";
|
|
|
|
const popUpContentImage =
|
2024-09-21 00:36:00 +02:00
|
|
|
"<img src='/img/" + customMarker.imgName + "'</img>";
|
2024-09-21 01:11:50 +02:00
|
|
|
const popUpContentDate =
|
2024-09-21 00:36:00 +02:00
|
|
|
"<br><p>Inserito il: " +
|
|
|
|
markerData.ts.substring(0, 10) +
|
|
|
|
"<br>alle " +
|
|
|
|
markerData.ts.substring(11, 16) +
|
|
|
|
"</p>";
|
2024-09-21 01:11:50 +02:00
|
|
|
const popUpContent =
|
2024-09-21 00:36:00 +02:00
|
|
|
popUpContentTitle +
|
|
|
|
popUpContentdescription +
|
|
|
|
popUpContentImage +
|
|
|
|
popUpContentDate;
|
|
|
|
marker.bindPopup(popUpContent).openPopup();
|
|
|
|
});
|
2024-06-30 22:56:19 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
export function createMarker(markerData, L, map, returnMarker = false) {
|
2024-09-21 01:11:50 +02:00
|
|
|
const marker = L.marker([
|
2024-09-21 00:36:00 +02:00
|
|
|
markerData.coordinate.y,
|
|
|
|
markerData.coordinate.x,
|
|
|
|
]).addTo(map);
|
2024-09-21 01:11:50 +02:00
|
|
|
const date = new Date(markerData.ts);
|
|
|
|
|
|
|
|
const popUpContentTitle = "<h1>" + markerData.name + "</h1>";
|
|
|
|
const popUpContentdescription = "<p>" + markerData.description + "</p>";
|
|
|
|
const popUpContentImage =
|
|
|
|
"<img src='/imgs/" + markerData.filename + "'</img>";
|
|
|
|
const popUpContentDate = `<br><p>Inserito il: ${formatDate(
|
|
|
|
date
|
|
|
|
)} <br>alle: ${formatTime(date)}</p>`;
|
|
|
|
|
|
|
|
//const popUpContentHour = "<p>" + "alle: " + markerData.ts.substring(11, 16) + "</p>";
|
|
|
|
const popUpContent =
|
2024-09-21 00:36:00 +02:00
|
|
|
popUpContentTitle +
|
|
|
|
popUpContentdescription +
|
|
|
|
popUpContentImage +
|
|
|
|
popUpContentDate; //+ popUpContentHour
|
|
|
|
marker.bindPopup(popUpContent);
|
|
|
|
if (returnMarker) {
|
|
|
|
return marker;
|
|
|
|
}
|
2024-07-16 18:31:53 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
export function createMarkerTemp(markerData, L, map, returnMarker = false) {
|
2024-09-21 01:11:50 +02:00
|
|
|
const marker = L.marker([
|
2024-09-21 00:36:00 +02:00
|
|
|
markerData.coordinate.y,
|
|
|
|
markerData.coordinate.x,
|
|
|
|
]).addTo(map);
|
2024-09-21 01:11:50 +02:00
|
|
|
const popUpContentdescription = "<p>" + markerData.description + "</p>";
|
|
|
|
const popUpContent = popUpContentdescription;
|
2024-09-21 00:36:00 +02:00
|
|
|
marker.bindPopup(popUpContent);
|
|
|
|
if (returnMarker) {
|
|
|
|
return marker;
|
|
|
|
}
|
2024-08-23 11:06:43 +02:00
|
|
|
}
|
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
export function updateMarkers(markerList, L, map) {
|
2024-09-21 01:11:50 +02:00
|
|
|
const layers = L.LayerGroup(); //layers contains all markers..
|
|
|
|
const contained = []; //makers in map boundingbox
|
2024-06-30 22:56:19 +02:00
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
layers.eachLayer(function (l) {
|
2024-09-21 01:11:50 +02:00
|
|
|
if (
|
|
|
|
layer instanceof L.Marker &&
|
|
|
|
map.getBounds().contains(layer.getLatLng())
|
|
|
|
)
|
|
|
|
contained.push(layer);
|
2024-09-21 00:36:00 +02:00
|
|
|
});
|
|
|
|
console.log(contained);
|
|
|
|
}
|