diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-05-26 10:48:43 +0200 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-05-26 10:48:43 +0200 |
| commit | 5ced7f916d94e86e9a7ec164bee56f9a8e3a2a3a (patch) | |
| tree | b1ef5afa17b4a2f9fb2cbd683afc2fb6d905b5e1 /src/controls/LocateControl.ts | |
| parent | 4637373b50636e78dc2c7b6f99be879edb4ff7dc (diff) | |
Replace Azure SWA with custom server
Diffstat (limited to 'src/controls/LocateControl.ts')
| -rw-r--r-- | src/controls/LocateControl.ts | 67 |
1 files changed, 0 insertions, 67 deletions
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 |
