From 049f86727bbeb7446677c13458af4d12c12f34ff Mon Sep 17 00:00:00 2001 From: luisgulo Date: Sun, 1 Nov 2026 12:10:28 +0100 Subject: [PATCH] Ponemos escala y calculamos millas --- regla_portland.html | 68 ++++++++++--- regla_portland_tablet.html | 197 +++++++++++++++++++++++++++++-------- 2 files changed, 210 insertions(+), 55 deletions(-) diff --git a/regla_portland.html b/regla_portland.html index 6a46216..b4f3b27 100644 --- a/regla_portland.html +++ b/regla_portland.html @@ -147,9 +147,11 @@ Haz clic para añadir puntos en la carta (A -> B -> C...) + @@ -559,7 +561,6 @@ } function updateReadouts() { - // Cálculo preciso unificado del Rumbo Verdadero (Rv) considerando la diferencia entre regla y brújula let baseReferenceAngle = (360 - state.rulerAngle) % 360; let rv = (state.rulerAngle + 90 - (state.diskAngle - baseReferenceAngle)) % 360; if (rv < 0) rv += 360; @@ -609,10 +610,11 @@ draw(); } - canvas.addEventListener('mousedown', (e) => { + // --- GESTIÓN DE RATÓN Y TÁCTIL UNIFICADA --- + function handleInteractionStart(clientX, clientY) { const rect = canvas.getBoundingClientRect(); - const clickX = e.clientX - rect.left; - const clickY = e.clientY - rect.top; + const clickX = clientX - rect.left; + const clickY = clientY - rect.top; if (state.mode === 'ADD_POINTS') { const nextChar = String.fromCharCode(65 + state.points.length); @@ -629,7 +631,6 @@ if (angleDeg < 0) angleDeg += 360; state.rulerAngle = Math.round(angleDeg); - // Configuración automática de la rosa según la orientación de la regla state.diskAngle = (360 - state.rulerAngle) % 360; document.getElementById('ruler-angle-slider').value = state.rulerAngle; @@ -640,34 +641,75 @@ } draw(); - return; + return true; } const dist = Math.hypot(clickX - state.rulerX, clickY - state.rulerY); - if (dist < 250) { + // Radio de toque amplio para asegurar que coja la regla cómodamente en tablets (aprox 300px) + if (dist < 300) { state.isDragging = true; state.dragStartX = clickX - state.rulerX; state.dragStartY = clickY - state.rulerY; canvas.classList.remove('cursor-grab-custom'); canvas.classList.add('cursor-grabbing'); + return true; // Capturado por la regla } - }); + return false; // Tocó fuera de la regla, permitir scroll del mapa + } - canvas.addEventListener('mousemove', (e) => { + function handleInteractionMove(clientX, clientY) { if (state.isDragging && state.mode === 'MOVE') { const rect = canvas.getBoundingClientRect(); - state.rulerX = (e.clientX - rect.left) - state.dragStartX; - state.rulerY = (e.clientY - rect.top) - state.dragStartY; + state.rulerX = (clientX - rect.left) - state.dragStartX; + state.rulerY = (clientY - rect.top) - state.dragStartY; draw(); + return true; } - }); + return false; + } - window.addEventListener('mouseup', () => { + function handleInteractionEnd() { if (state.isDragging) { state.isDragging = false; canvas.classList.remove('cursor-grabbing'); canvas.classList.add('cursor-grab-custom'); } + } + + // Eventos de Ratón + canvas.addEventListener('mousedown', (e) => { + handleInteractionStart(e.clientX, e.clientY); + }); + + canvas.addEventListener('mousemove', (e) => { + handleInteractionMove(e.clientX, e.clientY); + }); + + window.addEventListener('mouseup', () => { + handleInteractionEnd(); + }); + + // Eventos Táctiles (Tablet / Móvil) + canvas.addEventListener('touchstart', (e) => { + if (e.touches.length === 1) { + const touch = e.touches[0]; + const captured = handleInteractionStart(touch.clientX, touch.clientY); + if (captured || state.mode === 'ADD_POINTS') { + e.preventDefault(); // Evita scroll solo si estás moviendo la regla o añadiendo puntos + } + } + }, { passive: false }); + + canvas.addEventListener('touchmove', (e) => { + if (state.isDragging && e.touches.length === 1) { + const touch = e.touches[0]; + handleInteractionMove(touch.clientX, touch.clientY); + e.preventDefault(); // Bloquea el scroll de la página mientras arrastras la regla + } + }, { passive: false }); + + canvas.addEventListener('touchend', () => { + handleInteractionEnd(); }); document.getElementById('disk-angle-slider').addEventListener('input', (e) => { diff --git a/regla_portland_tablet.html b/regla_portland_tablet.html index b4f3b27..66ad4fb 100644 --- a/regla_portland_tablet.html +++ b/regla_portland_tablet.html @@ -3,7 +3,7 @@ - Regla Portland Plotter - Visor Pro Avanzado + Regla Portland Plotter - Visor Pro Avanzado con Escala