From 5ced7f916d94e86e9a7ec164bee56f9a8e3a2a3a Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 26 May 2025 10:48:43 +0200 Subject: Replace Azure SWA with custom server --- src/controls/LocateControl.ts | 67 ------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/controls/LocateControl.ts (limited to 'src/controls') diff --git a/src/controls/LocateControl.ts b/src/controls/LocateControl.ts deleted file mode 100644 index b8c2d1d..0000000 --- a/src/controls/LocateControl.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { createControlComponent } from '@react-leaflet/core'; -import { LocateControl as LeafletLocateControl, LocateOptions } from 'leaflet.locatecontrol'; -import "leaflet.locatecontrol/dist/L.Control.Locate.min.css"; -import { useEffect } from 'react'; -import { useMap } from 'react-leaflet'; -import { useApp } from '../AppContext'; - -interface EnhancedLocateControlProps { - options?: LocateOptions; -} - -// Componente que usa el contexto para manejar la localización -export const EnhancedLocateControl = (props: EnhancedLocateControlProps) => { - const map = useMap(); - const { mapState, setUserLocation, setLocationPermission } = useApp(); - - useEffect(() => { - // Configuración por defecto del control de localización - const defaultOptions: LocateOptions = { - position: 'topright', - strings: { - title: 'Mostrar mi ubicación', - }, - flyTo: true, - onLocationError: (err) => { - console.error('Error en la localización:', err); - setLocationPermission(false); - }, - returnToPrevBounds: true, - showPopup: false, - }; - - // Combinamos las opciones por defecto con las personalizadas - const options = { ...defaultOptions, ...props.options }; - - // Creamos la instancia del control - const locateControl = new LeafletLocateControl(options); - - // Añadimos el control al mapa - locateControl.addTo(map); - - // Si tenemos permiso de ubicación y ya conocemos la ubicación del usuario, - // podemos activarla automáticamente - if (mapState.hasLocationPermission && mapState.userLocation) { - // Esperamos a que el mapa esté listo - setTimeout(() => { - try { - locateControl.start(); - } catch (e) { - console.error('Error al iniciar la localización automática', e); - } - }, 1000); - } - - return () => { - // Limpieza al desmontar el componente - locateControl.remove(); - }; - }, [map, mapState.hasLocationPermission, mapState.userLocation, props.options, setLocationPermission, setUserLocation]); - - return null; -}; - -// Exportamos también el control base por compatibilidad -export const LocateControl = createControlComponent( - (props) => new LeafletLocateControl(props) -); \ No newline at end of file -- cgit v1.3