From f6118325925ba91173cf5bcc0a206b85fa3ef1a3 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 17 Aug 2024 21:35:03 +0200 Subject: [PATCH] add: marker poco temporaneo durante l'inserimento --- public/js/eventHandler.js | 11 ++++++++++- public/js/formHandler.js | 2 ++ public/js/markerHandler.js | 7 +++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/public/js/eventHandler.js b/public/js/eventHandler.js index f525445..5ce2b23 100644 --- a/public/js/eventHandler.js +++ b/public/js/eventHandler.js @@ -1,6 +1,7 @@ import { processForm } from "./formHandler.js"; import { basicElements } from "./getHtmlElements.js"; +import {createMarker} from "./markerHandler.js"; let editMode = false @@ -30,7 +31,15 @@ export function initEvents(map){ noticeCoordsPicker.style.display = 'none'; remainingForm.style.display = 'block'; map.getContainer().style.cursor = 'auto'; - // markerFormContainer.style.display = 'block'; + const tmpMarker = { + coordinate: { x: formInputCoordX.value, y: formInputCoordY.value}, + name: '', + description: '', + filename: '', + } + const marker = createMarker(tmpMarker, L, map) + // Va creata la logica di eliminazione del marker tmp + //localStorage.setItem("tmpMarkerId", marker._leaflet_id); } }); } \ No newline at end of file diff --git a/public/js/formHandler.js b/public/js/formHandler.js index c128004..eabe684 100644 --- a/public/js/formHandler.js +++ b/public/js/formHandler.js @@ -8,6 +8,8 @@ export async function processForm (e) { const formData = new FormData(markerForm) document.getElementById("markerFormContainer").style.display = 'none'; markerForm.reset(); + // const tmpMarker = localStorage.getItem("tmpMarkerId"); + // L.layerGroup().removeLayer(tmpMarker); await fetch('/uploadMarker', { method: 'POST', body: formData, diff --git a/public/js/markerHandler.js b/public/js/markerHandler.js index bbcddaf..a86b7fb 100644 --- a/public/js/markerHandler.js +++ b/public/js/markerHandler.js @@ -9,13 +9,16 @@ export function initMarkers(markerList, L, map){ }); } -export function createMarker(markerData, L, map){ +export function createMarker(markerData, L, map, returnMarker = false){ var marker = L.marker([markerData.coordinate.y, markerData.coordinate.x]).addTo(map); let popUpContentTitle = "

"+ markerData.name +"

"; let popUpContentdescription = "

"+ markerData.description +"

"; let popUpContentImage = ""; let popUpContent = popUpContentTitle + popUpContentdescription + popUpContentImage - marker.bindPopup(popUpContent); + marker.bindPopup(popUpContent); + if(returnMarker) { + return marker; + }; } export function updateMarkers(markerList, L, map){